Archive STM32 firmware to legacy/stm32/: - src/, include/, lib/USB_CDC/, platformio.ini, test stubs, flash_firmware.py - test/test_battery_adc.c, test_hw_button.c, test_pid_schedule.c, test_vesc_can.c, test_can_watchdog.c - USB_CDC_BUG.md Rename: stm32_protocol → esp32_protocol, mamba_protocol → balance_protocol, stm32_cmd_node → esp32_cmd_node, stm32_cmd_params → esp32_cmd_params, stm32_cmd.launch.py → esp32_cmd.launch.py, test_stm32_protocol → test_esp32_protocol, test_stm32_cmd_node → test_esp32_cmd_node Content cleanup across all files: - Mamba F722S → ESP32-S3 BALANCE - BlackPill → ESP32-S3 IO - STM32F722/F7xx → ESP32-S3 - stm32Mode/Version/Port → esp32Mode/Version/Port - STM32 State/Mode labels → ESP32 State/Mode - Jetson Nano → Jetson Orin Nano Super - /dev/stm32 → /dev/esp32 - stm32_bridge → esp32_bridge - STM32 HAL → ESP-IDF docs/SALTYLAB.md: - Update "Drone FC Details" to describe ESP32-S3 BALANCE board (Waveshare ESP32-S3 Touch LCD 1.28) - Replace verbose "Self-Balancing Control" STM32 section with brief note pointing to SAUL-TEE-SYSTEM-REFERENCE.md TEAM.md: Update Embedded Firmware Engineer role to ESP32-S3 / ESP-IDF No new functionality — cleanup only. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
125 lines
3.0 KiB
C
125 lines
3.0 KiB
C
#ifndef RGB_FSM_H
|
|
#define RGB_FSM_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
/*
|
|
* rgb_fsm.h — RGB Status LED State Machine (Issue #290)
|
|
*
|
|
* Manages an 8-LED WS2812 NeoPixel ring with 8 operational states.
|
|
* Each state has a specific color pattern and animation.
|
|
*
|
|
* States:
|
|
* BOOT — Blue pulse (startup sequence, 0.5 Hz)
|
|
* IDLE — Green breathe (standby, smooth 0.5 Hz pulse)
|
|
* ARMED — Solid green (ready to move)
|
|
* NAV — Cyan spin (autonomous navigation active, rotating pattern)
|
|
* ERROR — Red flash (fault detected, 2 Hz blink)
|
|
* LOW_BATT — Orange blink (battery low, 1 Hz blink)
|
|
* CHARGING — Green fill (charging, progressive LEDs filling)
|
|
* ESTOP — Red solid (emergency stop, full red, no animation)
|
|
*
|
|
* Transitions via UART command from Jetson.
|
|
* Non-blocking operation with tick-based timing.
|
|
*/
|
|
|
|
/* LED State Machine States */
|
|
typedef enum {
|
|
LED_STATE_BOOT = 0,
|
|
LED_STATE_IDLE,
|
|
LED_STATE_ARMED,
|
|
LED_STATE_NAV,
|
|
LED_STATE_ERROR,
|
|
LED_STATE_LOW_BATT,
|
|
LED_STATE_CHARGING,
|
|
LED_STATE_ESTOP,
|
|
LED_STATE_COUNT
|
|
} LedState;
|
|
|
|
/* RGB Color (8-bit per channel) */
|
|
typedef struct {
|
|
uint8_t r; /* Red (0-255) */
|
|
uint8_t g; /* Green (0-255) */
|
|
uint8_t b; /* Blue (0-255) */
|
|
} RgbColor;
|
|
|
|
/*
|
|
* rgb_fsm_init()
|
|
*
|
|
* Initialize LED state machine:
|
|
* - PB4 as TIM3_CH1 PWM output for WS2812 driver
|
|
* - Configure TIM3 for 800 kHz PWM frequency
|
|
* - Set initial state to BOOT
|
|
* - Initialize all LEDs to off
|
|
*/
|
|
void rgb_fsm_init(void);
|
|
|
|
/*
|
|
* rgb_fsm_set_state(state)
|
|
*
|
|
* Transition to a new LED state immediately.
|
|
* Resets animation timing for the new state.
|
|
*
|
|
* Arguments:
|
|
* - state: Target LED state (LedState enum)
|
|
*
|
|
* Returns: true if state changed, false if already in that state
|
|
*/
|
|
bool rgb_fsm_set_state(LedState state);
|
|
|
|
/*
|
|
* rgb_fsm_get_state()
|
|
*
|
|
* Get current LED state.
|
|
*
|
|
* Returns: Current LED state (LedState enum)
|
|
*/
|
|
LedState rgb_fsm_get_state(void);
|
|
|
|
/*
|
|
* rgb_fsm_tick(now_ms)
|
|
*
|
|
* Update function called periodically (recommended: every 10-50ms).
|
|
* Processes animations and timing for current state.
|
|
* Updates LED strip via PWM.
|
|
*
|
|
* Arguments:
|
|
* - now_ms: Current time in milliseconds (from HAL_GetTick() or similar)
|
|
*/
|
|
void rgb_fsm_tick(uint32_t now_ms);
|
|
|
|
/*
|
|
* rgb_fsm_set_color(led_index, color)
|
|
*
|
|
* Set color of a specific LED (for testing and manual control).
|
|
* Bypasses current animation.
|
|
*
|
|
* Arguments:
|
|
* - led_index: 0-7 (LED ring has 8 LEDs)
|
|
* - color: RgbColor with R, G, B values (0-255)
|
|
*
|
|
* Returns: true if set, false if index out of range
|
|
*/
|
|
bool rgb_fsm_set_color(uint8_t led_index, RgbColor color);
|
|
|
|
/*
|
|
* rgb_fsm_all_off()
|
|
*
|
|
* Turn off all LEDs immediately.
|
|
* Useful for shutdown or error conditions.
|
|
*/
|
|
void rgb_fsm_all_off(void);
|
|
|
|
/*
|
|
* rgb_fsm_get_animation_frame()
|
|
*
|
|
* Get current animation progress (0-255).
|
|
* Useful for testing and debugging animation timing.
|
|
*
|
|
* Returns: Current frame value for animation (0-255 represents full cycle)
|
|
*/
|
|
uint8_t rgb_fsm_get_animation_frame(void);
|
|
|
|
#endif /* RGB_FSM_H */
|