1
1
/*
2
2
* Copyright (c) 2022 Dhruva Gole
3
+ * Copyright (c) 2025 TOKITA Hiroshi
3
4
*
4
5
* SPDX-License-Identifier: Apache-2.0
5
6
*/
@@ -91,22 +92,6 @@ inline int global_gpio_pin_configure(pin_size_t pinNumber, int flags)
91
92
return gpio_pin_configure (local_gpio_port (pinNumber), local_gpio_pin (pinNumber), flags);
92
93
}
93
94
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
-
110
95
template <class N , class Head > constexpr const N max_in_list (const N max, const Head &head)
111
96
{
112
97
return (max >= head) ? max : head;
@@ -118,32 +103,6 @@ constexpr const N max_in_list(const N max, const Head &head, const Tail &...tail
118
103
return max_in_list ((max >= head) ? max : head, tail...);
119
104
}
120
105
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
-
147
106
#define GPIO_NGPIOS (n, p, i ) DT_PROP(DT_GPIO_CTLR_BY_IDX(n, p, i), ngpios)
148
107
const int max_ngpios = max_in_list(
149
108
0 , DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, GPIO_NGPIOS, (, )));
@@ -162,7 +121,7 @@ struct gpio_port_callback {
162
121
struct arduino_callback handlers[max_ngpios];
163
122
gpio_port_pins_t pins;
164
123
const struct device *dev;
165
- } port_callback[port_num ] = {0 };
124
+ } port_callback[ARRAY_SIZE(gpios) ] = {0 };
166
125
167
126
struct gpio_port_callback *find_gpio_port_callback (const struct device *dev)
168
127
{
@@ -258,17 +217,8 @@ size_t analog_pin_index(pin_size_t pinNumber) {
258
217
static unsigned int irq_key;
259
218
static bool interrupts_disabled = false ;
260
219
} // 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)));
266
220
267
221
void yield (void ) {
268
-
269
- LISTIFY (23 , PRINT_PIN, ());
270
-
271
-
272
222
k_yield ();
273
223
}
274
224
@@ -581,3 +531,11 @@ int digitalPinToInterrupt(pin_size_t pin) {
581
531
582
532
return (pcb) ? pin : -1 ;
583
533
}
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