Skip to content

Commit 7400c43

Browse files
committed
libraries: SPI: Hanlde multiple Wire instances
Create multiple SPI instance if spis array contains plural elements. Declare these as 'SPI1', 'SPI2', ..., from second element of the array. (First element is already declare as 'SPI'.) Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 4bc1867 commit 7400c43

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: libraries/SPI/SPI.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,28 @@ void arduino::ZephyrSPI::begin() {}
121121

122122
void arduino::ZephyrSPI::end() {}
123123

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. */
124141
arduino::ZephyrSPI
125142
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

Comments
 (0)