Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
gfx_library.c File Reference
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cascoda-bm/cascoda_evbme.h"
#include "cascoda-bm/cascoda_interface.h"
#include "cascoda-util/cascoda_tasklet.h"
#include "gfx_driver.h"
#include "gfx_library.h"
Include dependency graph for gfx_library.c:

Macros

#define min(a, b)   (((a) < (b)) ? (a) : (b))
 
#define _swap_int16_t(a, b)
 

Functions

void display_drawCircleHelper (uint16_t x0, uint16_t y0, uint16_t r, uint8_t cornername, uint16_t color)
 Quarter-circle drawer, used to do circles and roundrects. More...
 
void display_fillCircleHelper (uint16_t x0, uint16_t y0, uint16_t r, uint8_t corners, uint16_t delta, uint16_t color)
 Quarter-circle drawer with fill, used for circles and roundrects. More...
 
void writeLine (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
 Write a line. More...
 
uint8_t printNumber (uint32_t n, int8_t n_width, uint8_t _flags)
 
void printFloat (float float_n, int8_t f_width, int8_t decimal, uint8_t _flags)
 
void v_printf (const char *fmt, va_list arp)
 
void fillRect (uint16_t x0, uint16_t y0, uint16_t x1, int16_t y1, uint16_t color)
 
void display_drawPixel (int16_t x, int16_t y, uint16_t color)
 
void display_clear (void)
 clears the frame buffer intializes the background on white. More...
 
void display_setRotation (uint16_t rotation)
 set the rotation prints starting at the cursor position. More...
 
void display_fillRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
 draw filled rectangle More...
 
void display_drawHLine (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t color)
 
void display_drawVLine (uint16_t x0, uint16_t y0, uint16_t y1, uint16_t color)
 
void display_drawLine (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
 Draw a line. More...
 
void display_drawCircle (uint16_t x0, uint16_t y0, uint16_t r, uint16_t color)
 Draw a circle outline. More...
 
void display_fillCircle (uint16_t x0, uint16_t y0, uint16_t r, uint16_t color)
 Draw a circle with filled color. More...
 
void display_drawRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
 Draw a rectangle with no fill color. More...
 
void display_drawRoundRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t color)
 Draw a rounded rectangle with no fill color. More...
 
void display_fillRoundRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t color)
 Draw a rounded rectangle with fill color. More...
 
void display_drawTriangle (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 Draw a triangle with no fill color. More...
 
void display_fillTriangle (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 Draw a triangle with color-fill. More...
 
void display_putc (uint8_t c)
 Print one byte/character of data. More...
 
void display_puts (const uint8_t *s)
 Print a string to the display. More...
 
void display_puts_max_n (const uint8_t *s, uint8_t n)
 Print a maximum of (n - 1) characters from the input string to the display and put "..." as the nth character afterwards to indicate that the string was truncated. More...
 
void display_customChar (const uint8_t *c)
 
void display_drawChar (uint16_t x, uint16_t y, uint8_t c, uint16_t color, uint16_t bg, uint8_t size)
 Draw a single character. More...
 
void display_setCursor (uint16_t x, uint16_t y)
 Set text cursor location. More...
 
uint16_t display_getCursorX (void)
 Get text cursor X location. More...
 
uint16_t display_getCursorY (void)
 Get text cursor Y location. More...
 
void display_setTextSize (uint8_t s)
 Set text 'magnification' size. More...
 
void display_setTextColor (uint16_t c, uint16_t b)
 Set text font color with custom background color. More...
 
void display_setTextWrap (bool w)
 Whether text that is too long should 'wrap' around to the next line. More...
 
uint8_t display_getRotation (void)
 Get rotation setting for display. More...
 
uint16_t display_getWidth (void)
 Get width of the display, accounting for the current rotation. More...
 
uint16_t display_getHeight (void)
 Get height of the display, accounting for the current rotation. More...
 
uint16_t display_color565 (uint8_t red, uint8_t green, uint8_t blue)
 Given 8-bit red, green and blue values, return a 'packed' 16-bit color value in '565' RGB format (5 bits red, 6 bits green, 5 bits blue). More...
 
void display_drawBitmapV1 (uint16_t x, uint16_t y, const uint8_t *bitmap, uint16_t w, uint16_t h, uint16_t color)
 Draw a ROM-resident 1-bit image at the specified (x,y) position, using the specified foreground color (unset bits are transparent). More...
 
void display_drawBitmapV1_bg (uint16_t x, uint16_t y, const uint8_t *bitmap, uint16_t w, uint16_t h, uint16_t color, uint16_t bg)
 Draw a ROM-resident 1-bit image at the specified (x,y) position, using the specified foreground (for set bits) and background (unset bits) colors. More...
 
void display_drawBitmapV2 (uint16_t x, uint16_t y, const uint8_t *bitmap, uint16_t w, uint16_t h, uint16_t color)
 Draw a ROM-resident 1-bit image at the specified (x,y) position, using the specified foreground color (unset bits are transparent). More...
 
void display_drawBitmapV2_bg (uint16_t x, uint16_t y, const uint8_t *bitmap, uint16_t w, uint16_t h, uint16_t color, uint16_t bg)
 Draw a ROM-resident 1-bit image at the specified (x,y) position, using the specified foreground (for set bits) and background (unset bits) colors. More...
 
void display_double (char *text, int text_size, double v, int decimalDigits)
 convert a float to a string More...
 
void display_slider (int x, int y, int length, int value)
 
void display_progressbar (int x, int y, int length, int value)
 

Macro Definition Documentation

◆ _swap_int16_t

#define _swap_int16_t (   a,
 
)
Value:
{ \
int16_t t = a; \
a = b; \
b = t; \
}

◆ min

#define min (   a,
 
)    (((a) < (b)) ? (a) : (b))

