round at last..
Updated for the 0x0012 board revision on the new A+
@echo [Compile] $<
@$(CC) -c $(CFLAGS) $< -o $@
-.PHONEY: clean
+.PHONY: clean
clean:
@echo "[Clean]"
@rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPiDev.*
-.PHONEY: tags
+.PHONY: tags
tags: $(SRC)
@echo [ctags]
@ctags $(SRC)
-.PHONEY: install-headers
+.PHONY: install-headers
install-headers:
@echo "[Install Headers]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/include
@install -m 0644 lcd.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 piGlow.h $(DESTDIR)$(PREFIX)/include
-.PHONEY: install
+.PHONY: install
install: $(DYNAMIC) install-headers
@echo "[Install Dynamic Lib]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPiDev.so.$(VERSION) $(DESTDIR)/lib/libwiringPiDev.so
@ldconfig
-.PHONEY: install-static
+.PHONY: install-static
install-static: $(STATIC) install-headers
@echo "[Install Static Lib]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
@install -m 0755 libwiringPiDev.a $(DESTDIR)$(PREFIX)/lib
-.PHONEY: uninstall
+.PHONY: uninstall
uninstall:
@echo "[UnInstall]"
@rm -f $(DESTDIR)$(PREFIX)/include/ds1302.h
@ldconfig
-.PHONEY: depend
+.PHONY: depend
depend:
makedepend -Y $(SRC)
#define PIGLOW_RED 0
-#define PIGLOW_YELLOW 1
-#define PIGLOW_ORANGE 2
+#define PIGLOW_ORANGE 1
+#define PIGLOW_YELLOW 2
#define PIGLOW_GREEN 3
#define PIGLOW_BLUE 4
#define PIGLOW_WHITE 5
nes.c \
softPwm.c softTone.c \
delayTest.c serialRead.c serialTest.c okLed.c ds1302.c \
+ lowPower.c \
rht03.c piglow.c
OBJ = $(SRC:.c=.o)
--- /dev/null
+/*
+ * lowPower.c:
+ * Check the Pi's LOW-Power signal.
+ *
+ * This is a demonstration program that could be turned into some sort
+ * of logger via e.g. syslog - however it's also probably something
+ * that might be better handled by a future kernel - who knows.
+ *
+ * Copyright (c) 2014 Gordon Henderson.
+ ***********************************************************************
+ * This file is part of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+#include <stdio.h>
+#include <time.h>
+#include <wiringPi.h>
+
+
+#define LOW_POWER 35
+
+/*
+ * lowPower:
+ * This is an ISR that waits for the low-power signal going low and
+ * prints the result.
+ *********************************************************************************
+ */
+
+void lowPower (void)
+{
+ time_t t ;
+
+ time (&t) ;
+ printf ("%s: LOW POWER DETECTED\n", ctime (&t)) ;
+}
+
+
+/*
+ *********************************************************************************
+ * main
+ *********************************************************************************
+ */
+
+int main (void)
+{
+ wiringPiSetupGpio () ; // GPIO mode as it's an internal pin
+
+ wiringPiISR (LOW_POWER, INT_EDGE_FALLING, &lowPower) ;
+
+ for (;;)
+ delay (1000) ;
+
+ return 0 ;
+}
--- /dev/null
+/*
+ * spiSpeed.c:
+ * Code to measure the SPI speed/latency.
+ * Copyright (c) 2014 Gordon Henderson
+ ***********************************************************************
+ * This file is part of wiringPi:
+ * https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ * wiringPi is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * wiringPi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with wiringPi.
+ * If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+//#include <fcntl.h>
+//#include <sys/ioctl.h>
+//#include <linux/spi/spidev.h>
+
+#include <wiringPi.h>
+#include <wiringPiSPI.h>
+
+#define TRUE (1==1)
+#define FALSE (!TRUE)
+
+#define SPI_CHAN 0
+#define NUM_TIMES 100
+#define MAX_SIZE (1024*1024)
+
+static int myFd ;
+
+
+void spiSetup (int speed)
+{
+ if ((myFd = wiringPiSPISetup (SPI_CHAN, speed)) < 0)
+ {
+ fprintf (stderr, "Can't open the SPI bus: %s\n", strerror (errno)) ;
+ exit (EXIT_FAILURE) ;
+ }
+}
+
+
+int main (void)
+{
+ int speed, times, size ;
+ unsigned int start, end ;
+ int spiFail ;
+ unsigned char *myData ;
+ double timePerTransaction, perfectTimePerTransaction, dataSpeed ;
+
+ if ((myData = malloc (MAX_SIZE)) == NULL)
+ {
+ fprintf (stderr, "Unable to allocate buffer: %s\n", strerror (errno)) ;
+ exit (EXIT_FAILURE) ;
+ }
+
+ wiringPiSetup () ;
+
+ for (speed = 1 ; speed <= 32 ; speed *= 2)
+ {
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
+ printf ("| MHz | Size | mS/Trans | TpS | Mb/Sec | Latency mS |\n") ;
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
+
+ spiFail = FALSE ;
+ spiSetup (speed * 1000000) ;
+ for (size = 1 ; size <= MAX_SIZE ; size *= 2)
+ {
+ printf ("| %5d | %6d ", speed, size) ;
+
+ start = millis () ;
+ for (times = 0 ; times < NUM_TIMES ; ++times)
+ if (wiringPiSPIDataRW (SPI_CHAN, myData, size) == -1)
+ {
+ printf ("SPI failure: %s\n", strerror (errno)) ;
+ spiFail = TRUE ;
+ break ;
+ }
+ end = millis () ;
+
+ if (spiFail)
+ break ;
+
+ timePerTransaction = ((double)(end - start) / (double)NUM_TIMES) / 1000.0 ;
+ dataSpeed = (double)(size * 8) / (1024.0 * 1024.0) / timePerTransaction ;
+ perfectTimePerTransaction = ((double)(size * 8)) / ((double)(speed * 1000000)) ;
+
+ printf ("| %8.3f ", timePerTransaction * 1000.0) ;
+ printf ("| %8.1f ", 1.0 / timePerTransaction) ;
+ printf ("| %9.5f ", dataSpeed) ;
+ printf ("| %8.5f ", (timePerTransaction - perfectTimePerTransaction) * 1000.0) ;
+ printf ("|\n") ;
+
+ }
+
+ close (myFd) ;
+ printf ("+-------+--------+----------+----------+-----------+------------+\n") ;
+ printf ("\n") ;
+ }
+
+ return 0 ;
+}
* gpio.c:
* Swiss-Army-Knife, Set-UID command-line interface to the Raspberry
* Pi's GPIO.
- * Copyright (c) 2012-2013 Gordon Henderson
+ * Copyright (c) 2012-2014 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
# define FALSE (1==2)
#endif
-#define VERSION "2.20"
+#define VERSION "2.21"
#define PI_USB_POWER_CONTROL 38
#define I2CDETECT "/usr/sbin/i2cdetect"
static void doReset (char *progName)
{
- int pin ;
+ int model, rev, mem, maker, overVolted ;
+ int pin, endPin ;
+
+ printf ("GPIO Reset is dangerous!\n") ;
+ printf (" - Do Not rely on this to do anything sensible!\n") ;
- if (wiringPiNodes != NULL) // External reset
+ if (wiringPiNodes != NULL) // External
+ {
doResetExternal () ;
+ return ;
+ }
+
+ piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
+
+ /**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
+ endPin = 16 ;
+ else if (model == PI_MODEL_BP)
+ endPin = 39 ;
+ else if (model == PI_MODEL_CM)
+ {
+ printf (" - Don't know how to reset a comput module:\n") ;
+ printf (" Write a shell-script to reset the pins to the state you need.\n") ;
+ return ;
+ }
else
{
- doUnexportall (progName) ;
+ printf ("Oops - unable to determine board type... model: %d\n", model) ;
+ return ;
+ }
- for (pin = 0 ; pin < 64 ; ++pin)
- {
- if (wpiPinToGpio (pin) == -1)
- continue ;
+ for (pin = 0 ; pin <= endPin ; ++pin)
+ {
+ if (wpiPinToGpio (pin) == -1)
+ continue ;
- digitalWrite (pin, LOW) ;
- pinMode (pin, INPUT) ;
- pullUpDnControl (pin, PUD_OFF) ;
- }
+ digitalWrite (pin, LOW) ;
+ pinMode (pin, INPUT) ;
+ pullUpDnControl (pin, PUD_OFF) ;
}
}
/*
- * bPlusReadall:
- * Read all the pins on the model B+
+ * piPlusReadall:
+ * Read all the pins on the model A+ or the B+
*********************************************************************************
*/
-void bPlusReadall (void)
+void piPlusReadall (int model)
{
int pin ;
- printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
+ if (model == PI_MODEL_AP)
+ printf (" +-----+-----+---------+------+---+--A Plus--+---+------+---------+-----+-----+\n") ;
+ else
+ printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
+
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 1 ; pin <= 40 ; pin += 2)
readallPhys (pin) ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
- printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
+
+ if (model == PI_MODEL_AP)
+ printf (" +-----+-----+---------+------+---+--A Plus--+---+------+---------+-----+-----+\n") ;
+ else
+ printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
}
/**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
abReadall (model, rev) ;
- else if (model == PI_MODEL_BP)
- bPlusReadall () ;
+ else if ((model == PI_MODEL_BP) || (model == PI_MODEL_AP))
+ piPlusReadall (model) ;
else if (model == PI_MODEL_CM)
cmReadall () ;
else
@dvipdf pins.dvi
-.PHONEY: clean
+.PHONY: clean
clean:
@rm -f *.dvi *.aux *.log *.ps *.toc *.bak *~
@echo [Compile] $<
@$(CC) -c $(CFLAGS) $< -o $@
-.PHONEY: clean
+.PHONY: clean
clean:
@echo "[Clean]"
@rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPi.*
-.PHONEY: tags
+.PHONY: tags
tags: $(SRC)
@echo [ctags]
@ctags $(SRC)
-.PHONEY: install-headers
+.PHONY: install-headers
install-headers:
@echo "[Install Headers]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/include
@install -m 0644 pcf8591.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 sn3218.h $(DESTDIR)$(PREFIX)/include
-.PHONEY: install
+.PHONY: install
install: $(DYNAMIC) install-headers
@echo "[Install Dynamic Lib]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so
@ldconfig
-.PHONEY: install-static
+.PHONY: install-static
install-static: $(STATIC) install-headers
@echo "[Install Static Lib]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
@install -m 0755 libwiringPi.a $(DESTDIR)$(PREFIX)/lib
-.PHONEY: uninstall
+.PHONY: uninstall
uninstall:
@echo "[UnInstall]"
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPi.h
@ldconfig
-.PHONEY: depend
+.PHONY: depend
depend:
makedepend -Y $(SRC) $(SRC_I2C)
// and PI_VERSION_X defines in wiringPi.h
// Only intended for the gpio command - use at your own risk!
-const char *piModelNames [5] =
+const char *piModelNames [6] =
{
"Unknown",
"Model A",
"Model B",
"Model B+",
"Compute Module",
+ "Model A+",
} ;
const char *piRevisionNames [5] =
* 000f - Model B, Rev 2, 512MB, Qisda
* 0010 - Model B+, Rev 1.2, 512MB, Sony
* 0011 - Pi CM, Rev 1.2, 512MB, Sony
+ * 0012 - Model A+ Rev 1.2, 256MB, Sony
*
* A small thorn is the olde style overvolting - that will add in
* 1000000
// If you have overvolted the Pi, then it appears that the revision
// has 100000 added to it!
+// The actual condition for it being set is:
+// (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0
if (wiringPiDebug)
if (strlen (c) != 4)
- printf ("piboardRev: This Pi has/is overvolted!\n") ;
+ printf ("piboardRev: This Pi has/is (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0\n") ;
// Isolate last 4 characters:
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
+ else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
}
// Do a dummy read to clear the interrupt
// A one character read appars to be enough.
+// Followed by a seek to reset it.
(void)read (fd, &c, 1) ;
+ lseek (fd, 0, SEEK_SET) ;
return x ;
}
#define PI_MODEL_B 2
#define PI_MODEL_BP 3
#define PI_MODEL_CM 4
+#define PI_MODEL_AP 5
#define PI_VERSION_UNKNOWN 0
#define PI_VERSION_1 1
#define PI_MAKER_SONY 2
#define PI_MAKER_QISDA 3
-extern const char *piModelNames [5] ;
+extern const char *piModelNames [6] ;
extern const char *piRevisionNames [5] ;
extern const char *piMakerNames [4] ;