79
79
// make a list of the Arduino pin numbers in the Port/Pin order
80
80
//
81
81
82
- #define _PIN_ADD_2 (NAME_ALPHA , ARDUINO_NUM ) { {NAME_ALPHA}, ARDUINO_NUM },
83
82
#define _PIN_ADD (NAME_ALPHA , ARDUINO_NUM ) { NAME_ALPHA, ARDUINO_NUM },
84
83
#define PIN_ADD (NAME ) _PIN_ADD(#NAME, NAME)
85
84
@@ -108,7 +107,11 @@ const XrefInfo pin_xref[] PROGMEM = {
108
107
/**
109
108
* Translation of routines & variables used by pinsDebug.h
110
109
*/
111
- #define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
110
+
111
+ #if PA0 >= NUM_DIGITAL_PINS
112
+ #define HAS_HIGH_ANALOG_PINS 1
113
+ #endif
114
+ #define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS + TERN0(HAS_HIGH_ANALOG_PINS, NUM_ANALOG_INPUTS)
112
115
#define VALID_PIN (ANUM ) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
113
116
#define digitalRead_mod (Ard_num ) extDigitalRead(Ard_num) // must use Arduino pin numbers when doing reads
114
117
#define PRINT_PIN (Q )
@@ -164,17 +167,20 @@ bool GET_PINMODE(const pin_t Ard_num) {
164
167
return pin_mode == MODE_PIN_OUTPUT || pin_mode == MODE_PIN_ALT ; // assume all alt definitions are PWM
165
168
}
166
169
167
- int8_t digital_pin_to_analog_pin (pin_t Ard_num ) {
168
- Ard_num -= NUM_ANALOG_FIRST ;
169
- return (Ard_num >= 0 && Ard_num < NUM_ANALOG_INPUTS ) ? Ard_num : -1 ;
170
+ 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
+ return Ard_num - NUM_ANALOG_FIRST ;
173
+
174
+ const uint32_t ind = digitalPinToAnalogInput (Ard_num );
175
+ return (ind < NUM_ANALOG_INPUTS ) ? ind : -1 ;
170
176
}
171
177
172
178
bool IS_ANALOG (const pin_t Ard_num ) {
173
179
return get_pin_mode (Ard_num ) == MODE_PIN_ANALOG ;
174
180
}
175
181
176
- bool is_digital (const pin_t x ) {
177
- const uint8_t pin_mode = get_pin_mode (pin_array [x ].pin );
182
+ bool is_digital (const pin_t Ard_num ) {
183
+ const uint8_t pin_mode = get_pin_mode (pin_array [Ard_num ].pin );
178
184
return pin_mode == MODE_PIN_INPUT || pin_mode == MODE_PIN_OUTPUT ;
179
185
}
180
186
@@ -200,10 +206,15 @@ void port_print(const pin_t Ard_num) {
200
206
SERIAL_ECHO_SP (7 );
201
207
202
208
// Print number to be used with M42
203
- sprintf_P (buffer , PSTR (" M42 P%d " ), Ard_num );
204
- SERIAL_ECHO (buffer );
205
- if (Ard_num < 10 ) SERIAL_CHAR (' ' );
206
- if (Ard_num < 100 ) SERIAL_CHAR (' ' );
209
+ int calc_p = Ard_num % (NUM_DIGITAL_PINS + 1 );
210
+ if (Ard_num > NUM_DIGITAL_PINS && calc_p > 7 ) calc_p += 8 ;
211
+ SERIAL_ECHOPGM (" M42 P" , calc_p );
212
+ SERIAL_CHAR (' ' );
213
+ if (calc_p < 100 ) {
214
+ SERIAL_CHAR (' ' );
215
+ if (calc_p < 10 )
216
+ SERIAL_CHAR (' ' );
217
+ }
207
218
}
208
219
209
220
bool pwm_status (const pin_t Ard_num ) {
@@ -225,19 +236,19 @@ void pwm_details(const pin_t Ard_num) {
225
236
case 'D' : alt_all = GPIOD -> AFR [ind ]; break ;
226
237
#ifdef PE_0
227
238
case 'E' : alt_all = GPIOE -> AFR [ind ]; break ;
228
- #elif defined (PF_0 )
239
+ #elif defined(PF_0 )
229
240
case 'F' : alt_all = GPIOF -> AFR [ind ]; break ;
230
- #elif defined (PG_0 )
241
+ #elif defined(PG_0 )
231
242
case 'G' : alt_all = GPIOG -> AFR [ind ]; break ;
232
- #elif defined (PH_0 )
243
+ #elif defined(PH_0 )
233
244
case 'H' : alt_all = GPIOH -> AFR [ind ]; break ;
234
- #elif defined (PI_0 )
245
+ #elif defined(PI_0 )
235
246
case 'I' : alt_all = GPIOI -> AFR [ind ]; break ;
236
- #elif defined (PJ_0 )
247
+ #elif defined(PJ_0 )
237
248
case 'J' : alt_all = GPIOJ -> AFR [ind ]; break ;
238
- #elif defined (PK_0 )
249
+ #elif defined(PK_0 )
239
250
case 'K' : alt_all = GPIOK -> AFR [ind ]; break ;
240
- #elif defined (PL_0 )
251
+ #elif defined(PL_0 )
241
252
case 'L' : alt_all = GPIOL -> AFR [ind ]; break ;
242
253
#endif
243
254
}
0 commit comments