Function Documentation

◆ display_clear()

void display_clear ( void  )

clears the frame buffer intializes the background on white.

◆ display_color565()

uint16_t display_color565 ( uint8_t  red,
uint8_t  green,
uint8_t  blue 
)

Given 8-bit red, green and blue values, return a 'packed' 16-bit color value in '565' RGB format (5 bits red, 6 bits green, 5 bits blue).

This is just a mathematical operation, no hardware is touched.

Parameters
red8-bit red brightnesss (0 = off, 255 = max).
green8-bit green brightnesss (0 = off, 255 = max).
blue8-bit blue brightnesss (0 = off, 255 = max).
Returns
'Packed' 16-bit color value (565 format).

◆ display_customChar()

void display_customChar ( const uint8_t *  c)

◆ display_double()

void display_double ( char *  text,
int  text_size,
double  v,
int  decimalDigits 
)

convert a float to a string

Parameters
textthe text buffer to write in
text_sizethe size of the text buffer
vthe floating number to display
decimalDigitsthe decimal digit to display

◆ display_drawBitmapV1()

void display_drawBitmapV1 ( uint16_t  x,
uint16_t  y,
const uint8_t *  bitmap,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

Draw a ROM-resident 1-bit image at the specified (x,y) position, using the specified foreground color (unset bits are transparent).

Parameters
xTop left corner x coordinate
yTop left corner y coordinate
bitmapbyte array with monochrome bitmap
wWidth of bitmap in pixels
hHieght of bitmap in pixels
color16-bit 5-6-5 Color to draw with

◆ display_drawBitmapV1_bg()

void display_drawBitmapV1_bg ( uint16_t  x,
uint16_t  y,
const uint8_t *  bitmap,
uint16_t  w,
uint16_t  h,
uint16_t  color,
uint16_t  bg 
)

Draw a ROM-resident 1-bit image at the specified (x,y) position, using the specified foreground (for set bits) and background (unset bits) colors.

Parameters
xTop left corner x coordinate
yTop left corner y coordinate
bitmapbyte array with monochrome bitmap
wWidth of bitmap in pixels
hHieght of bitmap in pixels
color16-bit 5-6-5 Color to draw pixels with
bg16-bit 5-6-5 Color to draw background with

◆ display_drawBitmapV2()

void display_drawBitmapV2 ( uint16_t  x,
uint16_t  y,
const uint8_t *  bitmap,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

Draw a ROM-resident 1-bit image at the specified (x,y) position, using the specified foreground color (unset bits are transparent).

Parameters
xTop left corner x coordinate
yTop left corner y coordinate
bitmapbyte array with monochrome bitmap
wWidth of bitmap in pixels
hHieght of bitmap in pixels
color16-bit 5-6-5 Color to draw pixels with

◆ display_drawBitmapV2_bg()

void display_drawBitmapV2_bg ( uint16_t  x,
uint16_t  y,
const uint8_t *  bitmap,
uint16_t  w,
uint16_t  h,
uint16_t  color,
uint16_t  bg 
)

Draw a ROM-resident 1-bit image at the specified (x,y) position, using the specified foreground (for set bits) and background (unset bits) colors.

Parameters
xTop left corner x coordinate
yTop left corner y coordinate
bitmapbyte array with monochrome bitmap
wWidth of bitmap in pixels
hHieght of bitmap in pixels
color16-bit 5-6-5 Color to draw pixels with
bg16-bit 5-6-5 Color to draw background with

◆ display_drawChar()

void display_drawChar ( uint16_t  x,
uint16_t  y,
uint8_t  c,
uint16_t  color,
uint16_t  bg,
uint8_t  size 
)

Draw a single character.

Parameters
xBottom left corner x coordinate
yBottom left corner y coordinate
cThe 8-bit font-indexed character (likely ascii)
color16-bit 5-6-5 Color to draw chraracter with
bg16-bit 5-6-5 Color to fill background with (if same as color, no background)
sizeFont magnification level, 1 is 'original' size

◆ display_drawCircle()

void display_drawCircle ( uint16_t  x0,
uint16_t  y0,
uint16_t  r,
uint16_t  color 
)

Draw a circle outline.

draw circle

Parameters
x0Center-point x coordinate
y0Center-point y coordinate
rRadius of circle
color16-bit 5-6-5 Color to draw with

◆ display_drawCircleHelper()

void display_drawCircleHelper ( uint16_t  x0,
uint16_t  y0,
uint16_t  r,
uint8_t  cornername,
uint16_t  color 
)

Quarter-circle drawer, used to do circles and roundrects.

Parameters
x0Center-point x coordinate
y0Center-point y coordinate
rRadius of circle
cornernameMask bit #1 or bit #2 to indicate which quarters of the circle we're doing
color16-bit 5-6-5 Color to draw with

◆ display_drawHLine()

void display_drawHLine ( uint16_t  x0,
uint16_t  y0,
uint16_t  x1,
uint16_t  color 
)

◆ display_drawLine()

void display_drawLine ( uint16_t  x0,
uint16_t  y0,
uint16_t  x1,
uint16_t  y1,
uint16_t  color 
)

Draw a line.

draw line

Parameters
x0Start point x coordinate
y0Start point y coordinate
x1End point x coordinate
y1End point y coordinate
color16-bit 5-6-5 Color to draw with

◆ display_drawPixel()

void display_drawPixel ( int16_t  x,
int16_t  y,
uint16_t  color 
)

◆ display_drawRect()

void display_drawRect ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

Draw a rectangle with no fill color.

draw rectangle

Parameters
xTop left corner x coordinate
yTop left corner y coordinate
wWidth in pixels
hHeight in pixels
color16-bit 5-6-5 Color to draw with

◆ display_drawRoundRect()

void display_drawRoundRect ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  r,
uint16_t  color 
)

Draw a rounded rectangle with no fill color.

Parameters
xTop left corner x coordinate
yTop left corner y coordinate
wWidth in pixels
hHeight in pixels
rRadius of corner rounding
color16-bit 5-6-5 Color to draw with

◆ display_drawTriangle()

void display_drawTriangle ( uint16_t  x0,
uint16_t  y0,
uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  color 
)

Draw a triangle with no fill color.

Parameters
x0Vertex #0 x coordinate
y0Vertex #0 y coordinate
x1Vertex #1 x coordinate
y1Vertex #1 y coordinate
x2Vertex #2 x coordinate
y2Vertex #2 y coordinate
color16-bit 5-6-5 Color to draw with

◆ display_drawVLine()

void display_drawVLine ( uint16_t  x0,
uint16_t  y0,
uint16_t  y1,
uint16_t  color 
)

◆ display_fillCircle()

void display_fillCircle ( uint16_t  x0,
uint16_t  y0,
uint16_t  r,
uint16_t  color 
)

Draw a circle with filled color.

draw a filled circle

Parameters
x0Center-point x coordinate
y0Center-point y coordinate
rRadius of circle
color16-bit 5-6-5 Color to fill with

◆ display_fillCircleHelper()

void display_fillCircleHelper ( uint16_t  x0,
uint16_t  y0,
uint16_t  r,
uint8_t  corners,
uint16_t  delta,
uint16_t  color 
)

Quarter-circle drawer with fill, used for circles and roundrects.

Parameters
x0Center-point x coordinate
y0Center-point y coordinate
rRadius of circle
cornersMask bits indicating which quarters we're doing
deltaOffset from center-point, used for round-rects
color16-bit 5-6-5 Color to fill with

◆ display_fillRect()

void display_fillRect ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

draw filled rectangle

draws a filled rectangle

Parameters
x0the x coordinate
y0the y coordinate
wthe width of the rectangle
hthe height of the rectangle
colorthe color of the line (BLACK or WHITE)

◆ display_fillRoundRect()

void display_fillRoundRect ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  r,
uint16_t  color 
)

