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.

fastio_Due.h 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. /**
  23. * Fast I/O Routines for SAM3X8E
  24. * Use direct port manipulation to save scads of processor time.
  25. * Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
  26. */
  27. /**
  28. * Description: Fast IO functions for Arduino Due and compatible (SAM3X8E)
  29. *
  30. * For ARDUINO_ARCH_SAM
  31. * Note the code here was specifically crafted by disassembling what GCC produces
  32. * out of it, so GCC is able to optimize it out as much as possible to the least
  33. * amount of instructions. Be very carefull if you modify them, as "clean code"
  34. * leads to less efficient compiled code!!
  35. */
  36. #ifndef _FASTIO_DUE_H
  37. #define _FASTIO_DUE_H
  38. /**
  39. * Utility functions
  40. */
  41. // Due has 12 PWMs assigned to logical pins 2-13.
  42. // 6, 7, 8 & 9 come from the PWM controller. The others come from the timers.
  43. #define USEABLE_HARDWARE_PWM(p) ((2 <= p) && (p <= 13))
  44. #ifndef MASK
  45. #define MASK(PIN) (1 << PIN)
  46. #endif
  47. /**
  48. * Magic I/O routines
  49. *
  50. * Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
  51. *
  52. * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
  53. */
  54. // Read a pin
  55. #define _READ(IO) bool(DIO ## IO ## _WPORT -> PIO_PDSR & MASK(DIO ## IO ## _PIN))
  56. // Write to a pin
  57. #define _WRITE_VAR(IO,V) do { \
  58. volatile Pio* port = g_APinDescription[IO].pPort; \
  59. uint32_t mask = g_APinDescription[IO].ulPin; \
  60. if (V) port->PIO_SODR = mask; \
  61. else port->PIO_CODR = mask; \
  62. } while(0)
  63. // Write to a pin
  64. #define _WRITE(IO,V) do { \
  65. volatile Pio* port = (DIO ## IO ## _WPORT); \
  66. uint32_t mask = MASK(DIO ## IO ## _PIN); \
  67. if (V) port->PIO_SODR = mask; \
  68. else port->PIO_CODR = mask; \
  69. } while(0)
  70. // toggle a pin
  71. #define _TOGGLE(IO) _WRITE(IO, !READ(IO))
  72. // set pin as input
  73. #define _SET_INPUT(IO) do{ \
  74. pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
  75. PIO_Configure(g_APinDescription[IO].pPort, PIO_INPUT, g_APinDescription[IO].ulPin, 0); \
  76. }while(0)
  77. // set pin as output
  78. #define _SET_OUTPUT(IO) do{ \
  79. pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
  80. PIO_Configure(g_APinDescription[IO].pPort, _READ(IO) ? PIO_OUTPUT_1 : PIO_OUTPUT_0, g_APinDescription[IO].ulPin, g_APinDescription[IO].ulPinConfiguration); \
  81. g_pinStatus[IO] = (g_pinStatus[IO] & 0xF0) | PIN_STATUS_DIGITAL_OUTPUT;\
  82. }while(0)
  83. // set pin as input with pullup mode
  84. #define _PULLUP(IO,V) pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
  85. // check if pin is an input
  86. #define _GET_INPUT(IO)
  87. // check if pin is an output
  88. #define _GET_OUTPUT(IO)
  89. // check if pin is a timer
  90. #define _GET_TIMER(IO)
  91. // Read a pin wrapper
  92. #define READ(IO) _READ(IO)
  93. // Write to a pin wrapper
  94. #define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
  95. #define WRITE(IO,V) _WRITE(IO,V)
  96. // toggle a pin wrapper
  97. #define TOGGLE(IO) _TOGGLE(IO)
  98. // set pin as input wrapper
  99. #define SET_INPUT(IO) _SET_INPUT(IO)
  100. // set pin as input with pullup wrapper
  101. #define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
  102. // set pin as output wrapper - reads the pin and sets the output to that value
  103. #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
  104. // check if pin is an input wrapper
  105. #define GET_INPUT(IO) _GET_INPUT(IO)
  106. // check if pin is an output wrapper
  107. #define GET_OUTPUT(IO) _GET_OUTPUT(IO)
  108. // check if pin is a timer (wrapper)
  109. #define GET_TIMER(IO) _GET_TIMER(IO)
  110. // Shorthand
  111. #define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }
  112. /**
  113. * Ports and functions
  114. * Added as necessary or if I feel like it- not a comprehensive list!
  115. */
  116. // UART
  117. #define RXD DIO0
  118. #define TXD DIO1
  119. // TWI (I2C)
  120. #define SCL DIO21
  121. #define SDA DIO20
  122. /**
  123. * pins
  124. */
  125. #define DIO0_PIN 8
  126. #define DIO0_WPORT PIOA
  127. #define DIO1_PIN 9
  128. #define DIO1_WPORT PIOA
  129. #define DIO2_PIN 25
  130. #define DIO2_WPORT PIOB
  131. #define DIO3_PIN 28
  132. #define DIO3_WPORT PIOC
  133. #define DIO4_PIN 26
  134. #define DIO4_WPORT PIOC
  135. #define DIO5_PIN 25
  136. #define DIO5_WPORT PIOC
  137. #define DIO6_PIN 24
  138. #define DIO6_WPORT PIOC
  139. #define DIO7_PIN 23
  140. #define DIO7_WPORT PIOC
  141. #define DIO8_PIN 22
  142. #define DIO8_WPORT PIOC
  143. #define DIO9_PIN 21
  144. #define DIO9_WPORT PIOC
  145. #define DIO10_PIN 29
  146. #define DIO10_WPORT PIOC
  147. #define DIO11_PIN 7
  148. #define DIO11_WPORT PIOD
  149. #define DIO12_PIN 8
  150. #define DIO12_WPORT PIOD
  151. #define DIO13_PIN 27
  152. #define DIO13_WPORT PIOB
  153. #define DIO14_PIN 4
  154. #define DIO14_WPORT PIOD
  155. #define DIO15_PIN 5
  156. #define DIO15_WPORT PIOD
  157. #define DIO16_PIN 13
  158. #define DIO16_WPORT PIOA
  159. #define DIO17_PIN 12
  160. #define DIO17_WPORT PIOA
  161. #define DIO18_PIN 11
  162. #define DIO18_WPORT PIOA
  163. #define DIO19_PIN 10
  164. #define DIO19_WPORT PIOA
  165. #define DIO20_PIN 12
  166. #define DIO20_WPORT PIOB
  167. #define DIO21_PIN 13
  168. #define DIO21_WPORT PIOB
  169. #define DIO22_PIN 26
  170. #define DIO22_WPORT PIOB
  171. #define DIO23_PIN 14
  172. #define DIO23_WPORT PIOA
  173. #define DIO24_PIN 15
  174. #define DIO24_WPORT PIOA
  175. #define DIO25_PIN 0
  176. #define DIO25_WPORT PIOD
  177. #define DIO26_PIN 1
  178. #define DIO26_WPORT PIOD
  179. #define DIO27_PIN 2
  180. #define DIO27_WPORT PIOD
  181. #define DIO28_PIN 3
  182. #define DIO28_WPORT PIOD
  183. #define DIO29_PIN 6
  184. #define DIO29_WPORT PIOD
  185. #define DIO30_PIN 9
  186. #define DIO30_WPORT PIOD
  187. #define DIO31_PIN 7
  188. #define DIO31_WPORT PIOA
  189. #define DIO32_PIN 10
  190. #define DIO32_WPORT PIOD
  191. #define DIO33_PIN 1
  192. #define DIO33_WPORT PIOC
  193. #define DIO34_PIN 2
  194. #define DIO34_WPORT PIOC
  195. #define DIO35_PIN 3
  196. #define DIO35_WPORT PIOC
  197. #define DIO36_PIN 4
  198. #define DIO36_WPORT PIOC
  199. #define DIO37_PIN 5
  200. #define DIO37_WPORT PIOC
  201. #define DIO38_PIN 6
  202. #define DIO38_WPORT PIOC
  203. #define DIO39_PIN 7
  204. #define DIO39_WPORT PIOC
  205. #define DIO40_PIN 8
  206. #define DIO40_WPORT PIOC
  207. #define DIO41_PIN 9
  208. #define DIO41_WPORT PIOC
  209. #define DIO42_PIN 19
  210. #define DIO42_WPORT PIOA
  211. #define DIO43_PIN 20
  212. #define DIO43_WPORT PIOA
  213. #define DIO44_PIN 19
  214. #define DIO44_WPORT PIOC
  215. #define DIO45_PIN 18
  216. #define DIO45_WPORT PIOC
  217. #define DIO46_PIN 17
  218. #define DIO46_WPORT PIOC
  219. #define DIO47_PIN 16
  220. #define DIO47_WPORT PIOC
  221. #define DIO48_PIN 15
  222. #define DIO48_WPORT PIOC
  223. #define DIO49_PIN 14
  224. #define DIO49_WPORT PIOC
  225. #define DIO50_PIN 13
  226. #define DIO50_WPORT PIOC
  227. #define DIO51_PIN 12
  228. #define DIO51_WPORT PIOC
  229. #define DIO52_PIN 21
  230. #define DIO52_WPORT PIOB
  231. #define DIO53_PIN 14
  232. #define DIO53_WPORT PIOB
  233. #define DIO54_PIN 16
  234. #define DIO54_WPORT PIOA
  235. #define DIO55_PIN 24
  236. #define DIO55_WPORT PIOA
  237. #define DIO56_PIN 23
  238. #define DIO56_WPORT PIOA
  239. #define DIO57_PIN 22
  240. #define DIO57_WPORT PIOA
  241. #define DIO58_PIN 6
  242. #define DIO58_WPORT PIOA
  243. #define DIO59_PIN 4
  244. #define DIO59_WPORT PIOA
  245. #define DIO60_PIN 3
  246. #define DIO60_WPORT PIOA
  247. #define DIO61_PIN 2
  248. #define DIO61_WPORT PIOA
  249. #define DIO62_PIN 17
  250. #define DIO62_WPORT PIOB
  251. #define DIO63_PIN 18
  252. #define DIO63_WPORT PIOB
  253. #define DIO64_PIN 19
  254. #define DIO64_WPORT PIOB
  255. #define DIO65_PIN 20
  256. #define DIO65_WPORT PIOB
  257. #define DIO66_PIN 15
  258. #define DIO66_WPORT PIOB
  259. #define DIO67_PIN 16
  260. #define DIO67_WPORT PIOB
  261. #define DIO68_PIN 1
  262. #define DIO68_WPORT PIOA
  263. #define DIO69_PIN 0
  264. #define DIO69_WPORT PIOA
  265. #define DIO70_PIN 17
  266. #define DIO70_WPORT PIOA
  267. #define DIO71_PIN 18
  268. #define DIO71_WPORT PIOA
  269. #define DIO72_PIN 30
  270. #define DIO72_WPORT PIOC
  271. #define DIO73_PIN 21
  272. #define DIO73_WPORT PIOA
  273. #define DIO74_PIN 25
  274. #define DIO74_WPORT PIOA
  275. #define DIO75_PIN 26
  276. #define DIO75_WPORT PIOA
  277. #define DIO76_PIN 27
  278. #define DIO76_WPORT PIOA
  279. #define DIO77_PIN 28
  280. #define DIO77_WPORT PIOA
  281. #define DIO78_PIN 23
  282. #define DIO78_WPORT PIOB
  283. #define DIO79_PIN 17
  284. #define DIO79_WPORT PIOA
  285. #define DIO80_PIN 12
  286. #define DIO80_WPORT PIOB
  287. #define DIO81_PIN 8
  288. #define DIO81_WPORT PIOA
  289. #define DIO82_PIN 11
  290. #define DIO82_WPORT PIOA
  291. #define DIO83_PIN 13
  292. #define DIO83_WPORT PIOA
  293. #define DIO84_PIN 4
  294. #define DIO84_WPORT PIOD
  295. #define DIO85_PIN 11
  296. #define DIO85_WPORT PIOB
  297. #define DIO86_PIN 21
  298. #define DIO86_WPORT PIOB
  299. #define DIO87_PIN 29
  300. #define DIO87_WPORT PIOA
  301. #define DIO88_PIN 15
  302. #define DIO88_WPORT PIOB
  303. #define DIO89_PIN 14
  304. #define DIO89_WPORT PIOB
  305. #define DIO90_PIN 1
  306. #define DIO90_WPORT PIOA
  307. #define DIO91_PIN 15
  308. #define DIO91_WPORT PIOB
  309. #if ARDUINO_SAM_ARCHIM
  310. #define DIO92_PIN 11
  311. #define DIO92_WPORT PIOC
  312. #define DIO93_PIN 2
  313. #define DIO93_WPORT PIOB
  314. #define DIO94_PIN 1
  315. #define DIO94_WPORT PIOB
  316. #define DIO95_PIN 0
  317. #define DIO95_WPORT PIOB
  318. #define DIO96_PIN 10
  319. #define DIO96_WPORT PIOC
  320. #define DIO97_PIN 24
  321. #define DIO97_WPORT PIOB
  322. #define DIO98_PIN 7
  323. #define DIO98_WPORT PIOB
  324. #define DIO99_PIN 6
  325. #define DIO99_WPORT PIOB
  326. #define DIO100_PIN 8
  327. #define DIO100_WPORT PIOB
  328. #define DIO101_PIN 5
  329. #define DIO101_WPORT PIOB
  330. #define DIO102_PIN 4
  331. #define DIO102_WPORT PIOB
  332. #define DIO103_PIN 3
  333. #define DIO103_WPORT PIOB
  334. #define DIO104_PIN 20
  335. #define DIO104_WPORT PIOC
  336. #define DIO105_PIN 22
  337. #define DIO105_WPORT PIOB
  338. #define DIO106_PIN 27
  339. #define DIO106_WPORT PIOC
  340. #define DIO107_PIN 10
  341. #define DIO107_WPORT PIOB
  342. #else
  343. #define DIO92_PIN 5
  344. #define DIO92_WPORT PIOA
  345. #define DIO93_PIN 12
  346. #define DIO93_WPORT PIOB
  347. #define DIO94_PIN 22
  348. #define DIO94_WPORT PIOB
  349. #define DIO95_PIN 23
  350. #define DIO95_WPORT PIOB
  351. #define DIO96_PIN 24
  352. #define DIO96_WPORT PIOB
  353. #define DIO97_PIN 20
  354. #define DIO97_WPORT PIOC
  355. #define DIO98_PIN 27
  356. #define DIO98_WPORT PIOC
  357. #define DIO99_PIN 10
  358. #define DIO99_WPORT PIOC
  359. #define DIO100_PIN 11
  360. #define DIO100_WPORT PIOC
  361. #endif
  362. #endif // _FASTIO_DUE_H