|
@@ -1 +1,127 @@
|
1
|
|
-#error Debug pins is not supported on this Platform!
|
|
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
|
+
|
|
20
|
+/**
|
|
21
|
+ * Support routines for STM32F1
|
|
22
|
+ */
|
|
23
|
+#ifdef __STM32F1__
|
|
24
|
+
|
|
25
|
+/**
|
|
26
|
+ * Translation of routines & variables used by pinsDebug.h
|
|
27
|
+ */
|
|
28
|
+#include "fastio_STM32F1.h"
|
|
29
|
+
|
|
30
|
+extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS];
|
|
31
|
+
|
|
32
|
+#define NUM_DIGITAL_PINS BOARD_NR_GPIO_PINS
|
|
33
|
+#define NUMBER_PINS_TOTAL BOARD_NR_GPIO_PINS
|
|
34
|
+#define VALID_PIN(pin) (pin >= 0 && pin < BOARD_NR_GPIO_PINS)
|
|
35
|
+#define GET_ARRAY_PIN(p) pin_t(pin_array[p].pin)
|
|
36
|
+#define pwm_status(pin) PWM_PIN(pin)
|
|
37
|
+#define digitalRead_mod(p) extDigitalRead(p)
|
|
38
|
+#define NAME_FORMAT(p) PSTR("%-##p##s")
|
|
39
|
+#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3hd "), int16_t(p)); SERIAL_ECHO(buffer); }while(0)
|
|
40
|
+#define PRINT_PORT(p) print_port(p)
|
|
41
|
+#define PRINT_ARRAY_NAME(x) do {sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
|
|
42
|
+#define MULTI_NAME_PAD 20 // spaces needed to be pretty if not first name assigned to a pin
|
|
43
|
+
|
|
44
|
+// pins that will cause hang/reset/disconnect in M43 Toggle and Watch utilities
|
|
45
|
+#ifndef M43_NEVER_TOUCH
|
|
46
|
+ #define M43_NEVER_TOUCH(Q) (Q >= 9 && Q <= 12) // SERIAL/USB pins PA9(TX) PA10(RX)
|
|
47
|
+#endif
|
|
48
|
+
|
|
49
|
+static inline int8_t get_pin_mode(pin_t pin) {
|
|
50
|
+ return VALID_PIN(pin) ? _GET_MODE(pin) : -1;
|
|
51
|
+}
|
|
52
|
+
|
|
53
|
+static inline pin_t DIGITAL_PIN_TO_ANALOG_PIN(pin_t pin) {
|
|
54
|
+ if (!VALID_PIN(pin)) return -1;
|
|
55
|
+ int8_t adc_channel = int8_t(PIN_MAP[pin].adc_channel);
|
|
56
|
+ #ifdef NUM_ANALOG_INPUTS
|
|
57
|
+ if (adc_channel >= NUM_ANALOG_INPUTS) adc_channel = ADCx;
|
|
58
|
+ #endif
|
|
59
|
+ return pin_t(adc_channel);
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+static inline bool IS_ANALOG(pin_t pin) {
|
|
63
|
+ if (!VALID_PIN(pin)) return false;
|
|
64
|
+ if (PIN_MAP[pin].adc_channel != ADCx) {
|
|
65
|
+ #ifdef NUM_ANALOG_INPUTS
|
|
66
|
+ if (PIN_MAP[pin].adc_channel >= NUM_ANALOG_INPUTS) return false;
|
|
67
|
+ #endif
|
|
68
|
+ return _GET_MODE(pin) == GPIO_INPUT_ANALOG && !M43_NEVER_TOUCH(pin);
|
|
69
|
+ }
|
|
70
|
+ return false;
|
|
71
|
+}
|
|
72
|
+
|
|
73
|
+static inline bool GET_PINMODE(pin_t pin) {
|
|
74
|
+ return VALID_PIN(pin) ? !IS_INPUT(pin) : false;
|
|
75
|
+}
|
|
76
|
+
|
|
77
|
+static inline bool GET_ARRAY_IS_DIGITAL(int16_t array_pin) {
|
|
78
|
+ pin_t pin = GET_ARRAY_PIN(array_pin);
|
|
79
|
+ bool isDigital = !IS_ANALOG(pin);
|
|
80
|
+ #ifdef NUM_ANALOG_INPUTS
|
|
81
|
+ if (!isDigital && PIN_MAP[pin].adc_channel >= NUM_ANALOG_INPUTS)
|
|
82
|
+ isDigital = true;
|
|
83
|
+ #endif
|
|
84
|
+ return isDigital;
|
|
85
|
+}
|
|
86
|
+
|
|
87
|
+static inline void pwm_details(pin_t pin) {
|
|
88
|
+ if (PWM_PIN(pin)) {
|
|
89
|
+ char buffer[16], num = '?';
|
|
90
|
+ timer_dev * const tdev = PIN_MAP[pin].timer_device;
|
|
91
|
+ const uint8_t channel = PIN_MAP[pin].timer_channel;
|
|
92
|
+ if (tdev == &timer1) num = '1';
|
|
93
|
+ else if (tdev == &timer1) num = '1';
|
|
94
|
+ else if (tdev == &timer2) num = '2';
|
|
95
|
+ else if (tdev == &timer3) num = '3';
|
|
96
|
+ else if (tdev == &timer4) num = '4';
|
|
97
|
+ #ifdef STM32_HIGH_DENSITY
|
|
98
|
+ else if (tdev == &timer5) num = '5';
|
|
99
|
+ else if (tdev == &timer8) num = '8';
|
|
100
|
+ #endif
|
|
101
|
+ sprintf_P(buffer, PSTR(" TIM%c CH%c"), num, ('0' + channel));
|
|
102
|
+ SERIAL_ECHO(buffer);
|
|
103
|
+ }
|
|
104
|
+}
|
|
105
|
+
|
|
106
|
+static inline void print_port(pin_t pin) {
|
|
107
|
+ char buffer[8];
|
|
108
|
+ char port = 'A' + char(pin >> 4); // pin div 16
|
|
109
|
+ /* seems not to be required for our devices
|
|
110
|
+ gpio_dev* gp = PIN_MAP[pin].gpio_device;
|
|
111
|
+ if (gp == &gpioa) port = 'A';
|
|
112
|
+ else if (gp == &gpiob) port = 'B';
|
|
113
|
+ else if (gp == &gpioc) port = 'C';
|
|
114
|
+ else if (gp == &gpiod) port = 'D';
|
|
115
|
+ #if STM32_NR_GPIO_PORTS > 4
|
|
116
|
+ else if (gp == &gpioe) port = 'E';
|
|
117
|
+ else if (gp == &gpiof) port = 'F';
|
|
118
|
+ else if (gp == &gpiog) port = 'G';
|
|
119
|
+ #endif
|
|
120
|
+ */
|
|
121
|
+ const int16_t gbit = PIN_MAP[pin].gpio_bit;
|
|
122
|
+ sprintf_P(buffer, PSTR("P%c%hd "), port, gbit);
|
|
123
|
+ if (gbit < 10) SERIAL_CHAR(' ');
|
|
124
|
+ SERIAL_ECHO(buffer);
|
|
125
|
+}
|
|
126
|
+
|
|
127
|
+#endif // __STM32F1__
|