Skip to content

Commit f8138b3

Browse files
committed
Fix ESP32-P4 build: add support for DYNAMIC_ALLOCATION without SELECT_DRIVER_TYPE
ESP32-P4 only has RMT queues (no MCPWM_PCNT), so SUPPORT_SELECT_DRIVER_TYPE is not defined. Add the missing code paths for this configuration.
1 parent 53df2b7 commit f8138b3

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

src/FastAccelStepperEngine.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ void FastAccelStepperEngine::init() {
3333
for (uint8_t i = 0; i < MAX_STEPPER; i++) {
3434
_stepper[i] = NULL;
3535
}
36-
#if defined(SUPPORT_DYNAMIC_ALLOCATION)
36+
#if defined(SUPPORT_DYNAMIC_ALLOCATION)
3737
for (uint8_t i = 0; i < NUM_QUEUES; i++) {
3838
fas_queue[i] = NULL;
3939
}
40-
#endif
40+
#endif
4141

4242
#if defined(SUPPORT_RP_PICO)
4343
claimed_pios = 0;
@@ -74,9 +74,8 @@ bool FastAccelStepperEngine::initI2sMux(uint8_t data_pin, uint8_t bclk_pin,
7474
if (StepperQueue::_i2s_mux_initialized) {
7575
return false;
7676
}
77-
I2sManager* mgr = I2sManager::create((gpio_num_t)data_pin,
78-
(gpio_num_t)bclk_pin,
79-
(gpio_num_t)ws_pin);
77+
I2sManager* mgr = I2sManager::create(
78+
(gpio_num_t)data_pin, (gpio_num_t)bclk_pin, (gpio_num_t)ws_pin);
8079
if (mgr == nullptr) {
8180
return false;
8281
}
@@ -102,9 +101,15 @@ bool FastAccelStepperEngine::i2sMuxGetBit(uint8_t slot) {
102101

103102
#if defined(SUPPORT_DYNAMIC_ALLOCATION)
104103
// dynamic allocation is currently only supported for esp32
104+
#if defined(SUPPORT_SELECT_DRIVER_TYPE)
105105
FastAccelStepper* FastAccelStepperEngine::stepperConnectToPin(
106106
uint8_t step_pin, FasDriver driver_type) {
107107
StepperQueue* q = StepperQueue::tryAllocateQueue(driver_type, step_pin);
108+
#else
109+
FastAccelStepper* FastAccelStepperEngine::stepperConnectToPin(
110+
uint8_t step_pin) {
111+
StepperQueue* q = StepperQueue::tryAllocateQueue(step_pin);
112+
#endif
108113
if (q != nullptr) {
109114
uint8_t fas_stepper_num = _stepper_cnt;
110115
_stepper_cnt++;

src/fas_queue/protocol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#if defined(SUPPORT_SELECT_DRIVER_TYPE)
1515
static StepperQueue* tryAllocateQueue(FasDriver driver, uint8_t step_pin);
16+
#elif defined(SUPPORT_DYNAMIC_ALLOCATION)
17+
static StepperQueue* tryAllocateQueue(uint8_t step_pin);
1618
#endif
1719

1820
static bool isValidStepPin(uint8_t step_pin);

src/pd_esp32/esp32_queue.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <Arduino.h>
88

99
#if defined(SUPPORT_DYNAMIC_ALLOCATION)
10-
uint8_t StepperQueue::queues_allocated = 0;
1110
#if defined(SUPPORT_SELECT_DRIVER_TYPE)
11+
uint8_t StepperQueue::queues_allocated = 0;
1212
#if defined(SUPPORT_ESP32_I2S)
1313
bool StepperQueue::_i2s_mux_initialized = false;
1414
uint32_t StepperQueue::_i2s_mux_allocated_bitmask = 0;
@@ -20,6 +20,8 @@ uint8_t StepperQueue::_mcpwm_pcnt_allocated = 0;
2020
#ifdef SUPPORT_ESP32_RMT
2121
uint8_t StepperQueue::_rmt_allocated = 0;
2222
#endif
23+
#else
24+
uint8_t StepperQueue::queues_allocated = 0;
2325
#endif // SUPPORT_SELECT_DRIVER_TYPE
2426
#endif
2527

@@ -254,6 +256,29 @@ StepperQueue* StepperQueue::tryAllocateQueue(FasDriver driver,
254256
}
255257
#endif // SUPPORT_SELECT_DRIVER_TYPE && SUPPORT_DYNAMIC_ALLOCATION
256258

259+
#if !defined(SUPPORT_SELECT_DRIVER_TYPE) && defined(SUPPORT_DYNAMIC_ALLOCATION)
260+
StepperQueue* StepperQueue::tryAllocateQueue(uint8_t step_pin) {
261+
if (StepperQueue::queues_allocated >= MAX_STEPPER) {
262+
return nullptr;
263+
}
264+
265+
if (step_pin & PIN_EXTERNAL_FLAG) {
266+
return nullptr;
267+
}
268+
269+
if (!StepperQueue::isValidStepPin(step_pin)) {
270+
return nullptr;
271+
}
272+
273+
StepperQueue* q = new StepperQueue();
274+
#if defined(SUPPORT_ESP32_RMT)
275+
q->use_rmt = true;
276+
#endif
277+
StepperQueue::queues_allocated++;
278+
return q;
279+
}
280+
#endif // !SUPPORT_SELECT_DRIVER_TYPE && SUPPORT_DYNAMIC_ALLOCATION
281+
257282
void StepperTask(void* parameter) {
258283
FastAccelStepperEngine* engine = (FastAccelStepperEngine*)parameter;
259284
while (true) {

src/pd_esp32/esp32_queue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class StepperQueue : public StepperQueueBase {
3737
#endif
3838
}
3939
#endif
40+
#elif defined(SUPPORT_DYNAMIC_ALLOCATION)
41+
static uint8_t queues_allocated;
42+
static void initVars() { StepperQueue::queues_allocated = 0; }
4043
#endif // SUPPORT_SELECT_DRIVER_TYPE
4144

4245
volatile bool _isRunning;

0 commit comments

Comments
 (0)