PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

396 lines
10KB

  1. #ifndef Pins_Arduino_Compile_Time_h
  2. #define Pins_Arduino_Compile_time_h
  3. /* This is an alternative to pins_arduino.h
  4. In pins_arduino.h and .cpp the look up arrays are defined as:
  5. const uint16_t PROGMEM port_to_output_PGM[]
  6. This places the array in program memory. pgm_read_byte() functions are used to retreive the array from program memory at runtime.
  7. Because the arrays are received at runtime, it takes some instructions to look up the outputs.
  8. This is not a problem in most cases, but it is if you are trying to write super fast code.
  9. To make use of efficient sbi (Set Bit Immidiate) and cbi (Clear Bit Immidiate), the pin to write to must be defined as const.
  10. The compiler does not understand that digitalPinToPort(2) is constant and does not optimize it away.
  11. In this file I redefine the arrays as:
  12. volatile uint8_t * const port_to_output_PGM_ct[]
  13. So it is a constant pointer to a volatile uint8_t:
  14. a pointer to an output register that stays in the same place (* const), but can change in value (volatile uint8_t)
  15. These definitions are understood by the compiler and result in superfast code,
  16. but still allow you to use the arduino pin numbers instead of registers like PORTB
  17. (C) 2011-2012 Elco Jacobs. www.elcojacobs.com
  18. */
  19. #include <pins_arduino.h>
  20. #define NOT_A_PIN 0
  21. #define NOT_A_PORT 0
  22. // On the Arduino board, digital pins are also used
  23. // for the analog output (software PWM). Analog input
  24. // pins are a separate set.
  25. // ATMEL ATMEGA8 & 168 / ARDUINO
  26. //
  27. // +-\/-+
  28. // PC6 1| |28 PC5 (AI 5)
  29. // (D 0) PD0 2| |27 PC4 (AI 4)
  30. // (D 1) PD1 3| |26 PC3 (AI 3)
  31. // (D 2) PD2 4| |25 PC2 (AI 2)
  32. // PWM+ (D 3) PD3 5| |24 PC1 (AI 1)
  33. // (D 4) PD4 6| |23 PC0 (AI 0)
  34. // VCC 7| |22 GND
  35. // GND 8| |21 AREF
  36. // PB6 9| |20 AVCC
  37. // PB7 10| |19 PB5 (D 13)
  38. // PWM+ (D 5) PD5 11| |18 PB4 (D 12)
  39. // PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM
  40. // (D 7) PD7 13| |16 PB2 (D 10) PWM
  41. // (D 8) PB0 14| |15 PB1 (D 9) PWM
  42. // +----+
  43. //
  44. // (PWM+ indicates the additional PWM pins on the ATmega168.)
  45. // ATMEL ATMEGA1280 / ARDUINO
  46. //
  47. // 0-7 PE0-PE7 works
  48. // 8-13 PB0-PB5 works
  49. // 14-21 PA0-PA7 works
  50. // 22-29 PH0-PH7 works
  51. // 30-35 PG5-PG0 works
  52. // 36-43 PC7-PC0 works
  53. // 44-51 PJ7-PJ0 works
  54. // 52-59 PL7-PL0 works
  55. // 60-67 PD7-PD0 works
  56. // A0-A7 PF0-PF7
  57. // A8-A15 PK0-PK7
  58. #define PA 1
  59. #define PB 2
  60. #define PC 3
  61. #define PD 4
  62. #define PE 5
  63. #define PF 6
  64. #define PG 7
  65. #define PH 8
  66. #define PJ 10
  67. #define PK 11
  68. #define PL 12
  69. #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  70. volatile uint8_t * const port_to_output_PGM_ct[] = {
  71. NOT_A_PORT,
  72. &PORTA,
  73. &PORTB,
  74. &PORTC,
  75. &PORTD,
  76. &PORTE,
  77. &PORTF,
  78. &PORTG,
  79. &PORTH,
  80. NOT_A_PORT,
  81. &PORTJ,
  82. &PORTK,
  83. &PORTL,
  84. };
  85. const uint8_t digital_pin_to_port_PGM_ct[] = {
  86. // PORTLIST
  87. // -------------------------------------------
  88. PE , // PE 0 ** 0 ** USART0_RX
  89. PE , // PE 1 ** 1 ** USART0_TX
  90. PE , // PE 4 ** 2 ** PWM2
  91. PE , // PE 5 ** 3 ** PWM3
  92. PG , // PG 5 ** 4 ** PWM4
  93. PE , // PE 3 ** 5 ** PWM5
  94. PH , // PH 3 ** 6 ** PWM6
  95. PH , // PH 4 ** 7 ** PWM7
  96. PH , // PH 5 ** 8 ** PWM8
  97. PH , // PH 6 ** 9 ** PWM9
  98. PB , // PB 4 ** 10 ** PWM10
  99. PB , // PB 5 ** 11 ** PWM11
  100. PB , // PB 6 ** 12 ** PWM12
  101. PB , // PB 7 ** 13 ** PWM13
  102. PJ , // PJ 1 ** 14 ** USART3_TX
  103. PJ , // PJ 0 ** 15 ** USART3_RX
  104. PH , // PH 1 ** 16 ** USART2_TX
  105. PH , // PH 0 ** 17 ** USART2_RX
  106. PD , // PD 3 ** 18 ** USART1_TX
  107. PD , // PD 2 ** 19 ** USART1_RX
  108. PD , // PD 1 ** 20 ** I2C_SDA
  109. PD , // PD 0 ** 21 ** I2C_SCL
  110. PA , // PA 0 ** 22 ** D22
  111. PA , // PA 1 ** 23 ** D23
  112. PA , // PA 2 ** 24 ** D24
  113. PA , // PA 3 ** 25 ** D25
  114. PA , // PA 4 ** 26 ** D26
  115. PA , // PA 5 ** 27 ** D27
  116. PA , // PA 6 ** 28 ** D28
  117. PA , // PA 7 ** 29 ** D29
  118. PC , // PC 7 ** 30 ** D30
  119. PC , // PC 6 ** 31 ** D31
  120. PC , // PC 5 ** 32 ** D32
  121. PC , // PC 4 ** 33 ** D33
  122. PC , // PC 3 ** 34 ** D34
  123. PC , // PC 2 ** 35 ** D35
  124. PC , // PC 1 ** 36 ** D36
  125. PC , // PC 0 ** 37 ** D37
  126. PD , // PD 7 ** 38 ** D38
  127. PG , // PG 2 ** 39 ** D39
  128. PG , // PG 1 ** 40 ** D40
  129. PG , // PG 0 ** 41 ** D41
  130. PL , // PL 7 ** 42 ** D42
  131. PL , // PL 6 ** 43 ** D43
  132. PL , // PL 5 ** 44 ** D44
  133. PL , // PL 4 ** 45 ** D45
  134. PL , // PL 3 ** 46 ** D46
  135. PL , // PL 2 ** 47 ** D47
  136. PL , // PL 1 ** 48 ** D48
  137. PL , // PL 0 ** 49 ** D49
  138. PB , // PB 3 ** 50 ** SPI_MISO
  139. PB , // PB 2 ** 51 ** SPI_MOSI
  140. PB , // PB 1 ** 52 ** SPI_SCK
  141. PB , // PB 0 ** 53 ** SPI_SS
  142. PF , // PF 0 ** 54 ** A0
  143. PF , // PF 1 ** 55 ** A1
  144. PF , // PF 2 ** 56 ** A2
  145. PF , // PF 3 ** 57 ** A3
  146. PF , // PF 4 ** 58 ** A4
  147. PF , // PF 5 ** 59 ** A5
  148. PF , // PF 6 ** 60 ** A6
  149. PF , // PF 7 ** 61 ** A7
  150. PK , // PK 0 ** 62 ** A8
  151. PK , // PK 1 ** 63 ** A9
  152. PK , // PK 2 ** 64 ** A10
  153. PK , // PK 3 ** 65 ** A11
  154. PK , // PK 4 ** 66 ** A12
  155. PK , // PK 5 ** 67 ** A13
  156. PK , // PK 6 ** 68 ** A14
  157. PK , // PK 7 ** 69 ** A15
  158. };
  159. const uint8_t digital_pin_to_bit_PGM_ct[] = {
  160. // PIN IN PORT
  161. // -------------------------------------------
  162. 0 , // PE 0 ** 0 ** USART0_RX
  163. 1 , // PE 1 ** 1 ** USART0_TX
  164. 4 , // PE 4 ** 2 ** PWM2
  165. 5 , // PE 5 ** 3 ** PWM3
  166. 5 , // PG 5 ** 4 ** PWM4
  167. 3 , // PE 3 ** 5 ** PWM5
  168. 3 , // PH 3 ** 6 ** PWM6
  169. 4 , // PH 4 ** 7 ** PWM7
  170. 5 , // PH 5 ** 8 ** PWM8
  171. 6 , // PH 6 ** 9 ** PWM9
  172. 4 , // PB 4 ** 10 ** PWM10
  173. 5 , // PB 5 ** 11 ** PWM11
  174. 6 , // PB 6 ** 12 ** PWM12
  175. 7 , // PB 7 ** 13 ** PWM13
  176. 1 , // PJ 1 ** 14 ** USART3_TX
  177. 0 , // PJ 0 ** 15 ** USART3_RX
  178. 1 , // PH 1 ** 16 ** USART2_TX
  179. 0 , // PH 0 ** 17 ** USART2_RX
  180. 3 , // PD 3 ** 18 ** USART1_TX
  181. 2 , // PD 2 ** 19 ** USART1_RX
  182. 1 , // PD 1 ** 20 ** I2C_SDA
  183. 0 , // PD 0 ** 21 ** I2C_SCL
  184. 0 , // PA 0 ** 22 ** D22
  185. 1 , // PA 1 ** 23 ** D23
  186. 2 , // PA 2 ** 24 ** D24
  187. 3 , // PA 3 ** 25 ** D25
  188. 4 , // PA 4 ** 26 ** D26
  189. 5 , // PA 5 ** 27 ** D27
  190. 6 , // PA 6 ** 28 ** D28
  191. 7 , // PA 7 ** 29 ** D29
  192. 7 , // PC 7 ** 30 ** D30
  193. 6 , // PC 6 ** 31 ** D31
  194. 5 , // PC 5 ** 32 ** D32
  195. 4 , // PC 4 ** 33 ** D33
  196. 3 , // PC 3 ** 34 ** D34
  197. 2 , // PC 2 ** 35 ** D35
  198. 1 , // PC 1 ** 36 ** D36
  199. 0 , // PC 0 ** 37 ** D37
  200. 7 , // PD 7 ** 38 ** D38
  201. 2 , // PG 2 ** 39 ** D39
  202. 1 , // PG 1 ** 40 ** D40
  203. 0 , // PG 0 ** 41 ** D41
  204. 7 , // PL 7 ** 42 ** D42
  205. 6 , // PL 6 ** 43 ** D43
  206. 5 , // PL 5 ** 44 ** D44
  207. 4 , // PL 4 ** 45 ** D45
  208. 3 , // PL 3 ** 46 ** D46
  209. 2 , // PL 2 ** 47 ** D47
  210. 1 , // PL 1 ** 48 ** D48
  211. 0 , // PL 0 ** 49 ** D49
  212. 3 , // PB 3 ** 50 ** SPI_MISO
  213. 2 , // PB 2 ** 51 ** SPI_MOSI
  214. 1 , // PB 1 ** 52 ** SPI_SCK
  215. 0 , // PB 0 ** 53 ** SPI_SS
  216. 0 , // PF 0 ** 54 ** A0
  217. 1 , // PF 1 ** 55 ** A1
  218. 2 , // PF 2 ** 56 ** A2
  219. 3 , // PF 3 ** 57 ** A3
  220. 4 , // PF 4 ** 58 ** A4
  221. 5 , // PF 5 ** 59 ** A5
  222. 6 , // PF 6 ** 60 ** A6
  223. 7 , // PF 7 ** 61 ** A7
  224. 0 , // PK 0 ** 62 ** A8
  225. 1 , // PK 1 ** 63 ** A9
  226. 2 , // PK 2 ** 64 ** A10
  227. 3 , // PK 3 ** 65 ** A11
  228. 4 , // PK 4 ** 66 ** A12
  229. 5 , // PK 5 ** 67 ** A13
  230. 6 , // PK 6 ** 68 ** A14
  231. 7 , // PK 7 ** 69 ** A15
  232. };
  233. #elif defined(__AVR_ATmega32U4__)
  234. #if defined(CORE_TEENSY)
  235. volatile uint8_t * const port_to_output_PGM_ct[] = {
  236. NOT_A_PORT, NOT_A_PORT, &PORTB, &PORTC, &PORTD, &PORTE, &PORTF
  237. };
  238. const uint8_t digital_pin_to_port_PGM_ct[] = {
  239. PB, PB, PB, PB, PB, PD, PD, PD, PD, PC, PC,
  240. PD, PD, PB, PB, PB, PF, PF, PF, PF, PF, PF,
  241. PD, PD, PE
  242. };
  243. const uint8_t digital_pin_to_bit_PGM_ct[] = {
  244. 0, 1, 2, 3, 7, 0, 1, 2, 3, 6, 7,
  245. 6, 7, 4, 5, 6, 7, 6, 5, 4, 1, 0,
  246. 4, 5, 6
  247. };
  248. #else
  249. //Assumes Arduino Leonardo
  250. volatile uint8_t * const port_to_output_PGM_ct[] = {
  251. NOT_A_PORT, NOT_A_PORT, &PORTB, &PORTC, &PORTD, &PORTE, &PORTF
  252. };
  253. const uint8_t digital_pin_to_port_PGM_ct[] = {
  254. PD, PD, PD, PD, PD, PC, PD, PE, PB, PB, PB,
  255. PB, PD, PC, PB, PB, PB, PB, PF, PF, PF, PF,
  256. PF, PF, PD, PD, PB, PB, PB, PD
  257. };
  258. const uint8_t digital_pin_to_bit_PGM_ct[] = {
  259. 2, 3, 1, 0, 4, 6, 7, 6, 4, 5, 6,
  260. 7, 6, 7, 3, 1, 2, 0, 7, 6, 5, 4,
  261. 1, 0, 4, 7, 4, 5, 6, 6
  262. };
  263. #endif
  264. #elif defined(__AVR_AT90USB1286__)
  265. volatile uint8_t * const port_to_output_PGM_ct[] = {
  266. NOT_A_PORT, &PORTA, &PORTB, &PORTC, &PORTD, &PORTE, &PORTF
  267. };
  268. const uint8_t digital_pin_to_port_PGM_ct[] = {
  269. PD, PD, PD, PD, PD, PD, PD, PD, PE, PE,
  270. PC, PC, PC, PC, PC, PC, PC, PC, PE, PE,
  271. PB, PB, PB, PB, PB, PB, PB, PB, PA, PA,
  272. PA, PA, PA, PA, PA, PA, PE, PE, PF, PF,
  273. PF, PF, PF, PF, PF, PF
  274. };
  275. const uint8_t digital_pin_to_bit_PGM_ct[] = {
  276. 0, 1, 2, 3, 4, 5, 6, 7, 0, 1,
  277. 0, 1, 2, 3, 4, 5, 6, 7, 6, 7,
  278. 0, 1, 2, 3, 4, 5, 6, 7, 0, 1,
  279. 2, 3, 4, 5, 6, 7, 4, 5, 0, 1,
  280. 2, 3, 4, 5, 6, 7
  281. };
  282. #elif defined(__arm__) && defined(CORE_TEENSY)
  283. // for Teensy 3.x and Teensy LC
  284. #ifndef SHIFTPWM_NOSPI
  285. #error "On Teensy 3.x & LC, you must define SHIFTPWM_NOSPI, ShiftPWM_dataPin, ShiftPWM_clockPin"
  286. #endif
  287. #define SHIFTPWM_USE_DIGITALWRITEFAST
  288. volatile uint8_t * const port_to_output_PGM_ct[] = {
  289. NULL
  290. };
  291. const uint8_t digital_pin_to_port_PGM_ct[] = {
  292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  295. 0, 0, 0, 0
  296. };
  297. const uint8_t digital_pin_to_bit_PGM_ct[] = {
  298. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  299. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  300. 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  301. 30, 31, 32, 33
  302. };
  303. #else
  304. // these arrays map port names (e.g. port B) to the
  305. // appropriate addresses for various functions (e.g. reading
  306. // and writing)
  307. volatile uint8_t * const port_to_output_PGM_ct[] = {
  308. NOT_A_PORT,
  309. NOT_A_PORT,
  310. &PORTB,
  311. &PORTC,
  312. &PORTD,
  313. };
  314. const uint8_t digital_pin_to_port_PGM_ct[] = {
  315. PD, // 0
  316. PD,
  317. PD,
  318. PD,
  319. PD,
  320. PD,
  321. PD,
  322. PD,
  323. PB, // 8
  324. PB,
  325. PB,
  326. PB,
  327. PB,
  328. PB,
  329. PC, // 14
  330. PC,
  331. PC,
  332. PC,
  333. PC,
  334. PC,
  335. };
  336. const uint8_t digital_pin_to_bit_PGM_ct[] = {
  337. 0, // 0, port D
  338. 1,
  339. 2,
  340. 3,
  341. 4,
  342. 5,
  343. 6,
  344. 7,
  345. 0, // 8, port B
  346. 1,
  347. 2,
  348. 3,
  349. 4,
  350. 5,
  351. 0, // 14, port C /
  352. 1,
  353. 2,
  354. 3,
  355. 4,
  356. 5,
  357. };
  358. #endif
  359. #endif