55 */
66
77#include < Arduino.h>
8- #include " zephyrInternal .h"
8+ #include " wiring_private .h"
99
1010#include < zephyr/spinlock.h>
1111
@@ -22,10 +22,6 @@ void _reinit_peripheral_if_needed(pin_size_t pin, const struct device *dev) {
2222 }
2323}
2424
25- static const struct gpio_dt_spec arduino_pins[] = {
26- DT_FOREACH_PROP_ELEM_SEP (
27- DT_PATH (zephyr_user), digital_pin_gpios, GPIO_DT_SPEC_GET_BY_IDX, (, ))};
28-
2925#define RETURN_ON_INVALID_PIN (pinNumber, ...) \
3026 do { \
3127 if ((pin_size_t )(pinNumber) >= ARRAY_SIZE (arduino_pins)) { \
@@ -35,63 +31,6 @@ static const struct gpio_dt_spec arduino_pins[] = {
3531
3632namespace {
3733
38- #if DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
39-
40- /*
41- * Calculate GPIO ports/pins number statically from devicetree configuration
42- */
43-
44- template <class N , class Head > constexpr N sum_of_list (const N sum, const Head &head) {
45- return sum + head;
46- }
47-
48- template <class N , class Head , class ... Tail>
49- constexpr N sum_of_list (const N sum, const Head &head, const Tail &...tail) {
50- return sum_of_list (sum + head, tail...);
51- }
52-
53- template <class N , class Head > constexpr N max_in_list (const N max, const Head &head) {
54- return (max >= head) ? max : head;
55- }
56-
57- template <class N , class Head , class ... Tail>
58- constexpr N max_in_list (const N max, const Head &head, const Tail &...tail) {
59- return max_in_list ((max >= head) ? max : head, tail...);
60- }
61-
62- template <class Query , class Head >
63- constexpr size_t is_first_appearance (const size_t &idx, const size_t &at, const size_t &found,
64- const Query &query, const Head &head) {
65- return ((found == ((size_t )-1 )) && (query == head) && (idx == at)) ? 1 : 0 ;
66- }
67-
68- template <class Query , class Head , class ... Tail>
69- constexpr size_t is_first_appearance (const size_t &idx, const size_t &at, const size_t &found,
70- const Query &query, const Head &head, const Tail &...tail) {
71- return ((found == ((size_t )-1 )) && (query == head) && (idx == at)) ?
72- 1 :
73- is_first_appearance (idx + 1 , at, (query == head ? idx : found), query, tail...);
74- }
75-
76- #define GET_DEVICE_VARGS (n, p, i, _ ) DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(n, p, i))
77- #define FIRST_APPEARANCE (n, p, i ) \
78- is_first_appearance (0 , i, ((size_t )-1), DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(n, p, i)), \
79- DT_FOREACH_PROP_ELEM_SEP_VARGS(n, p, GET_DEVICE_VARGS, (, ), 0))
80- const int port_num = sum_of_list(
81- 0 , DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios,
82- FIRST_APPEARANCE, (, )));
83-
84- #define GPIO_NGPIOS (n, p, i ) DT_PROP(DT_GPIO_CTLR_BY_IDX(n, p, i), ngpios)
85- const int max_ngpios = max_in_list(
86- 0 , DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, GPIO_NGPIOS, (, )));
87-
88- #else
89-
90- const int port_num = 1 ;
91- const int max_ngpios = 0 ;
92-
93- #endif
94-
9534/*
9635 * GPIO callback implementation
9736 */
0 commit comments