Skip to content

Commit a6f1685

Browse files
committed
map
1 parent 2beaeeb commit a6f1685

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

cores/arduino/Arduino.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#endif
3434
#endif // LED_BUILTIN
3535

36+
37+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), digital_pin_gpios)
3638
/*
3739
* expand as
3840
* enum digitalPins { D0, D1, ... };
@@ -42,6 +44,33 @@ enum digitalPins {
4244
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, ZARD_DN_ENUMS, (, )),
4345
NUM_OF_DIGITAL_PINS
4446
};
47+
#else
48+
49+
#define ZARD_MKR_HDR_DN_ENUMS(n, p, i) \
50+
D##i = DT_FOREACH_PROP_ELEM_VARGS(DT_PATH(zephyr_user), gpio_ports, ZARD_ACCUM_NGPIOS, \
51+
DT_MAP_PARENT_ARG_BY_IDX(n, p, i)) \
52+
GET_ARG_N(1, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i))
53+
54+
#if DT_NODE_EXISTS(DT_NODELABEL(arduino_header))
55+
#define ZARD_CONNECTOR arduino_header
56+
#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_mkr_header))
57+
#define ZARD_CONNECTOR arduino_mkr_header
58+
#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_nano_header))
59+
#define ZARD_CONNECTOR arduino_nano_header
60+
#elif DT_NODE_EXISTS(DT_NODELABEL(pico_header))
61+
#define ZARD_CONNECTOR pico_header
62+
#elif DT_NODE_EXISTS(DT_NODELABEL(boosterpack_header))
63+
#define ZARD_CONNECTOR boosterpack_header
64+
#endif
65+
66+
#ifdef ZARD_CONNECTOR
67+
enum digitalPins {
68+
DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(ZARD_CONNECTOR), gpio_map, ZARD_MKR_HDR_DN_ENUMS, (, )),
69+
NUM_OF_DIGITAL_PINS
70+
};
71+
#endif
72+
73+
#endif
4574

4675
#ifdef CONFIG_ADC
4776
#define ZARD_AN_ENUMS(n, p, i) A##i = ZARD_GLOBAL_GPIO_NUM(n, p, i)

cores/arduino/zephyrCommon.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,15 @@ constexpr const N max_in_list(const N max, const Head &head, const Tail &...tail
7979
return max_in_list((max >= head) ? max : head, tail...);
8080
}
8181

82+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), digital_pin_gpios)
8283
#define GPIO_NGPIOS(n, p, i) DT_PROP(DT_GPIO_CTLR_BY_IDX(n, p, i), ngpios)
8384
constexpr int max_ngpios = max_in_list(
8485
0, DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, GPIO_NGPIOS, (, )));
86+
#elif defined(ZARD_CONNECTOR)
87+
#define MAP_NGPIOS(n, p, i) DT_PROP(DT_MAP_PARENT_ARG_BY_IDX(n, p, i), ngpios)
88+
constexpr int max_ngpios = max_in_list(
89+
0, DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(ZARD_CONNECTOR), gpio_map, MAP_NGPIOS, (, )));
90+
#endif
8591

8692
/*
8793
* GPIO callback implementation
@@ -208,7 +214,11 @@ PinStatus digitalRead(pin_size_t pinNumber) {
208214
}
209215

210216
#ifndef MAX_TONE_PINS
217+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), digital_pin_gpios)
211218
#define MAX_TONE_PINS DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios)
219+
#elif defined(ZARD_CONNECTOR)
220+
#define MAX_TONE_PINS DT_PROP_LEN(DT_NODELABEL(ZARD_CONNECTOR), gpio_map)
221+
#endif
212222
#endif
213223

214224
struct pin_timer {

0 commit comments

Comments
 (0)