Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b25521e

Browse files
committed
libraries: SPI: Hanlde multiple SPI 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 <tokita.hiroshi@gmail.com>
1 parent 4bc1867 commit b25521e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎libraries/SPI/SPI.cpp‎

Lines changed: 23 additions & 0 deletions
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_SPI_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(spis)
144+
/* If spis node is not defined, tries to use arduino_spi */
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)

AltStyle によって変換されたページ (->オリジナル) /