@@ -121,5 +121,28 @@ void arduino::ZephyrSPI::begin() {}
121
121
122
122
void arduino::ZephyrSPI::end () {}
123
123
124
+ #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), spis)
125
+ #if (DT_PROP_LEN(DT_PATH(zephyr_user), spis) > 1)
126
+ #define ARDUINO_SPI_DEFINED_0 1
127
+ #define DECL_SPI_0 (n, p, i ) arduino::ZephyrSPI SPI (DEVICE_DT_GET(DT_PHANDLE_BY_IDX(n, p, i)));
128
+ #define DECL_SPI_N (n, p, i ) arduino::ZephyrSPI SPI##i(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(n, p, i)));
129
+ #define DECLARE_WIRE_N (n, p, i ) \
130
+ COND_CODE_1 (ARDUINO_SPI_DEFINED_##i, (DECL_SPI_0(n, p, i)), (DECL_SPI_N(n, p, i)))
131
+
132
+ /* Declare SPI, SPI1, SPI2, ... */
133
+ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), spis, DECLARE_SPI_N)
134
+
135
+ #undef DECLARE_SPI_N
136
+ #undef DECL_SPI_N
137
+ #undef DECL_SPI_0
138
+ #undef ARDUINO_SPI_DEFINED_0
139
+ #else // PROP_LEN(spis) > 1
140
+ /* When PROP_LEN(spis) == 1, DT_FOREACH_PROP_ELEM work not correctly. */
124
141
arduino::ZephyrSPI
125
142
SPI (DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), spis, 0)));
143
+ #endif // HAS_PORP(i2cs)
144
+ /* If i2cs node is not defined, tries to use arduino_i2c */
145
+ #elif DT_NODE_EXISTS(DT_NODELABEL(arduino_spi))
146
+ arduino::ZephyrSPI
147
+ SPI (DEVICE_DT_GET(DT_NODELABEL(arduino_spi)));
148
+ #endif
0 commit comments