Longan Nano
Longan Nano Demo
|
Longan Nano Display Driver. More...
#include <ST7735S_W160_H80_C16.hpp>
Classes | |
struct | _Sprite |
Sprite informations. More... | |
Public Member Functions | |
Display (void) | |
constructor Display | void | More... | |
~Display (void) | |
destructor ~Display | void | More... | |
bool | init (void) |
Public init init | void |. More... | |
int | register_sprite (int origin_h, int origin_w, int size_h, int size_w, uint16_t *sprite_ptr) |
public method register_sprite | int | int | int | int | uint16_t * | More... | |
int | register_sprite (int origin_h, int origin_w, int size_h, int size_w, uint16_t sprite_color) |
public method register_sprite | int | int | int | int | uint16_t | More... | |
bool | update_sprite (void) |
public method update_sprite | void | More... | |
int | draw_sprite (int origin_h, int origin_w, int size_h, int size_w, uint16_t *sprite_ptr) |
public method draw_sprite | int | int | int | int | uint16_t * | More... | |
int | draw_sprite (int origin_h, int origin_w, int size_h, int size_w, uint16_t sprite_color) |
public method draw_sprite | int | int | int | int | uint16_t | More... | |
int | clear (void) |
public method clear | void | More... | |
int | clear (uint16_t color) |
public method clear | void | More... | |
Static Public Member Functions | |
static uint16_t | color (uint8_t r, uint8_t g, uint8_t b) |
Public Method color | uint8_t | uint8_t | uint8_t |. More... | |
Protected Types | |
enum | _Config { WIDTH = 160, HEIGHT = 80, PIXEL_COUNT = WIDTH *HEIGHT, COLOR_DEPTH = 16, ROW_ADDRESS_OFFSET = 1, COL_ADDRESS_OFFSET = 26, RS_GPIO = GPIOB, RS_PIN = GPIO_PIN_0, RST_GPIO = GPIOB, RST_PIN = GPIO_PIN_1, RESET_DELAY = 1, SPI_CH = SPI0, SPI_CS_GPIO = GPIOB, SPI_CS_PIN = GPIO_PIN_2, SPI_CLK_GPIO = GPIOA, SPI_CLK_PIN = GPIO_PIN_5, SPI_MISO_GPIO = GPIOA, SPI_MISO_PIN = GPIO_PIN_6, SPI_MOSI_GPIO = GPIOA, SPI_MOSI_PIN = GPIO_PIN_7, USE_DMA = true, DMA_SPI_TX = DMA0, DMA_SPI_TX_CH = (dma_channel_enum)DMA_CH2 } |
Configuration parameters of the LCD Display class. More... | |
typedef enum Longan_nano::Display::_Config | Config |
Configuration parameters of the LCD Display class. More... | |
Private Types | |
enum | _Command { SETUP_NORMAL_MODE = 0xB1, SETUP_IDLE_MODE = 0xB2, SETUP_PARTIAL_MODE = 0xB3, DISPLAY_INVERSION_CONTROL = 0xB4, POWER_GVDD = 0xC0, POWER_VGH_VGL = 0xC1, POWER_VCOM1 = 0xC5, POWER_MODE_NORMAL = 0xC2, POWER_MODE_IDLE = 0xC3, POWER_MODE_PARTIAL = 0xC4, ADJUST_GAMMA_PLUS = 0xE0, ADJUST_GAMMA_MINUS = 0xE1, COLOR_FORMAT = 0x3A, MEMORY_DATA_ACCESS_CONTROL = 0x36, DISPLAY_ON = 0x29, SLEEP_OUT_BOOSTER_ON = 0x11, ENABLE_DISPLAY_INVERSION = 0x21, SEND_ROW_ADDRESS = 0x2A, SEND_COL_ADDRESS = 0x2B, WRITE_MEM = 0x2C, TERMINATOR = 0xFF } |
ST7735S Commands. More... | |
typedef enum Longan_nano::Display::_Command | Command |
ST7735S Commands. More... | |
typedef struct Longan_nano::Display::_Sprite | Sprite |
Sprite informations. More... | |
Private Member Functions | |
bool | init_gpio (void) |
Private init init_gpio | void |. More... | |
bool | init_spi (void) |
Private init init_spi | void |. More... | |
bool | init_dma (void) |
Private init init_dma | void |. More... | |
bool | init_st7735 (void) |
Private init init_st7735 | void |. More... | |
bool | is_spi_idle (void) |
Private HAL Method is_spi_idle | void. More... | |
bool | is_spi_done_tx (void) |
Private HAL Method is_spi_done_tx | void. More... | |
void | spi_wait_idle (void) |
Private HAL Method spi_wait_idle | void. More... | |
void | spi_wait_tbe (void) |
Private HAL Method spi_wait_tbe | void |. More... | |
void | cs_active (void) |
Private HAL Method cs_active | void |. More... | |
void | cs_inactive (void) |
Private HAL Method cs_inactive | void |. More... | |
void | rs_mode_cmd (void) |
Private HAL Method rs_mode_cmd | void |. More... | |
void | rs_mode_data (void) |
Private HAL Method rs_mode_data | void |. More... | |
void | rst_active (void) |
Private HAL Method rst_active | void |. More... | |
void | rst_inactive (void) |
Private HAL Method rst_inactive | void |. More... | |
void | spi_set_8bit (void) |
Private HAL Method spi_set_8bit | void |. More... | |
void | spi_set_16bit (void) |
Private HAL Method spi_set_16bit | void |. More... | |
void | dma_send_map16 (uint16_t *data_ptr, uint16_t data_size) |
Private HAL Method dma_send_map16 | uint16_t * | uint16_t |. More... | |
void | dma_send_solid16 (uint16_t *data_ptr, uint16_t data_size) |
Private HAL Method dma_send_map16 | uint16_t * | uint16_t |. More... | |
Private Attributes | |
Sprite | g_sprite |
Runtime sprite informations. More... | |
uint16_t | g_address_buffer [2] |
Buffer to send address data using DMA. More... | |
uint32_t | g_sprite_status |
FSM status. More... | |
Static Private Attributes | |
static constexpr uint8_t | g_st7735s_init_sequence [] |
ST7735S initialization sequence. Stored in flash memory. More... | |
Longan Nano Display Driver.
Driver to use the embedded 160x80 0.96' LCD on the longan nano
SPI0 interface with physical screen
DMA0: executes a number of SPI0 transfers in background
Hardware display has a ST7735S controller
The driver is meant to accelerate sprite based drawing
Sprite buffer and draw are going to be handled by an higher level class
2020-07-07
Ported original LCD example to class. Basic operation. DMA doesn't work
2020-07-08
Skeletron for sprites
2020-07-10
Change architecture. S7735S_W160_H80_C16.hpp. Common name drive class: Display
With another display controller, Screen class and Display class interface remains the same
S7735S_W160_H80_C16.hpp is the specific lbrary for the physical display
Clean up, partition in a more intelligent way calls. Test project for driver only without sprites
2020-07-15
Tested draw with HAL builtin
2020-07-21
Found working DMA example from Samuli Laine https://github.com/slmisc/gd32v-lcd
2020-07-22
Transplant working driver function
Refactor function to use configuration and fit class form
set_sprite and update_sprite provide a non blocking draw method that hide the wait time
application can call update_sprite and immediately continue to do work while SPI and DMA are busy
update_sprite will immediately return without doing work if SPI or DMA are busy or if there is nothing to draw
2020-07-23
Clean up example
Prune excess methods from display class. Leave only the draw sprite primitives. Application is to be given control on resource utilization of the display
Refactor all calls to use configuration enum for the hardware peripherals
2020-07-24
Fixed color conversion function
2020-08-06
Massive update of style
Refactor functions, especially initialization
Full support for USE_DMA=false. screen updates much slower at the same CPU use
2020-08-07
Bugfix: Solid color draw was bugged
|
private |
ST7735S Commands.
|
protected |
Configuration parameters of the LCD Display class.
|
private |
Sprite informations.
|
private |
ST7735S Commands.
|
protected |
Configuration parameters of the LCD Display class.
Longan_nano::Display::Display | ( | void | ) |
constructor Display | void |
initialize display class
will NOT initialize the peripherals
Longan_nano::Display::~Display | ( | void | ) |
destructor ~Display | void |
|
inline |
public method clear | void |
color | | uint16_t | clear the display to a solid color |
Clear the screen. Blocking method.
Draw a black sprite the size of the screen
|
inline |
public method clear | void |
Clear the screen. Blocking method.
Draw a black sprite the size of the screen
|
static |
Public Method color | uint8_t | uint8_t | uint8_t |.
r | | uint8_t | 8bit red color channel |
g | | uint8_t | 8bit green color channel |
b | | uint8_t | 8bit blue color channel |
convert from 24b 8R8G8B space to 16bit 5R6G5B space
RRRRRRRR
GGGGGGGG
BBBBBBBB
RRRRRGGGGGGBBBBB
|
inlineprivate |
Private HAL Method cs_active | void |.
Select the ST7735 Display
|
inlineprivate |
Private HAL Method cs_inactive | void |.
Deselect the ST7735 Display
|
inlineprivate |
Private HAL Method dma_send_map16 | uint16_t * | uint16_t |.
data_ptr | | uint16_t * | pointer to RGB565 pixel color map |
data_size | | uint16_t | size of the pixel color map in pixels |
Use the DMA to send a 16b memory through the SPI
|
inlineprivate |
Private HAL Method dma_send_map16 | uint16_t * | uint16_t |.
data_ptr | | uint16_t * | pointer to RGB565 solid color for the full sprite |
data_size | | uint16_t | size of the pixel color map in pixels |
Use the DMA to send a 16b data through the SPI a number of times
int Longan_nano::Display::draw_sprite | ( | int | origin_h, |
int | origin_w, | ||
int | size_h, | ||
int | size_w, | ||
uint16_t * | sprite_ptr | ||
) |
public method draw_sprite | int | int | int | int | uint16_t * |
origin_h | | int | starting top left corner height of the sprite |
origin_w | | int | starting top left corner height of the sprite |
size_h | | int | height size of the sprite |
size_w | | int | width size of the sprite |
sprite_ptr | | uint16_t * | pointer to RGB565 pixel color map |
Draw a sprite
Blocking method
Draw a color map, requires a user buffer of the proper size
int Longan_nano::Display::draw_sprite | ( | int | origin_h, |
int | origin_w, | ||
int | size_h, | ||
int | size_w, | ||
uint16_t | sprite_color | ||
) |
public method draw_sprite | int | int | int | int | uint16_t |
origin_h | | int | starting top left corner height of the sprite |
origin_w | | int | starting top left corner height of the sprite |
size_h | | int | height size of the sprite |
size_w | | int | width size of the sprite |
sprite_color | | uint16_t | RGB565 pixel solid color for the full sprite |
Draw a sprite
Blocking method
Draw a solid color sprite and doesn't require a color map
bool Longan_nano::Display::init | ( | void | ) |
Public init init | void |.
initialize the longan nano display and related peripherals
|
inlineprivate |
Private init init_dma | void |.
Initialize DMA that accelerates the SPI
|
inlineprivate |
Private init init_gpio | void |.
HAL method
initialize GPIO configuration
|
inlineprivate |
Private init init_spi | void |.
HAL method
Initialize SPI that communicates with the Display
|
private |
Private init init_st7735 | void |.
Send initialization sequence to the ST7735 display controller
First byte in the sequence is command
Next bytes in the sequence are terminators
If the command is a terminator, it means the initialization sequence is complete
|
inlineprivate |
Private HAL Method is_spi_done_tx | void.
return true when the SPI is done TX
|
inlineprivate |
Private HAL Method is_spi_idle | void.
return true when the SPI is IDLE
int Longan_nano::Display::register_sprite | ( | int | origin_h, |
int | origin_w, | ||
int | size_h, | ||
int | size_w, | ||
uint16_t * | sprite_ptr | ||
) |
public method register_sprite | int | int | int | int | uint16_t * |
origin_h | | int | starting top left corner height of the sprite |
origin_w | | int | starting top left corner height of the sprite |
size_h | | int | height size of the sprite |
size_w | | int | width size of the sprite |
sprite_ptr | | uint16_t * | pointer to RGB565 pixel color map |
Ask the driver to draw a sprite
The draw method handles sprites that fill only part of the screen
If reworked, the buffer stays the same or is smaller than user buffer
1) Sprite fully inside screen area: the sprite is queued for draw
2) Sprite is fully outside screen area: no pixels are queued for draw
3) sprite is partially outside screen area: the method rework the buffer to include only pixel that can be drawn
int Longan_nano::Display::register_sprite | ( | int | origin_h, |
int | origin_w, | ||
int | size_h, | ||
int | size_w, | ||
uint16_t | sprite_color | ||
) |
public method register_sprite | int | int | int | int | uint16_t |
origin_h | | int | starting top left corner height of the sprite |
origin_w | | int | starting top left corner height of the sprite |
size_h | | int | height size of the sprite |
size_w | | int | width size of the sprite |
sprite_color | | uint16_t | RGB565 pixel solid color for the full sprite |
Ask the driver to draw a sprite with a solid color
The draw method handles sprites that fill only part of the screen
If reworked, the buffer stays the same or is smaller than user buffer
1) Sprite fully inside screen area: the sprite is queued for draw
2) Sprite is fully outside screen area: no pixels are queued for draw
3) sprite is partially outside screen area: the method rework the buffer to include only pixel that can be drawn
|
inlineprivate |
Private HAL Method rs_mode_cmd | void |.
Send a command to the display
|
inlineprivate |
Private HAL Method rs_mode_data | void |.
Send data to the display
|
inlineprivate |
Private HAL Method rst_active | void |.
Assert the reset pin of the physical display
The display will need time to become ready after an assert
|
inlineprivate |
Private HAL Method rst_inactive | void |.
Deassert the reset pin of the physical display
|
inlineprivate |
Private HAL Method spi_set_16bit | void |.
Configure the SPI to 16b
|
inlineprivate |
Private HAL Method spi_set_8bit | void |.
Configure the SPI to 8b
|
inlineprivate |
Private HAL Method spi_wait_idle | void.
Block execution until SPI is IDLE
|
inlineprivate |
Private HAL Method spi_wait_tbe | void |.
Block execution until SPI is done TX
bool Longan_nano::Display::update_sprite | ( | void | ) |
public method update_sprite | void |
Execute a step of the FSM that interfaces with the physical display
Handle both solid color and color map
sprite data must already be valid before execution
|
private |
Buffer to send address data using DMA.
|
private |
Runtime sprite informations.
|
private |
FSM status.
|
staticconstexprprivate |
ST7735S initialization sequence. Stored in flash memory.