Add CYD web radio: WiFi provision + HTTP MP3 to DAC26.
Supports 2.8/3.5 boards with on-screen station list; ships flashable firmware packages. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1127
include/lv_conf.h
Normal file
1127
include/lv_conf.h
Normal file
File diff suppressed because it is too large
Load Diff
45
include/pins.h
Normal file
45
include/pins.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
// Board pins — 2.8" default; 3.5" when CYD_BOARD_3248S035 is set (env:cyd_35r)
|
||||
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
#define TFT_BL_PIN 27
|
||||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#define UI_HOR_RES 480
|
||||
#define UI_VER_RES 320
|
||||
/* 3.5C capacitive GT911 (ESP32-3248S035C). GPIO33 is I2C SDA, not TOUCH_CS.
|
||||
* Backlight is GPIO27; INT is GPIO21 — they are NOT the same pin. */
|
||||
#define CYD_GT911_SDA 33
|
||||
#define CYD_GT911_SCL 32
|
||||
#define CYD_GT911_INT 21
|
||||
#define CYD_GT911_RST 25
|
||||
#else
|
||||
#define TFT_BL_PIN 21
|
||||
#define SCREEN_WIDTH 240
|
||||
#define SCREEN_HEIGHT 320
|
||||
#define UI_HOR_RES 320
|
||||
#define UI_VER_RES 240
|
||||
/* 2.8" CYD: dedicated SoftSPI touch bus. */
|
||||
#define CYD_TOUCH_IRQ 36
|
||||
#define CYD_TOUCH_MOSI 32
|
||||
#define CYD_TOUCH_MISO 39
|
||||
#define CYD_TOUCH_CLK 25
|
||||
#define CYD_TOUCH_CS 33
|
||||
#endif
|
||||
|
||||
/* Map 320x240 design coordinates onto the active UI resolution (identity on 2.8"). */
|
||||
#define UX(x) ((int)(((long)(x) * (UI_HOR_RES)) / 320))
|
||||
#define UY(y) ((int)(((long)(y) * (UI_VER_RES)) / 240))
|
||||
#define UW(w) UX(w)
|
||||
#define UH(h) UY(h)
|
||||
|
||||
/* Partial frame buffer: 3.5 needs smaller ratio to fit DRAM. */
|
||||
#if defined(CYD_BOARD_3248S035)
|
||||
#define DRAW_BUF_DIV 20
|
||||
#else
|
||||
#define DRAW_BUF_DIV 10
|
||||
#endif
|
||||
|
||||
/* On-board amp on P4 — DAC2 only. Never use GPIO25 (2.8 touch CLK / 3.5 GT911 RST). */
|
||||
#define SPEAKER_PIN 26
|
||||
29
include/radio_player.h
Normal file
29
include/radio_player.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct RadioStation {
|
||||
const char *name;
|
||||
const char *url;
|
||||
};
|
||||
|
||||
uint8_t radio_station_count();
|
||||
const RadioStation *radio_station(uint8_t idx);
|
||||
|
||||
void radio_player_begin();
|
||||
void radio_player_loop();
|
||||
|
||||
bool radio_player_play(uint8_t station_idx);
|
||||
void radio_player_stop();
|
||||
bool radio_player_is_playing();
|
||||
bool radio_player_is_starting();
|
||||
|
||||
uint8_t radio_player_station();
|
||||
void radio_player_next();
|
||||
void radio_player_prev();
|
||||
|
||||
void radio_player_set_volume(uint8_t percent);
|
||||
uint8_t radio_player_volume();
|
||||
|
||||
const char *radio_player_status();
|
||||
10
include/radio_ui.h
Normal file
10
include/radio_ui.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
void radio_ui_create();
|
||||
void radio_ui_show();
|
||||
void radio_ui_tick();
|
||||
bool radio_ui_is_active();
|
||||
|
||||
/** Wired from WiFi setup: reopen provisioning screens. */
|
||||
using RadioUiWifiCb = void (*)();
|
||||
void radio_ui_set_wifi_cb(RadioUiWifiCb cb);
|
||||
7
include/touch.h
Normal file
7
include/touch.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void touch_init();
|
||||
void touch_read_cb(lv_indev_t *indev, lv_indev_data_t *data);
|
||||
92
include/wifi_prov.h
Normal file
92
include/wifi_prov.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 通用 WiFi 配网核心(无 LVGL 依赖)
|
||||
*
|
||||
* 流程:
|
||||
* 1. wifi_prov_begin() 读 NVS,有凭证则尝试 STA 连接
|
||||
* 2. 失败 / 无凭证 → 业务层开屏上 UI 或 SoftAP 门户
|
||||
* 3. wifi_prov_save() + wifi_prov_connect_to() 完成配网
|
||||
* 4. loop 里调用 wifi_prov_loop() 做断线重连与门户处理
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#ifndef WIFI_PROV_AP_SSID
|
||||
#define WIFI_PROV_AP_SSID "CYD-Setup"
|
||||
#endif
|
||||
|
||||
#ifndef WIFI_PROV_CONNECT_TIMEOUT_MS
|
||||
#define WIFI_PROV_CONNECT_TIMEOUT_MS 30000u
|
||||
#endif
|
||||
|
||||
/* Ignore transient WL_NO_SSID_AVAIL / CONNECT_FAILED right after WiFi.begin(). */
|
||||
#ifndef WIFI_PROV_FAIL_GRACE_MS
|
||||
#define WIFI_PROV_FAIL_GRACE_MS 8000u
|
||||
#endif
|
||||
|
||||
#ifndef WIFI_PROV_RECONNECT_MS
|
||||
#define WIFI_PROV_RECONNECT_MS 8000u
|
||||
#endif
|
||||
|
||||
static constexpr int WIFI_PROV_MAX_SCAN = 16;
|
||||
static constexpr size_t WIFI_PROV_SSID_MAX = 32;
|
||||
static constexpr size_t WIFI_PROV_PASS_MAX = 64;
|
||||
|
||||
struct WifiScanItem {
|
||||
char ssid[WIFI_PROV_SSID_MAX + 1];
|
||||
int32_t rssi;
|
||||
wifi_auth_mode_t auth;
|
||||
};
|
||||
|
||||
enum WifiProvState : uint8_t {
|
||||
WIFI_PROV_IDLE = 0,
|
||||
WIFI_PROV_CONNECTING,
|
||||
WIFI_PROV_CONNECTED,
|
||||
WIFI_PROV_FAILED,
|
||||
WIFI_PROV_PORTAL,
|
||||
};
|
||||
|
||||
using WifiProvStateCb = void (*)(WifiProvState state, void *user);
|
||||
|
||||
void wifi_prov_set_state_cb(WifiProvStateCb cb, void *user = nullptr);
|
||||
|
||||
/** 初始化 Preferences + WiFi STA;有凭证则异步开始连接。返回是否已有凭证。 */
|
||||
bool wifi_prov_begin();
|
||||
|
||||
bool wifi_prov_has_credentials();
|
||||
bool wifi_prov_is_connected();
|
||||
WifiProvState wifi_prov_state();
|
||||
|
||||
String wifi_prov_ssid();
|
||||
String wifi_prov_ip();
|
||||
int8_t wifi_prov_rssi();
|
||||
|
||||
void wifi_prov_save(const char *ssid, const char *password);
|
||||
void wifi_prov_clear();
|
||||
|
||||
/** 用已存凭证连接(异步,结果看 wifi_prov_loop / state) */
|
||||
void wifi_prov_connect_saved();
|
||||
|
||||
/** 连接指定网络并在成功后写入 NVS */
|
||||
void wifi_prov_connect_to(const char *ssid, const char *password);
|
||||
|
||||
/** 同步扫描(会阻塞数秒;门户 HTML 可用)。屏上 UI 请用异步接口。 */
|
||||
int wifi_prov_scan(WifiScanItem *out, int max_items);
|
||||
|
||||
/** 异步扫描:start 后每 loop 调 poll;完成时写入 out 并返回条数,进行中返回 -1。 */
|
||||
bool wifi_prov_scan_start();
|
||||
bool wifi_prov_scan_busy();
|
||||
int wifi_prov_scan_poll(WifiScanItem *out, int max_items);
|
||||
|
||||
/**
|
||||
* SoftAP + 简易 Captive Portal(手机连 CYD-Setup → http://192.168.4.1)
|
||||
* 与屏上配网可并行;配网成功后会自动 stop。
|
||||
*/
|
||||
void wifi_prov_portal_start(const char *ap_ssid = WIFI_PROV_AP_SSID);
|
||||
void wifi_prov_portal_stop();
|
||||
bool wifi_prov_portal_active();
|
||||
|
||||
/** 每 loop 调用:重连、门户 HTTP、状态回调 */
|
||||
void wifi_prov_loop();
|
||||
21
include/wifi_ui.h
Normal file
21
include/wifi_ui.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* LVGL 屏上配网 UI(依赖 wifi_prov)
|
||||
* 复用:拷贝 wifi_ui.* + 在业务里 wifi_ui_create() / wifi_ui_tick()
|
||||
*/
|
||||
|
||||
void wifi_ui_create();
|
||||
void wifi_ui_tick();
|
||||
|
||||
/** 强制进入配网页(改密 / 首次) */
|
||||
void wifi_ui_show_setup();
|
||||
|
||||
/** 显示已连接状态页 */
|
||||
void wifi_ui_show_status();
|
||||
|
||||
bool wifi_ui_is_setup();
|
||||
|
||||
/** 连上后回调;未设置则仍进状态页。业务层可切到电台等主界面。 */
|
||||
using WifiUiConnectedCb = void (*)();
|
||||
void wifi_ui_set_connected_cb(WifiUiConnectedCb cb);
|
||||
Reference in New Issue
Block a user