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