Browse Source

Fix HAL/STM32 FastIO for analog pins (#19735)

Serhiy-K 3 years ago
parent
commit
cc7fbabc96
2 changed files with 9 additions and 11 deletions
  1. 5
    5
      Marlin/src/HAL/STM32/fastio.h
  2. 4
    6
      Marlin/src/HAL/STM32/pinsDebug_STM32duino.h

+ 5
- 5
Marlin/src/HAL/STM32/fastio.h View File

@@ -51,15 +51,15 @@ void FastIO_init(); // Must be called before using fast io macros
51 51
 
52 52
 #if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx)
53 53
   #define _WRITE(IO, V) do { \
54
-    if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \
55
-    else   FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR  = _BV32(STM_PIN(digitalPin[IO])) ; \
54
+    if (V) FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BSRR = _BV32(STM_PIN(digitalPinToPinName(IO))) ; \
55
+    else   FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BRR  = _BV32(STM_PIN(digitalPinToPinName(IO))) ; \
56 56
   }while(0)
57 57
 #else
58
-  #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + ((V) ? 0 : 16)))
58
+  #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BSRR = _BV32(STM_PIN(digitalPinToPinName(IO)) + ((V) ? 0 : 16)))
59 59
 #endif
60 60
 
61
-#define _READ(IO)               bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO]))))
62
-#define _TOGGLE(IO)             (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO])))
61
+#define _READ(IO)               bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->IDR, _BV32(STM_PIN(digitalPinToPinName(IO)))))
62
+#define _TOGGLE(IO)             (FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->ODR ^= _BV32(STM_PIN(digitalPinToPinName(IO))))
63 63
 
64 64
 #define _GET_MODE(IO)
65 65
 #define _SET_MODE(IO,M)         pinMode(IO, M)

+ 4
- 6
Marlin/src/HAL/STM32/pinsDebug_STM32duino.h View File

@@ -51,8 +51,8 @@
51 51
  *  It contains:
52 52
  *    - name of the signal
53 53
  *    - the Ard_num assigned by the pins_YOUR_BOARD.h file using the platform defines.
54
- *        EXAMPLE:  "#define KILL_PIN  PB1" results in Ard_num of 57.  57 is then used as an
55
- *                  index into digitalPin[] to get the Port_pin number
54
+ *        EXAMPLE:  "#define KILL_PIN  PB1" results in Ard_num of 57.  57 is then used as the
55
+ *                  argument to digitalPinToPinName(IO) to get the Port_pin number
56 56
  *    - if it is a digital or analog signal.  PWMs are considered digital here.
57 57
  *
58 58
  *  pin_xref is a structure generated by this header file.  It is generated by the
@@ -68,8 +68,6 @@
68 68
  *          signal.  The Arduino pin number is listed by the M43 I command.
69 69
  */
70 70
 
71
-extern const PinName digitalPin[];  // provided by the platform
72
-
73 71
 ////////////////////////////////////////////////////////
74 72
 //
75 73
 // make a list of the Arduino pin numbers in the Port/Pin order
@@ -137,7 +135,7 @@ const XrefInfo pin_xref[] PROGMEM = {
137 135
 
138 136
 uint8_t get_pin_mode(const pin_t Ard_num) {
139 137
   uint32_t mode_all = 0;
140
-  const PinName dp = digitalPin[Ard_num];
138
+  const PinName dp = digitalPinToPinName(Ard_num);
141 139
   switch (PORT_ALPHA(dp)) {
142 140
     case 'A' : mode_all = GPIOA->MODER; break;
143 141
     case 'B' : mode_all = GPIOB->MODER; break;
@@ -218,7 +216,7 @@ bool pwm_status(const pin_t Ard_num) {
218 216
 void pwm_details(const pin_t Ard_num) {
219 217
   if (pwm_status(Ard_num)) {
220 218
     uint32_t alt_all = 0;
221
-    const PinName dp = digitalPin[Ard_num];
219
+    const PinName dp = digitalPinToPinName(Ard_num);
222 220
     pin_t pin_number = uint8_t(PIN_NUM(dp));
223 221
     const bool over_7 = pin_number >= 8;
224 222
     const uint8_t ind = over_7 ? 1 : 0;

Loading…
Cancel
Save