diff --git a/cores/arduino/pins_arduino_var.h b/cores/arduino/pins_arduino_var.h index 27d6a72868..38d899f8d0 100644 --- a/cores/arduino/pins_arduino_var.h +++ b/cores/arduino/pins_arduino_var.h @@ -25,14 +25,16 @@ // Include board variant #include "variant.h" +// Avoid pins number misalignment +_Static_assert(NUM_DIGITAL_PINS==PEND, "NUM_DIGITAL_PINS and PEND differ!"); +_Static_assert(NUM_ANALOG_INPUTS==(AEND-A0), "NUM_ANALOG_INPUTS and (AEND-A0) differ!"); + #ifdef __cplusplus extern "C" { #endif #define NOT_AN_INTERRUPT NC // -1 -#define DEND PEND -#define NUM_DIGITAL_PINS ((uint32_t)DEND) -#define NUM_ANALOG_INPUTS ((uint32_t)(AEND-A0)) +#define DEND NUM_DIGITAL_PINS // Convert a digital pin number Dxx to a PinName PX_n // Note: Analog pin is also a digital pin. diff --git a/variants/DISCO_F100RB/variant.h b/variants/DISCO_F100RB/variant.h index 8cea3805fd..82413c8d92 100644 --- a/variants/DISCO_F100RB/variant.h +++ b/variants/DISCO_F100RB/variant.h @@ -105,6 +105,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 63 + enum { A_START_AFTER = D46, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -112,6 +115,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 16 + // On-board LED pin number #define LED_BUILTIN PC9 #define LED_GREEN LED_BUILTIN diff --git a/variants/DISCO_F407VG/variant.h b/variants/DISCO_F407VG/variant.h index a1b258cca2..55b6b151cb 100644 --- a/variants/DISCO_F407VG/variant.h +++ b/variants/DISCO_F407VG/variant.h @@ -131,12 +131,18 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 87 + enum { A_START_AFTER = D78, A0, A1, A2, A3, A4, A5, A6, A7, AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 8 + // On-board LED pin number #define LED_BUILTIN PD12 #define LED_GREEN LED_BUILTIN diff --git a/variants/DISCO_F746NG/variant.h b/variants/DISCO_F746NG/variant.h index f31df34001..fe9d07140f 100644 --- a/variants/DISCO_F746NG/variant.h +++ b/variants/DISCO_F746NG/variant.h @@ -63,12 +63,18 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 25 + enum { A_START_AFTER = D15, A0, A1, A2, A3, A4, A5, AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 6 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/DISCO_L072CZ_LRWAN1/variant.h b/variants/DISCO_L072CZ_LRWAN1/variant.h index 1b8c84631a..4d3f644696 100644 --- a/variants/DISCO_L072CZ_LRWAN1/variant.h +++ b/variants/DISCO_L072CZ_LRWAN1/variant.h @@ -73,12 +73,18 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 33 + enum { A_START_AFTER = D25, A0, A1, A2, A3, A4, A5, A6, AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 7 + // On-board LED pin number #define LED_BUILTIN PA5 #define LED_LD2 LED_BUILTIN diff --git a/variants/DISCO_L475VG_IOT/variant.h b/variants/DISCO_L475VG_IOT/variant.h index e48a6f6d55..b8ef035e79 100644 --- a/variants/DISCO_L475VG_IOT/variant.h +++ b/variants/DISCO_L475VG_IOT/variant.h @@ -132,6 +132,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 85 + enum { A_START_AFTER = D68, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -139,6 +142,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 16 + // On-board LED pin number #define LED_BUILTIN 13 #define LED1 LED_BUILTIN diff --git a/variants/NUCLEO_F030R8/variant.h b/variants/NUCLEO_F030R8/variant.h index 3e5c1a7e47..44065b8037 100644 --- a/variants/NUCLEO_F030R8/variant.h +++ b/variants/NUCLEO_F030R8/variant.h @@ -105,6 +105,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 61 + enum { A_START_AFTER = D48, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -112,6 +115,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 12 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F091RC/variant.h b/variants/NUCLEO_F091RC/variant.h index 14868c0772..9f4e537c7a 100644 --- a/variants/NUCLEO_F091RC/variant.h +++ b/variants/NUCLEO_F091RC/variant.h @@ -102,6 +102,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 58 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -109,6 +112,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 12 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F103RB/variant.h b/variants/NUCLEO_F103RB/variant.h index 3cb9949fad..7d3b8817ea 100644 --- a/variants/NUCLEO_F103RB/variant.h +++ b/variants/NUCLEO_F103RB/variant.h @@ -104,6 +104,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 60 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -111,6 +114,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 14 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F207ZG/variant.h b/variants/NUCLEO_F207ZG/variant.h index efe5c158d1..04c391182d 100644 --- a/variants/NUCLEO_F207ZG/variant.h +++ b/variants/NUCLEO_F207ZG/variant.h @@ -147,6 +147,10 @@ enum { PF9_2,//D95/A17 = D63 PEND }; + +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 96 + // Enum defining Arduino style alias for analog pin number --> Ax enum { A_START_AFTER = D77, // pin number preceding A0 @@ -155,6 +159,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 18 + // On-board LED pin number #define LED_BUILTIN PB0 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F302R8/variant.h b/variants/NUCLEO_F302R8/variant.h index 1c5c6ec272..64dcfa3bc5 100644 --- a/variants/NUCLEO_F302R8/variant.h +++ b/variants/NUCLEO_F302R8/variant.h @@ -102,6 +102,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 58 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -109,6 +112,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 12 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F303K8/variant.h b/variants/NUCLEO_F303K8/variant.h index 47bfd63b7e..70c7829523 100644 --- a/variants/NUCLEO_F303K8/variant.h +++ b/variants/NUCLEO_F303K8/variant.h @@ -61,12 +61,18 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 23 + enum { A_START_AFTER = D13, A0, A1, A2, A3, A4, A5, A6, AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 7 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F303RE/variant.h b/variants/NUCLEO_F303RE/variant.h index 4276359943..1349f4a118 100644 --- a/variants/NUCLEO_F303RE/variant.h +++ b/variants/NUCLEO_F303RE/variant.h @@ -104,6 +104,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 60 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -111,6 +114,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 14 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F401RE/variant.h b/variants/NUCLEO_F401RE/variant.h index 94a4d889c5..2d1e201c43 100644 --- a/variants/NUCLEO_F401RE/variant.h +++ b/variants/NUCLEO_F401RE/variant.h @@ -103,6 +103,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 59 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -110,6 +113,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 13 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F411RE/variant.h b/variants/NUCLEO_F411RE/variant.h index 5ccb173a6d..2be2eb01f2 100644 --- a/variants/NUCLEO_F411RE/variant.h +++ b/variants/NUCLEO_F411RE/variant.h @@ -103,6 +103,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 59 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -110,6 +113,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 13 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F429ZI/variant.h b/variants/NUCLEO_F429ZI/variant.h index 0fffb599c2..0b04ad4059 100644 --- a/variants/NUCLEO_F429ZI/variant.h +++ b/variants/NUCLEO_F429ZI/variant.h @@ -135,6 +135,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 96 + enum { A_START_AFTER = D77, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -142,6 +145,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 18 + // On-board LED pin number #define LED_BUILTIN PB0 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_F446RE/variant.h b/variants/NUCLEO_F446RE/variant.h index 2df76a8284..db06591554 100644 --- a/variants/NUCLEO_F446RE/variant.h +++ b/variants/NUCLEO_F446RE/variant.h @@ -104,6 +104,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 60 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -111,6 +114,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 14 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_LD2 LED_BUILTIN diff --git a/variants/NUCLEO_L031K6/variant.h b/variants/NUCLEO_L031K6/variant.h index 59b08c0f49..4e5f2355ef 100644 --- a/variants/NUCLEO_L031K6/variant.h +++ b/variants/NUCLEO_L031K6/variant.h @@ -73,12 +73,18 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 23 + enum { A_START_AFTER = D13, A0, A1, A2, A3, A4, A5, A6, AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 7 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_L053R8/variant.h b/variants/NUCLEO_L053R8/variant.h index 6e2975f158..35e281eb65 100644 --- a/variants/NUCLEO_L053R8/variant.h +++ b/variants/NUCLEO_L053R8/variant.h @@ -102,6 +102,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 58 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -109,6 +112,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 12 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_L152RE/variant.h b/variants/NUCLEO_L152RE/variant.h index 8d2cbd762b..25621d7b82 100644 --- a/variants/NUCLEO_L152RE/variant.h +++ b/variants/NUCLEO_L152RE/variant.h @@ -107,6 +107,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 63 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -114,6 +117,10 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 17 + + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_L432KC/variant.h b/variants/NUCLEO_L432KC/variant.h index a5648be475..e7bbfafe0c 100644 --- a/variants/NUCLEO_L432KC/variant.h +++ b/variants/NUCLEO_L432KC/variant.h @@ -61,12 +61,18 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 23 + enum { A_START_AFTER = D13, A0, A1, A2, A3, A4, A5, A6, AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 7 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/NUCLEO_L476RG/variant.h b/variants/NUCLEO_L476RG/variant.h index a841e78e66..ad75cf3dc6 100644 --- a/variants/NUCLEO_L476RG/variant.h +++ b/variants/NUCLEO_L476RG/variant.h @@ -102,6 +102,9 @@ enum { PEND }; +// This must be a literal with the same value as PEND +#define NUM_DIGITAL_PINS 58 + enum { A_START_AFTER = D45, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, @@ -109,6 +112,9 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +#define NUM_ANALOG_INPUTS 12 + // On-board LED pin number #define LED_BUILTIN 13 #define LED_GREEN LED_BUILTIN diff --git a/variants/board_template/variant.h b/variants/board_template/variant.h index f3302c0e7a..3e19bf2e9f 100644 --- a/variants/board_template/variant.h +++ b/variants/board_template/variant.h @@ -57,6 +57,12 @@ extern const PinName digitalPin[]; enum { PEND }; + +// This must be a literal with the same value as PEND +// It is used with preprocessor tests (e.g. #if NUM_DIGITAL_PINS > 3) +// so an enum will not work. +#define NUM_DIGITAL_PINS 0 + // Enum defining Arduino style alias for analog pin number --> Ax // !!! // !!! It must be aligned with the number of analog PinName @@ -69,6 +75,10 @@ enum { AEND }; +// This must be a literal with the same value as AEND-A0 +// It is used with preprocessor tests (e.g. #if NUM_ANALOG_INPUTS > 3) +// so an enum will not work. +#define NUM_ANALOG_INPUTS 18 // Below ADC, DAC and PWM definitions already done in the core // Could be redefined here if needed