ST7789V3 1.47 Inch LCD Driver
Public API reference for the ST7789V3 display driver
Loading...
Searching...
No Matches
ST7789V3.h File Reference

Public API for the ST7789V3 SPI display driver. More...

#include <fonts/fonts.h>
#include <stdint.h>
Include dependency graph for ST7789V3.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ST7789V3_Config
 Runtime configuration and hardware binding for one display instance. More...
 

Macros

Controller Command Macros

Controller command values used by the ST7789V3 display.

#define ST7789V3_rst
 
#define ST7789V3_backlight
 
#define Sleep_Out   0x11U
 
#define Sleep_In   0x10U
 
#define Display_On_Register   0x29U
 
#define Display_Off_Register   0x28U
 
#define CASET   0x2AU
 
#define RASET   0x2BU
 
#define RAMWR   0x2CU
 
#define COLMODE   0x3AU
 
#define MADCTL   0x36U
 
#define INVOFF_REG   0x20U
 
#define INVON_REG   0x21U
 
Color Constants

Predefined 24-bit RGB888 colors in 0xRRGGBB format.

#define BLACK   0x000000U
 
#define WHITE   0xFFFFFFU
 
#define RED   0xFF0000U
 
#define GREEN   0x00FF00U
 
#define BLUE   0x0000FFU
 
#define YELLOW   0xFFFF00U
 
#define CYAN   0x00FFFFU
 
#define MAGENTA   0xFF00FFU
 
#define ORANGE   0xFF6A00U
 
#define PINK   0xFF69B4U
 
#define PURPLE   0x800080U
 
#define LIME   0x32FF00U
 
#define NAVY   0x000080U
 
#define DARK_GREEN   0x006400U
 
#define MAROON   0x800000U
 
#define OLIVE   0x808000U
 
#define TEAL   0x008080U
 
#define SILVER   0xC0C0C0U
 
#define GRAY   0x808080U
 
#define DARK_GRAY   0x404040U
 
#define LIGHT_GRAY   0xD3D3D3U
 
#define GOLD   0xFFD700U
 
#define SKY_BLUE   0x87CEEBU
 

Functions

Core Control API

Functions for initialization and controller-level display control.

void ST7789V3_init (ST7789V3_Config *config)
 Initialize the display and apply the default startup sequence.
 
int8_t SetWindow (ST7789V3_Config *config, uint16_t X_Start, uint16_t X_End, uint16_t Y_Start, uint16_t Y_End)
 Set the active drawing window on the display.
 
int8_t SetColorMode (ST7789V3_Config *config, Color_Mode bitdepth)
 Set the controller pixel format.
 
void DISPLAYON (ST7789V3_Config *config)
 Enable display output.
 
void DISPLAYOFF (ST7789V3_Config *config)
 Disable display output.
 
void HardReset (ST7789V3_Config *config)
 Toggle the hardware reset line using the driver's reset sequence.
 
void InvertDisplay (ST7789V3_Config *config, Inversion_Mode Inversion)
 Enable or disable display inversion.
 
void SleepMode (ST7789V3_Config *config, Sleep_State sleepstate)
 Put the display into sleep mode or wake it up.
 
Drawing API

Functions for rendering pixels, text, and basic shapes.

int8_t DrawPixel (ST7789V3_Config *config, uint16_t x, uint16_t y, uint32_t hexcolor)
 Draw a single pixel using a 24-bit RGB888 input color.
 
void DrawChar (ST7789V3_Config *config, uint16_t x, uint16_t y, char user_char, uint32_t hexcolor, const FontDef *font)
 Draw a single printable ASCII character.
 
void FillScreen (ST7789V3_Config *config, uint32_t hexcolor)
 Fill the entire display with a single color.
 
void SetRotation (ST7789V3_Config *config, Orientation orientation)
 Change the logical display rotation.
 
void DrawString (ST7789V3_Config *config, uint16_t x, uint16_t y, const char *str, uint32_t hexcolor, const FontDef *font)
 Draw a null-terminated string.
 
void DrawLine (ST7789V3_Config *config, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t hexcolor)
 Draw a line between two points using Bresenham's algorithm.
 
void DrawRectangle (ST7789V3_Config *config, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t hexcolor)
 Draw an unfilled rectangle outline.
 
void DrawFilledRectangle (ST7789V3_Config *config, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t hexcolor)
 Draw a filled rectangle.
 
void DrawCircle (ST7789V3_Config *config, uint16_t x_center, uint16_t y_center, uint16_t radius, uint32_t hexcolor)
 Draw a circle outline using the midpoint circle algorithm.
 
void DrawFilledCircle (ST7789V3_Config *config, uint16_t x_center, uint16_t y_center, uint16_t radius, uint32_t hexcolor)
 Draw a filled circle using the midpoint circle algorithm.
 
