diff options
author | Damien George <damien@micropython.org> | 2022-02-01 16:58:56 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-02-01 16:58:56 +1100 |
commit | 1f04a9a1fcd4172f7c721e05a4515c9c8bb0e8c9 (patch) | |
tree | 0f27874be5adb50f2801735aa7e4be45fa2b52dc /ports/esp32/esp32_rmt.c | |
parent | 15e65b77ebfaeddc9a678d94cf1a2ced625a6d45 (diff) | |
download | micropython-1f04a9a1fcd4172f7c721e05a4515c9c8bb0e8c9.tar.gz micropython-1f04a9a1fcd4172f7c721e05a4515c9c8bb0e8c9.zip |
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>
Diffstat (limited to 'ports/esp32/esp32_rmt.c')
-rw-r--r-- | ports/esp32/esp32_rmt.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/ports/esp32/esp32_rmt.c b/ports/esp32/esp32_rmt.c index ca751d42a8..ac897e3336 100644 --- a/ports/esp32/esp32_rmt.c +++ b/ports/esp32/esp32_rmt.c @@ -47,6 +47,13 @@ // This current MicroPython implementation lacks some major features, notably receive pulses // and carrier output. +// Last available RMT channel that can transmit. +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 0) +#define RMT_LAST_TX_CHANNEL (RMT_CHANNEL_MAX - 1) +#else +#define RMT_LAST_TX_CHANNEL (SOC_RMT_TX_CANDIDATES_PER_GROUP - 1) +#endif + // Forward declaration extern const mp_obj_type_t esp32_rmt_type; @@ -62,7 +69,7 @@ typedef struct _esp32_rmt_obj_t { // Current channel used for machine.bitstream, in the machine_bitstream_high_low_rmt // implementation. A value of -1 means do not use RMT. -int8_t esp32_rmt_bitstream_channel_id = RMT_CHANNEL_MAX - 1; +int8_t esp32_rmt_bitstream_channel_id = RMT_LAST_TX_CHANNEL; #if MP_TASK_COREID == 0 @@ -336,7 +343,7 @@ STATIC mp_obj_t esp32_rmt_bitstream_channel(size_t n_args, const mp_obj_t *args) esp32_rmt_bitstream_channel_id = -1; } else { mp_int_t channel_id = mp_obj_get_int(args[0]); - if (channel_id < 0 || channel_id >= RMT_CHANNEL_MAX) { + if (channel_id < 0 || channel_id > RMT_LAST_TX_CHANNEL) { mp_raise_ValueError(MP_ERROR_TEXT("invalid channel")); } esp32_rmt_bitstream_channel_id = channel_id; |