Update for arduino esp32 3.0.0-rc.1

.. tested on matrixportal s3 only. Other esp-family mcus may need
further changes.
This commit is contained in:
Jeff Epler 2024-04-03 09:44:13 -05:00
parent e4506e5a57
commit 7155be1a75
2 changed files with 27 additions and 13 deletions

View file

@ -20,6 +20,8 @@
#if defined(ESP32) || \ #if defined(ESP32) || \
defined(ESP_PLATFORM) // *All* ESP32 variants (OG, S2, S3, etc.) defined(ESP_PLATFORM) // *All* ESP32 variants (OG, S2, S3, etc.)
#include <inttypes.h>
#include "esp_idf_version.h" #include "esp_idf_version.h"
// NOTE: there is some intentional repetition in the macros and functions // NOTE: there is some intentional repetition in the macros and functions
@ -38,7 +40,13 @@ Protomatter_core *_PM_protoPtr;
#if defined(ARDUINO) // COMPILING FOR ARDUINO ------------------------------ #if defined(ARDUINO) // COMPILING FOR ARDUINO ------------------------------
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
#define _PM_timerNum 0 // Timer #0 (can be 0-3) #define _PM_timerNum 0 // Timer #0 (can be 0-3)
static hw_timer_t *_PM_esp32timer = NULL;
#define _PM_TIMER_DEFAULT &_PM_esp32timer
#else
#define _PM_TIMER_DEFAULT ((void *)-1) // some non-NULL but non valid pointer
#endif
// The following defines and functions are common to all ESP32 variants in // The following defines and functions are common to all ESP32 variants in
// the Arduino platform. Anything unique to one variant (or a subset of // the Arduino platform. Anything unique to one variant (or a subset of
@ -47,16 +55,7 @@ Protomatter_core *_PM_protoPtr;
// started down that path, it's okay, but move the code out of here and // started down that path, it's okay, but move the code out of here and
// into the variant-specific headers. // into the variant-specific headers.
// This is the default aforementioned singular timer. IN THEORY, other extern void _PM_row_handler(Protomatter_core *core); // In core.c
// timers could be used, IF an Arduino sketch passes the address of its
// own hw_timer_t* to the Protomatter constructor and initializes that
// timer using ESP32's timerBegin(). All of the timer-related functions
// below pass around a handle rather than accessing _PM_esp32timer directly,
// in case that's ever actually used in the future.
static hw_timer_t *_PM_esp32timer = NULL;
#define _PM_TIMER_DEFAULT &_PM_esp32timer
extern IRAM_ATTR void _PM_row_handler(Protomatter_core *core); // In core.c
// Timer interrupt handler. This, _PM_row_handler() and any functions // Timer interrupt handler. This, _PM_row_handler() and any functions
// called by _PM_row_handler() should all have the IRAM_ATTR attribute // called by _PM_row_handler() should all have the IRAM_ATTR attribute
@ -70,9 +69,15 @@ IRAM_ATTR static void _PM_esp32timerCallback(void) {
// Set timer period, initialize count value to zero, enable timer. // Set timer period, initialize count value to zero, enable timer.
IRAM_ATTR inline void _PM_timerStart(Protomatter_core *core, uint32_t period) { IRAM_ATTR inline void _PM_timerStart(Protomatter_core *core, uint32_t period) {
hw_timer_t *timer = (hw_timer_t *)core->timer; hw_timer_t *timer = (hw_timer_t *)core->timer;
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
timerAlarmWrite(timer, period, true); timerAlarmWrite(timer, period, true);
timerAlarmEnable(timer); timerAlarmEnable(timer);
timerStart(timer); timerStart(timer);
#else
timerWrite(timer, 0);
timerAlarm(timer, period ? period : 1, true, 0);
timerStart(timer);
#endif
} }
// Disable timer and return current count value. // Disable timer and return current count value.
@ -86,11 +91,19 @@ IRAM_ATTR uint32_t _PM_timerStop(Protomatter_core *core) {
// that's common to all ESP32 variants; code in variant-specific files might // that's common to all ESP32 variants; code in variant-specific files might
// set up its own special peripherals, then call this. // set up its own special peripherals, then call this.
void _PM_esp32commonTimerInit(Protomatter_core *core) { void _PM_esp32commonTimerInit(Protomatter_core *core) {
hw_timer_t *timer = (hw_timer_t *)core->timer; // pointer-to-pointer hw_timer_t *timer_in = (hw_timer_t *)core->timer;
if (timer == _PM_TIMER_DEFAULT) { if (!timer_in || timer_in == _PM_TIMER_DEFAULT) {
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
core->timer = timerBegin(_PM_timerNum, 2, true); // 1:2 prescale, count up core->timer = timerBegin(_PM_timerNum, 2, true); // 1:2 prescale, count up
#else
core->timer = timerBegin(_PM_timerFreq);
#endif
} }
timerAttachInterrupt(timer, &_PM_esp32timerCallback, true); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
timerAttachInterrupt(core->timer, &_PM_esp32timerCallback, true);
#else
timerAttachInterrupt(core->timer, _PM_esp32timerCallback);
#endif
} }
#elif defined(CIRCUITPY) // COMPILING FOR CIRCUITPYTHON -------------------- #elif defined(CIRCUITPY) // COMPILING FOR CIRCUITPYTHON --------------------

View file

@ -90,6 +90,7 @@ IRAM_ATTR inline uint32_t _PM_timerGetCount(Protomatter_core *core) {
#else #else
#include <driver/periph_ctrl.h> #include <driver/periph_ctrl.h>
#endif #endif
#include <driver/gpio.h>
#include <esp_private/gdma.h> #include <esp_private/gdma.h>
#include <esp_rom_gpio.h> #include <esp_rom_gpio.h>
#include <hal/dma_types.h> #include <hal/dma_types.h>