Skip to content

Commit c4348f3

Browse files
authored
Merge branch 'next' into rpi_pico
2 parents 67b20bb + d190e21 commit c4348f3

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

cores/arduino/Arduino.h

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user),
9797

9898
#endif
9999

100+
void interrupts(void);
101+
void noInterrupts(void);
102+
100103
#include <variant.h>
101104
#ifdef __cplusplus
102105
#include <zephyrPrint.h>

cores/arduino/zephyrCommon.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ size_t analog_pin_index(pin_size_t pinNumber) {
175175

176176
#endif //CONFIG_ADC
177177

178+
static unsigned int irq_key;
179+
static bool interrupts_disabled = false;
180+
181+
void interrupts(void) {
182+
if (interrupts_disabled) {
183+
irq_unlock(irq_key);
184+
interrupts_disabled = false;
185+
}
186+
}
187+
188+
void noInterrupts(void) {
189+
if (!interrupts_disabled) {
190+
irq_key = irq_lock();
191+
interrupts_disabled = true;
192+
}
193+
}
178194
}
179195

180196
void yield(void) {

libraries/SPI/SPI.cpp

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

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

124-
arduino::ZephyrSPI
125-
SPI(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), spis, 0)));
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. */
141+
arduino::ZephyrSPI SPI(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), spis, 0)));
142+
#endif // HAS_PORP(spis)
143+
/* If spis node is not defined, tries to use arduino_spi */
144+
#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_spi))
145+
arduino::ZephyrSPI SPI(DEVICE_DT_GET(DT_NODELABEL(arduino_spi)));
146+
#endif

libraries/SPI/SPI.h

+17
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,24 @@ class ZephyrSPI : public HardwareSPI {
5656

5757
} // namespace arduino
5858

59+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), spis) && (DT_PROP_LEN(DT_PATH(zephyr_user), spis) > 1)
60+
#define ARDUINO_SPI_DEFINED_0 1
61+
#define DECL_EXTERN_SPI_0(i) extern arduino::ZephyrSPI SPI
62+
#define DECL_EXTERN_SPI_N(i) extern arduino::ZephyrSPI SPI##i
63+
#define DECLARE_EXTERN_SPI_N(n, p, i) \
64+
COND_CODE_1(ARDUINO_SPI_DEFINED_##i, (DECL_EXTERN_SPI_0(i);), (DECL_EXTERN_SPI_N(i);))
65+
66+
/* Declare SPI, SPI1, SPI2, ... */
67+
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), spis, DECLARE_EXTERN_SPI_N)
68+
69+
#undef DECLARE_EXTERN_SPI_N
70+
#undef DECL_EXTERN_SPI_N
71+
#undef DECL_EXTERN_SPI_0
72+
#undef ARDUINO_SPI_DEFINED_0
73+
#else
5974
extern arduino::ZephyrSPI SPI;
75+
#endif
76+
6077
/* Serial Peripheral Control Register */
6178
extern uint8_t SPCR;
6279

0 commit comments

Comments
 (0)