Longan Nano
Longan Nano Demo
Longan_nano::Screen Class Reference

Longan Nano Screen Class. More...

#include <longan_nano_screen.hpp>

Inheritance diagram for Longan_nano::Screen:
Collaboration diagram for Longan_nano::Screen:

Classes

struct  _Format_number
 number format to be printed by the print number method More...
 
struct  _Frame_buffer_sprite
 Structure that describes a sprite in the sprite frame buffer. More...
 
struct  _Fsm_status
 Status of the update FSM. More...
 

Public Types

enum  _Config {
  PEDANTIC_CHECKS = true, SPRITE_WIDTH = 8, SPRITE_HEIGHT = FONT_HEIGHT, SPRITE_PIXEL_COUNT = SPRITE_HEIGHT *SPRITE_WIDTH,
  SPRITE_SCAN_LIMIT = 5, NUM_SPECIAL_SPRITES = 5, SPRITE_TRANSPARENT = 0, SPRITE_BLACK = 1,
  SPRITE_WHITE = 2, SPRITE_BACKGROUND = 3, SPRITE_FOREGROUND = 4, ASCII_START = ' ',
  ASCII_STOP = '~', PALETTE_SIZE = 16, PALETTE_SIZE_BIT = 4, FRAME_BUFFER_WIDTH = Longan_nano::Display::Config::WIDTH /SPRITE_WIDTH,
  FRAME_BUFFER_HEIGHT = Longan_nano::Display::Config::HEIGHT /SPRITE_HEIGHT, FRAME_BUFFER_SIZE = FRAME_BUFFER_WIDTH *FRAME_BUFFER_HEIGHT, SPRITE_SIZE = 128, SPRITE_SIZE_BIT = 7
}
 Configuration parameters for the logical screen. More...
 
enum  _Color {
  BLACK, BLUE, GREEN, CYAN,
  RED, MAGENTA, BROWN, LGRAY,
  DGRAY, LBLUE, LGREEN, LCYAN,
  LRED, LMAGENTA, YELLOW, WHITE
}
 Use the default Color palette. Short hand indexes for user. User can change the palette at will. More...
 
enum  _Format_format { NUM, ENG }
 Possible number configurations. More...
 
enum  _Format_align { ADJ_LEFT, ADJ_RIGHT }
 Left or Right alignment for a number. More...
 
enum  _Error {
  OK, PENDING_OVERFLOW, PENDING_UNDERFLOW, REGISTER_SPRITE_FAIL,
  BAD_ERROR_CODE, NUM_ERROR_CODES
}
 Enumerate possible error of the Screen class. More...
 
typedef enum Longan_nano::Screen::_Config Config
 Configuration parameters for the logical screen. More...
 
typedef enum Longan_nano::Screen::_Color Color
 Use the default Color palette. Short hand indexes for user. User can change the palette at will. More...
 
typedef enum Longan_nano::Screen::_Format_format Format_format
 Possible number configurations. More...
 
typedef enum Longan_nano::Screen::_Format_align Format_align
 Left or Right alignment for a number. More...
 
typedef enum Longan_nano::Screen::_Error Error
 Enumerate possible error of the Screen class. More...
 

Public Member Functions

 Screen (void)
 empty constructor Screen | void More...
 
 ~Screen (void)
 empty destructor ~Screen | void | More...
 
bool init (void)
 public init init | void More...
 
bool reset_colors (void)
 public init reset_colors |
More...
 
int set_color (int origin_h, int origin_w, Color background, Color foreground)
 public setter set_color | int | int | Color | Color More...
 
int set_default_colors (Color new_background, Color new_foreground)
 public setter set_default_colors | Color | Color More...
 
int set_palette_color (Color palette_index, uint8_t r, uint8_t g, uint8_t b)
 public setter set_palette_color | Color | uint8_t | uint8_t | uint8_t | More...
 
bool set_format (int number_size, Format_align align, Format_format format)
 public setter set_format | int | Format_align | Format_format | More...
 
