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-
11095template <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)
148107const 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
167126struct 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) {
258217static unsigned int irq_key;
259218static 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
267221void 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+ }
0 commit comments