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>
112 lines
3.7 KiB
C
112 lines
3.7 KiB
C
/*
|
||
* face_animation.h — Face Emotion Renderer for LCD Display
|
||
*
|
||
* Renders expressive face animations for 5 core emotions:
|
||
* - HAPPY: upturned eyes, curved smile
|
||
* - SAD: downturned eyes, frown
|
||
* - CURIOUS: raised eyebrows, wide eyes, slight tilt
|
||
* - ANGRY: downturned brows, narrowed eyes, clenched mouth
|
||
* - SLEEPING: closed eyes, relaxed mouth, gentle sway (optional)
|
||
*
|
||
* HOW IT WORKS:
|
||
* - State machine with smooth transitions (easing over N frames)
|
||
* - Idle behavior: periodic blinking (duration configurable)
|
||
* - Each emotion has parameterized eye/mouth shapes (position, angle, curvature)
|
||
* - Transitions interpolate between emotion parameter sets
|
||
* - render() draws current state to LCD framebuffer via face_lcd_*() API
|
||
* - tick() advances frame counter, handles transitions, triggers blink
|
||
*
|
||
* ANIMATION SPECS:
|
||
* - Frame rate: 30 Hz (via systick)
|
||
* - Transition time: 0.5–1.0s (15–30 frames)
|
||
* - Blink duration: 100–150 ms (3–5 frames)
|
||
* - Blink interval: 4–6 seconds (120–180 frames at 30Hz)
|
||
*
|
||
* API:
|
||
* - face_animation_init() — Initialize state machine
|
||
* - face_animation_set_emotion(emotion) — Request state change (with smooth transition)
|
||
* - face_animation_tick() — Advance animation by 1 frame (call at 30Hz from systick)
|
||
* - face_animation_render() — Draw current face to LCD framebuffer
|
||
*/
|
||
|
||
#ifndef FACE_ANIMATION_H
|
||
#define FACE_ANIMATION_H
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
|
||
/* === Emotion Types === */
|
||
typedef enum {
|
||
FACE_HAPPY = 0,
|
||
FACE_SAD = 1,
|
||
FACE_CURIOUS = 2,
|
||
FACE_ANGRY = 3,
|
||
FACE_SLEEPING = 4,
|
||
FACE_NEUTRAL = 5, /* Default state */
|
||
} face_emotion_t;
|
||
|
||
/* === Animation Parameters (per emotion) === */
|
||
typedef struct {
|
||
int16_t eye_x; /* Eye horizontal offset from center (pixels) */
|
||
int16_t eye_y; /* Eye vertical offset from center (pixels) */
|
||
int16_t eye_open_y; /* Eye open height (pixels) */
|
||
int16_t eye_close_y; /* Eye close height (pixels, 0=fully closed) */
|
||
int16_t brow_angle; /* Eyebrow angle (-30..+30 degrees, tilt) */
|
||
int16_t brow_y_offset; /* Eyebrow vertical offset (pixels) */
|
||
int16_t mouth_x; /* Mouth horizontal offset (pixels) */
|
||
int16_t mouth_y; /* Mouth vertical offset (pixels) */
|
||
int16_t mouth_width; /* Mouth width (pixels) */
|
||
int16_t mouth_curve; /* Curvature: >0=smile, <0=frown, 0=neutral */
|
||
uint8_t blink_interval_ms; /* Idle blink interval (seconds, in 30Hz ticks) */
|
||
} face_params_t;
|
||
|
||
/* === Public API === */
|
||
|
||
/**
|
||
* Initialize face animation system.
|
||
* Sets initial emotion to NEUTRAL, clears blink timer.
|
||
*/
|
||
void face_animation_init(void);
|
||
|
||
/**
|
||
* Request a state change to a new emotion.
|
||
* Triggers smooth transition (easing) over TRANSITION_FRAMES.
|
||
*/
|
||
void face_animation_set_emotion(face_emotion_t emotion);
|
||
|
||
/**
|
||
* Advance animation by one frame.
|
||
* Called by systick ISR at 30 Hz.
|
||
* Handles:
|
||
* - Transition interpolation
|
||
* - Blink timing and rendering
|
||
* - Idle animations (sway, subtle movements)
|
||
*/
|
||
void face_animation_tick(void);
|
||
|
||
/**
|
||
* Render current face state to LCD framebuffer.
|
||
* Draws eyes, brows, mouth, and optional idle animations.
|
||
* Should be called after face_animation_tick().
|
||
*/
|
||
void face_animation_render(void);
|
||
|
||
/**
|
||
* Get current emotion (transition-aware).
|
||
* Returns the target emotion, or current if transition in progress.
|
||
*/
|
||
face_emotion_t face_animation_get_emotion(void);
|
||
|
||
/**
|
||
* Trigger a blink immediately (for special events).
|
||
* Overrides idle blink timer.
|
||
*/
|
||
void face_animation_blink_now(void);
|
||
|
||
/**
|
||
* Check if animation is idle (no active transition).
|
||
*/
|
||
bool face_animation_is_idle(void);
|
||
|
||
#endif // FACE_ANIMATION_H
|