2.9 KiB
You are an embedded engineer. Build a minimal ESP-IDF project that turns an ESP32-C6-LCD-1.69 board into a Gemini chat gadget with on-screen states and speaker beeps. • Target MCU/Board: ESP32-C6 DevKitC-1, ESP-IDF ≥ 5.4 Display: 1.69" ST7789V2, 240×280, SPI Pins (default; make configurable via Kconfig): MOSI=7, SCLK=6, CS=5, DC=2, RST=4, BL=15, BUTTON=0, LED=8, SPEAKER=25, BAT_EN=15 (drive HIGH on battery) • Project structure (ESP-IDF) CMakeLists.txt (project) main/CMakeLists.txt main/main.c sdkconfig.defaults (UART console on, tick 1 kHz; placeholders for Wi‑Fi SSID/PASS and GEMINI_API_KEY) • Functional requirements Power/Battery: Set BAT_EN (GPIO15) HIGH in app_main. Display (esp_lcd): Use esp_lcd_panel_io_spi + esp_lcd_new_panel_st7789. Implement an auto-probe routine that tries common rotations (0–3), offsets for 240×280 (e.g., 0/20 rows), and SPI clk (24–40 MHz) until color sweep appears; log each attempt. On success, show simple UI states with solid colors and brief labels (OK to log labels to Serial if you don’t add a font renderer). Wi‑Fi: STA mode; read SSID/PASS from Kconfig (fallback to sdkconfig.defaults). Connect with retry/backoff; log IP or fail after timeout. Gemini API: Use esp_http_client + cJSON. POST to https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${GEMINI_API_KEY}. Payload: contents[0].parts[0].text = short prompt; generationConfig with maxOutputTokens=150, temperature=0.7, topP=0.8, topK=40. Parse candidates[0].content.parts[0].text; log response. GEMINI_API_KEY configurable via Kconfig string; do not hardcode in source. UI state machine: States: BOOT → CONNECTING → READY → LISTENING (simulate 5s) → THINKING (HTTP) → SPEAKING (show/log reply) → READY; ERROR on failures. Show colors per state and print logs; optional minimal on-screen text. Audio: LEDC: 10-bit, tones on SPEAKER=25. Short beep on THINKING; continuous tone during LISTENING/SPEAKING demos. Input: Button on GPIO0 (FALLING), ISR + debounce counter to trigger one chat cycle. • Deliverables Buildable ESP-IDF project with the files above. Kconfig options: WIFI_SSID, WIFI_PASSWORD, GEMINI_API_KEY, and LCD pin overrides. Console logs that clearly show: auto-probe attempts/results, Wi‑Fi connect, HTTP status, extracted Gemini text. Basic README with build/flash steps and how to set Kconfig. • Build/flash idf.py set-target esp32c6 idf.py menuconfig (set Wi‑Fi and API key) idf.py build flash monitor • Acceptance criteria On boot: color-sweep during LCD auto-probe, then BOOT/CONNECTING/READY cycle. Button press: LISTENING (tone), THINKING (beep), HTTP POST, SPEAKING (tone) with reply logged, return to READY. Robust logs (no silent failures); clean error state if Wi‑Fi or HTTP fails. Keep the code small, clear, and dependency-light (esp_lcd, esp_http_client, cJSON, Wi‑Fi, LEDC).