chore: import local project into Gitea
This commit is contained in:
BIN
._.gitignore
Normal file
BIN
._.gitignore
Normal file
Binary file not shown.
BIN
.cache/clangd/index/main.c.40ECD50192E77BED.idx
Normal file
BIN
.cache/clangd/index/main.c.40ECD50192E77BED.idx
Normal file
Binary file not shown.
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# OS / tooling
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Editors
|
||||||
|
.cursor/
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# Secrets
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
!.env.template
|
||||||
|
sdkconfig
|
||||||
|
sdkconfig.old
|
||||||
|
|
||||||
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
.venv/
|
||||||
|
venv/
|
||||||
|
|
||||||
|
# Node / frontend
|
||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# ESP-IDF / embedded build output
|
||||||
|
build/
|
||||||
|
managed_components/
|
||||||
|
dependencies.lock
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
5
CMakeLists.txt
Normal file
5
CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(gemini_gadget)
|
||||||
|
|
||||||
76
README.md
Normal file
76
README.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# Gemini Chat Gadget for ESP32-C6-LCD-1.69
|
||||||
|
|
||||||
|
This project builds a minimal ESP-IDF application that turns an ESP32-C6-LCD-1.69 board into a Gemini chat gadget. It features on-screen state indicators, speaker beeps, Wi-Fi connectivity, and integration with the Gemini API.
|
||||||
|
|
||||||
|
## Hardware
|
||||||
|
|
||||||
|
* **MCU/Board:** ESP32-C6 DevKitC-1
|
||||||
|
* **Display:** 1.69" ST7789V2, 240x280 resolution, SPI interface
|
||||||
|
* **Default Pins (configurable via Kconfig):**
|
||||||
|
* MOSI: GPIO7
|
||||||
|
* SCLK: GPIO6
|
||||||
|
* CS: GPIO5
|
||||||
|
* DC: GPIO2
|
||||||
|
* RST: GPIO4
|
||||||
|
* BL (Backlight): GPIO15
|
||||||
|
* BUTTON: GPIO0
|
||||||
|
* LED: GPIO8
|
||||||
|
* SPEAKER: GPIO25
|
||||||
|
* BAT_EN (Battery Enable): GPIO15 (drive HIGH on battery)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* **Display Auto-Probe:** Automatically detects and configures the ST7789V2 display by trying common rotations, offsets, and SPI clock frequencies.
|
||||||
|
* **UI State Machine:** Visual feedback on the LCD for different states: BOOT, CONNECTING, READY, LISTENING, THINKING, SPEAKING, and ERROR.
|
||||||
|
* **Wi-Fi Connectivity:** Connects to a specified Wi-Fi network in STA mode.
|
||||||
|
* **Gemini API Integration:** Communicates with the Google Gemini API (gemini-1.5-flash model) to generate text responses.
|
||||||
|
* **Audio Feedback:** Uses LEDC to generate tones for listening and speaking states, and a short beep for thinking.
|
||||||
|
* **Button Input:** A button on GPIO0 triggers a chat cycle.
|
||||||
|
* **Battery Management:** Sets `BAT_EN` (GPIO15) HIGH to enable battery power.
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
* `CMakeLists.txt`: Main project CMake file.
|
||||||
|
* `main/CMakeLists.txt`: Component CMake file for the `main` component.
|
||||||
|
* `main/main.c`: Main application source code.
|
||||||
|
* `main/Kconfig.projbuild`: Defines Kconfig options for Wi-Fi credentials, Gemini API key, and LCD pin overrides.
|
||||||
|
* `sdkconfig.defaults`: Default configuration settings, including UART console, FreeRTOS tick rate, and placeholders for Wi-Fi and Gemini API key.
|
||||||
|
|
||||||
|
## Build and Flash Instructions
|
||||||
|
|
||||||
|
1. **Set the ESP-IDF Target:**
|
||||||
|
```bash
|
||||||
|
idf.py set-target esp32c6
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Configure Project Settings:**
|
||||||
|
Run `menuconfig` to set your Wi-Fi SSID, Wi-Fi Password, and Gemini API Key. You can also override default LCD pin assignments here if needed.
|
||||||
|
```bash
|
||||||
|
idf.py menuconfig
|
||||||
|
```
|
||||||
|
Navigate to "Application Configuration" to find the Wi-Fi and Gemini API key settings.
|
||||||
|
Navigate to "Application Configuration" -> "LCD Pin Configuration" to adjust pin assignments.
|
||||||
|
|
||||||
|
3. **Build, Flash, and Monitor:**
|
||||||
|
This command will build the project, flash it to your ESP32-C6 board, and open a serial monitor to view logs.
|
||||||
|
```bash
|
||||||
|
idf.py build flash monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
## Acceptance Criteria
|
||||||
|
|
||||||
|
* Upon boot, the LCD should display a color-sweep during the auto-probe routine, followed by the BOOT, CONNECTING, and READY states.
|
||||||
|
* Pressing the button should initiate the LISTENING state (with a tone), transition to THINKING (with a beep), perform an HTTP POST to the Gemini API, move to SPEAKING (with a tone) while logging the reply, and finally return to the READY state.
|
||||||
|
* The console logs should clearly show auto-probe attempts and results, Wi-Fi connection status, HTTP status codes, and the extracted Gemini text response.
|
||||||
|
* The application should handle Wi-Fi or HTTP failures gracefully, transitioning to an ERROR state with appropriate logging.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
The project is designed to be lightweight and uses the following ESP-IDF components:
|
||||||
|
|
||||||
|
* `esp_lcd`
|
||||||
|
* `esp_http_client`
|
||||||
|
* `cJSON`
|
||||||
|
* `esp_wifi`
|
||||||
|
* `driver` (for GPIO and LEDC)
|
||||||
|
* `esp_timer`
|
||||||
1
components/cjson/CMakeLists.txt
Normal file
1
components/cjson/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
idf_component_register(SRCS "cJSON.c" INCLUDE_DIRS ".")
|
||||||
3452
components/cjson/cJSON.c
Normal file
3452
components/cjson/cJSON.c
Normal file
File diff suppressed because it is too large
Load Diff
306
components/cjson/cJSON.h
Normal file
306
components/cjson/cJSON.h
Normal file
@@ -0,0 +1,306 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef cJSON__h
|
||||||
|
#define cJSON__h
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||||
|
#define __WINDOWS__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
|
||||||
|
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
||||||
|
|
||||||
|
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
||||||
|
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
||||||
|
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
||||||
|
|
||||||
|
For *nix builds that support visibility attribute, you can define similar behavior by
|
||||||
|
|
||||||
|
setting default visibility to hidden by adding
|
||||||
|
-fvisibility=hidden (for gcc)
|
||||||
|
or
|
||||||
|
-xldscope=hidden (for sun cc)
|
||||||
|
to CFLAGS
|
||||||
|
|
||||||
|
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define CJSON_CDECL __cdecl
|
||||||
|
#define CJSON_STDCALL __stdcall
|
||||||
|
|
||||||
|
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
||||||
|
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
||||||
|
#define CJSON_EXPORT_SYMBOLS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CJSON_HIDE_SYMBOLS)
|
||||||
|
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
||||||
|
#elif defined(CJSON_EXPORT_SYMBOLS)
|
||||||
|
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
||||||
|
#elif defined(CJSON_IMPORT_SYMBOLS)
|
||||||
|
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
||||||
|
#endif
|
||||||
|
#else /* !__WINDOWS__ */
|
||||||
|
#define CJSON_CDECL
|
||||||
|
#define CJSON_STDCALL
|
||||||
|
|
||||||
|
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
||||||
|
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||||
|
#else
|
||||||
|
#define CJSON_PUBLIC(type) type
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* project version */
|
||||||
|
#define CJSON_VERSION_MAJOR 1
|
||||||
|
#define CJSON_VERSION_MINOR 7
|
||||||
|
#define CJSON_VERSION_PATCH 18
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/* cJSON Types: */
|
||||||
|
#define cJSON_Invalid (0)
|
||||||
|
#define cJSON_False (1 << 0)
|
||||||
|
#define cJSON_True (1 << 1)
|
||||||
|
#define cJSON_NULL (1 << 2)
|
||||||
|
#define cJSON_Number (1 << 3)
|
||||||
|
#define cJSON_String (1 << 4)
|
||||||
|
#define cJSON_Array (1 << 5)
|
||||||
|
#define cJSON_Object (1 << 6)
|
||||||
|
#define cJSON_Raw (1 << 7) /* raw json */
|
||||||
|
|
||||||
|
#define cJSON_IsReference 256
|
||||||
|
#define cJSON_StringIsConst 512
|
||||||
|
|
||||||
|
/* The cJSON structure: */
|
||||||
|
typedef struct cJSON
|
||||||
|
{
|
||||||
|
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||||
|
struct cJSON *next;
|
||||||
|
struct cJSON *prev;
|
||||||
|
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||||
|
struct cJSON *child;
|
||||||
|
|
||||||
|
/* The type of the item, as above. */
|
||||||
|
int type;
|
||||||
|
|
||||||
|
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
||||||
|
char *valuestring;
|
||||||
|
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||||
|
int valueint;
|
||||||
|
/* The item's number, if type==cJSON_Number */
|
||||||
|
double valuedouble;
|
||||||
|
|
||||||
|
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||||
|
char *string;
|
||||||
|
} cJSON;
|
||||||
|
|
||||||
|
typedef struct cJSON_Hooks
|
||||||
|
{
|
||||||
|
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||||
|
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||||
|
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||||
|
} cJSON_Hooks;
|
||||||
|
|
||||||
|
typedef int cJSON_bool;
|
||||||
|
|
||||||
|
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
|
||||||
|
* This is to prevent stack overflows. */
|
||||||
|
#ifndef CJSON_NESTING_LIMIT
|
||||||
|
#define CJSON_NESTING_LIMIT 1000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Limits the length of circular references can be before cJSON rejects to parse them.
|
||||||
|
* This is to prevent stack overflows. */
|
||||||
|
#ifndef CJSON_CIRCULAR_LIMIT
|
||||||
|
#define CJSON_CIRCULAR_LIMIT 10000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* returns the version of cJSON as a string */
|
||||||
|
CJSON_PUBLIC(const char*) cJSON_Version(void);
|
||||||
|
|
||||||
|
/* Supply malloc, realloc and free functions to cJSON */
|
||||||
|
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||||
|
|
||||||
|
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
||||||
|
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||||
|
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||||
|
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||||
|
|
||||||
|
/* Render a cJSON entity to text for transfer/storage. */
|
||||||
|
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
||||||
|
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||||
|
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||||
|
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||||
|
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||||
|
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||||
|
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||||
|
/* Delete a cJSON entity and all subentities. */
|
||||||
|
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||||
|
|
||||||
|
/* Returns the number of items in an array (or object). */
|
||||||
|
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
||||||
|
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
|
||||||
|
/* Get item "string" from object. Case insensitive. */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||||
|
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||||
|
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||||
|
|
||||||
|
/* Check item type and return its value */
|
||||||
|
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
||||||
|
|
||||||
|
/* These functions check the type of an item */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
|
||||||
|
|
||||||
|
/* These calls create a cJSON item of the appropriate type. */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
||||||
|
/* raw json */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
||||||
|
|
||||||
|
/* Create a string where valuestring references a string so
|
||||||
|
* it will not be freed by cJSON_Delete */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
||||||
|
/* Create an object/array that only references it's elements so
|
||||||
|
* they will not be freed by cJSON_Delete */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
||||||
|
|
||||||
|
/* These utilities create an Array of count items.
|
||||||
|
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
|
||||||
|
|
||||||
|
/* Append item to the specified array/object. */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||||
|
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
|
||||||
|
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
|
||||||
|
* writing to `item->string` */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
||||||
|
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
||||||
|
|
||||||
|
/* Remove/Detach items from Arrays/Objects. */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
|
||||||
|
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||||
|
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
||||||
|
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||||
|
|
||||||
|
/* Update array items. */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
|
||||||
|
|
||||||
|
/* Duplicate a cJSON item */
|
||||||
|
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
||||||
|
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||||
|
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||||
|
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||||
|
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
||||||
|
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||||
|
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
|
||||||
|
|
||||||
|
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||||
|
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||||
|
* but should point to a readable and writable address area. */
|
||||||
|
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||||
|
|
||||||
|
/* Helper functions for creating and adding items to an object at the same time.
|
||||||
|
* They return the added item or NULL on failure. */
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
|
||||||
|
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
|
||||||
|
|
||||||
|
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||||
|
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||||
|
/* helper for the cJSON_SetNumberValue macro */
|
||||||
|
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||||
|
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||||
|
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
||||||
|
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||||
|
|
||||||
|
/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
|
||||||
|
#define cJSON_SetBoolValue(object, boolValue) ( \
|
||||||
|
(object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
|
||||||
|
(object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
|
||||||
|
cJSON_Invalid\
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Macro for iterating over an array or object */
|
||||||
|
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||||
|
|
||||||
|
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||||
|
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||||
|
CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
14
main/CMakeLists.txt
Normal file
14
main/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS "main.c"
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES
|
||||||
|
esp_wifi
|
||||||
|
esp_event
|
||||||
|
esp_netif
|
||||||
|
nvs_flash
|
||||||
|
esp_lcd
|
||||||
|
driver
|
||||||
|
esp_http_client
|
||||||
|
esp_timer
|
||||||
|
cjson
|
||||||
|
)
|
||||||
85
main/Kconfig.projbuild
Normal file
85
main/Kconfig.projbuild
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
menu "Application Configuration"
|
||||||
|
|
||||||
|
config APP_WIFI_SSID
|
||||||
|
string "Wi-Fi SSID"
|
||||||
|
default "YOUR_WIFI_SSID"
|
||||||
|
help
|
||||||
|
SSID of the Wi-Fi network to connect to.
|
||||||
|
|
||||||
|
config APP_WIFI_PASSWORD
|
||||||
|
string "Wi-Fi Password"
|
||||||
|
default "YOUR_WIFI_PASSWORD"
|
||||||
|
help
|
||||||
|
Password of the Wi-Fi network.
|
||||||
|
|
||||||
|
config APP_GEMINI_API_KEY
|
||||||
|
string "Gemini API Key"
|
||||||
|
default "YOUR_GEMINI_API_KEY"
|
||||||
|
help
|
||||||
|
API key for accessing the Gemini API.
|
||||||
|
|
||||||
|
menu "LCD Pin Configuration"
|
||||||
|
|
||||||
|
config LCD_PIN_MOSI
|
||||||
|
int "LCD MOSI Pin"
|
||||||
|
default 7
|
||||||
|
help
|
||||||
|
GPIO pin for LCD MOSI.
|
||||||
|
|
||||||
|
config LCD_PIN_SCLK
|
||||||
|
int "LCD SCLK Pin"
|
||||||
|
default 6
|
||||||
|
help
|
||||||
|
GPIO pin for LCD SCLK.
|
||||||
|
|
||||||
|
config LCD_PIN_CS
|
||||||
|
int "LCD CS Pin"
|
||||||
|
default 5
|
||||||
|
help
|
||||||
|
GPIO pin for LCD CS.
|
||||||
|
|
||||||
|
config LCD_PIN_DC
|
||||||
|
int "LCD DC Pin"
|
||||||
|
default 2
|
||||||
|
help
|
||||||
|
GPIO pin for LCD DC.
|
||||||
|
|
||||||
|
config LCD_PIN_RST
|
||||||
|
int "LCD RST Pin"
|
||||||
|
default 4
|
||||||
|
help
|
||||||
|
GPIO pin for LCD RST.
|
||||||
|
|
||||||
|
config LCD_PIN_BL
|
||||||
|
int "LCD Backlight Pin"
|
||||||
|
default 15
|
||||||
|
help
|
||||||
|
GPIO pin for LCD Backlight.
|
||||||
|
|
||||||
|
config LCD_PIN_BUTTON
|
||||||
|
int "Button Pin"
|
||||||
|
default 0
|
||||||
|
help
|
||||||
|
GPIO pin for the user button.
|
||||||
|
|
||||||
|
config LCD_PIN_LED
|
||||||
|
int "Status LED Pin"
|
||||||
|
default 8
|
||||||
|
help
|
||||||
|
GPIO pin for the status LED.
|
||||||
|
|
||||||
|
config LCD_PIN_SPEAKER
|
||||||
|
int "Speaker Pin"
|
||||||
|
default 25
|
||||||
|
help
|
||||||
|
GPIO pin for the speaker.
|
||||||
|
|
||||||
|
config LCD_PIN_BAT_EN
|
||||||
|
int "Battery Enable Pin"
|
||||||
|
default 15
|
||||||
|
help
|
||||||
|
GPIO pin to enable battery power.
|
||||||
|
|
||||||
|
endmenu
|
||||||
|
|
||||||
|
endmenu
|
||||||
16
main/idf_component.yml
Normal file
16
main/idf_component.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
## IDF Component Manager Manifest File
|
||||||
|
dependencies:
|
||||||
|
## Required IDF version
|
||||||
|
idf:
|
||||||
|
version: ">=4.1.0"
|
||||||
|
# # Put list of dependencies here
|
||||||
|
# # For components maintained by Espressif:
|
||||||
|
# component: "~1.0.0"
|
||||||
|
# # For 3rd party components:
|
||||||
|
# username/component: ">=1.0.0,<2.0.0"
|
||||||
|
# username2/component2:
|
||||||
|
# version: "~1.0.0"
|
||||||
|
# # For transient dependencies `public` flag can be set.
|
||||||
|
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||||
|
# # All dependencies of `main` are public by default.
|
||||||
|
# public: true
|
||||||
598
main/main.c
Normal file
598
main/main.c
Normal file
@@ -0,0 +1,598 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_timer.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "esp_event.h"
|
||||||
|
#include "esp_netif.h"
|
||||||
|
#include "esp_netif_ip_addr.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
#include "esp_http_client.h"
|
||||||
|
// TLS bundle not required as a build dependency; keep header optional
|
||||||
|
#ifdef __has_include
|
||||||
|
# if __has_include("esp_crt_bundle.h")
|
||||||
|
# include "esp_crt_bundle.h"
|
||||||
|
# define HAS_CRT_BUNDLE 1
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "driver/ledc.h"
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
|
||||||
|
#include "esp_lcd_panel_io.h"
|
||||||
|
#include "esp_lcd_panel_vendor.h"
|
||||||
|
#include "esp_lcd_panel_ops.h"
|
||||||
|
#include "esp_lcd_types.h"
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include "cJSON.h"
|
||||||
|
|
||||||
|
// Kconfig symbols
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
// Pins from Kconfig (with sensible fallbacks)
|
||||||
|
#ifndef CONFIG_LCD_PIN_MOSI
|
||||||
|
#define CONFIG_LCD_PIN_MOSI 7
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_SCLK
|
||||||
|
#define CONFIG_LCD_PIN_SCLK 6
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_CS
|
||||||
|
#define CONFIG_LCD_PIN_CS 5
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_DC
|
||||||
|
#define CONFIG_LCD_PIN_DC 2
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_RST
|
||||||
|
#define CONFIG_LCD_PIN_RST 4
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_BL
|
||||||
|
#define CONFIG_LCD_PIN_BL 15
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_BUTTON
|
||||||
|
#define CONFIG_LCD_PIN_BUTTON 0
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_LED
|
||||||
|
#define CONFIG_LCD_PIN_LED 8
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_SPEAKER
|
||||||
|
#define CONFIG_LCD_PIN_SPEAKER 25
|
||||||
|
#endif
|
||||||
|
#ifndef CONFIG_LCD_PIN_BAT_EN
|
||||||
|
#define CONFIG_LCD_PIN_BAT_EN 15
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Display constants
|
||||||
|
#define LCD_H_RES 240
|
||||||
|
#define LCD_V_RES 280
|
||||||
|
|
||||||
|
static const char *TAG = "GEMINI_GADGET";
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
UI_BOOT,
|
||||||
|
UI_CONNECTING,
|
||||||
|
UI_READY,
|
||||||
|
UI_LISTENING,
|
||||||
|
UI_THINKING,
|
||||||
|
UI_SPEAKING,
|
||||||
|
UI_ERROR
|
||||||
|
} ui_state_t;
|
||||||
|
|
||||||
|
// LCD handles
|
||||||
|
static esp_lcd_panel_handle_t s_panel = NULL;
|
||||||
|
static int s_rotation = 0;
|
||||||
|
static int s_offset_y = 0;
|
||||||
|
static int s_spi_clk_hz = 0;
|
||||||
|
|
||||||
|
// Button semaphore to trigger a chat cycle
|
||||||
|
static SemaphoreHandle_t s_btn_sem = NULL;
|
||||||
|
|
||||||
|
// Tone control
|
||||||
|
static void tone_init(void);
|
||||||
|
static void tone_start(uint32_t freq_hz);
|
||||||
|
static void tone_stop(void);
|
||||||
|
static void tone_beep(uint32_t freq_hz, uint32_t duration_ms);
|
||||||
|
|
||||||
|
// Wi-Fi
|
||||||
|
static esp_err_t wifi_init_and_connect(const char *ssid, const char *pass, int timeout_ms);
|
||||||
|
|
||||||
|
// HTTP / Gemini
|
||||||
|
static char *gemini_generate_text(const char *api_key, const char *prompt, int *http_status_out);
|
||||||
|
|
||||||
|
// UI helpers
|
||||||
|
static void ui_set_state(ui_state_t state);
|
||||||
|
static bool lcd_autoprobe(void);
|
||||||
|
|
||||||
|
// Simple color helper (RGB565)
|
||||||
|
static inline uint16_t rgb565(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_solid_color(uint16_t color) {
|
||||||
|
if (!s_panel) return;
|
||||||
|
static uint16_t *line = NULL;
|
||||||
|
const int width = LCD_H_RES;
|
||||||
|
const int height = LCD_V_RES;
|
||||||
|
if (!line) {
|
||||||
|
line = (uint16_t *)heap_caps_malloc(width * sizeof(uint16_t), MALLOC_CAP_DMA);
|
||||||
|
}
|
||||||
|
if (!line) {
|
||||||
|
ESP_LOGE(TAG, "Failed to alloc line buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int x = 0; x < width; ++x) line[x] = color;
|
||||||
|
for (int y = 0; y < height; ++y) {
|
||||||
|
esp_lcd_panel_draw_bitmap(s_panel, 0, y, width, y + 1, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void color_sweep(void) {
|
||||||
|
if (!s_panel) return;
|
||||||
|
const uint16_t colors[] = {
|
||||||
|
rgb565(255, 0, 0),
|
||||||
|
rgb565(0, 255, 0),
|
||||||
|
rgb565(0, 0, 255),
|
||||||
|
rgb565(255, 255, 255),
|
||||||
|
rgb565(0, 0, 0)
|
||||||
|
};
|
||||||
|
for (size_t i = 0; i < sizeof(colors)/sizeof(colors[0]); ++i) {
|
||||||
|
draw_solid_color(colors[i]);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(200));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ui_set_state(ui_state_t state) {
|
||||||
|
switch (state) {
|
||||||
|
case UI_BOOT:
|
||||||
|
ESP_LOGI(TAG, "STATE: BOOT");
|
||||||
|
draw_solid_color(rgb565(32, 32, 64));
|
||||||
|
break;
|
||||||
|
case UI_CONNECTING:
|
||||||
|
ESP_LOGI(TAG, "STATE: CONNECTING");
|
||||||
|
draw_solid_color(rgb565(64, 64, 0));
|
||||||
|
break;
|
||||||
|
case UI_READY:
|
||||||
|
ESP_LOGI(TAG, "STATE: READY");
|
||||||
|
draw_solid_color(rgb565(0, 64, 0));
|
||||||
|
break;
|
||||||
|
case UI_LISTENING:
|
||||||
|
ESP_LOGI(TAG, "STATE: LISTENING");
|
||||||
|
draw_solid_color(rgb565(0, 0, 128));
|
||||||
|
break;
|
||||||
|
case UI_THINKING:
|
||||||
|
ESP_LOGI(TAG, "STATE: THINKING");
|
||||||
|
draw_solid_color(rgb565(128, 0, 128));
|
||||||
|
break;
|
||||||
|
case UI_SPEAKING:
|
||||||
|
ESP_LOGI(TAG, "STATE: SPEAKING");
|
||||||
|
draw_solid_color(rgb565(0, 128, 128));
|
||||||
|
break;
|
||||||
|
case UI_ERROR:
|
||||||
|
default:
|
||||||
|
ESP_LOGE(TAG, "STATE: ERROR");
|
||||||
|
draw_solid_color(rgb565(128, 0, 0));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Button ISR
|
||||||
|
static volatile uint64_t s_last_btn_us = 0;
|
||||||
|
static void IRAM_ATTR button_isr(void *arg) {
|
||||||
|
uint64_t now = esp_timer_get_time();
|
||||||
|
if ((now - s_last_btn_us) > 200000) { // 200ms debounce
|
||||||
|
BaseType_t hpw = pdFALSE;
|
||||||
|
xSemaphoreGiveFromISR(s_btn_sem, &hpw);
|
||||||
|
if (hpw) portYIELD_FROM_ISR();
|
||||||
|
s_last_btn_us = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gpio_init_all(void) {
|
||||||
|
// Battery enable
|
||||||
|
gpio_config_t io = {
|
||||||
|
.pin_bit_mask = 1ULL << CONFIG_LCD_PIN_BAT_EN,
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = GPIO_INTR_DISABLE
|
||||||
|
};
|
||||||
|
gpio_config(&io);
|
||||||
|
gpio_set_level(CONFIG_LCD_PIN_BAT_EN, 1);
|
||||||
|
|
||||||
|
// Backlight
|
||||||
|
io.pin_bit_mask = 1ULL << CONFIG_LCD_PIN_BL;
|
||||||
|
gpio_config(&io);
|
||||||
|
gpio_set_level(CONFIG_LCD_PIN_BL, 1);
|
||||||
|
|
||||||
|
// Status LED (optional)
|
||||||
|
io.pin_bit_mask = 1ULL << CONFIG_LCD_PIN_LED;
|
||||||
|
gpio_config(&io);
|
||||||
|
gpio_set_level(CONFIG_LCD_PIN_LED, 0);
|
||||||
|
|
||||||
|
// Button
|
||||||
|
gpio_config_t bi = {
|
||||||
|
.pin_bit_mask = 1ULL << CONFIG_LCD_PIN_BUTTON,
|
||||||
|
.mode = GPIO_MODE_INPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = GPIO_INTR_NEGEDGE
|
||||||
|
};
|
||||||
|
gpio_config(&bi);
|
||||||
|
gpio_install_isr_service(0);
|
||||||
|
gpio_isr_handler_add(CONFIG_LCD_PIN_BUTTON, button_isr, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tone_init(void) {
|
||||||
|
ledc_timer_config_t tcfg = {
|
||||||
|
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||||
|
.duty_resolution = LEDC_TIMER_10_BIT,
|
||||||
|
.timer_num = LEDC_TIMER_0,
|
||||||
|
.freq_hz = 2000,
|
||||||
|
.clk_cfg = LEDC_AUTO_CLK,
|
||||||
|
};
|
||||||
|
ledc_timer_config(&tcfg);
|
||||||
|
|
||||||
|
ledc_channel_config_t ccfg = {
|
||||||
|
.gpio_num = CONFIG_LCD_PIN_SPEAKER,
|
||||||
|
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||||
|
.channel = LEDC_CHANNEL_0,
|
||||||
|
.intr_type = LEDC_INTR_DISABLE,
|
||||||
|
.timer_sel = LEDC_TIMER_0,
|
||||||
|
.duty = 0,
|
||||||
|
.hpoint = 0,
|
||||||
|
.flags = {0},
|
||||||
|
};
|
||||||
|
ledc_channel_config(&ccfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tone_start(uint32_t freq_hz) {
|
||||||
|
ledc_set_freq(LEDC_LOW_SPEED_MODE, LEDC_TIMER_0, freq_hz);
|
||||||
|
ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, (1 << 9)); // ~50% of 10-bit
|
||||||
|
ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tone_stop(void) {
|
||||||
|
ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0);
|
||||||
|
ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tone_beep(uint32_t freq_hz, uint32_t duration_ms) {
|
||||||
|
tone_start(freq_hz);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(duration_ms));
|
||||||
|
tone_stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// LCD setup using esp_lcd
|
||||||
|
static bool lcd_autoprobe(void) {
|
||||||
|
ESP_LOGI(TAG, "LCD autoprobe start");
|
||||||
|
|
||||||
|
// Prepare SPI bus using SPI master driver (compatible across IDF versions)
|
||||||
|
spi_bus_config_t buscfg = {
|
||||||
|
.sclk_io_num = CONFIG_LCD_PIN_SCLK,
|
||||||
|
.mosi_io_num = CONFIG_LCD_PIN_MOSI,
|
||||||
|
.miso_io_num = -1,
|
||||||
|
.quadwp_io_num = -1,
|
||||||
|
.quadhd_io_num = -1,
|
||||||
|
.max_transfer_sz = LCD_H_RES * 40 * sizeof(uint16_t),
|
||||||
|
.flags = 0,
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||||
|
|
||||||
|
const int clk_candidates[] = { 40000000, 32000000, 24000000 };
|
||||||
|
const int offsets_y[] = { 0, 20 };
|
||||||
|
|
||||||
|
for (size_t ck = 0; ck < sizeof(clk_candidates)/sizeof(clk_candidates[0]); ++ck) {
|
||||||
|
for (int rot = 0; rot < 4; ++rot) {
|
||||||
|
for (size_t oy = 0; oy < sizeof(offsets_y)/sizeof(offsets_y[0]); ++oy) {
|
||||||
|
int offy = offsets_y[oy];
|
||||||
|
ESP_LOGI(TAG, "Probe try: clk=%d rot=%d offY=%d", clk_candidates[ck], rot, offy);
|
||||||
|
|
||||||
|
esp_lcd_panel_io_spi_config_t io_cfg = {
|
||||||
|
.dc_gpio_num = CONFIG_LCD_PIN_DC,
|
||||||
|
.cs_gpio_num = CONFIG_LCD_PIN_CS,
|
||||||
|
.pclk_hz = clk_candidates[ck],
|
||||||
|
.lcd_cmd_bits = 8,
|
||||||
|
.lcd_param_bits = 8,
|
||||||
|
.spi_mode = 0,
|
||||||
|
.trans_queue_depth = 10,
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||||
|
if (esp_lcd_new_panel_io_spi(SPI2_HOST, &io_cfg, &io_handle) != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "io new failed");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_lcd_panel_dev_config_t panel_cfg = {
|
||||||
|
.reset_gpio_num = CONFIG_LCD_PIN_RST,
|
||||||
|
.color_space = ESP_LCD_COLOR_SPACE_RGB,
|
||||||
|
.bits_per_pixel = 16,
|
||||||
|
.vendor_config = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_lcd_panel_handle_t panel = NULL;
|
||||||
|
if (esp_lcd_new_panel_st7789(io_handle, &panel_cfg, &panel) != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "panel new failed");
|
||||||
|
esp_lcd_panel_io_del(io_handle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (esp_lcd_panel_reset(panel) != ESP_OK || esp_lcd_panel_init(panel) != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "panel init failed");
|
||||||
|
esp_lcd_panel_del(panel);
|
||||||
|
esp_lcd_panel_io_del(io_handle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_lcd_panel_swap_xy(panel, rot & 1);
|
||||||
|
esp_lcd_panel_mirror(panel, (rot & 2) != 0, (rot & 2) != 0);
|
||||||
|
esp_lcd_panel_set_gap(panel, 0, offy);
|
||||||
|
|
||||||
|
s_panel = panel;
|
||||||
|
s_rotation = rot;
|
||||||
|
s_offset_y = offy;
|
||||||
|
s_spi_clk_hz = clk_candidates[ck];
|
||||||
|
|
||||||
|
color_sweep();
|
||||||
|
ESP_LOGI(TAG, "LCD autoprobe success: clk=%d rot=%d offY=%d", s_spi_clk_hz, s_rotation, s_offset_y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_LOGE(TAG, "LCD autoprobe failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wi-Fi event group substitute via callbacks
|
||||||
|
static bool s_got_ip = false;
|
||||||
|
static void on_got_ip(void* arg, esp_event_base_t base, int32_t id, void* data) {
|
||||||
|
ip_event_got_ip_t *e = (ip_event_got_ip_t *)data;
|
||||||
|
ESP_LOGI(TAG, "Got IP: " IPSTR, IP2STR(&e->ip_info.ip));
|
||||||
|
s_got_ip = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t wifi_init_and_connect(const char *ssid, const char *pass, int timeout_ms) {
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_init());
|
||||||
|
ESP_ERROR_CHECK(esp_netif_init());
|
||||||
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
|
esp_netif_create_default_wifi_sta();
|
||||||
|
|
||||||
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &on_got_ip, NULL));
|
||||||
|
|
||||||
|
wifi_config_t wcfg = {0};
|
||||||
|
strlcpy((char*)wcfg.sta.ssid, ssid ? ssid : "", sizeof(wcfg.sta.ssid));
|
||||||
|
strlcpy((char*)wcfg.sta.password, pass ? pass : "", sizeof(wcfg.sta.password));
|
||||||
|
wcfg.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
|
||||||
|
wcfg.sta.pmf_cfg.capable = true;
|
||||||
|
wcfg.sta.pmf_cfg.required = false;
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wcfg));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||||
|
|
||||||
|
const int64_t start = esp_timer_get_time();
|
||||||
|
int backoff_ms = 500;
|
||||||
|
while (!s_got_ip) {
|
||||||
|
if ((esp_timer_get_time() - start) / 1000 > timeout_ms) {
|
||||||
|
ESP_LOGE(TAG, "Wi-Fi connect timeout");
|
||||||
|
return ESP_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(backoff_ms));
|
||||||
|
backoff_ms = backoff_ms < 5000 ? backoff_ms * 2 : 5000;
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP client event: accumulate body
|
||||||
|
typedef struct {
|
||||||
|
char *buf;
|
||||||
|
size_t len;
|
||||||
|
} http_buf_t;
|
||||||
|
|
||||||
|
static esp_err_t http_evt_hdl(esp_http_client_event_t *evt) {
|
||||||
|
http_buf_t *hb = (http_buf_t *)evt->user_data;
|
||||||
|
switch (evt->event_id) {
|
||||||
|
case HTTP_EVENT_ON_DATA:
|
||||||
|
if (evt->data_len > 0) {
|
||||||
|
char *p = realloc(hb->buf, hb->len + evt->data_len + 1);
|
||||||
|
if (!p) return ESP_FAIL;
|
||||||
|
hb->buf = p;
|
||||||
|
memcpy(hb->buf + hb->len, evt->data, evt->data_len);
|
||||||
|
hb->len += evt->data_len;
|
||||||
|
hb->buf[hb->len] = '\0';
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *json_escape(const char *s) {
|
||||||
|
size_t n = 0;
|
||||||
|
for (const char *p = s; *p; ++p) {
|
||||||
|
switch (*p) { case '"': case '\\': case '\n': case '\r': case '\t': n += 2; break; default: n += 1; }
|
||||||
|
}
|
||||||
|
char *out = malloc(n + 1);
|
||||||
|
char *w = out;
|
||||||
|
for (const char *p = s; *p; ++p) {
|
||||||
|
switch (*p) {
|
||||||
|
case '"': *w++ = '\\'; *w++ = '"'; break;
|
||||||
|
case '\\': *w++ = '\\'; *w++ = '\\'; break;
|
||||||
|
case '\n': *w++ = '\\'; *w++ = 'n'; break;
|
||||||
|
case '\r': *w++ = '\\'; *w++ = 'r'; break;
|
||||||
|
case '\t': *w++ = '\\'; *w++ = 't'; break;
|
||||||
|
default: *w++ = *p; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*w = '\0';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *build_gemini_payload(const char *prompt) {
|
||||||
|
char *e = json_escape(prompt);
|
||||||
|
const char *fmt = "{\"contents\":[{\"parts\":[{\"text\":\"%s\"}]}],\"generationConfig\":{\"maxOutputTokens\":150,\"temperature\":0.7,\"topP\":0.8,\"topK\":40}}";
|
||||||
|
size_t len = strlen(fmt) + strlen(e) + 1;
|
||||||
|
char *buf = malloc(len);
|
||||||
|
snprintf(buf, len, fmt, e);
|
||||||
|
free(e);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *parse_gemini_reply(const char *json) {
|
||||||
|
cJSON *root = cJSON_Parse(json);
|
||||||
|
if (!root) {
|
||||||
|
ESP_LOGE(TAG, "JSON parse error: %s", cJSON_GetErrorPtr());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *candidates = cJSON_GetObjectItemCaseSensitive(root, "candidates");
|
||||||
|
if (!cJSON_IsArray(candidates) || cJSON_GetArraySize(candidates) == 0) {
|
||||||
|
ESP_LOGE(TAG, "No candidates found in JSON");
|
||||||
|
cJSON_Delete(root);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *first_candidate = cJSON_GetArrayItem(candidates, 0);
|
||||||
|
cJSON *content = cJSON_GetObjectItemCaseSensitive(first_candidate, "content");
|
||||||
|
cJSON *parts = cJSON_GetObjectItemCaseSensitive(content, "parts");
|
||||||
|
if (!cJSON_IsArray(parts) || cJSON_GetArraySize(parts) == 0) {
|
||||||
|
ESP_LOGE(TAG, "No parts found in content");
|
||||||
|
cJSON_Delete(root);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *first_part = cJSON_GetArrayItem(parts, 0);
|
||||||
|
cJSON *text = cJSON_GetObjectItemCaseSensitive(first_part, "text");
|
||||||
|
|
||||||
|
char *reply_text = NULL;
|
||||||
|
if (cJSON_IsString(text) && (text->valuestring != NULL)) {
|
||||||
|
reply_text = strdup(text->valuestring);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "Text field not found or not a string");
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(root);
|
||||||
|
return reply_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *gemini_generate_text(const char *api_key, const char *prompt, int *http_status_out) {
|
||||||
|
if (!api_key || strlen(api_key) == 0) {
|
||||||
|
ESP_LOGE(TAG, "API key not set");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char url[256];
|
||||||
|
snprintf(url, sizeof(url),
|
||||||
|
"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=%s",
|
||||||
|
api_key);
|
||||||
|
|
||||||
|
http_buf_t hb = {0};
|
||||||
|
esp_http_client_config_t cfg = {
|
||||||
|
.url = url,
|
||||||
|
.event_handler = http_evt_hdl,
|
||||||
|
.user_data = &hb,
|
||||||
|
.method = HTTP_METHOD_POST,
|
||||||
|
#ifdef HAS_CRT_BUNDLE
|
||||||
|
.crt_bundle_attach = esp_crt_bundle_attach,
|
||||||
|
#endif
|
||||||
|
.timeout_ms = 15000,
|
||||||
|
};
|
||||||
|
esp_http_client_handle_t cli = esp_http_client_init(&cfg);
|
||||||
|
if (!cli) return NULL;
|
||||||
|
|
||||||
|
char *payload = build_gemini_payload(prompt);
|
||||||
|
esp_http_client_set_header(cli, "Content-Type", "application/json");
|
||||||
|
esp_http_client_set_post_field(cli, payload, strlen(payload));
|
||||||
|
|
||||||
|
esp_err_t err = esp_http_client_perform(cli);
|
||||||
|
int status = -1;
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
status = esp_http_client_get_status_code(cli);
|
||||||
|
ESP_LOGI(TAG, "HTTP status: %d, len=%d", status, (int)hb.len);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "HTTP perform failed: %s", esp_err_to_name(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (http_status_out) *http_status_out = status;
|
||||||
|
char *reply_text = NULL;
|
||||||
|
if (status == 200 && hb.buf) {
|
||||||
|
reply_text = parse_gemini_reply(hb.buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(payload);
|
||||||
|
if (hb.buf) free(hb.buf);
|
||||||
|
esp_http_client_cleanup(cli);
|
||||||
|
return reply_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void chat_cycle_task(void *arg) {
|
||||||
|
while (1) {
|
||||||
|
if (xSemaphoreTake(s_btn_sem, portMAX_DELAY) == pdTRUE) {
|
||||||
|
ui_set_state(UI_LISTENING);
|
||||||
|
tone_start(880);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(5000)); // simulate listening
|
||||||
|
tone_stop();
|
||||||
|
|
||||||
|
ui_set_state(UI_THINKING);
|
||||||
|
tone_beep(1400, 150);
|
||||||
|
|
||||||
|
int http_status = -1;
|
||||||
|
char *reply = gemini_generate_text(CONFIG_APP_GEMINI_API_KEY, "Say a friendly hello from ESP32-C6.", &http_status);
|
||||||
|
|
||||||
|
if (!reply) {
|
||||||
|
ESP_LOGE(TAG, "Gemini request failed (status=%d)", http_status);
|
||||||
|
ui_set_state(UI_ERROR);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
ui_set_state(UI_READY);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_set_state(UI_SPEAKING);
|
||||||
|
ESP_LOGI(TAG, "Gemini reply: %s", reply);
|
||||||
|
tone_start(660);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1500));
|
||||||
|
tone_stop();
|
||||||
|
|
||||||
|
free(reply);
|
||||||
|
ui_set_state(UI_READY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_main(void) {
|
||||||
|
s_btn_sem = xSemaphoreCreateBinary();
|
||||||
|
gpio_init_all();
|
||||||
|
tone_init();
|
||||||
|
|
||||||
|
ui_set_state(UI_BOOT);
|
||||||
|
|
||||||
|
if (!lcd_autoprobe()) {
|
||||||
|
ui_set_state(UI_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_set_state(UI_CONNECTING);
|
||||||
|
if (wifi_init_and_connect(CONFIG_APP_WIFI_SSID, CONFIG_APP_WIFI_PASSWORD, 30000) != ESP_OK) {
|
||||||
|
ui_set_state(UI_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_set_state(UI_READY);
|
||||||
|
|
||||||
|
xTaskCreate(chat_cycle_task, "chat", 8192, NULL, 5, NULL);
|
||||||
|
}
|
||||||
46
readme_ai.md
Normal file
46
readme_ai.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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).
|
||||||
26
sdkconfig.defaults
Normal file
26
sdkconfig.defaults
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# UART console on
|
||||||
|
CONFIG_ESP_CONSOLE_UART_ENABLE=y
|
||||||
|
CONFIG_ESP_CONSOLE_UART_NUM=0
|
||||||
|
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
|
||||||
|
|
||||||
|
# Tick 1 kHz
|
||||||
|
CONFIG_FREERTOS_HZ=1000
|
||||||
|
|
||||||
|
# Wi-Fi SSID and Password placeholders
|
||||||
|
CONFIG_APP_WIFI_SSID="YOUR_WIFI_SSID"
|
||||||
|
CONFIG_APP_WIFI_PASSWORD="YOUR_WIFI_PASSWORD"
|
||||||
|
|
||||||
|
# Gemini API Key placeholder
|
||||||
|
CONFIG_APP_GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
|
||||||
|
|
||||||
|
# Default LCD Pin Configuration (from readme_ai.md)
|
||||||
|
CONFIG_LCD_PIN_MOSI=7
|
||||||
|
CONFIG_LCD_PIN_SCLK=6
|
||||||
|
CONFIG_LCD_PIN_CS=5
|
||||||
|
CONFIG_LCD_PIN_DC=2
|
||||||
|
CONFIG_LCD_PIN_RST=4
|
||||||
|
CONFIG_LCD_PIN_BL=15
|
||||||
|
CONFIG_LCD_PIN_BUTTON=0
|
||||||
|
CONFIG_LCD_PIN_LED=8
|
||||||
|
CONFIG_LCD_PIN_SPEAKER=25
|
||||||
|
CONFIG_LCD_PIN_BAT_EN=15
|
||||||
Reference in New Issue
Block a user