Skip to content

Commit f7193e9

Browse files
authored
Merge branch 'main' into waveshare-c6-touch-amoled-1.32
2 parents 4b2acda + 1664fda commit f7193e9

File tree

8 files changed

+597
-8
lines changed

8 files changed

+597
-8
lines changed

main/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ elseif(CONFIG_BOARD_TYPE_WAVESHARE_C6_TOUCH_AMOLED_1_32)
284284
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
285285
set(BUILTIN_ICON_FONT font_awesome_20_4)
286286
set(DEFAULT_EMOJI_COLLECTION twemoji_32)
287+
elseif(CONFIG_BOARD_TYPE_WAVESHARE_S3_TOUCH_AMOLED_1_32)
288+
set(BOARD_TYPE "waveshare-s3-touch-amoled-1.32")
289+
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
290+
set(BUILTIN_ICON_FONT font_awesome_20_4)
291+
set(DEFAULT_EMOJI_COLLECTION twemoji_32)
287292
elseif(CONFIG_BOARD_TYPE_WAVESHARE_P4_NANO)
288293
set(BOARD_TYPE "waveshare-p4-nano")
289294
set(BUILTIN_TEXT_FONT font_puhui_basic_30_4)

main/Kconfig.projbuild

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ choice BOARD_TYPE
273273
config BOARD_TYPE_WAVESHARE_C6_TOUCH_AMOLED_1_32
274274
bool "Waveshare ESP32-C6-Touch-AMOLOED-1.32"
275275
depends on IDF_TARGET_ESP32C6
276+
config BOARD_TYPE_WAVESHARE_S3_TOUCH_AMOLED_1_32
277+
bool "Waveshare ESP32-S3-Touch-AMOLOED-1.32"
278+
depends on IDF_TARGET_ESP32S3
276279
config BOARD_TYPE_WAVESHARE_S3_TOUCH_LCD_3_49
277280
bool "Waveshare ESP32-S3-Touch-LCD-3.49"
278281
depends on IDF_TARGET_ESP32S3
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 产品链接
2+
3+
[微雪电子 ESP32-S3-Touch-AMOLED-1.32](https://www.waveshare.net/shop/ESP32-S3-Touch-AMOLED-1.32.htm)
4+
5+
# 编译配置命令
6+
7+
**克隆工程**
8+
9+
```bash
10+
git clone https://github.com/78/xiaozhi-esp32.git
11+
```
12+
13+
**进入工程**
14+
15+
```bash
16+
cd xiaozhi-esp32
17+
```
18+
19+
**配置编译目标为 ESP32S3**
20+
21+
```bash
22+
idf.py set-target esp32s3
23+
```
24+
25+
**打开 menuconfig**
26+
27+
```bash
28+
idf.py menuconfig
29+
```
30+
31+
**选择板子**
32+
33+
```bash
34+
Xiaozhi Assistant -> Board Type -> Waveshare ESP32-S3-Touch-AMOLED-1.32
35+
```
36+
37+
**编译**
38+
39+
```ba
40+
idf.py build
41+
```
42+
43+
**下载并打开串口终端**
44+
45+
```bash
46+
idf.py build flash monitor
47+
```
48+
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+
6+
#define AUDIO_INPUT_SAMPLE_RATE 24000
7+
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
8+
9+
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_38
10+
#define AUDIO_I2S_GPIO_WS GPIO_NUM_41
11+
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_39
12+
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_40
13+
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_42
14+
15+
#define AUDIO_CODEC_PA_PIN GPIO_NUM_46
16+
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_47
17+
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_48
18+
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
19+
20+
#define BOOT_BUTTON_GPIO GPIO_NUM_0
21+
#define PWR_BUTTON_GPIO GPIO_NUM_17
22+
#define PWR_EN_GPIO GPIO_NUM_18
23+
24+
25+
/*disp-qspi-lcd*/
26+
#define LCD_CS GPIO_NUM_10
27+
#define LCD_PCLK GPIO_NUM_11
28+
#define LCD_D0 GPIO_NUM_12
29+
#define LCD_D1 GPIO_NUM_13
30+
#define LCD_D2 GPIO_NUM_14
31+
#define LCD_D3 GPIO_NUM_15
32+
#define LCD_RST GPIO_NUM_8
33+
#define LCD_LIGHT (-1)
34+
35+
#define EXAMPLE_LCD_H_RES 466
36+
#define EXAMPLE_LCD_V_RES 466
37+
38+
#define DISPLAY_MIRROR_X false
39+
#define DISPLAY_MIRROR_Y false
40+
#define DISPLAY_SWAP_XY false
41+
42+
#define DISPLAY_OFFSET_X 0
43+
#define DISPLAY_OFFSET_Y 0
44+
45+
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-amoled-1.32",
6+
"sdkconfig_append": [
7+
"CONFIG_ESPTOOLPY_FLASHSIZE=8MB",
8+
"CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=partitions/v2/8m.csv"
9+
]
10+
}
11+
]
12+
}
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
#include "application.h"
2+
#include "button.h"
3+
#include "codecs/es8311_audio_codec.h"
4+
#include "config.h"
5+
#include "wifi_board.h"
6+
7+
#include "display/lcd_display.h"
8+
#include "esp_lcd_sh8601.h"
9+
#include "lvgl.h"
10+
#include "mcp_server.h"
11+
#include <driver/i2c_master.h>
12+
#include <driver/spi_common.h>
13+
#include <esp_lcd_panel_vendor.h>
14+
#include <esp_log.h>
15+
#include <wifi_station.h>
16+
17+
#define TAG "waveshare_s3_amoled_1_32"
18+
19+
static const sh8601_lcd_init_cmd_t lcd_init_cmds[] = {
20+
{0xFE, (uint8_t[]) {0x00}, 1, 0},
21+
{0xC4, (uint8_t[]) {0x80}, 1, 0},
22+
{0x3A, (uint8_t[]) {0x55}, 1, 0}, // 0x55 for RGB565, 0x77 for RGB888
23+
{0x35, (uint8_t[]) {0x00}, 1, 0},
24+
{0x53, (uint8_t[]) {0x20}, 1, 0},
25+
{0x51, (uint8_t[]) {0xFF}, 1, 0}, // Brightness
26+
{0x63, (uint8_t[]) {0xFF}, 1, 0},
27+
{0x2A, (uint8_t[]) {0x00, 0x06, 0x01, 0xD7}, 4, 0},
28+
{0x2B, (uint8_t[]) {0x00, 0x00, 0x01, 0xD1}, 4, 0},
29+
{0x11, (uint8_t[]) {0x00}, 0, 100},
30+
{0x29, (uint8_t[]) {0x00}, 0, 0},
31+
};
32+
33+
class CustomLcdDisplay : public SpiLcdDisplay {
34+
private:
35+
esp_lcd_panel_io_handle_t io_handle_;
36+
37+
public:
38+
static void my_draw_event_cb(lv_event_t *e) {
39+
lv_area_t *area = (lv_area_t *) lv_event_get_param(e);
40+
41+
uint16_t x1 = area->x1;
42+
uint16_t x2 = area->x2;
43+
uint16_t y1 = area->y1;
44+
uint16_t y2 = area->y2;
45+
46+
// Round area for better performance
47+
area->x1 = (x1 >> 1) << 1;
48+
area->y1 = (y1 >> 1) << 1;
49+
area->x2 = ((x2 >> 1) << 1) + 1;
50+
area->y2 = ((y2 >> 1) << 1) + 1;
51+
}
52+
53+
void SetMIRROR_XY(uint8_t mirror) {
54+
uint32_t lcd_cmd = 0x36;
55+
lcd_cmd &= 0xff;
56+
lcd_cmd <<= 8;
57+
lcd_cmd |= 0x02 << 24;
58+
uint8_t param = mirror;
59+
esp_lcd_panel_io_tx_param(io_handle_, lcd_cmd, &param, 1);
60+
}
61+
62+
CustomLcdDisplay(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_handle_t panel_handle, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy) :
63+
SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy),
64+
io_handle_(io_handle) {
65+
DisplayLockGuard lock(this);
66+
lv_display_add_event_cb(display_, my_draw_event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
67+
SetMIRROR_XY(0xC0); // Rotate 180 degrees
68+
lv_obj_invalidate(lv_screen_active());
69+
}
70+
};
71+
72+
class CustomBoard : public WifiBoard {
73+
private:
74+
i2c_master_bus_handle_t i2c_bus_;
75+
Button boot_button_;
76+
Button pwr_button_;
77+
esp_lcd_panel_handle_t panel_handle = NULL;
78+
esp_lcd_panel_io_handle_t io_handle = NULL;
79+
CustomLcdDisplay *display_;
80+
lv_indev_t *touch_indev = NULL;
81+
i2c_master_dev_handle_t disp_touch_dev_handle = NULL;
82+
83+
void InitializeI2c() {
84+
i2c_master_bus_config_t i2c_bus_cfg = {};
85+
i2c_bus_cfg.i2c_port = I2C_NUM_0;
86+
i2c_bus_cfg.sda_io_num = AUDIO_CODEC_I2C_SDA_PIN;
87+
i2c_bus_cfg.scl_io_num = AUDIO_CODEC_I2C_SCL_PIN;
88+
i2c_bus_cfg.clk_source = I2C_CLK_SRC_DEFAULT;
89+
i2c_bus_cfg.glitch_ignore_cnt = 7;
90+
i2c_bus_cfg.intr_priority = 0;
91+
i2c_bus_cfg.trans_queue_depth = 0;
92+
i2c_bus_cfg.flags.enable_internal_pullup = 1;
93+
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
94+
}
95+
96+
void SetDispbacklight(uint8_t backlight) {
97+
uint32_t lcd_cmd = 0x51;
98+
lcd_cmd &= 0xff;
99+
lcd_cmd <<= 8;
100+
lcd_cmd |= 0x02 << 24;
101+
uint8_t param = backlight;
102+
esp_lcd_panel_io_tx_param(io_handle, lcd_cmd, &param, 1);
103+
}
104+
105+
void InitializeButtons() {
106+
boot_button_.OnClick([this]() {
107+
auto &app = Application::GetInstance();
108+
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
109+
ResetWifiConfiguration();
110+
}
111+
app.ToggleChatState();
112+
});
113+
114+
pwr_button_.OnLongPress([this]() {
115+
GetDisplay()->SetChatMessage("system", "OFF");
116+
vTaskDelay(pdMS_TO_TICKS(1000));
117+
gpio_set_level(PWR_EN_GPIO, 0);
118+
});
119+
}
120+
121+
void InitializeSpi() {
122+
spi_bus_config_t buscfg = {};
123+
buscfg.data0_io_num = LCD_D0;
124+
buscfg.data1_io_num = LCD_D1;
125+
buscfg.sclk_io_num = LCD_PCLK;
126+
buscfg.data2_io_num = LCD_D2;
127+
buscfg.data3_io_num = LCD_D3;
128+
buscfg.max_transfer_sz = EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES * sizeof(uint16_t);
129+
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
130+
}
131+
132+
void InitializeLcdDisplay() {
133+
esp_lcd_panel_io_spi_config_t io_config = {};
134+
io_config.cs_gpio_num = LCD_CS;
135+
io_config.dc_gpio_num = -1;
136+
io_config.spi_mode = 0;
137+
io_config.pclk_hz = 40 * 1000 * 1000;
138+
io_config.trans_queue_depth = 8;
139+
io_config.on_color_trans_done = NULL;
140+
io_config.user_ctx = NULL;
141+
io_config.lcd_cmd_bits = 32;
142+
io_config.lcd_param_bits = 8;
143+
io_config.flags.quad_mode = true;
144+
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI2_HOST, &io_config, &io_handle));
145+
146+
sh8601_vendor_config_t vendor_config = {};
147+
vendor_config.init_cmds = lcd_init_cmds;
148+
vendor_config.init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]);
149+
vendor_config.flags.use_qspi_interface = 1;
150+
151+
esp_lcd_panel_dev_config_t panel_config = {};
152+
panel_config.reset_gpio_num = LCD_RST;
153+
panel_config.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB;
154+
panel_config.bits_per_pixel = 16;
155+
panel_config.vendor_config = &vendor_config;
156+
157+
ESP_ERROR_CHECK(esp_lcd_new_panel_sh8601(io_handle, &panel_config, &panel_handle));
158+
esp_lcd_panel_set_gap(panel_handle, 0x06, 0x00);
159+
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
160+
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
161+
162+
display_ = new CustomLcdDisplay(io_handle, panel_handle, EXAMPLE_LCD_H_RES, EXAMPLE_LCD_V_RES, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
163+
}
164+
165+
void InitializeTools() {
166+
auto &mcp_server = McpServer::GetInstance();
167+
mcp_server.AddTool("self.disp.setbacklight", "设置屏幕亮度", PropertyList({Property("level", kPropertyTypeInteger, 0, 255)}), [this](const PropertyList &properties) -> ReturnValue {
168+
int level = properties["level"].value<int>();
169+
ESP_LOGI("setbacklight", "%d", level);
170+
SetDispbacklight(level);
171+
return true;
172+
});
173+
174+
mcp_server.AddTool("self.disp.network", "重新配网", PropertyList(), [this](const PropertyList &) -> ReturnValue {
175+
ResetWifiConfiguration();
176+
return true;
177+
});
178+
}
179+
180+
void CheckPowerKeyState() {
181+
gpio_config_t gpio_conf = {};
182+
gpio_conf.intr_type = GPIO_INTR_DISABLE;
183+
gpio_conf.mode = GPIO_MODE_OUTPUT;
184+
gpio_conf.pin_bit_mask = (0x1ULL << PWR_EN_GPIO);
185+
gpio_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
186+
gpio_conf.pull_up_en = GPIO_PULLUP_ENABLE;
187+
ESP_ERROR_CHECK_WITHOUT_ABORT(gpio_config(&gpio_conf));
188+
gpio_set_level(PWR_EN_GPIO, 1);
189+
do {
190+
vTaskDelay(pdMS_TO_TICKS(10));
191+
} while (!gpio_get_level(PWR_BUTTON_GPIO));
192+
}
193+
194+
public:
195+
CustomBoard() : boot_button_(BOOT_BUTTON_GPIO), pwr_button_(PWR_BUTTON_GPIO) {
196+
CheckPowerKeyState();
197+
InitializeI2c();
198+
InitializeSpi();
199+
InitializeLcdDisplay();
200+
InitializeButtons();
201+
InitializeTools();
202+
}
203+
204+
virtual AudioCodec *GetAudioCodec() override {
205+
static Es8311AudioCodec audio_codec(i2c_bus_, I2C_NUM_0, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE, AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN, AUDIO_CODEC_PA_PIN, AUDIO_CODEC_ES8311_ADDR);
206+
return &audio_codec;
207+
}
208+
209+
virtual Display *GetDisplay() override {
210+
return display_;
211+
}
212+
};
213+
214+
DECLARE_BOARD(CustomBoard);