bool set_format (int number_size, Format_align align, Format_format format, int exp)
 public setter set_format | int | Format_align | Format_format | int | More...
 
int get_pending (void)
 public getter get_pending | void | More...
 
Error get_error (void)
 public getter get_pending | void | More...
 
bool update (void)
 public method update | void More...
 
int change_color (Color source, Color dest)
 public method change_color | Color | Color | More...
 
int clear (void)
 public method clear | void | More...
 
int clear (Color color_tmp)
 public method clear | Color | More...
 
int print (int origin_h, int origin_w, char c, Color background, Color foreground)
 public method print | int | int | char | Color | Color More...
 
int print (int origin_h, int origin_w, char c, Color foreground)
 public method print | int | int | char | Color More...
 
int print (int origin_h, int origin_w, char c)
 public method print | int | int | char | More...
 
int print (int origin_h, int origin_w, const char *str, Color background, Color foreground)
 public method print | int | int | const char * | Color | Color | More...
 
int print (int origin_h, int origin_w, const char *str, Color foreground)
 public method print | int | int | const char* | Color | More...
 
int print (int origin_h, int origin_w, const char *str)
 public method print | int | int | const char* | More...
 
int print (int origin_h, int origin_w, int num, Color background, Color foreground)
 public method print | int | int | int | Color | Color | More...
 
int print (int origin_h, int origin_w, int num, Color foreground)
 public method print | int | int | int | Color |
More...
 
int print (int origin_h, int origin_w, int num)
 public method print | int | int | int | More...
 
int paint (int origin_h, int origin_w, Color color)
 public method paint | int | int | Color | More...
 
int print_err (int origin_h, int origin_w)
 public method print_err | int | int | 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...
 

Private Types

enum  _Fsm_state { SCAN_SPRITE, SEND_SPRITE }
 States of the Screen side FSM. Display driver also has its own FSM states
More...
 
typedef enum Longan_nano::Screen::_Fsm_state Fsm_state
 States of the Screen side FSM. Display driver also has its own FSM states
More...
 
typedef struct Longan_nano::Screen::_Frame_buffer_sprite Frame_buffer_sprite
 Structure that describes a sprite in the sprite frame buffer. More...
 
typedef struct Longan_nano::Screen::_Fsm_status Fsm_status
 Status of the update FSM. More...
 
typedef struct Longan_nano::Screen::_Format_number Format_number
 number format to be printed by the print number method More...
 
- Private Types inherited from Longan_nano::Display
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 Member Functions

bool init_class_vars (void)
 private init init_class_vars | void | More...
 
bool init_frame_buffer (void)
 private init init_frame_buffer | void More...
 
bool init_default_colors (void)
 private init init_default_colors | void | More...
 
bool init_palette (void)
 private init init_palette | void More...
 
bool init_fsm (void)
 private init init_fsm | void | More...
 
bool is_valid_char (char c)
 private tester is_valid_char | char | More...
 
bool is_using_background (uint8_t sprite)
 private tester is_using_background | uint8_t | More...
 
bool is_using_foreground (uint8_t sprite)
 private tester is_using_foreground | uint8_t | More...
 
bool is_same_sprite (Frame_buffer_sprite sprite_a, Frame_buffer_sprite sprite_b)
 private tester is_same_sprite | Frame_buffer_sprite | Frame_buffer_sprite | More...
 
int8_t register_sprite (uint16_t index_h, uint16_t index_w)
 private method register_sprite | uint16_t | uint16_t | More...
 
int8_t update_sprite (uint16_t index_h, uint16_t index_w, Frame_buffer_sprite new_sprite)
 private tester update_sprite | uint16_t | uint16_t | Frame_buffer_sprite | More...
 
void report_error (Error error_code)
 private setter report_error | Error | More...
 
- Private Member Functions inherited from Longan_nano::Display
 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...
 

Private Attributes

Error g_error_code
 Error code of the library. Default is Error::OK. More...
 
Color g_default_background_color
 Default background and foreground colors to be used. More...
 
Color g_default_foreground_color
 
