8000 esp32/esp32_rmt: Select correct last RMT channel on S2, S3, C3 variants. · micropython/micropython@1f04a9a · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f04a9a

Browse files
committed
esp32/esp32_rmt: Select correct last RMT channel on S2, S3, C3 variants.
For example the ESP32-C3 has 2 TX channels and 2 RX channels in total, and in this case channel 1 must be the default for bitstream. Signed-off-by: Damien George <damien@micropython.org>
1 parent 15e65b7 commit 1f04a9a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ports/esp32/esp32_rmt.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
// This current MicroPython implementation lacks some major features, notably receive pulses
4848
// and carrier output.
4949

50+
// Last available RMT channel that can transmit.
51+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 0)
52+
#define RMT_LAST_TX_CHANNEL (RMT_CHANNEL_MAX - 1)
53+
#else
54+
#define RMT_LAST_TX_CHANNEL (SOC_RMT_TX_CANDIDATES_PER_GROUP - 1)
55+
#endif
56+
5057
// Forward declaration
5158
extern const mp_obj_type_t esp32_rmt_type;
5259

@@ -62,7 +69,7 @@ typedef struct _esp32_rmt_obj_t {
6269

6370
// Current channel used for machine.bitstream, in the machine_bitstream_high_low_rmt
6471
// implementation. A value of -1 means do not use RMT.
65-
int8_t esp32_rmt_bitstream_channel_id = RMT_CHANNEL_MAX - 1;
72+
int8_t esp32_rmt_bitstream_channel_id = RMT_LAST_TX_CHANNEL;
6673

6774
#if MP_TASK_COREID == 0
6875

@@ -336,7 +343,7 @@ STATIC mp_obj_t esp32_rmt_bitstream_channel(size_t n_args, const mp_obj_t *args)
336343
esp32_rmt_bitstream_channel_id = -1;
337344
} else {
338345
mp_int_t channel_id = mp_obj_get_int(args[0]);
339-
if (channel_id < 0 || channel_id >= RMT_CHANNEL_MAX) {
346+
if (channel_id < 0 || channel_id > RMT_LAST_TX_CHANNEL) {
340347
mp_raise_ValueError(MP_ERROR_TEXT("invalid channel"));
341348
}
342349
esp32_rmt_bitstream_channel_id = channel_id;

0 commit comments

Comments
 (0)
0