Skip to content

Commit 141cf39

Browse files
committed
esp32/RMT: let RMT decide mult-core allocation
Signed-off-by: Rick Sorensen <[email protected]>
1 parent bbad5b0 commit 141cf39

File tree

3 files changed

+6
-45
lines changed

3 files changed

+6
-45
lines changed

ports/esp32/esp32_rmt.c

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -68,44 +68,6 @@ typedef struct _esp32_rmt_obj_t {
6868
mp_uint_t idle_level;
6969
} esp32_rmt_obj_t;
7070

71-
#if MP_TASK_COREID == 0
72-
73-
typedef struct _rmt_enable_state_t {
74-
SemaphoreHandle_t handle;
75-
rmt_channel_handle_t channel;
76-
esp_err_t ret;
77-
} rmt_enable_state_t;
78-
79-
static void rmt_enable_task(void *pvParameter) {
80-
rmt_enable_state_t *state = pvParameter;
81-
state->ret = rmt_enable(state->channel);
82-
xSemaphoreGive(state->handle);
83-
vTaskDelete(NULL);
84-
}
85-
86-
// Call rmt_enable on core 1. This ensures that the RMT interrupt handler is
87-
// serviced on core 1, so that WiFi (if active) does not interrupt it and cause glitches.
88-
esp_err_t rmt_enable_core1(rmt_channel_handle_t channel) {
89-
TaskHandle_t th;
90-
rmt_enable_state_t state;
91-
state.handle = xSemaphoreCreateBinary();
92-
state.channel = channel;
93-
xTaskCreatePinnedToCore(rmt_enable_task, "rmt_enable_task", 2048 / sizeof(StackType_t), &state, ESP_TASK_PRIO_MIN + 1, &th, 1);
94-
xSemaphoreTake(state.handle, portMAX_DELAY);
95-
vSemaphoreDelete(state.handle);
96-
return state.ret;
97-
}
98-
99-
#else
100-
101-
// MicroPython runs on core 1, so we can call the RMT installer directly and its
102-
// interrupt handler will also run on core 1.
103-
esp_err_t rmt_enable_core1(rmt_channel_handle_t channel) {
104-
return rmt_enable(channel);
105-
}
106-
107-
#endif
108-
10971
static bool IRAM_ATTR esp32_rmt_tx_trans_done(rmt_channel_handle_t channel, const rmt_tx_done_event_data_t *edata, void *user_ctx) {
11072
esp32_rmt_obj_t *self = user_ctx;
11173
self->tx_ongoing -= 1;
@@ -357,7 +319,7 @@ static mp_obj_t esp32_rmt_write_pulses(size_t n_args, const mp_obj_t *args) {
357319
if (self->enabled) {
358320
rmt_tx_wait_all_done(self->channel, -1);
359321
} else {
360-
check_esp_err(rmt_enable_core1(self->channel));
322+
check_esp_err(rmt_enable(self->channel));
361323
self->enabled = true;
362324
}
363325

ports/esp32/machine_bitstream.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void IRAM_ATTR machine_bitstream_high_low_bitbang(mp_hal_pin_obj_t pin, u
9494
// RMT implementation
9595

9696
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,3,0)
97-
#include "rmt_private.h" //RJS need to add rmt_private path in _common.cmake
97+
#include "rmt_private.h"
9898
#endif
9999
#include "driver/rmt_tx.h"
100100
#include "driver/rmt_encoder.h"
@@ -112,7 +112,7 @@ static void machine_bitstream_high_low_rmt(mp_hal_pin_obj_t pin, uint32_t *timin
112112
.trans_queue_depth = 1,
113113
};
114114
check_esp_err(rmt_new_tx_channel(&tx_chan_config, &channel));
115-
check_esp_err(rmt_enable_core1(channel));
115+
check_esp_err(rmt_enable(channel));
116116

117117
// Get the tick rate in kHz (this will likely be 40000).
118118
uint32_t counter_clk_khz = APB_CLK_FREQ / clock_div;
@@ -150,15 +150,16 @@ static void machine_bitstream_high_low_rmt(mp_hal_pin_obj_t pin, uint32_t *timin
150150
rmt_encoder_reset(encoder);
151151
check_esp_err(rmt_transmit(channel, encoder, buf, len, &tx_config));
152152

153-
check_esp_err(rmt_tx_wait_all_done(channel, -1));
153+
// Wait until completion.
154+
rmt_tx_wait_all_done(channel, -1);
154155

155156
// Disable and release channel.
156157
check_esp_err(rmt_del_encoder(encoder));
157158
rmt_disable(channel);
158159
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,3,0)
159160
channel->del(channel);
160161
#else
161-
rmt_del_channel(channel); // RJS untested
162+
rmt_del_channel(channel);
162163
#endif
163164

164165
// Cancel RMT output to GPIO pin.

ports/esp32/modesp32.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,4 @@ extern const mp_obj_type_t esp32_partition_type;
6666
extern const mp_obj_type_t esp32_rmt_type;
6767
extern const mp_obj_type_t esp32_ulp_type;
6868

69-
esp_err_t rmt_enable_core1(rmt_channel_handle_t channel);
70-
7169
#endif // MICROPY_INCLUDED_ESP32_MODESP32_H

0 commit comments

Comments
 (0)