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_STM32GENERIC.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #pragma once
  20. /**
  21. * Support routines for STM32GENERIC (Maple)
  22. */
  23. /**
  24. * Translation of routines & variables used by pinsDebug.h
  25. */
  26. #ifdef BOARD_NR_GPIO_PINS // Only in STM32GENERIC (Maple)
  27. #ifdef __STM32F1__
  28. #include "../STM32F1/fastio.h"
  29. #elif defined(STM32F4) || defined(STM32F7)
  30. #include "../STM32_F4_F7/fastio.h"
  31. #else
  32. #include "fastio.h"
  33. #endif
  34. extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS];
  35. #define NUM_DIGITAL_PINS BOARD_NR_GPIO_PINS
  36. #define NUMBER_PINS_TOTAL BOARD_NR_GPIO_PINS
  37. #define VALID_PIN(pin) (pin >= 0 && pin < BOARD_NR_GPIO_PINS)
  38. #define GET_ARRAY_PIN(p) pin_t(pin_array[p].pin)
  39. #define pwm_status(pin) PWM_PIN(pin)
  40. #define digitalRead_mod(p) extDigitalRead(p)
  41. #define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3hd "), int16_t(p)); 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 inline int8_t get_pin_mode(pin_t pin) {
  50. return VALID_PIN(pin) ? _GET_MODE(pin) : -1;
  51. }
  52. static inline 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 inline 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 inline bool GET_PINMODE(const pin_t pin) {
  71. return VALID_PIN(pin) && !IS_INPUT(pin);
  72. }
  73. static inline 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 inline 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 inline 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. }
  109. #endif // BOARD_NR_GPIO_PINS