Skip to content

Commit 3086485

Browse files
committed
x
1 parent 3be3a53 commit 3086485

File tree

3 files changed

+15
-53
lines changed

3 files changed

+15
-53
lines changed

cores/arduino/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
#define ZARD_DN_ENUMS(n, p, i) DX##i = ZARD_GLOBAL_GPIO_NUM(n, p, i)
9797
enum digitalPinsx {
9898
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, ZARD_DN_ENUMS, (,))
99+
, NUM_OF_DIGIAL_PINSX
99100
};
100101

101102
enum digitalPins {

cores/arduino/zephyrCommon.cpp

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2022 Dhruva Gole
3+
* Copyright (c) 2025 TOKITA Hiroshi
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -91,22 +92,6 @@ inline int global_gpio_pin_configure(pin_size_t pinNumber, int flags)
9192
return gpio_pin_configure(local_gpio_port(pinNumber), local_gpio_pin(pinNumber), flags);
9293
}
9394

94-
95-
/*
96-
* Calculate GPIO ports/pins number statically from devicetree configuration
97-
*/
98-
99-
template <class N, class Head> constexpr const N sum_of_list(const N sum, const Head &head)
100-
{
101-
return sum + head;
102-
}
103-
104-
template <class N, class Head, class... Tail>
105-
constexpr const N sum_of_list(const N sum, const Head &head, const Tail &...tail)
106-
{
107-
return sum_of_list(sum + head, tail...);
108-
}
109-
11095
template <class N, class Head> constexpr const N max_in_list(const N max, const Head &head)
11196
{
11297
return (max >= head) ? max : head;
@@ -118,32 +103,6 @@ constexpr const N max_in_list(const N max, const Head &head, const Tail &...tail
118103
return max_in_list((max >= head) ? max : head, tail...);
119104
}
120105

121-
template <class Query, class Head>
122-
constexpr const size_t is_first_appearance(const size_t &idx, const size_t &at, const size_t &found,
123-
const Query &query, const Head &head)
124-
{
125-
return ((found == ((size_t)-1)) && (query == head) && (idx == at)) ? 1 : 0;
126-
}
127-
128-
template <class Query, class Head, class... Tail>
129-
constexpr const size_t is_first_appearance(const size_t &idx, const size_t &at, const size_t &found,
130-
const Query &query, const Head &head,
131-
const Tail &...tail)
132-
{
133-
return ((found == ((size_t)-1)) && (query == head) && (idx == at))
134-
? 1
135-
: is_first_appearance(idx + 1, at, (query == head ? idx : found), query,
136-
tail...);
137-
}
138-
139-
#define GET_DEVICE_VARGS(n, p, i, _) DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(n, p, i))
140-
#define FIRST_APPEARANCE(n, p, i) \
141-
is_first_appearance(0, i, ((size_t)-1), DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(n, p, i)), \
142-
DT_FOREACH_PROP_ELEM_SEP_VARGS(n, p, GET_DEVICE_VARGS, (, ), 0))
143-
const int port_num =
144-
sum_of_list(0, DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios,
145-
FIRST_APPEARANCE, (, )));
146-
147106
#define GPIO_NGPIOS(n, p, i) DT_PROP(DT_GPIO_CTLR_BY_IDX(n, p, i), ngpios)
148107
const int max_ngpios = max_in_list(
149108
0, DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, GPIO_NGPIOS, (, )));
@@ -162,7 +121,7 @@ struct gpio_port_callback {
162121
struct arduino_callback handlers[max_ngpios];
163122
gpio_port_pins_t pins;
164123
const struct device *dev;
165-
} port_callback[port_num] = {0};
124+
} port_callback[ARRAY_SIZE(gpios)] = {0};
166125

167126
struct gpio_port_callback *find_gpio_port_callback(const struct device *dev)
168127
{
@@ -258,17 +217,8 @@ size_t analog_pin_index(pin_size_t pinNumber) {
258217
static unsigned int irq_key;
259218
static bool interrupts_disabled = false;
260219
} // namespace
261-
//
262-
263-
#define Dx(x) D ## x
264-
#define DXx(x) DX ## x
265-
#define PRINT_PIN(p, _) printf(STRINGIFY(Dx(p)) ":%d:%p:%d - " STRINGIFY(DXx(p)) ":%d:%p:%d\n", Dx(p), arduino_pins[Dx(p)].port, arduino_pins[Dx(p)].pin, DXx(p), local_gpio_port(DXx(p)), local_gpio_pin(DXx(p)));
266220

267221
void yield(void) {
268-
269-
LISTIFY(23, PRINT_PIN, ());
270-
271-
272222
k_yield();
273223
}
274224

@@ -581,3 +531,11 @@ int digitalPinToInterrupt(pin_size_t pin) {
581531

582532
return (pcb) ? pin : -1;
583533
}
534+
535+
#define Dx(x) D ## x
536+
#define DXx(x) DX ## x
537+
#define PRINT_PIN(p, _) printf(STRINGIFY(Dx(p)) ":%d:%p:%d - " STRINGIFY(DXx(p)) ":%d:%p:%d\n", Dx(p), arduino_pins[Dx(p)].port, arduino_pins[Dx(p)].pin, DXx(p), local_gpio_port(DXx(p)), local_gpio_pin(DXx(p)));
538+
539+
void debug_dump(void) {
540+
LISTIFY(DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios), PRINT_PIN, ());
541+
}

samples/hello_arduino/src/app.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ void setup() {
1010
// put your setup code here, to run once:
1111
Serial.begin(115200); // dummy as of now, need to study and refer https://docs.zephyrproject.org/latest/hardware/peripherals/uart.html
1212
}
13+
14+
void debug_dump();
15+
1316
void loop() {
14-
yield();
17+
debug_dump();
1518
while(true);
1619
}

0 commit comments

Comments
 (0)