Skip to content

Commit

Permalink
Merge pull request #313 from wizmo2/rmt-esp32s3
Browse files Browse the repository at this point in the history
Support for ESP32S3 RMT channel restrictions
  • Loading branch information
philippe44 authored Sep 28, 2023
2 parents f5d6f26 + f33cb56 commit f6fd117
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/led_strip/led_vu.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void led_vu_init()
led_strip_config.led_strip_working = heap_caps_malloc(strip.length * sizeof(struct led_color_t), MALLOC_CAP_8BIT);
led_strip_config.led_strip_showing = heap_caps_malloc(strip.length * sizeof(struct led_color_t), MALLOC_CAP_8BIT);
led_strip_config.gpio = strip.gpio;
led_strip_config.rmt_channel = rmt_system_base_channel++;
led_strip_config.rmt_channel = RMT_NEXT_TX_CHANNEL();

// initialize driver
bool led_init_ok = led_strip_init(&led_strip_config);
Expand Down
6 changes: 5 additions & 1 deletion components/services/globdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
#define I2C_SYSTEM_PORT 1
#define SPI_SYSTEM_HOST SPI2_HOST

#define RMT_NEXT_TX_CHANNEL() rmt_system_base_tx_channel++;
#define RMT_NEXT_RX_CHANNEL() rmt_system_base_rx_channel--;

extern int i2c_system_port;
extern int i2c_system_speed;
extern int spi_system_host;
extern int spi_system_dc_gpio;
extern int rmt_system_base_channel;
extern int rmt_system_base_tx_channel;
extern int rmt_system_base_rx_channel;
typedef struct {
int timer, base_channel, max;
} pwm_system_t;
Expand Down
2 changes: 1 addition & 1 deletion components/services/infrared.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ int8_t infrared_gpio(void) {
*
*/
void infrared_init(RingbufHandle_t *rb, int gpio, infrared_mode_t mode) {
int rmt_channel = rmt_system_base_channel++;
int rmt_channel = RMT_NEXT_RX_CHANNEL();
rmt_config_t rmt_rx_config = RMT_DEFAULT_CONFIG_RX(gpio, rmt_channel);
rmt_config(&rmt_rx_config);
rmt_driver_install(rmt_rx_config.channel, 1000, 0);
Expand Down
2 changes: 1 addition & 1 deletion components/services/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool led_config(int idx, gpio_num_t gpio, int color, int bright, led_type_t type
for (const struct rmt_led_param_s *p = rmt_led_param; !leds[idx].rmt && p->type >= 0; p++) if (p->type == type) leds[idx].rmt = p;
if (!leds[idx].rmt) return false;

if (led_rmt_channel < 0) led_rmt_channel = rmt_system_base_channel++;
if (led_rmt_channel < 0) led_rmt_channel = RMT_NEXT_TX_CHANNEL();
leds[idx].channel = led_rmt_channel;
leds[idx].bright = bright > 0 ? bright : 100;

Expand Down
3 changes: 2 additions & 1 deletion components/services/services.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ int i2c_system_port = I2C_SYSTEM_PORT;
int i2c_system_speed = 400000;
int spi_system_host = SPI_SYSTEM_HOST;
int spi_system_dc_gpio = -1;
int rmt_system_base_channel = RMT_CHANNEL_0;
int rmt_system_base_tx_channel = RMT_CHANNEL_0;
int rmt_system_base_rx_channel = RMT_CHANNEL_MAX-1;

pwm_system_t pwm_system = {
.timer = LEDC_TIMER_0,
Expand Down
2 changes: 1 addition & 1 deletion components/targets/muse/muse.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void setup_rmt_data_buffer(struct led_state new_state);

void ws2812_control_init(void)
{
rmt_channel = rmt_system_base_channel++;
rmt_channel = RMT_NEXT_TX_CHANNEL();
rmt_config_t config;
config.rmt_mode = RMT_MODE_TX;
config.channel = rmt_channel;
Expand Down

0 comments on commit f6fd117

Please sign in to comment.