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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * Support routines for MAPLE_STM32F1
  25. */
  26. /**
  27. * Translation of routines & variables used by pinsDebug.h
  28. */
  29. #ifndef BOARD_NR_GPIO_PINS // Only in MAPLE_STM32F1
  30. #error "Expected BOARD_NR_GPIO_PINS not found"
  31. #endif
  32. #include "fastio.h"
  33. extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS];
  34. #define NUM_DIGITAL_PINS BOARD_NR_GPIO_PINS
  35. #define NUMBER_PINS_TOTAL BOARD_NR_GPIO_PINS
  36. #define VALID_PIN(pin) (pin >= 0 && pin < BOARD_NR_GPIO_PINS)
  37. #define GET_ARRAY_PIN(p) pin_t(pin_array[p].pin)
  38. #define pwm_status(pin) PWM_PIN(pin)
  39. #define digitalRead_mod(p) extDigitalRead(p)
  40. #define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3hd "), int16_t(p)); SERIAL_ECHO(buffer); }while(0)
  41. #define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
  42. #define PRINT_PORT(p) print_port(p)
  43. #define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
  44. #define MULTI_NAME_PAD 21 // space needed to be pretty if not first name assigned to a pin
  45. // pins that will cause hang/reset/disconnect in M43 Toggle and Watch utilities
  46. #ifndef M43_NEVER_TOUCH
  47. #define M43_NEVER_TOUCH(Q) (Q >= 9 && Q <= 12) // SERIAL/USB pins PA9(TX) PA10(RX)
  48. #endif
  49. static int8_t get_pin_mode(pin_t pin) {
  50. return VALID_PIN(pin) ? _GET_MODE(pin) : -1;
  51. }
  52. static pin_t DIGITAL_PIN_TO_ANALOG_PIN(pin_t pin) {
  53. if (!VALID_PIN(pin)) return -1;
  54. int8_t adc_channel = int8_t(PIN_MAP[pin].adc_channel);
  55. #ifdef NUM_ANALOG_INPUTS
  56. if (adc_channel >= NUM_ANALOG_INPUTS) adc_channel = ADCx;
  57. #endif
  58. return pin_t(adc_channel);
  59. }
  60. static bool IS_ANALOG(pin_t pin) {
  61. if (!VALID_PIN(pin)) return false;
  62. if (PIN_MAP[pin].adc_channel != ADCx) {
  63. #ifdef NUM_ANALOG_INPUTS
  64. if (PIN_MAP[pin].adc_channel >= NUM_ANALOG_INPUTS) return false;
  65. #endif
  66. return _GET_MODE(pin) == GPIO_INPUT_ANALOG && !M43_NEVER_TOUCH(pin);
  67. }
  68. return false;
  69. }
  70. static bool GET_PINMODE(const pin_t pin) {
  71. return VALID_PIN(pin) && !IS_INPUT(pin);
  72. }
  73. static bool GET_ARRAY_IS_DIGITAL(const int16_t array_pin) {
  74. const pin_t pin = GET_ARRAY_PIN(array_pin);
  75. return (!IS_ANALOG(pin)
  76. #ifdef NUM_ANALOG_INPUTS
  77. || PIN_MAP[pin].adc_channel >= NUM_ANALOG_INPUTS
  78. #endif
  79. );
  80. }
  81. #include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
  82. static void pwm_details(const pin_t pin) {
  83. if (PWM_PIN(pin)) {
  84. timer_dev * const tdev = PIN_MAP[pin].timer_device;
  85. const uint8_t channel = PIN_MAP[pin].timer_channel;
  86. const char num = (
  87. #if EITHER(STM32_HIGH_DENSITY, STM32_XL_DENSITY)
  88. tdev == &timer8 ? '8' :
  89. tdev == &timer5 ? '5' :
  90. #endif
  91. tdev == &timer4 ? '4' :
  92. tdev == &timer3 ? '3' :
  93. tdev == &timer2 ? '2' :
  94. tdev == &timer1 ? '1' : '?'
  95. );
  96. char buffer[10];
  97. sprintf_P(buffer, PSTR(" TIM%c CH%c"), num, ('0' + channel));
  98. SERIAL_ECHO(buffer);
  99. }
  100. }
  101. static void print_port(pin_t pin) {
  102. const char port = 'A' + char(pin >> 4); // pin div 16
  103. const int16_t gbit = PIN_MAP[pin].gpio_bit;
  104. char buffer[8];
  105. sprintf_P(buffer, PSTR("P%c%hd "), port, gbit);
  106. if (gbit < 10) SERIAL_CHAR(' ');
  107. SERIAL_ECHO(buffer);
  108. }