Skip to content

Commit d20ef62

Browse files
committed
digitalPins: take into account boards without gpios
1 parent 41ae538 commit d20ef62

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cores/arduino/Arduino.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <zephyr/drivers/adc.h>
1515
#include <zephyr/drivers/i2c.h>
1616

17+
#if DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
1718
#define DIGITAL_PIN_EXISTS(n, p, i, dev, num) \
1819
(((dev == DT_REG_ADDR(DT_PHANDLE_BY_IDX(n, p, i))) && \
1920
(num == DT_PHA_BY_IDX(n, p, i, pin))) \
@@ -32,6 +33,7 @@
3233
#endif
3334

3435
#undef DIGITAL_PIN_CHECK_UNIQUE
36+
#endif
3537

3638
#ifndef LED_BUILTIN
3739

@@ -83,7 +85,9 @@
8385
* enum digitalPins { D0, D1, ... LED... NUM_OF_DIGITAL_PINS };
8486
*/
8587
enum digitalPins {
88+
#if DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
8689
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, DN_ENUMS, (, )),
90+
#endif
8791
NUM_OF_DIGITAL_PINS
8892
};
8993

cores/arduino/zephyrCommon.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ static const struct gpio_dt_spec arduino_pins[] = {DT_FOREACH_PROP_ELEM_SEP(
1212

1313
namespace {
1414

15+
#if DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
16+
1517
/*
1618
* Calculate GPIO ports/pins number statically from devicetree configuration
1719
*/
@@ -68,6 +70,13 @@ const int port_num =
6870
const int max_ngpios = max_in_list(
6971
0, DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, GPIO_NGPIOS, (, )));
7072

73+
#else
74+
75+
const int port_num = 1;
76+
const int max_ngpios = 0;
77+
78+
#endif
79+
7180
/*
7281
* GPIO callback implementation
7382
*/

0 commit comments

Comments
 (0)