9.2 KiB
9.2 KiB
Project Rules for ESP32-S3 Audio Board Development
This workspace is for the ESP32-S3 AI Smart Speaker Development Board. All agents interacting with this project must follow these guidelines:
-
Target Hardware: UeeKKoo (Waveshare) ESP32-S3-AUDIO-Board-EN (No Battery version).
- CPU: Dual-core Xtensa 32-bit LX7 CPU, running at 240 MHz (ESP32-S3R8).
- Memory: 16 MB Flash, 8 MB Octal PSRAM (0.01 GB RAM total).
- OS: FreeRTOS.
- Connectivity: Wi-Fi & Bluetooth.
- USB: 1x USB port.
- Audio Codec Hardware:
- Playback (DAC): ES8311 low-power mono audio codec chip.
- Recording (ADC): ES7210 audio encoder chip.
- I2S / I2C Pin Mapping:
- I2S MCLK: GPIO 12
- I2S BCLK: GPIO 13
- I2S LRCK: GPIO 14
- I2S DIN (Microphone): GPIO 15
- I2S DOUT (Speaker): GPIO 16
- I2C SDA: GPIO 11
- I2C SCL: GPIO 10
- WS2812 RGB LEDs: GPIO 38
- Key Features & Peripherals:
- Support for AI Speech Interaction with Dual Digital Microphone Array.
- Hardware/Software Noise Reduction and Echo Cancellation.
- Support for External Displays (1.47", 2", 2.8", 3.5" LCDs) and Cameras (OV2640, OV5640).
- 7-ring programmable RGB LEDs (WS2812B, GRB/RGB order, connected to GPIO 38).
- PCF85063 RTC chip.
-
Development Environment & Toolchain Details:
- ESP-IDF Version: v6.0.1 (Target:
esp32s3) - ESP-IDF Directory:
C:\esp\v6.0.1\esp-idf - ESP-IDF Tools Path:
C:\Espressif\tools - Build Command:
eim run "idf.py build"or executebuild.bat - Flash Command:
eim run "idf.py flash"or executeflash.bat - Serial Monitor Command:
eim run "idf.py monitor"or executemonitor.bat
- ESP-IDF Version: v6.0.1 (Target:
-
Helper Scripts Folder (
/scripts):build.bat/build.ps1: Triggers standard incremental project build.flash.bat/flash.ps1: Automatically rebuilds and flashes project toCOM5at 460800 baud.monitor.bat/monitor.ps1: Launches target serial logging monitor onCOM5(pressCtrl + ]to exit).clean.bat/clean.ps1: Deletes the/buildfolder to enforce clean target configs.
-
Implemented Wi-Fi Functionality:
- Credentials Storage: Wi-Fi credentials are read from the
wifi-credentialsfile in the project root. This file is parsed by CMake during the configure step, and dynamically generateswifi_credentials.hinside the build directory so credentials are never checked into Git. - Station Connection: Initializes Wi-Fi in Station mode and handles auto-reconnect on disconnect (up to 5 retries). Implemented in
wifi_connect.cand started inmain.c.
- Credentials Storage: Wi-Fi credentials are read from the
-
Implemented Audio Functionality:
- Startup Sound: Plays
startup.mp3immediately on boot. - Chime Assets: The audio files in SPIFFS were generated using
agentctl tts:startup.mp3: "Ding Dong, I'm turned on!"connecting_wifi.mp3: "Connecting to the wifi"connected_wifi.mp3: "I'm now connected to the wifi"connected.mp3: "I'm connected!"connect_fail.mp3: "I could not connect"- Packaged into internal SPIFFS partition
modelon the device's flash.
- Playback Management: Implemented
Audio_Play_Music_To_Endinaudio_driver.cto perform blocking playback, preventing overlapping audio playback during initialization. - Codec Init: Initializes ES8311 DAC via I2C at sample rate 16000Hz, stereo (2 channels), 16-bit depth.
- PA Enable: Drivers enable the speaker power amplifier (
PA_CTRL) on pin 8 of the TCA9555 IO expander. - Volume Adjust: Set to
85(0 to 100 range scale) viaVolume_Adjustment(85)insidemain/main.c.
- Startup Sound: Plays
-
Implemented LED Ring Functionality:
- State-driven Display: Background FreeRTOS task
led_rainbow_taskdrives the 7 WS2812B LEDs connected to GPIO 38 based on the global connection state:LED_STATE_IDLE: LEDs remain off during initial startup sounds.LED_STATE_CONNECTING: LEDs flash orange (approx. 500ms intervals) during connection.LED_STATE_FAILED: LEDs glow solid red at 20% brightness on failure.LED_STATE_CONNECTED: LEDs run a vibrant, moving color fade using HSV-to-RGB translation rotating around the ring (speed set to approx. 2.25 seconds per cycle at 20% brightness).
- Dependency: Linked and integrated using the
espressif/led_strip(^3.0.1) component.
- State-driven Display: Background FreeRTOS task
-
Build & Partition Configurations:
- Partition Table: Defined in
partitions.csvwith custommodel(SPIFFS, 5900K size) andflash_test(FATFS, 528K size) partitions. - SPIFFS Generation: The
modelpartition image is automatically built from foldermain/spiffsand flashed using CMake macrospiffs_create_partition_image(model spiffs FLASH_IN_PROJECT)declared insidemain/CMakeLists.txt. - Flash/PSRAM config: Configured for 16MB flash (
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y) and 8MB Octal SPIRAM (CONFIG_SPIRAM=y&CONFIG_SPIRAM_MODE_OCT=y) via pre-configuredsdkconfigimported from Waveshare's demo.
- Partition Table: Defined in
-
Troubleshooting & Porting to ESP-IDF v6.x:
- I2S Types: ESP-IDF v6 removes the legacy I2S driver definitions. Any parameter defined as legacy
i2s_port_tin BSP libraries (e.g.,bsp_board.c) must be changed toint. - Serial Monitoring: The standard serial monitor
idf.py monitorrequires an attached interactive TTY. In sandboxed running environments, raw serial read scripts should be used instead.
- I2S Types: ESP-IDF v6 removes the legacy I2S driver definitions. Any parameter defined as legacy
-
Development Socket Server & Cloudflare Tunneling:
- Dev Server Folder (
/dev-server): Node.js/TypeScript Express & WebSockets server listening on port8901. - Auto-Reload: Configured via
nodemonandts-nodeusingnpm run devin/dev-server. - Logging: Console logs when clients connect, send messages, disconnect, or trigger errors.
- Cloudflare Tunnel Routing: Local configuration
config.ymlis mapped to forward public traffic forexample.comanddashboard.example.comdirectly to loopbackhttp://127.0.0.1:8901. - DNS Mappings: Configure your public hostnames to point to your deployment tunnel or reverse proxy.
- Command Routing: Monitor clients can broadcast
control_devicecommand payloads (volume level adjustments, voice text-to-speech output, LED strip animations, or chime prompts) targeting specific client IDs, which the dev-server routes to standard client device sockets.
- Dev Server Folder (
-
Real-Time Monitor Dashboard Server (
/monitor-server):- Service Port: Port
8902(running via Express). Starts withnpm start. - Layout & Structure: Built with an enterprise-grade dark theme layout featuring a collapsible left sidebar, header operations cards, and responsive page views (
Overview,Device Fleet Manager, andTelemetry Terminal Console). - Dynamic Elements: Includes dynamic search boxes, severity filter button groups, CSV/JSON log exporters, device diagnostic modals, and volume/LED controllers that dispatch control instructions directly to connected ESP32-S3 boards.
- Service Port: Port
-
Hardware Model Variants (DEV-1 and PROTO-1):
- Model Configuration: Defined in the
device-configfile in the project root. Edit this file to switch the active hardware profile:MODEL=DEV-1 # Standard Waveshare development board (default) MODEL=PROTO-1 # Prototype board with additional peripherals - How it works: CMake reads
device-configat configure-time, generatesdevice_config.hin the build directory, and defines eitherMODEL_DEV_1=1orMODEL_PROTO_1=1as a compiler macro on the${COMPONENT_LIB}target. - ⚠️ After changing
device-config: Always runscripts/clean.batfollowed byscripts/build.batto force CMake to regeneratedevice_config.hwith the new model value. An incremental build alone will NOT pick up the change. - DEV-1 Variant: Includes all core firmware functionalities (Wi-Fi, audio playback, WS2812B LEDs on GPIO 38, WebSocket telemetry).
- PROTO-1 Variant: Inherits DEV-1 baseline and introduces:
- Audio I2C/I2S Interface: Same as DEV-1 (GPIO 10–16, EXIO 8 PA_EN), but DIN/DOUT are physically swapped on the PROTO board.
- GPIO 9: WS2812 RGB LED strip signal (replaces GPIO 38 used on DEV-1)
- GPIO 5: Haptics motor — PWM output via LEDC driver (1kHz, 10-bit duty cycle)
- GPIO 4: Ambient light sensor (LDR) — ADC1 Channel 3, analog oneshot read, scaled 0–4095 → 0–100%
- GPIO 7: Capacitive touch sensor — digital input, active HIGH when touched
- Background FreeRTOS task
proto1_sensor_taskpolls GPIO 4 and GPIO 7 every 100ms and updatesdevice_state_tfields:ambient_light(int) andtouch_active(bool). - Haptic intensity is downlink-controllable via
set_hapticsWebSocket command (value 0–100).
- Model Configuration: Defined in the
-
Protocol-First Development Rules:
- API Specification Priority: When implementing any new client/device functionality or modifying messaging structures, you MUST always update
API.mdFIRST as the absolute source of truth before editing any application or driver code. - Implementation Sequence:
- Update/define the JSON schema, commands, and fields in
API.md. - Write the corresponding host (gateway/server) and client (firmware) code changes matching the specification.
- Update/define the JSON schema, commands, and fields in
- API Specification Priority: When implementing any new client/device functionality or modifying messaging structures, you MUST always update