Skip to content

Commit a2183cd

Browse files
committed
Add support for Waveshare ESP32-C6-Touch-AMOLED-1.32 board
1 parent 221d4e7 commit a2183cd

File tree

6 files changed

+325
-0
lines changed

6 files changed

+325
-0
lines changed

main/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ elseif(CONFIG_BOARD_TYPE_WAVESHARE_C6_TOUCH_AMOLED_1_43)
279279
set(BUILTIN_TEXT_FONT font_puhui_basic_30_4)
280280
set(BUILTIN_ICON_FONT font_awesome_30_4)
281281
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
282+
elseif(CONFIG_BOARD_TYPE_WAVESHARE_C6_TOUCH_AMOLED_1_32)
283+
set(BOARD_TYPE "waveshare-c6-touch-amoled-1.32")
284+
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
285+
set(BUILTIN_ICON_FONT font_awesome_20_4)
286+
set(DEFAULT_EMOJI_COLLECTION twemoji_32)
282287
elseif(CONFIG_BOARD_TYPE_WAVESHARE_P4_NANO)
283288
set(BOARD_TYPE "waveshare-p4-nano")
284289
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
@@ -270,6 +270,9 @@ choice BOARD_TYPE
270270
config BOARD_TYPE_WAVESHARE_C6_TOUCH_AMOLED_1_43
271271
bool "Waveshare ESP32-C6-Touch-AMOLOED-1.43"
272272
depends on IDF_TARGET_ESP32C6
273+
config BOARD_TYPE_WAVESHARE_C6_TOUCH_AMOLED_1_32
274+
bool "Waveshare ESP32-C6-Touch-AMOLOED-1.32"
275+
depends on IDF_TARGET_ESP32C6
273276
config BOARD_TYPE_WAVESHARE_S3_TOUCH_LCD_3_49
274277
bool "Waveshare ESP32-S3-Touch-LCD-3.49"
275278
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-C6-Touch-AMOLED-1.32](https://www.waveshare.net/shop/ESP32-C6-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+
**配置编译目标为 ESP32C6**
20+
21+
```bash
22+
idf.py set-target esp32c6
23+
```
24+
25+
**打开 menuconfig**
26+
27+
```bash
28+
idf.py menuconfig
29+
```
30+
31+
**选择板子**
32+
33+
```bash
34+
Xiaozhi Assistant -> Board Type -> Waveshare ESP32-C6-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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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_15
10+
#define AUDIO_I2S_GPIO_WS GPIO_NUM_5
11+
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_3
12+
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_4
13+
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_6
14+
15+
#define AUDIO_CODEC_PA_PIN GPIO_NUM_23
16+
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_8
17+
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_7
18+
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
19+
20+
#define BOOT_BUTTON_GPIO GPIO_NUM_9
21+
22+
23+
#define LCD_CS GPIO_NUM_22
24+
#define LCD_PCLK GPIO_NUM_18
25+
#define LCD_D0 GPIO_NUM_19
26+
#define LCD_D1 GPIO_NUM_20
27+
#define LCD_D2 GPIO_NUM_10
28+
#define LCD_D3 GPIO_NUM_11
29+
#define LCD_RST GPIO_NUM_21
30+
31+
#define EXAMPLE_LCD_H_RES 466
32+
#define EXAMPLE_LCD_V_RES 466
33+
34+
#define DISPLAY_MIRROR_X false
35+
#define DISPLAY_MIRROR_Y false
36+
#define DISPLAY_SWAP_XY false
37+
38+
#define DISPLAY_OFFSET_X 0
39+
#define DISPLAY_OFFSET_Y 0
40+
41+
#define SYS_POWER_IO_PIN GPIO_NUM_2
42+
#define PWR_KEY_GPIO GPIO_NUM_1
43+
44+
#endif // _BOARD_CONFIG_H_
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"target": "esp32c6",
3+
"builds": [
4+
{
5+
"name": "esp32-c6-touch-amoled-1.32",
6+
"sdkconfig_append": [
7+
"CONFIG_USE_ESP_WAKE_WORD=y"
8+
]
9+
}
10+
]
11+
}
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_c6_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(SYS_POWER_IO_PIN, 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 << SYS_POWER_IO_PIN);
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(SYS_POWER_IO_PIN, 1);
189+
do {
190+
vTaskDelay(pdMS_TO_TICKS(10));
191+
} while (!gpio_get_level(PWR_KEY_GPIO));
192+
}
193+
194+
public:
195+
CustomBoard() : boot_button_(BOOT_BUTTON_GPIO), pwr_button_(PWR_KEY_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);

0 commit comments

Comments
 (0)