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.

pinsDebug.h 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  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. // How many DIO pins are defined?
  23. #ifdef DIO85_PIN
  24. // #define DIO_COUNT 86
  25. #define DIO_COUNT 70 // digitalRead and other Arduino IDE routines only know about pins 0 through 69
  26. #elif defined(DIO53_PIN)
  27. #define DIO_COUNT 54
  28. #elif defined(DIO47_PIN)
  29. #define DIO_COUNT 48
  30. #elif defined(DIO31_PIN)
  31. #define DIO_COUNT 32
  32. #elif defined(DIO21_PIN)
  33. #define DIO_COUNT 22
  34. #endif
  35. bool endstop_monitor_flag = false;
  36. #define NAME_FORMAT "%-28s" // one place to specify the format of all the sources of names
  37. // "-" left justify, "28" minimum width of name, pad with blanks
  38. #define _PIN_SAY(NAME) { sprintf(buffer, NAME_FORMAT, NAME); SERIAL_ECHO(buffer); return true; }
  39. #define PIN_SAY(NAME) if (pin == NAME) _PIN_SAY(#NAME);
  40. #define _ANALOG_PIN_SAY(NAME) { sprintf(buffer, NAME_FORMAT, NAME); SERIAL_ECHO(buffer); pin_is_analog = true; return true; }
  41. #define ANALOG_PIN_SAY(NAME) if (pin == analogInputToDigitalPin(NAME)) _ANALOG_PIN_SAY(#NAME);
  42. #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(5)))
  43. int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
  44. uint8_t port = digitalPinToPort(pin);
  45. return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
  46. }
  47. /**
  48. * Report pin name for a given fastio digital pin index
  49. */
  50. static bool report_pin_name(int8_t pin, bool &pin_is_analog) {
  51. char buffer[30]; // for the sprintf statements
  52. pin_is_analog = false; // default to digital pin
  53. if (IS_ANALOG(pin)) {
  54. sprintf(buffer, "(A%2d) ", int(pin - analogInputToDigitalPin(0)));
  55. SERIAL_ECHO(buffer);
  56. }
  57. else SERIAL_ECHOPGM(" ");
  58. #if defined(RXD) && RXD >= 0
  59. if (pin == 0) { sprintf(buffer, NAME_FORMAT, "RXD"); SERIAL_ECHO(buffer); return true; }
  60. #endif
  61. #if defined(TXD) && TXD >= 0
  62. if (pin == 1) { sprintf(buffer, NAME_FORMAT, "TXD"); SERIAL_ECHO(buffer); return true; }
  63. #endif
  64. // Pin list updated from 7 OCT RCBugfix branch
  65. #if defined(__FD) && __FD >= 0
  66. PIN_SAY(__FD)
  67. #endif
  68. #if defined(__FS) && __FS >= 0
  69. PIN_SAY(__FS)
  70. #endif
  71. #if defined(__GD) && __GD >= 0
  72. PIN_SAY(__GD)
  73. #endif
  74. #if defined(__GS) && __GS >= 0
  75. PIN_SAY(__GS)
  76. #endif
  77. #if PIN_EXISTS(AVR_MISO)
  78. PIN_SAY(AVR_MISO_PIN);
  79. #endif
  80. #if PIN_EXISTS(AVR_MOSI)
  81. PIN_SAY(AVR_MOSI_PIN);
  82. #endif
  83. #if PIN_EXISTS(AVR_SCK)
  84. PIN_SAY(AVR_SCK_PIN);
  85. #endif
  86. #if PIN_EXISTS(AVR_SS)
  87. PIN_SAY(AVR_SS_PIN);
  88. #endif
  89. #if PIN_EXISTS(BEEPER)
  90. PIN_SAY(BEEPER_PIN);
  91. #endif
  92. #if defined(BTN_CENTER) && BTN_CENTER >= 0
  93. PIN_SAY(BTN_CENTER);
  94. #endif
  95. #if defined(BTN_DOWN) && BTN_DOWN >= 0
  96. PIN_SAY(BTN_DOWN);
  97. #endif
  98. #if defined(BTN_DWN) && BTN_DWN >= 0
  99. PIN_SAY(BTN_DWN);
  100. #endif
  101. #if defined(BTN_EN1) && BTN_EN1 >= 0
  102. PIN_SAY(BTN_EN1);
  103. #endif
  104. #if defined(BTN_EN2) && BTN_EN2 >= 0
  105. PIN_SAY(BTN_EN2);
  106. #endif
  107. #if defined(BTN_ENC) && BTN_ENC >= 0
  108. PIN_SAY(BTN_ENC);
  109. #endif
  110. #if defined(BTN_HOME) && BTN_HOME >= 0
  111. PIN_SAY(BTN_HOME);
  112. #endif
  113. #if defined(BTN_LEFT) && BTN_LEFT >= 0
  114. PIN_SAY(BTN_LEFT);
  115. #endif
  116. #if defined(BTN_LFT) && BTN_LFT >= 0
  117. PIN_SAY(BTN_LFT);
  118. #endif
  119. #if defined(BTN_RIGHT) && BTN_RIGHT >= 0
  120. PIN_SAY(BTN_RIGHT);
  121. #endif
  122. #if defined(BTN_RT) && BTN_RT >= 0
  123. PIN_SAY(BTN_RT);
  124. #endif
  125. #if defined(BTN_UP) && BTN_UP >= 0
  126. PIN_SAY(BTN_UP);
  127. #endif
  128. #if PIN_EXISTS(CONTROLLERFAN)
  129. PIN_SAY(CONTROLLERFAN_PIN);
  130. #endif
  131. #if PIN_EXISTS(DAC_DISABLE)
  132. PIN_SAY(DAC_DISABLE_PIN);
  133. #endif
  134. #if defined(DAC_STEPPER_GAIN) && DAC_STEPPER_GAIN >= 0
  135. PIN_SAY(DAC_STEPPER_GAIN);
  136. #endif
  137. #if defined(DAC_STEPPER_VREF) && DAC_STEPPER_VREF >= 0
  138. PIN_SAY(DAC_STEPPER_VREF);
  139. #endif
  140. #if PIN_EXISTS(DEBUG)
  141. PIN_SAY(DEBUG_PIN);
  142. #endif
  143. #if PIN_EXISTS(DIGIPOTSS)
  144. PIN_SAY(DIGIPOTSS_PIN);
  145. #endif
  146. #if defined(DIO_COUNT) && DIO_COUNT >= 0
  147. PIN_SAY(DIO_COUNT);
  148. #endif
  149. #if defined(DOGLCD_A0) && DOGLCD_A0 >= 0
  150. PIN_SAY(DOGLCD_A0);
  151. #endif
  152. #if defined(DOGLCD_CS) && DOGLCD_CS >= 0
  153. PIN_SAY(DOGLCD_CS);
  154. #endif
  155. #if defined(DOGLCD_MOSI) && DOGLCD_MOSI >= 0
  156. PIN_SAY(DOGLCD_MOSI);
  157. #endif
  158. #if defined(DOGLCD_SCK) && DOGLCD_SCK >= 0
  159. PIN_SAY(DOGLCD_SCK);
  160. #endif
  161. #if PIN_EXISTS(E0_ATT)
  162. PIN_SAY(E0_ATT_PIN);
  163. #endif
  164. #if PIN_EXISTS(E0_AUTO_FAN)
  165. PIN_SAY(E0_AUTO_FAN_PIN);
  166. #endif
  167. #if PIN_EXISTS(E1_AUTO_FAN)
  168. PIN_SAY(E1_AUTO_FAN_PIN);
  169. #endif
  170. #if PIN_EXISTS(E2_AUTO_FAN)
  171. PIN_SAY(E2_AUTO_FAN_PIN);
  172. #endif
  173. #if PIN_EXISTS(E3_AUTO_FAN)
  174. PIN_SAY(E3_AUTO_FAN_PIN);
  175. #endif
  176. #if PIN_EXISTS(E0_DIR)
  177. PIN_SAY(E0_DIR_PIN);
  178. #endif
  179. #if PIN_EXISTS(E0_ENABLE)
  180. PIN_SAY(E0_ENABLE_PIN);
  181. #endif
  182. #if PIN_EXISTS(E0_MS1)
  183. PIN_SAY(E0_MS1_PIN);
  184. #endif
  185. #if PIN_EXISTS(E0_MS2)
  186. PIN_SAY(E0_MS2_PIN);
  187. #endif
  188. #if PIN_EXISTS(E0_STEP)
  189. PIN_SAY(E0_STEP_PIN);
  190. #endif
  191. #if PIN_EXISTS(E1_DIR)
  192. PIN_SAY(E1_DIR_PIN);
  193. #endif
  194. #if PIN_EXISTS(E1_ENABLE)
  195. PIN_SAY(E1_ENABLE_PIN);
  196. #endif
  197. #if PIN_EXISTS(E1_MS1)
  198. PIN_SAY(E1_MS1_PIN);
  199. #endif
  200. #if PIN_EXISTS(E1_MS2)
  201. PIN_SAY(E1_MS2_PIN);
  202. #endif
  203. #if PIN_EXISTS(E1_STEP)
  204. PIN_SAY(E1_STEP_PIN);
  205. #endif
  206. #if PIN_EXISTS(E2_DIR)
  207. PIN_SAY(E2_DIR_PIN);
  208. #endif
  209. #if PIN_EXISTS(E2_ENABLE)
  210. PIN_SAY(E2_ENABLE_PIN);
  211. #endif
  212. #if PIN_EXISTS(E2_STEP)
  213. PIN_SAY(E2_STEP_PIN);
  214. #endif
  215. #if PIN_EXISTS(E3_DIR)
  216. PIN_SAY(E3_DIR_PIN);
  217. #endif
  218. #if PIN_EXISTS(E3_ENABLE)
  219. PIN_SAY(E3_ENABLE_PIN);
  220. #endif
  221. #if PIN_EXISTS(E3_STEP)
  222. PIN_SAY(E3_STEP_PIN);
  223. #endif
  224. #if PIN_EXISTS(E4_DIR)
  225. PIN_SAY(E4_DIR_PIN);
  226. #endif
  227. #if PIN_EXISTS(E4_ENABLE)
  228. PIN_SAY(E4_ENABLE_PIN);
  229. #endif
  230. #if PIN_EXISTS(E4_STEP)
  231. PIN_SAY(E4_STEP_PIN);
  232. #endif
  233. #if defined(encrot1) && encrot1 >= 0
  234. PIN_SAY(encrot1);
  235. #endif
  236. #if defined(encrot2) && encrot2 >= 0
  237. PIN_SAY(encrot2);
  238. #endif
  239. #if defined(encrot3) && encrot3 >= 0
  240. PIN_SAY(encrot3);
  241. #endif
  242. #if defined(EXT_AUX_A0_IO) && EXT_AUX_A0_IO >= 0
  243. PIN_SAY(EXT_AUX_A0_IO);
  244. #endif
  245. #if defined(EXT_AUX_A1) && EXT_AUX_A1 >= 0
  246. PIN_SAY(EXT_AUX_A1);
  247. #endif
  248. #if defined(EXT_AUX_A1_IO) && EXT_AUX_A1_IO >= 0
  249. PIN_SAY(EXT_AUX_A1_IO);
  250. #endif
  251. #if defined(EXT_AUX_A2) && EXT_AUX_A2 >= 0
  252. PIN_SAY(EXT_AUX_A2);
  253. #endif
  254. #if defined(EXT_AUX_A2_IO) && EXT_AUX_A2_IO >= 0
  255. PIN_SAY(EXT_AUX_A2_IO);
  256. #endif
  257. #if defined(EXT_AUX_A3) && EXT_AUX_A3 >= 0
  258. PIN_SAY(EXT_AUX_A3);
  259. #endif
  260. #if defined(EXT_AUX_A3_IO) && EXT_AUX_A3_IO >= 0
  261. PIN_SAY(EXT_AUX_A3_IO);
  262. #endif
  263. #if defined(EXT_AUX_A4) && EXT_AUX_A4 >= 0
  264. PIN_SAY(EXT_AUX_A4);
  265. #endif
  266. #if defined(EXT_AUX_A4_IO) && EXT_AUX_A4_IO >= 0
  267. PIN_SAY(EXT_AUX_A4_IO);
  268. #endif
  269. #if defined(EXT_AUX_PWM_D24) && EXT_AUX_PWM_D24 >= 0
  270. PIN_SAY(EXT_AUX_PWM_D24);
  271. #endif
  272. #if defined(EXT_AUX_RX1_D2) && EXT_AUX_RX1_D2 >= 0
  273. PIN_SAY(EXT_AUX_RX1_D2);
  274. #endif
  275. #if defined(EXT_AUX_SDA_D1) && EXT_AUX_SDA_D1 >= 0
  276. PIN_SAY(EXT_AUX_SDA_D1);
  277. #endif
  278. #if defined(EXT_AUX_TX1_D3) && EXT_AUX_TX1_D3 >= 0
  279. PIN_SAY(EXT_AUX_TX1_D3);
  280. #endif
  281. #if PIN_EXISTS(FAN)
  282. PIN_SAY(FAN_PIN);
  283. #endif
  284. #if PIN_EXISTS(FAN0)
  285. PIN_SAY(FAN0_PIN);
  286. #endif
  287. #if PIN_EXISTS(FAN1)
  288. PIN_SAY(FAN1_PIN);
  289. #endif
  290. #if PIN_EXISTS(FAN2)
  291. PIN_SAY(FAN2_PIN);
  292. #endif
  293. #if PIN_EXISTS(FIL_RUNOUT)
  294. PIN_SAY(FIL_RUNOUT_PIN);
  295. #endif
  296. #if PIN_EXISTS(FILWIDTH)
  297. ANALOG_PIN_SAY(FILWIDTH_PIN);
  298. #endif
  299. #if defined(GEN7_VERSION) && GEN7_VERSION >= 0
  300. PIN_SAY(GEN7_VERSION);
  301. #endif
  302. #if PIN_EXISTS(HEATER_0)
  303. PIN_SAY(HEATER_0_PIN);
  304. #endif
  305. #if PIN_EXISTS(HEATER_1)
  306. PIN_SAY(HEATER_1_PIN);
  307. #endif
  308. #if PIN_EXISTS(HEATER_2)
  309. PIN_SAY(HEATER_2_PIN);
  310. #endif
  311. #if PIN_EXISTS(HEATER_3)
  312. PIN_SAY(HEATER_3_PIN);
  313. #endif
  314. #if PIN_EXISTS(HEATER_4)
  315. PIN_SAY(HEATER_4_PIN);
  316. #endif
  317. #if PIN_EXISTS(HEATER_5)
  318. PIN_SAY(HEATER_5_PIN);
  319. #endif
  320. #if PIN_EXISTS(HEATER_6)
  321. PIN_SAY(HEATER_6_PIN);
  322. #endif
  323. #if PIN_EXISTS(HEATER_7)
  324. PIN_SAY(HEATER_7_PIN);
  325. #endif
  326. #if PIN_EXISTS(HEATER_BED)
  327. PIN_SAY(HEATER_BED_PIN);
  328. #endif
  329. #if defined(I2C_SCL) && I2C_SCL >= 0
  330. PIN_SAY(I2C_SCL);
  331. #endif
  332. #if defined(I2C_SDA) && I2C_SDA >= 0
  333. PIN_SAY(I2C_SDA);
  334. #endif
  335. #if PIN_EXISTS(KILL)
  336. PIN_SAY(KILL_PIN);
  337. #endif
  338. #if PIN_EXISTS(LCD_BACKLIGHT)
  339. PIN_SAY(LCD_BACKLIGHT_PIN);
  340. #endif
  341. #if defined(LCD_CONTRAST) && LCD_CONTRAST >= 0
  342. PIN_SAY(LCD_CONTRAST);
  343. #endif
  344. #if defined(LCD_PINS_D4) && LCD_PINS_D4 >= 0
  345. PIN_SAY(LCD_PINS_D4);
  346. #endif
  347. #if defined(LCD_PINS_D5) && LCD_PINS_D5 >= 0
  348. PIN_SAY(LCD_PINS_D5);
  349. #endif
  350. #if defined(LCD_PINS_D6) && LCD_PINS_D6 >= 0
  351. PIN_SAY(LCD_PINS_D6);
  352. #endif
  353. #if defined(LCD_PINS_D7) && LCD_PINS_D7 >= 0
  354. PIN_SAY(LCD_PINS_D7);
  355. #endif
  356. #if defined(LCD_PINS_ENABLE) && LCD_PINS_ENABLE >= 0
  357. PIN_SAY(LCD_PINS_ENABLE);
  358. #endif
  359. #if defined(LCD_PINS_RS) && LCD_PINS_RS >= 0
  360. PIN_SAY(LCD_PINS_RS);
  361. #endif
  362. #if defined(LCD_SDSS) && LCD_SDSS >= 0
  363. PIN_SAY(LCD_SDSS);
  364. #endif
  365. #if PIN_EXISTS(LED)
  366. PIN_SAY(LED_PIN);
  367. #endif
  368. #if PIN_EXISTS(MAIN_VOLTAGE_MEASURE)
  369. PIN_SAY(MAIN_VOLTAGE_MEASURE_PIN);
  370. #endif
  371. #if defined(MAX6675_SS) && MAX6675_SS >= 0
  372. PIN_SAY(MAX6675_SS);
  373. #endif
  374. #if PIN_EXISTS(MISO)
  375. PIN_SAY(MISO_PIN);
  376. #endif
  377. #if PIN_EXISTS(MOSFET_D)
  378. PIN_SAY(MOSFET_D_PIN);
  379. #endif
  380. #if PIN_EXISTS(MOSI)
  381. PIN_SAY(MOSI_PIN);
  382. #endif
  383. #if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
  384. PIN_SAY(MOTOR_CURRENT_PWM_E_PIN);
  385. #endif
  386. #if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
  387. PIN_SAY(MOTOR_CURRENT_PWM_XY_PIN);
  388. #endif
  389. #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
  390. PIN_SAY(MOTOR_CURRENT_PWM_Z_PIN);
  391. #endif
  392. #if defined(NUM_TLCS) && NUM_TLCS >= 0
  393. PIN_SAY(NUM_TLCS);
  394. #endif
  395. #if PIN_EXISTS(PHOTOGRAPH)
  396. PIN_SAY(PHOTOGRAPH_PIN);
  397. #endif
  398. #if PIN_EXISTS(PS_ON)
  399. PIN_SAY(PS_ON_PIN);
  400. #endif
  401. #if PIN_EXISTS(RAMPS_D10)
  402. PIN_SAY(RAMPS_D10_PIN);
  403. #endif
  404. #if PIN_EXISTS(RAMPS_D8)
  405. PIN_SAY(RAMPS_D8_PIN);
  406. #endif
  407. #if PIN_EXISTS(RAMPS_D9)
  408. PIN_SAY(RAMPS_D9_PIN);
  409. #endif
  410. #if PIN_EXISTS(RX_ENABLE)
  411. PIN_SAY(RX_ENABLE_PIN);
  412. #endif
  413. #if PIN_EXISTS(SAFETY_TRIGGERED)
  414. PIN_SAY(SAFETY_TRIGGERED_PIN);
  415. #endif
  416. #if PIN_EXISTS(SCK)
  417. PIN_SAY(SCK_PIN);
  418. #endif
  419. #if defined(SCL) && SCL >= 0
  420. PIN_SAY(SCL);
  421. #endif
  422. #if PIN_EXISTS(SD_DETECT)
  423. PIN_SAY(SD_DETECT_PIN);
  424. #endif
  425. #if defined(SDA) && SDA >= 0
  426. PIN_SAY(SDA);
  427. #endif
  428. #if defined(SDPOWER) && SDPOWER >= 0
  429. PIN_SAY(SDPOWER);
  430. #endif
  431. #if defined(SDSS) && SDSS >= 0
  432. PIN_SAY(SDSS);
  433. #endif
  434. #if PIN_EXISTS(SERVO0)
  435. PIN_SAY(SERVO0_PIN);
  436. #endif
  437. #if PIN_EXISTS(SERVO1)
  438. PIN_SAY(SERVO1_PIN);
  439. #endif
  440. #if PIN_EXISTS(SERVO2)
  441. PIN_SAY(SERVO2_PIN);
  442. #endif
  443. #if PIN_EXISTS(SERVO3)
  444. PIN_SAY(SERVO3_PIN);
  445. #endif
  446. #if defined(SHIFT_CLK) && SHIFT_CLK >= 0
  447. PIN_SAY(SHIFT_CLK);
  448. #endif
  449. #if defined(SHIFT_EN) && SHIFT_EN >= 0
  450. PIN_SAY(SHIFT_EN);
  451. #endif
  452. #if defined(SHIFT_LD) && SHIFT_LD >= 0
  453. PIN_SAY(SHIFT_LD);
  454. #endif
  455. #if defined(SHIFT_OUT) && SHIFT_OUT >= 0
  456. PIN_SAY(SHIFT_OUT);
  457. #endif
  458. #if PIN_EXISTS(SLED)
  459. PIN_SAY(SLED_PIN);
  460. #endif
  461. #if PIN_EXISTS(SLEEP_WAKE)
  462. PIN_SAY(SLEEP_WAKE_PIN);
  463. #endif
  464. #if PIN_EXISTS(SOL1)
  465. PIN_SAY(SOL1_PIN);
  466. #endif
  467. #if PIN_EXISTS(SOL2)
  468. PIN_SAY(SOL2_PIN);
  469. #endif
  470. #if PIN_EXISTS(SPINDLE_ENABLE)
  471. PIN_SAY(SPINDLE_ENABLE_PIN);
  472. #endif
  473. #if PIN_EXISTS(SPINDLE_SPEED)
  474. PIN_SAY(SPINDLE_SPEED_PIN);
  475. #endif
  476. #if PIN_EXISTS(SS)
  477. PIN_SAY(SS_PIN);
  478. #endif
  479. #if PIN_EXISTS(STAT_LED_BLUE)
  480. PIN_SAY(STAT_LED_BLUE_PIN);
  481. #endif
  482. #if PIN_EXISTS(STAT_LED_RED)
  483. PIN_SAY(STAT_LED_RED_PIN);
  484. #endif
  485. #if PIN_EXISTS(STEPPER_RESET)
  486. PIN_SAY(STEPPER_RESET_PIN);
  487. #endif
  488. #if PIN_EXISTS(SUICIDE)
  489. PIN_SAY(SUICIDE_PIN);
  490. #endif
  491. #if defined(TC1) && TC1 >= 0
  492. ANALOG_PIN_SAY(TC1);
  493. #endif
  494. #if defined(TC2) && TC2 >= 0
  495. ANALOG_PIN_SAY(TC2);
  496. #endif
  497. #if PIN_EXISTS(TEMP_0)
  498. ANALOG_PIN_SAY(TEMP_0_PIN);
  499. #endif
  500. #if PIN_EXISTS(TEMP_1)
  501. ANALOG_PIN_SAY(TEMP_1_PIN);
  502. #endif
  503. #if PIN_EXISTS(TEMP_2)
  504. ANALOG_PIN_SAY(TEMP_2_PIN);
  505. #endif
  506. #if PIN_EXISTS(TEMP_3)
  507. ANALOG_PIN_SAY(TEMP_3_PIN);
  508. #endif
  509. #if PIN_EXISTS(TEMP_4)
  510. ANALOG_PIN_SAY(TEMP_4_PIN);
  511. #endif
  512. #if PIN_EXISTS(TEMP_BED)
  513. ANALOG_PIN_SAY(TEMP_BED_PIN);
  514. #endif
  515. #if PIN_EXISTS(TEMP_X)
  516. ANALOG_PIN_SAY(TEMP_X_PIN);
  517. #endif
  518. #if defined(TLC_BLANK_BIT) && TLC_BLANK_BIT >= 0
  519. PIN_SAY(TLC_BLANK_BIT);
  520. #endif
  521. #if PIN_EXISTS(TLC_BLANK)
  522. PIN_SAY(TLC_BLANK_PIN);
  523. #endif
  524. #if defined(TLC_CLOCK_BIT) && TLC_CLOCK_BIT >= 0
  525. PIN_SAY(TLC_CLOCK_BIT);
  526. #endif
  527. #if PIN_EXISTS(TLC_CLOCK)
  528. PIN_SAY(TLC_CLOCK_PIN);
  529. #endif
  530. #if defined(TLC_DATA_BIT) && TLC_DATA_BIT >= 0
  531. PIN_SAY(TLC_DATA_BIT);
  532. #endif
  533. #if PIN_EXISTS(TLC_DATA)
  534. PIN_SAY(TLC_DATA_PIN);
  535. #endif
  536. #if PIN_EXISTS(TLC_XLAT)
  537. PIN_SAY(TLC_XLAT_PIN);
  538. #endif
  539. #if PIN_EXISTS(TX_ENABLE)
  540. PIN_SAY(TX_ENABLE_PIN);
  541. #endif
  542. #if defined(UNUSED_PWM) && UNUSED_PWM >= 0
  543. PIN_SAY(UNUSED_PWM);
  544. #endif
  545. #if PIN_EXISTS(X_ATT)
  546. PIN_SAY(X_ATT_PIN);
  547. #endif
  548. #if PIN_EXISTS(X_DIR)
  549. PIN_SAY(X_DIR_PIN);
  550. #endif
  551. #if PIN_EXISTS(X_ENABLE)
  552. PIN_SAY(X_ENABLE_PIN);
  553. #endif
  554. #if PIN_EXISTS(X_MAX)
  555. PIN_SAY(X_MAX_PIN);
  556. #endif
  557. #if PIN_EXISTS(X_MIN)
  558. PIN_SAY(X_MIN_PIN);
  559. #endif
  560. #if PIN_EXISTS(X_MS1)
  561. PIN_SAY(X_MS1_PIN);
  562. #endif
  563. #if PIN_EXISTS(X_MS2)
  564. PIN_SAY(X_MS2_PIN);
  565. #endif
  566. #if PIN_EXISTS(X_STEP)
  567. PIN_SAY(X_STEP_PIN);
  568. #endif
  569. #if PIN_EXISTS(X_STOP)
  570. PIN_SAY(X_STOP_PIN);
  571. #endif
  572. #if PIN_EXISTS(X2_DIR)
  573. PIN_SAY(X2_DIR_PIN);
  574. #endif
  575. #if PIN_EXISTS(X2_ENABLE)
  576. PIN_SAY(X2_ENABLE_PIN);
  577. #endif
  578. #if PIN_EXISTS(X2_STEP)
  579. PIN_SAY(X2_STEP_PIN);
  580. #endif
  581. #if PIN_EXISTS(Y_ATT)
  582. PIN_SAY(Y_ATT_PIN);
  583. #endif
  584. #if PIN_EXISTS(Y_DIR)
  585. PIN_SAY(Y_DIR_PIN);
  586. #endif
  587. #if PIN_EXISTS(Y_ENABLE)
  588. PIN_SAY(Y_ENABLE_PIN);
  589. #endif
  590. #if PIN_EXISTS(Y_MAX)
  591. PIN_SAY(Y_MAX_PIN);
  592. #endif
  593. #if PIN_EXISTS(Y_MIN)
  594. PIN_SAY(Y_MIN_PIN);
  595. #endif
  596. #if PIN_EXISTS(Y_MS1)
  597. PIN_SAY(Y_MS1_PIN);
  598. #endif
  599. #if PIN_EXISTS(Y_MS2)
  600. PIN_SAY(Y_MS2_PIN);
  601. #endif
  602. #if PIN_EXISTS(Y_STEP)
  603. PIN_SAY(Y_STEP_PIN);
  604. #endif
  605. #if PIN_EXISTS(Y_STOP)
  606. PIN_SAY(Y_STOP_PIN);
  607. #endif
  608. #if PIN_EXISTS(Y2_DIR)
  609. PIN_SAY(Y2_DIR_PIN);
  610. #endif
  611. #if PIN_EXISTS(Y2_ENABLE)
  612. PIN_SAY(Y2_ENABLE_PIN);
  613. #endif
  614. #if PIN_EXISTS(Y2_STEP)
  615. PIN_SAY(Y2_STEP_PIN);
  616. #endif
  617. #if PIN_EXISTS(Z_ATT)
  618. PIN_SAY(Z_ATT_PIN);
  619. #endif
  620. #if PIN_EXISTS(Z_DIR)
  621. PIN_SAY(Z_DIR_PIN);
  622. #endif
  623. #if PIN_EXISTS(Z_ENABLE)
  624. PIN_SAY(Z_ENABLE_PIN);
  625. #endif
  626. #if PIN_EXISTS(Z_MAX)
  627. PIN_SAY(Z_MAX_PIN);
  628. #endif
  629. #if PIN_EXISTS(Z_MIN)
  630. PIN_SAY(Z_MIN_PIN);
  631. #endif
  632. #if PIN_EXISTS(Z_MIN_PROBE)
  633. PIN_SAY(Z_MIN_PROBE_PIN);
  634. #endif
  635. #if PIN_EXISTS(Z_MS1)
  636. PIN_SAY(Z_MS1_PIN);
  637. #endif
  638. #if PIN_EXISTS(Z_MS2)
  639. PIN_SAY(Z_MS2_PIN);
  640. #endif
  641. #if PIN_EXISTS(Z_STEP)
  642. PIN_SAY(Z_STEP_PIN);
  643. #endif
  644. #if PIN_EXISTS(Z_STOP)
  645. PIN_SAY(Z_STOP_PIN);
  646. #endif
  647. #if PIN_EXISTS(Z2_DIR)
  648. PIN_SAY(Z2_DIR_PIN);
  649. #endif
  650. #if PIN_EXISTS(Z2_ENABLE)
  651. PIN_SAY(Z2_ENABLE_PIN);
  652. #endif
  653. #if PIN_EXISTS(Z2_STEP)
  654. PIN_SAY(Z2_STEP_PIN);
  655. #endif
  656. sprintf(buffer, NAME_FORMAT, "<unused> ");
  657. SERIAL_ECHO(buffer);
  658. return false;
  659. } // report_pin_name
  660. #define PWM_PRINT(V) do{ sprintf(buffer, "PWM: %4d", V); SERIAL_ECHO(buffer); }while(0)
  661. #define PWM_CASE(N) \
  662. case TIMER##N: \
  663. if (TCCR##N & (_BV(COM## N ##1) | _BV(COM## N ##0))) { \
  664. PWM_PRINT(OCR##N); \
  665. return true; \
  666. } else return false
  667. /**
  668. * Print a pin's PWM status.
  669. * Return true if it's currently a PWM pin.
  670. */
  671. static bool PWM_status(uint8_t pin) {
  672. char buffer[20]; // for the sprintf statements
  673. switch(digitalPinToTimer(pin)) {
  674. #if defined(TCCR0A) && defined(COM0A1)
  675. PWM_CASE(0A);
  676. PWM_CASE(0B);
  677. #endif
  678. #if defined(TCCR1A) && defined(COM1A1)
  679. PWM_CASE(1A);
  680. PWM_CASE(1B);
  681. PWM_CASE(1C);
  682. #endif
  683. #if defined(TCCR2A) && defined(COM2A1)
  684. PWM_CASE(2A);
  685. PWM_CASE(2B);
  686. #endif
  687. #if defined(TCCR3A) && defined(COM3A1)
  688. PWM_CASE(3A);
  689. PWM_CASE(3B);
  690. PWM_CASE(3C);
  691. #endif
  692. #ifdef TCCR4A
  693. PWM_CASE(4A);
  694. PWM_CASE(4B);
  695. PWM_CASE(4C);
  696. #endif
  697. #if defined(TCCR5A) && defined(COM5A1)
  698. PWM_CASE(5A);
  699. PWM_CASE(5B);
  700. PWM_CASE(5C);
  701. #endif
  702. case NOT_ON_TIMER:
  703. default:
  704. return false;
  705. }
  706. SERIAL_PROTOCOLPGM(" ");
  707. } //PWM_status
  708. #define WGM_MAKE3(N) ((TEST(TCCR##N##B, WGM##N##2) >> 1) | (TCCR##N##A & (_BV(WGM##N##0) | _BV(WGM##N##1))))
  709. #define WGM_MAKE4(N) (WGM_MAKE3(N) | (TEST(TCCR##N##B, WGM##N##3) >> 1))
  710. #define TIMER_PREFIX(T,L,N) do{ \
  711. WGM = WGM_MAKE##N(T); \
  712. SERIAL_PROTOCOLPGM(" TIMER"); \
  713. SERIAL_PROTOCOLPGM(STRINGIFY(T) STRINGIFY(L)); \
  714. SERIAL_PROTOCOLPAIR(" WGM: ", WGM); \
  715. SERIAL_PROTOCOLPAIR(" TIMSK" STRINGIFY(T) ": ", TIMSK##T); \
  716. }while(0)
  717. #define WGM_TEST1 (WGM == 0 || WGM == 2 || WGM == 4 || WGM == 6)
  718. #define WGM_TEST2 (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13)
  719. static void err_is_counter() {
  720. SERIAL_PROTOCOLPGM(" Can't ");
  721. SERIAL_PROTOCOLPGM("be used as a PWM because ");
  722. SERIAL_PROTOCOLPGM("of counter mode");
  723. }
  724. static void err_is_interrupt() {
  725. SERIAL_PROTOCOLPGM(" Can't ");
  726. SERIAL_PROTOCOLPGM("be used as a PWM because ");
  727. SERIAL_PROTOCOLPGM("it's ");
  728. SERIAL_PROTOCOLPGM("being used as an interrupt");
  729. }
  730. static void err_prob_interrupt() {
  731. SERIAL_PROTOCOLPGM(" Probably can't ");
  732. SERIAL_PROTOCOLPGM("be used as a PWM because ");
  733. SERIAL_PROTOCOLPGM("counter/timer is ");
  734. SERIAL_PROTOCOLPGM("being used as an interrupt");
  735. }
  736. static void can_be_used() { SERIAL_PROTOCOLPGM(" can be used as PWM "); }
  737. static void PWM_details(uint8_t pin) {
  738. uint8_t WGM;
  739. switch(digitalPinToTimer(pin)) {
  740. #if defined(TCCR0A) && defined(COM0A1)
  741. case TIMER0A:
  742. TIMER_PREFIX(0,A,3);
  743. if (WGM_TEST1) err_is_counter();
  744. else if (TEST(TIMSK0, OCIE0A)) err_is_interrupt();
  745. else if (TEST(TIMSK0, TOIE0)) err_prob_interrupt();
  746. else can_be_used();
  747. break;
  748. case TIMER0B:
  749. TIMER_PREFIX(0,B,3);
  750. if (WGM_TEST1) err_is_counter();
  751. else if (TEST(TIMSK0, OCIE0B)) err_is_interrupt();
  752. else if (TEST(TIMSK0, TOIE0)) err_prob_interrupt();
  753. else can_be_used();
  754. break;
  755. #endif
  756. #if defined(TCCR1A) && defined(COM1A1)
  757. case TIMER1A:
  758. TIMER_PREFIX(1,A,4);
  759. if (WGM_TEST2) err_is_counter();
  760. else if (TEST(TIMSK1, OCIE1A)) err_is_interrupt();
  761. else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt();
  762. else can_be_used();
  763. break;
  764. case TIMER1B:
  765. TIMER_PREFIX(1,B,4);
  766. if (WGM_TEST2) err_is_counter();
  767. else if (TEST(TIMSK1, OCIE1B)) err_is_interrupt();
  768. else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt();
  769. else can_be_used();
  770. break;
  771. case TIMER1C:
  772. TIMER_PREFIX(1,C,4);
  773. if (WGM_TEST2) err_is_counter();
  774. else if (TEST(TIMSK1, OCIE1C)) err_is_interrupt();
  775. else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt();
  776. else can_be_used();
  777. break;
  778. #endif
  779. #if defined(TCCR2A) && defined(COM2A1)
  780. case TIMER2A:
  781. TIMER_PREFIX(2,A,3);
  782. if (WGM_TEST1) err_is_counter();
  783. else if (TIMSK2 & (_BV(TOIE2) | _BV(OCIE2A))) err_is_interrupt();
  784. else if (TEST(TIMSK2, TOIE2)) err_prob_interrupt();
  785. else can_be_used();
  786. break;
  787. case TIMER2B:
  788. TIMER_PREFIX(2,B,3);
  789. if (WGM_TEST1) err_is_counter();
  790. else if (TEST(TIMSK2, OCIE2B)) err_is_interrupt();
  791. else if (TEST(TIMSK2, TOIE2)) err_prob_interrupt();
  792. else can_be_used();
  793. break;
  794. #endif
  795. #if defined(TCCR3A) && defined(COM3A1)
  796. case TIMER3A:
  797. TIMER_PREFIX(3,A,3);
  798. if (WGM_TEST2) err_is_counter();
  799. else if (TEST(TIMSK3, OCIE3A)) err_is_interrupt();
  800. else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt();
  801. else can_be_used();
  802. break;
  803. case TIMER3B:
  804. TIMER_PREFIX(3,B,3);
  805. if (WGM_TEST2) err_is_counter();
  806. else if (TEST(TIMSK3, OCIE3B)) err_is_interrupt();
  807. else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt();
  808. else can_be_used();
  809. break;
  810. case TIMER3C:
  811. TIMER_PREFIX(3,C,3);
  812. if (WGM_TEST2) err_is_counter();
  813. else if (TEST(TIMSK3, OCIE3C)) err_is_interrupt();
  814. else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt();
  815. else can_be_used();
  816. break;
  817. #endif
  818. #ifdef TCCR4A
  819. case TIMER4A:
  820. TIMER_PREFIX(4,A,4);
  821. if (WGM_TEST2) err_is_counter();
  822. else if (TEST(TIMSK4, OCIE4A)) err_is_interrupt();
  823. else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4))) err_prob_interrupt();
  824. else can_be_used();
  825. break;
  826. case TIMER4B:
  827. TIMER_PREFIX(4,B,4);
  828. if (WGM_TEST2) err_is_counter();
  829. else if (TEST(TIMSK4, OCIE4B)) err_is_interrupt();
  830. else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4))) err_prob_interrupt();
  831. else can_be_used();
  832. break;
  833. case TIMER4C:
  834. TIMER_PREFIX(4,C,4);
  835. if (WGM_TEST2) err_is_counter();
  836. else if (TEST(TIMSK4, OCIE4C)) err_is_interrupt();
  837. else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4))) err_prob_interrupt();
  838. else can_be_used();
  839. break;
  840. #endif
  841. #if defined(TCCR5A) && defined(COM5A1)
  842. case TIMER5A:
  843. TIMER_PREFIX(5,A,4);
  844. if (WGM_TEST2) err_is_counter();
  845. else if (TEST(TIMSK5, OCIE5A)) err_is_interrupt();
  846. else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5))) err_prob_interrupt();
  847. else can_be_used();
  848. break;
  849. case TIMER5B:
  850. TIMER_PREFIX(5,B,4);
  851. if (WGM_TEST2) err_is_counter();
  852. else if (TEST(TIMSK5, OCIE5B)) err_is_interrupt();
  853. else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5))) err_prob_interrupt();
  854. else can_be_used();
  855. break;
  856. case TIMER5C:
  857. TIMER_PREFIX(5,C,4);
  858. if (WGM_TEST2) err_is_counter();
  859. else if (TEST(TIMSK5, OCIE5C)) err_is_interrupt();
  860. else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5))) err_prob_interrupt();
  861. else can_be_used();
  862. break;
  863. #endif
  864. case NOT_ON_TIMER: break;
  865. }
  866. SERIAL_PROTOCOLPGM(" ");
  867. } // PWM_details
  868. inline void report_pin_state(int8_t pin) {
  869. SERIAL_ECHO((int)pin);
  870. SERIAL_CHAR(' ');
  871. bool dummy;
  872. if (report_pin_name(pin, dummy)) {
  873. if (pin_is_protected(pin))
  874. SERIAL_ECHOPGM(" (protected)");
  875. else {
  876. SERIAL_ECHOPGM(" = ");
  877. pinMode(pin, INPUT_PULLUP);
  878. SERIAL_ECHO(digitalRead(pin));
  879. if (IS_ANALOG(pin)) {
  880. SERIAL_CHAR(' '); SERIAL_CHAR('(');
  881. SERIAL_ECHO(analogRead(pin - analogInputToDigitalPin(0)));
  882. SERIAL_CHAR(')');
  883. }
  884. }
  885. }
  886. SERIAL_EOL;
  887. }
  888. bool get_pinMode(int8_t pin) { return *portModeRegister(digitalPinToPort(pin)) & digitalPinToBitMask(pin); }
  889. // pretty report with PWM info
  890. inline void report_pin_state_extended(int8_t pin, bool ignore) {
  891. char buffer[30]; // for the sprintf statements
  892. // report pin number
  893. sprintf(buffer, "PIN:% 3d ", pin);
  894. SERIAL_ECHO(buffer);
  895. // report pin name
  896. bool analog_pin;
  897. report_pin_name(pin, analog_pin);
  898. // report pin state
  899. if (pin_is_protected(pin) && !ignore)
  900. SERIAL_ECHOPGM("protected ");
  901. else {
  902. if (analog_pin) {
  903. sprintf(buffer, "Analog in =% 5d", analogRead(pin - analogInputToDigitalPin(0)));
  904. SERIAL_ECHO(buffer);
  905. }
  906. else {
  907. if (!get_pinMode(pin)) {
  908. pinMode(pin, INPUT_PULLUP); // make sure input isn't floating
  909. SERIAL_PROTOCOLPAIR("Input = ", digitalRead_mod(pin));
  910. }
  911. else if (PWM_status(pin)) {
  912. // do nothing
  913. }
  914. else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
  915. }
  916. }
  917. // report PWM capabilities
  918. PWM_details(pin);
  919. SERIAL_EOL;
  920. }