From 5195172168c68b21c07f43ef474af08f81afb728 Mon Sep 17 00:00:00 2001 From: imi415 Date: Tue, 22 Dec 2020 01:01:46 +0800 Subject: [PATCH] Added LCD driver, modified include. --- Core/Inc/st7789_lcd.h | 27 +++++++++++++++++++++++++++ Core/Src/main.c | 2 +- Core/Src/st7789_lcd.c | 36 ++++++++++++++++++++++++++++++++++++ Makefile | 1 + 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Core/Inc/st7789_lcd.h create mode 100644 Core/Src/st7789_lcd.c diff --git a/Core/Inc/st7789_lcd.h b/Core/Inc/st7789_lcd.h new file mode 100644 index 0000000..a604760 --- /dev/null +++ b/Core/Inc/st7789_lcd.h @@ -0,0 +1,27 @@ +#ifndef __ST7789_LCD_H +#define __ST7789_LCD_H + +#include + +#define ST7789_PANEL_SELECTION st7789_zjy_240_240_init_sequence + +#define ST7789_ERROR_CHECK(x) if(x != ST7789_RET_OK) return ST7789_RET_ERR + +typedef enum { + ST7789_RET_OK, + ST7789_RET_ERR +} st7789_ret_t; + +typedef struct { + st7789_ret_t (*write_cmd_cb)(void *handle, uint8_t *cmd, uint16_t len); + st7789_ret_t (*write_data_cb)(void *handle, uint8_t *data, uint16_t len); +} st7789_cb_t; + +typedef struct { + void *user_data; + st7789_cb_t cb; +} st7789_handle_t; + +st7789_ret_t st7789_lcd_init(st7789_handle_t *lcd); + +#endif //__ST7789_LCD_H diff --git a/Core/Src/main.c b/Core/Src/main.c index 2750072..db2c5b0 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -25,7 +25,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include "lv_conf.h" +#include "lvgl.h" /* USER CODE END Includes */ diff --git a/Core/Src/st7789_lcd.c b/Core/Src/st7789_lcd.c new file mode 100644 index 0000000..605a42c --- /dev/null +++ b/Core/Src/st7789_lcd.c @@ -0,0 +1,36 @@ +#include "st7789_lcd.h" + +const uint8_t st7789_zjy_240_240_init_sequence[] = { + 0x05, 0xB2, 0x0C, 0x0C, 0x00, 0x33, 0x33, // Porch Setting + 0x01, 0xB7, 0x35, // Gate Control + 0x01, 0xBB, 0x19, // VCOM Setting // Factory 0x19 -> 0.725V + 0x01, 0xC0, 0x2C, // LCM Control + 0x01, 0xC2, 0x01, // VDV and VRH Command Enable + 0x01, 0xC3, 0x12, // VRH Set // Factory 12H + 0x01, 0xC4, 0x20, // VDV Set + 0x01, 0xC6, 0x0F, //Frame Rate Control in Normal Mode + 0x02, 0xD0, 0xA4, 0xA1, // Power Control 1 + 0x0E, 0xE0, 0xD0, 0x04, 0x0D, 0x11, 0x13, 0x2B, 0x3F, 0x54, 0x4C, 0x18, 0x0D, 0x0B, 0x1F, + 0x23, // Positive Voltage Gamma Control + 0x0E, 0xE1, 0xD0, 0x04, 0x0C, 0x11, 0x13, 0x2C, 0x3F, 0x44, 0x51, 0x2F, 0x1F, 0x1F, 0x20, + 0x23, // Negative Voltage Gamma Control + 0x00, 0x21, // Inversion On +}; + +st7789_ret_t _st7789_init_seq(st7789_handle_t *lcd) { + uint16_t i = 0; + while(i < sizeof(ST7789_PANEL_SELECTION)) { + ST7789_ERROR_CHECK(lcd->cb.write_cmd_cb(lcd->user_data, &ST7789_PANEL_SELECTION[i + 1], ST7789_PANEL_SELECTION[i] + 1)); + i = ST7789_PANEL_SELECTION[i] + 2; + } + return ST7789_RET_OK; +} + +st7789_ret_t _st7789_ptr(st7789_handle_t *lcd, uint16_t x_start, uint16_t x_end, uint16_t y_start, uint16_t y_end) { + +} + +st7789_ret_t st7789_lcd_init(st7789_handle_t *lcd) { + return _st7789_init_seq(lcd); +} + diff --git a/Makefile b/Makefile index 6c1d1ee..6040495 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,7 @@ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c \ Core/Src/system_stm32h7xx.c \ Core/Src/freertos.c \ Core/Src/stm32h7xx_hal_timebase_tim.c \ +Core/Src/st7789_lcd.c \ FATFS/App/fatfs.c \ FATFS/Target/bsp_driver_sd.c \ FATFS/Target/sd_diskio.c \