Compare commits

4 Commits

Author SHA1 Message Date
cqc
a2605672d2 https request with graphics works finally 2026-02-21 16:21:47 +01:00
cqc
b8d315d7e4 basic wifi station 2026-02-02 01:02:01 +01:00
cqc
6230255137 lvgl hello world 2026-02-02 00:43:39 +01:00
cqc
818f773c49 using ESP-IDF v5.5.2 with ESP32-C6-Touch-AMOLED-2.06 2026-02-01 23:28:52 +01:00
11 changed files with 443 additions and 32 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
secrets.h
# esp-idf stuff
build/
managed_components/
sdkconfig
dependencies.lock
.#*
*~

8
CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_compile_options(-Wno-format)
project(lvgl_demo_v9)

View File

@ -1,10 +1,23 @@
# freeside minimap
This branch targets esp32c6 waveshare watch board: https://www.waveshare.com/esp32-c6-touch-amoled-2.06.htm?sku=32769
```
wget https://github.com/espressif/idf-im-ui/releases/download/v0.7.1/eim-cli-linux-x64.zip
unzip eim-cli-linux-x64.zip
./eim install
source "/home/$USER/.espressif/tools/activate_idf_v5.5.2.sh"
idf.py set-target esp32c6
idf.py build
idf.py flash
```
# todo
- part selection
- esp32-s3?
- c6 does 802.11ax, probably better
- c6 is riscv so it's "cool"
- does micropython run on c6, yes
- screen
- 128x128 color oled?
- input device

View File

@ -1,6 +0,0 @@
import update
update.main()
import minimap
minimap.main()

14
main/CMakeLists.txt Normal file
View File

