Skip to content

Commit 9dc1e91

Browse files
committed
Clean up old way to define Ax pins definition
NUM_ANALOG_FIRST is no more supported. Only analogInputPin array is. Signed-off-by: Frederic Pillon <[email protected]>
1 parent 7dc7b39 commit 9dc1e91

File tree

76 files changed

+753
-432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+753
-432
lines changed

cores/arduino/pins_arduino.c

-8
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,12 @@ bool pinIsAnalogInput(uint32_t pin)
7171
{
7272
bool ret = false;
7373
#if NUM_ANALOG_INPUTS > 0
74-
#ifndef NUM_ANALOG_LAST
75-
ret = (pin >= A0) && (pin < (A0 + NUM_ANALOG_INPUTS));
76-
#else
7774
for (uint32_t i = 0; i < NUM_ANALOG_INPUTS; i++) {
7875
if (analogInputPin[i] == pin) {
7976
ret = true;
8077
break;
8178
}
8279
}
83-
#endif /* NUM_ANALOG_LAST */
8480
#endif /* NUM_ANALOG_INPUTS > 0 */
8581
return ret;
8682
}
@@ -89,16 +85,12 @@ uint32_t digitalPinToAnalogInput(uint32_t pin)
8985
{
9086
uint32_t ret = NUM_ANALOG_INPUTS;
9187
#if NUM_ANALOG_INPUTS > 0
92-
#ifndef NUM_ANALOG_LAST
93-
ret = pin - A0;
94-
#else
9588
for (uint32_t i = 0; i < NUM_ANALOG_INPUTS; i++) {
9689
if (analogInputPin[i] == pin) {
9790
ret = i;
9891
break;
9992
}
10093
}
101-
#endif /* NUM_ANALOG_LAST */
10294
#endif /* NUM_ANALOG_INPUTS > 0 */
10395
return ret;
10496
}

cores/arduino/pins_arduino.h

+6-14
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ _Static_assert(LastPort <= 0x0F, "PortName must be less than 16");
3030

3131
_Static_assert(NUM_ANALOG_INPUTS <= MAX_ANALOG_INPUTS,
3232
"Core NUM_ANALOG_INPUTS limited to MAX_ANALOG_INPUTS");
33-
/* Analog pins must be contiguous to be able to loop on each value */
34-
_Static_assert(NUM_ANALOG_FIRST >= NUM_ANALOG_INPUTS,
35-
"First analog pin value (A0) must be greater than or equal to NUM_ANALOG_INPUTS");
3633

3734
/* Default for Arduino connector compatibility */
3835
/* SPI Definitions */
@@ -86,34 +83,29 @@ extern const uint32_t analogInputPin[];
8683
#define NOT_AN_INTERRUPT (uint32_t)NC
8784

8885
/* Convert a digital pin number Dxx to a PinName PX_n */
86+
#if NUM_ANALOG_INPUTS > 0
8987
/* Note: Analog pin is also a digital pin */
90-
#ifndef NUM_ANALOG_LAST
91-
#define digitalPinToPinName(p) (((uint32_t)p < NUM_DIGITAL_PINS) ? digitalPin[p] : NC)
92-
#else
9388
#define digitalPinToPinName(p) (((uint32_t)p < NUM_DIGITAL_PINS) ? digitalPin[p] : \
9489
((uint32_t)p >= NUM_ANALOG_FIRST) && ((uint32_t)p <= NUM_ANALOG_LAST) ? \
9590
digitalPin[analogInputPin[p-NUM_ANALOG_FIRST]] : NC)
96-
#endif
91+
#else
92+
#define digitalPinToPinName(p) (((uint32_t)p < NUM_DIGITAL_PINS) ? digitalPin[p] : NC)
93+
#endif /* NUM_ANALOG_INPUTS > 0 */
9794
/* Convert a PinName PX_n to a digital pin number */
9895
uint32_t pinNametoDigitalPin(PinName p);
9996