main/idf_component.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ dependencies:
2020
78/esp_lcd_nv3023: ~1.0.0
2121
78/esp-wifi-connect: ~2.6.1
2222
78/esp-opus-encoder: ~2.4.1
23-
78/esp-ml307: ~3.3.6
23+
78/esp-ml307: ~3.3.7
2424
78/xiaozhi-fonts: ~1.5.4
2525
espressif/led_strip: ~3.0.1
2626
espressif/esp_codec_dev: ~1.5
27-
espressif/esp-sr: ~2.1.5
27+
espressif/esp-sr: ~2.2.0
2828
espressif/button: ~4.1.3
2929
espressif/knob: ^1.0.0
3030
espressif/esp_video:
@@ -43,15 +43,11 @@ dependencies:
4343
lvgl/lvgl: ~9.3.0
4444
esp_lvgl_port: ~2.6.0
4545
espressif/esp_io_expander_tca95xx_16bit: ^2.0.0
46-
espressif2022/image_player: ==1.1.0~1
46+
espressif2022/image_player: ^1.1.1
4747
espressif2022/esp_emote_gfx: ^1.1.2
4848
espressif/adc_mic: ^0.2.1
4949
espressif/esp_mmap_assets: '>=1.2'
50-
txp666/otto-emoji-gif-component:
51-
version: 1.0.2
52-
rules:
53-
- if: target not in [esp32c5]
54-
50+
txp666/otto-emoji-gif-component: ^1.0.3
5551
espressif/adc_battery_estimation: ^0.2.0
5652
espressif/esp_new_jpeg: ^0.6.1
5753

0 commit comments

Comments
 (0)