Introduction
Project includes component for controlling LCD displays. Currently supports only one LCD controller - SSD1283A but it may change in the future. It is compatible with ESP32 microcontrollers. Source code of the driver has been written in C.
It is written and tested for v4.4.2 of the ESP-IDF environment using the xtensa-esp32-elf toolchain (gcc version 8.4.0).
Build
To include the component into your ESP-IDF project, you need to create CMakeLists.txt
file containing:
idf_component_register(
SRC_DIRS "." "com" "controllers"
INCLUDE_DIRS "/include" "com/include" "controllers/include"
)
Consult ESP-IDF documentation for more details about build system.
Features
✔️ Instantiation - using many driver instances simultaneously is possible
✔️ Supports the following LCD controllers:
- SSD1283A (SPI interface only)
✔️ Very basic display control - turning it on and off, clearing the entire screen
✔️ Basic shape drawing function - rectangles in the desired positions on the screen
✔️ Supports drawing texts on the screen using included default font:
- Possibility to add your own fonts - please check the documentation for details
✔️ Supports drawing images on the screen:
- Your image have to be converted and embed in the code as an array of the pixels - please check the documentation for more details and the example below
✔️ Supports color formats:
❌ Supports touch screens
❌ Static memory allocation - creating driver instance requires dynamic allocation
Example
Below are some examples of using the driver.
- Creating, initializing and destroying the concrete driver instance (SSD1283A + SPI interface)
#define LCD_SPI_HOST VSPI_HOST
#define LCD_SPI_DMA SPI_DMA_CH_AUTO
#define LCD_MISO_GPIO 19
#define LCD_MOSI_GPIO 23
#define LCD_SCLK_GPIO 18
#define LCD_CS_GPIO 5
#define LCD_DC_GPIO 22
#define LCD_RST_GPIO 21
#define LCD_WP_GPIO -1
#define LCD_HOLD_GPIO -1
spi_device_handle_t spi;
if (
SPI_OK !=
spi_init(LCD_MISO_GPIO, LCD_MOSI_GPIO, LCD_SCLK_GPIO, LCD_WP_GPIO, LCD_HOLD_GPIO, LCD_CS_GPIO,
{
}
{
}
{
}
LCD_error_t lcd__Destroy(LCD_handle_t *device)
Destroys the specific LCD driver instance.
Definition: lcd.c:122
LCD_error_t lcd__Init(LCD_handle_t device)
Initializes the specific LCD device.
Definition: lcd.c:23
@ LCD_OK
Definition: lcd_error_codes.h:39
#define SSD1283A_SPI_QUEUE_SIZE
Definition: lcd_ssd1283a.h:33
#define SSD1283A_SPI_CLOCK_SPEED
Definition: lcd_ssd1283a.h:34
#define SSD1283A_SPI_MAX_TRANSFER_SIZE
Definition: lcd_ssd1283a.h:32
LCD_handle_t lcd_ssd1283a_spi__Create(spi_device_handle_t spi, const int dc, const int reset)
Creates the instance of LCD driver to communicate with SSD1283A controller using SPI interface.
Definition: lcd_ssd1283a.c:196
spi_error_t spi_init(const int miso, const int mosi, const int sclk, const int wp, const int hd, const int cs, const int maxTransferSize, const int queueSize, const int clockSpeedHz, const spi_host_device_t host, const spi_dma_chan_t dma, spi_device_handle_t *const spi)
Initializes SPI bus and registers the single device on it.
Definition: spi.c:56
@ SPI_OK
Definition: spi_error_codes.h:39
Base structure describing characteristics of LCD display and its driver.
Definition: lcd_low.h:100
- Drawing example rectangle on the screen
{
}
LCD_error_t lcd__DrawRect(LCD_handle_t device, const uint16_t x, const uint16_t y, const uint16_t width, const uint16_t height, const uint16_t color)
Draws rectangle on the LCD display in specific position and color.
Definition: lcd.c:65
#define RGB565_RED
Definition: lcd_colors.h:30
#define SSD1283A_HEIGHT
Definition: lcd_ssd1283a.h:37
#define SSD1283A_WIDTH
Definition: lcd_ssd1283a.h:36
- Drawing example text on the screen
{
}
LCD_error_t lcd__DrawText(LCD_handle_t device, uint16_t x, uint16_t y, const char *text, const int16_t letterSpacing, const int16_t lineSpacing, const LCD_font_t *font, const uint16_t fontColor, const uint16_t bgrColor)
Draws text on the LCD display with specified properties.
Definition: lcd.c:93
const LCD_font_t LCD_BASIC_FONT
Definition: lcd_basic_font.c:127
#define RGB565_BLACK
Definition: lcd_colors.h:33
#define RGB565_WHITE
Definition: lcd_colors.h:34
- Drawing example image on the screen
lcd_example_image.h
:
Describes properties of the image to be drawn on LCD display.
Definition: lcd_image.h:39
lcd_example_image.c
:
#define LCD_EXAMPLE_IMAGE_WIDTH 15
#define LCD_EXAMPLE_IMAGE_HEIGHT 15
static const uint8_t pixels[] =
{
};
{
.
width = LCD_IMAGE_SUN_FULL_WIDTH,
.height = LCD_IMAGE_SUN_FULL_HEIGHT,
.pixels = pixels,
};
const uint16_t width
Definition: lcd_image.h:40
main.c
:
{
}
LCD_error_t lcd__DrawImage(LCD_handle_t device, const uint16_t x, const uint16_t y, const LCD_image_t *image)
Draws image on the LCD display in specific position.
Definition: lcd.c:79
Documentation
Generated API documentation is available here.
Source Code
The source code is available on GitHub.
License
The code in this project is licensed under the MIT license - see LICENSE.md for details.
Links