23 #ifdef NUM_DIGITAL_PINS // Only in ST's Arduino core (STM32duino, STM32Core)
78 #define _PIN_ADD_2(NAME_ALPHA, ARDUINO_NUM) { {NAME_ALPHA}, ARDUINO_NUM },
79 #define _PIN_ADD(NAME_ALPHA, ARDUINO_NUM) { NAME_ALPHA, ARDUINO_NUM },
80 #define PIN_ADD(NAME) _PIN_ADD(#NAME, NAME)
83 char Port_pin_alpha[5];
87 const XrefInfo pin_xref[]
PROGMEM = {
93 #define MODE_PIN_INPUT 0 // Input mode (reset state)
94 #define MODE_PIN_OUTPUT 1 // General purpose output mode
95 #define MODE_PIN_ALT 2 // Alternate function mode
96 #define MODE_PIN_ANALOG 3 // Analog mode
98 #define PIN_NUM(P) (P & 0x000F)
99 #define PIN_NUM_ALPHA_LEFT(P) (((P & 0x000F) < 10) ? ('0' + (P & 0x000F)) : '1')
100 #define PIN_NUM_ALPHA_RIGHT(P) (((P & 0x000F) > 9) ? ('0' + (P & 0x000F) - 10) : 0 )
101 #define PORT_NUM(P) ((P >> 4) & 0x0007)
102 #define PORT_ALPHA(P) ('A' + (P >> 4))
107 #define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
108 #define VALID_PIN(ANUM) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
109 #define digitalRead_mod(Ard_num) extDigitalRead(Ard_num) // must use Arduino pin numbers when doing reads
111 #define PRINT_PORT(ANUM) port_print(ANUM)
112 #define DIGITAL_PIN_TO_ANALOG_PIN(ANUM) -1 // will report analog pin number in the print port routine
113 #define GET_PIN_MAP_PIN_M43(Index) pin_xref[Index].Ard_num
116 #define GET_ARRAY_IS_DIGITAL(x) ((bool) pin_array[x].is_digital)
117 #define GET_ARRAY_PIN(x) ((pin_t) pin_array[x].pin)
118 #define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
119 #define MULTI_NAME_PAD 33 // space needed to be pretty if not first name assigned to a pin
121 #ifndef M43_NEVER_TOUCH
122 #define _M43_NEVER_TOUCH(Index) (Index >= 9 && Index <= 12) // SERIAL/USB pins: PA9(TX) PA10(RX) PA11(USB_DM) PA12(USB_DP)
124 #define M43_NEVER_TOUCH(Index) m43_never_touch(Index)
126 bool m43_never_touch(
const pin_t Index) {
127 static pin_t M43_kill_index = -1;
128 if (M43_kill_index < 0)
130 if (
KILL_PIN == GET_PIN_MAP_PIN_M43(M43_kill_index))
break;
131 return _M43_NEVER_TOUCH(Index) || Index == M43_kill_index;
134 #define M43_NEVER_TOUCH(Index) _M43_NEVER_TOUCH(Index)
139 uint32_t mode_all = 0;
141 switch (PORT_ALPHA(dp)) {
142 case 'A' : mode_all = GPIOA->MODER;
break;
143 case 'B' : mode_all = GPIOB->MODER;
break;
144 case 'C' : mode_all = GPIOC->MODER;
break;
145 case 'D' : mode_all = GPIOD->MODER;
break;
147 case 'E' : mode_all = GPIOE->MODER;
break;
149 case 'F' : mode_all = GPIOF->MODER;
break;
151 case 'G' : mode_all = GPIOG->MODER;
break;
153 case 'H' : mode_all = GPIOH->MODER;
break;
155 case 'I' : mode_all = GPIOI->MODER;
break;
157 case 'J' : mode_all = GPIOJ->MODER;
break;
159 case 'K' : mode_all = GPIOK->MODER;
break;
161 case 'L' : mode_all = GPIOL->MODER;
break;
164 return (mode_all >> (2 *
uint8_t(PIN_NUM(dp)))) & 0x03;
169 return pin_mode == MODE_PIN_OUTPUT || pin_mode == MODE_PIN_ALT;
172 int8_t digital_pin_to_analog_pin(
pin_t Ard_num) {
181 bool is_digital(
const pin_t x) {
183 return pin_mode == MODE_PIN_INPUT || pin_mode == MODE_PIN_OUTPUT;
186 void port_print(
const pin_t Ard_num) {
190 if (Ard_num == GET_PIN_MAP_PIN_M43(Index))
break;
192 const char * ppa = pin_xref[Index].Port_pin_alpha;
198 const int8_t Port_pin = digital_pin_to_analog_pin(Ard_num);
220 uint32_t alt_all = 0;
223 const bool over_7 = pin_number >= 8;
224 const uint8_t ind = over_7 ? 1 : 0;
225 switch (PORT_ALPHA(dp)) {
226 case 'A' : alt_all = GPIOA->AFR[ind];
break;
227 case 'B' : alt_all = GPIOB->AFR[ind];
break;
228 case 'C' : alt_all = GPIOC->AFR[ind];
break;
229 case 'D' : alt_all = GPIOD->AFR[ind];
break;
231 case 'E' : alt_all = GPIOE->AFR[ind];
break;
233 case 'F' : alt_all = GPIOF->AFR[ind];
break;
235 case 'G' : alt_all = GPIOG->AFR[ind];
break;
237 case 'H' : alt_all = GPIOH->AFR[ind];
break;
239 case 'I' : alt_all = GPIOI->AFR[ind];
break;
241 case 'J' : alt_all = GPIOJ->AFR[ind];
break;
243 case 'K' : alt_all = GPIOK->AFR[ind];
break;
245 case 'L' : alt_all = GPIOL->AFR[ind];
break;
248 if (over_7) pin_number -= 8;
250 uint8_t alt_func = (alt_all >> (4 * pin_number)) & 0x0F;
264 case 9 :
SERIAL_ECHOPGM(
"CAN1/CAN2, TIM12..14 (probably PWM)");
break;
275 #endif // NUM_DIGITAL_PINS