forked from xiaozhi/xiaozhi-esp32
添加 Waveshare ESP32-S3-Touch-LCD-3.49 (#1227)
This commit is contained in:
3
main/boards/waveshare-s3-touch-lcd-3.49/README.md
Normal file
3
main/boards/waveshare-s3-touch-lcd-3.49/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
新增 微雪 开发板: ESP32-S3-Touch-LCD-3.49
|
||||
产品链接:
|
||||
https://www.waveshare.net/shop/ESP32-S3-Touch-LCD-3.49.htm
|
||||
62
main/boards/waveshare-s3-touch-lcd-3.49/config.h
Normal file
62
main/boards/waveshare-s3-touch-lcd-3.49/config.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef _BOARD_CONFIG_H_
|
||||
#define _BOARD_CONFIG_H_
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_master.h>
|
||||
#include "lvgl.h"
|
||||
|
||||
#define AUDIO_INPUT_SAMPLE_RATE 24000
|
||||
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
|
||||
|
||||
#define AUDIO_INPUT_REFERENCE true
|
||||
|
||||
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_7
|
||||
#define AUDIO_I2S_GPIO_WS GPIO_NUM_46
|
||||
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_15
|
||||
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_6
|
||||
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_45
|
||||
|
||||
#define AUDIO_CODEC_PA_PIN GPIO_NUM_NC
|
||||
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_47
|
||||
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_48
|
||||
#define Dev_Touch_I2C_SDA_PIN GPIO_NUM_17
|
||||
#define Dev_Touch_I2C_SCL_PIN GPIO_NUM_18
|
||||
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
|
||||
#define AUDIO_CODEC_ES7210_ADDR ES7210_CODEC_DEFAULT_ADDR
|
||||
|
||||
#define I2C_Touch_ADDRESS 0x3b
|
||||
#define I2C_Touch_SDA_PIN GPIO_NUM_17
|
||||
#define I2C_Touch_SCL_PIN GPIO_NUM_18
|
||||
|
||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||
#define PWR_BUTTON_GPIO GPIO_NUM_16
|
||||
|
||||
#define LCD_CS GPIO_NUM_9
|
||||
#define LCD_PCLK GPIO_NUM_10
|
||||
#define LCD_D0 GPIO_NUM_11
|
||||
#define LCD_D1 GPIO_NUM_12
|
||||
#define LCD_D2 GPIO_NUM_13
|
||||
#define LCD_D3 GPIO_NUM_14
|
||||
#define LCD_RST GPIO_NUM_21
|
||||
#define LCD_LIGHT (-1)
|
||||
|
||||
#define DISPLAY_WIDTH 172
|
||||
#define DISPLAY_HEIGHT 640
|
||||
#define LVGL_DMA_BUFF_LEN (DISPLAY_WIDTH * 64 * 2)
|
||||
#define LVGL_SPIRAM_BUFF_LEN (DISPLAY_WIDTH * DISPLAY_HEIGHT * 2)
|
||||
|
||||
#define DISPLAY_ROTATION_90 false
|
||||
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
|
||||
|
||||
#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_8
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT true
|
||||
|
||||
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
12
main/boards/waveshare-s3-touch-lcd-3.49/config.json
Normal file
12
main/boards/waveshare-s3-touch-lcd-3.49/config.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"target": "esp32s3",
|
||||
"builds": [
|
||||
{
|
||||
"name": "waveshare-s3-touch-lcd-3.49",
|
||||
"sdkconfig_append": [
|
||||
"CONFIG_USE_WECHAT_MESSAGE_STYLE=n",
|
||||
"CONFIG_USE_DEVICE_AEC=y"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
145
main/boards/waveshare-s3-touch-lcd-3.49/custom_lcd_display.cc
Normal file
145
main/boards/waveshare-s3-touch-lcd-3.49/custom_lcd_display.cc
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "custom_lcd_display.h"
|
||||
|
||||
#include "lcd_display.h"
|
||||
|
||||
#include <vector>
|
||||
#include <esp_log.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
#include "assets/lang_config.h"
|
||||
#include <cstring>
|
||||
#include "settings.h"
|
||||
|
||||
#include "esp_lcd_panel_io.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define TAG "CustomLcdDisplay"
|
||||
|
||||
static SemaphoreHandle_t trans_done_sem = NULL;
|
||||
static uint16_t *trans_buf_1;
|
||||
|
||||
#if (DISPLAY_ROTATION_90 == true)
|
||||
static uint16_t *dest_map;
|
||||
#endif
|
||||
|
||||
|
||||
bool CustomLcdDisplay::lvgl_port_flush_io_ready_callback(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx) {
|
||||
BaseType_t taskAwake = pdFALSE;
|
||||
lv_display_t *disp_drv = (lv_display_t *)user_ctx;
|
||||
assert(disp_drv != NULL);
|
||||
if (trans_done_sem) {
|
||||
xSemaphoreGiveFromISR(trans_done_sem, &taskAwake);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CustomLcdDisplay::lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, uint8_t *color_map) {
|
||||
assert(drv != NULL);
|
||||
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)lv_display_get_user_data(drv);
|
||||
assert(panel_handle != NULL);
|
||||
|
||||
lv_draw_sw_rgb565_swap(color_map, lv_area_get_width(area) * lv_area_get_height(area));
|
||||
|
||||
#if (DISPLAY_ROTATION_90 == true)
|
||||
lv_display_rotation_t rotation = lv_display_get_rotation(drv);
|
||||
lv_area_t rotated_area;
|
||||
if(rotation != LV_DISPLAY_ROTATION_0) {
|
||||
lv_color_format_t cf = lv_display_get_color_format(drv);
|
||||
/*Calculate the position of the rotated area*/
|
||||
rotated_area = *area;
|
||||
lv_display_rotate_area(drv, &rotated_area);
|
||||
/*Calculate the source stride (bytes in a line) from the width of the area*/
|
||||
uint32_t src_stride = lv_draw_buf_width_to_stride(lv_area_get_width(area), cf);
|
||||
/*Calculate the stride of the destination (rotated) area too*/
|
||||
uint32_t dest_stride = lv_draw_buf_width_to_stride(lv_area_get_width(&rotated_area), cf);
|
||||
/*Have a buffer to store the rotated area and perform the rotation*/
|
||||
|
||||
int32_t src_w = lv_area_get_width(area);
|
||||
int32_t src_h = lv_area_get_height(area);
|
||||
lv_draw_sw_rotate(color_map, dest_map, src_w, src_h, src_stride, dest_stride, rotation, cf);
|
||||
/*Use the rotated area and rotated buffer from now on*/
|
||||
area = &rotated_area;
|
||||
}
|
||||
#endif
|
||||
const int flush_coun = (LVGL_SPIRAM_BUFF_LEN / LVGL_DMA_BUFF_LEN);
|
||||
const int offgap = (DISPLAY_HEIGHT / flush_coun);
|
||||
const int dmalen = (LVGL_DMA_BUFF_LEN / 2);
|
||||
int offsetx1 = 0;
|
||||
int offsety1 = 0;
|
||||
int offsetx2 = DISPLAY_WIDTH;
|
||||
int offsety2 = offgap;
|
||||
#if (DISPLAY_ROTATION_90 == true)
|
||||
uint16_t *map = (uint16_t*)dest_map;
|
||||
#else
|
||||
uint16_t *map = (uint16_t*)color_map;
|
||||
#endif
|
||||
xSemaphoreGive(trans_done_sem);
|
||||
|
||||
for(int i = 0; i<flush_coun; i++) {
|
||||
xSemaphoreTake(trans_done_sem,portMAX_DELAY);
|
||||
memcpy(trans_buf_1,map,LVGL_DMA_BUFF_LEN);
|
||||
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2, offsety2, trans_buf_1);
|
||||
offsety1 += offgap;
|
||||
offsety2 += offgap;
|
||||
map += dmalen;
|
||||
}
|
||||
xSemaphoreTake(trans_done_sem,portMAX_DELAY);
|
||||
lv_disp_flush_ready(drv);
|
||||
}
|
||||
|
||||
|
||||
CustomLcdDisplay::CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
int width, int height, int offset_x, int offset_y,
|
||||
bool mirror_x, bool mirror_y, bool swap_xy)
|
||||
: LcdDisplay(panel_io, panel, width, height) {
|
||||
|
||||
ESP_LOGI(TAG, "Initialize LVGL library");
|
||||
lv_init();
|
||||
|
||||
ESP_LOGI(TAG, "Initialize LVGL port");
|
||||
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
|
||||
port_cfg.task_priority = 2;
|
||||
port_cfg.timer_period_ms = 50;
|
||||
lvgl_port_init(&port_cfg);
|
||||
trans_done_sem = xSemaphoreCreateBinary();
|
||||
trans_buf_1 = (uint16_t *)heap_caps_malloc(LVGL_DMA_BUFF_LEN, MALLOC_CAP_DMA);
|
||||
|
||||
uint32_t buffer_size = 0;
|
||||
lv_color_t *buf1 = NULL;
|
||||
lvgl_port_lock(0);
|
||||
uint8_t color_bytes = lv_color_format_get_size(LV_COLOR_FORMAT_RGB565);
|
||||
display_ = lv_display_create(width_, height_);
|
||||
lv_display_set_flush_cb(display_, lvgl_port_flush_callback);
|
||||
buffer_size = width_ * height_;
|
||||
buf1 = (lv_color_t *)heap_caps_aligned_alloc(1, buffer_size * color_bytes, MALLOC_CAP_SPIRAM);
|
||||
#if (DISPLAY_ROTATION_90 == true)
|
||||
dest_map = (uint16_t *)heap_caps_malloc(buffer_size * color_bytes, MALLOC_CAP_SPIRAM);
|
||||
lv_display_set_rotation(display_, LV_DISPLAY_ROTATION_90);
|
||||
#endif
|
||||
lv_display_set_buffers(display_, buf1, NULL, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_FULL);
|
||||
lv_display_set_user_data(display_, panel_);
|
||||
lvgl_port_unlock();
|
||||
|
||||
esp_lcd_panel_io_callbacks_t cbs = {
|
||||
.on_color_trans_done = lvgl_port_flush_io_ready_callback,
|
||||
};
|
||||
/* Register done callback */
|
||||
esp_lcd_panel_io_register_event_callbacks(panel_io_, &cbs, display_);
|
||||
|
||||
if (display_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to add display");
|
||||
return;
|
||||
}
|
||||
|
||||
if (offset_x != 0 || offset_y != 0) {
|
||||
lv_display_set_offset(display_, offset_x, offset_y);
|
||||
}
|
||||
SetupUI();
|
||||
}
|
||||
17
main/boards/waveshare-s3-touch-lcd-3.49/custom_lcd_display.h
Normal file
17
main/boards/waveshare-s3-touch-lcd-3.49/custom_lcd_display.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef __CUSTOM_LCD_DISPLAY_H__
|
||||
#define __CUSTOM_LCD_DISPLAY_H__
|
||||
|
||||
#include "lcd_display.h"
|
||||
|
||||
// // SPI LCD显示器
|
||||
class CustomLcdDisplay : public LcdDisplay {
|
||||
public:
|
||||
CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
int width, int height, int offset_x, int offset_y,
|
||||
bool mirror_x, bool mirror_y, bool swap_xy);
|
||||
private:
|
||||
static bool lvgl_port_flush_io_ready_callback(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx);
|
||||
static void lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, uint8_t *color_map);
|
||||
};
|
||||
|
||||
#endif // __CUSTOM_LCD_DISPLAY_H__
|
||||
@@ -0,0 +1,253 @@
|
||||
#include "wifi_board.h"
|
||||
#include "codecs/box_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "system_reset.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include "i2c_device.h"
|
||||
#include <driver/i2c_master.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <wifi_station.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
|
||||
#include <esp_timer.h>
|
||||
#include "esp_io_expander_tca9554.h"
|
||||
|
||||
#include "esp_lcd_axs15231b.h"
|
||||
|
||||
#include "custom_lcd_display.h"
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#define TAG "waveshare_lcd_3_39"
|
||||
|
||||
|
||||
static const axs15231b_lcd_init_cmd_t lcd_init_cmds[] = {
|
||||
{0x11, (uint8_t []){0x00}, 0, 100},
|
||||
{0x29, (uint8_t []){0x00}, 0, 100},
|
||||
};
|
||||
|
||||
class CustomBoard : public WifiBoard {
|
||||
private:
|
||||
Button boot_button_;
|
||||
Button pwr_button_;
|
||||
i2c_master_bus_handle_t i2c_bus_;
|
||||
esp_io_expander_handle_t io_expander = NULL;
|
||||
LcdDisplay* display_;
|
||||
i2c_master_dev_handle_t disp_touch_dev_handle = NULL;
|
||||
lv_indev_t *touch_indev = NULL; //touch
|
||||
bool is_PwrControlEn = false;
|
||||
|
||||
void InitializeI2c() {
|
||||
// Initialize I2C peripheral
|
||||
i2c_master_bus_config_t i2c_bus_cfg = {
|
||||
.i2c_port = (i2c_port_t)I2C_NUM_0,
|
||||
.sda_io_num = AUDIO_CODEC_I2C_SDA_PIN,
|
||||
.scl_io_num = AUDIO_CODEC_I2C_SCL_PIN,
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.intr_priority = 0,
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
.enable_internal_pullup = 1,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
|
||||
}
|
||||
|
||||
void InitializeTca9554(void) {
|
||||
esp_err_t ret = esp_io_expander_new_i2c_tca9554(i2c_bus_, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &io_expander);
|
||||
if(ret != ESP_OK)
|
||||
ESP_LOGE(TAG, "TCA9554 create returned error");
|
||||
ret = esp_io_expander_set_dir(io_expander, IO_EXPANDER_PIN_NUM_7 | IO_EXPANDER_PIN_NUM_6, IO_EXPANDER_OUTPUT);
|
||||
ESP_ERROR_CHECK(ret);
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_7 | IO_EXPANDER_PIN_NUM_6, 1);
|
||||
ESP_ERROR_CHECK(ret);
|
||||
}
|
||||
|
||||
void InitializeSpi() {
|
||||
ESP_LOGI(TAG, "Initialize QSPI bus");
|
||||
spi_bus_config_t buscfg = {};
|
||||
buscfg.data0_io_num = LCD_D0;
|
||||
buscfg.data1_io_num = LCD_D1;
|
||||
buscfg.data2_io_num = LCD_D2;
|
||||
buscfg.data3_io_num = LCD_D3;
|
||||
buscfg.sclk_io_num = LCD_PCLK;
|
||||
buscfg.max_transfer_sz = LVGL_DMA_BUFF_LEN;
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
}
|
||||
|
||||
void InitializeLcdDisplay() {
|
||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||
esp_lcd_panel_handle_t panel = nullptr;
|
||||
// RESET PIN INIT
|
||||
gpio_config_t gpio_conf = {};
|
||||
gpio_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
gpio_conf.mode = GPIO_MODE_OUTPUT;
|
||||
gpio_conf.pin_bit_mask = ((uint64_t)0x01<<LCD_RST);
|
||||
gpio_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
gpio_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(gpio_config(&gpio_conf));
|
||||
|
||||
// 液晶屏控制IO初始化
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_spi_config_t io_config = AXS15231B_PANEL_IO_QSPI_CONFIG(
|
||||
LCD_CS,
|
||||
NULL,
|
||||
NULL);
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io));
|
||||
|
||||
// 初始化液晶屏驱动芯片
|
||||
ESP_LOGI(TAG, "Install LCD driver");
|
||||
const axs15231b_vendor_config_t vendor_config = {
|
||||
.init_cmds = lcd_init_cmds, // Uncomment these line if use custom initialization commands
|
||||
.init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]),
|
||||
.flags = {
|
||||
.use_qspi_interface = 1,
|
||||
},
|
||||
};
|
||||
esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = -1,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||
.bits_per_pixel = 16,
|
||||
.vendor_config = (void *)&vendor_config,
|
||||
};
|
||||
esp_lcd_new_panel_axs15231b(panel_io, &panel_config, &panel);
|
||||
|
||||
gpio_set_level(LCD_RST,1);
|
||||
vTaskDelay(pdMS_TO_TICKS(30));
|
||||
gpio_set_level(LCD_RST,0);
|
||||
vTaskDelay(pdMS_TO_TICKS(250));
|
||||
gpio_set_level(LCD_RST,1);
|
||||
vTaskDelay(pdMS_TO_TICKS(30));
|
||||
esp_lcd_panel_init(panel);
|
||||
|
||||
display_ = new CustomLcdDisplay(panel_io, panel,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
app.ToggleChatState();
|
||||
});
|
||||
|
||||
pwr_button_.OnLongPress([this]() {
|
||||
if(is_PwrControlEn) {
|
||||
is_PwrControlEn = false;
|
||||
esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_6, 0);
|
||||
}
|
||||
});
|
||||
|
||||
pwr_button_.OnPressUp([this]() {
|
||||
if(!is_PwrControlEn) {
|
||||
is_PwrControlEn = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void InitializeTouch() {
|
||||
i2c_master_bus_handle_t touch_i2c_bus_;
|
||||
// Initialize I2C peripheral
|
||||
i2c_master_bus_config_t i2c_bus_cfg = {};
|
||||
i2c_bus_cfg.i2c_port = (i2c_port_t)I2C_NUM_1;
|
||||
i2c_bus_cfg.sda_io_num = I2C_Touch_SDA_PIN;
|
||||
i2c_bus_cfg.scl_io_num = I2C_Touch_SCL_PIN;
|
||||
i2c_bus_cfg.clk_source = I2C_CLK_SRC_DEFAULT;
|
||||
i2c_bus_cfg.glitch_ignore_cnt = 7;
|
||||
i2c_bus_cfg.intr_priority = 0;
|
||||
i2c_bus_cfg.trans_queue_depth = 0;
|
||||
i2c_bus_cfg.flags.enable_internal_pullup = 1;
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &touch_i2c_bus_));
|
||||
|
||||
i2c_device_config_t dev_cfg = {
|
||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||
.device_address = I2C_Touch_ADDRESS,
|
||||
.scl_speed_hz = 300000,
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(touch_i2c_bus_, &dev_cfg, &disp_touch_dev_handle));
|
||||
|
||||
touch_indev = lv_indev_create();
|
||||
lv_indev_set_type(touch_indev, LV_INDEV_TYPE_POINTER);
|
||||
lv_indev_set_read_cb(touch_indev, TouchInputReadCallback);
|
||||
lv_indev_set_user_data(touch_indev, disp_touch_dev_handle);
|
||||
}
|
||||
|
||||
static void TouchInputReadCallback(lv_indev_t * indev, lv_indev_data_t *indevData) {
|
||||
i2c_master_dev_handle_t i2c_dev = (i2c_master_dev_handle_t)lv_indev_get_user_data(indev);
|
||||
uint8_t read_touchpad_cmd[11] = {0xb5, 0xab, 0xa5, 0x5a, 0x0, 0x0, 0x0, 0x0e,0x0, 0x0, 0x0};
|
||||
uint8_t buff[32] = {0};
|
||||
i2c_master_transmit_receive(i2c_dev,read_touchpad_cmd,11,buff,32,1000);
|
||||
uint16_t pointX;
|
||||
uint16_t pointY;
|
||||
pointX = (((uint16_t)buff[2] & 0x0f) << 8) | (uint16_t)buff[3];
|
||||
pointY = (((uint16_t)buff[4] & 0x0f) << 8) | (uint16_t)buff[5];
|
||||
if (buff[1]>0 && buff[1]<5) {
|
||||
indevData->state = LV_INDEV_STATE_PRESSED;
|
||||
if(pointX > DISPLAY_WIDTH) pointX = DISPLAY_WIDTH;
|
||||
if(pointY > DISPLAY_HEIGHT) pointY = DISPLAY_HEIGHT;
|
||||
indevData->point.x = pointY;
|
||||
indevData->point.y = (DISPLAY_HEIGHT-pointX);
|
||||
ESP_LOGE("Touch","(%ld,%ld)",indevData->point.x,indevData->point.y);
|
||||
} else {
|
||||
indevData->state = LV_INDEV_STATE_RELEASED;
|
||||
}
|
||||
}
|
||||
|
||||
void GetPwrCurrentState() {
|
||||
if(gpio_get_level(PWR_BUTTON_GPIO)) {
|
||||
is_PwrControlEn = true;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
CustomBoard() :
|
||||
boot_button_(BOOT_BUTTON_GPIO),
|
||||
pwr_button_(PWR_BUTTON_GPIO) {
|
||||
InitializeI2c();
|
||||
InitializeTca9554();
|
||||
InitializeSpi();
|
||||
InitializeLcdDisplay();
|
||||
InitializeButtons();
|
||||
InitializeTouch();
|
||||
GetPwrCurrentState();
|
||||
GetBacklight()->RestoreBrightness();
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
static BoxAudioCodec audio_codec(
|
||||
i2c_bus_,
|
||||
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,
|
||||
AUDIO_CODEC_ES7210_ADDR,
|
||||
AUDIO_INPUT_REFERENCE);
|
||||
return &audio_codec;
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual Backlight* GetBacklight() override {
|
||||
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
|
||||
return &backlight;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(CustomBoard);
|
||||
Reference in New Issue
Block a user