From 3e20b79de78eaa95d5333d71bc0410cb580471a6 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 14 Feb 2026 22:06:28 +0100 Subject: [PATCH] sbus invertion in config --- README.md | 6 +++--- main/config.c | 3 +++ main/config.h | 1 + main/rcsignal.c | 7 +++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 302ad33..f22a6d7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Professional LED controller firmware for ESP32. Designed for model aircraft with ### Hardware Support - **ESP32 DevKitC** and **ESP32-C3 MINI** Development Board - Dual WS2812B LED strip support (configurable GPIOs) -- PWM signal input for RC control +- PWM or SBUS signal input for RC control - Real-time LED animation at 60 FPS ### Animation Modes @@ -35,7 +35,7 @@ led-controller-firmware/ │ ├── control.c/h # initialization │ ├── config.c/h # NVS │ ├── led.c/h # WS2812B control (RMT driver) -│ ├── rcsignal.c/h # PWM signal reading +│ ├── rcsignal.c/h # PWM/SBUS signal reading │ ├── localbtn.c/h # Local btn reading │ └── animation.c/h # LED animation patterns ├── CMakeLists.txt @@ -80,7 +80,7 @@ ESP32 Pin -> Component ----------- ---------- GPIO XX -> WS2812B Strip A Data GPIO XX -> WS2812B Strip B Data -GPIO XX -> RC PWM Signal +GPIO XX -> RC PWM/SBUS Signal GPIO XX -> Local button Signal GND -> Common Ground 5V -> LED Strip Power (if current < 500mA) diff --git a/main/config.c b/main/config.c index 73f68cb..b742e49 100644 --- a/main/config.c +++ b/main/config.c @@ -31,6 +31,7 @@ static const char *TAG = "CONFIG"; #define HARDCODED_CONFIG_SBUS_TRIGGER_CHANNEL 3U // Channel 4 #define HARDCODED_CONFIG_SBUS_THRESHOLD_LOW 800U #define HARDCODED_CONFIG_SBUS_THRESHOLD_HIGH 1100U +#define HARDCODED_CONFIG_SBUS_INVERTED true // Set inverted RX for FrSky receivers (they output inverted SBUS) #if defined(CONFIG_IDF_TARGET_ESP32C3) #define HARDCODED_CONFIG_LOCALBTN_PIN 9 @@ -54,6 +55,7 @@ static config_t current_config = { .sbus_trigger_channel = 3, .sbus_threshold_low = 800, .sbus_threshold_high = 1100, + .sbus_inverted = false, }; static void calculate_config_hash(const config_t *cfg, uint8_t *out_hash); @@ -197,6 +199,7 @@ esp_err_t config_init(void) current_config.sbus_trigger_channel = HARDCODED_CONFIG_SBUS_TRIGGER_CHANNEL; current_config.sbus_threshold_low = HARDCODED_CONFIG_SBUS_THRESHOLD_LOW; current_config.sbus_threshold_high = HARDCODED_CONFIG_SBUS_THRESHOLD_HIGH; + current_config.sbus_inverted = HARDCODED_CONFIG_SBUS_INVERTED; save_config_to_nvs(); #endif diff --git a/main/config.h b/main/config.h index d32140c..bc522b6 100644 --- a/main/config.h +++ b/main/config.h @@ -29,6 +29,7 @@ typedef struct uint8_t sbus_trigger_channel; // SBUS channel for mode trigger (0-15, typically 3 for CH4) uint16_t sbus_threshold_low; // SBUS low threshold (default 800) uint16_t sbus_threshold_high; // SBUS high threshold (default 1100) + bool sbus_inverted; // true = SBUS in inverted mode (like FrSky), false = normal mode uint8_t hash[CONFIG_HASH_LEN]; // SHA256 Hash of config } config_t; diff --git a/main/rcsignal.c b/main/rcsignal.c index 130466e..762996c 100644 --- a/main/rcsignal.c +++ b/main/rcsignal.c @@ -269,8 +269,11 @@ esp_err_t rcsignal_init(const config_t *config) ESP_ERROR_CHECK(uart_set_pin(UART_NUM, UART_PIN_NO_CHANGE, rcsignal.gpio_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); ESP_ERROR_CHECK(uart_driver_install(UART_NUM, UART_BUF_SIZE * 2, 0, 0, NULL, 0)); - // Set inverted RX for FrSky receivers (they output inverted SBUS) - ESP_ERROR_CHECK(uart_set_line_inverse(UART_NUM, UART_SIGNAL_RXD_INV)); + if (config->sbus_inverted) + { + // Set inverted RX for FrSky receivers (they output inverted SBUS) + ESP_ERROR_CHECK(uart_set_line_inverse(UART_NUM, UART_SIGNAL_RXD_INV)); + } ESP_LOGI(TAG, "SBUS UART configured with inverted RX"); }