LCD implementation.
This commit is contained in:
parent
28508e798c
commit
2f5b6f8d9b
|
@ -10,6 +10,7 @@ set(C_SOURCES
|
|||
"src/drivers/user_gpio_driver.c"
|
||||
"src/drivers/user_spi_driver.c"
|
||||
"src/drivers/user_config_driver.c"
|
||||
"src/impl/user_st7789_impl.c"
|
||||
"src/impl/user_lvgl_impl.c"
|
||||
"src/tasks/user_lvgl_task.c"
|
||||
"src/utils/user_log_util.c"
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef __USER_ST7789_IMPL_H
|
||||
#define __USER_ST7789_IMPL_H
|
||||
|
||||
#include "drivers/user_gpio_driver.h"
|
||||
#include "drivers/user_spi_driver.h"
|
||||
#include "st7789_lcd.h"
|
||||
|
||||
typedef struct {
|
||||
user_spi_driver_t *spi_driver;
|
||||
user_gpio_t cs_gpio;
|
||||
user_gpio_t dc_gpio;
|
||||
user_gpio_t reset_gpio;
|
||||
} user_st7789_impl_t;
|
||||
|
||||
int user_st7789_impl_init(void *handle, user_spi_driver_t *spi_driver);
|
||||
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);
|
||||
|
||||
#endif
|
|
@ -1,50 +1,25 @@
|
|||
#include "lvgl.h"
|
||||
|
||||
#include "st7789_lcd.h"
|
||||
|
||||
#include "drivers/user_gpio_driver.h"
|
||||
#include "drivers/user_spi_driver.h"
|
||||
#include "impl/user_st7789_impl.h"
|
||||
|
||||
extern user_spi_driver_t g_spi;
|
||||
|
||||
st7789_ret_t _user_lvgl_impl_lcd_write_cmd(void *handle, uint8_t *cmd,
|
||||
uint8_t len);
|
||||
st7789_ret_t _user_lvgl_impl_lcd_write_data(void *handle, uint8_t *data,
|
||||
uint32_t len);
|
||||
st7789_ret_t _user_lvgl_impl_lcd_reset(void *handle);
|
||||
|
||||
user_st7789_impl_t g_lcd_impl;
|
||||
st7789_lcd_t g_lcd = {
|
||||
.cb =
|
||||
{
|
||||
.write_cmd_cb = _user_lvgl_impl_lcd_write_cmd,
|
||||
.write_data_cb = _user_lvgl_impl_lcd_write_data,
|
||||
.reset_cb = _user_lvgl_impl_lcd_reset,
|
||||
.write_cmd_cb = user_st7789_impl_write_cmd,
|
||||
.write_data_cb = user_st7789_impl_write_data,
|
||||
.reset_cb = user_st7789_impl_reset,
|
||||
},
|
||||
.config =
|
||||
{
|
||||
.direction = ST7789_DIR_0,
|
||||
.pix_fmt = ST7789_RGB888,
|
||||
},
|
||||
.user_data = &g_lcd_impl,
|
||||
};
|
||||
|
||||
void user_lvgl_impl_init(void) {}
|
||||
|
||||
st7789_ret_t _user_lvgl_impl_lcd_write_cmd(void *handle, uint8_t *cmd,
|
||||
uint8_t len) {
|
||||
// TODO: Change CS and DC here
|
||||
if(user_spi_driver_xfer(&g_spi, cmd, NULL, len) != USER_SPI_OK) {
|
||||
return ST7789_ERROR;
|
||||
}
|
||||
void user_lvgl_impl_init(void) {
|
||||
user_st7789_impl_init(&g_lcd_impl, &g_spi);
|
||||
}
|
||||
|
||||
st7789_ret_t _user_lvgl_impl_lcd_write_data(void *handle, uint8_t *data,
|
||||
uint32_t len) {
|
||||
// TODO: Change CS and DC here
|
||||
if(user_spi_driver_xfer(&g_spi, data, NULL, len) != USER_SPI_OK) {
|
||||
return ST7789_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
st7789_ret_t _user_lvgl_impl_lcd_reset(void *handle) {
|
||||
// Implement reset here.
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
#include "impl/user_st7789_impl.h"
|
||||
|
||||
int user_st7789_impl_init(void *handle, user_spi_driver_t *spi_driver) {
|
||||
|
||||
user_st7789_impl_t *impl = handle;
|
||||
|
||||
if(user_gpio_init(&impl->cs_gpio, "/dev/gpiochip0", 0) != USER_GPIO_OK)
|
||||
return -1;
|
||||
if(user_gpio_init(&impl->dc_gpio, "/dev/gpiochip0", 0) != USER_GPIO_OK)
|
||||
return -2;
|
||||
if(user_gpio_init(&impl->reset_gpio, "/dev/gpiochip0", 0) != USER_GPIO_OK)
|
||||
return -3;
|
||||
|
||||
if(spi_driver == NULL) return -4;
|
||||
|
||||
impl->spi_driver = spi_driver;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void user_st7789_impl_deinit(void *handle) {
|
||||
|
||||
user_st7789_impl_t *impl = handle;
|
||||
|
||||
user_gpio_deinit(&impl->cs_gpio);
|
||||
user_gpio_deinit(&impl->dc_gpio);
|
||||
user_gpio_deinit(&impl->reset_gpio);
|
||||
}
|
||||
|
||||
st7789_ret_t user_st7789_impl_write_cmd(void *handle, uint8_t *cmd,
|
||||
uint8_t len) {
|
||||
|
||||
user_st7789_impl_t *impl = handle;
|
||||
|
||||
if(user_gpio_set(&impl->dc_gpio, 0) != USER_GPIO_OK) return ST7789_ERROR;
|
||||
if(user_gpio_set(&impl->cs_gpio, 0) != USER_GPIO_OK) return ST7789_ERROR;
|
||||
|
||||
// ST7789VW requires parameters to be sent with DC=0.
|
||||
if(user_spi_driver_xfer(impl->spi_driver, cmd, NULL, len) != USER_SPI_OK) {
|
||||
user_gpio_set(&impl->cs_gpio, 1);
|
||||
return ST7789_ERROR;
|
||||
}
|
||||
if(user_gpio_set(&impl->cs_gpio, 1) != USER_GPIO_OK) return ST7789_ERROR;
|
||||
|
||||
return ST7789_OK;
|
||||
}
|
||||
|
||||
st7789_ret_t user_st7789_impl_write_data(void *handle, uint8_t *data,
|
||||
uint32_t len) {
|
||||
user_st7789_impl_t *impl = handle;
|
||||
|
||||
if(user_gpio_set(&impl->dc_gpio, 1) != USER_GPIO_OK) return ST7789_ERROR;
|
||||
if(user_gpio_set(&impl->cs_gpio, 0) != USER_GPIO_OK) return ST7789_ERROR;
|
||||
if(user_spi_driver_xfer(impl->spi_driver, data, NULL, len) != USER_SPI_OK) {
|
||||
user_gpio_set(&impl->cs_gpio, 1);
|
||||
return ST7789_ERROR;
|
||||
}
|
||||
if(user_gpio_set(&impl->cs_gpio, 1) != USER_GPIO_OK) return ST7789_ERROR;
|
||||
|
||||
return ST7789_OK;
|
||||
}
|
||||
|
||||
st7789_ret_t user_st7789_impl_reset(void *handle) {
|
||||
|
||||
user_st7789_impl_t *impl = handle;
|
||||
|
||||
if(&impl->reset_gpio == NULL) return ST7789_OK;
|
||||
|
||||
if(user_gpio_set(&impl->reset_gpio, 0) != USER_GPIO_OK) return ST7789_ERROR;
|
||||
usleep(10 * 1000); // Sleep 10ms
|
||||
if(user_gpio_set(&impl->cs_gpio, 1) != USER_GPIO_OK) return ST7789_ERROR;
|
||||
}
|
Loading…
Reference in New Issue