Fixes for pulsein on ESP32S3
This commit is contained in:
parent
4d0e1d9055
commit
367a1d53c0
@ -94,7 +94,7 @@ static void IRAM_ATTR ws2812_rmt_adapter(const void *src, rmt_item32_t *dest, si
|
||||
void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, uint8_t *pixels, uint32_t numBytes) {
|
||||
// Reserve channel
|
||||
uint8_t number = digitalinout->pin->number;
|
||||
rmt_channel_t channel = peripherals_find_and_reserve_rmt();
|
||||
rmt_channel_t channel = peripherals_find_and_reserve_rmt(TRANSMIT_MODE);
|
||||
if (channel == RMT_CHANNEL_MAX) {
|
||||
mp_raise_RuntimeError(translate("All timers in use"));
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu
|
||||
}
|
||||
|
||||
// Find a free RMT Channel and configure it
|
||||
rmt_channel_t channel = peripherals_find_and_reserve_rmt();
|
||||
rmt_channel_t channel = peripherals_find_and_reserve_rmt(RECEIVE_MODE);
|
||||
if (channel == RMT_CHANNEL_MAX) {
|
||||
mp_raise_RuntimeError(translate("All timers in use"));
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
|
||||
uint32_t frequency,
|
||||
uint16_t duty_cycle) {
|
||||
|
||||
rmt_channel_t channel = peripherals_find_and_reserve_rmt();
|
||||
rmt_channel_t channel = peripherals_find_and_reserve_rmt(TRANSMIT_MODE);
|
||||
if (channel == RMT_CHANNEL_MAX) {
|
||||
mp_raise_RuntimeError(translate("All timers in use"));
|
||||
}
|
||||
|
@ -37,8 +37,17 @@ void peripherals_rmt_reset(void) {
|
||||
}
|
||||
}
|
||||
|
||||
rmt_channel_t peripherals_find_and_reserve_rmt(void) {
|
||||
for (size_t i = 0; i < RMT_CHANNEL_MAX; i++) {
|
||||
rmt_channel_t peripherals_find_and_reserve_rmt(bool mode) {
|
||||
size_t start_channel = 0;
|
||||
size_t end_channel = RMT_CHANNEL_MAX;
|
||||
#if SOC_RMT_CHANNELS_PER_GROUP > 4
|
||||
if (mode == RECEIVE_MODE) {
|
||||
start_channel = 4;
|
||||
} else {
|
||||
end_channel = 4;
|
||||
}
|
||||
#endif
|
||||
for (size_t i = start_channel; i < end_channel; i++) {
|
||||
if (!rmt_reserved_channels[i]) {
|
||||
rmt_reserved_channels[i] = true;
|
||||
return i;
|
||||
|
@ -30,9 +30,11 @@
|
||||
#include "py/mphal.h"
|
||||
#include "components/driver/include/driver/rmt.h"
|
||||
#include <stdint.h>
|
||||
#define TRANSMIT_MODE true
|
||||
#define RECEIVE_MODE false
|
||||
|
||||
void peripherals_rmt_reset(void);
|
||||
rmt_channel_t peripherals_find_and_reserve_rmt(void);
|
||||
rmt_channel_t peripherals_find_and_reserve_rmt(bool mode);
|
||||
void peripherals_free_rmt(rmt_channel_t chan);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ESPRESSIF_PERIPHERALS_RMT_H
|
||||
|
Loading…
Reference in New Issue
Block a user