uint16_t g_palette [Config::PALETTE_SIZE]
 Color Palette. One special code for transparent. Two special indexes store global background and foreground. More...
 
Frame_buffer_sprite g_frame_buffer [Config::FRAME_BUFFER_HEIGHT][Config::FRAME_BUFFER_WIDTH]
 Frame Buffer. More...
 
uint16_t g_pending_cnt
 Track the number of sprites that require update. At zero the update method quit without scanning and print methods will set the scan to the correct index. More...
 
uint16_t g_pixel_data [Config::SPRITE_PIXEL_COUNT]
 Sprite buffer that stores raw pixel data for a single sprite. More...
 
Fsm_status g_status
 Status of the update FSM. More...
 
Format_number g_format_number
 Display format for print numeric values. More...
 

Static Private Attributes

static constexpr uint8_t g_ascii_sprites [96 *10]
 ASCII Sprites. Stored in the flash memory. 95 sprites from space ' ' code 32 to tilda '~' code 126 + special code 127. FONT_HEIGHT is used to change font. More...
 

Additional Inherited Members

- Static Private Member Functions inherited from Longan_nano::Display
static uint16_t color (uint8_t r, uint8_t g, uint8_t b)
 Public Method color | uint8_t | uint8_t | uint8_t |. More...
 

Detailed Description

Longan Nano Screen Class.

Author
Orso Eric
Version
2020-08-08
Date
2020-07-09


Screen class: abstraction layer for low level LCD HAL for the ST7735S Longan Nano Display
Screen provides a frame buffer and functions to write on it
LCD class: low level driver for screen hardware. Inherited by screen
2020-07-09
Formulated architeture
Focus on Display dirver first
2020-07-23
Display driver working
Core methods: register_sprite and update
Formulated palette, frame sprite and sprite pixel buffer architecture
Use 16x08 sprites. They already exists and 8 by 8 are too small
Structure of the Screen Update FSM Up
FSM is partitioned into the Display side FSM that handles the physical display and the Screen side FSM that handles the sprite based frame buffer
Screen class is designed to massively reduce memory usage and data sent to physical display. Most of the time I need fast updating characters and nothing more.
2020-07-24
Added through debug
BUG: Color decoding macro: FIXED
Test clear black and white inherited from display: SUCCESS
clear function tested with background calls from update and periodic calls of clear triggered by the RTC interrupt
Test clear screen cycling colors from the palette: SUCCESS
2020-07-25
Test random characters in random position: SUCCESS
"is_same" check if two sprites are the same looking for all the nuances
"paint" method, meant to draw special graphics sprites
"Symbol" enum, meant to provide a few graphical sprites. Few in numbers and meant for light graphics, like progress bars.
Test draw a random sprite with a random color:
2020-07-26
Test print string functions: SUCCESS
Change architecture: do not use RTC ISR but use chrono class for timings. Save a peripheral and achieve a mini hardwired scheduler. PA8 release button switches between demos: SUCCESS
2020-07-27
print number with format
User::String class handles number to string conversion up to 32b signed and unsigned
2020-07-28
tested print numbers with format: SUCCESS
bugfix: check that the number fits than the allowed size. Caused dot artifacts on screen
2020-07-29
"change_color" allow to change the color of all sprites from one to another. E.G. red background to blue background
"set_default_colors" allow to set the default background and foreground colors to be used. Change all the sprites that use those colors as well
"set_palette_color" change a color in the palette. Mark all the sprites that use those colors for update
2020-07-30
color methods
2020-07-31
change color demo
with this release, I have a working screen library that does all I need it to do with 2.804% CPU usage at 100uS slice time
I will add to this library as i work on the end applications and find bugs and shortcomings
BUGFIX: print string had a botched same sprite detection 0.18% absolute performance improvement
Now print number won't refresh sprites that have not changed
Migrated print functions to return the number of updated sprites. -1 if error
2020-08-03
g_pending_cnt was meant to skip scan if zero sprites need updating in the frame buffer
it just increases CPU use overall, so was removed
Paint square method. Removed Symbols.
2020-08-04
Unpack methods from class to make the header interface clear while keeping the implementation in the .hpp
Complete doxygen documentation for all methods
2020-08-06
Add pending_cnt. When counter is zero, the update method won't waste time scanning and print method will start seeking from the first valid sprite saving CPU
Adding error codes and print_err
Add rule. allow conditional formatting of number based on rules
Generated two fonts. 16 pixel height NSimSun and 10 pixel height Courier Now
2020-08-07
Bugfix: Driver wasn't taking advantage of the Display solid color register method to avoid computing a complex color map
and was always computing a full color map. Now solid sprites just send one color.
2020-08-08
Bugfix: The draw string with colors and set color methods sometimes didn't update the sprites correctly
either duplicating the previous char or leaving an artifact on pixel 0,0 of the sprite
it was caused by the update FSM disagreeing on which sprites were solid colors or color maps
now a register_sprite method combine the processing of color data and registering of sprites
this reduces workload and solves the bug. Now Screen::register_sprite and Display::register_sprite nicely handle the hierarchy
just like Screen::update and Display::update

