Browse Source

🧑‍💻 STM32G0B1RE Pins Debugging (#24748)

Chris Bagwell 2 years ago
parent
commit
9467b68608
No account linked to committer's email address

+ 1
- 1
Marlin/src/HAL/DUE/pinsDebug.h View File

@@ -70,7 +70,7 @@
70 70
 #define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d)  "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
71 71
 #define GET_ARRAY_PIN(p) pin_array[p].pin
72 72
 #define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
73
-#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL ? 1 : 0)
73
+#define VALID_PIN(pin) (pin >= 0 && pin < int8_t(NUMBER_PINS_TOTAL))
74 74
 #define DIGITAL_PIN_TO_ANALOG_PIN(p) int(p - analogInputToDigitalPin(0))
75 75
 #define IS_ANALOG(P) WITHIN(P, char(analogInputToDigitalPin(0)), char(analogInputToDigitalPin(NUM_ANALOG_INPUTS - 1)))
76 76
 #define pwm_status(pin) (((g_pinStatus[pin] & 0xF) == PIN_STATUS_PWM) && \

+ 1
- 1
Marlin/src/HAL/SAMD51/pinsDebug.h View File

@@ -29,7 +29,7 @@
29 29
 #define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d)  "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
30 30
 #define GET_ARRAY_PIN(p) pin_array[p].pin
31 31
 #define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
32
-#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL)
32
+#define VALID_PIN(pin) (pin >= 0 && pin < int8_t(NUMBER_PINS_TOTAL))
33 33
 #define DIGITAL_PIN_TO_ANALOG_PIN(p) digitalPinToAnalogInput(p)
34 34
 #define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P)!=-1)
35 35
 #define pwm_status(pin) digitalPinHasPWM(pin)

+ 11
- 7
Marlin/src/HAL/STM32/pinsDebug.h View File

@@ -102,17 +102,18 @@ const XrefInfo pin_xref[] PROGMEM = {
102 102
 #define PIN_NUM_ALPHA_LEFT(P) (((P & 0x000F) < 10) ? ('0' + (P & 0x000F)) : '1')
103 103
 #define PIN_NUM_ALPHA_RIGHT(P) (((P & 0x000F) > 9)  ? ('0' + (P & 0x000F) - 10) : 0 )
104 104
 #define PORT_NUM(P) ((P  >> 4) & 0x0007)
105
-#define PORT_ALPHA(P) ('A' + (P  >> 4))
105
+#define PORT_ALPHA(P) ('A' + (P >> 4))
106 106
 
107 107
 /**
108 108
  * Translation of routines & variables used by pinsDebug.h
109 109
  */
110 110
 
111
-#if PA0 >= NUM_DIGITAL_PINS
111
+#if NUM_ANALOG_FIRST >= NUM_DIGITAL_PINS
112 112
   #define HAS_HIGH_ANALOG_PINS 1
113 113
 #endif
114
-#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS + TERN0(HAS_HIGH_ANALOG_PINS, NUM_ANALOG_INPUTS)
115
-#define VALID_PIN(ANUM) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
114
+#define NUM_ANALOG_LAST ((NUM_ANALOG_FIRST) + (NUM_ANALOG_INPUTS) - 1)
115
+#define NUMBER_PINS_TOTAL ((NUM_DIGITAL_PINS) + TERN0(HAS_HIGH_ANALOG_PINS, NUM_ANALOG_INPUTS))
116
+#define VALID_PIN(P) (WITHIN(P, 0, (NUM_DIGITAL_PINS) - 1) || TERN0(HAS_HIGH_ANALOG_PINS, WITHIN(P, NUM_ANALOG_FIRST, NUM_ANALOG_LAST)))
116 117
 #define digitalRead_mod(Ard_num) extDigitalRead(Ard_num)  // must use Arduino pin numbers when doing reads
117 118
 #define PRINT_PIN(Q)
118 119
 #define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d)  "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
@@ -168,7 +169,7 @@ bool GET_PINMODE(const pin_t Ard_num) {
168 169
 }
169 170
 
170 171
 int8_t digital_pin_to_analog_pin(const pin_t Ard_num) {
171
-  if (WITHIN(Ard_num, NUM_ANALOG_FIRST, NUM_ANALOG_FIRST + NUM_ANALOG_INPUTS - 1))
172
+  if (WITHIN(Ard_num, NUM_ANALOG_FIRST, NUM_ANALOG_LAST))
172 173
     return Ard_num - NUM_ANALOG_FIRST;
173 174
 
174 175
   const uint32_t ind = digitalPinToAnalogInput(Ard_num);
@@ -206,8 +207,11 @@ void port_print(const pin_t Ard_num) {
206 207
     SERIAL_ECHO_SP(7);
207 208
 
208 209
   // Print number to be used with M42
209
-  int calc_p = Ard_num % (NUM_DIGITAL_PINS + 1);
210
-  if (Ard_num > NUM_DIGITAL_PINS && calc_p > 7) calc_p += 8;
210
+  int calc_p = Ard_num;
211
+  if (Ard_num > NUM_DIGITAL_PINS) {
212
+    calc_p -= NUM_ANALOG_FIRST;
213
+    if (calc_p > 7) calc_p += 8;
214
+  }
211 215
   SERIAL_ECHOPGM(" M42 P", calc_p);
212 216
   SERIAL_CHAR(' ');
213 217
   if (calc_p < 100) {

+ 1
- 1
Marlin/src/HAL/TEENSY40_41/pinsDebug.h View File

@@ -36,7 +36,7 @@
36 36
 #define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d)  "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
37 37
 #define GET_ARRAY_PIN(p) pin_array[p].pin
38 38
 #define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
39
-#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL ? 1 : 0)
39
+#define VALID_PIN(pin) (pin >= 0 && pin < int8_t(NUMBER_PINS_TOTAL))
40 40
 #define DIGITAL_PIN_TO_ANALOG_PIN(p) int(p - analogInputToDigitalPin(0))
41 41
 #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && (P) <= analogInputToDigitalPin(13)) || ((P) >= analogInputToDigitalPin(14) && (P) <= analogInputToDigitalPin(17))
42 42
 #define pwm_status(pin) HAL_pwm_status(pin)

+ 1
- 1
Marlin/src/gcode/config/M43.cpp View File

@@ -313,7 +313,7 @@ void GcodeSuite::M43() {
313 313
 
314 314
   // 'P' Get the range of pins to test or watch
315 315
   uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
316
-          last_pin = parser.seenval('P') ? first_pin : TERN(HAS_HIGH_ANALOG_PINS, NUM_DIGITAL_PINS, NUMBER_PINS_TOTAL) - 1;
316
+          last_pin = parser.seenval('P') ? first_pin : (NUMBER_PINS_TOTAL) - 1;
317 317
 
318 318
   if (first_pin > last_pin) return;
319 319
 

+ 1
- 0
buildroot/share/PlatformIO/variants/MARLIN_G0B1RE/variant_MARLIN_STM32G0B1RE.h View File

@@ -124,6 +124,7 @@
124 124
 #define NUM_DIGITAL_PINS        62
125 125
 #define NUM_REMAP_PINS          2
126 126
 #define NUM_ANALOG_INPUTS       16
127
+#define NUM_ANALOG_FIRST        PA0
127 128
 
128 129
 // SPI definitions
129 130
 #ifndef PIN_SPI_SS

Loading…
Cancel
Save