From 5be4660e7ce7210f0432191deaf66657916a2f7b Mon Sep 17 00:00:00 2001 From: imi415 Date: Sat, 26 Jun 2021 11:07:58 +0800 Subject: [PATCH] Updated ST7789 driver. --- include/impl/user_st7789_impl.h | 17 +++++++++-------- lib/st7789_lcd | 2 +- src/impl/user_lvgl_impl.c | 7 +++++-- src/impl/user_st7789_impl.c | 22 ++++++++++++++++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/include/impl/user_st7789_impl.h b/include/impl/user_st7789_impl.h index 1368e65..8b62370 100644 --- a/include/impl/user_st7789_impl.h +++ b/include/impl/user_st7789_impl.h @@ -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 \ No newline at end of file diff --git a/lib/st7789_lcd b/lib/st7789_lcd index 93c56ce..e4ea256 160000 --- a/lib/st7789_lcd +++ b/lib/st7789_lcd @@ -1 +1 @@ -Subproject commit 93c56ceaa021dde3f22057dabaecdb9f4eddb5f1 +Subproject commit e4ea2560c14255e1525068419fd1206fe395fa5c diff --git a/src/impl/user_lvgl_impl.c b/src/impl/user_lvgl_impl.c index 34b1aeb..2b61432 100644 --- a/src/impl/user_lvgl_impl.c +++ b/src/impl/user_lvgl_impl.c @@ -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; diff --git a/src/impl/user_st7789_impl.c b/src/impl/user_st7789_impl.c index 4289ec0..e2a25ef 100644 --- a/src/impl/user_st7789_impl.c +++ b/src/impl/user_st7789_impl.c @@ -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; +} \ No newline at end of file