chiark / gitweb /
Minor changes to the PiGlow code - got the orange & yellow the right way
authorGordon Henderson <projects@drogon.net>
Mon, 10 Nov 2014 10:55:23 +0000 (10:55 +0000)
committerGordon Henderson <projects@drogon.net>
Mon, 10 Nov 2014 10:55:23 +0000 (10:55 +0000)
round at last..

Updated for the 0x0012 board revision on the new A+

devLib/Makefile
devLib/piGlow.h
examples/Makefile
examples/lowPower.c [new file with mode: 0644]
examples/spiSpeed.c [new file with mode: 0644]
gpio/gpio.c
gpio/readall.c
pins/Makefile
wiringPi/Makefile
wiringPi/wiringPi.c
wiringPi/wiringPi.h

index a3c0d4228c51b787ed2413ac03e7cae20bc96e88..4ba17746d7c58d8e2af36041c3c6f84994e515d8 100644 (file)
@@ -65,18 +65,18 @@ $(DYNAMIC): $(OBJ)
        @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
@@ -89,7 +89,7 @@ install-headers:
        @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
@@ -97,13 +97,13 @@ install:    $(DYNAMIC) install-headers
        @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
@@ -118,7 +118,7 @@ uninstall:
        @ldconfig
 
 
-.PHONEY:       depend
+.PHONY:        depend
 depend:
        makedepend -Y $(SRC)
 
index d501c2c4e2033c467b0e64fb7fb74407801d0cc5..a4d89d01baf3a1102374d361a22accd9574d664b 100644 (file)
@@ -24,8 +24,8 @@
 
 
 #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
index 571e3419ff42a70163035b20aac4d48c99f81509..c9967dc4bf0c5be1c488888b34b7ba1803fd7914 100644 (file)
@@ -43,6 +43,7 @@ SRC   =       blink.c blink8.c blink12.c                                      \
                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)
diff --git a/examples/lowPower.c b/examples/lowPower.c
new file mode 100644 (file)
index 0000000..e901e7f
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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 ;
+}
diff --git a/examples/spiSpeed.c b/examples/spiSpeed.c
new file mode 100644 (file)
index 0000000..0208f0a
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * 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 ;
+}
index c4408746a69d26ee3878d2c30cf97e2e84271905..43e69341b090ff430d7c91b25327450a751e50e7 100644 (file)
@@ -2,7 +2,7 @@
  * 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/
@@ -53,7 +53,7 @@ extern void doPins       (void) ;
 #  define      FALSE   (1==2)
 #endif
 
-#define        VERSION                 "2.20"
+#define        VERSION                 "2.21"
 #define        PI_USB_POWER_CONTROL    38
 #define        I2CDETECT               "/usr/sbin/i2cdetect"
 
@@ -612,23 +612,44 @@ static void doResetExternal (void)
 
 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) ;
   }
 }
 
index 76b5cfc979ea04034160c95d858b6e18d3045ee8..aba8de8c19a489d7ca460bbe7f36b5bbd808f308 100644 (file)
@@ -278,23 +278,31 @@ void abReadall (int model, int rev)
 
 
 /*
- * 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") ;
 }
 
 
@@ -312,8 +320,8 @@ void doReadall (void)
 
   /**/ 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
index 5e200c28f9d3309c63dc5d43df231c473f5dadd3..fd34ee930ac8fc730b659b1713652d2a0ad70a7c 100644 (file)
@@ -13,6 +13,6 @@ pdf:  pins.dvi
        @dvipdf pins.dvi
 
 
-.PHONEY:       clean
+.PHONY:        clean
 clean:
        @rm -f *.dvi *.aux *.log *.ps *.toc *.bak *~
index 78d36121c9a81dfb35575fd996cca5f00e39c48d..4e3342e03ca354c531fc3f687885a360ca7a9432 100644 (file)
@@ -77,18 +77,18 @@ $(DYNAMIC): $(OBJ)
        @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
@@ -116,7 +116,7 @@ install-headers:
        @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
@@ -124,13 +124,13 @@ install:  $(DYNAMIC) install-headers
        @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
@@ -160,7 +160,7 @@ uninstall:
        @ldconfig
 
 
-.PHONEY:       depend
+.PHONY:        depend
 depend:
        makedepend -Y $(SRC) $(SRC_I2C)
 
index e7ae3863c7ca0fe6f5b66e08a833293965d9325b..ba45f4ddc30704da97e801d2feb314dc380cb0f6 100644 (file)
@@ -203,13 +203,14 @@ static volatile uint32_t *timerIrqRaw ;
 //     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] =
@@ -620,6 +621,7 @@ int wiringPiFailure (int fatal, const char *message, ...)
  *     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
@@ -687,10 +689,12 @@ int piBoardRev (void)
   
 // 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:
 
@@ -782,6 +786,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
   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 ;               }
 }
  
@@ -1474,8 +1479,10 @@ int waitForInterrupt (int pin, int mS)
 
 // 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 ;
 }
index 2bc63ba0146c1837e2d0e791655d09bebcf9e1d4..42265fc836063b9a5262bc06da7739c879270663 100644 (file)
@@ -75,6 +75,7 @@
 #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
@@ -87,7 +88,7 @@
 #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] ;