Member Typedef Documentation

◆ Color

Use the default Color palette. Short hand indexes for user. User can change the palette at will.

◆ Config

Configuration parameters for the logical screen.

◆ Error

Enumerate possible error of the Screen class.

◆ Format_align

Left or Right alignment for a number.

◆ Format_format

Possible number configurations.

◆ Format_number

number format to be printed by the print number method

◆ Frame_buffer_sprite

Structure that describes a sprite in the sprite frame buffer.

◆ Fsm_state

States of the Screen side FSM. Display driver also has its own FSM states

◆ Fsm_status

Status of the update FSM.

Member Enumeration Documentation

◆ _Color

Use the default Color palette. Short hand indexes for user. User can change the palette at will.

Enumerator
BLACK 
BLUE 
GREEN 
CYAN 
RED 
MAGENTA 
BROWN 
LGRAY 
DGRAY 
LBLUE 
LGREEN 
LCYAN 
LRED 
LMAGENTA 
YELLOW 
WHITE 

◆ _Config

Configuration parameters for the logical screen.

Enumerator
PEDANTIC_CHECKS 
SPRITE_WIDTH 
SPRITE_HEIGHT 
SPRITE_PIXEL_COUNT 
SPRITE_SCAN_LIMIT 
NUM_SPECIAL_SPRITES 
SPRITE_TRANSPARENT 
SPRITE_BLACK 
SPRITE_WHITE 
SPRITE_BACKGROUND 
SPRITE_FOREGROUND 
ASCII_START 
ASCII_STOP 
PALETTE_SIZE 
PALETTE_SIZE_BIT 
FRAME_BUFFER_WIDTH 
FRAME_BUFFER_HEIGHT 
FRAME_BUFFER_SIZE 
SPRITE_SIZE 
SPRITE_SIZE_BIT 

◆ _Error

Enumerate possible error of the Screen class.

Enumerator
OK 
PENDING_OVERFLOW 
PENDING_UNDERFLOW 
REGISTER_SPRITE_FAIL 
BAD_ERROR_CODE 
NUM_ERROR_CODES 

◆ _Format_align

Left or Right alignment for a number.

Enumerator
ADJ_LEFT 
ADJ_RIGHT 

◆ _Format_format

Possible number configurations.

Enumerator
NUM 
ENG 

◆ _Fsm_state

States of the Screen side FSM. Display driver also has its own FSM states

Enumerator
SCAN_SPRITE 
SEND_SPRITE 

Constructor & Destructor Documentation

◆ Screen()

Longan_nano::Screen::Screen ( void  )

empty constructor Screen | void


Empty constructor

Here is the call graph for this function:

◆ ~Screen()

Longan_nano::Screen::~Screen ( void  )

empty destructor ~Screen | void |


Void destructor

Member Function Documentation

◆ change_color()

int Longan_nano::Screen::change_color ( Color  source,
Color  dest 
)

public method change_color | Color | Color |

