From 2ca0d48258cfc79eb9e0e31992ef745cb7c313bc Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Fri, 2 Dec 2022 10:28:04 +0100 Subject: [PATCH] Started to implement the lcd driver --- src/W800 SDK v1.00.08/app/Makefile | 1 + src/W800 SDK v1.00.08/app/drivers/Makefile | 16 +++++ .../app/drivers/lcd/Makefile | 15 ++++ src/W800 SDK v1.00.08/app/drivers/lcd/lcd.c | 70 +++++++++++++++++++ src/W800 SDK v1.00.08/app/drivers/lcd/lcd.h | 52 ++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 src/W800 SDK v1.00.08/app/drivers/Makefile create mode 100644 src/W800 SDK v1.00.08/app/drivers/lcd/Makefile create mode 100644 src/W800 SDK v1.00.08/app/drivers/lcd/lcd.c create mode 100644 src/W800 SDK v1.00.08/app/drivers/lcd/lcd.h diff --git a/src/W800 SDK v1.00.08/app/Makefile b/src/W800 SDK v1.00.08/app/Makefile index 7b0a56b..767c138 100644 --- a/src/W800 SDK v1.00.08/app/Makefile +++ b/src/W800 SDK v1.00.08/app/Makefile @@ -4,6 +4,7 @@ sinclude $(TOP_DIR)/tools/w800/conf.mk ifndef PDIR GEN_LIBS = libuser$(LIB_EXT) COMPONENTS_libuser = gfx/libusergfx$(LIB_EXT) +#COMPONENTS_libuser = drivers/libdrivers$(LIB_EXT) endif #DEFINES += diff --git a/src/W800 SDK v1.00.08/app/drivers/Makefile b/src/W800 SDK v1.00.08/app/drivers/Makefile new file mode 100644 index 0000000..5bbe903 --- /dev/null +++ b/src/W800 SDK v1.00.08/app/drivers/Makefile @@ -0,0 +1,16 @@ +TOP_DIR = ../.. +sinclude $(TOP_DIR)/tools/w800/conf.mk + +ifndef PDIR +GEN_LIBS = libdrivers$(LIB_EXT) +COMPONENTS_libdrivers = lcd/libdriverslcd$(LIB_EXT) +endif + +#DEFINES += + +sinclude $(TOP_DIR)/tools/w800/rules.mk + +INCLUDES := $(INCLUDES) -I $(PDIR)include + +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile \ No newline at end of file diff --git a/src/W800 SDK v1.00.08/app/drivers/lcd/Makefile b/src/W800 SDK v1.00.08/app/drivers/lcd/Makefile new file mode 100644 index 0000000..a61dd1b --- /dev/null +++ b/src/W800 SDK v1.00.08/app/drivers/lcd/Makefile @@ -0,0 +1,15 @@ +TOP_DIR = ../../.. +sinclude $(TOP_DIR)/tools/w800/conf.mk + +ifndef PDIR +GEN_LIBS = libdriverslcd$(LIB_EXT) +endif + +#DEFINES += + +sinclude $(TOP_DIR)/tools/w800/rules.mk + +INCLUDES := $(INCLUDES) -I $(PDIR)include + +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile \ No newline at end of file diff --git a/src/W800 SDK v1.00.08/app/drivers/lcd/lcd.c b/src/W800 SDK v1.00.08/app/drivers/lcd/lcd.c new file mode 100644 index 0000000..b5006e8 --- /dev/null +++ b/src/W800 SDK v1.00.08/app/drivers/lcd/lcd.c @@ -0,0 +1,70 @@ +#include "FreeRTOS.h" +#include "lcd.h" + +void lcd_config_init(LCDConfig_t * const LCDConfig) +{ + if(!LCDConfig) return; + + LCDConfig->LCDPWMBacklightPin = -1; + LCDConfig->LCDClockPin = -1; + LCDConfig->LCDDataPin = -1; + LCDConfig->LCDCSPin = -1; + LCDConfig->LCDDataCommandPin = -1; + LCDConfig->LCDResetPin = -1; + +} + +void lcd_init(LCDConfig_t * const LCDConfig) +{ + if(!LCDConfig) return; + + // Backlight is controlled using PWM + tls_gpio_cfg(LCDConfig->LCDPWMBacklightPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING); + + tls_gpio_cfg(LCDConfig->LCDCSPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING); + tls_gpio_cfg(LCDConfig->LCDDataCommandPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING); + tls_gpio_cfg(LCDConfig->LCDResetPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH); + + // The clock and data line are driven using the MMC peripheral + tls_io_cfg_set(LCDConfig->LCDClockPin, WM_IO_OPTION2); + tls_io_cfg_set(LCDConfig->LCDDataPin, WM_IO_OPTION2); + + // We set some of the pins default value + lcd_set_backlight(LCDConfig, 0); + lcd_set_cs(LCDConfig, false); + lcd_set_data_command(LCDConfig, LCD_DATA); + + lcd_hardware_reset(LCDConfig); + + // Init MMC SDIO peripheral +} + +void lcd_set_window(u16 x_start, u16 y_start, u16 x_end, u16 y_end); + +void lcd_write_frame(void); + +void lcd_set_backlight(LCDConfig_t * const LCDConfig, u8 brightness) +{ + if(brightness) + tls_gpio_write(LCDConfig->LCDPWMBacklightPin, 1); + else + tls_gpio_write(LCDConfig->LCDPWMBacklightPin, 1); +} + +void lcd_set_cs(LCDConfig_t * const LCDConfig, bool selected) +{ + // CS is active low... + tls_gpio_write(LCDConfig->LCDCSPin, !selected); +} + +void lcd_set_data_command(LCDConfig_t * const LCDConfig, LCDDataCommand_e dataCommand) +{ + tls_gpio_write(LCDConfig->LCDDataCommandPin, dataCommand); +} + +void lcd_hardware_reset(LCDConfig_t * const LCDConfig) +{ + tls_gpio_write(LCDConfig->LCDResetPin, 0); + tls_os_time_delay(pdMS_TO_TICKS(1)); + tls_gpio_write(LCDConfig->LCDResetPin, 1); +} \ No newline at end of file diff --git a/src/W800 SDK v1.00.08/app/drivers/lcd/lcd.h b/src/W800 SDK v1.00.08/app/drivers/lcd/lcd.h new file mode 100644 index 0000000..f6033ca --- /dev/null +++ b/src/W800 SDK v1.00.08/app/drivers/lcd/lcd.h @@ -0,0 +1,52 @@ +#ifndef LCD_H +#define LCD_H + +#include "wm_include.h" +#include "lv_conf.h" +/* Used SOC : W800 or W801*/ +#define W800 +/* Display drive controller */ +#define DISPLAY_CONTROLLER ILI9341 +//#define DISPLAY_CONTROLLER ST7789V + +typedef enum LCDDataCommand +{ + LCD_COMMAND = 0, + LCD_DATA = 1 +} LCDDataCommand_e; + +typedef struct LCDConfig +{ + enum tls_io_name LCDPWMBacklightPin; + enum tls_io_name LCDClockPin; + enum tls_io_name LCDDataPin; + enum tls_io_name LCDCSPin; + enum tls_io_name LCDDataCommandPin; + enum tls_io_name LCDResetPin; +} LCDConfig_t; + +/* Initializes the LCDConfig object to known values */ +void lcd_config_init(LCDConfig_t * const LCDConfig); + +/* Initializes IOs using the configured LCDConfig object and the LCD display */ +void lcd_init(LCDConfig_t * const LCDConfig); + +/* Sets the LCD write window area */ +void lcd_set_window(u16 x_start, u16 y_start, u16 x_end, u16 y_end); + +/* Writes the frame to display's internal RAM */ +void lcd_write_frame(void); + +/* Sets the backlight to the specified brightness value */ +void lcd_set_backlight(LCDConfig_t * const LCDConfig, u8 brightness); + +/* Sets the chip select pin */ +void lcd_set_cs(LCDConfig_t * const LCDConfig, bool selected); + +/* Sets the data/command pin state */ +void lcd_set_data_command(LCDConfig_t * const LCDConfig, LCDDataCommand_e dataCommand); + +/* Issues a reset of the lcd display */ +void lcd_hardware_reset(LCDConfig_t * const LCDConfig); + +#endif //LCD_H \ No newline at end of file