From 60bd591bf83386296dccc3c8bd72b4e01bace5fb Mon Sep 17 00:00:00 2001 From: Wizmo2 Date: Mon, 25 Sep 2023 19:32:13 -0400 Subject: [PATCH 1/2] support for c3 and s3 channel restrictions --- components/led_strip/led_vu.c | 2 +- components/services/globdefs.h | 6 +++++- components/services/infrared.c | 2 +- components/services/led.c | 2 +- components/services/services.c | 3 ++- components/targets/muse/muse.c | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/components/led_strip/led_vu.c b/components/led_strip/led_vu.c index 59ca0defd..ba9ebfc22 100644 --- a/components/led_strip/led_vu.c +++ b/components/led_strip/led_vu.c @@ -97,7 +97,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); diff --git a/components/services/globdefs.h b/components/services/globdefs.h index 93aafb8f0..581cd49d0 100644 --- a/components/services/globdefs.h +++ b/components/services/globdefs.h @@ -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; diff --git a/components/services/infrared.c b/components/services/infrared.c index 8b22ee7aa..4827fbeaa 100644 --- a/components/services/infrared.c +++ b/components/services/infrared.c @@ -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); diff --git a/components/services/led.c b/components/services/led.c index 25e854780..491171582 100644 --- a/components/services/led.c +++ b/components/services/led.c @@ -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; diff --git a/components/services/services.c b/components/services/services.c index 211ba6cbb..ba1e93df9 100644 --- a/components/services/services.c +++ b/components/services/services.c @@ -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, diff --git a/components/targets/muse/muse.c b/components/targets/muse/muse.c index 4ee2fc12c..7a5f50d6f 100644 --- a/components/targets/muse/muse.c +++ b/components/targets/muse/muse.c @@ -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; From f33cb569cef023d58f07b12994e4d106b17a8eab Mon Sep 17 00:00:00 2001 From: Wizmo2 Date: Thu, 28 Sep 2023 07:34:58 -0400 Subject: [PATCH 2/2] rmt helper to function --- components/led_strip/led_vu.c | 2 +- components/services/globdefs.h | 4 ++-- components/services/infrared.c | 2 +- components/services/led.c | 2 +- components/targets/muse/muse.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/led_strip/led_vu.c b/components/led_strip/led_vu.c index ba9ebfc22..54319bfa4 100644 --- a/components/led_strip/led_vu.c +++ b/components/led_strip/led_vu.c @@ -97,7 +97,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_NEXT_TX_CHANNEL; + led_strip_config.rmt_channel = RMT_NEXT_TX_CHANNEL(); // initialize driver bool led_init_ok = led_strip_init(&led_strip_config); diff --git a/components/services/globdefs.h b/components/services/globdefs.h index 581cd49d0..b3816e064 100644 --- a/components/services/globdefs.h +++ b/components/services/globdefs.h @@ -13,8 +13,8 @@ #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--; +#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; diff --git a/components/services/infrared.c b/components/services/infrared.c index 4827fbeaa..a48aa0c57 100644 --- a/components/services/infrared.c +++ b/components/services/infrared.c @@ -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_NEXT_RX_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); diff --git a/components/services/led.c b/components/services/led.c index 491171582..9e7ea874a 100644 --- a/components/services/led.c +++ b/components/services/led.c @@ -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_NEXT_TX_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; diff --git a/components/targets/muse/muse.c b/components/targets/muse/muse.c index 7a5f50d6f..71b0a62fc 100644 --- a/components/targets/muse/muse.c +++ b/components/targets/muse/muse.c @@ -95,7 +95,7 @@ void setup_rmt_data_buffer(struct led_state new_state); void ws2812_control_init(void) { - rmt_channel = RMT_NEXT_TX_CHANNEL; + rmt_channel = RMT_NEXT_TX_CHANNEL(); rmt_config_t config; config.rmt_mode = RMT_MODE_TX; config.channel = rmt_channel;