@ -0,0 +1,14 @@
set(LV_DEMO_DIR ../managed_components/lvgl__lvgl/demos)
file(GLOB_RECURSE LV_DEMOS_SOURCES ${LV_DEMO_DIR}/*.c)
idf_component_register(
SRCS main.c ${LV_DEMOS_SOURCES}
INCLUDE_DIRS . ${LV_DEMO_DIR})
idf_component_get_property(LVGL_LIB lvgl__lvgl COMPONENT_LIB)
target_compile_options(
${LVGL_LIB}
PRIVATE
-DLV_LVGL_H_INCLUDE_SIMPLE
-DLV_USE_DEMO_MUSIC
)

5
main/component.mk Normal file
View File

@ -0,0 +1,5 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

7
main/idf_component.yml Normal file
View File

@ -0,0 +1,7 @@
## IDF Component Manager Manifest File
dependencies:
waveshare/esp32_c6_touch_amoled_2_06:
version: "*"
lvgl/lvgl:
version: "9.2.0"
public: true

333
main/main.c Normal file
View File

@ -0,0 +1,333 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#include "nvs_flash.h"
#include "nvs.h"
#include "esp_check.h"
#include "esp_memory_utils.h"
#include "lvgl.h"
#include "bsp/esp-bsp.h"
#include "bsp/display.h"
#include "secrets.h"
#include "esp_crt_bundle.h"
#include "esp_tls.h"
#include "esp_http_client.h"
#define MAX_HTTP_RECV_BUFFER 512
#define MAX_HTTP_OUTPUT_BUFFER 2048
/* FreeRTOS event group to signal when we are connected*/
static EventGroupHandle_t s_wifi_event_group;
/* The event group allows multiple bits for each event, but we only care about two events:
* - we are connected to the AP with an IP
* - we failed to connect after the maximum amount of retries */
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1
static EventGroupHandle_t s_wifi_event_group;
static const char *TAG = "main";
static int s_retry_num = 0;
void textarea_log(char * s);
static void event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
esp_wifi_connect();
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
if (s_retry_num < 10000) {
esp_wifi_connect();
s_retry_num++;
ESP_LOGI(TAG, "retry to connect to the AP");
} else {
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
}
ESP_LOGI(TAG,"connect to the AP fail");
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
char ipaddr_string[20];
snprintf(ipaddr_string, sizeof(ipaddr_string), "ip:"IPSTR"\n", IP2STR(&event->ip_info.ip));
textarea_log(ipaddr_string);
s_retry_num = 0;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
}
}
void wifi_init_sta(void)
{
s_wifi_event_group = xEventGroupCreate();
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_event_handler_instance_t instance_any_id;
esp_event_handler_instance_t instance_got_ip;
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
ESP_EVENT_ANY_ID,
&event_handler,
NULL,
&instance_any_id));
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
IP_EVENT_STA_GOT_IP,
&event_handler,
NULL,
&instance_got_ip));
wifi_config_t wifi_config = {
.sta = {
.ssid = WIFI_SSID,
.password = WIFI_PASS,
/* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (password len => 8).
* If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value
* to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to
* WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards.
*/
.threshold.authmode = WIFI_AUTH_OPEN,
//.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
//.sae_h2e_identifier = CONFIG_ESP_WIFI_PW_ID,
// .disable_wpa3_compatible_mode = 0,
},
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
ESP_ERROR_CHECK(esp_wifi_start() );
ESP_LOGI(TAG, "wifi_init_sta finished.");
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
/* EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, */
/* WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, */
/* pdFALSE, */
/* pdFALSE, */
/* portMAX_DELAY); */
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
* happened. */
/* if (bits & WIFI_CONNECTED_BIT) { */
/* ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", */
/* WIFI_SSID, WIFI_PASS); */
/* } else if (bits & WIFI_FAIL_BIT) { */
/* ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", */
/* WIFI_SSID, WIFI_PASS); */
/* } else { */
/* ESP_LOGE(TAG, "UNEXPECTED EVENT"); */
/* } */
}
static char *output_buffer; // Buffer to store response of http request from event handler
static int output_len; // Stores number of bytes read
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
{
const char *TAG = "_http_event_hander";
esp_log_level_set(TAG, ESP_LOG_DEBUG);
switch(evt->event_id) {
case HTTP_EVENT_ERROR:
ESP_LOGD(TAG, "HTTP_EVENT_ERROR");
break;
case HTTP_EVENT_ON_CONNECTED:
ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
break;
case HTTP_EVENT_HEADER_SENT:
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
break;
case HTTP_EVENT_ON_HEADER:
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
break;
case HTTP_EVENT_ON_DATA:
ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
// Clean the buffer in case of a new request
if (output_len == 0 && evt->user_data) {
// we are just starting to copy the output data into the use
memset(evt->user_data, 0, MAX_HTTP_OUTPUT_BUFFER);
}
/*
* Check for chunked encoding is added as the URL for chunked encoding used in this example returns binary data.
* However, event handler can also be used in case chunked encoding is used.
*/
if (!esp_http_client_is_chunked_response(evt->client)) {
// If user_data buffer is configured, copy the response into the buffer
int copy_len = 0;
if (evt->user_data) {
// The last byte in evt->user_data is kept for the NULL character in case of out-of-bound access.
copy_len = MIN(evt->data_len, (MAX_HTTP_OUTPUT_BUFFER - output_len));
if (copy_len) {
memcpy(evt->user_data + output_len, evt->data, copy_len);
}
} else {
int content_len = esp_http_client_get_content_length(evt->client);
if (output_buffer == NULL) {
// We initialize output_buffer with 0 because it is used by strlen() and similar functions therefore should be null terminated.
ESP_LOGI(TAG, "calloc()");
output_buffer = (char *) calloc(content_len + 1, sizeof(char));
output_len = 0;
if (output_buffer == NULL) {
ESP_LOGE(TAG, "Failed to allocate memory for output buffer");
return ESP_FAIL;
}
}
copy_len = MIN(evt->data_len, (content_len - output_len));
if (copy_len) {
memcpy(output_buffer + output_len, evt->data, copy_len);
}
}
output_len += copy_len;
}
break;
case HTTP_EVENT_ON_FINISH:
ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH");
if (output_buffer != NULL) {
free(output_buffer);
output_buffer = NULL;
}
output_len = 0;
break;
case HTTP_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "HTTP_EVENT_DISCONNECTED");
int mbedtls_err = 0;
esp_err_t err = esp_tls_get_and_clear_last_error((esp_tls_error_handle_t)evt->data, &mbedtls_err, NULL);
if (err != 0) {
ESP_LOGI(TAG, "Last esp error code: 0x%x", err);
ESP_LOGI(TAG, "Last mbedtls failure: 0x%x", mbedtls_err);
}
if (output_buffer != NULL) {
ESP_LOGI(TAG, "output_buffer free()");
free(output_buffer);
output_buffer = NULL;
}
output_len = 0;
break;
case HTTP_EVENT_REDIRECT:
ESP_LOGD(TAG, "HTTP_EVENT_REDIRECT");
esp_http_client_set_header(evt->client, "From", "user@example.com");
esp_http_client_set_header(evt->client, "Accept", "text/html");
esp_http_client_set_redirection(evt->client);
break;
}
return ESP_OK;
}
static void http_test_task(void *pvParameters) {
esp_log_level_set("esp-tls-mbedtls", ESP_LOG_DEBUG);
// wait for wifi to be connected
while (!(WIFI_CONNECTED_BIT & xEventGroupWaitBits(s_wifi_event_group,
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
pdFALSE,
pdFALSE,
portMAX_DELAY)));
char local_response_buffer[MAX_HTTP_OUTPUT_BUFFER + 1] = {0};
esp_http_client_config_t config = {
.url = "https://snieck.us",
.event_handler = _http_event_handler,
.user_data = local_response_buffer, // Pass address of local buffer to get response
/* .crt_bundle_attach = esp_crt_bundle_attach, */
};
ESP_LOGI(TAG, "HTTPS request with url => %s", config.url);
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
ESP_LOGI(TAG, "HTTPS Status = %d, content_length = %"PRId64,
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
esp_http_client_cleanup(client);
} else {
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
}
vTaskDelete(NULL);
}
static const lv_font_t * font_large;
static lv_style_t style_bw;
static lv_obj_t * text;
void textarea_log(char * s) {
bsp_display_lock(100);
lv_textarea_add_text(text, s);
bsp_display_unlock();
}
void app_main(void)
{
//Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
// initialize wifi station connection
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
wifi_init_sta();
// initialize http client
ESP_ERROR_CHECK(esp_netif_init());
xTaskCreate(&http_test_task, "http_test_task", 8192, NULL, 5, NULL);
// initalize graphics
bsp_display_start();
bsp_display_lock(100);
bsp_display_brightness_set(20);
font_large = &lv_font_montserrat_18;
lv_style_init(&style_bw);
//lv_style_set_text_font(&style_bw, font_large);
lv_style_set_bg_color(&style_bw, lv_color_hex(0x000000));
lv_style_set_text_color(&style_bw, lv_color_hex(0xffffff));
lv_style_set_radius(&style_bw, 0);
lv_obj_add_style(lv_screen_active(), &style_bw, LV_PART_MAIN);
/*
lv_obj_t * cont = lv_obj_create(lv_screen_active());
lv_obj_add_style(cont, &style_bw, LV_PART_MAIN);
lv_obj_set_style_border_width(cont, 0, LV_PART_MAIN);
lv_obj_set_size(cont, lv_pct(100), lv_pct(100));
lv_obj_center(cont);
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
*/
lv_obj_t * title = lv_label_create(lv_screen_active());
lv_obj_add_style(title, &style_bw, LV_PART_MAIN);
lv_label_set_text(title, "freeside minimap");
lv_obj_set_align(title, LV_ALIGN_TOP_MID);
text = lv_textarea_create(lv_screen_active());
lv_obj_add_style(text, &style_bw, LV_PART_MAIN);
lv_obj_set_pos(text, 50, 25);
lv_textarea_add_text(text, "hello");
lv_textarea_add_text(text, " world!\n");
bsp_display_unlock();
while (true) {
vTaskDelay(configTICK_RATE_HZ); // 50us
ESP_LOGI(TAG, " all done ");
}
}