Parameters
source| Color | color to be changed
dest| Color | replacement color
Returns
int | >=0 Number of sprites changed | < 0 error |

Every sprite that use the "source" palette color as either background or foreground has it swapped for the "dest" palette color. All changed sprites are marked for update

Here is the call graph for this function:

◆ clear() [1/2]

int Longan_nano::Screen::clear ( Color  color_tmp)

public method clear | Color |

Parameters
color_tmp| Color | index of the solid sprite in the palette
Returns
int | >=0 Number of sprites changed | < 0 error |


Clear the screen by setting a solid color sprite to each element of the sprite frame buffer

Here is the call graph for this function:

◆ clear() [2/2]

int Longan_nano::Screen::clear ( void  )

public method clear | void |

Returns
int | >=0 Number of sprites changed | < 0 error |


Clear the screen by setting a solid color sprite to each element of the sprite frame buffer

Here is the call graph for this function:
Here is the caller graph for this function:

◆ color()

uint16_t Longan_nano::Display::color
static

Public Method color | uint8_t | uint8_t | uint8_t |.

Parameters
r| uint8_t | 8bit red color channel
g| uint8_t | 8bit green color channel
b| uint8_t | 8bit blue color channel
Returns
uint16_t | RGB565 color compatible with ST7735 display color space


convert from 24b 8R8G8B space to 16bit 5R6G5B space
RRRRRRRR
GGGGGGGG
BBBBBBBB
RRRRRGGGGGGBBBBB

◆ get_error()

Screen::Error Longan_nano::Screen::get_error ( void  )

public getter get_pending | void |

Returns
int | number of sprites pending for update in the frame buffer


return the number of sprites pending for update in the frame buffer


RETURN

Here is the caller graph for this function:

◆ get_pending()

int Longan_nano::Screen::get_pending ( void  )

public getter get_pending | void |

Returns
int | number of sprites pending for update in the frame buffer


return the number of sprites pending for update in the frame buffer


RETURN

Here is the caller graph for this function:

◆ init()

bool Longan_nano::Screen::init ( void  )

public init init | void

Returns
bool | false = OK | true = ERR


call the initializations for the driver

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_class_vars()

bool Longan_nano::Screen::init_class_vars ( void  )
private

private init init_class_vars | void |

Returns
bool | false = OK | true = ERR


Initialize the class vars

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_default_colors()

bool Longan_nano::Screen::init_default_colors ( void  )
inlineprivate

private init init_default_colors | void |

Returns
void


Initialize the default background and foreground colors

Here is the caller graph for this function:

◆ init_frame_buffer()

bool Longan_nano::Screen::init_frame_buffer ( void  )
private

private init init_frame_buffer | void

Returns
bool | false = OK | true = ERR


Initialize the sprite frame buffer

Here is the caller graph for this function:

◆ init_fsm()

bool Longan_nano::Screen::init_fsm ( void  )
private

private init init_fsm | void |

Returns
bool | false = OK | true = ERR


Initialize the update FSM machine

Here is the caller graph for this function:

◆ init_palette()

bool Longan_nano::Screen::init_palette ( void  )
private

private init init_palette | void

Returns
bool | false = OK | true = ERR


initialize palette to default values

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_same_sprite()

bool Longan_nano::Screen::is_same_sprite ( Frame_buffer_sprite  sprite_a,
Frame_buffer_sprite  sprite_b 
)
private

private tester is_same_sprite | Frame_buffer_sprite | Frame_buffer_sprite |

Returns
bool | false = different | true = same

check if sprite_a is functionally the same as sprite_b this is used to decide if mark a sprite for update or leave it as is this function is more nuanced that it appears this function is inside the drivers and assumes all relevant checks have been made by interface functions E.G. >a foreground sprite with with foreground is the same as a background sprite with white background E.G. >writing 'a' red on black is differet from writing 'a' green on black A change of a color in the palette will automatically mark for update all characters that use that palette color, but its taken care by the relevant function Because of that, no function but the update FSM is allowed to deactivate the update flag, so don't be overly aggressive with the result of this function

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_using_background()

