Updated ST7789 driver.

This commit is contained in:
imi415 2021-06-26 11:07:58 +08:00
parent a31ece1567
commit 5be4660e7c
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
4 changed files with 37 additions and 11 deletions

View File

@ -1,9 +1,9 @@
#ifndef __USER_ST7789_IMPL_H
#define __USER_ST7789_IMPL_H
#include "drivers/user_config_driver.h"
#include "drivers/user_gpio_driver.h"
#include "drivers/user_spi_driver.h"
#include "drivers/user_config_driver.h"
#include "st7789_lcd.h"
@ -12,14 +12,15 @@ typedef struct {
user_gpio_t *cs_gpio;
user_gpio_t *dc_gpio;
user_gpio_t *reset_gpio;
user_gpio_t *bl_gpio;
} user_st7789_impl_t;
int user_st7789_impl_init(void *handle);
int user_st7789_impl_init(void *handle);
void user_st7789_impl_deinit(void *handle);
st7789_ret_t user_st7789_impl_write_cmd(void *handle, uint8_t *cmd,
uint8_t len);
st7789_ret_t user_st7789_impl_write_data(void *handle,
uint8_t *data, uint32_t len);
st7789_ret_t user_st7789_impl_reset(void *handle);
st7789_ret_t user_st7789_impl_write_cmd(void *handle, uint8_t *cmd,
uint8_t len);
st7789_ret_t user_st7789_impl_write_data(void *handle, uint8_t *data,
uint32_t len);
st7789_ret_t user_st7789_impl_reset(void *handle);
st7789_ret_t user_st7789_impl_backlight(void *handle, uint8_t on);
#endif

@ -1 +1 @@
Subproject commit 93c56ceaa021dde3f22057dabaecdb9f4eddb5f1
Subproject commit e4ea2560c14255e1525068419fd1206fe395fa5c

View File

@ -18,6 +18,7 @@ st7789_lcd_t g_lcd = {
.write_cmd_cb = user_st7789_impl_write_cmd,
.write_data_cb = user_st7789_impl_write_data,
.reset_cb = user_st7789_impl_reset,
.backlight_cb = user_st7789_impl_backlight,
},
.config =
{
@ -92,7 +93,8 @@ lv_fs_res_t user_lvgl_impl_fs_read_cb(lv_fs_drv_t *drv, void *file_p, void *buf,
if(fd > 0) {
*br = read(fd, buf, btr);
USER_LOG(USER_LOG_DEBUG, "Called read() on fd %d, len=%d, rlen=%d", fd, btr, *br);
USER_LOG(USER_LOG_DEBUG, "Called read() on fd %d, len=%d, rlen=%d", fd,
btr, *br);
if(*br < 0) return LV_FS_RES_FS_ERR;
return LV_FS_RES_OK;
@ -135,7 +137,8 @@ lv_fs_res_t user_lvgl_impl_fs_seek_cb(lv_fs_drv_t *drv, void *file_p,
if(fd > 0) {
int new_offset = lseek(fd, pos, l_whence);
USER_LOG(USER_LOG_DEBUG, "Called seek() on fd %d, pos=%d, whence=%d", fd, pos, l_whence);
USER_LOG(USER_LOG_DEBUG, "Called seek() on fd %d, pos=%d, whence=%d",
fd, pos, l_whence);
if(new_offset < 0) return LV_FS_RES_FS_ERR;
return LV_FS_RES_OK;

View File

@ -39,6 +39,8 @@ int user_st7789_impl_init(void *handle) {
if(!impl->dc_gpio) return -1;
impl->reset_gpio = malloc(sizeof(user_gpio_t));
if(!impl->reset_gpio) return -1;
impl->bl_gpio = malloc(sizeof(user_gpio_t));
if(!impl->bl_gpio) return -1;
if(_user_st7789_impl_init_pin(impl->cs_gpio, "cs", 1) != 0) {
free(impl->cs_gpio);
@ -57,6 +59,12 @@ int user_st7789_impl_init(void *handle) {
USER_LOG(USER_LOG_WARN, "No Reset pin found.");
}
if(_user_st7789_impl_init_pin(impl->bl_gpio, "backlight", 1) != 0) {
free(impl->bl_gpio);
impl->bl_gpio = NULL;
USER_LOG(USER_LOG_WARN, "No backlight pin found.");
}
impl->spi_driver = &g_spi;
return 0;
@ -78,6 +86,10 @@ void user_st7789_impl_deinit(void *handle) {
user_gpio_deinit(impl->reset_gpio);
free(impl->reset_gpio);
}
if(impl->bl_gpio) {
user_gpio_deinit(impl->bl_gpio);
free(impl->bl_gpio);
}
}
st7789_ret_t user_st7789_impl_write_cmd(void *handle, uint8_t *cmd,
@ -136,3 +148,13 @@ st7789_ret_t user_st7789_impl_reset(void *handle) {
return ST7789_OK;
}
st7789_ret_t user_st7789_impl_backlight(void *handle, uint8_t on) {
user_st7789_impl_t *impl = handle;
if(impl->bl_gpio == NULL) return ST7789_OK;
if(user_gpio_set(impl->bl_gpio, (on ? 0 : 1)) != 0) return ST7789_ERROR;
return ST7789_OK;
}