6
partitions.csv Normal file
View File

@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, , 8M,
storage, data, spiffs, , 7M,
1 # Name, Type, SubType, Offset, Size, Flags
2 # Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
3 nvs, data, nvs, 0x9000, 0x6000,
4 phy_init, data, phy, 0xf000, 0x1000,
5 factory, app, factory, , 8M,
6 storage, data, spiffs, , 7M,

47
sdkconfig.defaults Normal file
View File

@ -0,0 +1,47 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_COMPILER_OPTIMIZATION_PERF=y
CONFIG_SPIRAM=y
CONFIG_SPIRAM_MODE_OCT=y
CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y
CONFIG_SPIRAM_RODATA=y
CONFIG_SPIRAM_SPEED_80M=y
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_BSP_I2C_NUM=0
CONFIG_FREERTOS_HZ=1000
CONFIG_LV_USE_CLIB_MALLOC=y
CONFIG_LV_USE_CLIB_STRING=y
CONFIG_LV_USE_CLIB_SPRINTF=y
CONFIG_LV_DEF_REFR_PERIOD=15
CONFIG_LV_OS_FREERTOS=y
CONFIG_LV_DRAW_SW_DRAW_UNIT_CNT=2
CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM=y
CONFIG_LV_FONT_MONTSERRAT_12=y
CONFIG_LV_FONT_MONTSERRAT_16=y
CONFIG_LV_FONT_MONTSERRAT_18=y
CONFIG_LV_FONT_MONTSERRAT_20=y
CONFIG_LV_FONT_MONTSERRAT_22=y
CONFIG_LV_FONT_MONTSERRAT_24=y
CONFIG_LV_FONT_MONTSERRAT_26=y
CONFIG_LV_USE_FONT_COMPRESSED=y
CONFIG_LV_TXT_BREAK_CHARS=" ,.;:-_"
CONFIG_LV_USE_SYSMON=y
CONFIG_LV_USE_PERF_MONITOR=y
CONFIG_LV_USE_IMGFONT=y
CONFIG_LV_USE_DEMO_WIDGETS=y
CONFIG_LV_USE_DEMO_BENCHMARK=y
CONFIG_LV_USE_DEMO_RENDER=y
CONFIG_LV_USE_DEMO_SCROLL=y
CONFIG_LV_USE_DEMO_STRESS=y
CONFIG_LV_USE_DEMO_TRANSFORM=y
CONFIG_LV_USE_DEMO_MUSIC=y
CONFIG_LV_DEMO_MUSIC_AUTO_PLAY=y
CONFIG_LV_USE_DEMO_FLEX_LAYOUT=y
CONFIG_LV_USE_DEMO_MULTILANG=y
CONFIG_IDF_EXPERIMENTAL_FEATURES=y

View File

@ -1,26 +0,0 @@
import io
import storage
import wifi
import adafruit_connection_manager
import adafruit_requests
update_url = "https://gitea.departmentofinter.net/cqc/freeside-minimap/raw/branch/memes/minimap.py"
update_file = 'minimap.py'
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
requests = adafruit_requests.Session(pool, ssl_context)
def run_update():
with io.open(update_file, mode='w') as f:
with requests.get(update_url) as r:
print('\nupdating',update_file)
f.write(r.text)
def main():
try:
run_update()
except Exception as e:
import traceback
traceback.print_exception(e)