7979// make a list of the Arduino pin numbers in the Port/Pin order
8080//
8181
82- #define _PIN_ADD_2 (NAME_ALPHA , ARDUINO_NUM ) { {NAME_ALPHA}, ARDUINO_NUM },
8382#define _PIN_ADD (NAME_ALPHA , ARDUINO_NUM ) { NAME_ALPHA, ARDUINO_NUM },
8483#define PIN_ADD (NAME ) _PIN_ADD(#NAME, NAME)
8584
@@ -108,7 +107,11 @@ const XrefInfo pin_xref[] PROGMEM = {
108107/**
109108 * Translation of routines & variables used by pinsDebug.h
110109 */
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)
112115#define VALID_PIN (ANUM ) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
113116#define digitalRead_mod (Ard_num ) extDigitalRead(Ard_num) // must use Arduino pin numbers when doing reads
114117#define PRINT_PIN (Q )
@@ -164,17 +167,20 @@ bool GET_PINMODE(const pin_t Ard_num) {
164167 return pin_mode == MODE_PIN_OUTPUT || pin_mode == MODE_PIN_ALT ; // assume all alt definitions are PWM
165168}
166169
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 ;
170176}
171177
172178bool IS_ANALOG (const pin_t Ard_num ) {
173179 return get_pin_mode (Ard_num ) == MODE_PIN_ANALOG ;
174180}
175181
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 );
178184 return pin_mode == MODE_PIN_INPUT || pin_mode == MODE_PIN_OUTPUT ;
179185}
180186
@@ -200,10 +206,15 @@ void port_print(const pin_t Ard_num) {
200206 SERIAL_ECHO_SP (7 );
201207
202208 // 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+ }
207218}
208219
209220bool pwm_status (const pin_t Ard_num ) {
@@ -225,19 +236,19 @@ void pwm_details(const pin_t Ard_num) {
225236 case 'D' : alt_all = GPIOD -> AFR [ind ]; break ;
226237 #ifdef PE_0
227238 case 'E' : alt_all = GPIOE -> AFR [ind ]; break ;
228- #elif defined (PF_0 )
239+ #elif defined(PF_0 )
229240 case 'F' : alt_all = GPIOF -> AFR [ind ]; break ;
230- #elif defined (PG_0 )
241+ #elif defined(PG_0 )
231242 case 'G' : alt_all = GPIOG -> AFR [ind ]; break ;
232- #elif defined (PH_0 )
243+ #elif defined(PH_0 )
233244 case 'H' : alt_all = GPIOH -> AFR [ind ]; break ;
234- #elif defined (PI_0 )
245+ #elif defined(PI_0 )
235246 case 'I' : alt_all = GPIOI -> AFR [ind ]; break ;
236- #elif defined (PJ_0 )
247+ #elif defined(PJ_0 )
237248 case 'J' : alt_all = GPIOJ -> AFR [ind ]; break ;
238- #elif defined (PK_0 )
249+ #elif defined(PK_0 )
239250 case 'K' : alt_all = GPIOK -> AFR [ind ]; break ;
240- #elif defined (PL_0 )
251+ #elif defined(PL_0 )
241252 case 'L' : alt_all = GPIOL -> AFR [ind ]; break ;
242253 #endif
243254 }
0 commit comments