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.

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