Skip to content

Commit 7a85430

Browse files
New Waveshare ESP32-S3-Touch-LCD-1.83 third-party board is available (#1323)
1 parent e8ed16b commit 7a85430

File tree

6 files changed

+334
-1
lines changed

6 files changed

+334
-1
lines changed

main/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_AMOLED_1_75)
238238
set(BUILTIN_TEXT_FONT font_puhui_basic_30_4)
239239
set(BUILTIN_ICON_FONT font_awesome_30_4)
240240
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
241+
elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_1_83)
242+
set(BOARD_TYPE "waveshare-s3-touch-lcd-1.83")
243+
set(BUILTIN_TEXT_FONT font_puhui_basic_16_4)
244+
set(BUILTIN_ICON_FONT font_awesome_16_4)
245+
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
241246
elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_1_85C)
242247
set(BOARD_TYPE "esp32-s3-touch-lcd-1.85c")
243248
set(BUILTIN_TEXT_FONT font_puhui_basic_16_4)

main/Kconfig.projbuild

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ choice BOARD_TYPE
249249
config BOARD_TYPE_ESP32S3_Touch_AMOLED_1_75
250250
bool "Waveshare ESP32-S3-Touch-AMOLED-1.75"
251251
depends on IDF_TARGET_ESP32S3
252+
config BOARD_TYPE_ESP32S3_Touch_LCD_1_83
253+
bool "Waveshare ESP32-S3-Touch-LCD-1.83"
254+
depends on IDF_TARGET_ESP32S3
252255
config BOARD_TYPE_ESP32S3_Touch_LCD_4B
253256
bool "Waveshare ESP32-S3-Touch-LCD-4B"
254257
depends on IDF_TARGET_ESP32S3
@@ -628,7 +631,7 @@ config USE_DEVICE_AEC
628631
bool "Enable Device-Side AEC"
629632
default n
630633
depends on USE_AUDIO_PROCESSOR && (BOARD_TYPE_ESP_BOX_3 || BOARD_TYPE_ESP_BOX || BOARD_TYPE_ESP_BOX_LITE \
631-
|| BOARD_TYPE_LICHUANG_DEV || BOARD_TYPE_ESP32S3_KORVO2_V3 || BOARD_TYPE_ESP32S3_Touch_AMOLED_1_75 \
634+
|| BOARD_TYPE_LICHUANG_DEV || BOARD_TYPE_ESP32S3_KORVO2_V3 || BOARD_TYPE_ESP32S3_Touch_AMOLED_1_75 || BOARD_TYPE_ESP32S3_Touch_LCD_1_83\
632635
|| BOARD_TYPE_ESP32S3_Touch_AMOLED_2_06 || BOARD_TYPE_ESP32S3_Touch_LCD_4B || BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_4B || BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_7B \
633636
|| BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_XC || BOARD_TYPE_ESP_S3_LCD_EV_Board_2 || BOARD_TYPE_YUNLIAO_S3 \
634637
|| BOARD_TYPE_ECHOEAR || BOARD_TYPE_ESP32S3_Touch_LCD_3_49)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Waveshare ESP32-S3-Touch-LCD-1.83
2+
3+
4+
[ESP32-S3-Touch-LCD-1.83](https://www.waveshare.com/esp32-s3-touch-lcd-1.83.htm) ESP32-S3-Touch-LCD-1.83 is a high-performance and highly integrated microcontroller development board designed by Waveshare. With a compact board size, it is equipped with a 1.83-inch capacitive LCD screen, a highly integrated power management chip, six-axis sensors (three-axis accelerometer and three-axis gyroscope), RTC and low-power audio codec chip, etc., making it convenient for development and easy to be embedded in products.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef _BOARD_CONFIG_H_
2+
#define _BOARD_CONFIG_H_
3+
4+
#include <driver/gpio.h>
5+
#include <driver/spi_master.h>
6+
7+
#define AUDIO_INPUT_SAMPLE_RATE 24000
8+
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
9+
10+
#define AUDIO_INPUT_REFERENCE true
11+
12+
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_16
13+
#define AUDIO_I2S_GPIO_WS GPIO_NUM_45
14+
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_9
15+
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_10
16+
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_8
17+
18+
#define AUDIO_CODEC_PA_PIN GPIO_NUM_46
19+
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_15
20+
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_14
21+
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
22+
#define AUDIO_CODEC_ES7210_ADDR ES7210_CODEC_DEFAULT_ADDR
23+
24+
#define BOOT_BUTTON_GPIO GPIO_NUM_0
25+
#define PWR_BUTTON_GPIO GPIO_NUM_41
26+
27+
#define DISPLAY_SPI_MODE 3
28+
#define DISPLAY_CS_PIN GPIO_NUM_5
29+
#define DISPLAY_MOSI_PIN GPIO_NUM_7
30+
#define DISPLAY_MISO_PIN GPIO_NUM_NC
31+
#define DISPLAY_CLK_PIN GPIO_NUM_6
32+
#define DISPLAY_DC_PIN GPIO_NUM_4
33+
#define DISPLAY_RST_PIN GPIO_NUM_38
34+
35+
#define DISPLAY_WIDTH 240
36+
#define DISPLAY_HEIGHT 284
37+
#define DISPLAY_MIRROR_X false
38+
#define DISPLAY_MIRROR_Y false
39+
#define DISPLAY_SWAP_XY false
40+
41+
#define DISPLAY_OFFSET_X 0
42+
#define DISPLAY_OFFSET_Y 0
43+
44+
#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_40
45+
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
46+
47+
#endif // _BOARD_CONFIG_H_
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"target": "esp32s3",
3+
"builds": [
4+
{
5+
"name": "waveshare-s3-touch-lcd-1.83",
6+
"sdkconfig_append": [
7+
"CONFIG_USE_WECHAT_MESSAGE_STYLE=n",
8+
"CONFIG_USE_DEVICE_AEC=y"
9+
]
10+
}
11+
]
12+
}
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
#include "wifi_board.h"
2+
#include "display/lcd_display.h"
3+
#include "codecs/box_audio_codec.h"
4+
#include "application.h"
5+
#include "button.h"
6+
#include "led/single_led.h"
7+
#include "mcp_server.h"
8+
#include "config.h"
9+
#include "power_save_timer.h"
10+
#include "axp2101.h"
11+
#include "i2c_device.h"
12+
#include <wifi_station.h>
13+
14+
#include <esp_log.h>
15+
#include <esp_lcd_panel_vendor.h>
16+
#include <driver/i2c_master.h>
17+
#include <driver/spi_master.h>
18+
#include "settings.h"
19+
20+
#include <esp_lcd_touch_cst816s.h>
21+
#include <esp_lvgl_port.h>
22+
#include <lvgl.h>
23+
24+
#define TAG "WaveshareEsp32s3TouchLCD1inch83"
25+
26+
class Pmic : public Axp2101 {
27+
public:
28+
Pmic(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : Axp2101(i2c_bus, addr) {
29+
WriteReg(0x22, 0b110); // PWRON > OFFLEVEL as POWEROFF Source enable
30+
WriteReg(0x27, 0x10); // hold 4s to power off
31+
32+
// Disable All DCs but DC1
33+
WriteReg(0x80, 0x01);
34+
// Disable All LDOs
35+
WriteReg(0x90, 0x00);
36+
WriteReg(0x91, 0x00);
37+
38+
// Set DC1 to 3.3V
39+
WriteReg(0x82, (3300 - 1500) / 100);
40+
41+
// Set ALDO1 to 3.3V
42+
WriteReg(0x92, (3300 - 500) / 100);
43+
44+
// Enable ALDO1(MIC)
45+
WriteReg(0x90, 0x01);
46+
47+
WriteReg(0x64, 0x02); // CV charger voltage setting to 4.1V
48+
49+
WriteReg(0x61, 0x02); // set Main battery precharge current to 50mA
50+
WriteReg(0x62, 0x08); // set Main battery charger current to 400mA ( 0x08-200mA, 0x09-300mA, 0x0A-400mA )
51+
WriteReg(0x63, 0x01); // set Main battery term charge current to 25mA
52+
}
53+
};
54+
55+
class WaveshareEsp32s3TouchLCD1inch83 : public WifiBoard {
56+
private:
57+
i2c_master_bus_handle_t i2c_bus_;
58+
Pmic* pmic_ = nullptr;
59+
Button boot_button_;
60+
Display* display_;
61+
PowerSaveTimer* power_save_timer_;
62+
63+
void InitializePowerSaveTimer() {
64+
power_save_timer_ = new PowerSaveTimer(-1, 60, 300);
65+
power_save_timer_->OnEnterSleepMode([this]() {
66+
GetDisplay()->SetPowerSaveMode(true);
67+
GetBacklight()->SetBrightness(20); });
68+
power_save_timer_->OnExitSleepMode([this]() {
69+
GetDisplay()->SetPowerSaveMode(false);
70+
GetBacklight()->RestoreBrightness(); });
71+
power_save_timer_->OnShutdownRequest([this](){
72+
pmic_->PowerOff(); });
73+
power_save_timer_->SetEnabled(true);
74+
}
75+
76+
void InitializeCodecI2c() {
77+
// Initialize I2C peripheral
78+
i2c_master_bus_config_t i2c_bus_cfg = {
79+
.i2c_port = I2C_NUM_0,
80+
.sda_io_num = AUDIO_CODEC_I2C_SDA_PIN,
81+
.scl_io_num = AUDIO_CODEC_I2C_SCL_PIN,
82+
.clk_source = I2C_CLK_SRC_DEFAULT,
83+
.flags = {
84+
.enable_internal_pullup = 1,
85+
},
86+
};
87+
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
88+
}
89+
90+
void InitializeAxp2101() {
91+
ESP_LOGI(TAG, "Init AXP2101");
92+
pmic_ = new Pmic(i2c_bus_, 0x34);
93+
}
94+
95+
void InitializeSpi() {
96+
spi_bus_config_t buscfg = {};
97+
buscfg.mosi_io_num = DISPLAY_MOSI_PIN;
98+
buscfg.miso_io_num = GPIO_NUM_NC;
99+
buscfg.sclk_io_num = DISPLAY_CLK_PIN;
100+
buscfg.quadwp_io_num = GPIO_NUM_NC;
101+
buscfg.quadhd_io_num = GPIO_NUM_NC;
102+
buscfg.max_transfer_sz = DISPLAY_WIDTH* DISPLAY_HEIGHT* sizeof(uint16_t);
103+
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
104+
}
105+
106+
void InitializeButtons() {
107+
boot_button_.OnClick([this]() {
108+
auto& app = Application::GetInstance();
109+
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
110+
ResetWifiConfiguration();
111+
}
112+
app.ToggleChatState();
113+
});
114+
115+
#if CONFIG_USE_DEVICE_AEC
116+
boot_button_.OnDoubleClick([this]() {
117+
auto& app = Application::GetInstance();
118+
if (app.GetDeviceState() == kDeviceStateIdle) {
119+
app.SetAecMode(app.GetAecMode() == kAecOff ? kAecOnDeviceSide : kAecOff);
120+
}
121+
});
122+
#endif
123+
}
124+
125+
void InitializeDisplay() {
126+
esp_lcd_panel_io_handle_t panel_io = nullptr;
127+
esp_lcd_panel_handle_t panel = nullptr;
128+
129+
// 液晶屏控制IO初始化
130+
ESP_LOGD(TAG, "Install panel IO");
131+
esp_lcd_panel_io_spi_config_t io_config = {};
132+
io_config.cs_gpio_num = DISPLAY_CS_PIN;
133+
io_config.dc_gpio_num = DISPLAY_DC_PIN;
134+
io_config.spi_mode = 0;
135+
io_config.pclk_hz = 24 * 1000 * 1000;
136+
io_config.trans_queue_depth = 10;
137+
io_config.lcd_cmd_bits = 8;
138+
io_config.lcd_param_bits = 8;
139+
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io));
140+
141+
// 初始化液晶屏驱动芯片
142+
ESP_LOGD(TAG, "Install LCD driver");
143+
esp_lcd_panel_dev_config_t panel_config = {};
144+
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
145+
panel_config.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB;
146+
panel_config.bits_per_pixel = 16;
147+
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
148+
esp_lcd_panel_reset(panel);
149+
esp_lcd_panel_init(panel);
150+
esp_lcd_panel_invert_color(panel, true);
151+
// esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
152+
esp_lcd_panel_disp_on_off(panel, true);
153+
display_ = new SpiLcdDisplay(panel_io, panel,
154+
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
155+
}
156+
157+
void InitializeTouch() {
158+
esp_lcd_touch_handle_t tp;
159+
esp_lcd_touch_config_t tp_cfg = {
160+
.x_max = DISPLAY_WIDTH - 1,
161+
.y_max = DISPLAY_HEIGHT - 1,
162+
.rst_gpio_num = GPIO_NUM_39,
163+
.int_gpio_num = GPIO_NUM_13,
164+
.levels = {
165+
.reset = 0,
166+
.interrupt = 0,
167+
},
168+
.flags = {
169+
.swap_xy = 0,
170+
.mirror_x = 0,
171+
.mirror_y = 0,
172+
},
173+
};
174+
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
175+
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG();
176+
tp_io_config.scl_speed_hz = 400* 1000;
177+
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus_, &tp_io_config, &tp_io_handle));
178+
ESP_LOGI(TAG, "Initialize touch controller");
179+
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_cst816s(tp_io_handle, &tp_cfg, &tp));
180+
const lvgl_port_touch_cfg_t touch_cfg = {
181+
.disp = lv_display_get_default(),
182+
.handle = tp,
183+
};
184+
lvgl_port_add_touch(&touch_cfg);
185+
ESP_LOGI(TAG, "Touch panel initialized successfully");
186+
}
187+
188+
// 初始化工具
189+
void InitializeTools() {
190+
auto &mcp_server = McpServer::GetInstance();
191+
mcp_server.AddTool("self.system.reconfigure_wifi",
192+
"Reboot the device and enter WiFi configuration mode.\n"
193+
"**CAUTION** You must ask the user to confirm this action.",
194+
PropertyList(), [this](const PropertyList& properties) {
195+
ResetWifiConfiguration();
196+
return true;
197+
});
198+
}
199+
200+
public:
201+
WaveshareEsp32s3TouchLCD1inch83() : boot_button_(BOOT_BUTTON_GPIO) {
202+
InitializePowerSaveTimer();
203+
InitializeCodecI2c();
204+
InitializeAxp2101();
205+
InitializeSpi();
206+
InitializeDisplay();
207+
InitializeTouch();
208+
InitializeButtons();
209+
InitializeTools();
210+
GetBacklight()->RestoreBrightness();
211+
}
212+
213+
virtual AudioCodec* GetAudioCodec() override {
214+
static BoxAudioCodec audio_codec(
215+
i2c_bus_,
216+
AUDIO_INPUT_SAMPLE_RATE,
217+
AUDIO_OUTPUT_SAMPLE_RATE,
218+
AUDIO_I2S_GPIO_MCLK,
219+
AUDIO_I2S_GPIO_BCLK,
220+
AUDIO_I2S_GPIO_WS,
221+
AUDIO_I2S_GPIO_DOUT,
222+
AUDIO_I2S_GPIO_DIN,
223+
AUDIO_CODEC_PA_PIN,
224+
AUDIO_CODEC_ES8311_ADDR,
225+
AUDIO_CODEC_ES7210_ADDR,
226+
AUDIO_INPUT_REFERENCE);
227+
return &audio_codec;
228+
}
229+
230+
virtual Display* GetDisplay() override {
231+
return display_;
232+
}
233+
234+
virtual Backlight* GetBacklight() override {
235+
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
236+
return &backlight;
237+
}
238+
239+
virtual bool GetBatteryLevel(int &level, bool &charging, bool &discharging) override {
240+
static bool last_discharging = false;
241+
charging = pmic_->IsCharging();
242+
discharging = pmic_->IsDischarging();
243+
if (discharging != last_discharging)
244+
{
245+
power_save_timer_->SetEnabled(discharging);
246+
last_discharging = discharging;
247+
}
248+
249+
level = pmic_->GetBatteryLevel();
250+
return true;
251+
}
252+
253+
virtual void SetPowerSaveMode(bool enabled) override {
254+
if (!enabled)
255+
{
256+
power_save_timer_->WakeUp();
257+
}
258+
WifiBoard::SetPowerSaveMode(enabled);
259+
}
260+
};
261+
262+
DECLARE_BOARD(WaveshareEsp32s3TouchLCD1inch83);

0 commit comments

Comments
 (0)