You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

545 regels
25 KiB

  1. /*
  2. * readall.c:
  3. * The readall functions - getting a bit big, so split them out.
  4. * Copyright (c) 2012-2018 Gordon Henderson
  5. ***********************************************************************
  6. * This file is part of wiringPi:
  7. * https://github.com/WiringPi/WiringPi/
  8. *
  9. * wiringPi is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * wiringPi is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  21. ***********************************************************************
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <stdint.h>
  26. #include <ctype.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <errno.h>
  30. #include <fcntl.h>
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <wiringPi.h>
  34. extern int wpMode;
  35. #ifndef TRUE
  36. # define TRUE (1==1)
  37. # define FALSE (1==2)
  38. #endif
  39. /*
  40. * doReadallExternal:
  41. * A relatively crude way to read the pins on an external device.
  42. * We don't know the input/output mode of pins, but we can tell
  43. * if it's an analog pin or a digital one...
  44. *********************************************************************************
  45. */
  46. static void doReadallExternal (void)
  47. {
  48. int pin;
  49. printf ("+------+---------+--------+\n");
  50. printf ("| Pin | Digital | Analog |\n");
  51. printf ("+------+---------+--------+\n");
  52. for (pin = wiringPiNodes->pinBase; pin <= wiringPiNodes->pinMax; ++pin)
  53. printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin));
  54. printf ("+------+---------+--------+\n");
  55. }
  56. /*
  57. * doReadall:
  58. * Read all the GPIO pins
  59. * We also want to use this to read the state of pins on an externally
  60. * connected device, so we need to do some fiddling with the internal
  61. * wiringPi node structures - since the gpio command can only use
  62. * one external device at a time, we'll use that to our advantage...
  63. *********************************************************************************
  64. */
  65. // FSEL_INPT, FSEL_OUTP, FSEL_ALT5, FSEL_ALT4, FSEL_ALT0, FSEL_ALT1, FSEL_ALT2, FSEL_ALT3
  66. // 000, 001, 010, 011, 100, 101, 110, 111
  67. static char *alts[] =
  68. {
  69. "IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
  70. };
  71. static int physToWpi[64] =
  72. {
  73. -1, // 0
  74. -1, -1, // 1, 2
  75. 8, -1,
  76. 9, -1,
  77. 7, 15,
  78. -1, 16,
  79. 0, 1,
  80. 2, -1,
  81. 3, 4,
  82. -1, 5,
  83. 12, -1,
  84. 13, 6,
  85. 14, 10,
  86. -1, 11, // 25, 26
  87. 30, 31, // Actually I2C, but not used
  88. 21, -1,
  89. 22, 26,
  90. 23, -1,
  91. 24, 27,
  92. 25, 28,
  93. -1, 29, // 39, 40
  94. -1, -1, // 41, 42
  95. -1, -1,
  96. -1, -1,
  97. -1, -1,
  98. -1, -1,
  99. 17, 18,
  100. 19, 20, // 53, 54
  101. -1, -1, -1, -1, -1, -1, -1, -1, -1
  102. };
  103. // This is ony used for power and ground pins & old abReadall().
  104. static char *physNames[64] =
  105. {
  106. NULL,
  107. " 3.3v", "5v ",
  108. " SDA.1", "5v ",
  109. " SCL.1", "GND ",
  110. " GPCLK0", "TXD1 ",
  111. " GND", "RXD1 ",
  112. "GPIO.17", "GPIO.18",
  113. "GPIO.27", "GND ",
  114. "GPIO.22", "GPIO.23",
  115. " 3.3v", "GPIO.24",
  116. " MOSI", "GND ",
  117. " MISO", "GPIO.25",
  118. " SCLK", "CE0 ",
  119. " GND", "CE1 ",
  120. " SDA.0", "SCL.0 ",
  121. "GPIO.05", "GND ",
  122. "GPIO.06", "GPIO.12",
  123. "GPIO.13", "GND ",
  124. "GPIO.19", "GPIO.16",
  125. "GPIO.26", "GPIO.20",
  126. " GND", "GPIO.21",
  127. NULL, NULL,
  128. NULL, NULL,
  129. NULL, NULL,
  130. NULL, NULL,
  131. NULL, NULL,
  132. "GPIO.28", "GPIO.29",
  133. "GPIO.30", "GPIO.31",
  134. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  135. };
  136. static const char *gpio_alt_names_2835[54*8] = {
  137. // FSEL_INPT, FSEL_OUTP, FSEL_ALT5 , FSEL_ALT4 , FSEL_ALT0 , FSEL_ALT1 , FSEL_ALT2 , FSEL_ALT3
  138. // 000, 001, 010 , 011 , 100 , 101 , 110 , 111
  139. "GPIO.00" , "GPIO.00", 0 , "AVEIN_VCLK" , "SDA0" , "SA5" , "PCLK" , "AVEOUT_VCLK" ,
  140. "GPIO.01" , "GPIO.01", 0 , "AVEIN_DSYNC", "SCL0" , "SA4" , "DE" , "AVEOUT_DSYNC" ,
  141. "GPIO.02" , "GPIO.02", 0 , "AVEIN_VSYNC", "SDA1" , "SA3" , "LCD_VSYNC" , "AVEOUT_VSYNC" ,
  142. "GPIO.03" , "GPIO.03", 0 , "AVEIN_HSYNC", "SCL1" , "SA2" , "LCD_HSYNC" , "AVEOUT_HSYNC" ,
  143. "GPIO.04" , "GPIO.04", "ARM_TDI" , "AVEIN_VID0" , "GPCLK0" , "SA1" , "DPI_D0" , "AVEOUT_VID0" ,
  144. "GPIO.05" , "GPIO.05", "ARM_TDO" , "AVEIN_VID1" , "GPCLK1" , "SA0" , "DPI_D1" , "AVEOUT_VID1" ,
  145. "GPIO.06" , "GPIO.06", "ARM_RTCK" , "AVEIN_VID2" , "GPCLK2" , "SOE_N_SE" , "DPI_D2" , "AVEOUT_VID2" ,
  146. "GPIO.07" , "GPIO.07", 0 , "AVEIN_VID3" , "SPI0_CE1_N", "SWE_N_SRW_N", "DPI_D3" , "AVEOUT_VID3" ,
  147. "GPIO.08" , "GPIO.08", 0 , "AVEIN_VID4" , "SPI0_CE0_N", "SD0" , "DPI_D4" , "AVEOUT_VID4" ,
  148. "GPIO.09" , "GPIO.09", 0 , "AVEIN_VID5" , "SPI0_MISO" , "SD1" , "DPI_D5" , "AVEOUT_VID5" ,
  149. "GPIO.10" , "GPIO.10", 0 , "AVEIN_VID6" , "SPI0_MOSI" , "SD2" , "DPI_D6" , "AVEOUT_VID6" ,
  150. "GPIO.11" , "GPIO.11", 0 , "AVEIN_VID7" , "SPI0_SCLK" , "SD3" , "DPI_D7" , "AVEOUT_VID7" ,
  151. "GPIO.12" , "GPIO.12", "ARM_TMS" , "AVEIN_VID8" , "PWM0" , "SD4" , "DPI_D8" , "AVEOUT_VID8" ,
  152. "GPIO.13" , "GPIO.13", "ARM_TCK" , "AVEIN_VID9" , "PWM1" , "SD5" , "DPI_D9" , "AVEOUT_VID9" ,
  153. "GPIO.14" , "GPIO.14", "TXD1" , "AVEIN_VID10", "TXD0" , "SD6" , "DPI_D10" , "AVEOUT_VID10" ,
  154. "GPIO.15" , "GPIO.15", "RXD1" , "AVEIN_VID11", "RXD0" , "SD7" , "DPI_D11" , "AVEOUT_VID11" ,
  155. "GPIO.16" , "GPIO.16", "CTS1" , "SPI1_CE2_N" , "FL0" , "SD8" , "DPI_D12" , "CTS0" ,
  156. "GPIO.17" , "GPIO.17", "RTS1" , "SPI1_CE1_N" , "FL1" , "SD9" , "DPI_D13" , "RTS0" ,
  157. "GPIO.18" , "GPIO.18", "PWM0" , "SPI1_CE0_N" , "PCM_CLK" , "SD10" , "DPI_D14" , "I2CSL_SDA_MOSI",
  158. "GPIO.19" , "GPIO.19", "PWM1" , "SPI1_MISO" , "PCM_FS" , "SD11" , "DPI_D15" , "I2CSL_SCL_SCLK",
  159. "GPIO.20" , "GPIO.20", "GPCLK0" , "SPI1_MOSI" , "PCM_DIN" , "SD12" , "DPI_D16" , "I2CSL_MISO" ,
  160. "GPIO.21" , "GPIO.21", "GPCLK1" , "SPI1_SCLK" , "PCM_DOUT" , "SD13" , "DPI_D17" , "I2CSL_CE_N" ,
  161. "GPIO.22" , "GPIO.22", 0 , "ARM_TRST" , "SD0_CLK" , "SD14" , "DPI_D18" , "SD1_CLK" ,
  162. "GPIO.23" , "GPIO.23", 0 , "ARM_RTCK" , "SD0_CMD" , "SD15" , "DPI_D19" , "SD1_CMD" ,
  163. "GPIO.24" , "GPIO.24", 0 , "ARM_TDO" , "SD0_DAT0" , "SD16" , "DPI_D20" , "SD1_DAT0" ,
  164. "GPIO.25" , "GPIO.25", 0 , "ARM_TCK" , "SD0_DAT1" , "SD17" , "DPI_D21" , "SD1_DAT1" ,
  165. "GPIO.26" , "GPIO.26", 0 , "ARM_TDI" , "SD0_DAT2" , "TE0" , "DPI_D22" , "SD1_DAT2" ,
  166. "GPIO.27" , "GPIO.27", 0 , "ARM_TMS" , "SD0_DAT3" , "TE1" , "DPI_D23" , "SD1_DAT3" ,
  167. "GPIO.28" , "GPIO.28", 0 , 0 , "SDA0" , "SA5" , "PCM_CLK" , "FL0" ,
  168. "GPIO.29" , "GPIO.29", 0 , 0 , "SCL0" , "SA4" , "PCM_FS" , "FL1" ,
  169. "GPIO.30" , "GPIO.30", "CTS1" , 0 , "TE0" , "SA3" , "PCM_DIN" , "CTS0" ,
  170. "GPIO.31" , "GPIO.31", "RTS1" , 0 , "FL0" , "SA2" , "PCM_DOUT" , "RTS0" ,
  171. "GPIO.32" , "GPIO.32", "TXD1" , 0 , "GPCLK0" , "SA1" , "RING_OCLK" , "TXD0" ,
  172. "GPIO.33" , "GPIO.33", "RXD1" , 0 , "FL1" , "SA0" , "TE1" , "RXD0" ,
  173. "GPIO.34" , "GPIO.34", 0 , 0 , "GPCLK0" , "SOE_N_SE" , "TE2" , "SD1_CLK" ,
  174. "GPIO.35" , "GPIO.35", 0 , 0 , "SPI0_CE1_N", "SWE_N_SRW_N", 0 , "SD1_CMD" ,
  175. "GPIO.36" , "GPIO.36", 0 , 0 , "SPI0_CE0_N", "SD0" , "TXD0" , "SD1_DAT0" ,
  176. "GPIO.37" , "GPIO.37", 0 , 0 , "SPI0_MISO" , "SD1" , "RXD0" , "SD1_DAT1" ,
  177. "GPIO.38" , "GPIO.38", 0 , 0 , "SPI0_MOSI" , "SD2" , "RTS0" , "SD1_DAT2" ,
  178. "GPIO.39" , "GPIO.39", 0 , 0 , "SPI0_SCLK" , "SD3" , "CTS0" , "SD1_DAT3" ,
  179. "GPIO.40" , "GPIO.40", "TXD1" , "SPI2_MISO" , "PWM0" , "SD4" , 0 , "SD1_DAT4" ,
  180. "GPIO.41" , "GPIO.41", "RXD1" , "SPI2_MOSI" , "PWM1" , "SD5" , "TE0" , "SD1_DAT5" ,
  181. "GPIO.42" , "GPIO.42", "RTS1" , "SPI2_SCLK" , "GPCLK1" , "SD6" , "TE1" , "SD1_DAT6" ,
  182. "GPIO.43" , "GPIO.43", "CTS1" , "SPI2_CE0_N" , "GPCLK2" , "SD7" , "TE2" , "SD1_DAT7" ,
  183. "GPIO.44" , "GPIO.44", 0 , "SPI2_CE1_N" , "GPCLK1" , "SDA0" , "SDA1" , "TE0" ,
  184. "GPIO.45" , "GPIO.45", 0 , "SPI2_CE2_N" , "PWM1" , "SCL0" , "SCL1" , "TE1" ,
  185. "GPIO.46" , "GPIO.46", "SPI2_CE1_N", 0 , "SDA0" , "SDA1" , "SPI0_CE0_N", 0 ,
  186. "GPIO.47" , "GPIO.47", "SPI2_CE0_N", 0 , "SCL0" , "SCL1" , "SPI0_MISO" , 0 ,
  187. "GPIO.48" , "GPIO.48", "SPI2_SCLK" , "ARM_TRST" , "SD0_CLK" , "FL0" , "SPI0_MOSI" , "SD1_CLK" ,
  188. "GPIO.49" , "GPIO.49", "SPI2_MOSI" , "ARM_RTCK" , "SD0_CMD" , "GPCLK0" , "SPI0_SCLK" , "SD1_CMD" ,
  189. "GPIO.50" , "GPIO.50", 0 , "ARM_TDO" , "SD0_DAT0" , "GPCLK1" , "PCM_CLK" , "SD1_DAT0" ,
  190. "GPIO.51" , "GPIO.51", 0 , "ARM_TCK" , "SD0_DAT1" , "GPCLK2" , "PCM_FS" , "SD1_DAT1" ,
  191. "GPIO.52" , "GPIO.52", 0 , "ARM_TDI" , "SD0_DAT2" , "PWM0" , "PCM_DIN" , "SD1_DAT2" ,
  192. "GPIO.53" , "GPIO.53", 0 , "ARM_TMS" , "SD0_DAT3" , "PWM1" , "PCM_DOUT" , "SD1_DAT3"
  193. };
  194. static const char *gpio_alt_names_2711[54*8] = {
  195. // FSEL_INPT, FSEL_OUTP, FSEL_ALT5 , FSEL_ALT4 , FSEL_ALT0 , FSEL_ALT1 , FSEL_ALT2 , FSEL_ALT3
  196. // 000, 001, 010 , 011 , 100 , 101 , 110 , 111
  197. "GPIO.00" , "GPIO.00", "SDA6" , "TXD2" , "SDA0" , "SA5" , "PCLK" , "SPI3_CE0_N" ,
  198. "GPIO.01" , "GPIO.01", "SCL6" , "RXD2" , "SCL0" , "SA4" , "DE" , "SPI3_MISO" ,
  199. "GPIO.02" , "GPIO.02", "SDA3" , "CTS2" , "SDA1" , "SA3" , "LCD_VSYNC" , "SPI3_MOSI" ,
  200. "GPIO.03" , "GPIO.03", "SCL3" , "RTS2" , "SCL1" , "SA2" , "LCD_HSYNC" , "SPI3_SCLK" ,
  201. "GPIO.04" , "GPIO.04", "SDA3" , "TXD3" , "GPCLK0" , "SA1" , "DPI_D0" , "SPI4_CE0_N" ,
  202. "GPIO.05" , "GPIO.05", "SCL3" , "RXD3" , "GPCLK1" , "SA0" , "DPI_D1" , "SPI4_MISO" ,
  203. "GPIO.06" , "GPIO.06", "SDA4" , "CTS3" , "GPCLK2" , "SOE_N_SE" , "DPI_D2" , "SPI4_MOSI" ,
  204. "GPIO.07" , "GPIO.07", "SCL4" , "RTS3" , "SPI0_CE1_N", "SWE_N_SRW_N", "DPI_D3" , "SPI4_SCLK" ,
  205. "GPIO.08" , "GPIO.08", "SDA4" , "TXD4" , "SPI0_CE0_N", "SD0" , "DPI_D4" , "I2CSL_CE_N" ,
  206. "GPIO.09" , "GPIO.09", "SCL4" , "RXD4" , "SPI0_MISO" , "SD1" , "DPI_D5" , "I2CSL_SDI_MISO",
  207. "GPIO.10" , "GPIO.10", "SDA5" , "CTS4" , "SPI0_MOSI" , "SD2" , "DPI_D6" , "I2CSL_SDA_MOSI",
  208. "GPIO.11" , "GPIO.11", "SCL5" , "RTS4" , "SPI0_SCLK" , "SD3" , "DPI_D7" , "I2CSL_SCL_SCLK",
  209. "GPIO.12" , "GPIO.12", "SDA5" , "TXD5" , "PWM0_0" , "SD4" , "DPI_D8" , "SPI5_CE0_N" ,
  210. "GPIO.13" , "GPIO.13", "SCL5" , "RXD5" , "PWM0_1" , "SD5" , "DPI_D9" , "SPI5_MISO" ,
  211. "GPIO.14" , "GPIO.14", "TXD1" , "CTS5" , "TXD0" , "SD6" , "DPI_D10" , "SPI5_MOSI" ,
  212. "GPIO.15" , "GPIO.15", "RXD1" , "RTS5" , "RXD0" , "SD7" , "DPI_D11" , "SPI5_SCLK" ,
  213. "GPIO.16" , "GPIO.16", "CTS1" , "SPI1_CE2_N" , 0 , "SD8" , "DPI_D12" , "CTS0" ,
  214. "GPIO.17" , "GPIO.17", "RTS1" , "SPI1_CE1_N" , 0 , "SD9" , "DPI_D13" , "RTS0" ,
  215. "GPIO.18" , "GPIO.18", "PWM0_0" , "SPI1_CE0_N" , "PCM_CLK" , "SD10" , "DPI_D14" , "SPI6_CE0_N" ,
  216. "GPIO.19" , "GPIO.19", "PWM0_1" , "SPI1_MISO" , "PCM_FS" , "SD11" , "DPI_D15" , "SPI6_MISO" ,
  217. "GPIO.20" , "GPIO.20", "GPCLK0" , "SPI1_MOSI" , "PCM_DIN" , "SD12" , "DPI_D16" , "SPI6_MOSI" ,
  218. "GPIO.21" , "GPIO.21", "GPCLK1" , "SPI1_SCLK" , "PCM_DOUT" , "SD13" , "DPI_D17" , "SPI6_SCLK" ,
  219. "GPIO.22" , "GPIO.22", "SDA6" , "ARM_TRST" , "SD0_CLK" , "SD14" , "DPI_D18" , "SD1_CLK" ,
  220. "GPIO.23" , "GPIO.23", "SCL6" , "ARM_RTCK" , "SD0_CMD" , "SD15" , "DPI_D19" , "SD1_CMD" ,
  221. "GPIO.24" , "GPIO.24", "SPI3_CE1_N" , "ARM_TDO" , "SD0_DAT0" , "SD16" , "DPI_D20" , "SD1_DAT0" ,
  222. "GPIO.25" , "GPIO.25", "SPI4_CE1_N" , "ARM_TCK" , "SD0_DAT1" , "SD17" , "DPI_D21" , "SD1_DAT1" ,
  223. "GPIO.26" , "GPIO.26", "SPI5_CE1_N" , "ARM_TDI" , "SD0_DAT2" , 0 , "DPI_D22" , "SD1_DAT2" ,
  224. "GPIO.27" , "GPIO.27", "SPI6_CE1_N" , "ARM_TMS" , "SD0_DAT3" , 0 , "DPI_D23" , "SD1_DAT3" ,
  225. "GPIO.28" , "GPIO.28", "RGMII_MDIO" , "MII_A_RX_ERR" , "SDA0" , "SA5" , "PCM_CLK" , 0 ,
  226. "GPIO.29" , "GPIO.29", "RGMII_MDC" , "MII_A_TX_ERR" , "SCL0" , "SA4" , "PCM_FS" , 0 ,
  227. "GPIO.30" , "GPIO.30", "CTS1" , "MII_A_CRS" , 0 , "SA3" , "PCM_DIN" , "CTS0" ,
  228. "GPIO.31" , "GPIO.31", "RTS1" , "MII_A_COL" , 0 , "SA2" , "PCM_DOUT" , "RTS0" ,
  229. "GPIO.32" , "GPIO.32", "TXD1" , "SD_CARD_PRES" , "GPCLK0" , "SA1" , 0 , "TXD0" ,
  230. "GPIO.33" , "GPIO.33", "RXD1" , "SD_CARD_WRPROT" , 0 , "SA0" , 0 , "RXD0" ,
  231. "GPIO.34" , "GPIO.34", "RGMII_IRQ" , "SD_CARD_LED" , "GPCLK0" , "SOE_N_SE" , 0 , "SD1_CLK" ,
  232. "GPIO.35" , "GPIO.35", 0 , "RGMII_START_STOP", "SPI0_CE1_N", "SWE_N_SRW_N", 0 , "SD1_CMD" ,
  233. "GPIO.36" , "GPIO.36", "MII_A_RX_ERR", "RGMII_RX_OK" , "SPI0_CE0_N", "SD0" , "TXD0" , "SD1_DAT0" ,
  234. "GPIO.37" , "GPIO.37", "MII_A_TX_ERR", "RGMII_MDIO" , "SPI0_MISO" , "SD1" , "RXD0" , "SD1_DAT1" ,
  235. "GPIO.38" , "GPIO.38", "MII_A_CRS" , "RGMII_MDC" , "SPI0_MOSI" , "SD2" , "RTS0" , "SD1_DAT2" ,
  236. "GPIO.39" , "GPIO.39", "MII_A_COL" , "RGMII_IRQ" , "SPI0_SCLK" , "SD3" , "CTS0" , "SD1_DAT3" ,
  237. "GPIO.40" , "GPIO.40", "TXD1" , "SPI0_MISO" , "PWM1_0" , "SD4" , 0 , "SD1_DAT4" ,
  238. "GPIO.41" , "GPIO.41", "RXD1" , "SPI0_MOSI" , "PWM1_1" , "SD5" , 0 , "SD1_DAT5" ,
  239. "GPIO.42" , "GPIO.42", "RTS1" , "SPI0_SCLK" , "GPCLK1" , "SD6" , 0 , "SD1_DAT6" ,
  240. "GPIO.43" , "GPIO.43", "CTS1" , "SPI0_CE0_N" , "GPCLK2" , "SD7" , 0 , "SD1_DAT7" ,
  241. "GPIO.44" , "GPIO.44", "SD_CARD_VOLT", "SPI0_CE1_N" , "GPCLK1" , "SDA0" , "SDA1" , 0 ,
  242. "GPIO.45" , "GPIO.45", "SD_CARD_PWR0", "SPI0_CE2_N" , "PWM0_1" , "SCL0" , "SCL1" , 0 ,
  243. "GPIO.46" , "GPIO.46", "SPI2_CE1_N" , 0 , "SDA0" , "SDA1" , "SPI0_CE0_N", 0 ,
  244. "GPIO.47" , "GPIO.47", "SPI2_CE0_N" , 0 , "SCL0" , "SCL1" , "SPI0_MISO" , 0 ,
  245. "GPIO.48" , "GPIO.48", "SPI2_SCLK" , "ARM_TRST" , "SD0_CLK" , 0 , "SPI0_MOSI" , "SD1_CLK" ,
  246. "GPIO.49" , "GPIO.49", "SPI2_MOSI" , "ARM_RTCK" , "SD0_CMD" , "GPCLK0" , "SPI0_SCLK" , "SD1_CMD" ,
  247. "GPIO.50" , "GPIO.50", "SPI2_MISO" , "ARM_TDO" , "SD0_DAT0" , "GPCLK1" , "PCM_CLK" , "SD1_DAT0" ,
  248. "GPIO.51" , "GPIO.51", "SD_CARD_LED" , "ARM_TCK" , "SD0_DAT1" , "GPCLK2" , "PCM_FS" , "SD1_DAT1" ,
  249. "GPIO.52" , "GPIO.52", 0 , "ARM_TDI" , "SD0_DAT2" , "PWM0_0" , "PCM_DIN" , "SD1_DAT2" ,
  250. "GPIO.53" , "GPIO.53", 0 , "ARM_TMS" , "SD0_DAT3" , "PWM0_1" , "PCM_DOUT" , "SD1_DAT3" ,
  251. };
  252. static const char **gpio_alt_names = gpio_alt_names_2711;
  253. /*
  254. * readallPhys:
  255. * Given a physical pin output the data on it and the next pin:
  256. *| BCM | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi | BCM |
  257. *********************************************************************************
  258. */
  259. static void readallPhys (int physPin)
  260. {
  261. int pin;
  262. // | BCM | WPi
  263. if (physPinToGpio (physPin) == -1)
  264. printf (" | | ");
  265. else
  266. printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi[physPin]);
  267. // | Name | Mode | Value
  268. if (physToWpi[physPin] == -1)
  269. {
  270. printf (" | %10s", physNames[physPin]);
  271. printf (" | | ");
  272. }
  273. else
  274. {
  275. if (wpMode == WPI_MODE_GPIO)
  276. pin = physPinToGpio (physPin);
  277. else if (wpMode == WPI_MODE_PHYS)
  278. pin = physPin;
  279. else
  280. pin = physToWpi[physPin];
  281. printf (" | %10s", gpio_alt_names[pin*8 + getAlt(pin)]);
  282. printf (" | %4s", alts[getAlt (pin)]);
  283. printf (" | %d", digitalRead (pin));
  284. }
  285. // Pin numbers:
  286. printf (" | %2d", physPin);
  287. ++physPin;
  288. printf (" || %-2d", physPin);
  289. // Same, reversed
  290. if (physToWpi[physPin] == -1)
  291. {
  292. printf (" | | ");
  293. printf (" | %-10s", physNames[physPin]);
  294. }
  295. else
  296. {
  297. if (wpMode == WPI_MODE_GPIO)
  298. pin = physPinToGpio (physPin);
  299. else if (wpMode == WPI_MODE_PHYS)
  300. pin = physPin;
  301. else
  302. pin = physToWpi[physPin];
  303. printf (" | %d", digitalRead (pin));
  304. printf (" | %4s", alts[getAlt (pin)]);
  305. printf (" | %-10s", gpio_alt_names[pin*8 + getAlt(pin)]);
  306. }
  307. if (physToWpi [physPin] == -1)
  308. printf (" | | ");
  309. else
  310. printf (" | %-3d | %-3d", physToWpi[physPin], physPinToGpio (physPin));
  311. printf (" |\n");
  312. }
  313. /*
  314. * allReadall:
  315. * Read all the pins regardless of the model. Primarily of use for
  316. * the compute module, but handy for other fiddling...
  317. *********************************************************************************
  318. */
  319. static void allReadall (void)
  320. {
  321. int pin;
  322. printf ("+------+------+-------+ +------+------+-------+\n");
  323. printf ("| BCM | | | | BCM | | |\n");
  324. printf ("| GPIO | Mode | Value | | GPIO | Mode | Value |\n");
  325. printf ("+------+------+-------+ +------+------+-------+\n");
  326. for (pin = 0; pin < 27; ++pin)
  327. {
  328. printf ("| %3d ", pin);
  329. printf ("| %-4s ", alts[getAlt (pin)]);
  330. printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ");
  331. printf ("| ");
  332. printf ("| %3d ", pin + 27);
  333. printf ("| %-4s ", alts[getAlt (pin + 27)]);
  334. printf ("| %s ", digitalRead (pin + 27) == HIGH ? "High" : "Low ");
  335. printf ("|\n");
  336. }
  337. printf ("+------+------+-------+ +------+------+-------+\n");
  338. }
  339. /*
  340. * abReadall:
  341. * Read all the pins on the model A or B.
  342. *********************************************************************************
  343. */
  344. void abReadall (int model, int rev)
  345. {
  346. int pin;
  347. char *type;
  348. if (model == PI_MODEL_A)
  349. type = " A";
  350. else
  351. if (rev == PI_VERSION_2)
  352. type = "B2";
  353. else
  354. type = "B1";
  355. printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type);
  356. printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n");
  357. printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n");
  358. for (pin = 1; pin <= 26; pin += 2)
  359. readallPhys (pin);
  360. if (rev == PI_VERSION_2) // B version 2
  361. {
  362. printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n");
  363. for (pin = 51; pin <= 54; pin += 2)
  364. readallPhys (pin);
  365. }
  366. printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n");
  367. printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n");
  368. printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type);
  369. }
  370. /*
  371. * piPlusReadall:
  372. * Read all the pins on the model A+ or the B+ or actually, all 40-pin Pi's
  373. *********************************************************************************
  374. */
  375. static void plus2header (int model)
  376. {
  377. /**/ if (model == PI_MODEL_AP)
  378. printf (" +-----+-----+---------+------+---+---Pi A+--+---+------+---------+-----+-----+\n");
  379. else if (model == PI_MODEL_BP)
  380. printf (" +-----+-----+---------+------+---+---Pi B+--+---+------+---------+-----+-----+\n");
  381. else if (model == PI_MODEL_ZERO)
  382. printf (" +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+\n");
  383. else if (model == PI_MODEL_ZERO_W)
  384. printf (" +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+\n");
  385. else if (model == PI_MODEL_ZERO_2W)
  386. printf (" +-----+-----+---------+------+---+Pi Zero 2W+---+------+---------+-----+-----+\n");
  387. else if (model == PI_MODEL_2B)
  388. printf (" +-----+-----+------------+------+---+---Pi 2---+---+------+------------+-----+-----+\n");
  389. else if (model == PI_MODEL_3B)
  390. printf (" +-----+-----+------------+------+---+---Pi 3B--+---+------+------------+-----+-----+\n");
  391. else if (model == PI_MODEL_3BP)
  392. printf (" +-----+-----+------------+------+---+---Pi 3B--+---+------+------------+-----+-----+\n");
  393. else if (model == PI_MODEL_3AP)
  394. printf (" +-----+-----+------------+------+---+---Pi 3A--+---+------+------------+-----+-----+\n");
  395. else if (model == PI_MODEL_4B)
  396. printf (" +-----+-----+------------+------+---+---Pi 4B--+---+------+------------+-----+-----+\n");
  397. else if (model == PI_MODEL_400)
  398. printf (" +-----+-----+------------+------+---+---Pi 400-+---+------+------------+-----+-----+\n");
  399. else
  400. printf (" +-----+-----+------------+------+---+---Pi ?---+---+------+------------+-----+-----+\n");
  401. }
  402. static void piPlusReadall (int model)
  403. {
  404. int pin;
  405. plus2header (model);
  406. printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n");
  407. printf (" +-----+-----+------------+------+---+----++----+---+------+------------+-----+-----+\n");
  408. for (pin = 1; pin <= 40; pin += 2)
  409. readallPhys (pin);
  410. printf (" +-----+-----+------------+------+---+----++----+---+------+------------+-----+-----+\n");
  411. printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n");
  412. plus2header (model);
  413. }
  414. /*
  415. * doReadall:
  416. * Generic read all pins called from main program. Works out the Pi type
  417. * and calls the appropriate function.
  418. *********************************************************************************
  419. */
  420. void doReadall (void)
  421. {
  422. int model, proc, rev, mem, maker, overVolted;
  423. if (wiringPiNodes != NULL) // External readall
  424. {
  425. doReadallExternal ();
  426. return;
  427. }
  428. piBoardId (&model, &proc, &rev, &mem, &maker, &overVolted);
  429. if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
  430. {
  431. gpio_alt_names = gpio_alt_names_2835;
  432. abReadall (model, rev);
  433. }
  434. else if ((model == PI_MODEL_BP) || (model == PI_MODEL_AP) ||
  435. (model == PI_MODEL_2B) ||
  436. (model == PI_MODEL_3AP) ||
  437. (model == PI_MODEL_3B) || (model == PI_MODEL_3BP) ||
  438. (model == PI_MODEL_4B) || (model == PI_MODEL_400) || (model == PI_MODEL_CM4) ||
  439. (model == PI_MODEL_ZERO) || (model == PI_MODEL_ZERO_W) || (model == PI_MODEL_ZERO_2W))
  440. {
  441. gpio_alt_names = gpio_alt_names_2711;
  442. piPlusReadall (model);
  443. }
  444. else if ((model == PI_MODEL_CM1) || (model == PI_MODEL_CM3) || (model == PI_MODEL_CM3P) )
  445. {
  446. allReadall ();
  447. }
  448. else
  449. {
  450. printf ("Oops - unable to determine board type... model: %d\n", model);
  451. }
  452. }
  453. /*
  454. * doAllReadall:
  455. * Force reading of all pins regardless of Pi model
  456. *********************************************************************************
  457. */
  458. void doAllReadall (void)
  459. {
  460. allReadall ();
  461. }
  462. /*
  463. * doQmode:
  464. * Query mode on a pin
  465. *********************************************************************************
  466. */
  467. void doQmode (int argc, char *argv[])
  468. {
  469. int pin;
  470. if (argc != 3)
  471. {
  472. fprintf (stderr, "Usage: %s qmode pin\n", argv[0]);
  473. exit (EXIT_FAILURE);
  474. }
  475. pin = atoi (argv[2]);
  476. printf ("%s\n", alts[getAlt (pin)]);
  477. }