bool Longan_nano::Screen::is_using_background ( uint8_t  sprite)
inlineprivate

private tester is_using_background | uint8_t |

Returns
bool | false = sprite do not use background color | true = sprite use background color

return true if the sprite make use of the background palette color

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_using_foreground()

bool Longan_nano::Screen::is_using_foreground ( uint8_t  sprite)
inlineprivate

private tester is_using_foreground | uint8_t |

Returns
bool | false = sprite do not use foreground color | true = sprite use foreground color

return true if the sprite make use of the foreground palette color

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_valid_char()

bool Longan_nano::Screen::is_valid_char ( char  c)
inlineprivate

private tester is_valid_char | char |

Returns
bool | false = INVALID | true =VALID

return true if the char is stored inside the ascii sprite table

Here is the caller graph for this function:

◆ paint()

int Longan_nano::Screen::paint ( int  origin_h,
int  origin_w,
Color  color 
)

public method paint | int | int | Color |

Returns
int16_t | >=0 Number of sprites changed | < 0 error |


Draw a solid color on the screen
There are ery few graphics sprite as they ar meant for progress bars and little more

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [1/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
char  c 
)
inline

public method print | int | int | char |

Parameters
origin_h| int | height position of the sprite
origin_w| int | width position of the sprite
c| char | ascii char to be drawn
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


print a char inside the sprite frame buffer and mark it for update if needs to be
uses default background and foreground colors

Here is the call graph for this function:

◆ print() [2/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
char  c,
Color  background,
Color  foreground 
)

public method print | int | int | char | Color | Color

Parameters
origin_h| int | height position of the sprite
origin_w| int | width position of the sprite
c| char | ascii char to be drawn
background| Color | background color of ths sprite as index from the palette
foreground| Color | foreground color of ths sprite as index from the palette
Returns
int | >=0 Number of sprites changed | < 0 error |
Todo:
add special non drawable sprite


Print a character on screen using user defined background and foreground colors
Mark the sprite for update if needs to be

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [3/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
char  c,
Color  foreground 
)
inline

public method print | int | int | char | Color

Parameters
origin_h| int | height position of the sprite
origin_w| int | width position of the sprite
c| char | ascii char to be drawn
foreground| Color | foreground color of ths sprite as index from the palette
Returns
int | >=0 Number of sprites changed | < 0 error |


Print a character on screen using default background color but a user defined foreground color

Here is the call graph for this function:

◆ print() [4/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
const char *  str 
)
inline

public method print | int | int | const char* |

Parameters
origin_h| int | height position of the sprite
origin_w| int | width position of the sprite
str| const char * | string to be drawn. Must be null terminated
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


print a char inside the sprite frame buffer and mark it for update if needs to be
uses default background and foreground colors
wrapper for more general print string function

Here is the call graph for this function:

◆ print() [5/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
const char *  str,
Color  background,
Color  foreground 
)

public method print | int | int | const char * | Color | Color |

Parameters
origin_h| int | height position of the sprite
origin_w| int | width position of the sprite
str| const char * | string to be drawn. Must be null terminated
background| Color | background color of ths sprite as index from the palette
foreground| Color | foreground color of ths sprite as index from the palette
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


Print a string on screen using user defined background and foreground colors
Strings will not wrap around the screen
String must be \0 terminated

Todo:
Use placeholder sprite (special '?')
Here is the call graph for this function:

◆ print() [6/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
const char *  str,
Color  foreground 
)
inline

public method print | int | int | const char* | Color |

Parameters
origin_h| int | height position of the sprite
origin_w| int | width position of the sprite
str| const char * | string to be drawn. Must be null terminated
foreground| Color | foreground color of ths sprite as index from the palette
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


print a char inside the sprite frame buffer and mark it for update if needs to be
use default background
wrapper for more general print string function

Here is the call graph for this function:

◆ print() [7/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
int  num 
)
inline

public method print | int | int | int |

Parameters
origin_h| int | height position of the first character
origin_w| int | width position of the first character
num| int | number to be shown on screen
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