10097
/* Convert an analog pin number to a digital pin number */
10198
#if NUM_ANALOG_INPUTS > 0
10299
/* Used by analogRead api to have A0 == 0 */
103-
/* For contiguous analog pins definition in digitalPin array */
104-
#ifndef NUM_ANALOG_LAST
105-
#define analogInputToDigitalPin(p) (((uint32_t)p < NUM_ANALOG_INPUTS) ? (p+A0) : p)
106-
#else
107-
/* For non contiguous analog pins definition in digitalPin array */
100+
/* Non contiguous analog pins definition in digitalPin array */
108101
#define analogInputToDigitalPin(p) ( \
109102
((uint32_t)p < NUM_ANALOG_INPUTS) ? analogInputPin[p] : \
110103
((uint32_t)p >= NUM_ANALOG_FIRST) && ((uint32_t)p <= NUM_ANALOG_LAST) ? \
111104
analogInputPin[p-NUM_ANALOG_FIRST] : p)
112-
#endif // !NUM_ANALOG_LAST
113105
#else
114106
/* No analog pin defined */
115107
#define analogInputToDigitalPin(p) (NUM_DIGITAL_PINS)
116-
#endif // NUM_ANALOG_INPUTS > 0
108+
#endif /* NUM_ANALOG_INPUTS > 0 */
117109

118110
/* Convert an analog pin number Axx to a PinName PX_n */
119111
PinName analogInputToPinName(uint32_t pin);

cores/arduino/pins_arduino_analog.h

+3-12
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,9 @@
2020
#define NUM_ANALOG_INPUTS 0
2121
#endif
2222

23-
/*
24-
* If NUM_ANALOG_FIRST is not defined:
25-
* - Ax are not contiguous in the digitalPin array
26-
* - analogInputPin array is available
27-
*/
28-
#ifndef NUM_ANALOG_FIRST
29-
#define NUM_ANALOG_FIRST (NUM_DIGITAL_PINS + 1)
30-
#define NUM_ANALOG_LAST (NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS)
31-
#define NUM_ANALOG_INTERNAL_FIRST (NUM_ANALOG_LAST + 1)
32-
#else
33-
#define NUM_ANALOG_INTERNAL_FIRST (NUM_DIGITAL_PINS + 1)
34-
#endif
23+
#define NUM_ANALOG_FIRST (NUM_DIGITAL_PINS + 1)
24+
#define NUM_ANALOG_LAST (NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS)
25+
#define NUM_ANALOG_INTERNAL_FIRST (NUM_ANALOG_LAST + 1)
3526

3627
/* ADC internal channels (not a pins) */
3728
/* Only used for analogRead() */

variants/STM32F0xx/DISCO_F072RB/variant.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ const PinName digitalPin[] = {
111111
PB_12, //D50
112112
};
113113

114+
// Analog (Ax) pin number array
115+
const uint32_t analogInputPin[] = {
116+
31, // A0
117+
32, // A1
118+
33, // A2
119+
34, // A3
120+
35, // A4
121+
36, // A5
122+
37, // A6
123+
38, // A7
124+
39, // A8
125+
40, // A9
126+
41, // A10
127+
42, // A11
128+
43, // A12
129+
44, // A13
130+
45, // A14
131+
46 // A15
132+
};
133+
114134
#ifdef __cplusplus
115135
}
116136
#endif

variants/STM32F0xx/DISCO_F072RB/variant.h

