Skip to content

Commit 367a1d5

Browse files
committed
Fixes for pulsein on ESP32S3
1 parent 4d0e1d9 commit 367a1d5

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

ports/espressif/common-hal/neopixel_write/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void IRAM_ATTR ws2812_rmt_adapter(const void *src, rmt_item32_t *dest, si
9494
void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, uint8_t *pixels, uint32_t numBytes) {
9595
// Reserve channel
9696
uint8_t number = digitalinout->pin->number;
97-
rmt_channel_t channel = peripherals_find_and_reserve_rmt();
97+
rmt_channel_t channel = peripherals_find_and_reserve_rmt(TRANSMIT_MODE);
9898
if (channel == RMT_CHANNEL_MAX) {
9999
mp_raise_RuntimeError(translate("All timers in use"));
100100
}

ports/espressif/common-hal/pulseio/PulseIn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
107107
}
108108

109109
// Find a free RMT Channel and configure it
110-
rmt_channel_t channel = peripherals_find_and_reserve_rmt();
110+
rmt_channel_t channel = peripherals_find_and_reserve_rmt(RECEIVE_MODE);
111111
if (channel == RMT_CHANNEL_MAX) {
112112
mp_raise_RuntimeError(translate("All timers in use"));
113113
}

ports/espressif/common-hal/pulseio/PulseOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
3737
uint32_t frequency,
3838
uint16_t duty_cycle) {
3939

40-
rmt_channel_t channel = peripherals_find_and_reserve_rmt();
40+
rmt_channel_t channel = peripherals_find_and_reserve_rmt(TRANSMIT_MODE);
4141
if (channel == RMT_CHANNEL_MAX) {
4242
mp_raise_RuntimeError(translate("All timers in use"));
4343
}

ports/espressif/peripherals/rmt.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@ void peripherals_rmt_reset(void) {
3737
}
3838
}
3939

40-
rmt_channel_t peripherals_find_and_reserve_rmt(void) {
41-
for (size_t i = 0; i < RMT_CHANNEL_MAX; i++) {
40+
rmt_channel_t peripherals_find_and_reserve_rmt(bool mode) {
41+
size_t start_channel = 0;
42+
size_t end_channel = RMT_CHANNEL_MAX;
43+
#if SOC_RMT_CHANNELS_PER_GROUP > 4
44+
if (mode == RECEIVE_MODE) {
45+
start_channel = 4;
46+
} else {
47+
end_channel = 4;
48+
}
49+
#endif
50+
for (size_t i = start_channel; i < end_channel; i++) {
4251
if (!rmt_reserved_channels[i]) {
4352
rmt_reserved_channels[i] = true;
4453
return i;

ports/espressif/peripherals/rmt.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
#include "py/mphal.h"
3131
#include "components/driver/include/driver/rmt.h"
3232
#include <stdint.h>
33+
#define TRANSMIT_MODE true
34+
#define RECEIVE_MODE false
3335

3436
void peripherals_rmt_reset(void);
35-
rmt_channel_t peripherals_find_and_reserve_rmt(void);
37+
rmt_channel_t peripherals_find_and_reserve_rmt(bool mode);
3638
void peripherals_free_rmt(rmt_channel_t chan);
3739

3840
#endif // MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_RMT_H

0 commit comments

Comments
 (0)