Draw a rounded rectangle with fill color.

Parameters
xTop left corner x coordinate
yTop left corner y coordinate
wWidth in pixels
hHeight in pixels
rRadius of corner rounding
color16-bit 5-6-5 Color to draw/fill with

◆ display_fillTriangle()

void display_fillTriangle ( uint16_t  x0,
uint16_t  y0,
uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  color 
)

Draw a triangle with color-fill.

Parameters
x0Vertex #0 x coordinate
y0Vertex #0 y coordinate
x1Vertex #1 x coordinate
y1Vertex #1 y coordinate
x2Vertex #2 x coordinate
y2Vertex #2 y coordinate
color16-bit 5-6-5 Color to fill/draw with

◆ display_getCursorX()

uint16_t display_getCursorX ( void  )

Get text cursor X location.

Returns
X coordinate in pixels

◆ display_getCursorY()

uint16_t display_getCursorY ( void  )

Get text cursor Y location.

Returns
Y coordinate in pixels

◆ display_getHeight()

uint16_t display_getHeight ( void  )

Get height of the display, accounting for the current rotation.

Get display Height.

Returns
Height in pixels

◆ display_getRotation()

uint8_t display_getRotation ( void  )

Get rotation setting for display.

Returns
0 thru 3 corresponding to 4 cardinal rotations

