sbus invertion in config

This commit is contained in:
2026-02-14 22:06:28 +01:00
parent 40d2880fdc
commit 3e20b79de7
4 changed files with 12 additions and 5 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;

View File

@ -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");
}