First working C64 READY screen
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
.pio/
|
||||
.vscode/
|
||||
@@ -0,0 +1,15 @@
|
||||
# Waveshare ESP32-S3-Touch-LCD-3.49 - C64 READY
|
||||
|
||||
PlatformIO starter showing Commodore 64-style READY. with a blinking cursor.
|
||||
|
||||
Hardware: ESP32-S3R8, 16 MB flash, 8 MB PSRAM, 172x640 AXS15231B QSPI LCD.
|
||||
|
||||
Build: `pio run`
|
||||
Upload: `pio run -t upload`
|
||||
Monitor: 115200 baud
|
||||
|
||||
C64 palette: background `#40318D`; text/cursor `#7869C4`.
|
||||
|
||||
Sources:
|
||||
- https://www.waveshare.com/wiki/ESP32-S3-Touch-LCD-3.49
|
||||
- https://github.com/waveshareteam/ESP32-S3-Touch-LCD-3.49
|
||||
@@ -0,0 +1,21 @@
|
||||
[env:waveshare-c64-ready]
|
||||
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
|
||||
board = esp32-s3-devkitc-1
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
upload_speed = 921600
|
||||
board_build.flash_size = 16MB
|
||||
board_build.flash_mode = qio
|
||||
board_upload.maximum_size = 16777216
|
||||
board_build.arduino.memory_type = qio_opi
|
||||
board_build.partitions = default_16MB.csv
|
||||
build_flags =
|
||||
-DBOARD_HAS_PSRAM
|
||||
-DARDUINO_USB_MODE=1
|
||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||
-DLV_CONF_SKIP
|
||||
-DLV_COLOR_DEPTH=16
|
||||
-DLV_COLOR_16_SWAP=1
|
||||
-DLV_FONT_MONTSERRAT_48=1
|
||||
lib_deps =
|
||||
lvgl/lvgl@8.4.0
|
||||
@@ -0,0 +1,550 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_lcd_panel_interface.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_panel_commands.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "../touch/esp_lcd_touch.h"
|
||||
|
||||
#include "esp_lcd_axs15231b.h"
|
||||
|
||||
/*max point num*/
|
||||
#define AXS_MAX_TOUCH_NUMBER (1)
|
||||
|
||||
#define LCD_OPCODE_WRITE_CMD (0x02ULL)
|
||||
#define LCD_OPCODE_READ_CMD (0x0BULL)
|
||||
#define LCD_OPCODE_WRITE_COLOR (0x32ULL)
|
||||
|
||||
static const char *TAG = "lcd_panel.axs15231b";
|
||||
|
||||
static esp_err_t panel_axs15231b_del(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_axs15231b_reset(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_axs15231b_init(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_axs15231b_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data);
|
||||
static esp_err_t panel_axs15231b_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
|
||||
static esp_err_t panel_axs15231b_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
|
||||
static esp_err_t panel_axs15231b_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
|
||||
static esp_err_t panel_axs15231b_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
|
||||
static esp_err_t panel_axs15231b_disp_off(esp_lcd_panel_t *panel, bool off);
|
||||
|
||||
static esp_err_t touch_axs15231b_read_data(esp_lcd_touch_handle_t tp);
|
||||
static bool touch_axs15231b_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num);
|
||||
static esp_err_t touch_axs15231b_del(esp_lcd_touch_handle_t tp);
|
||||
static esp_err_t touch_axs15231b_reset(esp_lcd_touch_handle_t tp);
|
||||
|
||||
static esp_err_t i2c_read_bytes(esp_lcd_touch_handle_t tp, int reg, uint8_t *data, uint8_t len);
|
||||
static esp_err_t i2c_write_bytes(esp_lcd_touch_handle_t tp, int reg, const uint8_t *data, uint8_t len);
|
||||
|
||||
typedef struct {
|
||||
esp_lcd_panel_t base;
|
||||
esp_lcd_panel_io_handle_t io;
|
||||
int reset_gpio_num;
|
||||
int x_gap;
|
||||
int y_gap;
|
||||
uint8_t fb_bits_per_pixel;
|
||||
uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register
|
||||
uint8_t colmod_val; // save surrent value of LCD_CMD_COLMOD register
|
||||
const axs15231b_lcd_init_cmd_t *init_cmds;
|
||||
uint16_t init_cmds_size;
|
||||
struct {
|
||||
unsigned int use_qspi_interface: 1;
|
||||
unsigned int reset_level: 1;
|
||||
} flags;
|
||||
} axs15231b_panel_t;
|
||||
|
||||
esp_err_t esp_lcd_new_panel_axs15231b(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
axs15231b_panel_t *axs15231b = NULL;
|
||||
ESP_GOTO_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
|
||||
axs15231b = calloc(1, sizeof(axs15231b_panel_t));
|
||||
ESP_GOTO_ON_FALSE(axs15231b, ESP_ERR_NO_MEM, err, TAG, "no mem for axs15231b panel");
|
||||
|
||||
if (panel_dev_config->reset_gpio_num >= 0) {
|
||||
gpio_config_t io_conf = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << panel_dev_config->reset_gpio_num,
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for RST line failed");
|
||||
}
|
||||
|
||||
switch (panel_dev_config->color_space) {
|
||||
case LCD_RGB_ELEMENT_ORDER_RGB:
|
||||
axs15231b->madctl_val = 0;
|
||||
break;
|
||||
case LCD_RGB_ELEMENT_ORDER_BGR:
|
||||
axs15231b->madctl_val |= LCD_CMD_BGR_BIT;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported RGB element order");
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t fb_bits_per_pixel = 0;
|
||||
switch (panel_dev_config->bits_per_pixel) {
|
||||
case 16: // RGB565
|
||||
axs15231b->colmod_val = 0x55;
|
||||
fb_bits_per_pixel = 16;
|
||||
break;
|
||||
case 18: // RGB666
|
||||
axs15231b->colmod_val = 0x66;
|
||||
// each color component (R/G/B) should occupy the 6 high bits of a byte, which means 3 full bytes are required for a pixel
|
||||
fb_bits_per_pixel = 24;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
|
||||
break;
|
||||
}
|
||||
|
||||
axs15231b->io = io;
|
||||
axs15231b->fb_bits_per_pixel = fb_bits_per_pixel;
|
||||
axs15231b->reset_gpio_num = panel_dev_config->reset_gpio_num;
|
||||
axs15231b->flags.reset_level = panel_dev_config->flags.reset_active_high;
|
||||
if (panel_dev_config->vendor_config) {
|
||||
axs15231b->init_cmds = ((axs15231b_vendor_config_t *)panel_dev_config->vendor_config)->init_cmds;
|
||||
axs15231b->init_cmds_size = ((axs15231b_vendor_config_t *)panel_dev_config->vendor_config)->init_cmds_size;
|
||||
axs15231b->flags.use_qspi_interface = ((axs15231b_vendor_config_t *)panel_dev_config->vendor_config)->flags.use_qspi_interface;
|
||||
}
|
||||
axs15231b->base.del = panel_axs15231b_del;
|
||||
axs15231b->base.reset = panel_axs15231b_reset;
|
||||
axs15231b->base.init = panel_axs15231b_init;
|
||||
axs15231b->base.draw_bitmap = panel_axs15231b_draw_bitmap;
|
||||
axs15231b->base.invert_color = panel_axs15231b_invert_color;
|
||||
axs15231b->base.set_gap = panel_axs15231b_set_gap;
|
||||
axs15231b->base.mirror = panel_axs15231b_mirror;
|
||||
axs15231b->base.swap_xy = panel_axs15231b_swap_xy;
|
||||
axs15231b->base.disp_on_off = panel_axs15231b_disp_off;
|
||||
*ret_panel = &(axs15231b->base);
|
||||
ESP_LOGD(TAG, "new axs15231b panel @%p", axs15231b);
|
||||
//ESP_LOGI(TAG, "LCD panel create success, version: %d.%d.%d", ESP_LCD_AXS15231B_VER_MAJOR, ESP_LCD_AXS15231B_VER_MINOR,
|
||||
// ESP_LCD_AXS15231B_VER_PATCH);
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (axs15231b) {
|
||||
if (panel_dev_config->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(panel_dev_config->reset_gpio_num);
|
||||
}
|
||||
free(axs15231b);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t tx_param(axs15231b_panel_t *axs15231b, esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size)
|
||||
{
|
||||
if (axs15231b->flags.use_qspi_interface) {
|
||||
lcd_cmd &= 0xff;
|
||||
lcd_cmd <<= 8;
|
||||
lcd_cmd |= LCD_OPCODE_WRITE_CMD << 24;
|
||||
}
|
||||
return esp_lcd_panel_io_tx_param(io, lcd_cmd, param, param_size);
|
||||
}
|
||||
|
||||
static esp_err_t tx_color(axs15231b_panel_t *axs15231b, esp_lcd_panel_io_handle_t io, int lcd_cmd, const void *param, size_t param_size)
|
||||
{
|
||||
if (axs15231b->flags.use_qspi_interface) {
|
||||
lcd_cmd &= 0xff;
|
||||
lcd_cmd <<= 8;
|
||||
lcd_cmd |= LCD_OPCODE_WRITE_COLOR << 24;
|
||||
}
|
||||
return esp_lcd_panel_io_tx_color(io, lcd_cmd, param, param_size);
|
||||
}
|
||||
|
||||
static esp_err_t panel_axs15231b_del(esp_lcd_panel_t *panel)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
|
||||
if (axs15231b->reset_gpio_num >= 0) {
|
||||
gpio_reset_pin(axs15231b->reset_gpio_num);
|
||||
}
|
||||
ESP_LOGD(TAG, "del axs15231b panel @%p", axs15231b);
|
||||
free(axs15231b);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_axs15231b_reset(esp_lcd_panel_t *panel)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = axs15231b->io;
|
||||
|
||||
// perform hardware reset
|
||||
if (axs15231b->reset_gpio_num >= 0) {
|
||||
gpio_set_level(axs15231b->reset_gpio_num, !axs15231b->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
gpio_set_level(axs15231b->reset_gpio_num, axs15231b->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
gpio_set_level(axs15231b->reset_gpio_num, !axs15231b->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
} else { // perform software reset
|
||||
tx_param(axs15231b, io, LCD_CMD_SWRESET, NULL, 0);
|
||||
vTaskDelay(pdMS_TO_TICKS(120)); // spec, wait at least 5m before sending new command
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static const axs15231b_lcd_init_cmd_t vendor_specific_init_default[] = {
|
||||
{0xBB, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A, 0xA5}, 8, 0},
|
||||
{0xA0, (uint8_t[]){0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x64, 0x3F, 0x20, 0x05, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00}, 17, 0},
|
||||
{0xA2, (uint8_t[]){0x30, 0x04, 0x0A, 0x3C, 0xEC, 0x54, 0xC4, 0x30, 0xAC, 0x28, 0x7F, 0x7F, 0x7F, 0x20, 0xF8, 0x10, 0x02, 0xFF, 0xFF, 0xF0, 0x90, 0x01, 0x32, 0xA0, 0x91, 0xC0, 0x20, 0x7F, 0xFF, 0x00, 0x54}, 31, 0},
|
||||
{0xD0, (uint8_t[]){0x30, 0xAC, 0x21, 0x24, 0x08, 0x09, 0x10, 0x01, 0xAA, 0x14, 0xC2, 0x00, 0x22, 0x22, 0xAA, 0x03, 0x10, 0x12, 0x40, 0x14, 0x1E, 0x51, 0x15, 0x00, 0x40, 0x10, 0x00, 0x03, 0x3D, 0x12}, 30, 0},
|
||||
{0xA3, (uint8_t[]){0xA0, 0x06, 0xAA, 0x08, 0x08, 0x02, 0x0A, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x55, 0x55}, 22, 0},
|
||||
{0xC1, (uint8_t[]){0x33, 0x04, 0x02, 0x02, 0x71, 0x05, 0x24, 0x55, 0x02, 0x00, 0x41, 0x00, 0x53, 0xFF, 0xFF, 0xFF, 0x4F, 0x52, 0x00, 0x4F, 0x52, 0x00, 0x45, 0x3B, 0x0B, 0x02, 0x0D, 0x00, 0xFF, 0x40}, 30, 0},
|
||||
{0xC3, (uint8_t[]){0x00, 0x00, 0x00, 0x50, 0x03, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01}, 11, 0},
|
||||
{0xC4, (uint8_t[]){0x00, 0x24, 0x33, 0x90, 0x50, 0xea, 0x64, 0x32, 0xC8, 0x64, 0xC8, 0x32, 0x90, 0x90, 0x11, 0x06, 0xDC, 0xFA, 0x04, 0x03, 0x80, 0xFE, 0x10, 0x10, 0x00, 0x0A, 0x0A, 0x44, 0x50}, 29, 0},
|
||||
{0xC5, (uint8_t[]){0x18, 0x00, 0x00, 0x03, 0xFE, 0x78, 0x33, 0x20, 0x30, 0x10, 0x88, 0xDE, 0x0D, 0x08, 0x0F, 0x0F, 0x01, 0x78, 0x33, 0x20, 0x10, 0x10, 0x80}, 23, 0},
|
||||
{0xC6, (uint8_t[]){0x05, 0x0A, 0x05, 0x0A, 0x00, 0xE0, 0x2E, 0x0B, 0x12, 0x22, 0x12, 0x22, 0x01, 0x00, 0x00, 0x3F, 0x6A, 0x18, 0xC8, 0x22}, 20, 0},
|
||||
{0xC7, (uint8_t[]){0x50, 0x32, 0x28, 0x00, 0xa2, 0x80, 0x8f, 0x00, 0x80, 0xff, 0x07, 0x11, 0x9F, 0x6f, 0xff, 0x26, 0x0c, 0x0d, 0x0e, 0x0f}, 20, 0},
|
||||
{0xC9, (uint8_t[]){0x33, 0x44, 0x44, 0x01}, 4, 0},
|
||||
{0xCF, (uint8_t[]){0x34, 0x1E, 0x88, 0x58, 0x13, 0x18, 0x56, 0x18, 0x1E, 0x68, 0xF7, 0x00, 0x65, 0x0C, 0x22, 0xC4, 0x0C, 0x77, 0x22, 0x44, 0xAA, 0x55, 0x04, 0x04, 0x12, 0xA0, 0x08}, 27, 0},
|
||||
{0xD5, (uint8_t[]){0x3E, 0x3E, 0x88, 0x00, 0x44, 0x04, 0x78, 0x33, 0x20, 0x78, 0x33, 0x20, 0x04, 0x28, 0xD3, 0x47, 0x03, 0x03, 0x03, 0x03, 0x86, 0x00, 0x00, 0x00, 0x30, 0x52, 0x3f, 0x40, 0x40, 0x96}, 30, 0},
|
||||
{0xD6, (uint8_t[]){0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0x95, 0x00, 0x01, 0x83, 0x75, 0x36, 0x20, 0x75, 0x36, 0x20, 0x3F, 0x03, 0x03, 0x03, 0x10, 0x10, 0x00, 0x04, 0x51, 0x20, 0x01, 0x00}, 30, 0},
|
||||
{0xD7, (uint8_t[]){0x0a, 0x08, 0x0e, 0x0c, 0x1E, 0x18, 0x19, 0x1F, 0x00, 0x1F, 0x1A, 0x1F, 0x3E, 0x3E, 0x04, 0x00, 0x1F, 0x1F, 0x1F}, 19, 0},
|
||||
{0xD8, (uint8_t[]){0x0B, 0x09, 0x0F, 0x0D, 0x1E, 0x18, 0x19, 0x1F, 0x01, 0x1F, 0x1A, 0x1F}, 12, 0},
|
||||
{0xD9, (uint8_t[]){0x00, 0x0D, 0x0F, 0x09, 0x0B, 0x1F, 0x18, 0x19, 0x1F, 0x01, 0x1E, 0x1A, 0x1F}, 13, 0},
|
||||
{0xDD, (uint8_t[]){0x0C, 0x0E, 0x08, 0x0A, 0x1F, 0x18, 0x19, 0x1F, 0x00, 0x1E, 0x1A, 0x1F}, 12, 0},
|
||||
{0xDF, (uint8_t[]){0x44, 0x73, 0x4B, 0x69, 0x00, 0x0A, 0x02, 0x90}, 8, 0},
|
||||
{0xE0, (uint8_t[]){0x19, 0x20, 0x0A, 0x13, 0x0E, 0x09, 0x12, 0x28, 0xD4, 0x24, 0x0C, 0x35, 0x13, 0x31, 0x36, 0x2f, 0x03}, 17, 0},
|
||||
{0xE1, (uint8_t[]){0x38, 0x20, 0x09, 0x12, 0x0E, 0x08, 0x12, 0x28, 0xC5, 0x24, 0x0C, 0x34, 0x12, 0x31, 0x36, 0x2f, 0x27}, 17, 0},
|
||||
{0xE2, (uint8_t[]){0x19, 0x20, 0x0A, 0x11, 0x09, 0x06, 0x11, 0x25, 0xD4, 0x22, 0x0B, 0x33, 0x12, 0x2D, 0x32, 0x2f, 0x03}, 17, 0},
|
||||
{0xE3, (uint8_t[]){0x38, 0x20, 0x0A, 0x11, 0x09, 0x06, 0x11, 0x25, 0xC4, 0x21, 0x0A, 0x32, 0x11, 0x2C, 0x32, 0x2f, 0x27}, 17, 0},
|
||||
{0xE4, (uint8_t[]){0x19, 0x20, 0x0D, 0x14, 0x0D, 0x08, 0x12, 0x2A, 0xD4, 0x26, 0x0E, 0x35, 0x13, 0x34, 0x39, 0x2f, 0x03}, 17, 0},
|
||||
{0xE5, (uint8_t[]){0x38, 0x20, 0x0D, 0x13, 0x0D, 0x07, 0x12, 0x29, 0xC4, 0x25, 0x0D, 0x35, 0x12, 0x33, 0x39, 0x2f, 0x27}, 17, 0},
|
||||
{0xBB, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, 0},
|
||||
{0x13, (uint8_t[]){0x00}, 0, 0},
|
||||
{0x11, (uint8_t[]){0x00}, 0, 200},
|
||||
{0x29, (uint8_t[]){0x00}, 0, 200},
|
||||
{0x2C, (uint8_t[]){0x00, 0x00, 0x00, 0x00}, 4, 0},
|
||||
{0x22, (uint8_t[]){0x00}, 0, 200},//All Pixels off
|
||||
};
|
||||
|
||||
static esp_err_t panel_axs15231b_init(esp_lcd_panel_t *panel)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = axs15231b->io;
|
||||
|
||||
// LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first
|
||||
ESP_RETURN_ON_ERROR(tx_param(axs15231b, io, LCD_CMD_SLPOUT, NULL, 0), TAG, "send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
ESP_RETURN_ON_ERROR(tx_param(axs15231b, io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
axs15231b->madctl_val,
|
||||
}, 1), TAG, "send command failed");
|
||||
ESP_RETURN_ON_ERROR(tx_param(axs15231b, io, LCD_CMD_COLMOD, (uint8_t[]) {
|
||||
axs15231b->colmod_val,
|
||||
}, 1), TAG, "send command failed");
|
||||
|
||||
const axs15231b_lcd_init_cmd_t *init_cmds = NULL;
|
||||
uint16_t init_cmds_size = 0;
|
||||
if (axs15231b->init_cmds) {
|
||||
init_cmds = axs15231b->init_cmds;
|
||||
init_cmds_size = axs15231b->init_cmds_size;
|
||||
} else {
|
||||
init_cmds = vendor_specific_init_default;
|
||||
init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(axs15231b_lcd_init_cmd_t);
|
||||
}
|
||||
|
||||
bool is_cmd_overwritten = false;
|
||||
for (int i = 0; i < init_cmds_size; i++) {
|
||||
// Check if the command has been used or conflicts with the internal
|
||||
switch (init_cmds[i].cmd) {
|
||||
case LCD_CMD_MADCTL:
|
||||
is_cmd_overwritten = true;
|
||||
axs15231b->madctl_val = ((uint8_t *)init_cmds[i].data)[0];
|
||||
break;
|
||||
case LCD_CMD_COLMOD:
|
||||
is_cmd_overwritten = true;
|
||||
axs15231b->colmod_val = ((uint8_t *)init_cmds[i].data)[0];
|
||||
break;
|
||||
default:
|
||||
is_cmd_overwritten = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_cmd_overwritten) {
|
||||
ESP_LOGW(TAG, "The %02Xh command has been used and will be overwritten by external initialization sequence", init_cmds[i].cmd);
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(tx_param(axs15231b, io, init_cmds[i].cmd, init_cmds[i].data, init_cmds[i].data_bytes), TAG, "send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(init_cmds[i].delay_ms));
|
||||
}
|
||||
ESP_LOGI(TAG, "send init commands success");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_axs15231b_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
assert((x_start < x_end) && (y_start < y_end) && "start position must be smaller than end position");
|
||||
esp_lcd_panel_io_handle_t io = axs15231b->io;
|
||||
|
||||
x_start += axs15231b->x_gap;
|
||||
x_end += axs15231b->x_gap;
|
||||
y_start += axs15231b->y_gap;
|
||||
y_end += axs15231b->y_gap;
|
||||
|
||||
// define an area of frame memory where MCU can access
|
||||
tx_param(axs15231b, io, LCD_CMD_CASET, (uint8_t[]) {
|
||||
(x_start >> 8) & 0xFF,
|
||||
x_start & 0xFF,
|
||||
((x_end - 1) >> 8) & 0xFF,
|
||||
(x_end - 1) & 0xFF,
|
||||
}, 4);
|
||||
|
||||
if (0 == axs15231b->flags.use_qspi_interface) {
|
||||
tx_param(axs15231b, io, LCD_CMD_RASET, (uint8_t[]) {
|
||||
(y_start >> 8) & 0xFF,
|
||||
y_start & 0xFF,
|
||||
((y_end - 1) >> 8) & 0xFF,
|
||||
(y_end - 1) & 0xFF,
|
||||
}, 4);
|
||||
}
|
||||
|
||||
// transfer frame buffer
|
||||
size_t len = (x_end - x_start) * (y_end - y_start) * axs15231b->fb_bits_per_pixel / 8;
|
||||
if (y_start == 0) {
|
||||
tx_color(axs15231b, io, LCD_CMD_RAMWR, color_data, len);//2C
|
||||
} else {
|
||||
tx_color(axs15231b, io, LCD_CMD_RAMWRC, color_data, len);//3C
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_axs15231b_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = axs15231b->io;
|
||||
int command = 0;
|
||||
if (invert_color_data) {
|
||||
command = LCD_CMD_INVON;
|
||||
} else {
|
||||
command = LCD_CMD_INVOFF;
|
||||
}
|
||||
tx_param(axs15231b, io, command, NULL, 0);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_axs15231b_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = axs15231b->io;
|
||||
if (mirror_x) {
|
||||
axs15231b->madctl_val |= LCD_CMD_MX_BIT;
|
||||
} else {
|
||||
axs15231b->madctl_val &= ~LCD_CMD_MX_BIT;
|
||||
}
|
||||
if (mirror_y) {
|
||||
axs15231b->madctl_val |= LCD_CMD_MY_BIT;
|
||||
} else {
|
||||
axs15231b->madctl_val &= ~LCD_CMD_MY_BIT;
|
||||
}
|
||||
tx_param(axs15231b, io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
axs15231b->madctl_val
|
||||
}, 1);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_axs15231b_swap_xy(esp_lcd_panel_t *panel, bool swap_axes)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = axs15231b->io;
|
||||
if (swap_axes) {
|
||||
axs15231b->madctl_val |= LCD_CMD_MV_BIT;
|
||||
} else {
|
||||
axs15231b->madctl_val &= ~LCD_CMD_MV_BIT;
|
||||
}
|
||||
tx_param(axs15231b, io, LCD_CMD_MADCTL, (uint8_t[]) {
|
||||
axs15231b->madctl_val
|
||||
}, 1);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_axs15231b_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
axs15231b->x_gap = x_gap;
|
||||
axs15231b->y_gap = y_gap;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_axs15231b_disp_off(esp_lcd_panel_t *panel, bool off)
|
||||
{
|
||||
axs15231b_panel_t *axs15231b = __containerof(panel, axs15231b_panel_t, base);
|
||||
esp_lcd_panel_io_handle_t io = axs15231b->io;
|
||||
int command = 0;
|
||||
if (off) {
|
||||
command = LCD_CMD_DISPOFF;
|
||||
} else {
|
||||
command = LCD_CMD_DISPON;
|
||||
}
|
||||
tx_param(axs15231b, io, command, NULL, 0);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_new_i2c_axs15231b(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *tp)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(io, ESP_ERR_INVALID_ARG, TAG, "Invalid io");
|
||||
ESP_RETURN_ON_FALSE(config, ESP_ERR_INVALID_ARG, TAG, "Invalid config");
|
||||
ESP_RETURN_ON_FALSE(tp, ESP_ERR_INVALID_ARG, TAG, "Invalid touch handle");
|
||||
|
||||
/* Prepare main structure */
|
||||
esp_err_t ret = ESP_OK;
|
||||
esp_lcd_touch_handle_t axs15231b = calloc(1, sizeof(esp_lcd_touch_t));
|
||||
ESP_GOTO_ON_FALSE(axs15231b, ESP_ERR_NO_MEM, err, TAG, "Touch handle malloc failed");
|
||||
|
||||
/* Communication interface */
|
||||
axs15231b->io = io;
|
||||
/* Only supported callbacks are set */
|
||||
axs15231b->read_data = touch_axs15231b_read_data;
|
||||
axs15231b->get_xy = touch_axs15231b_get_xy;
|
||||
axs15231b->del = touch_axs15231b_del;
|
||||
/* Mutex */
|
||||
axs15231b->data.lock.owner = portMUX_FREE_VAL;
|
||||
/* Save config */
|
||||
memcpy(&axs15231b->config, config, sizeof(esp_lcd_touch_config_t));
|
||||
|
||||
/* Prepare pin for touch interrupt */
|
||||
if (axs15231b->config.int_gpio_num != GPIO_NUM_NC) {
|
||||
const gpio_config_t int_gpio_config = {
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.intr_type = GPIO_INTR_NEGEDGE,
|
||||
.pin_bit_mask = BIT64(axs15231b->config.int_gpio_num)
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(gpio_config(&int_gpio_config), err, TAG, "GPIO intr config failed");
|
||||
|
||||
/* Register interrupt callback */
|
||||
if (axs15231b->config.interrupt_callback) {
|
||||
esp_lcd_touch_register_interrupt_callback(axs15231b, axs15231b->config.interrupt_callback);
|
||||
}
|
||||
}
|
||||
/* Prepare pin for touch controller reset */
|
||||
if (axs15231b->config.rst_gpio_num != GPIO_NUM_NC) {
|
||||
const gpio_config_t rst_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = BIT64(axs15231b->config.rst_gpio_num)
|
||||
};
|
||||
ESP_GOTO_ON_ERROR(gpio_config(&rst_gpio_config), err, TAG, "GPIO reset config failed");
|
||||
}
|
||||
/* Reset controller */
|
||||
ESP_GOTO_ON_ERROR(touch_axs15231b_reset(axs15231b), err, TAG, "Reset failed");
|
||||
*tp = axs15231b;
|
||||
|
||||
return ESP_OK;
|
||||
err:
|
||||
if (axs15231b) {
|
||||
touch_axs15231b_del(axs15231b);
|
||||
}
|
||||
ESP_LOGE(TAG, "Initialization failed!");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t touch_axs15231b_read_data(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
typedef struct {
|
||||
uint8_t gesture; //AXS_TOUCH_GESTURE_POS:0
|
||||
uint8_t num; //AXS_TOUCH_POINT_NUM:1
|
||||
uint8_t x_h : 4; //AXS_TOUCH_X_H_POS:2
|
||||
uint8_t : 2;
|
||||
uint8_t event : 2; //AXS_TOUCH_EVENT_POS:2
|
||||
uint8_t x_l; //AXS_TOUCH_X_L_POS:3
|
||||
uint8_t y_h : 4; //AXS_TOUCH_Y_H_POS:4
|
||||
uint8_t : 4;
|
||||
uint8_t y_l; //AXS_TOUCH_Y_L_POS:5
|
||||
} __attribute__((packed)) touch_record_struct_t;
|
||||
|
||||
touch_record_struct_t *p_touch_data = NULL;
|
||||
|
||||
uint8_t data[AXS_MAX_TOUCH_NUMBER * 6 + 2] = {0}; /*1 Point:8; 2 Point: 14 */
|
||||
const uint8_t read_cmd[11] = {0xb5, 0xab, 0xa5, 0x5a, 0x00, 0x00, (AXS_MAX_TOUCH_NUMBER * 6 + 2) >> 8, (AXS_MAX_TOUCH_NUMBER * 6 + 2) & 0xff, 0x00, 0x00, 0x00};
|
||||
|
||||
ESP_RETURN_ON_ERROR(i2c_write_bytes(tp, -1, read_cmd, sizeof(read_cmd)), TAG, "I2C write failed");
|
||||
ESP_RETURN_ON_ERROR(i2c_read_bytes(tp, -1, data, sizeof(data)), TAG, "I2C read failed");
|
||||
|
||||
p_touch_data = (touch_record_struct_t *) data;
|
||||
if (p_touch_data->num && (AXS_MAX_TOUCH_NUMBER >= p_touch_data->num)) {
|
||||
portENTER_CRITICAL(&tp->data.lock);
|
||||
tp->data.points = p_touch_data->num;
|
||||
/* Fill all coordinates */
|
||||
for (int i = 0; i < tp->data.points; i++) {
|
||||
tp->data.coords[i].x = ((p_touch_data->x_h & 0x0F) << 8) | p_touch_data->x_l;
|
||||
tp->data.coords[i].y = ((p_touch_data->y_h & 0x0F) << 8) | p_touch_data->y_l;
|
||||
}
|
||||
portEXIT_CRITICAL(&tp->data.lock);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static bool touch_axs15231b_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num)
|
||||
{
|
||||
portENTER_CRITICAL(&tp->data.lock);
|
||||
/* Count of points */
|
||||
*point_num = (tp->data.points > max_point_num ? max_point_num : tp->data.points);
|
||||
for (size_t i = 0; i < *point_num; i++) {
|
||||
x[i] = tp->data.coords[i].x;
|
||||
y[i] = tp->data.coords[i].y;
|
||||
|
||||
if (strength) {
|
||||
strength[i] = tp->data.coords[i].strength;
|
||||
}
|
||||
}
|
||||
/* Invalidate */
|
||||
tp->data.points = 0;
|
||||
portEXIT_CRITICAL(&tp->data.lock);
|
||||
|
||||
return (*point_num > 0);
|
||||
}
|
||||
|
||||
static esp_err_t touch_axs15231b_del(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
/* Reset GPIO pin settings */
|
||||
if (tp->config.int_gpio_num != GPIO_NUM_NC) {
|
||||
gpio_reset_pin(tp->config.int_gpio_num);
|
||||
}
|
||||
if (tp->config.rst_gpio_num != GPIO_NUM_NC) {
|
||||
gpio_reset_pin(tp->config.rst_gpio_num);
|
||||
}
|
||||
/* Release memory */
|
||||
free(tp);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t touch_axs15231b_reset(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
if (tp->config.rst_gpio_num != GPIO_NUM_NC) {
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, tp->config.levels.reset), TAG, "GPIO set level failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
ESP_RETURN_ON_ERROR(gpio_set_level(tp->config.rst_gpio_num, !tp->config.levels.reset), TAG, "GPIO set level failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t i2c_read_bytes(esp_lcd_touch_handle_t tp, int reg, uint8_t *data, uint8_t len)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(data, ESP_ERR_INVALID_ARG, TAG, "Invalid data");
|
||||
|
||||
return esp_lcd_panel_io_rx_param(tp->io, reg, data, len);
|
||||
}
|
||||
|
||||
static esp_err_t i2c_write_bytes(esp_lcd_touch_handle_t tp, int reg, const uint8_t *data, uint8_t len)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(data, ESP_ERR_INVALID_ARG, TAG, "Invalid data");
|
||||
|
||||
return esp_lcd_panel_io_tx_param(tp->io, reg, data, len);
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
* @brief ESP LCD & Touch: AXS15231B
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/spi_ll.h"
|
||||
#include "../touch/esp_lcd_touch.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief LCD panel initialization commands.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
int cmd; /*<! The specific LCD command */
|
||||
const void *data; /*<! Buffer that holds the command specific data */
|
||||
size_t data_bytes; /*<! Size of `data` in memory, in bytes */
|
||||
unsigned int delay_ms; /*<! Delay in milliseconds after this command */
|
||||
} axs15231b_lcd_init_cmd_t;
|
||||
|
||||
/**
|
||||
* @brief LCD panel vendor configuration.
|
||||
*
|
||||
* @note This structure needs to be passed to the `vendor_config` field in `esp_lcd_panel_dev_config_t`.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
const axs15231b_lcd_init_cmd_t *init_cmds; /*!< Pointer to initialization commands array. Set to NULL if using default commands.
|
||||
* The array should be declared as `static const` and positioned outside the function.
|
||||
* Please refer to `vendor_specific_init_default` in source file.
|
||||
*/
|
||||
uint16_t init_cmds_size; /*<! Number of commands in above array */
|
||||
struct {
|
||||
unsigned int use_qspi_interface: 1; /*<! Set to 1 if use QSPI interface, default is SPI interface */
|
||||
} flags;
|
||||
} axs15231b_vendor_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create LCD panel for model AXS15231B
|
||||
*
|
||||
* @note Vendor specific initialization can be different between manufacturers, should consult the LCD supplier for initialization sequence code.
|
||||
*
|
||||
* @param[in] io LCD panel IO handle
|
||||
* @param[in] panel_dev_config general panel device configuration
|
||||
* @param[out] ret_panel Returned LCD panel handle
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
||||
* - ESP_ERR_NO_MEM if out of memory
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_new_panel_axs15231b(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel);
|
||||
|
||||
/**
|
||||
* @brief LCD panel bus configuration structure
|
||||
*
|
||||
*/
|
||||
#define AXS15231B_PANEL_BUS_I80_CONFIG(dc, wr, clk, d0, d1, d2, d3, d4, d5, d6, d7, b_w, max_trans_sz) \
|
||||
{ \
|
||||
.dc_gpio_num = dc, \
|
||||
.wr_gpio_num = wr, \
|
||||
.clk_src = clk, \
|
||||
.data_gpio_nums = { \
|
||||
d0, \
|
||||
d1, \
|
||||
d2, \
|
||||
d3, \
|
||||
d4, \
|
||||
d5, \
|
||||
d6, \
|
||||
d7, \
|
||||
}, \
|
||||
.bus_width = b_w, \
|
||||
.max_transfer_bytes = max_trans_sz, \
|
||||
}
|
||||
|
||||
#define AXS15231B_PANEL_BUS_SPI_CONFIG(sclk, mosi, max_trans_sz) \
|
||||
{ \
|
||||
.sclk_io_num = sclk, \
|
||||
.mosi_io_num = mosi, \
|
||||
.miso_io_num = -1, \
|
||||
.quadhd_io_num = -1, \
|
||||
.quadwp_io_num = -1, \
|
||||
.max_transfer_sz = max_trans_sz, \
|
||||
}
|
||||
#define AXS15231B_PANEL_BUS_QSPI_CONFIG(sclk, d0, d1, d2, d3, max_trans_sz) \
|
||||
{ \
|
||||
.sclk_io_num = sclk, \
|
||||
.data0_io_num = d0, \
|
||||
.data1_io_num = d1, \
|
||||
.data2_io_num = d2, \
|
||||
.data3_io_num = d3, \
|
||||
.max_transfer_sz = max_trans_sz, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD panel IO configuration structure
|
||||
*
|
||||
*/
|
||||
#define AXS15231B_PANEL_IO_I80_CONFIG(cs, dc, cb, cb_ctx) \
|
||||
{ \
|
||||
.cs_gpio_num = cs, \
|
||||
.pclk_hz = 20 * 1000 * 1000, \
|
||||
.on_color_trans_done = cb, \
|
||||
.trans_queue_depth = 10, \
|
||||
.user_ctx = cb_ctx, \
|
||||
.dc_levels = { \
|
||||
.dc_idle_level = 0, \
|
||||
.dc_cmd_level = 0, \
|
||||
.dc_dummy_level = 0, \
|
||||
.dc_data_level = 1, \
|
||||
}, \
|
||||
.lcd_cmd_bits = 8, \
|
||||
.lcd_param_bits = 8, \
|
||||
}
|
||||
|
||||
#define AXS15231B_PANEL_IO_SPI_CONFIG(cs, dc, cb, cb_ctx) \
|
||||
{ \
|
||||
.cs_gpio_num = cs, \
|
||||
.dc_gpio_num = dc, \
|
||||
.spi_mode = 3, \
|
||||
.pclk_hz = 40 * 1000 * 1000, \
|
||||
.trans_queue_depth = 10, \
|
||||
.on_color_trans_done = cb, \
|
||||
.user_ctx = cb_ctx, \
|
||||
.lcd_cmd_bits = 8, \
|
||||
.lcd_param_bits = 8, \
|
||||
}
|
||||
|
||||
#define AXS15231B_PANEL_IO_QSPI_CONFIG(cs, cb, cb_ctx) \
|
||||
{ \
|
||||
.cs_gpio_num = cs, \
|
||||
.dc_gpio_num = -1, \
|
||||
.spi_mode = 3, \
|
||||
.pclk_hz = 40 * 1000 * 1000, \
|
||||
.trans_queue_depth = 10, \
|
||||
.on_color_trans_done = cb, \
|
||||
.user_ctx = cb_ctx, \
|
||||
.lcd_cmd_bits = 32, \
|
||||
.lcd_param_bits = 8, \
|
||||
.flags = { \
|
||||
.quad_mode = true, \
|
||||
}, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a new AXS15231B1B touch driver
|
||||
*
|
||||
* @note The I2C communication should be initialized before use this function.
|
||||
*
|
||||
* @param io LCD panel IO handle, it should be created by `esp_lcd_new_panel_io_i2c()`
|
||||
* @param config Touch panel configuration
|
||||
* @param tp Touch panel handle
|
||||
* @return
|
||||
* - ESP_OK: on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_new_i2c_axs15231b(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *tp);
|
||||
|
||||
/**
|
||||
* @brief I2C address of the AXS15231B controller
|
||||
*
|
||||
*/
|
||||
#define ESP_LCD_TOUCH_IO_I2C_AXS15231B_ADDRESS (0x3B)
|
||||
|
||||
/**
|
||||
* @brief Touch IO configuration structure
|
||||
*
|
||||
*/
|
||||
|
||||
#define ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG() \
|
||||
{ \
|
||||
.dev_addr = ESP_LCD_TOUCH_IO_I2C_AXS15231B_ADDRESS, \
|
||||
.control_phase_bytes = 1, \
|
||||
.dc_bit_offset = 0, \
|
||||
.lcd_cmd_bits = 8, \
|
||||
.flags = \
|
||||
{ \
|
||||
.disable_control_phase = 1, \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG_EX(scl_speed_hz) \
|
||||
{ \
|
||||
.dev_addr = ESP_LCD_TOUCH_IO_I2C_AXS15231B_ADDRESS, \
|
||||
.control_phase_bytes = 1, \
|
||||
.dc_bit_offset = 0, \
|
||||
.lcd_cmd_bits = 8, \
|
||||
.flags = \
|
||||
{ \
|
||||
.disable_control_phase = 1, \
|
||||
}, \
|
||||
.scl_speed_hz = scl_speed_hz, \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "c64_ui.h"
|
||||
#include <lvgl.h>
|
||||
#define C64_BLUE lv_color_make(64,49,141)
|
||||
#define C64_LIGHT_BLUE lv_color_make(120,105,196)
|
||||
static void cursor_blink(void*o,int32_t v){lv_obj_set_style_opa((lv_obj_t*)o,v?LV_OPA_COVER:LV_OPA_TRANSP,LV_PART_MAIN);}
|
||||
void c64_ui_create(void){lv_obj_t*s=lv_scr_act();lv_obj_set_style_bg_color(s,C64_BLUE,LV_PART_MAIN);lv_obj_set_style_bg_opa(s,LV_OPA_COVER,LV_PART_MAIN);lv_obj_clear_flag(s,LV_OBJ_FLAG_SCROLLABLE);lv_obj_t*r=lv_label_create(s);lv_label_set_text(r,"READY.");lv_obj_set_style_text_color(r,C64_LIGHT_BLUE,LV_PART_MAIN);lv_obj_set_style_text_font(r,&lv_font_montserrat_48,LV_PART_MAIN);lv_obj_align(r,LV_ALIGN_TOP_LEFT,12,44);lv_obj_t*c=lv_obj_create(s);lv_obj_remove_style_all(c);lv_obj_set_size(c,29,8);lv_obj_set_style_bg_color(c,C64_LIGHT_BLUE,LV_PART_MAIN);lv_obj_set_style_bg_opa(c,LV_OPA_COVER,LV_PART_MAIN);lv_obj_align_to(c,r,LV_ALIGN_OUT_BOTTOM_LEFT,0,10);lv_anim_t a;lv_anim_init(&a);lv_anim_set_var(&a,c);lv_anim_set_values(&a,1,0);lv_anim_set_time(&a,500);lv_anim_set_playback_time(&a,500);lv_anim_set_repeat_count(&a,LV_ANIM_REPEAT_INFINITE);lv_anim_set_exec_cb(&a,cursor_blink);lv_anim_start(&a);}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void c64_ui_create(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
#include <stdio.h>
|
||||
#include "i2c_bsp.h"
|
||||
#include "user_config.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
static i2c_master_bus_handle_t user_i2c_port0_handle = NULL;
|
||||
static i2c_master_bus_handle_t user_i2c_port1_handle = NULL;
|
||||
i2c_master_dev_handle_t disp_touch_dev_handle = NULL;
|
||||
i2c_master_dev_handle_t rtc_dev_handle = NULL;
|
||||
i2c_master_dev_handle_t imu_dev_handle = NULL;
|
||||
|
||||
|
||||
static uint32_t i2c_data_pdMS_TICKS = 0;
|
||||
static uint32_t i2c_done_pdMS_TICKS = 0;
|
||||
|
||||
|
||||
void i2c_master_Init(void)
|
||||
{
|
||||
i2c_data_pdMS_TICKS = pdMS_TO_TICKS(5000);
|
||||
i2c_done_pdMS_TICKS = pdMS_TO_TICKS(1000);
|
||||
/*i2c_port 0 init*/
|
||||
i2c_master_bus_config_t i2c_bus_config =
|
||||
{
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.i2c_port = I2C_NUM_0,
|
||||
.scl_io_num = ESP_SCL_NUM,
|
||||
.sda_io_num = ESP_SDA_NUM,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.flags = {
|
||||
.enable_internal_pullup = true,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &user_i2c_port0_handle));
|
||||
i2c_bus_config.scl_io_num = Touch_SCL_NUM;
|
||||
i2c_bus_config.sda_io_num = Touch_SDA_NUM;
|
||||
i2c_bus_config.i2c_port = I2C_NUM_1;
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &user_i2c_port1_handle));
|
||||
|
||||
i2c_device_config_t dev_cfg =
|
||||
{
|
||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||
.scl_speed_hz = 300000,
|
||||
};
|
||||
dev_cfg.device_address = EXAMPLE_RTC_ADDR;
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(user_i2c_port0_handle, &dev_cfg, &rtc_dev_handle));
|
||||
|
||||
dev_cfg.device_address = EXAMPLE_IMU_ADDR;
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(user_i2c_port0_handle, &dev_cfg, &imu_dev_handle));
|
||||
|
||||
dev_cfg.device_address = I2C_TOUCH_ADDR;
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(user_i2c_port1_handle, &dev_cfg, &disp_touch_dev_handle));
|
||||
|
||||
}
|
||||
|
||||
uint8_t i2c_write_buff(i2c_master_dev_handle_t dev_handle,int reg,uint8_t *buf,uint8_t len)
|
||||
{
|
||||
uint8_t ret;
|
||||
uint8_t *pbuf = NULL;
|
||||
ret = i2c_master_bus_wait_all_done(user_i2c_port0_handle,i2c_done_pdMS_TICKS);
|
||||
if(ret != ESP_OK)
|
||||
return ret;
|
||||
if(reg == -1)
|
||||
{
|
||||
ret = i2c_master_transmit(dev_handle,buf,len,i2c_data_pdMS_TICKS);
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf = (uint8_t*)malloc(len+1);
|
||||
pbuf[0] = reg;
|
||||
for(uint8_t i = 0; i<len; i++)
|
||||
{
|
||||
pbuf[i+1] = buf[i];
|
||||
}
|
||||
ret = i2c_master_transmit(dev_handle,pbuf,len+1,i2c_data_pdMS_TICKS);
|
||||
free(pbuf);
|
||||
pbuf = NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
uint8_t i2c_master_write_read_dev(i2c_master_dev_handle_t dev_handle,uint8_t *writeBuf,uint8_t writeLen,uint8_t *readBuf,uint8_t readLen)
|
||||
{
|
||||
uint8_t ret;
|
||||
ret = i2c_master_bus_wait_all_done(user_i2c_port0_handle,i2c_done_pdMS_TICKS);
|
||||
if(ret != ESP_OK)
|
||||
return ret;
|
||||
ret = i2c_master_transmit_receive(dev_handle,writeBuf,writeLen,readBuf,readLen,i2c_data_pdMS_TICKS);
|
||||
return ret;
|
||||
}
|
||||
uint8_t i2c_read_buff(i2c_master_dev_handle_t dev_handle,int reg,uint8_t *buf,uint8_t len)
|
||||
{
|
||||
uint8_t ret;
|
||||
uint8_t addr = 0;
|
||||
ret = i2c_master_bus_wait_all_done(user_i2c_port0_handle,i2c_done_pdMS_TICKS);
|
||||
if(ret != ESP_OK)
|
||||
return ret;
|
||||
if( reg == -1 )
|
||||
{ret = i2c_master_receive(dev_handle, buf,len, i2c_data_pdMS_TICKS);}
|
||||
else
|
||||
{addr = (uint8_t)reg; ret = i2c_master_transmit_receive(dev_handle,&addr,1,buf,len,i2c_data_pdMS_TICKS);}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint8_t i2c_master_touch_write_read(i2c_master_dev_handle_t dev_handle,uint8_t *writeBuf,uint8_t writeLen,uint8_t *readBuf,uint8_t readLen)
|
||||
{
|
||||
uint8_t ret;
|
||||
ret = i2c_master_bus_wait_all_done(user_i2c_port1_handle,i2c_done_pdMS_TICKS);
|
||||
if(ret != ESP_OK)
|
||||
return ret;
|
||||
ret = i2c_master_transmit_receive(dev_handle,writeBuf,writeLen,readBuf,readLen,i2c_data_pdMS_TICKS);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef I2C_BSP_H
|
||||
#define I2C_BSP_H
|
||||
#include "driver/i2c_master.h"
|
||||
|
||||
extern i2c_master_dev_handle_t disp_touch_dev_handle;
|
||||
extern i2c_master_dev_handle_t rtc_dev_handle;
|
||||
extern i2c_master_dev_handle_t imu_dev_handle;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void i2c_master_Init(void);
|
||||
uint8_t i2c_write_buff(i2c_master_dev_handle_t dev_handle,int reg,uint8_t *buf,uint8_t len);
|
||||
uint8_t i2c_master_write_read_dev(i2c_master_dev_handle_t dev_handle,uint8_t *writeBuf,uint8_t writeLen,uint8_t *readBuf,uint8_t readLen);
|
||||
uint8_t i2c_read_buff(i2c_master_dev_handle_t dev_handle,int reg,uint8_t *buf,uint8_t len);
|
||||
uint8_t i2c_master_touch_write_read(i2c_master_dev_handle_t dev_handle,uint8_t *writeBuf,uint8_t writeLen,uint8_t *readBuf,uint8_t readLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include "lcd_bl_pwm_bsp.h"
|
||||
#include "esp_err.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "user_config.h"
|
||||
|
||||
void gpio_init(void)
|
||||
{
|
||||
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<<EXAMPLE_PIN_NUM_BK_LIGHT);
|
||||
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));
|
||||
}
|
||||
void lcd_bl_pwm_bsp_init(uint16_t duty)
|
||||
{
|
||||
ledc_timer_config_t timer_conf =
|
||||
{
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.duty_resolution = LEDC_TIMER_8_BIT, //256
|
||||
.timer_num = LEDC_TIMER_3,
|
||||
.freq_hz = 50 * 1000,
|
||||
.clk_cfg = LEDC_SLOW_CLK_RC_FAST,
|
||||
};
|
||||
ledc_channel_config_t ledc_conf =
|
||||
{
|
||||
.gpio_num = EXAMPLE_PIN_NUM_BK_LIGHT,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.channel = LEDC_CHANNEL_1,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = LEDC_TIMER_3,
|
||||
.duty = duty, //占空比
|
||||
.hpoint = 0, //相位
|
||||
};
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(ledc_timer_config(&timer_conf));
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(ledc_channel_config(&ledc_conf));
|
||||
}
|
||||
|
||||
void setUpduty(uint16_t duty)
|
||||
{
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, duty));
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1));
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef LCD_BL_PWM_BSP_H
|
||||
#define LCD_BL_PWM_BSP_H
|
||||
|
||||
|
||||
|
||||
#define LCD_PWM_MODE_0 (0xff-0)
|
||||
#define LCD_PWM_MODE_25 (0xff-25)
|
||||
#define LCD_PWM_MODE_50 (0xff-50)
|
||||
#define LCD_PWM_MODE_75 (0xff-75)
|
||||
#define LCD_PWM_MODE_100 (0xff-100)
|
||||
#define LCD_PWM_MODE_125 (0xff-125)
|
||||
#define LCD_PWM_MODE_150 (0xff-150)
|
||||
#define LCD_PWM_MODE_175 (0xff-175)
|
||||
#define LCD_PWM_MODE_200 (0xff-200)
|
||||
#define LCD_PWM_MODE_225 (0xff-225)
|
||||
#define LCD_PWM_MODE_255 (0xff-255)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void lcd_bl_pwm_bsp_init(uint16_t duty);
|
||||
void setUpduty(uint16_t duty);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "lvgl_port.h"
|
||||
#include "c64_ui.h"
|
||||
#include "lvgl.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_timer.h"
|
||||
#include "user_config.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "esp_lcd_io_spi.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "axs15231b/esp_lcd_axs15231b.h"
|
||||
#include "demos/lv_demos.h"
|
||||
#include "i2c_bsp.h"
|
||||
|
||||
#define LCD_BIT_PER_PIXEL (16)
|
||||
|
||||
static const char *TAG = "lvgl_port";
|
||||
static SemaphoreHandle_t lvgl_mux = NULL;
|
||||
|
||||
static uint16_t *lvgl_dma_buf = NULL;
|
||||
static SemaphoreHandle_t lvgl_flush_semap;
|
||||
|
||||
#if (Rotated == USER_DISP_ROT_90)
|
||||
uint16_t* rotat_ptr = NULL;
|
||||
#endif
|
||||
|
||||
static const axs15231b_lcd_init_cmd_t lcd_init_cmds[] =
|
||||
{
|
||||
{0x11, (uint8_t []){0x00}, 0, 100},
|
||||
{0x29, (uint8_t []){0x00}, 0, 100},
|
||||
};
|
||||
|
||||
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
|
||||
{
|
||||
BaseType_t TaskWoken;
|
||||
xSemaphoreGiveFromISR(lvgl_flush_semap,&TaskWoken);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void example_increase_lvgl_tick(void *arg)
|
||||
{
|
||||
lv_tick_inc(EXAMPLE_LVGL_TICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
|
||||
{
|
||||
#if (Rotated == USER_DISP_ROT_90)
|
||||
uint32_t index = 0;
|
||||
uint16_t *data_ptr = (uint16_t *)color_map;
|
||||
for (uint16_t j = 0; j < EXAMPLE_LCD_H_RES; j++)
|
||||
{
|
||||
for (uint16_t i = 0; i < EXAMPLE_LCD_V_RES; i++)
|
||||
{
|
||||
rotat_ptr[index++] = data_ptr[EXAMPLE_LCD_H_RES * (EXAMPLE_LCD_V_RES - i - 1) + j];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t) drv->user_data;
|
||||
const int flush_coun = (LVGL_SPIRAM_BUFF_LEN / LVGL_DMA_BUFF_LEN);
|
||||
const int offgap = (LCD_NOROT_VRES / flush_coun);
|
||||
const int dmalen = (LVGL_DMA_BUFF_LEN / 2);
|
||||
int offsetx1 = 0;
|
||||
int offsety1 = 0;
|
||||
int offsetx2 = LCD_NOROT_HRES;
|
||||
int offsety2 = offgap;
|
||||
|
||||
#if (Rotated == USER_DISP_ROT_90)
|
||||
uint16_t *map = (uint16_t *)rotat_ptr;
|
||||
#else
|
||||
uint16_t *map = (uint16_t *)color_map;
|
||||
#endif
|
||||
|
||||
xSemaphoreGive(lvgl_flush_semap);
|
||||
for(int i = 0; i<flush_coun; i++)
|
||||
{
|
||||
xSemaphoreTake(lvgl_flush_semap,portMAX_DELAY);
|
||||
memcpy(lvgl_dma_buf,map,LVGL_DMA_BUFF_LEN);
|
||||
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2, offsety2, lvgl_dma_buf);
|
||||
offsety1 += offgap;
|
||||
offsety2 += offgap;
|
||||
map += dmalen;
|
||||
}
|
||||
xSemaphoreTake(lvgl_flush_semap,portMAX_DELAY);
|
||||
lv_disp_flush_ready(drv);
|
||||
}
|
||||
|
||||
static void example_lvgl_touch_cb(lv_indev_drv_t *drv, lv_indev_data_t *data)
|
||||
{
|
||||
//static uint8_t read_touchpad_cmd[8] = {0xb5, 0xab, 0xa5, 0x5a, 0x0, 0x0, 0x0, 0x8};
|
||||
uint8_t read_touchpad_cmd[11] = {0xb5, 0xab, 0xa5, 0x5a, 0x0, 0x0, 0x0, 0x0e,0x0, 0x0, 0x0};
|
||||
uint8_t buff[32] = {0};
|
||||
memset(buff,0,32);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(i2c_master_write_read_dev(disp_touch_dev_handle,read_touchpad_cmd,11,buff,32));
|
||||
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];
|
||||
//ESP_LOGI("Touch","%d,%d",buff[0],buff[1]);
|
||||
if (buff[1]>0 && buff[1]<5)
|
||||
{
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
#if (Rotated == USER_DISP_ROT_NONO)
|
||||
if(pointX > EXAMPLE_LCD_V_RES) pointX = EXAMPLE_LCD_V_RES;
|
||||
if(pointY > EXAMPLE_LCD_H_RES) pointY = EXAMPLE_LCD_H_RES;
|
||||
data->point.x = pointY;
|
||||
data->point.y = (EXAMPLE_LCD_V_RES-pointX);
|
||||
#else
|
||||
if(pointX > EXAMPLE_LCD_H_RES) pointX = EXAMPLE_LCD_H_RES;
|
||||
if(pointY > EXAMPLE_LCD_V_RES) pointY = EXAMPLE_LCD_V_RES;
|
||||
data->point.x = (EXAMPLE_LCD_H_RES - pointX);
|
||||
data->point.y = (EXAMPLE_LCD_V_RES - pointY);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool example_lvgl_lock(int timeout_ms)
|
||||
{
|
||||
const TickType_t timeout_ticks = (timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
|
||||
return xSemaphoreTake(lvgl_mux, timeout_ticks) == pdTRUE;
|
||||
}
|
||||
|
||||
static void example_lvgl_unlock(void)
|
||||
{
|
||||
assert(lvgl_mux && "bsp_display_start must be called first");
|
||||
xSemaphoreGive(lvgl_mux);
|
||||
}
|
||||
|
||||
void example_lvgl_port_task(void *arg)
|
||||
{
|
||||
uint32_t task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS;
|
||||
for(;;)
|
||||
{
|
||||
if (example_lvgl_lock(-1))
|
||||
{
|
||||
task_delay_ms = lv_timer_handler();
|
||||
//Release the mutex
|
||||
example_lvgl_unlock();
|
||||
}
|
||||
if (task_delay_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS)
|
||||
{
|
||||
task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS;
|
||||
} else if (task_delay_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS)
|
||||
{
|
||||
task_delay_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
|
||||
}
|
||||
}
|
||||
|
||||
void lvgl_port_init(void)
|
||||
{
|
||||
#if (Rotated == USER_DISP_ROT_90)
|
||||
rotat_ptr = (uint16_t*)heap_caps_malloc(EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES * sizeof(uint16_t), MALLOC_CAP_SPIRAM);
|
||||
assert(rotat_ptr);
|
||||
#endif
|
||||
lvgl_flush_semap = xSemaphoreCreateBinary();
|
||||
|
||||
static lv_disp_draw_buf_t disp_buf; // contains internal graphic buffer(s) called draw buffer(s)
|
||||
static lv_disp_drv_t disp_drv; // contains callback functions
|
||||
ESP_LOGI(TAG, "Initialize LCD RESET GPIO");
|
||||
|
||||
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<<EXAMPLE_PIN_NUM_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));
|
||||
|
||||
ESP_LOGI(TAG, "Initialize QSPI bus");
|
||||
spi_bus_config_t buscfg = {};
|
||||
buscfg.data0_io_num = EXAMPLE_PIN_NUM_LCD_DATA0;
|
||||
buscfg.data1_io_num = EXAMPLE_PIN_NUM_LCD_DATA1;
|
||||
buscfg.sclk_io_num = EXAMPLE_PIN_NUM_LCD_PCLK;
|
||||
buscfg.data2_io_num = EXAMPLE_PIN_NUM_LCD_DATA2;
|
||||
buscfg.data3_io_num = EXAMPLE_PIN_NUM_LCD_DATA3;
|
||||
buscfg.max_transfer_sz = LVGL_DMA_BUFF_LEN;
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t panel_io = NULL;
|
||||
esp_lcd_panel_handle_t panel = NULL;
|
||||
|
||||
esp_lcd_panel_io_spi_config_t io_config = {};
|
||||
io_config.cs_gpio_num = EXAMPLE_PIN_NUM_LCD_CS;
|
||||
io_config.dc_gpio_num = -1;
|
||||
io_config.spi_mode = 3;
|
||||
io_config.pclk_hz = 40 * 1000 * 1000;
|
||||
io_config.trans_queue_depth = 10;
|
||||
io_config.on_color_trans_done = example_notify_lvgl_flush_ready;
|
||||
//io_config.user_ctx = &disp_drv,
|
||||
io_config.lcd_cmd_bits = 32;
|
||||
io_config.lcd_param_bits = 8;
|
||||
io_config.flags.quad_mode = true;
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(LCD_HOST, &io_config, &panel_io));
|
||||
|
||||
axs15231b_vendor_config_t vendor_config = {};
|
||||
vendor_config.flags.use_qspi_interface = 1;
|
||||
vendor_config.init_cmds = lcd_init_cmds;
|
||||
vendor_config.init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]);
|
||||
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = -1;
|
||||
panel_config.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB;
|
||||
panel_config.bits_per_pixel = LCD_BIT_PER_PIXEL;
|
||||
panel_config.vendor_config = &vendor_config;
|
||||
|
||||
ESP_LOGI(TAG, "Install panel driver");
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_axs15231b(panel_io, &panel_config, &panel));
|
||||
|
||||
ESP_ERROR_CHECK(gpio_set_level(EXAMPLE_PIN_NUM_LCD_RST,1));
|
||||
vTaskDelay(pdMS_TO_TICKS(30));
|
||||
ESP_ERROR_CHECK(gpio_set_level(EXAMPLE_PIN_NUM_LCD_RST,0));
|
||||
vTaskDelay(pdMS_TO_TICKS(250));
|
||||
ESP_ERROR_CHECK(gpio_set_level(EXAMPLE_PIN_NUM_LCD_RST,1));
|
||||
vTaskDelay(pdMS_TO_TICKS(30));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(panel));
|
||||
|
||||
lv_init();
|
||||
|
||||
lvgl_dma_buf = (uint16_t *)heap_caps_malloc(LVGL_DMA_BUFF_LEN , MALLOC_CAP_DMA);
|
||||
assert(lvgl_dma_buf);
|
||||
lv_color_t *buffer_1 = (lv_color_t *)heap_caps_malloc(LVGL_SPIRAM_BUFF_LEN , MALLOC_CAP_SPIRAM);
|
||||
lv_color_t *buffer_2 = (lv_color_t *)heap_caps_malloc(LVGL_SPIRAM_BUFF_LEN , MALLOC_CAP_SPIRAM);
|
||||
assert(buffer_1);
|
||||
assert(buffer_2);
|
||||
lv_disp_draw_buf_init(&disp_buf, buffer_1, buffer_2, EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES);
|
||||
|
||||
ESP_LOGI(TAG, "Register display driver to LVGL");
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
disp_drv.hor_res = EXAMPLE_LCD_H_RES;
|
||||
disp_drv.ver_res = EXAMPLE_LCD_V_RES;
|
||||
disp_drv.flush_cb = example_lvgl_flush_cb;
|
||||
disp_drv.draw_buf = &disp_buf;
|
||||
disp_drv.full_refresh = 1; //full_refresh must be 1
|
||||
disp_drv.user_data = panel;
|
||||
lv_disp_drv_register(&disp_drv);
|
||||
|
||||
ESP_LOGI(TAG, "Install LVGL tick timer");
|
||||
esp_timer_create_args_t lvgl_tick_timer_args = {};
|
||||
lvgl_tick_timer_args.callback = &example_increase_lvgl_tick;
|
||||
lvgl_tick_timer_args.name = "lvgl_tick";
|
||||
esp_timer_handle_t lvgl_tick_timer = NULL;
|
||||
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
|
||||
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer,EXAMPLE_LVGL_TICK_PERIOD_MS * 1000));
|
||||
|
||||
static lv_indev_drv_t indev_drv; // Input device driver (Touch)
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = example_lvgl_touch_cb;
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
|
||||
lvgl_mux = xSemaphoreCreateMutex();
|
||||
assert(lvgl_mux);
|
||||
xTaskCreatePinnedToCore(example_lvgl_port_task, "LVGL", 4000, NULL, 4, NULL,0); //运行于内核_0
|
||||
if (example_lvgl_lock(-1))
|
||||
{
|
||||
c64_ui_create();
|
||||
example_lvgl_unlock();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef LVGL_PORT_H
|
||||
#define LVGL_PORT_H
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
void lvgl_port_init(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#include <Arduino.h>
|
||||
#include "i2c_bsp.h"
|
||||
#include "lvgl_port.h"
|
||||
#include "lcd_bl_bsp/lcd_bl_pwm_bsp.h"
|
||||
void setup(){Serial.begin(115200);i2c_master_Init();lvgl_port_init();lcd_bl_pwm_bsp_init(LCD_PWM_MODE_255);Serial.println("READY.");}
|
||||
void loop(){delay(1000);}
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_lcd_touch.h"
|
||||
|
||||
static const char *TAG = "TP";
|
||||
|
||||
/*******************************************************************************
|
||||
* Function definitions
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variables
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Public API functions
|
||||
*******************************************************************************/
|
||||
|
||||
esp_err_t esp_lcd_touch_enter_sleep(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
if (tp->enter_sleep == NULL) {
|
||||
ESP_LOGE(TAG, "Sleep mode not supported!");
|
||||
return ESP_FAIL;
|
||||
} else {
|
||||
return tp->enter_sleep(tp);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_exit_sleep(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
if (tp->exit_sleep == NULL) {
|
||||
ESP_LOGE(TAG, "Sleep mode not supported!");
|
||||
return ESP_FAIL;
|
||||
} else {
|
||||
return tp->exit_sleep(tp);
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_read_data(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(tp->read_data != NULL);
|
||||
|
||||
return tp->read_data(tp);
|
||||
}
|
||||
|
||||
bool esp_lcd_touch_get_coordinates(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num)
|
||||
{
|
||||
bool touched = false;
|
||||
|
||||
assert(tp != NULL);
|
||||
assert(x != NULL);
|
||||
assert(y != NULL);
|
||||
assert(tp->get_xy != NULL);
|
||||
|
||||
touched = tp->get_xy(tp, x, y, strength, point_num, max_point_num);
|
||||
if (!touched) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Process coordinates by user */
|
||||
if (tp->config.process_coordinates != NULL) {
|
||||
tp->config.process_coordinates(tp, x, y, strength, point_num, max_point_num);
|
||||
}
|
||||
|
||||
/* Software coordinates adjustment needed */
|
||||
bool sw_adj_needed = ((tp->config.flags.mirror_x && (tp->set_mirror_x == NULL)) ||
|
||||
(tp->config.flags.mirror_y && (tp->set_mirror_y == NULL)) ||
|
||||
(tp->config.flags.swap_xy && (tp->set_swap_xy == NULL)));
|
||||
|
||||
/* Adjust all coordinates */
|
||||
for (int i = 0; (sw_adj_needed && i < *point_num); i++) {
|
||||
|
||||
/* Mirror X coordinates (if not supported by HW) */
|
||||
if (tp->config.flags.mirror_x && tp->set_mirror_x == NULL) {
|
||||
x[i] = tp->config.x_max - x[i];
|
||||
}
|
||||
|
||||
/* Mirror Y coordinates (if not supported by HW) */
|
||||
if (tp->config.flags.mirror_y && tp->set_mirror_y == NULL) {
|
||||
y[i] = tp->config.y_max - y[i];
|
||||
}
|
||||
|
||||
/* Swap X and Y coordinates (if not supported by HW) */
|
||||
if (tp->config.flags.swap_xy && tp->set_swap_xy == NULL) {
|
||||
uint16_t tmp = x[i];
|
||||
x[i] = y[i];
|
||||
y[i] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return touched;
|
||||
}
|
||||
|
||||
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
|
||||
esp_err_t esp_lcd_touch_get_button_state(esp_lcd_touch_handle_t tp, uint8_t n, uint8_t *state)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(state != NULL);
|
||||
|
||||
*state = 0;
|
||||
|
||||
if (tp->get_button_state) {
|
||||
return tp->get_button_state(tp, n, state);
|
||||
} else {
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
esp_err_t esp_lcd_touch_set_swap_xy(esp_lcd_touch_handle_t tp, bool swap)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
tp->config.flags.swap_xy = swap;
|
||||
|
||||
/* Is swap supported by HW? */
|
||||
if (tp->set_swap_xy) {
|
||||
return tp->set_swap_xy(tp, swap);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_get_swap_xy(esp_lcd_touch_handle_t tp, bool *swap)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(swap != NULL);
|
||||
|
||||
/* Is swap supported by HW? */
|
||||
if (tp->get_swap_xy) {
|
||||
return tp->get_swap_xy(tp, swap);
|
||||
} else {
|
||||
*swap = tp->config.flags.swap_xy;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_set_mirror_x(esp_lcd_touch_handle_t tp, bool mirror)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
tp->config.flags.mirror_x = mirror;
|
||||
|
||||
/* Is mirror supported by HW? */
|
||||
if (tp->set_mirror_x) {
|
||||
return tp->set_mirror_x(tp, mirror);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_get_mirror_x(esp_lcd_touch_handle_t tp, bool *mirror)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(mirror != NULL);
|
||||
|
||||
/* Is swap supported by HW? */
|
||||
if (tp->get_mirror_x) {
|
||||
return tp->get_mirror_x(tp, mirror);
|
||||
} else {
|
||||
*mirror = tp->config.flags.mirror_x;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_set_mirror_y(esp_lcd_touch_handle_t tp, bool mirror)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
tp->config.flags.mirror_y = mirror;
|
||||
|
||||
/* Is mirror supported by HW? */
|
||||
if (tp->set_mirror_y) {
|
||||
return tp->set_mirror_y(tp, mirror);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_get_mirror_y(esp_lcd_touch_handle_t tp, bool *mirror)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
assert(mirror != NULL);
|
||||
|
||||
/* Is swap supported by HW? */
|
||||
if (tp->get_mirror_y) {
|
||||
return tp->get_mirror_y(tp, mirror);
|
||||
} else {
|
||||
*mirror = tp->config.flags.mirror_y;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_del(esp_lcd_touch_handle_t tp)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
if (tp->del != NULL) {
|
||||
return tp->del(tp);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_register_interrupt_callback(esp_lcd_touch_handle_t tp, esp_lcd_touch_interrupt_callback_t callback)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
assert(tp != NULL);
|
||||
|
||||
/* Interrupt pin is not selected */
|
||||
if (tp->config.int_gpio_num == GPIO_NUM_NC) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
tp->config.interrupt_callback = callback;
|
||||
|
||||
if (callback != NULL) {
|
||||
ret = gpio_install_isr_service(0);
|
||||
/* ISR service can be installed from user before, then it returns invalid state */
|
||||
if (ret != ESP_OK && ret != ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGE(TAG, "GPIO ISR install failed");
|
||||
return ret;
|
||||
}
|
||||
/* Add GPIO ISR handler */
|
||||
ret = gpio_intr_enable(tp->config.int_gpio_num);
|
||||
ESP_RETURN_ON_ERROR(ret, TAG, "GPIO ISR install failed");
|
||||
ret = gpio_isr_handler_add(tp->config.int_gpio_num, (gpio_isr_t)tp->config.interrupt_callback, tp);
|
||||
ESP_RETURN_ON_ERROR(ret, TAG, "GPIO ISR install failed");
|
||||
} else {
|
||||
/* Remove GPIO ISR handler */
|
||||
ret = gpio_isr_handler_remove(tp->config.int_gpio_num);
|
||||
ESP_RETURN_ON_ERROR(ret, TAG, "GPIO ISR remove handler failed");
|
||||
ret = gpio_intr_disable(tp->config.int_gpio_num);
|
||||
ESP_RETURN_ON_ERROR(ret, TAG, "GPIO ISR disable failed");
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_lcd_touch_register_interrupt_callback_with_data(esp_lcd_touch_handle_t tp, esp_lcd_touch_interrupt_callback_t callback, void *user_data)
|
||||
{
|
||||
assert(tp != NULL);
|
||||
|
||||
tp->config.user_data = user_data;
|
||||
return esp_lcd_touch_register_interrupt_callback(tp, callback);
|
||||
}
|
||||
@@ -0,0 +1,433 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief ESP LCD touch
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_err.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
/*为了避免报错*/
|
||||
#define CONFIG_ESP_LCD_TOUCH_MAX_POINTS 5
|
||||
#define CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Touch controller type
|
||||
*
|
||||
*/
|
||||
typedef struct esp_lcd_touch_s esp_lcd_touch_t;
|
||||
typedef esp_lcd_touch_t *esp_lcd_touch_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Touch controller interrupt callback type
|
||||
*
|
||||
*/
|
||||
typedef void (*esp_lcd_touch_interrupt_callback_t)(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/**
|
||||
* @brief Touch Configuration Type
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t x_max; /*!< X coordinates max (for mirroring) */
|
||||
uint16_t y_max; /*!< Y coordinates max (for mirroring) */
|
||||
|
||||
gpio_num_t rst_gpio_num; /*!< GPIO number of reset pin */
|
||||
gpio_num_t int_gpio_num; /*!< GPIO number of interrupt pin */
|
||||
|
||||
struct {
|
||||
unsigned int reset: 1; /*!< Level of reset pin in reset */
|
||||
unsigned int interrupt: 1;/*!< Active Level of interrupt pin */
|
||||
} levels;
|
||||
|
||||
struct {
|
||||
unsigned int swap_xy: 1; /*!< Swap X and Y after read coordinates */
|
||||
unsigned int mirror_x: 1; /*!< Mirror X after read coordinates */
|
||||
unsigned int mirror_y: 1; /*!< Mirror Y after read coordinates */
|
||||
} flags;
|
||||
|
||||
/*!< User callback called after get coordinates from touch controller for apply user adjusting */
|
||||
void (*process_coordinates)(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num);
|
||||
/*!< User callback called after the touch interrupt occurred */
|
||||
esp_lcd_touch_interrupt_callback_t interrupt_callback;
|
||||
/*!< User data passed to callback */
|
||||
void *user_data;
|
||||
/*!< User data passed to driver */
|
||||
void *driver_data;
|
||||
} esp_lcd_touch_config_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t points; /*!< Count of touch points saved */
|
||||
|
||||
struct {
|
||||
uint16_t x; /*!< X coordinate */
|
||||
uint16_t y; /*!< Y coordinate */
|
||||
uint16_t strength; /*!< Strength */
|
||||
} coords[CONFIG_ESP_LCD_TOUCH_MAX_POINTS];
|
||||
|
||||
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
|
||||
uint8_t buttons; /*!< Count of buttons states saved */
|
||||
|
||||
struct {
|
||||
uint8_t status; /*!< Status of button */
|
||||
} button[CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS];
|
||||
#endif
|
||||
|
||||
portMUX_TYPE lock; /*!< Lock for read/write */
|
||||
} esp_lcd_touch_data_t;
|
||||
|
||||
/**
|
||||
* @brief Declare of Touch Type
|
||||
*
|
||||
*/
|
||||
struct esp_lcd_touch_s {
|
||||
|
||||
/**
|
||||
* @brief set touch controller into sleep mode
|
||||
*
|
||||
* @note This function is usually blocking.
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*enter_sleep)(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/**
|
||||
* @brief set touch controller into normal mode
|
||||
*
|
||||
* @note This function is usually blocking.
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*exit_sleep)(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/**
|
||||
* @brief Read data from touch controller (mandatory)
|
||||
*
|
||||
* @note This function is usually blocking.
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*read_data)(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/**
|
||||
* @brief Get coordinates from touch controller (mandatory)
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param x: Array of X coordinates
|
||||
* @param y: Array of Y coordinates
|
||||
* @param strength: Array of strengths
|
||||
* @param point_num: Count of points touched (equals with count of items in x and y array)
|
||||
* @param max_point_num: Maximum count of touched points to return (equals with max size of x and y array)
|
||||
*
|
||||
* @return
|
||||
* - Returns true, when touched and coordinates readed. Otherwise returns false.
|
||||
*/
|
||||
bool (*get_xy)(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num);
|
||||
|
||||
|
||||
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
|
||||
/**
|
||||
* @brief Get button state (optional)
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param n: Button index
|
||||
* @param state: Button state
|
||||
*
|
||||
* @return
|
||||
* - Returns true, when touched and coordinates readed. Otherwise returns false.
|
||||
*/
|
||||
esp_err_t (*get_button_state)(esp_lcd_touch_handle_t tp, uint8_t n, uint8_t *state);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Swap X and Y after read coordinates (optional)
|
||||
* If set, then not used SW swapping.
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param swap: Set swap value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*set_swap_xy)(esp_lcd_touch_handle_t tp, bool swap);
|
||||
|
||||
/**
|
||||
* @brief Are X and Y coordinates swapped (optional)
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param swap: Get swap value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*get_swap_xy)(esp_lcd_touch_handle_t tp, bool *swap);
|
||||
|
||||
/**
|
||||
* @brief Mirror X after read coordinates
|
||||
* If set, then not used SW mirroring.
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param mirror: Set X mirror value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*set_mirror_x)(esp_lcd_touch_handle_t tp, bool mirror);
|
||||
|
||||
/**
|
||||
* @brief Is mirrored X (optional)
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param mirror: Get X mirror value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*get_mirror_x)(esp_lcd_touch_handle_t tp, bool *mirror);
|
||||
|
||||
/**
|
||||
* @brief Mirror Y after read coordinates
|
||||
* If set, then not used SW mirroring.
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param mirror: Set Y mirror value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*set_mirror_y)(esp_lcd_touch_handle_t tp, bool mirror);
|
||||
|
||||
/**
|
||||
* @brief Is mirrored Y (optional)
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param mirror: Get Y mirror value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*get_mirror_y)(esp_lcd_touch_handle_t tp, bool *mirror);
|
||||
|
||||
/**
|
||||
* @brief Delete Touch
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, otherwise returns ESP_ERR_xxx
|
||||
*/
|
||||
esp_err_t (*del)(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/**
|
||||
* @brief Configuration structure
|
||||
*/
|
||||
esp_lcd_touch_config_t config;
|
||||
|
||||
/**
|
||||
* @brief Communication interface
|
||||
*/
|
||||
esp_lcd_panel_io_handle_t io;
|
||||
|
||||
/**
|
||||
* @brief Data structure
|
||||
*/
|
||||
esp_lcd_touch_data_t data;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Read data from touch controller
|
||||
*
|
||||
* @note This function is usually blocking.
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG parameter error
|
||||
* - ESP_FAIL sending command error, slave hasn't ACK the transfer
|
||||
* - ESP_ERR_INVALID_STATE I2C driver not installed or not in master mode
|
||||
* - ESP_ERR_TIMEOUT operation timeout because the bus is busy
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_read_data(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/**
|
||||
* @brief Read coordinates from touch controller
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param x: Array of X coordinates
|
||||
* @param y: Array of Y coordinates
|
||||
* @param strength: Array of the strengths (can be NULL)
|
||||
* @param point_num: Count of points touched (equals with count of items in x and y array)
|
||||
* @param max_point_num: Maximum count of touched points to return (equals with max size of x and y array)
|
||||
*
|
||||
* @return
|
||||
* - Returns true, when touched and coordinates readed. Otherwise returns false.
|
||||
*/
|
||||
bool esp_lcd_touch_get_coordinates(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num);
|
||||
|
||||
|
||||
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
|
||||
/**
|
||||
* @brief Get button state
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param n: Button index
|
||||
* @param state: Button state
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NOT_SUPPORTED if this function is not supported by controller
|
||||
* - ESP_ERR_INVALID_ARG if bad button index
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_get_button_state(esp_lcd_touch_handle_t tp, uint8_t n, uint8_t *state);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Swap X and Y after read coordinates
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param swap: Set swap value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_set_swap_xy(esp_lcd_touch_handle_t tp, bool swap);
|
||||
|
||||
/**
|
||||
* @brief Are X and Y coordinates swapped
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param swap: Get swap value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_get_swap_xy(esp_lcd_touch_handle_t tp, bool *swap);
|
||||
|
||||
/**
|
||||
* @brief Mirror X after read coordinates
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param mirror: Set X mirror value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_set_mirror_x(esp_lcd_touch_handle_t tp, bool mirror);
|
||||
|
||||
/**
|
||||
* @brief Is mirrored X
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param mirror: Get X mirror value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_get_mirror_x(esp_lcd_touch_handle_t tp, bool *mirror);
|
||||
|
||||
/**
|
||||
* @brief Mirror Y after read coordinates
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param mirror: Set Y mirror value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_set_mirror_y(esp_lcd_touch_handle_t tp, bool mirror);
|
||||
|
||||
/**
|
||||
* @brief Is mirrored Y
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param mirror: Get Y mirror value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_get_mirror_y(esp_lcd_touch_handle_t tp, bool *mirror);
|
||||
|
||||
/**
|
||||
* @brief Delete touch (free all allocated memory and restart HW)
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_del(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/**
|
||||
* @brief Register user callback called after the touch interrupt occurred
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param callback: Interrupt callback
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_register_interrupt_callback(esp_lcd_touch_handle_t tp, esp_lcd_touch_interrupt_callback_t callback);
|
||||
|
||||
/**
|
||||
* @brief Register user callback called after the touch interrupt occurred with user data
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
* @param callback: Interrupt callback
|
||||
* @param user_data: User data passed to callback
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_register_interrupt_callback_with_data(esp_lcd_touch_handle_t tp, esp_lcd_touch_interrupt_callback_t callback, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Enter sleep mode
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_enter_sleep(esp_lcd_touch_handle_t tp);
|
||||
|
||||
/**
|
||||
* @brief Exit sleep mode
|
||||
*
|
||||
* @param tp: Touch handler
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
||||
*/
|
||||
esp_err_t esp_lcd_touch_exit_sleep(esp_lcd_touch_handle_t tp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
#ifndef USER_CONFIG_H
|
||||
#define USER_CONFIG_H
|
||||
|
||||
//spi & i2c handle
|
||||
#define LCD_HOST SPI3_HOST
|
||||
|
||||
// touch I2C port
|
||||
#define Touch_SCL_NUM (GPIO_NUM_18)
|
||||
#define Touch_SDA_NUM (GPIO_NUM_17)
|
||||
|
||||
// touch esp
|
||||
#define ESP_SCL_NUM (GPIO_NUM_48)
|
||||
#define ESP_SDA_NUM (GPIO_NUM_47)
|
||||
|
||||
// DISP
|
||||
#define EXAMPLE_PIN_NUM_LCD_CS (GPIO_NUM_9)
|
||||
#define EXAMPLE_PIN_NUM_LCD_PCLK (GPIO_NUM_10)
|
||||
#define EXAMPLE_PIN_NUM_LCD_DATA0 (GPIO_NUM_11)
|
||||
#define EXAMPLE_PIN_NUM_LCD_DATA1 (GPIO_NUM_12)
|
||||
#define EXAMPLE_PIN_NUM_LCD_DATA2 (GPIO_NUM_13)
|
||||
#define EXAMPLE_PIN_NUM_LCD_DATA3 (GPIO_NUM_14)
|
||||
#define EXAMPLE_PIN_NUM_LCD_RST (GPIO_NUM_21)
|
||||
#define EXAMPLE_PIN_NUM_BK_LIGHT (GPIO_NUM_8)
|
||||
|
||||
|
||||
#define I2C_TOUCH_ADDR 0x3b
|
||||
#define EXAMPLE_PIN_NUM_TOUCH_RST (-1)
|
||||
#define EXAMPLE_PIN_NUM_TOUCH_INT (-1)
|
||||
|
||||
|
||||
#define EXAMPLE_LVGL_TICK_PERIOD_MS 5
|
||||
#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500
|
||||
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 5
|
||||
|
||||
|
||||
/*bl test*/
|
||||
#define Backlight_Testing 0
|
||||
|
||||
/*ADDR*/
|
||||
#define EXAMPLE_RTC_ADDR 0x51
|
||||
|
||||
#define EXAMPLE_IMU_ADDR 0x6b
|
||||
|
||||
|
||||
#define USER_DISP_ROT_90 1
|
||||
#define USER_DISP_ROT_NONO 0
|
||||
#define Rotated USER_DISP_ROT_NONO //软件实现旋转
|
||||
|
||||
|
||||
|
||||
|
||||
#if (Rotated == USER_DISP_ROT_NONO)
|
||||
#define EXAMPLE_LCD_H_RES 172
|
||||
#define EXAMPLE_LCD_V_RES 640
|
||||
#else
|
||||
#define EXAMPLE_LCD_H_RES 640
|
||||
#define EXAMPLE_LCD_V_RES 172
|
||||
#endif
|
||||
|
||||
#define LCD_NOROT_HRES 172
|
||||
#define LCD_NOROT_VRES 640
|
||||
#define LVGL_DMA_BUFF_LEN (LCD_NOROT_HRES * 64 * 2)
|
||||
#define LVGL_SPIRAM_BUFF_LEN (EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES * 2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user