Skip to content

Commit d37253c

Browse files
soburiDhruvaG2000
authored andcommitted
variants: Introduce the builtin-led-gpios node
Introduce the `builtin-led-gpios` node to make possible to configuring the builtin-led from dts. This node uses to determine the value of the `LED_BUILTIN` macro. Use the `led0` alias to determine the `LED_BUILTIN` if the `builtin-led-gpios` is not defined. The behavior can override by defining the `LED_BUILTIN` in pinmap.h. It uses definitions that are defined in the header preferentially. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 6d919d8 commit d37253c

File tree

9 files changed

+49
-7
lines changed

9 files changed

+49
-7
lines changed

variants/arduino_mkrzero/arduino_mkrzero.overlay

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
<&arduino_mkr_header 18 0>, /* D18 / A4 / I2C-SDA */
3030
<&arduino_mkr_header 19 0>, /* D19 / A5 / I2C-SCL */
3131
<&arduino_mkr_header 20 0>,
32-
<&arduino_mkr_header 21 0>;
32+
<&arduino_mkr_header 21 0>,
33+
<&portb 8 0>;
3334

3435
pwms = <&tcc0 2 255>,
3536
<&tcc0 3 255>;

variants/arduino_mkrzero/arduino_mkrzero_pinmap.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
#include <zephyr/kernel.h>
1010
#include <zephyr/drivers/i2c.h>
1111

12-
#define LED_BUILTIN 22

variants/arduino_nano_33_ble/arduino_nano_33_ble.overlay

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
serials = <&uart0>;
4646
i2cs = <&arduino_nano_i2c>;
47+
48+
builtin-led-gpios = <&arduino_nano_header 13 0>;
4749
};
4850
};
4951

variants/arduino_nano_33_ble/arduino_nano_33_ble_pinmap.h

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/device.h>
1313

14-
#define LED_BUILTIN 13

variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense.overlay

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
serials = <&uart0>;
4646
i2cs = <&arduino_nano_i2c>;
47+
48+
builtin-led-gpios = <&arduino_nano_header 13 0>;
4749
};
4850
};
4951

variants/arduino_nano_33_ble_sense/arduino_nano_33_ble_sense_pinmap.h

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/device.h>
1313

14-
#define LED_BUILTIN 13

variants/arduino_nano_33_iot/arduino_nano_33_iot_pinmap.h

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/device.h>
1313

14-
#define LED_BUILTIN 13

variants/nrf52840dk_nrf52840/nrf52840dk_nrf52840_pinmap.h

-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/kernel.h>
1313

14-
#define LED_BUILTIN 22
15-
1614
#endif

variants/variants.h

+43
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,49 @@
3737

3838
#undef DIGITAL_PIN_CHECK_UNIQUE
3939

40+
#ifndef LED_BUILTIN
41+
42+
/* Return the index of it if matched, oterwise return 0 */
43+
#define LED_BUILTIN_INDEX_BY_REG_AND_PINNUM(n, p, i, dev, num) \
44+
(DIGITAL_PIN_EXISTS(n, p, i, dev, num) ? i : 0)
45+
46+
/* Only matched pin returns non-zero value, so the sum is matched pin's index */
47+
#define LED_BUILTIN_FIND_DIGITAL_PIN(dev, pin) \
48+
DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \
49+
LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin)
50+
51+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), builtin_led_gpios) && \
52+
(DT_PROP_LEN(DT_PATH(zephyr_user), builtin_led_gpios) > 0)
53+
54+
#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS( \
55+
DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
56+
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \
57+
DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) > 0)
58+
#warning "pin not found in digital_pin_gpios"
59+
#else
60+
#define LED_BUILTIN \
61+
LED_BUILTIN_FIND_DIGITAL_PIN( \
62+
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \
63+
DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin))
64+
#endif
65+
66+
/* If digital-pin-gpios is not defined, tries to use the led0 alias */
67+
#elif DT_NODE_EXISTS(DT_ALIAS(led0))
68+
69+
#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, \
70+
(+), DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \
71+
DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) > 0)
72+
#warning "pin not found in digital_pin_gpios"
73+
#else
74+
#define LED_BUILTIN \
75+
LED_BUILTIN_FIND_DIGITAL_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \
76+
DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin))
77+
#endif
78+
79+
#endif // builtin_led_gpios
80+
81+
#endif // LED_BUILTIN
82+
4083
#define DN_ENUMS(n, p, i) D##i = i
4184

4285
/*

0 commit comments

Comments
 (0)