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

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