◆ display_getWidth()

uint16_t display_getWidth ( void  )

Get width of the display, accounting for the current rotation.

Get display Width.

Returns
Width in pixels

◆ display_progressbar()

void display_progressbar ( int  x,
int  y,
int  length,
int  value 
)

◆ display_putc()

void display_putc ( uint8_t  c)

Print one byte/character of data.

Parameters
cThe 8-bit ascii character to write

◆ display_puts()

void display_puts ( const uint8_t *  s)

Print a string to the display.

Parameters
sThe string to write

note use snprintf to format text snprintf does not display floating numbers use display_double() to display floating numbers

◆ display_puts_max_n()

void display_puts_max_n ( const uint8_t *  s,
uint8_t  n 
)

Print a maximum of (n - 1) characters from the input string to the display and put "..." as the nth character afterwards to indicate that the string was truncated.

Parameters
sThe input string to write (will be truncated if longer than n characters)
nThe maximum number of characters (minus 1 to leave space for "...") to display from the input string NOTE: This is only the number of VISIBLE characters, so excludes NULL terminator.

note use snprintf to format text snprintf does not display floating numbers use display_double() to display floating numbers

EXAMPLE: const char *str = "Hello, World!"; display_puts_max_n(s, 30); // Result is: Hello, World! display_puts_max_n(s, 9); // Result is: Hello, W...

◆ display_setCursor()

void display_setCursor ( uint16_t  x,
uint16_t  y 
)

Set text cursor location.

Parameters
xX coordinate in pixels
yY coordinate in pixels

◆ display_setRotation()

void display_setRotation ( uint16_t  rotation)

set the rotation prints starting at the cursor position.

Parameters
rotation0 == no rotation, 1 = 90 degrees

◆ display_setTextColor()

void display_setTextColor ( uint16_t  c,
uint16_t  b 
)

Set text font color with custom background color.

Parameters
c16-bit 5-6-5 Color to draw text with
b16-bit 5-6-5 Color to draw background/fill with

◆ display_setTextSize()

void display_setTextSize ( uint8_t  s)

Set text 'magnification' size.

Each increase in s makes 1 pixel that much bigger.

Parameters
sDesired text size. 1 is default 6x8, 2 is 12x16, 3 is 18x24, etc

◆ display_setTextWrap()

void display_setTextWrap ( bool  w)

Whether text that is too long should 'wrap' around to the next line.

Parameters
wSet true for wrapping, false for clipping

◆ display_slider()

void display_slider ( int  x,
int  y,
int  length,
int  value 
)

◆ fillRect()

void fillRect ( uint16_t  x0,
uint16_t  y0,
uint16_t  x1,
int16_t  y1,
uint16_t  color 
)

◆ printFloat()

void printFloat ( float  float_n,
int8_t  f_width,
int8_t  decimal,
uint8_t  _flags 
)

◆ printNumber()

uint8_t printNumber ( uint32_t  n,
int8_t  n_width,
uint8_t  _flags 
)

◆ v_printf()

void v_printf ( const char *  fmt,
va_list  arp 
)

◆ writeLine()

void writeLine ( uint16_t  x0,
uint16_t  y0,
uint16_t  x1,
uint16_t  y1,
uint16_t  color 
)

Write a line.

Bresenham's algorithm - thx wikpedia

Parameters
x0Start point x coordinate
y0Start point y coordinate
x1End point x coordinate
y1End point y coordinate
color16-bit 5-6-5 Color to draw with