Skip to content

Commit 33d603b

Browse files
committed
variants: Define common digital pin definition
The digitalPins enumeration, arduino_pins array, and contents of these are determined by d[N]_gpios declaration in dts. Interlock the declaration with the dts definition.
1 parent 8a28d3a commit 33d603b

File tree

5 files changed

+37
-291
lines changed

5 files changed

+37
-291
lines changed

variants/arduino_nano_33_ble/arduino_nano_33_ble_pinmap.h

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,74 +13,4 @@
1313

1414
#define LED_BUILTIN 13
1515

16-
static struct gpio_dt_spec d0 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
17-
static struct gpio_dt_spec d1 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
18-
static struct gpio_dt_spec d2 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
19-
static struct gpio_dt_spec d3 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
20-
static struct gpio_dt_spec d4 =
21-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
22-
static struct gpio_dt_spec d5 =
23-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d5_gpios);
24-
static struct gpio_dt_spec d6 =
25-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d6_gpios);
26-
static struct gpio_dt_spec d7 =
27-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d7_gpios);
28-
static struct gpio_dt_spec d8 =
29-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d8_gpios);
30-
static struct gpio_dt_spec d9 =
31-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d9_gpios);
32-
static struct gpio_dt_spec d10 =
33-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d10_gpios);
34-
static struct gpio_dt_spec d11 =
35-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d11_gpios);
36-
static struct gpio_dt_spec d12 =
37-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d12_gpios);
38-
static struct gpio_dt_spec d13 =
39-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
40-
static struct gpio_dt_spec d14 =
41-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
42-
static struct gpio_dt_spec d15 =
43-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d15_gpios);
44-
static struct gpio_dt_spec d16 =
45-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d16_gpios);
46-
static struct gpio_dt_spec d17 =
47-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d17_gpios);
48-
static struct gpio_dt_spec d18 =
49-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d18_gpios);
50-
static struct gpio_dt_spec d19 =
51-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d19_gpios);
52-
static struct gpio_dt_spec d20 =
53-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d20_gpios);
54-
static struct gpio_dt_spec d21 =
55-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d21_gpios);
56-
57-
static struct gpio_dt_spec *arduino_pins[22] = {
58-
&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, &d9, &d10,
59-
&d11, &d12, &d13, &d14, &d15, &d16, &d17, &d18, &d19, &d20, &d21};
60-
61-
enum digitalPins {
62-
D0,
63-
D1,
64-
D2,
65-
D3,
66-
D4,
67-
D5,
68-
D6,
69-
D7,
70-
D8,
71-
D9,
72-
D10,
73-
D11,
74-
D12,
75-
D13,
76-
D14,
77-
D15,
78-
D16,
79-
D17,
80-
D18,
81-
D19,
82-
D20,
83-
D21
84-
};
85-
86-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));
16+
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense_pinmap.h

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,74 +13,4 @@
1313

1414
#define LED_BUILTIN 13
1515

16-
static struct gpio_dt_spec d0 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
17-
static struct gpio_dt_spec d1 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
18-
static struct gpio_dt_spec d2 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
19-
static struct gpio_dt_spec d3 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
20-
static struct gpio_dt_spec d4 =
21-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
22-
static struct gpio_dt_spec d5 =
23-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d5_gpios);
24-
static struct gpio_dt_spec d6 =
25-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d6_gpios);
26-
static struct gpio_dt_spec d7 =
27-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d7_gpios);
28-
static struct gpio_dt_spec d8 =
29-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d8_gpios);
30-
static struct gpio_dt_spec d9 =
31-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d9_gpios);
32-
static struct gpio_dt_spec d10 =
33-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d10_gpios);
34-
static struct gpio_dt_spec d11 =
35-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d11_gpios);
36-
static struct gpio_dt_spec d12 =
37-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d12_gpios);
38-
static struct gpio_dt_spec d13 =
39-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
40-
static struct gpio_dt_spec d14 =
41-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
42-
static struct gpio_dt_spec d15 =
43-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d15_gpios);
44-
static struct gpio_dt_spec d16 =
45-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d16_gpios);
46-
static struct gpio_dt_spec d17 =
47-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d17_gpios);
48-
static struct gpio_dt_spec d18 =
49-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d18_gpios);
50-
static struct gpio_dt_spec d19 =
51-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d19_gpios);
52-
static struct gpio_dt_spec d20 =
53-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d20_gpios);
54-
static struct gpio_dt_spec d21 =
55-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d21_gpios);
56-
57-
static struct gpio_dt_spec *arduino_pins[22] = {
58-
&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, &d9, &d10,
59-
&d11, &d12, &d13, &d14, &d15, &d16, &d17, &d18, &d19, &d20, &d21};
60-
61-
enum digitalPins {
62-
D0,
63-
D1,
64-
D2,
65-
D3,
66-
D4,
67-
D5,
68-
D6,
69-
D7,
70-
D8,
71-
D9,
72-
D10,
73-
D11,
74-
D12,
75-
D13,
76-
D14,
77-
D15,
78-
D16,
79-
D17,
80-
D18,
81-
D19,
82-
D20,
83-
D21
84-
};
85-
86-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));
16+
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

variants/arduino_nano_33_iot/arduino_nano_33_iot_pinmap.h

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,74 +13,4 @@
1313

1414
#define LED_BUILTIN 13
1515

16-
static struct gpio_dt_spec d0 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
17-
static struct gpio_dt_spec d1 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
18-
static struct gpio_dt_spec d2 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
19-
static struct gpio_dt_spec d3 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
20-
static struct gpio_dt_spec d4 =
21-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
22-
static struct gpio_dt_spec d5 =
23-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d5_gpios);
24-
static struct gpio_dt_spec d6 =
25-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d6_gpios);
26-
static struct gpio_dt_spec d7 =
27-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d7_gpios);
28-
static struct gpio_dt_spec d8 =
29-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d8_gpios);
30-
static struct gpio_dt_spec d9 =
31-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d9_gpios);
32-
static struct gpio_dt_spec d10 =
33-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d10_gpios);
34-
static struct gpio_dt_spec d11 =
35-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d11_gpios);
36-
static struct gpio_dt_spec d12 =
37-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d12_gpios);
38-
static struct gpio_dt_spec d13 =
39-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
40-
static struct gpio_dt_spec d14 =
41-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
42-
static struct gpio_dt_spec d15 =
43-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d15_gpios);
44-
static struct gpio_dt_spec d16 =
45-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d16_gpios);
46-
static struct gpio_dt_spec d17 =
47-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d17_gpios);
48-
static struct gpio_dt_spec d18 =
49-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d18_gpios);
50-
static struct gpio_dt_spec d19 =
51-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d19_gpios);
52-
static struct gpio_dt_spec d20 =
53-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d20_gpios);
54-
static struct gpio_dt_spec d21 =
55-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d21_gpios);
56-
57-
static struct gpio_dt_spec *arduino_pins[22] = {
58-
&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, &d9, &d10,
59-
&d11, &d12, &d13, &d14, &d15, &d16, &d17, &d18, &d19, &d20, &d21};
60-
61-
enum digitalPins {
62-
D0,
63-
D1,
64-
D2,
65-
D3,
66-
D4,
67-
D5,
68-
D6,
69-
D7,
70-
D8,
71-
D9,
72-
D10,
73-
D11,
74-
D12,
75-
D13,
76-
D14,
77-
D15,
78-
D16,
79-
D17,
80-
D18,
81-
D19,
82-
D20,
83-
D21
84-
};
85-
86-
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));
16+
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840_pinmap.h

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -13,84 +13,6 @@
1313

1414
#define LED_BUILTIN 22
1515

