@@ -24,7 +24,14 @@ class TimerTask;
2424#endif // has include "io_local_definitions"
2525
2626// when not on mbed, we need to load Arduino.h to get the right defines for some boards.
27- #ifndef __MBED__
27+ #if defined(BUILD_FOR_PICO_CMAKE)
28+ #include < pico/stdlib.h>
29+ #include < valarray>
30+ #ifndef min
31+ #define min (a, b ) (((a) < (b)) ? (a) : (b))
32+ #define max (a, b ) (((a) > (b)) ? (a) : (b))
33+ #endif
34+ #elif !defined(__MBED__)
2835#include < Arduino.h>
2936#endif
3037
@@ -116,7 +123,6 @@ namespace tm_internal {
116123 }
117124}
118125#elif defined(ESP8266) || defined(ESP32) || defined(ARDUINO_PICO_REVISION)
119- #include " Arduino.h"
120126typedef uint8_t pintype_t ;
121127# define IOA_USE_ARDUINO
122128#if defined(TM_ENABLE_CAPTURED_LAMBDAS)
@@ -244,7 +250,51 @@ namespace tm_internal {
244250 }
245251}
246252#endif
253+ #elif defined(BUILD_FOR_PICO_CMAKE)
254+ #include < pico/critical_section.h>
255+ #if defined(TM_ENABLE_CAPTURED_LAMBDAS)
256+ #define TM_ALLOW_CAPTURED_LAMBDA
257+ #endif
258+ typedef uint8_t pintype_t ;
259+ namespace tm_internal {
260+ typedef TimerTask *volatile TimerTaskAtomicPtr;
261+ typedef volatile bool TmAtomicBool;
262+ extern critical_section_t * tmLock;
263+ void initPicoTmLock ();
264+
265+ static bool atomicSwapBool (volatile bool *ptr, bool expected, bool newValue) {
266+ bool ret = false ;
267+ critical_section_enter_blocking (tmLock);
268+ if (*ptr == expected) {
269+ *ptr = newValue;
270+ ret = true ;
271+ }
272+ critical_section_exit (tmLock);
273+ return ret;
274+ }
275+
276+ static void atomicWriteBool (volatile bool *ptr, bool val) {
277+ critical_section_enter_blocking (tmLock);
278+ *ptr = val;
279+ critical_section_exit (tmLock);
280+ }
281+
282+ inline bool atomicReadBool (volatile bool *ptr) {
283+ bool ret = false ;
284+ critical_section_enter_blocking (tmLock);
285+ ret = *ptr;
286+ critical_section_exit (tmLock);
287+ return ret;
288+ }
289+
290+ inline void atomicWritePtr (TimerTaskAtomicPtr *ptr, TimerTask *newVal) {
291+ *ptr = newVal;
292+ }
247293
294+ inline TimerTask *atomicReadPtr (TimerTaskAtomicPtr *ptr) {
295+ return *ptr;
296+ }
297+ }
248298#else
249299// fall back to using Arduino regular logic, works for all single core boards. If we end up here for a multicore
250300// board then there may be problems. Here we are in full arduino mode (AVR, MKR etc).
0 commit comments