Print a number on screen. Overload with default background and foreground

Here is the call graph for this function:

◆ print() [8/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
int  num,
Color  background,
Color  foreground 
)

public method print | int | int | int | Color | Color |

Parameters
origin_h| int | height position of the first character
origin_w| int | width position of the first character
num| int | number to be shown on screen
background| Color | background color of ths sprite as index from the palette
foreground| Color | foreground color of ths sprite as index from the palette
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


Print a number on screen. Format configuration is handled by format
With left asjust, the number is print starting from left an origin is the position of the most significant number
With right adjust, the origin is the position of the least significant number

LEFT 78901 12.71m
RIGHT 78901 12.71m
ORIGIN ^ ^
The format also specifies full number or enginnering format

Here is the call graph for this function:

◆ print() [9/9]

int Longan_nano::Screen::print ( int  origin_h,
int  origin_w,
int  num,
Color  foreground 
)
inline

public method print | int | int | int | Color |

Parameters
origin_h| int | height position of the first character
origin_w| int | width position of the first character
num| int | number to be shown on screen
foreground| Color | foreground color of ths sprite as index from the palette
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


Print a number on screen. Overload with default background.

Here is the call graph for this function:

◆ print_err()

int Longan_nano::Screen::print_err ( int  origin_h,
int  origin_w 
)

public method print_err | int | int |

Parameters
origin_h| int | height position of the sprite
origin_w| int | width position of the sprite
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


print a char inside the sprite frame buffer and mark it for update if needs to be
use default background
wrapper for more general print string function

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_sprite()

int8_t Longan_nano::Screen::register_sprite ( uint16_t  index_h,
uint16_t  index_w 
)
private

private method register_sprite | uint16_t | uint16_t |

Parameters
index_h| uint16_t | index of the sprite in the frame buffer to build pixel from
index_w| uint16_t | index of the sprite in the frame buffer to build pixel from
Returns
int8_t | -1 error | >= 0 sprites registered for draw


Register a sprite for draw in the display driver if possible
Sprite can be xomplex color map or solid color

Here is the call graph for this function:
Here is the caller graph for this function:

◆ report_error()

void Longan_nano::Screen::report_error ( Error  error_code)
private

private setter report_error | Error |

Parameters
error_code| Error | error code of the Screen Class
Returns
no return

Method


CHECK


RETURN

Here is the caller graph for this function:

◆ reset_colors()

bool Longan_nano::Screen::reset_colors ( void  )

public init reset_colors |

Returns
bool | false = OK | true = ERR


Reset the colors to default

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_color()

int Longan_nano::Screen::set_color ( int  origin_h,
int  origin_w,
Color  background,
Color  foreground 
)
inline

public setter set_color | int | int | Color | Color

Parameters
origin_h| int | height position of the sprite
origin_w| int | width position of the sprite
background| Color | background color of ths sprite as index from the palette
foreground| Color | foreground color of ths sprite as index from the palette
Returns
int | <0 ERR | >= 0 number of updated sprites


Set background and foreground color of a given sprite

Here is the call graph for this function:

◆ set_default_colors()

int Longan_nano::Screen::set_default_colors ( Color  new_background,
Color  new_foreground 
)

public setter set_default_colors | Color | Color

Parameters
new_background| Color | background color of ths sprite as index from the palette
new_foreground| Color | foreground color of ths sprite as index from the palette
Returns
int16_t | >=0 Number of sprites changed | < 0 error |


Change the default background and foreground colors
All existing sprites are automatically updated as needed

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_format() [1/2]

bool Longan_nano::Screen::set_format ( int  number_size,
Format_align  align,
Format_format  format 
)
inline

public setter set_format | int | Format_align | Format_format |

Parameters
number_size| int | sprites reserved for the number
align| Format_align | set alignment of the number
format| Format_format | set display format of the number
Returns
bool | false = OK | true = ERR


With left adjust, the number is print starting from left an origin is the position of the most significant number
With right adjust, the origin is the position of the least significant number