16-
static struct gpio_dt_spec d0 =
17-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
18-
static struct gpio_dt_spec d1 =
19-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d1_gpios);
20-
static struct gpio_dt_spec d2 =
21-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d2_gpios);
22-
static struct gpio_dt_spec d3 =
23-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d3_gpios);
24-
static struct gpio_dt_spec d4 =
25-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d4_gpios);
26-
static struct gpio_dt_spec d5 =
27-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d5_gpios);
28-
static struct gpio_dt_spec d6 =
29-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d6_gpios);
30-
static struct gpio_dt_spec d7 =
31-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d7_gpios);
32-
static struct gpio_dt_spec d8 =
33-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d8_gpios);
34-
static struct gpio_dt_spec d9 =
35-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d9_gpios);
36-
static struct gpio_dt_spec d10 =
37-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d10_gpios);
38-
static struct gpio_dt_spec d11 =
39-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d11_gpios);
40-
static struct gpio_dt_spec d12 =
41-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d12_gpios);
42-
static struct gpio_dt_spec d13 =
43-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
44-
static struct gpio_dt_spec d14 =
45-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d13_gpios);
46-
static struct gpio_dt_spec d15 =
47-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d15_gpios);
48-
static struct gpio_dt_spec d16 =
49-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d16_gpios);
50-
static struct gpio_dt_spec d17 =
51-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d17_gpios);
52-
static struct gpio_dt_spec d18 =
53-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d18_gpios);
54-
static struct gpio_dt_spec d19 =
55-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d19_gpios);
56-
static struct gpio_dt_spec d20 =
57-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d20_gpios);
58-
static struct gpio_dt_spec d21 =
59-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d21_gpios);
60-
static struct gpio_dt_spec d22 =
61-
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d22_gpios); /* LED0 */
62-
63-
static struct gpio_dt_spec *arduino_pins[23] = {
64-
&d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7, &d8, &d9, &d10,
65-
&d11, &d12, &d13, &d14, &d15, &d16, &d17, &d18, &d19, &d20, &d21,
66-
&d22};
67-
68-
enum digitalPins {
69-
D0,
70-
D1,
71-
D2,
72-
D3,
73-
D4,
74-
D5,
75-
D6,
76-
D7,
77-
D8,
78-
D9,
79-
D10,
80-
D11,
81-
D12,
82-
D13,
83-
D14,
84-
D15,
85-
D16,
86-
D17,
87-
D18,
88-
D19,
89-
D20,
90-
D21,
91-
D22 /* LED0 */
92-
};
93-
9416
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(arduino_i2c));
9517

9618
#endif

variants/variants.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#ifdef CONFIG_BOARD_ARDUINO_NANO_33_BLE
24
#include <arduino_nano_33_ble_pinmap.h>
35
#endif // CONFIG_BOARD_ARDUINO_NANO_33_BLE
@@ -10,3 +12,35 @@
1012
#ifdef CONFIG_BOARD_NRF52840DK_NRF52840
1113
#include "nrf52840dk_nrf52840_pinmap.h"
1214
#endif /* CONFIG_BOARD_NRF52840DK_NRF52840 */
15+
16+
#define dN_GPIO_DT_SPEC(n,_) \
17+
COND_CODE_1( DT_NODE_HAS_PROP(DT_PATH(zephyr_user), d ## n ## _gpios), \
18+
(static struct gpio_dt_spec d ## n = \
19+
GPIO_DT_SPEC_GET( DT_PATH(zephyr_user), d ## n ## _gpios);), () )
20+
21+
#define DN_ENUMS(n,_) COND_CODE_1( DT_NODE_HAS_PROP(DT_PATH(zephyr_user), d ## n ## _gpios), \
22+
(D ## n ,), () )
23+
24+
#define dN_PINS(n,_) COND_CODE_1( DT_NODE_HAS_PROP(DT_PATH(zephyr_user), d ## n ## _gpios), \
25+
(&d ## n ,), () )
26+
27+
#define MAX_DIGITAL_PINS 255
28+
29+
/*
30+
* expand as
31+
* static struct gpio_dt_spec d0 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), d0_gpios);
32+
* ...
33+
*/
34+
LISTIFY(MAX_DIGITAL_PINS, dN_GPIO_DT_SPEC, ())
35+
36+
/*
37+
* expand as
38+
* enum digitalPins { D0, D1, ... NUM_OF_DIGITAL_PINS };
39+
*/
40+
enum digitalPins { LISTIFY(MAX_DIGITAL_PINS, DN_ENUMS, () ) NUM_OF_DIGITAL_PINS };
41+
42+
/*
43+
* expand as
44+
* static struct gpio_dt_spec *arduion_pins[NUM_OF_DIGITAL_PINS] = { &d0, &d1, ... };
45+
*/
46+
static struct gpio_dt_spec *arduino_pins[NUM_OF_DIGITAL_PINS] = { LISTIFY(MAX_DIGITAL_PINS, dN_PINS, ()) };

0 commit comments

Comments
 (0)