My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

pinmapping.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef _PINMAPPING_H_
  23. #define _PINMAPPING_H_
  24. #include "../../../inc/MarlinConfigPre.h"
  25. #include <stdint.h>
  26. typedef int16_t pin_t;
  27. #define PORT_0 000
  28. #define PORT_1 001
  29. #define PORT_2 010
  30. #define PORT_3 011
  31. #define PORT_4 100
  32. #define PORT_(p) PORT_##p
  33. #define PORT(p) PORT_(p)
  34. #define PIN_0 00000
  35. #define PIN_1 00001
  36. #define PIN_2 00010
  37. #define PIN_3 00011
  38. #define PIN_4 00100
  39. #define PIN_5 00101
  40. #define PIN_6 00110
  41. #define PIN_7 00111
  42. #define PIN_8 01000
  43. #define PIN_9 01001
  44. #define PIN_10 01010
  45. #define PIN_11 01011
  46. #define PIN_12 01100
  47. #define PIN_13 01101
  48. #define PIN_14 01110
  49. #define PIN_15 01111
  50. #define PIN_16 10000
  51. #define PIN_17 10001
  52. #define PIN_18 10010
  53. #define PIN_19 10011
  54. #define PIN_20 10100
  55. #define PIN_21 10101
  56. #define PIN_22 10110
  57. #define PIN_23 10111
  58. #define PIN_24 11000
  59. #define PIN_25 11001
  60. #define PIN_26 11010
  61. #define PIN_27 11011
  62. #define PIN_28 11100
  63. #define PIN_29 11101
  64. #define PIN_30 11110
  65. #define PIN_31 11111
  66. #define PIN_(p) PIN_##p
  67. #define PIN(p) PIN_(p)
  68. #define ADC_NONE 0000
  69. #define ADC_CHAN_0 0001
  70. #define ADC_CHAN_1 0010
  71. #define ADC_CHAN_2 0011
  72. #define ADC_CHAN_3 0100
  73. #define ADC_CHAN_4 0101
  74. #define ADC_CHAN_5 0110
  75. #define ADC_CHAN_6 0111
  76. #define ADC_CHAN_7 1000
  77. #define ADC_CHAN_(c) ADC_CHAN_##c
  78. #define ADC_CHAN(p) ADC_CHAN_(p)
  79. #define BOOL_0 0
  80. #define BOOL_1 1
  81. #define BOOL_(b) BOOL_##b
  82. #define INTERRUPT(b) BOOL_(b)
  83. #define PWM(b) BOOL_(b)
  84. // Combine elements into pin bits: 0b00AAAAWIPPPNNNNN
  85. #define LPC1768_PIN_(port, pin, int, pwm, adc) 0b00##adc##pwm##int##port##pin
  86. #define LPC1768_PIN(port, pin, int, pwm, adc) LPC1768_PIN_(port, pin, int, pwm, adc)
  87. constexpr uint8_t LPC1768_PIN_PORT(const pin_t pin) { return ((uint8_t)((pin >> 5) & 0b111)); }
  88. constexpr uint8_t LPC1768_PIN_PIN(const pin_t pin) { return ((uint8_t)(pin & 0b11111)); }
  89. constexpr bool LPC1768_PIN_INTERRUPT(const pin_t pin) { return (((pin >> 8) & 0b1) != 0); }
  90. constexpr bool LPC1768_PIN_PWM(const pin_t pin) { return (((pin >> 9) & 0b1) != 0); }
  91. constexpr int8_t LPC1768_PIN_ADC(const pin_t pin) { return (int8_t)((pin >> 10) & 0b1111) - 1; }
  92. // ******************
  93. // Runtime pinmapping
  94. // ******************
  95. #define P_NC -1
  96. #if SERIAL_PORT != 3 && SERIAL_PORT_2 != 3
  97. #define P0_00 LPC1768_PIN(PORT(0), PIN( 0), INTERRUPT(1), PWM(0), ADC_NONE)
  98. #define P0_01 LPC1768_PIN(PORT(0), PIN( 1), INTERRUPT(1), PWM(0), ADC_NONE)
  99. #endif
  100. #if SERIAL_PORT != 0 && SERIAL_PORT_2 != 0
  101. #define P0_02 LPC1768_PIN(PORT(0), PIN( 2), INTERRUPT(1), PWM(0), ADC_CHAN(7))
  102. #define P0_03 LPC1768_PIN(PORT(0), PIN( 3), INTERRUPT(1), PWM(0), ADC_CHAN(6))
  103. #endif
  104. #define P0_04 LPC1768_PIN(PORT(0), PIN( 4), INTERRUPT(1), PWM(0), ADC_NONE)
  105. #define P0_05 LPC1768_PIN(PORT(0), PIN( 5), INTERRUPT(1), PWM(0), ADC_NONE)
  106. #define P0_06 LPC1768_PIN(PORT(0), PIN( 6), INTERRUPT(1), PWM(0), ADC_NONE)
  107. #define P0_07 LPC1768_PIN(PORT(0), PIN( 7), INTERRUPT(1), PWM(0), ADC_NONE)
  108. #define P0_08 LPC1768_PIN(PORT(0), PIN( 8), INTERRUPT(1), PWM(0), ADC_NONE)
  109. #define P0_09 LPC1768_PIN(PORT(0), PIN( 9), INTERRUPT(1), PWM(0), ADC_NONE)
  110. #if SERIAL_PORT != 2 && SERIAL_PORT_2 != 2
  111. #define P0_10 LPC1768_PIN(PORT(0), PIN(10), INTERRUPT(1), PWM(0), ADC_NONE)
  112. #define P0_11 LPC1768_PIN(PORT(0), PIN(11), INTERRUPT(1), PWM(0), ADC_NONE)
  113. #endif
  114. #if SERIAL_PORT != 1 && SERIAL_PORT_2 != 1
  115. #define P0_15 LPC1768_PIN(PORT(0), PIN(15), INTERRUPT(1), PWM(0), ADC_NONE)
  116. #define P0_16 LPC1768_PIN(PORT(0), PIN(16), INTERRUPT(1), PWM(0), ADC_NONE)
  117. #endif
  118. #define P0_17 LPC1768_PIN(PORT(0), PIN(17), INTERRUPT(1), PWM(0), ADC_NONE)
  119. #define P0_18 LPC1768_PIN(PORT(0), PIN(18), INTERRUPT(1), PWM(0), ADC_NONE)
  120. #define P0_19 LPC1768_PIN(PORT(0), PIN(19), INTERRUPT(1), PWM(0), ADC_NONE)
  121. #define P0_20 LPC1768_PIN(PORT(0), PIN(20), INTERRUPT(1), PWM(0), ADC_NONE)
  122. #define P0_21 LPC1768_PIN(PORT(0), PIN(21), INTERRUPT(1), PWM(0), ADC_NONE)
  123. #define P0_22 LPC1768_PIN(PORT(0), PIN(22), INTERRUPT(1), PWM(0), ADC_NONE)
  124. #define P0_23 LPC1768_PIN(PORT(0), PIN(23), INTERRUPT(1), PWM(0), ADC_CHAN(0))
  125. #define P0_24 LPC1768_PIN(PORT(0), PIN(24), INTERRUPT(1), PWM(0), ADC_CHAN(1))
  126. #define P0_25 LPC1768_PIN(PORT(0), PIN(25), INTERRUPT(1), PWM(0), ADC_CHAN(2))
  127. #define P0_26 LPC1768_PIN(PORT(0), PIN(26), INTERRUPT(1), PWM(0), ADC_CHAN(3))
  128. #define P0_27 LPC1768_PIN(PORT(0), PIN(27), INTERRUPT(1), PWM(0), ADC_NONE)
  129. #define P0_28 LPC1768_PIN(PORT(0), PIN(28), INTERRUPT(1), PWM(0), ADC_NONE)
  130. #if SERIAL_PORT != -1 && SERIAL_PORT_2 != -1
  131. #define P0_29 LPC1768_PIN(PORT(0), PIN(29), INTERRUPT(1), PWM(0), ADC_NONE)
  132. #define P0_30 LPC1768_PIN(PORT(0), PIN(30), INTERRUPT(1), PWM(0), ADC_NONE)
  133. #endif
  134. #define P1_00 LPC1768_PIN(PORT(1), PIN( 0), INTERRUPT(0), PWM(0), ADC_NONE)
  135. #define P1_01 LPC1768_PIN(PORT(1), PIN( 1), INTERRUPT(0), PWM(0), ADC_NONE)
  136. #define P1_04 LPC1768_PIN(PORT(1), PIN( 4), INTERRUPT(0), PWM(0), ADC_NONE)
  137. #define P1_08 LPC1768_PIN(PORT(1), PIN( 8), INTERRUPT(0), PWM(0), ADC_NONE)
  138. #define P1_09 LPC1768_PIN(PORT(1), PIN( 9), INTERRUPT(0), PWM(0), ADC_NONE)
  139. #define P1_10 LPC1768_PIN(PORT(1), PIN(10), INTERRUPT(0), PWM(0), ADC_NONE)
  140. #define P1_14 LPC1768_PIN(PORT(1), PIN(14), INTERRUPT(0), PWM(0), ADC_NONE)
  141. #define P1_15 LPC1768_PIN(PORT(1), PIN(15), INTERRUPT(0), PWM(0), ADC_NONE)
  142. #define P1_16 LPC1768_PIN(PORT(1), PIN(16), INTERRUPT(0), PWM(0), ADC_NONE)
  143. #define P1_17 LPC1768_PIN(PORT(1), PIN(17), INTERRUPT(0), PWM(0), ADC_NONE)
  144. #define P1_18 LPC1768_PIN(PORT(1), PIN(18), INTERRUPT(0), PWM(1), ADC_NONE)
  145. #define P1_19 LPC1768_PIN(PORT(1), PIN(19), INTERRUPT(0), PWM(0), ADC_NONE)
  146. #define P1_20 LPC1768_PIN(PORT(1), PIN(20), INTERRUPT(0), PWM(1), ADC_NONE)
  147. #define P1_21 LPC1768_PIN(PORT(1), PIN(21), INTERRUPT(0), PWM(1), ADC_NONE)
  148. #define P1_22 LPC1768_PIN(PORT(1), PIN(22), INTERRUPT(0), PWM(0), ADC_NONE)
  149. #define P1_23 LPC1768_PIN(PORT(1), PIN(23), INTERRUPT(0), PWM(1), ADC_NONE)
  150. #define P1_24 LPC1768_PIN(PORT(1), PIN(24), INTERRUPT(0), PWM(1), ADC_NONE)
  151. #define P1_25 LPC1768_PIN(PORT(1), PIN(25), INTERRUPT(0), PWM(0), ADC_NONE)
  152. #define P1_26 LPC1768_PIN(PORT(1), PIN(26), INTERRUPT(0), PWM(1), ADC_NONE)
  153. #define P1_27 LPC1768_PIN(PORT(1), PIN(27), INTERRUPT(0), PWM(0), ADC_NONE)
  154. #define P1_28 LPC1768_PIN(PORT(1), PIN(28), INTERRUPT(0), PWM(0), ADC_NONE)
  155. #define P1_29 LPC1768_PIN(PORT(1), PIN(29), INTERRUPT(0), PWM(0), ADC_NONE)
  156. #define P1_30 LPC1768_PIN(PORT(1), PIN(30), INTERRUPT(0), PWM(0), ADC_CHAN(4))
  157. #define P1_31 LPC1768_PIN(PORT(1), PIN(31), INTERRUPT(0), PWM(0), ADC_CHAN(5))
  158. #define P2_00 LPC1768_PIN(PORT(2), PIN( 0), INTERRUPT(1), PWM(1), ADC_NONE)
  159. #define P2_01 LPC1768_PIN(PORT(2), PIN( 1), INTERRUPT(1), PWM(1), ADC_NONE)
  160. #define P2_02 LPC1768_PIN(PORT(2), PIN( 2), INTERRUPT(1), PWM(1), ADC_NONE)
  161. #define P2_03 LPC1768_PIN(PORT(2), PIN( 3), INTERRUPT(1), PWM(1), ADC_NONE)
  162. #define P2_04 LPC1768_PIN(PORT(2), PIN( 4), INTERRUPT(1), PWM(1), ADC_NONE)
  163. #define P2_05 LPC1768_PIN(PORT(2), PIN( 5), INTERRUPT(1), PWM(1), ADC_NONE)
  164. #define P2_06 LPC1768_PIN(PORT(2), PIN( 6), INTERRUPT(1), PWM(0), ADC_NONE)
  165. #define P2_07 LPC1768_PIN(PORT(2), PIN( 7), INTERRUPT(1), PWM(0), ADC_NONE)
  166. #define P2_08 LPC1768_PIN(PORT(2), PIN( 8), INTERRUPT(1), PWM(0), ADC_NONE)
  167. #define P2_09 LPC1768_PIN(PORT(2), PIN( 9), INTERRUPT(1), PWM(0), ADC_NONE)
  168. #define P2_10 LPC1768_PIN(PORT(2), PIN(10), INTERRUPT(1), PWM(0), ADC_NONE)
  169. #define P2_11 LPC1768_PIN(PORT(2), PIN(11), INTERRUPT(1), PWM(0), ADC_NONE)
  170. #define P2_12 LPC1768_PIN(PORT(2), PIN(12), INTERRUPT(1), PWM(0), ADC_NONE)
  171. #define P2_13 LPC1768_PIN(PORT(2), PIN(13), INTERRUPT(1), PWM(0), ADC_NONE)
  172. #define P3_25 LPC1768_PIN(PORT(3), PIN(25), INTERRUPT(0), PWM(1), ADC_NONE)
  173. #define P3_26 LPC1768_PIN(PORT(3), PIN(26), INTERRUPT(0), PWM(1), ADC_NONE)
  174. #define P4_28 LPC1768_PIN(PORT(4), PIN(28), INTERRUPT(0), PWM(0), ADC_NONE)
  175. #define P4_29 LPC1768_PIN(PORT(4), PIN(29), INTERRUPT(0), PWM(0), ADC_NONE)
  176. // Pin index for M43 and M226
  177. constexpr pin_t pin_map[] = {
  178. #if SERIAL_PORT != 3 && SERIAL_PORT_2 != 3
  179. P0_00, P0_01,
  180. #else
  181. P_NC, P_NC,
  182. #endif
  183. #if SERIAL_PORT != 0 && SERIAL_PORT_2 != 0
  184. P0_02, P0_03,
  185. #else
  186. P_NC, P_NC,
  187. #endif
  188. P0_04, P0_05, P0_06, P0_07,
  189. P0_08, P0_09,
  190. #if SERIAL_PORT != 2 && SERIAL_PORT_2 != 2
  191. P0_10, P0_11,
  192. #else
  193. P_NC, P_NC,
  194. #endif
  195. P_NC, P_NC, P_NC,
  196. #if SERIAL_PORT != 1 && SERIAL_PORT_2 != 1
  197. P0_15,
  198. P0_16,
  199. #else
  200. P_NC,
  201. P_NC,
  202. #endif
  203. P0_17, P0_18, P0_19, P0_20, P0_21, P0_22, P0_23,
  204. P0_24, P0_25, P0_26, P0_27, P0_28,
  205. #if SERIAL_PORT != -1 && SERIAL_PORT_2 != -1
  206. P0_29, P0_30,
  207. #else
  208. P_NC, P_NC,
  209. #endif
  210. P_NC,
  211. P1_00, P1_01, P_NC, P_NC, P1_04, P_NC, P_NC, P_NC,
  212. P1_08, P1_09, P1_10, P_NC, P_NC, P_NC, P1_14, P1_15,
  213. P1_16, P1_17, P1_18, P1_19, P1_20, P1_21, P1_22, P1_23,
  214. P1_24, P1_25, P1_26, P1_27, P1_28, P1_29, P1_30, P1_31,
  215. P2_00, P2_01, P2_02, P2_03, P2_04, P2_05, P2_06, P2_07,
  216. P2_08, P2_09, P2_10, P2_11, P2_12, P2_13, P_NC, P_NC,
  217. P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC,
  218. P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC,
  219. P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC,
  220. P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC,
  221. P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC,
  222. P_NC, P3_25, P3_26, P_NC, P_NC, P_NC, P_NC, P_NC,
  223. P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC,
  224. P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC,
  225. P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC, P_NC,
  226. P_NC, P_NC, P_NC, P_NC, P4_28, P4_29, P_NC, P_NC
  227. };
  228. constexpr uint8_t NUM_DIGITAL_PINS = COUNT(pin_map);
  229. constexpr pin_t adc_pin_table[] = {
  230. P0_23, P0_24, P0_25, P0_26, P1_30, P1_31,
  231. #if SERIAL_PORT != 0 && SERIAL_PORT_2 != 0
  232. P0_03, P0_02
  233. #endif
  234. };
  235. #if SERIAL_PORT != 0 && SERIAL_PORT_2 != 0
  236. #define NUM_ANALOG_INPUTS 8
  237. #else
  238. #define NUM_ANALOG_INPUTS 6
  239. #endif
  240. // P0.6 thru P0.9 are for the onboard SD card
  241. #define HAL_SENSITIVE_PINS P0_06, P0_07, P0_08, P0_09
  242. // Get the digital pin for an analog index
  243. pin_t analogInputToDigitalPin(const int8_t p);
  244. // Return the index of a pin number
  245. // The pin number given here is in the form ppp:nnnnn
  246. int16_t GET_PIN_MAP_INDEX(const pin_t pin);
  247. // Test whether the pin is valid
  248. bool VALID_PIN(const pin_t p);
  249. // Get the analog index for a digital pin
  250. int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t p);
  251. // Test whether the pin is PWM
  252. bool PWM_PIN(const pin_t p);
  253. // Test whether the pin is interruptable
  254. bool INTERRUPT_PIN(const pin_t p);
  255. // Get the pin number at the given index
  256. pin_t GET_PIN_MAP_PIN(const int16_t ind);
  257. // Parse a G-code word into a pin index
  258. int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
  259. #endif // _PINMAPPING_H_