bolar_2_lcd demo
This commit is contained in:
82
main/screen.h
Normal file
82
main/screen.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
#include "tca9555.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "esp_err.h"
|
||||
#include <cstdint>
|
||||
#include <cmath>
|
||||
#define LCD_WIDTH 128
|
||||
#define LCD_HEIGHT 130
|
||||
// 128x128圆形屏幕地址偏移
|
||||
#define LCD_COL_OFFSET 0
|
||||
#define LCD_ROW_OFFSET 0
|
||||
|
||||
// SPI屏幕硬件引脚(原理图SCREEN总线)
|
||||
#define LCD_DC_GPIO GPIO_NUM_8
|
||||
#define LCD_MOSI_GPIO GPIO_NUM_9
|
||||
#define LCD_SCK_GPIO GPIO_NUM_10
|
||||
|
||||
#define LCD_CS_GPIO GPIO_NUM_12
|
||||
#define LCD_SPI_HOST SPI3_HOST
|
||||
#define LCD_SPI_CLK (1 * 1000 * 1000)
|
||||
|
||||
// ST7735 基础指令
|
||||
#define CMD_SWRESET 0x01
|
||||
#define CMD_SLPOUT 0x11
|
||||
#define CMD_DISPOFF 0x28
|
||||
#define CMD_DISPON 0x29
|
||||
#define CMD_COLMOD 0x3A
|
||||
#define CMD_MADCTL 0x36
|
||||
#define CMD_CASET 0x2A
|
||||
#define CMD_RASET 0x2B
|
||||
#define CMD_RAMWR 0x2C
|
||||
|
||||
#define CMD_INVOFF 0x20 // 关闭反转显示
|
||||
#define CMD_INVON 0x21 // 开启反转显示(通常不需要)
|
||||
|
||||
// RGB565标准色
|
||||
#define COLOR_RED 0xF800
|
||||
#define COLOR_GREEN 0x07E0
|
||||
#define COLOR_BLUE 0x001F
|
||||
#define COLOR_WHITE 0xFFFF
|
||||
#define COLOR_YELLOW 0xFFE0
|
||||
#define COLOR_BLACK 0x0000
|
||||
|
||||
|
||||
enum class EyeAnimState
|
||||
{
|
||||
EYE_OPEN, // 正常睁眼向前看
|
||||
EYE_CLOSE, // 完全闭眼
|
||||
EYE_LOOK_LEFT, // 眼睛看向左边
|
||||
EYE_LOOK_RIGHT, // 眼睛看向右边
|
||||
EYE_BLINK_AUTO // 自动循环眨眼动画
|
||||
};
|
||||
|
||||
class LcdScreen
|
||||
{
|
||||
public:
|
||||
spi_device_handle_t _spi_handle;
|
||||
static __attribute__((aligned(4))) uint8_t full_buf[LCD_WIDTH * LCD_HEIGHT * 2];
|
||||
esp_err_t power_up(TCA9555 &tca);
|
||||
esp_err_t spi_init(void);
|
||||
void send_cmd(uint8_t cmd);
|
||||
void send_data(uint8_t dat);
|
||||
void ic_init_sequence(void);
|
||||
void fill_color(uint16_t rgb565);
|
||||
|
||||
void draw_single_eye(int cx, int cy, int eye_radius, int pupil_ofs_x, int pupil_r);
|
||||
// 安全画点,圆形屏边界裁剪
|
||||
inline void DrawPixel(int x, int y, uint16_t color)
|
||||
{
|
||||
int px = x + LCD_COL_OFFSET;
|
||||
int py = y + LCD_ROW_OFFSET;
|
||||
if (px >= 0 && px < LCD_WIDTH && py >= 0 && py < LCD_HEIGHT)
|
||||
{
|
||||
// RGB565:2字节一个像素,高字节在前
|
||||
int idx = (py * LCD_WIDTH + px) * 2;
|
||||
full_buf[idx] = (uint8_t)(color >> 8);
|
||||
full_buf[idx+1] = (uint8_t)(color & 0xFF);
|
||||
}
|
||||
}
|
||||
void Flush();
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user