Skip to content

Commit 7aa7d7e

Browse files
committed
variants: Add 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. - Automatically calculate digitalPin enumeration and arduino_pins array from devicetree configuration. - LED digital pin definition read from 'leds' node in devicetree. Append it to enumeration and pins array. - static struct gpio_dt_spec d0, d1, ... declaration seem bit redundant. Declare as array of gpio_dt_spec. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
1 parent a896076 commit 7aa7d7e

File tree

7 files changed

+36
-372
lines changed

7 files changed

+36
-372
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ void yield(void) {
1717
*/
1818
void pinMode(pin_size_t pinNumber, PinMode pinMode) {
1919
if (pinMode == INPUT) { // input mode
20-
gpio_pin_configure_dt(arduino_pins[pinNumber],
20+
gpio_pin_configure_dt(&arduino_pins[pinNumber],
2121
GPIO_INPUT | GPIO_ACTIVE_HIGH);
2222
} else if (pinMode == INPUT_PULLUP) { // input with internal pull-up
23-
gpio_pin_configure_dt(arduino_pins[pinNumber],
23+
gpio_pin_configure_dt(&arduino_pins[pinNumber],
2424
GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_HIGH);
2525
} else if (pinMode == INPUT_PULLDOWN) { // input with internal pull-down
26-
gpio_pin_configure_dt(arduino_pins[pinNumber],
26+
gpio_pin_configure_dt(&arduino_pins[pinNumber],
2727
GPIO_INPUT | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH);
2828
} else if (pinMode == OUTPUT) { // output mode
29-
gpio_pin_configure_dt(arduino_pins[pinNumber],
29+
gpio_pin_configure_dt(&arduino_pins[pinNumber],
3030
GPIO_OUTPUT_LOW | GPIO_ACTIVE_HIGH);
3131
}
3232
}
3333

3434
void digitalWrite(pin_size_t pinNumber, PinStatus status) {
35-
gpio_pin_set_dt(arduino_pins[pinNumber], status);
35+
gpio_pin_set_dt(&arduino_pins[pinNumber], status);
3636
}
3737

3838
PinStatus digitalRead(pin_size_t pinNumber) {
39-
return (gpio_pin_get_dt(arduino_pins[pinNumber]) == 1) ? HIGH : LOW;
39+
return (gpio_pin_get_dt(&arduino_pins[pinNumber]) == 1) ? HIGH : LOW;
4040
}
4141

4242
void delay(unsigned long ms) { k_sleep(K_MSEC(ms)); }

variants/arduino_mkrzero/arduino_mkrzero_pinmap.h

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -10,83 +10,5 @@
1010
#include <zephyr/drivers/i2c.h>
1111

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

9214
const static struct device *i2c_dev = DEVICE_DT_GET(DT_NODELABEL(sercom0));

variants/arduino_nano_33_ble/arduino_nano_33_ble_pinmap.h

Lines changed: 0 additions & 70 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-
8616
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: 0 additions & 70 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-
8616
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: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,5 @@
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-
8616
const static struct device *i2c_dev =
8717
DEVICE_DT_GET(DT_NODELABEL(arduino_nano_i2c));

0 commit comments

Comments
 (0)