LEFT 78901 12.71m
RIGHT 78901 12.71m
ORIGIN ^ ^
The format also specifies full number or enginnering format

Here is the caller graph for this function:

◆ set_format() [2/2]

bool Longan_nano::Screen::set_format ( int  number_size,
Format_align  align,
Format_format  format,
int  exp 
)
inline

public setter set_format | int | Format_align | Format_format | int |

Parameters
number_size| int | sprites reserved for the number
align| Format_align | set alignment of the number
format| Format_format | set display format of the number
exp| int | ENG number exponent
Returns
bool | false = OK | true = ERR


With left adjust, the number is print starting from left an origin is the position of the most significant number
With right adjust, the origin is the position of the least significant number

LEFT 78901 12.71m
RIGHT 78901 12.71m
ORIGIN ^ ^
The format also specifies full number or enginnering format

◆ set_palette_color()

int Longan_nano::Screen::set_palette_color ( Color  palette_index,
uint8_t  r,
uint8_t  g,
uint8_t  b 
)

public setter set_palette_color | Color | uint8_t | uint8_t | uint8_t |

Parameters
palette_index| Color | color index of the palette to be changed
r| uint8_t | red color channel
g| uint8_t | red color channel
b| uint8_t | red color channel
Returns
int | >=0 Number of sprites changed | < 0 error |


Change a color in the palette to another RGB color
Change all sprites that use that color and mark them for update
Use the conversion function provided by the Display driver to compute the right color space

Here is the call graph for this function:

◆ update()

bool Longan_nano::Screen::update ( void  )

public method update | void

Returns
bool | false = OK | true = ERR

FSM that synchronize the frame buffer with the display using the driver The low level driver exposes control steps used by the high level frame buffer driver

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_sprite()

int8_t Longan_nano::Screen::update_sprite ( uint16_t  index_h,
uint16_t  index_w,
Frame_buffer_sprite  new_sprite 
)
private

private tester update_sprite | uint16_t | uint16_t | Frame_buffer_sprite |

Returns
ont | <0 = error coccurred | 0 = frame buffer wasn't updated | 1 = frame buffer was updated

Update a sprite in the frame buffer and mark it for update if required Increase the workload counter if applicable If workload counter is zero, set the scan to the current sprite to quicken the seek

Here is the call graph for this function:

Member Data Documentation

◆ g_ascii_sprites

constexpr uint8_t Longan_nano::Screen::g_ascii_sprites[96 *10]
staticconstexprprivate

ASCII Sprites. Stored in the flash memory. 95 sprites from space ' ' code 32 to tilda '~' code 126 + special code 127. FONT_HEIGHT is used to change font.

◆ g_default_background_color

Color Longan_nano::Screen::g_default_background_color
private

Default background and foreground colors to be used.

◆ g_default_foreground_color

Color Longan_nano::Screen::g_default_foreground_color
private

◆ g_error_code

Error Longan_nano::Screen::g_error_code
private

Error code of the library. Default is Error::OK.

◆ g_format_number

Format_number Longan_nano::Screen::g_format_number
private

Display format for print numeric values.

◆ g_frame_buffer

Frame_buffer_sprite Longan_nano::Screen::g_frame_buffer[Config::FRAME_BUFFER_HEIGHT][Config::FRAME_BUFFER_WIDTH]
private

Frame Buffer.

◆ g_palette

uint16_t Longan_nano::Screen::g_palette[Config::PALETTE_SIZE]
private

Color Palette. One special code for transparent. Two special indexes store global background and foreground.

◆ g_pending_cnt

uint16_t Longan_nano::Screen::g_pending_cnt
private

Track the number of sprites that require update. At zero the update method quit without scanning and print methods will set the scan to the correct index.

◆ g_pixel_data

uint16_t Longan_nano::Screen::g_pixel_data[Config::SPRITE_PIXEL_COUNT]
private

Sprite buffer that stores raw pixel data for a single sprite.

◆ g_status

Fsm_status Longan_nano::Screen::g_status
private

Status of the update FSM.


The documentation for this class was generated from the following file: