runnable on WT32-SC01-PLUS
This commit is contained in:
10
firmware/main/CMakeLists.txt
Normal file
10
firmware/main/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
idf_component_register(SRCS
|
||||
"lgfx.cpp"
|
||||
"main.cpp"
|
||||
PRIV_REQUIRES
|
||||
fatfs
|
||||
esp_wifi
|
||||
wpa_supplicant
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
fatfs_create_spiflash_image(storage ../storage FLASH_IN_PROJECT PRESERVE_TIME)
|
26
firmware/main/idf_component.yml
Normal file
26
firmware/main/idf_component.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
## 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
|
||||
espressif/esp_lvgl_port: ^2.0.0
|
||||
lvgl/lvgl:
|
||||
version: ^9.0.0
|
||||
public: true
|
||||
lovyan03/LovyanGFX:
|
||||
git: https://github.com/lovyan03/LovyanGFX.git
|
||||
version: 1.2.0
|
||||
#espressif/esp_mmap_assets: ^1.3.0
|
||||
#espressif/esp_lv_fs: ^1.0.0
|
||||
#joltwallet/littlefs: ^1.18.1
|
17
firmware/main/image.h
Normal file
17
firmware/main/image.h
Normal file
File diff suppressed because one or more lines are too long
89
firmware/main/lgfx.cpp
Normal file
89
firmware/main/lgfx.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "lgfx.h"
|
||||
|
||||
LGFX::LGFX(void)
|
||||
{
|
||||
{ // バス制御の設定を行います。
|
||||
auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。
|
||||
// 8ビットパラレルバスの設定
|
||||
// cfg.i2s_port = I2S_NUM_0; // 使用するI2Sポートを選択 (I2S_NUM_0 or I2S_NUM_1) (ESP32のI2S LCDモードを使用します)
|
||||
cfg.freq_write = 20000000; // 送信クロック (最大20MHz, 80MHzを整数で割った値に丸められます)
|
||||
cfg.pin_wr = 47; // WR を接続しているピン番号
|
||||
cfg.pin_rd = -1; // RD を接続しているピン番号
|
||||
cfg.pin_rs = 0; // RS(D/C)を接続しているピン番号
|
||||
cfg.pin_d0 = 9; // D0を接続しているピン番号
|
||||
cfg.pin_d1 = 46; // D1を接続しているピン番号
|
||||
cfg.pin_d2 = 3; // D2を接続しているピン番号
|
||||
cfg.pin_d3 = 8; // D3を接続しているピン番号
|
||||
cfg.pin_d4 = 18; // D4を接続しているピン番号
|
||||
cfg.pin_d5 = 17; // D5を接続しているピン番号
|
||||
cfg.pin_d6 = 16; // D6を接続しているピン番号
|
||||
cfg.pin_d7 = 15; // D7を接続しているピン番号
|
||||
_bus_instance.config(cfg); // 設定値をバスに反映します。
|
||||
_panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。
|
||||
}
|
||||
|
||||
{ // 表示パネル制御の設定を行います。
|
||||
auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。
|
||||
|
||||
cfg.pin_cs = -1; // CSが接続されているピン番号 (-1 = disable)
|
||||
cfg.pin_rst = 4; // RSTが接続されているピン番号 (-1 = disable)
|
||||
cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable)
|
||||
|
||||
// ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。
|
||||
|
||||
cfg.panel_width = 320; // 実際に表示可能な幅
|
||||
cfg.panel_height = 480; // 実際に表示可能な高さ
|
||||
cfg.offset_x = 0; // パネルのX方向オフセット量
|
||||
cfg.offset_y = 0; // パネルのY方向オフセット量
|
||||
cfg.offset_rotation = 0; // 回転方向の値のオフセット 0~7 (4~7は上下反転)
|
||||
cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数
|
||||
cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数
|
||||
cfg.readable = true; // データ読出しが可能な場合 trueに設定
|
||||
cfg.invert = true; // パネルの明暗が反転してしまう場合 trueに設定
|
||||
cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定
|
||||
cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定
|
||||
cfg.bus_shared = true; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います)
|
||||
|
||||
// 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。
|
||||
// cfg.memory_width = 240; // ドライバICがサポートしている最大の幅
|
||||
// cfg.memory_height = 320; // ドライバICがサポートしている最大の高さ
|
||||
|
||||
_panel_instance.config(cfg);
|
||||
}
|
||||
|
||||
//*
|
||||
{ // バックライト制御の設定を行います。(必要なければ削除)
|
||||
auto cfg = _light_instance.config(); // バックライト設定用の構造体を取得します。
|
||||
|
||||
cfg.pin_bl = 45; // バックライトが接続されているピン番号
|
||||
cfg.invert = false; // バックライトの輝度を反転させる場合 true
|
||||
cfg.freq = 44100; // バックライトのPWM周波数
|
||||
cfg.pwm_channel = 7; // 使用するPWMのチャンネル番号
|
||||
|
||||
_light_instance.config(cfg);
|
||||
_panel_instance.setLight(&_light_instance); // バックライトをパネルにセットします。
|
||||
}
|
||||
|
||||
{ // タッチスクリーン制御の設定を行います。(必要なければ削除)
|
||||
auto cfg = _touch_instance.config();
|
||||
|
||||
cfg.x_min = 0; // タッチスクリーンから得られる最小のX値(生の値)
|
||||
cfg.x_max = 319; // タッチスクリーンから得られる最大のX値(生の値)
|
||||
cfg.y_min = 0; // タッチスクリーンから得られる最小のY値(生の値)
|
||||
cfg.y_max = 479; // タッチスクリーンから得られる最大のY値(生の値)
|
||||
cfg.pin_int = 7; // INTが接続されているピン番号
|
||||
cfg.bus_shared = true; // 画面と共通のバスを使用している場合 trueを設定
|
||||
cfg.offset_rotation = 0; // 表示とタッチの向きのが一致しない場合の調整 0~7の値で設定
|
||||
// I2C接続の場合
|
||||
cfg.i2c_port = 1; // 使用するI2Cを選択 (0 or 1)
|
||||
cfg.i2c_addr = 0x38; // I2Cデバイスアドレス番号
|
||||
cfg.pin_sda = 6; // SDAが接続されているピン番号
|
||||
cfg.pin_scl = 5; // SCLが接続されているピン番号
|
||||
cfg.freq = 400000; // I2Cクロックを設定
|
||||
|
||||
_touch_instance.config(cfg);
|
||||
_panel_instance.setTouch(&_touch_instance); // タッチスクリーンをパネルにセットします。
|
||||
}
|
||||
//*/
|
||||
setPanel(&_panel_instance); // 使用するパネルをセットします。
|
||||
};
|
19
firmware/main/lgfx.h
Normal file
19
firmware/main/lgfx.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#define LGFX_USE_V1
|
||||
|
||||
#include <LovyanGFX.hpp>
|
||||
|
||||
class LGFX : public lgfx::LGFX_Device
|
||||
{
|
||||
private:
|
||||
lgfx::Panel_ST7796 _panel_instance;
|
||||
lgfx::Bus_Parallel8 _bus_instance; // 8ビットパラレルバスのインスタンス (ESP32のみ)
|
||||
lgfx::Light_PWM _light_instance;
|
||||
lgfx::Touch_FT5x06 _touch_instance; // FT5206, FT5306, FT5406, FT6206, FT6236, FT6336, FT6436
|
||||
|
||||
public:
|
||||
LGFX(void);
|
||||
};
|
189
firmware/main/main.cpp
Normal file
189
firmware/main/main.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#include <lgfx.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "esp_vfs.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "image.h"
|
||||
|
||||
#define screenWidth (480)
|
||||
#define screenHeight (320)
|
||||
|
||||
const unsigned int lvBufferSize = screenWidth * screenHeight / 10 * (LV_COLOR_DEPTH / 8);
|
||||
uint8_t lvBuffer1[lvBufferSize];
|
||||
uint8_t lvBuffer2[lvBufferSize];
|
||||
|
||||
static const char *TAG = "main";
|
||||
const char *base_path = "/storage";
|
||||
|
||||
LGFX tft;
|
||||
|
||||
void setup_tft(void)
|
||||
{
|
||||
tft.begin();
|
||||
tft.setRotation(1);
|
||||
tft.setBrightness(255);
|
||||
}
|
||||
|
||||
void flush(lv_display_t *display, const lv_area_t *area, unsigned char *data)
|
||||
{
|
||||
uint32_t w = lv_area_get_width(area);
|
||||
uint32_t h = lv_area_get_height(area);
|
||||
lv_draw_sw_rgb565_swap(data, w * h);
|
||||
tft.pushImageDMA(area->x1, area->y1, w, h, (uint16_t *)data);
|
||||
lv_display_flush_ready(display);
|
||||
}
|
||||
|
||||
void my_touch_read(lv_indev_t *indev_driver, lv_indev_data_t *data)
|
||||
{
|
||||
uint16_t touchX, touchY;
|
||||
bool touched = tft.getTouch(&touchX, &touchY);
|
||||
if (!touched)
|
||||
{
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
data->point.x = touchX;
|
||||
data->point.y = touchY;
|
||||
}
|
||||
}
|
||||
|
||||
void lv_handler()
|
||||
{
|
||||
static uint64_t previousUpdate = 0;
|
||||
static uint64_t interval = 0;
|
||||
|
||||
uint64_t eus = esp_timer_get_time();
|
||||
if (eus - previousUpdate > interval)
|
||||
{
|
||||
previousUpdate = eus;
|
||||
interval = lv_timer_handler(); // Update the UI
|
||||
lv_tick_inc(interval);
|
||||
vTaskDelay(pdMS_TO_TICKS(interval - 1));
|
||||
}
|
||||
}
|
||||
|
||||
void setup_fatfs()
|
||||
{
|
||||
const esp_vfs_fat_mount_config_t mount_config = {
|
||||
.format_if_mount_failed = false,
|
||||
.max_files = 4,
|
||||
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE,
|
||||
.disk_status_check_enable = false,
|
||||
.use_one_fat = false,
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "Mounting FAT filesystem in read/write mode");
|
||||
static wl_handle_t wl_handle = WL_INVALID_HANDLE;
|
||||
esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(base_path, "storage", &mount_config, &wl_handle);
|
||||
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *f;
|
||||
ESP_LOGI(TAG, "Reading file");
|
||||
|
||||
const char *host_filename1 = "/storage/response.png";
|
||||
|
||||
struct stat info;
|
||||
struct tm timeinfo;
|
||||
char buffer[32];
|
||||
|
||||
if (stat(host_filename1, &info) < 0)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to read file stats");
|
||||
return;
|
||||
}
|
||||
localtime_r(&info.st_mtime, &timeinfo);
|
||||
strftime(buffer, sizeof(buffer), "%Y-%m-%d", &timeinfo);
|
||||
|
||||
ESP_LOGI(TAG, "The file '%s' was modified at date: %s", host_filename1, buffer);
|
||||
|
||||
f = fopen(host_filename1, "rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
ESP_LOGI(TAG, "Unmounting FAT filesystem");
|
||||
ESP_ERROR_CHECK(esp_vfs_fat_spiflash_unmount_rw_wl(base_path, wl_handle));
|
||||
ESP_LOGI(TAG, "Done");
|
||||
}
|
||||
|
||||
void esp_lv_log_print(lv_log_level_t level, const char *buf)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case LV_LOG_LEVEL_TRACE:
|
||||
ESP_LOGV("LVGL", "%s", buf);
|
||||
break;
|
||||
case LV_LOG_LEVEL_INFO:
|
||||
ESP_LOGI("LVGL", "%s", buf);
|
||||
break;
|
||||
case LV_LOG_LEVEL_WARN:
|
||||
ESP_LOGW("LVGL", "%s", buf);
|
||||
break;
|
||||
case LV_LOG_LEVEL_ERROR:
|
||||
ESP_LOGE("LVGL", "%s", buf);
|
||||
break;
|
||||
case LV_LOG_LEVEL_USER:
|
||||
ESP_LOGI("LVGL", "%s", buf);
|
||||
break;
|
||||
case LV_LOG_LEVEL_NONE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
setup_fatfs();
|
||||
|
||||
setup_tft();
|
||||
|
||||
lv_init();
|
||||
|
||||
lv_log_register_print_cb(esp_lv_log_print);
|
||||
|
||||
static auto *display = lv_display_create(screenWidth, screenHeight);
|
||||
lv_display_set_color_format(display, LV_COLOR_FORMAT_RGB565);
|
||||
lv_display_set_flush_cb(display, flush);
|
||||
lv_display_set_buffers(display, lvBuffer1, lvBuffer2, lvBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
|
||||
|
||||
static auto *lvInput = lv_indev_create();
|
||||
lv_indev_set_type(lvInput, LV_INDEV_TYPE_POINTER);
|
||||
lv_indev_set_read_cb(lvInput, my_touch_read);
|
||||
|
||||
ESP_LOGI(TAG, "create image");
|
||||
static auto *image = lv_image_create(lv_scr_act());
|
||||
lv_image_set_src(image, &image_data);
|
||||
lv_obj_align(image, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
ESP_LOGI(TAG, "image created");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
lv_handler();
|
||||
}
|
||||
|
||||
void lvgl_task(void *pvParameter)
|
||||
{
|
||||
setup();
|
||||
while (1)
|
||||
{
|
||||
loop();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
xTaskCreatePinnedToCore(lvgl_task, "lvgl_task", 4096, NULL, 5, NULL, 1);
|
||||
}
|
121
firmware/main/wps.c
Normal file
121
firmware/main/wps.c
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "WPS_EXAMPLE";
|
||||
|
||||
// Funktion, um WPS zu starten (z.B. durch Button-Interrupt aufgerufen)
|
||||
void start_wps_process()
|
||||
{
|
||||
ESP_LOGI(TAG, "Starting WPS...");
|
||||
// esp_wifi_wps_config_t wps_config = WPS_CONFIG_INIT_DEFAULT(WPS_TYPE_PBC);
|
||||
// ESP_ERROR_CHECK(esp_wifi_wps_enable(&wps_config));
|
||||
// ESP_ERROR_CHECK(esp_wifi_wps_start(0)); // Start WPS indefinitely (handle timeout via event)
|
||||
}
|
||||
|
||||
static void wifi_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT)
|
||||
{
|
||||
switch (event_id)
|
||||
{
|
||||
case WIFI_EVENT_STA_START:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_START: Wi-Fi station started.");
|
||||
// Option 1: Start WPS direkt hier
|
||||
// start_wps_process();
|
||||
// Option 2: Warten auf externen Trigger (z.B. Button), siehe start_wps_process()
|
||||
// Optional: Versuchen, sich normal zu verbinden, falls Zugangsdaten gespeichert sind
|
||||
// esp_wifi_connect();
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_CONNECTED:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_CONNECTED");
|
||||
// Falls verbunden (z.B. aus Flash), WPS deaktivieren, falls es noch lief
|
||||
// esp_wifi_wps_disable();
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_DISCONNECTED");
|
||||
// Eventuell normalen Verbindungsversuch starten oder auf WPS-Trigger warten
|
||||
// esp_wifi_connect(); // Oder: Warte auf Button für WPS
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_WPS_ER_SUCCESS:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_SUCCESS");
|
||||
// WPS erfolgreich, Zugangsdaten wurden empfangen.
|
||||
// Der Wi-Fi Stack versucht nun automatisch, sich zu verbinden.
|
||||
// WPS deaktivieren.
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
// Optional: Zugangsdaten auslesen und speichern, falls nötig (normalerweise nicht erforderlich, da der Stack sie intern nutzt)
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_WPS_ER_FAILED:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_FAILED");
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
// Hier Fehlerbehandlung: Info an User, evtl. erneuten Start ermöglichen
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_WPS_ER_TIMEOUT:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_TIMEOUT");
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
// Hier Fehlerbehandlung: Info an User, evtl. erneuten Start ermöglichen
|
||||
break;
|
||||
|
||||
case WIFI_EVENT_STA_WPS_ER_PIN:
|
||||
ESP_LOGI(TAG, "WIFI_EVENT_STA_WPS_ER_PIN");
|
||||
// Relevant für PIN-Modus
|
||||
// wifi_event_sta_wps_er_pin_t* event = (wifi_event_sta_wps_er_pin_t*) event_data;
|
||||
// ESP_LOGI(TAG, "WPS PIN: %.*s", event->pin_code_len, event->pin_code); // Beispiel: ESP32 generiert PIN
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 address: " IPSTR, IP2STR(&event->ip_info.ip));
|
||||
// Verbindung erfolgreich hergestellt
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_init_sta_wps(void)
|
||||
{
|
||||
// 1. NVS initialisieren
|
||||
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);
|
||||
|
||||
// 2. TCP/IP Stack initialisieren
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
// 3. Event Loop erstellen
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
// 4. Default Wi-Fi Station Netif erstellen
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
// 5. Wi-Fi Treiber initialisieren
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
// 6. Event Handler registrieren
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &wifi_event_handler, NULL));
|
||||
|
||||
// 7. Wi-Fi Modus auf Station setzen
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
|
||||
// 8. Wi-Fi starten (löst WIFI_EVENT_STA_START aus)
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAG, "Wi-Fi Initialisierung abgeschlossen.");
|
||||
ESP_LOGI(TAG, "Bereit für WPS Trigger (z.B. Button-Druck oder automatischen Start in STA_START).");
|
||||
}
|
Reference in New Issue
Block a user