Update to use display_bsp

This commit is contained in:
C47D 2021-07-29 19:05:17 -05:00
parent 6122d139de
commit 2629b6d86a

View file

@ -4,21 +4,19 @@
* Mostly taken from lbthomsen/esp-idf-littlevgl github.
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#include "esp_log.h"
#include "st7789.h"
#include "disp_spi.h"
#include "driver/gpio.h"
#include "display_bsp.h"
/*********************
* DEFINES
*********************/
#define TAG "st7789"
#define TAG "ST7789"
/**********************
* TYPEDEFS
**********************/
@ -38,12 +36,6 @@ static void st7789_set_orientation(uint8_t orientation);
static void st7789_send_color(void *data, size_t length);
static void st7789_reset(void);
/* The user should init all the hardware related to the display in this
* function, maybe it's better to do this outside the display code, e.g.
* in main before calling anything related to LVGL.
* Some platforms, like STM32CubeIDE init and configure all the hardware
* with auto generated code. */
static void bsp_init_hardware(void);
/**********************
* STATIC VARIABLES
**********************/
@ -57,7 +49,7 @@ static void bsp_init_hardware(void);
**********************/
void st7789_init(void)
{
bsp_init_hardware();
display_bsp_init_io();
lcd_init_cmd_t st7789_init_cmds[] = {
{0xCF, {0x00, 0x83, 0X30}, 3},
@ -96,7 +88,7 @@ void st7789_init(void)
st7789_reset();
printf("ST7789 initialization.\n");
ESP_LOGI(TAG, "Initialization.\n");
//Send all the commands
uint16_t cmd = 0;
@ -104,7 +96,7 @@ void st7789_init(void)
st7789_send_cmd(st7789_init_cmds[cmd].cmd);
st7789_send_data(st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F);
if (st7789_init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS);
display_bsp_delay(100);
}
cmd++;
}
@ -112,6 +104,22 @@ void st7789_init(void)
st7789_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
}
void st7789_enable_backlight(bool backlight)
{
#if ST7789_ENABLE_BACKLIGHT_CONTROL
ESP_LOGI(TAG, "%s backlight.\n", backlight ? "Enabling" : "Disabling");
uint32_t tmp = 0;
#if (ST7789_BCKL_ACTIVE_LVL==1)
tmp = backlight ? 1 : 0;
#else
tmp = backlight ? 0 : 1;
#endif
display_bsp_backlight(tmp);
#endif
}
/* The ST7789 display controller can drive 320*240 displays, when using a 240*240
* display there's a gap of 80px, we need to edit the coordinates to take into
* account that gap, this is not necessary in all orientations. */
@ -171,21 +179,21 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
void st7789_send_cmd(uint8_t cmd)
{
disp_wait_for_pending_transactions();
bsp_gpio_dc(0);
display_bsp_gpio_dc(0);
disp_spi_send_data(&cmd, 1);
}
void st7789_send_data(void * data, uint16_t length)
{
disp_wait_for_pending_transactions();
bsp_gpio_dc(1);
display_bsp_gpio_dc(1);
disp_spi_send_data(data, length);
}
static void st7789_send_color(void * data, size_t length)
{
disp_wait_for_pending_transactions();
bsp_gpio_dc(1);
display_bsp_gpio_dc(1);
disp_spi_send_colors(data, length);
}
@ -193,10 +201,10 @@ static void st7789_send_color(void * data, size_t length)
static void st7789_reset(void)
{
#if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET)
bsp_gpio_rst(0);
bsp_delay(100);
bsp_gpio_rst(1);
bsp_delay(100);
display_bsp_gpio_rst(0);
display_bsp_delay(100);
display_bsp_gpio_rst(1);
display_bsp_delay(100);
#else
st7789_send_cmd(ST7789_SWRESET);
#endif
@ -204,8 +212,6 @@ static void st7789_reset(void)
static void st7789_set_orientation(uint8_t orientation)
{
// ESP_ASSERT(orientation < 4);
const char *orientation_str[] = {
"PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED"
};
@ -227,39 +233,3 @@ static void st7789_set_orientation(uint8_t orientation)
st7789_send_data((void *) &data[orientation], 1);
}
static void bsp_delay(uint32_t delay_ms)
{
vTaskDelay(delay_ms / portTICK_RATE_MS);
}
static void bsp_backlight(uint8_t state)
{
gpio_set_level(ST7789_BCKL, state);
}
static void bsp_gpio_dc(uint8_t state)
{
gpio_set_level(ST7789_DC, state);
}
static void bsp_gpio_rst(uint8_t state)
{
gpio_set_level(ST7789_RST, state);
}
static void bsp_init_hardware(void)
{
//Initialize non-SPI GPIOs
gpio_pad_select_gpio(ST7789_DC);
gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT);
#if !defined(CONFIG_LV_DISP_ST7789_SOFT_RESET)
gpio_pad_select_gpio(ST7789_RST);
gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT);
#endif
#if ST7789_ENABLE_BACKLIGHT_CONTROL
gpio_pad_select_gpio(ST7789_BCKL);
gpio_set_direction(ST7789_BCKL, GPIO_MODE_OUTPUT);
#endif
}