+16-17
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@ extern "C" {
8686
#define PC15 28
8787
#define PF0 29
8888
#define PF1 30
89-
#define PC0 31 // A0 - NCS_MEMS_SPI (L3GD20)
90-
#define PC1 32 // A1 - MEMS INT1 (L3GD20)
91-
#define PC2 33 // A2 - MEMS INT2 (L3GD20)
92-
#define PC3 34 // A3
93-
#define PA0 35 // A4 - USER_BTN
94-
#define PA1 36 // A5
95-
#define PA2 37 // A6 - SB27 (default OFF): TS_G1_IO3
96-
#define PA3 38 // A7 - SB28 (default OFF): TS_G1_IO4
97-
#define PA4 39 // A8
98-
#define PA5 40 // A9
99-
#define PA6 41 // A10 - SB29 (default OFF): TS_G2_IO3
100-
#define PA7 42 // A11 - SB30 (default OFF): TS_G2_IO4
101-
#define PC4 43 // A12
102-
#define PC5 44 // A13 - Ext Reset
103-
#define PB0 45 // A14 - SB31 (default OFF): TS_G3_IO2
104-
#define PB1 46 // A15 - SB32 (default OFF): TS_G3_IO3
89+
#define PC0 A0 // NCS_MEMS_SPI (L3GD20)
90+
#define PC1 A1 // MEMS INT1 (L3GD20)
91+
#define PC2 A2 // MEMS INT2 (L3GD20)
92+
#define PC3 A3
93+
#define PA0 A4 // USER_BTN
94+
#define PA1 A5
95+
#define PA2 A6 // SB27 (default OFF): TS_G1_IO3
96+
#define PA3 A7 // SB28 (default OFF): TS_G1_IO4
97+
#define PA4 A8
98+
#define PA5 A9
99+
#define PA6 A10 // SB29 (default OFF): TS_G2_IO3
100+
#define PA7 A11 // SB30 (default OFF): TS_G2_IO4
101+
#define PC4 A12
102+
#define PC5 A13 // Ext Reset
103+
#define PB0 A14 // SB31 (default OFF): TS_G3_IO2
104+
#define PB1 A15 // SB32 (default OFF): TS_G3_IO3
105105
#define PB2 47
106106
#define PB10 48 // I2C2 SCL: Extension / RF EEprom Connector
107107
#define PB11 49 // I2C2 SDA: Extension / RF EEprom Connector
@@ -111,7 +111,6 @@ extern "C" {
111111
#define NUM_DIGITAL_PINS 51
112112
// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
113113
#define NUM_ANALOG_INPUTS 16
114-
#define NUM_ANALOG_FIRST 31
115114

116115
//On-board LED pin number
117116
#define LED_BUILTIN PC9

variants/STM32F0xx/EEXTR_F030_V1/variant.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ const PinName digitalPin[] = {
7777
PB_9, // D38
7878
};
7979

80+
// Analog (Ax) pin number array
81+
const uint32_t analogInputPin[] = {
82+
5, // A0
83+
6, // A1
84+
7 // A2
85+
};
86+
8087
#ifdef __cplusplus
8188
}
8289
#endif

variants/STM32F0xx/EEXTR_F030_V1/variant.h

+4-11
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ extern "C" {
4545
#define PC15 2
4646
#define PF0 3
4747
#define PF1 4
48-
#define PA0 5 // A0
49-
#define PA1 6 // A1
50-
#define PA2 7 // A2
48+
#define PA0 A0
49+
#define PA1 A1
50+
#define PA2 A2
5151
#define PA3 8
5252
#define PA4 9
5353
#define PA5 10
@@ -84,17 +84,10 @@ extern "C" {
8484
#define NUM_DIGITAL_PINS 39
8585
// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
8686
#define NUM_ANALOG_INPUTS 3
87-
#define NUM_ANALOG_FIRST 5
88-
89-
//On-board LED pin number
90-
//#define LED_BUILTIN -1
91-
92-
//On-board user button
93-
//#define USER_BTN -1
9487

9588
// SPI definitions
9689
// SPI1 is used
97-
#define PIN_SPI_SS -1
90+
#define PIN_SPI_SS NC
9891
#define PIN_SPI_MOSI PA7
9992
#define PIN_SPI_MISO PA6
10093
#define PIN_SPI_SCK PA5

variants/STM32F0xx/ELEKTOR_F072Cx/variant.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ const PinName digitalPin[] = {
7878
PF_1 //D38
7979
};
8080

81+
// Analog (Ax) pin number array
82+
const uint32_t analogInputPin[] = {
83+
25, // A0
84+
26, // A1
85+
27, // A2
86+
28, // A3
87+
29, // A4
88+
30, // A5
89+
31, // A6
90+
32, // A7
91+
33, // A8
92+
34 // A9
93+
};
94+
8195
#ifdef __cplusplus
8296
}
8397
#endif

variants/STM32F0xx/ELEKTOR_F072Cx/variant.h

+10-12
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,22 @@ extern "C" {
6464
#define PC13 22
6565
#define PC14 23
6666
#define PC15 24
67-
#define PA0 25
68-
#define PA1 26
69-
#define PA2 27
70-
#define PA3 28
71-
#define PA4 29
72-
#define PA5 30
73-
#define PA6 31
74-
#define PA7 32
75-
#define PB0 33
76-
#define PB1 34
67+
#define PA0 A0
68+
#define PA1 A1
69+
#define PA2 A2
70+
#define PA3 A3
71+
#define PA4 A4
72+
#define PA5 A5
73+
#define PA6 A6
74+
#define PA7 A7
75+
#define PB0 A8
76+
#define PB1 A9
7777
#define PF0 35
7878
#define PF1 36
7979

80-
8180
// This must be a literal
8281
#define NUM_DIGITAL_PINS 37
8382
#define NUM_ANALOG_INPUTS 10
84-
#define NUM_ANALOG_FIRST 26
8583

8684
// On-board LED pin number
8785
#define LED_BUILTIN PA15

variants/STM32F0xx/MALYANMx00_F070CB/variant.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ const PinName digitalPin[] = {
8383
PA_14, //D34 - SWCLK
8484
};
8585

86+
// Analog (Ax) pin number array
87+
const uint32_t analogInputPin[] = {
88+
20, // A0
89+
21, // A1
90+
22, // A2
91+
23, // A3
92+
24, // A4
93+
25, // A5
94+
26, // A6
95+
27, // A7
96+
28, // A8
97+
29 // A9
98+
};
99+
86100
#ifdef __cplusplus
87101
}
88102
#endif

variants/STM32F0xx/MALYANMx00_F070CB/variant.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ extern "C" {
8686
#define PC13 17
8787
#define PC14 18
8888
#define PC15 19
89-
#define PA0 20 // A0
90-
#define PA1 21 // A1
91-
#define PA2 22 // A2
92-
#define PA3 23 // A3
93-
#define PA4 24 // A4
94-
#define PA5 25 // A5
95-
#define PA6 26 // A6
96-
#define PA7 27 // A7
97-
#define PB0 28 // A8
98-
#define PB1 29 // A9
89+
#define PA0 A0
90+
#define PA1 A1
91+
#define PA2 A2
92+
#define PA3 A3
93+
#define PA4 A4
94+
#define PA5 A5
95+
#define PA6 A6
96+
#define PA7 A7
97+
#define PB0 A8
98+
#define PB1 A9
9999
#define PB10 30
100100
#define PB11 31
101101
// Other
@@ -107,7 +107,6 @@ extern "C" {
107107
#define NUM_DIGITAL_PINS 35
108108
// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
109109
#define NUM_ANALOG_INPUTS 10
110-
#define NUM_ANALOG_FIRST 20
111110

112111
// On-board LED pin number
113112
#ifdef ARDUINO_MALYANM200_F070CB

variants/STM32F0xx/NUCLEO_F031K6/variant.cpp

+20-8
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,29 @@ const PinName digitalPin[] = {
3838
PB_5, //D11
3939
PB_4, //D12
4040
PB_3, //D13 - LED
41-
PA_0, //D14//A0
42-
PA_1, //D15//A1
43-
PA_3, //D16//A2
44-
PA_4, //D17//A3
45-
PA_5, //D18//A4
46-
PA_6, //D19//A5
47-
PA_7, //D20//A6
48-
PA_2, //D21 - STLink Tx (no A7)
41+
PA_0, //D14/A0
42+
PA_1, //D15/A1
43+
PA_3, //D16/A2
44+
PA_4, //D17/A3
45+
PA_5, //D18/A4
46+
PA_6, //D19/A5
47+
PA_7, //D20/A6
48+
PA_2, //D21/A7 - STLink Tx
4949
PA_15 //D22 - STLink Rx
5050
};
5151

52+
// Analog (Ax) pin number array
53+
const uint32_t analogInputPin[] = {
54+
14, // A0
55+
15, // A1
56+
16, // A2
57+
17, // A3
58+
18, // A4
59+
19, // A5
60+
20, // A6
61+
21 // A7
62+
};
63+
5264
#ifdef __cplusplus
5365
}
5466
#endif

0 commit comments

Comments
 (0)