Tanguy Pruvot 5 лет назад
Родитель
Сommit
52383633e7

+ 13
- 1
Marlin/src/HAL/HAL_STM32F1/HAL.cpp Просмотреть файл

@@ -32,9 +32,10 @@
32 32
 // --------------------------------------------------------------------------
33 33
 
34 34
 #include "HAL.h"
35
-#include <STM32ADC.h>
36 35
 #include "../../inc/MarlinConfig.h"
37 36
 
37
+#include <STM32ADC.h>
38
+
38 39
 // --------------------------------------------------------------------------
39 40
 // Externals
40 41
 // --------------------------------------------------------------------------
@@ -314,4 +315,15 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) {
314 315
 
315 316
 uint16_t HAL_adc_get_result(void) { return HAL_adc_result; }
316 317
 
318
+uint16_t analogRead(pin_t pin) {
319
+  const bool is_analog = _GET_MODE(pin) == GPIO_INPUT_ANALOG;
320
+  return is_analog ? analogRead(uint8_t(pin)) : 0;
321
+}
322
+
323
+// Wrapper to maple unprotected analogWrite
324
+void analogWrite(pin_t pin, int pwm_val8) {
325
+  if (PWM_PIN(pin) && IS_OUTPUT(pin))
326
+    analogWrite(uint8_t(pin), pwm_val8);
327
+}
328
+
317 329
 #endif // __STM32F1__

+ 3
- 0
Marlin/src/HAL/HAL_STM32F1/HAL.h Просмотреть файл

@@ -255,6 +255,9 @@ void HAL_adc_init(void);
255 255
 void HAL_adc_start_conversion(const uint8_t adc_pin);
256 256
 uint16_t HAL_adc_get_result(void);
257 257
 
258
+uint16_t analogRead(pin_t pin); // need HAL_ANALOG_SELECT() first
259
+void analogWrite(pin_t pin, int pwm_val8); // PWM only! mul by 257 in maple!?
260
+
258 261
 #define GET_PIN_MAP_PIN(index) index
259 262
 #define GET_PIN_MAP_INDEX(pin) pin
260 263
 #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

+ 127
- 1
Marlin/src/HAL/HAL_STM32F1/pinsDebug.h Просмотреть файл

@@ -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__

+ 3
- 1
Marlin/src/feature/leds/leds.cpp Просмотреть файл

@@ -118,7 +118,9 @@ void LEDLights::set_color(const LEDColor &incol
118 118
 
119 119
     // This variant uses 3-4 separate pins for the RGB(W) components.
120 120
     // If the pins can do PWM then their intensity will be set.
121
-    #define UPDATE_RGBW(C,c) do{ if (PWM_PIN(RGB_LED_##C##_PIN)) analogWrite(RGB_LED_##C##_PIN, incol.c); else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
121
+    #define UPDATE_RGBW(C,c) do { if (PWM_PIN(RGB_LED_##C##_PIN)) \
122
+        analogWrite(pin_t(RGB_LED_##C##_PIN), incol.c); \
123
+      else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); } while(0)
122 124
     UPDATE_RGBW(R,r);
123 125
     UPDATE_RGBW(G,g);
124 126
     UPDATE_RGBW(B,b);

+ 1
- 1
Marlin/src/module/endstops.cpp Просмотреть файл

@@ -896,7 +896,7 @@ void Endstops::update() {
896 896
         ES_REPORT_CHANGE(Z3_MAX);
897 897
       #endif
898 898
       SERIAL_ECHOLNPGM("\n");
899
-      analogWrite(LED_PIN, local_LED_status);
899
+      analogWrite(pin_t(LED_PIN), local_LED_status);
900 900
       local_LED_status ^= 255;
901 901
       old_live_state_local = live_state_local;
902 902
     }

+ 3
- 3
Marlin/src/module/planner.cpp Просмотреть файл

@@ -1294,13 +1294,13 @@ void Planner::check_axes_activity() {
1294 1294
     #else
1295 1295
 
1296 1296
       #if HAS_FAN0
1297
-        analogWrite(FAN_PIN, CALC_FAN_SPEED(0));
1297
+        analogWrite(pin_t(FAN_PIN), CALC_FAN_SPEED(0));
1298 1298
       #endif
1299 1299
       #if HAS_FAN1
1300
-        analogWrite(FAN1_PIN, CALC_FAN_SPEED(1));
1300
+        analogWrite(pin_t(FAN1_PIN), CALC_FAN_SPEED(1));
1301 1301
       #endif
1302 1302
       #if HAS_FAN2
1303
-        analogWrite(FAN2_PIN, CALC_FAN_SPEED(2));
1303
+        analogWrite(pin_t(FAN2_PIN), CALC_FAN_SPEED(2));
1304 1304
       #endif
1305 1305
     #endif
1306 1306
   #else

Загрузка…
Отмена
Сохранить