Skip to content

Commit 874bd80

Browse files
facchinmsoburi
authored andcommitted
cores: arduino: digitalPins: take into account boards without gpios
Added a condition that the length of digital_pin_gpios is 0 or more. ------------------------------------------------------------------- Pick: arduino@d20ef628 Co-Authored-by: Martino Facchin <m.facchin@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 8f7c7db commit 874bd80

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

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))) && (num == DT_PHA_BY_IDX(n, p, i, pin))) ? \
1920
1 : \
@@ -31,6 +32,7 @@
3132
#endif
3233

3334
#undef DIGITAL_PIN_CHECK_UNIQUE
35+
#endif
3436

3537
/* Return the index of it if matched, oterwise return 0 */
3638
#define LED_BUILTIN_INDEX_BY_REG_AND_PINNUM(n, p, i, dev, num) \
@@ -79,7 +81,9 @@
7981
* enum digitalPins { D0, D1, ... LED... NUM_OF_DIGITAL_PINS };
8082
*/
8183
enum digitalPins {
84+
#if DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
8285
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, DN_ENUMS, (, )),
86+
#endif
8387
NUM_OF_DIGITAL_PINS
8488
};
8589

cores/arduino/zephyrCommon.cpp

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

1616
namespace {
1717

18+
#if DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
19+
1820
/*
1921
* Calculate GPIO ports/pins number statically from devicetree configuration
2022
*/
@@ -64,6 +66,13 @@ const int port_num = sum_of_list(
6466
const int max_ngpios = max_in_list(
6567
0, DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, GPIO_NGPIOS, (, )));
6668

69+
#else
70+
71+
const int port_num = 1;
72+
const int max_ngpios = 0;
73+
74+
#endif
75+
6776
/*
6877
* GPIO callback implementation
6978
*/

0 commit comments

Comments
 (0)