DMA API

Optional non-blocking transfer helpers.

int8_t ST7789V3_WriteBuffer_DMA (ST7789V3_Config *config, const uint8_t *buf, uint16_t len)
 Start a non-blocking DMA write of pixel data to the display.
 
void ST7789V3_DMA_Complete (ST7789V3_Config *config)
 Finish a successful DMA transfer and run the completion callback.
 
void ST7789V3_DMA_Error (ST7789V3_Config *config)
 Finish a failed DMA transfer and run the error callback.
 

Enums and Types

Public state, mode, and callback types used by the driver.

enum  GPIO_Pinstate { HIGH = 1 , LOW = 0 }
 Logical output level used by GPIO control callbacks. More...
 
enum  Trans_State { DATA = 1 , CMD = 0 }
 Select whether the current SPI byte stream is command or pixel/data content. More...
 
enum  Color_Mode { bit_12 = 0x03U , bit_16 = 0x05U , bit_18 = 0x06U }
 Pixel format written to the display controller. More...
 
enum  Inversion_Mode { INVON = 1 , INVOFF = 0 }
 Display inversion mode selection. More...
 
enum  Sleep_State { Asleep = 0 , Awake = 1 }
 Sleep state selection for the display. More...
 
enum  Orientation { Portrait = 0 , Landscape = 1 , Portrait_Inverted = 2 , Landscape_Inverted = 3 }
 Logical display orientation used by SetRotation. More...
 
enum  ST7789V3_State { ST7789_STATE_READY = 0 , ST7789_STATE_BUSY = 1 , ST7789_STATE_ERROR = 2 }
 Driver transfer state used for DMA operations. More...
 
typedef struct ST7789V3_Config ST7789V3_Config
 Forward declaration of the driver configuration structure.
 
typedef void(* ST7789V3_Callback) (ST7789V3_Config *config, void *user_data)
 Callback signature used for DMA completion and error notifications.
 

Detailed Description

Public API for the ST7789V3 SPI display driver.

This module provides a small, platform-agnostic interface for controlling an ST7789V3-based display over SPI. The application supplies the hardware access callbacks in ST7789V3_Config, then uses the driver to initialize the display, configure core display settings, draw graphics primitives, and optionally stream pixel buffers with DMA.

Typical responsibilities handled by this header include:

  • Display initialization and reset flow
  • Display mode control such as sleep, inversion, and rotation
  • Drawing text, pixels, lines, rectangles, and circles
  • Optional non-blocking DMA pixel transfers with completion callbacks

Example setup:

ST7789V3_Config config = {0};
config.set_cs = set_cs;
config.set_dc = set_dc;
config.set_rst = set_rst;
config.spi_write = spi_write;
config.spi_write_dma = spi_write_dma;
config.delay_ms = HAL_Delay;
config.LCD_Width = 172;
config.LCD_Height = 320;
ST7789V3_init(&config);
FillScreen(&config, BLACK);
DrawString(&config, 16, 32, "Hello", WHITE, &Font_16x16);
const FontDef Font_16x16
Definition font_16x16.c:1622
void FillScreen(ST7789V3_Config *config, uint32_t hexcolor)
Fill the entire LCD with a single RGB565 color. e.g take orange convert it to 5 bit 6 bit 5 bit TODO:...
Definition ST7789V3.c:228
void ST7789V3_init(ST7789V3_Config *config)
Initialize the display and apply the default startup sequence.
Definition ST7789V3.c:32
void DrawString(ST7789V3_Config *config, uint16_t x, uint16_t y, const char *str, uint32_t hexcolor, const FontDef *font)
Draw a null-terminated string.
Definition ST7789V3.c:340
#define BLACK
Definition ST7789V3.h:79
#define WHITE
Definition ST7789V3.h:80
@ ST7789_STATE_READY
Definition ST7789V3.h:165
Runtime configuration and hardware binding for one display instance.
Definition ST7789V3.h:199
uint16_t LCD_Height
Definition ST7789V3.h:211
int8_t(* set_rst)(GPIO_Pinstate state)
Definition ST7789V3.h:207
uint16_t LCD_Width
Definition ST7789V3.h:210
void(* delay_ms)(uint32_t milliseconds)
Definition ST7789V3.h:203
volatile ST7789V3_State State
Definition ST7789V3.h:218
int8_t(* set_dc)(Trans_State state)
Definition ST7789V3.h:206
int8_t(* set_cs)(GPIO_Pinstate state)
Definition ST7789V3.h:205
int8_t(* spi_write_dma)(uint16_t len, const uint8_t *pData)
Definition ST7789V3.h:202
int8_t(* spi_write)(uint16_t len, const uint8_t *pData)
Definition ST7789V3.h:200