How baihengrui/esp32c3_usb_meter works
This firmware turns an ESP32-C3 USB meter into a live measurement instrument: it initializes the hardware, samples an INA226/INA228, updates threshold timing and graph data, and presents readings and system state on the LCD. Separate FreeRTOS tasks handle button interaction, host commands, UI rendering, and queued offline recording. The documented product branches include settings, waveforms, threshold-triggered sessions, LittleFS export, and USB CDC data transfer. Main task wiring and storage behavior are sampled; several HAL/UI details are supported by the README, not inspected source excerpts.
Main entry points: main.cpp FreeRTOS tasks · hal_storage.cpp Recording service · hal_uart.cpp UART commands · globals.cpp Shared meter state
Components 22
Runtime and HAL
- FreeRTOS tasks
src/main.cpp - HAL application
src/hal/hal.cpp - Shared meter state
src/hal/globals.cpp - Persistent settings
src/hal/hal_nvs.cpp
Measurement
- INA acquisition
src/hal/hal_ina.cpp - Threshold timing
src/hal/hal_timer.cpp - Graph sampling
src/hal/hal.cpp
Interaction and display
- Button events
src/hal/hal_button.cpp - UART commands
src/hal/hal_uart.cpp - Settings menu
src/hal/lcd_menu.cpp - Meter UI
src/ui/ui.cpp - LCD control
src/hal/hal_lcd.cpp - USB protocol hook
src/hal/hal_protocol.cpp
Offline records
- Recording service
src/hal/hal_storage.cpp - Record queue
src/hal/hal_storage.cpp - Session files
src/hal/hal_storage.cpp
Other components
- Meter operator
- Host computer
- INA226/228 sensor
- Physical buttons
- TFT display
- LittleFS
Connections 33
- Meter operator → Physical buttons: presses
- Physical buttons → Button events: generates events
- FreeRTOS tasks → HAL application: initializes system
- FreeRTOS tasks → INA acquisition: runs acquisition task
- FreeRTOS tasks → Threshold timing: updates thresholds
- FreeRTOS tasks → Recording service: runs storage task
- FreeRTOS tasks → Button events: polls buttons
- FreeRTOS tasks → UART commands: polls commands
- FreeRTOS tasks → Graph sampling: updates graph data
- FreeRTOS tasks → Meter UI: runs app rendering
- INA acquisition → INA226/228 sensor: reads measurements
- INA acquisition → Shared meter state: updates readings
- Threshold timing → Shared meter state: updates timing state
- Graph sampling → Shared meter state: updates graph buffer
- Button events → Settings menu: controls settings
- Button events → Shared meter state: changes app state
- UART commands → Shared meter state: updates settings
- UART commands → Persistent settings: persists settings
- UART commands → Host computer: sends CDC data
- Host computer → UART commands: sends commands
- UART commands → Recording service: requests record actions
- Recording service → Record queue: receives samples
- INA acquisition → Recording service: samples for recording
- Recording service → Session files: writes sessions
- Recording service → LittleFS: reads and writes
- Recording service → Host computer: streams exports
- Meter UI → Shared meter state: reads meter state
- Meter UI → TFT display: renders screens
- HAL application → LCD control: initializes display
- LCD control → TFT display: controls display
- Settings menu → Persistent settings: reads and writes
- Threshold timing → Recording service: triggers recording
- UART commands → USB protocol hook: delegates USB protocol