hardware-mapping.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
  2. * Copyright (C) 2013, 2016 Henner Zeller <h.zeller@acm.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http: *gnu.org/licenses/gpl-2.0.txt>
  15. */
  16. /*
  17. * We do this in plain C so that we can use designated initializers.
  18. */
  19. #include "hardware-mapping.h"
  20. #define GPIO_BIT(b) ((uint64_t)1<<(b))
  21. struct HardwareMapping matrix_hardware_mappings[] = {
  22. /*
  23. * The regular hardware mapping described in the wiring.md and used
  24. * by the adapter PCBs.
  25. */
  26. {
  27. .name = "regular",
  28. .output_enable = GPIO_BIT(18),
  29. .clock = GPIO_BIT(17),
  30. .strobe = GPIO_BIT(4),
  31. /* Address lines */
  32. .a = GPIO_BIT(22),
  33. .b = GPIO_BIT(23),
  34. .c = GPIO_BIT(24),
  35. .d = GPIO_BIT(25),
  36. .e = GPIO_BIT(15), /* RxD kept free unless 1:64 */
  37. /* Parallel chain 0, RGB for both sub-panels */
  38. .p0_r1 = GPIO_BIT(11), /* masks: SPI0_SCKL */
  39. .p0_g1 = GPIO_BIT(27), /* Not on RPi1, Rev1; use "regular-pi1" instead */
  40. .p0_b1 = GPIO_BIT(7), /* masks: SPI0_CE1 */
  41. .p0_r2 = GPIO_BIT(8), /* masks: SPI0_CE0 */
  42. .p0_g2 = GPIO_BIT(9), /* masks: SPI0_MISO */
  43. .p0_b2 = GPIO_BIT(10), /* masks: SPI0_MOSI */
  44. /* All the following are only available with 40 GPIP pins, on A+/B+/Pi2,3 */
  45. /* Chain 1 */
  46. .p1_r1 = GPIO_BIT(12),
  47. .p1_g1 = GPIO_BIT(5),
  48. .p1_b1 = GPIO_BIT(6),
  49. .p1_r2 = GPIO_BIT(19),
  50. .p1_g2 = GPIO_BIT(13),
  51. .p1_b2 = GPIO_BIT(20),
  52. /* Chain 2 */
  53. .p2_r1 = GPIO_BIT(14), /* masks TxD when parallel=3 */
  54. .p2_g1 = GPIO_BIT(2), /* masks SCL when parallel=3 */
  55. .p2_b1 = GPIO_BIT(3), /* masks SDA when parallel=3 */
  56. .p2_r2 = GPIO_BIT(26),
  57. .p2_g2 = GPIO_BIT(16),
  58. .p2_b2 = GPIO_BIT(21),
  59. },
  60. /*
  61. * This is used if you have an Adafruit HAT in the default configuration
  62. */
  63. {
  64. .name = "adafruit-hat",
  65. .output_enable = GPIO_BIT(4),
  66. .clock = GPIO_BIT(17),
  67. .strobe = GPIO_BIT(21),
  68. .a = GPIO_BIT(22),
  69. .b = GPIO_BIT(26),
  70. .c = GPIO_BIT(27),
  71. .d = GPIO_BIT(20),
  72. .e = GPIO_BIT(24), /* Needs manual wiring, see README.md */
  73. .p0_r1 = GPIO_BIT(5),
  74. .p0_g1 = GPIO_BIT(13),
  75. .p0_b1 = GPIO_BIT(6),
  76. .p0_r2 = GPIO_BIT(12),
  77. .p0_g2 = GPIO_BIT(16),
  78. .p0_b2 = GPIO_BIT(23),
  79. },
  80. /*
  81. * An Adafruit HAT with the PWM modification
  82. */
  83. {
  84. .name = "adafruit-hat-pwm",
  85. .output_enable = GPIO_BIT(18), /* The only change compared to above */
  86. .clock = GPIO_BIT(17),
  87. .strobe = GPIO_BIT(21),
  88. .a = GPIO_BIT(22),
  89. .b = GPIO_BIT(26),
  90. .c = GPIO_BIT(27),
  91. .d = GPIO_BIT(20),
  92. .e = GPIO_BIT(24),
  93. .p0_r1 = GPIO_BIT(5),
  94. .p0_g1 = GPIO_BIT(13),
  95. .p0_b1 = GPIO_BIT(6),
  96. .p0_r2 = GPIO_BIT(12),
  97. .p0_g2 = GPIO_BIT(16),
  98. .p0_b2 = GPIO_BIT(23),
  99. },
  100. /*
  101. * The regular pin-out, but for Raspberry Pi1. The very first Pi1 Rev1 uses
  102. * the same pin for GPIO-21 as later Pis use GPIO-27. Make it work for both.
  103. */
  104. {
  105. .name = "regular-pi1",
  106. .output_enable = GPIO_BIT(18),
  107. .clock = GPIO_BIT(17),
  108. .strobe = GPIO_BIT(4),
  109. /* Address lines */
  110. .a = GPIO_BIT(22),
  111. .b = GPIO_BIT(23),
  112. .c = GPIO_BIT(24),
  113. .d = GPIO_BIT(25),
  114. .e = GPIO_BIT(15), /* RxD kept free unless 1:64 */
  115. /* Parallel chain 0, RGB for both sub-panels */
  116. .p0_r1 = GPIO_BIT(11), /* masks: SPI0_SCKL */
  117. /* On Pi1 Rev1, the pin other Pis have GPIO27, these have GPIO21. So make
  118. * this work for both Rev1 and Rev2.
  119. */
  120. .p0_g1 = GPIO_BIT(21) | GPIO_BIT(27),
  121. .p0_b1 = GPIO_BIT(7), /* masks: SPI0_CE1 */
  122. .p0_r2 = GPIO_BIT(8), /* masks: SPI0_CE0 */
  123. .p0_g2 = GPIO_BIT(9), /* masks: SPI0_MISO */
  124. .p0_b2 = GPIO_BIT(10), /* masks: SPI0_MOSI */
  125. /* No more chains - there are not enough GPIO */
  126. },
  127. /*
  128. * Classic: Early forms of this library had this as default mapping, mostly
  129. * derived from the 26 GPIO-header version so that it also can work
  130. * on 40 Pin GPIO headers with more parallel chains.
  131. * Not used anymore.
  132. */
  133. {
  134. .name = "classic",
  135. .output_enable = GPIO_BIT(27), /* Not available on RPi1, Rev 1 */
  136. .clock = GPIO_BIT(11),
  137. .strobe = GPIO_BIT(4),
  138. .a = GPIO_BIT(7),
  139. .b = GPIO_BIT(8),
  140. .c = GPIO_BIT(9),
  141. .d = GPIO_BIT(10),
  142. .p0_r1 = GPIO_BIT(17),
  143. .p0_g1 = GPIO_BIT(18),
  144. .p0_b1 = GPIO_BIT(22),
  145. .p0_r2 = GPIO_BIT(23),
  146. .p0_g2 = GPIO_BIT(24),
  147. .p0_b2 = GPIO_BIT(25),
  148. .p1_r1 = GPIO_BIT(12),
  149. .p1_g1 = GPIO_BIT(5),
  150. .p1_b1 = GPIO_BIT(6),
  151. .p1_r2 = GPIO_BIT(19),
  152. .p1_g2 = GPIO_BIT(13),
  153. .p1_b2 = GPIO_BIT(20),
  154. .p2_r1 = GPIO_BIT(14), /* masks TxD if parallel = 3 */
  155. .p2_g1 = GPIO_BIT(2), /* masks SDA if parallel = 3 */
  156. .p2_b1 = GPIO_BIT(3), /* masks SCL if parallel = 3 */
  157. .p2_r2 = GPIO_BIT(15),
  158. .p2_g2 = GPIO_BIT(26),
  159. .p2_b2 = GPIO_BIT(21),
  160. },
  161. /*
  162. * Classic pin-out for Rev-A Raspberry Pi.
  163. */
  164. {
  165. .name = "classic-pi1",
  166. /* The Revision-1 and Revision-2 boards have different GPIO mappings
  167. * on the P1-3 and P1-5. So we use both interpretations.
  168. * To keep the I2C pins free, we avoid these in later mappings.
  169. */
  170. .output_enable = GPIO_BIT(0) | GPIO_BIT(2),
  171. .clock = GPIO_BIT(1) | GPIO_BIT(3),
  172. .strobe = GPIO_BIT(4),
  173. .a = GPIO_BIT(7),
  174. .b = GPIO_BIT(8),
  175. .c = GPIO_BIT(9),
  176. .d = GPIO_BIT(10),
  177. .p0_r1 = GPIO_BIT(17),
  178. .p0_g1 = GPIO_BIT(18),
  179. .p0_b1 = GPIO_BIT(22),
  180. .p0_r2 = GPIO_BIT(23),
  181. .p0_g2 = GPIO_BIT(24),
  182. .p0_b2 = GPIO_BIT(25),
  183. },
  184. #ifdef ENABLE_WIDE_GPIO_COMPUTE_MODULE
  185. /*
  186. * Custom pin-out for compute-module
  187. */
  188. {
  189. .name = "compute-module",
  190. /* This GPIO mapping is made for the official I/O development
  191. * board. No pin is left free when using 6 parallel chains.
  192. */
  193. .output_enable = GPIO_BIT(18),
  194. .clock = GPIO_BIT(16),
  195. .strobe = GPIO_BIT(17),
  196. .a = GPIO_BIT(2),
  197. .b = GPIO_BIT(3),
  198. .c = GPIO_BIT(4),
  199. .d = GPIO_BIT(5),
  200. .e = GPIO_BIT(6), /* RxD kept free unless 1:64 */
  201. /* Chain 0 */
  202. .p0_r1 = GPIO_BIT(7),
  203. .p0_g1 = GPIO_BIT(8),
  204. .p0_b1 = GPIO_BIT(9),
  205. .p0_r2 = GPIO_BIT(10),
  206. .p0_g2 = GPIO_BIT(11),
  207. .p0_b2 = GPIO_BIT(12),
  208. /* Chain 1 */
  209. .p1_r1 = GPIO_BIT(13),
  210. .p1_g1 = GPIO_BIT(14),
  211. .p1_b1 = GPIO_BIT(15),
  212. .p1_r2 = GPIO_BIT(19),
  213. .p1_g2 = GPIO_BIT(20),
  214. .p1_b2 = GPIO_BIT(21),
  215. /* Chain 2 */
  216. .p2_r1 = GPIO_BIT(22),
  217. .p2_g1 = GPIO_BIT(23),
  218. .p2_b1 = GPIO_BIT(24),
  219. .p2_r2 = GPIO_BIT(25),
  220. .p2_g2 = GPIO_BIT(26),
  221. .p2_b2 = GPIO_BIT(27),
  222. /* Chain 3 */
  223. .p3_r1 = GPIO_BIT(28),
  224. .p3_g1 = GPIO_BIT(29),
  225. .p3_b1 = GPIO_BIT(30),
  226. .p3_r2 = GPIO_BIT(31),
  227. .p3_g2 = GPIO_BIT(32),
  228. .p3_b2 = GPIO_BIT(33),
  229. /* Chain 4 */
  230. .p4_r1 = GPIO_BIT(34),
  231. .p4_g1 = GPIO_BIT(35),
  232. .p4_b1 = GPIO_BIT(36),
  233. .p4_r2 = GPIO_BIT(37),
  234. .p4_g2 = GPIO_BIT(38),
  235. .p4_b2 = GPIO_BIT(39),
  236. /* Chain 5 */
  237. .p5_r1 = GPIO_BIT(40),
  238. .p5_g1 = GPIO_BIT(41),
  239. .p5_b1 = GPIO_BIT(42),
  240. .p5_r2 = GPIO_BIT(43),
  241. .p5_g2 = GPIO_BIT(44),
  242. .p5_b2 = GPIO_BIT(45),
  243. },
  244. #endif
  245. {0}
  246. };