Embedded Artistry Framework
Embedded Systems C++ Framework
Modules | Classes
Framework Drivers

Drivers provided by the framework. More...

Collaboration diagram for Framework Drivers:

Modules

 Unit Test Drivers
 Drivers intended for use with unit test code.
 
 Simulator Drivers
 Drivers intended for use with simulator applications (run on host machine)
 

Classes

class  embdrv::ssd1306
 Driver for the SSD1306 Display Driver. More...
 
class  embdrv::vl53l1x
 ST VL53L1X Time-of-Flight Sensor Driver. More...
 

Detailed Description

Drivers provided by the framework.


Class Documentation

◆ embdrv::ssd1306

class embdrv::ssd1306

Driver for the SSD1306 Display Driver.

This implementation only supports I2C, though the part supports SPI and Parallel modes To implement that support, please use a state pattern and adjust the i2cWrite function to be a more generic write. This single function can be swapped out for the particular data mode.

The screen size is hard-coded to be 64 x 48 with an offset of 32. Adjustments are needed to make the screen size specification generic.

Inheritance diagram for embdrv::ssd1306:
Inheritance graph

Public Types

enum  invert : uint8_t { invert::normal = 0, invert::invert }
 Display color inversion options. More...
 
enum  mode : uint8_t { mode::normal = 0, mode::XOR }
 Set the drawing mode, if supported by the driver. More...
 
enum  color : uint8_t { color::black = 0, color::white }
 Basic displays have two pixel colors: black and white. More...
 
using coord_t = uint8_t
 Coordinate representation type. More...
 

Public Member Functions

 ssd1306 (embvm::i2c::master &i2c, uint8_t i2c_addr=DEFAULT_SSD1306_I2C_ADDR)
 Address is 0x3D if DC pin is set to 1. More...
 
void clear () noexcept final
 Clear the screen contents. More...
 
void clearAndDisplay () noexcept
 
void invert (enum invert inv) noexcept final
 Invert the display color. More...
 
void contrast (uint8_t contrast) noexcept final
 Set contrast. More...
 
void cursor (coord_t x, coord_t y) noexcept final
 Set the cusor within the screen buffer. More...
 
void pixel (coord_t x, coord_t y, color c, mode m) noexcept final
 Draw a pixel with a specific color and mode. More...
 
void line (coord_t x0, coord_t y0, coord_t x1, coord_t y1, color c, mode m) noexcept final
 Draw a line with a specific color and mode. More...
 
void rect (coord_t x, coord_t y, uint8_t width, uint8_t height, color c, mode m) noexcept final
 Draw a rectangle with a specific color and mode. More...
 
void rectFill (coord_t x, coord_t y, uint8_t width, uint8_t height, color c, mode m) noexcept final
 Draw a filled rectangle with a specific color and mode. More...
 
void circle (coord_t x, coord_t y, uint8_t radius, color c, mode m) noexcept final
 Draw a circle with a specific color and mode. More...
 
void circleFill (coord_t x, coord_t y, uint8_t radius, color c, mode m) noexcept final
 Draw a filled circle with a specific color and mode. More...
 
void drawChar (coord_t x, coord_t y, uint8_t character, color c, mode m) noexcept final
 Draw an ASCII character with a specific color and mode. More...
 
void drawBitmap (uint8_t *bitmap) noexcept final
 Replace the screen buffer with a bitmap. More...
 
uint8_t screenWidth () const noexcept final
 Check the screen width. More...
 
uint8_t screenHeight () const noexcept final
 Check the screen height. More...
 
void scrollRight (coord_t start, coord_t stop) noexcept final
 Enable right scrolling. More...
 
void scrollLeft (coord_t start, coord_t stop) noexcept final
 Enable left scrolling. More...
 
void scrollVertRight (coord_t start, coord_t stop) noexcept final
 
void scrollVertLeft (coord_t start, coord_t stop) noexcept final
 
void scrollStop () noexcept final
 Stop scrolling. More...
 
void flipVertical (bool flip) noexcept final
 Vertical flip. More...
 
void flipHorizontal (bool flip) noexcept final
 Horizontal flip. More...
 
void display () noexcept final
 Flush the screen buffer contents to the hardware display buffer. More...
 
uint8_t fontType (uint8_t type) noexcept
 Set the font type. More...
 
uint8_t fontType () const noexcept
 Get the current font type. More...
 
uint8_t fontWidth () const noexcept
 Get the font width. More...
 
uint8_t fontHeight () const noexcept
 Get the font height. More...
 
uint8_t totalFonts () const noexcept
 Get the total number of supported fonts. More...
 
uint8_t fontStartChar () const noexcept
 Get the starting character for the font. More...
 
uint8_t fontTotalChar () const noexcept
 Get the total number of characters supported by the font. More...
 
void putchar (uint8_t c) noexcept final
 Print a character on the display. More...
 
void pixel (coord_t x, coord_t y) noexcept
 Draw a pixel in the screen buffer. More...
 
void line (coord_t x0, coord_t y0, coord_t x1, coord_t y1) noexcept
 Draw a line. More...
 
void lineH (coord_t x, coord_t y, uint8_t width) noexcept
 Draw a horizontal line. More...
 
void lineH (coord_t x, coord_t y, uint8_t width, color c, mode m) noexcept
 Draw a horizontal line with a specific color and mode. More...
 
void lineV (coord_t x, coord_t y, uint8_t height) noexcept
 Draw a vertical line. More...
 
void lineV (coord_t x, coord_t y, uint8_t height, color c, mode m) noexcept
 Draw a vertical line with a specific color and mode. More...
 
void rect (coord_t x, coord_t y, uint8_t width, uint8_t height) noexcept
 Draw a rectangle. More...
 
void rectFill (coord_t x, coord_t y, uint8_t width, uint8_t height) noexcept
 Draw a filled rectangle. More...
 
void circle (coord_t x, coord_t y, uint8_t radius) noexcept
 Draw a circle. More...
 
void circleFill (coord_t x, coord_t y, uint8_t radius) noexcept
 Draw a filled circle. More...
 
void drawChar (coord_t x, coord_t y, uint8_t character) noexcept
 Draw an ASCII character. More...
 
void printString (coord_t x, coord_t y, const char *str) noexcept
 Print a string on the display. More...
 
void printString (coord_t x, coord_t y, const char *str, size_t length) noexcept
 Print a string on the display. More...
 
void drawColor (color c) noexcept
 Set color. More...
 
virtual void drawMode (mode m) noexcept
 Set draw mode. More...
 
void start () noexcept
 Start the driver. More...
 
void stop () noexcept
 Stop the driver. More...
 
void restart () noexcept
 Restart the driver. More...
 
type_safe::boolean started () const noexcept
 Check if the driver has been started. More...
 
constexpr embvm::DriverType_t DriverType () const noexcept
 Returns the registered type ID of the driver. More...
 
constexpr const std::string_view & name () const noexcept
 Provides a string_view reference of the driver name. More...
 
constexpr const char * name_cstr () const noexcept
 Provides a c-string version of the driver name. More...
 
virtual DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 Basic Display Driver Type ID. More...
 

Protected Attributes

mode mode_ = mode::normal
 The current display mode setting. More...
 
color color_ = color::black
 The current display color setting. More...
 
type_safe::boolean started_ = false
 Tracks the driver state. More...
 
const std::string_view name_
 Name of the driver instance. More...
 
const embvm::DriverType_t type_
 Type ID of the driver instance. More...
 

Private Member Functions

void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void i2c_write (const uint8_t *buffer, uint8_t size, const embvm::i2c::master::cb_t &cb) noexcept
 Helper function which performs an I2C write. More...
 
void clear (uint8_t c) noexcept
 Clear the display and initialize buffer bytes with the target value. More...
 
void command (uint8_t c) noexcept
 Send a command to the display driver hardware. More...
 
void command (uint8_t cmd, uint8_t arg1) noexcept
 Send a command with one argument to the display driver hardware. More...
 
void command (uint8_t cmd, uint8_t arg1, uint8_t arg2) noexcept
 Send a command with two arguments to the display driver hardware. More...
 
void data (uint8_t c) noexcept
 Send a data byte to the display driver hardware. More...
 
void setColumnAddress (uint8_t add) noexcept
 Set the column address. More...
 
void setPageAddress (uint8_t add) noexcept
 Set the page address. More...
 
void drawCharSingleRow (coord_t x, coord_t y, uint8_t character, color c, mode m) noexcept
 
void drawCharMultiRow (coord_t x, coord_t y, uint8_t character, color c, mode m) noexcept
 

Private Attributes

uint8_t fontWidth_ = 0
 
uint8_t fontHeight_ = 0
 
uint8_t fontType_ = 0
 
uint8_t fontStartChar_ = 0
 
uint8_t fontTotalChar_ = 0
 
uint16_t fontMapWidth_ = 0
 
uint8_t cursorX_ = 0
 X-axies position of the cursor. More...
 
uint8_t cursorY_ = 0
 Y-axis position of the cursor. More...
 
embvm::i2c::masteri2c_
 The i2c instance this display driver is attached to. More...
 
uint8_t i2c_addr_
 The I2C address for this dispaly. More...
 
etl::variant_pool< 128, uint8_t, uint16_t, uint32_ti2c_pool_ {}
 Static memory pool which is used for display I2C transactions. More...
 
uint8_t display_buffer_ [SCREEN_BUFFER_SIZE+1] = {0}
 OLED screen buffer. More...
 
uint8_t *const screen_buffer_ = &display_buffer_[1]
 Pointer alias to the display_buffer_ which accounts for the single byte reserved for the DATA command value. More...
 

Static Private Attributes

static constexpr uint8_t SCREEN_WIDTH = 64
 The width of the scren in pixels. More...
 
static constexpr uint8_t SCREEN_HEIGHT = 48
 The height of the screen in pixels. More...
 
static constexpr size_t SCREEN_BUFFER_SIZE = ((SCREEN_WIDTH * SCREEN_HEIGHT) / 8)
 The size of the screen buffer We divide by 8 because each byte controls the state of 8 pixels. More...
 
static constexpr uint8_t COLUMN_OFFSET = 32
 The number of columns offset into the display where the active display area starts. More...
 
static const std::array< const uint8_t *, 2 > fonts_ = {font5x7, font8x16}
 Array of fonts supported by this driver. More...
 

Member Typedef Documentation

◆ coord_t

Coordinate representation type.

Member Enumeration Documentation

◆ color

enum embvm::basicDisplay::color : uint8_t
stronginherited

Basic displays have two pixel colors: black and white.

Enumerator
black 
white 

◆ invert

enum embvm::basicDisplay::invert : uint8_t
stronginherited

Display color inversion options.

Enumerator
normal 

Use the default display color setting.

invert 

Invert the display colors.

◆ mode

enum embvm::basicDisplay::mode : uint8_t
stronginherited

Set the drawing mode, if supported by the driver.

Enumerator
normal 

Either sets or clears a pixel as requested, overwriting the value set in the screen buffer.

XOR 

The pixel output in the screen buffer will be an XOR of the current value and the input value.

Constructor & Destructor Documentation

◆ ssd1306()

embdrv::ssd1306::ssd1306 ( embvm::i2c::master i2c,
uint8_t  i2c_addr = DEFAULT_SSD1306_I2C_ADDR 
)
inlineexplicit

Address is 0x3D if DC pin is set to 1.

References display_buffer_.

Member Function Documentation

◆ circle() [1/2]

void ssd1306::circle ( coord_t  x,
coord_t  y,
uint8_t  radius,
color  c,
mode  m 
)
finalvirtualnoexcept

Draw a circle with a specific color and mode.

Draw a circle with center (x,y) and the specified radius using a specific color setting and draw mode in the screen buffer. Only the boundary of the circle will be drawn.

Parameters
xX-coorindate for the center of the circle.
yY-coordinate for the center of the circle.
radiusThe radius of the circle.
cPixel color.
mMode used to update the screen buffer.

Implements embvm::basicDisplay.

◆ circle() [2/2]

void embvm::basicDisplay::circle ( coord_t  x,
coord_t  y,
uint8_t  radius 
)
inlinenoexceptinherited

Draw a circle.

Draw a circle with center (x,y) and the specified radius using the configured color setting and draw mode in the screen buffer. Only the boundary of the circle will be drawn.

Parameters
xX-coorindate for the center of the circle.
yY-coordinate for the center of the circle.
radiusThe radius of the circle.

References embvm::basicDisplay::color_, and embvm::basicDisplay::mode_.

◆ circleFill() [1/2]

void ssd1306::circleFill ( coord_t  x,
coord_t  y,
uint8_t  radius,
color  c,
mode  m 
)
finalvirtualnoexcept

Draw a filled circle with a specific color and mode.

Draw a filled circle with center (x,y) and the specified radius using a specific color setting and draw mode in the screen buffer. The interior of the circle will be filled with the specified color setting.

Parameters
xX-coorindate for the center of the circle.
yY-coordinate for the center of the circle.
radiusThe radius of the circle.
cPixel color.
mMode used to update the screen buffer.

Implements embvm::basicDisplay.

◆ circleFill() [2/2]

void embvm::basicDisplay::circleFill ( coord_t  x,
coord_t  y,
uint8_t  radius 
)
inlinenoexceptinherited

Draw a filled circle.

Draw a filled circle with center (x,y) and the specified radius using the configured color setting and draw mode in the screen buffer. The interior of the circle will be filled with the specified color setting.

Parameters
xX-coorindate for the center of the circle.
yY-coordinate for the center of the circle.
radiusThe radius of the circle.

References embvm::basicDisplay::color_, and embvm::basicDisplay::mode_.

◆ clear() [1/2]

void ssd1306::clear ( )
finalvirtualnoexcept

Clear the screen contents.

Implements embvm::basicDisplay.

Referenced by clearAndDisplay(), and start_().

◆ clear() [2/2]

void ssd1306::clear ( uint8_t  c)
privatenoexcept

Clear the display and initialize buffer bytes with the target value.

Parameters
cThe value to initialize the bytes of the screen buffe rwith.

References memset().

◆ clearAndDisplay()

void ssd1306::clearAndDisplay ( )
noexcept

References clear(), and display().

◆ command() [1/3]

void ssd1306::command ( uint8_t  c)
privatenoexcept

Send a command to the display driver hardware.

Parameters
cthe command byte.

Referenced by scrollStop(), start_(), and stop_().

◆ command() [2/3]

void ssd1306::command ( uint8_t  cmd,
uint8_t  arg1 
)
privatenoexcept

Send a command with one argument to the display driver hardware.

Parameters
cmdthe command byte.
arg1The argument to send with the command byte.

◆ command() [3/3]

void ssd1306::command ( uint8_t  cmd,
uint8_t  arg1,
uint8_t  arg2 
)
privatenoexcept

Send a command with two arguments to the display driver hardware.

Parameters
cmdthe command byte.
arg1The first argument to send with the command byte.
arg2The second argumet to send with the command byte.

◆ contrast()

void ssd1306::contrast ( uint8_t  contrast)
finalvirtualnoexcept

Set contrast.

Parameters
contrastTarget display contrast value, ranging from 0 to 255.

Implements embvm::basicDisplay.

◆ cursor()

void ssd1306::cursor ( coord_t  x,
coord_t  y 
)
finalvirtualnoexcept

Set the cusor within the screen buffer.

Contents in the screen buffer are not modified by setting the cursor position.

Parameters
xX-coordinate of the cursor.
yY-coordinate of the cursor.

Implements embvm::basicDisplay.

Referenced by start_().

◆ data()

void ssd1306::data ( uint8_t  c)
privatenoexcept

Send a data byte to the display driver hardware.

Parameters
cThe data byte to send to the display.

◆ display()

void ssd1306::display ( )
finalvirtualnoexcept

Flush the screen buffer contents to the hardware display buffer.

Implements embvm::basicDisplay.

References display_buffer_, i2c_, i2c_addr_, t, and embvm::i2c::write.

Referenced by clearAndDisplay(), and start_().

◆ drawBitmap()

void ssd1306::drawBitmap ( uint8_t bitmap)
finalvirtualnoexcept

Replace the screen buffer with a bitmap.

Supply a bitmap to write to the screen buffer. If the size of the bitmap is less than the size of the screen buffer, the remainder of the screen buffer will not be modified.

Parameters
bitmapBitmap array which will be used to overwrite the screen buffer.

Implements embvm::basicDisplay.

References memcpy().

◆ drawChar() [1/2]

void ssd1306::drawChar ( coord_t  x,
coord_t  y,
uint8_t  character,
color  c,
mode  m 
)
finalvirtualnoexcept

Draw an ASCII character with a specific color and mode.

Draw an ASCII character using a specific color and draw mode with the upper left corner of the character located at (x,y).

Parameters
xX-coordinate representing the top-left of the character.
yY-coordinate representing the top-left of the character.
characterthe ASCII character to draw. Must be present in the font file. If the requested character is not present, nothing will be drawn on the screen buffer.
cPixel color.
mMode used to update the screen buffer.

Implements embvm::basicDisplay.

References assert.

◆ drawChar() [2/2]

void embvm::basicDisplay::drawChar ( coord_t  x,
coord_t  y,
uint8_t  character 
)
inlinenoexceptinherited

Draw an ASCII character.

Draw an ASCII character using the configured color and draw mode with the upper left corner of the character located at (x,y).

Parameters
xX-coordinate representing the top-left of the character.
yY-coordinate representing the top-left of the character.
characterthe ASCII character to draw. Must be present in the font file. If the requested character is not present, nothing will be drawn on the screen buffer.

References embvm::basicDisplay::color_, and embvm::basicDisplay::mode_.

◆ drawCharMultiRow()

void ssd1306::drawCharMultiRow ( coord_t  x,
coord_t  y,
uint8_t  character,
color  c,
mode  m 
)
privatenoexcept

◆ drawCharSingleRow()

void ssd1306::drawCharSingleRow ( coord_t  x,
coord_t  y,
uint8_t  character,
color  c,
mode  m 
)
privatenoexcept

◆ drawColor()

void embvm::basicDisplay::drawColor ( color  c)
inlinenoexceptinherited

Set color.

Set the current draw's color. Only WHITE and BLACK available.

Parameters
cThe desired draw color setting.

References assert, embvm::basicDisplay::black, embvm::basicDisplay::color_, and embvm::basicDisplay::white.

Referenced by start_().

◆ drawMode()

virtual void embvm::basicDisplay::drawMode ( mode  m)
inlinevirtualnoexceptinherited

Set draw mode.

Parameters
mDesired draw mode: NORM or XOR.

References assert, embvm::basicDisplay::mode_, embvm::basicDisplay::normal, and embvm::basicDisplay::XOR.

Referenced by start_().

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
inlinenoexceptinherited

Returns the registered type ID of the driver.

When using DriverBase interfaces, clients can retrieve the registered driver type in order to up-cast to the correct interface.

The type is returned as a embvm::DriverType_t rather than a embvm::DriverType enum to work with custom user-defined types. Enforcing a embvm::DriverType return value would prevent clients from defining and using their own custom types.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ flipHorizontal()

void ssd1306::flipHorizontal ( bool  flip)
finalvirtualnoexcept

Horizontal flip.

Flip the graphics on the display horizontally.

Parameters
flipTrue enables horizontal flip, false disables horizontal flip.

Implements embvm::basicDisplay.

References x0.

◆ flipVertical()

void ssd1306::flipVertical ( bool  flip)
finalvirtualnoexcept

Vertical flip.

Flip the graphics on the display vertically.

Parameters
flipTrue enables vertical flip, false disables vertical flip.

Implements embvm::basicDisplay.

◆ fontHeight()

uint8_t embdrv::ssd1306::fontHeight ( ) const
inlinenoexcept

Get the font height.

Returns
the height of the currently selected font in pixels

References fontHeight_.

◆ fontStartChar()

uint8_t embdrv::ssd1306::fontStartChar ( ) const
inlinenoexcept

Get the starting character for the font.

Returns
the starting ASCII character for the currently selected font

References fontStartChar_.

◆ fontTotalChar()

uint8_t embdrv::ssd1306::fontTotalChar ( ) const
inlinenoexcept

Get the total number of characters supported by the font.

Returns
the number of characters supported by the currently selected font

References fontTotalChar_.

◆ fontType() [1/2]

uint8_t ssd1306::fontType ( uint8_t  type)
noexcept

Set the font type.

Parameters
typeIndex for the font to use
Returns
the currently selected font.

References assert, and type.

◆ fontType() [2/2]

uint8_t embdrv::ssd1306::fontType ( ) const
inlinenoexcept

Get the current font type.

Returns
the currently selected font.

References fontType_.

Referenced by start_().

◆ fontWidth()

uint8_t embdrv::ssd1306::fontWidth ( ) const
inlinenoexcept

Get the font width.

Returns
the width of the currently selected font in pixels

References fontWidth_.

◆ i2c_write()

void ssd1306::i2c_write ( const uint8_t buffer,
uint8_t  size,
const embvm::i2c::master::cb_t cb 
)
privatenoexcept

Helper function which performs an I2C write.

Parameters
bufferThe transaction buffer.
sizeThe size of the write.
cbThe callback function to invoke when the write completes.

References t, and embvm::i2c::write.

◆ invert()

void ssd1306::invert ( enum invert  inv)
finalvirtualnoexcept

Invert the display color.

The WHITE color of the display will turn to BLACK and the BLACK will turn to WHITE.

Parameters
invinvert::invert uses color inversion, invert::normal uses the display standard.

Implements embvm::basicDisplay.

References normal.

◆ line() [1/2]

void ssd1306::line ( coord_t  x0,
coord_t  y0,
coord_t  x1,
coord_t  y1,
color  c,
mode  m 
)
finalvirtualnoexcept

Draw a line with a specific color and mode.

Draw line with a specific color setting and draw mode from (x0,y0) to (x1,y1) of the screen buffer.

Parameters
x0X-coordinate where the line originates.
y0Y-coordinate where the line originates.
x1X-coordinate where the line terminates.
y1Y-coordinate where the line terminates.
cPixel color.
mMode used to update the screen buffer.

Implements embvm::basicDisplay.

References abs(), swap, and x0.

◆ line() [2/2]

void embvm::basicDisplay::line ( coord_t  x0,
coord_t  y0,
coord_t  x1,
coord_t  y1 
)
inlinenoexceptinherited

Draw a line.

Draw a line using the configured color setting and draw mode from (x0,y0) to (x1,y1) of the screen buffer.

Parameters
x0X-coordinate where the line originates.
y0Y-coordinate where the line originates.
x1X-coordinate where the line terminates.
y1Y-coordinate where the line terminates.

References embvm::basicDisplay::color_, embvm::basicDisplay::mode_, and x0.

Referenced by embvm::basicDisplay::lineH(), and embvm::basicDisplay::lineV().

◆ lineH() [1/2]

void embvm::basicDisplay::lineH ( coord_t  x,
coord_t  y,
uint8_t  width 
)
inlinenoexceptinherited

Draw a horizontal line.

Draw a horizontal line using the configured color setting and draw mode from (x,y) to (x+width,y) in the screen buffer.

Parameters
xX-coordinate where the line originates.
yY-coordinate where the line originates.
widthLength of the line, in pixels. The line will terminate at coordinate (x+width, y).

References embvm::basicDisplay::color_, and embvm::basicDisplay::mode_.

◆ lineH() [2/2]

void embvm::basicDisplay::lineH ( coord_t  x,
coord_t  y,
uint8_t  width,
color  c,
mode  m 
)
inlinenoexceptinherited

Draw a horizontal line with a specific color and mode.

Draw a horizontal line with a specific color setting and draw mode from (x,y) to (x+width,y) in the screen buffer.

Parameters
xX-coordinate where the line originates.
yY-coordinate where the line originates.
widthLength of the line, in pixels. The line will terminate at coordinate (x+width, y).
cPixel color.
mMode used to update the screen buffer.

References embvm::basicDisplay::line().

◆ lineV() [1/2]

void embvm::basicDisplay::lineV ( coord_t  x,
coord_t  y,
uint8_t  height 
)
inlinenoexceptinherited

Draw a vertical line.

Draw a vertical line using the configured color setting and draw mode from (x,y) to (x,y+height) in the screen buffer.

Parameters
xX-coordinate where the line originates.
yY-coordinate where the line originates.
heightLength of the line, in pixels. The line will terminate at coordinate (x, y+height).

References embvm::basicDisplay::color_, and embvm::basicDisplay::mode_.

◆ lineV() [2/2]

void embvm::basicDisplay::lineV ( coord_t  x,
coord_t  y,
uint8_t  height,
color  c,
mode  m 
)
inlinenoexceptinherited

Draw a vertical line with a specific color and mode.

Draw a vertical line using a specific color setting and draw mode from (x,y) to (x,y+height) in the screen buffer.

Parameters
xX-coordinate where the line originates.
yY-coordinate where the line originates.
heightLength of the line, in pixels. The line will terminate at coordinate (x, y+height).
cPixel color.
mMode used to update the screen buffer.

References embvm::basicDisplay::line().

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ pixel() [1/2]

void ssd1306::pixel ( coord_t  x,
coord_t  y,
color  c,
mode  m 
)
finalvirtualnoexcept

Draw a pixel with a specific color and mode.

Draw a pixel at position (x,y) with a specific color setting and draw mode.

Parameters
xX-coordinate of the pixel.
yY-coordinate of the pixel.
cPixel color.
mMode used to update the screen buffer.

Implements embvm::basicDisplay.

References SET_BIT.

◆ pixel() [2/2]

void embvm::basicDisplay::pixel ( coord_t  x,
coord_t  y 
)
inlinenoexceptinherited

Draw a pixel in the screen buffer.

Draw pixel using the configured color setting and draw mode in the screen buffer's x,y position.

Parameters
xX-coordinate of the pixel.
yY-coordinate of the pixel.

References embvm::basicDisplay::color_, and embvm::basicDisplay::mode_.

◆ printString() [1/2]

void embvm::basicDisplay::printString ( coord_t  x,
coord_t  y,
const char *  str 
)
inlinenoexceptinherited

Print a string on the display.

Parameters
xThe x-coordinate to start the string.
yThe y-coordinate to start the string.
strThe string to print to the display.

References strlen().

◆ printString() [2/2]

void embvm::basicDisplay::printString ( coord_t  x,
coord_t  y,
const char *  str,
size_t  length 
)
inlinenoexceptinherited

Print a string on the display.

Parameters
xThe x-coordinate to start the string.
yThe y-coordinate to start the string.
strThe string to print to the display.
lengthThe number of characters in str.

References embvm::basicDisplay::cursor(), length, and embvm::basicDisplay::putchar().

◆ putchar()

void ssd1306::putchar ( uint8_t  c)
finalvirtualnoexcept

Print a character on the display.

Parameters
cthe character to print to the display

Implements embvm::basicDisplay.

◆ rect() [1/2]

void ssd1306::rect ( coord_t  x,
coord_t  y,
uint8_t  width,
uint8_t  height,
color  c,
mode  m 
)
finalvirtualnoexcept

Draw a rectangle with a specific color and mode.

Draw a rectangle with a specific color setting and draw mode from (x,y) to (x+width,y+height) in the screen buffer. Only the boundary of the rectangle will be drawn.

Parameters
xX-coordinate where the rectangle originates.
yY-coordinate where the rectangle originates.
widthWidth of the rectangle, in pixels. The rectangle width spans from x to x+width.
heightHeight of the rectangle, in pixels. The rectangle height spans from y + y+height.
cPixel color.
mMode used to update the screen buffer.

Implements embvm::basicDisplay.

◆ rect() [2/2]

void embvm::basicDisplay::rect ( coord_t  x,
coord_t  y,
uint8_t  width,
uint8_t  height 
)
inlinenoexceptinherited

Draw a rectangle.

Draw a rectangle using the configured color setting and draw mode from (x,y) to (x+width,y+height) in the screen buffer. Only the boundary of the rectangle will be drawn.

Parameters
xX-coordinate where the rectangle originates.
yY-coordinate where the rectangle originates.
widthWidth of the rectangle, in pixels. The rectangle width spans from x to x+width.
heightHeight of the rectangle, in pixels. The rectangle height spans from y + y+height.

References embvm::basicDisplay::color_, and embvm::basicDisplay::mode_.

◆ rectFill() [1/2]

void ssd1306::rectFill ( coord_t  x,
coord_t  y,
uint8_t  width,
uint8_t  height,
color  c,
mode  m 
)
finalvirtualnoexcept

Draw a filled rectangle with a specific color and mode.

Draw a filled rectangle using a specific color setting and draw mode from (x,y) to (x+width,y+height) in the screen buffer. The interior of the rectangle will be filled with the specified color setting.

Parameters
xX-coordinate where the rectangle originates.
yY-coordinate where the rectangle originates.
widthWidth of the rectangle, in pixels. The rectangle width spans from x to x+width.
heightHeight of the rectangle, in pixels. The rectangle height spans from y + y+height.
cPixel color.
mMode used to update the screen buffer.

Implements embvm::basicDisplay.

◆ rectFill() [2/2]

void embvm::basicDisplay::rectFill ( coord_t  x,
coord_t  y,
uint8_t  width,
uint8_t  height 
)
inlinenoexceptinherited

Draw a filled rectangle.

Draw a filled rectangle using the configured color setting and draw mode from (x,y) to (x+width,y+height) in the screen buffer. The interior of the rectangle will be filled with the configured color setting.

Parameters
xX-coordinate where the rectangle originates.
yY-coordinate where the rectangle originates.
widthWidth of the rectangle, in pixels. The rectangle width spans from x to x+width.
heightHeight of the rectangle, in pixels. The rectangle height spans from y + y+height.

References embvm::basicDisplay::color_, and embvm::basicDisplay::mode_.

◆ restart()

void embvm::DriverBase::restart ( )
inlinenoexceptinherited

Restart the driver.

Calls stop() and then start() on the driver. If the driver is not started, then it will be started after the start() function is invoked.

References embvm::DriverBase::start(), and embvm::DriverBase::stop().

◆ screenHeight()

uint8_t ssd1306::screenHeight ( ) const
finalvirtualnoexcept

Check the screen height.

The drived class must implement this function.

Returns
The height of the screen in pixels.

Implements embvm::basicDisplay.

References SCREEN_HEIGHT.

◆ screenWidth()

uint8_t ssd1306::screenWidth ( ) const
finalvirtualnoexcept

Check the screen width.

The drived class must implement this function.

Returns
The width of the screen in pixels.

Implements embvm::basicDisplay.

References SCREEN_WIDTH.

◆ scrollLeft()

void ssd1306::scrollLeft ( coord_t  start,
coord_t  stop 
)
finalvirtualnoexcept

Enable left scrolling.

Set row start to row stop on the display to scroll left.

Parameters
startThe start row index.
stopThe stop row index.
Precondition
Scrolling is not enabled, stop < start.
Postcondition
The display is scrolling to the left.

Implements embvm::basicDisplay.

References assert.

◆ scrollRight()

void ssd1306::scrollRight ( coord_t  start,
coord_t  stop 
)
finalvirtualnoexcept

Enable right scrolling.

Set row start to row stop on the display to scroll right.

Parameters
startThe start row index.
stopThe stop row index.
Precondition
Scrolling is not enabled, start < stop.
Postcondition
The display is scrolling to the right.

Implements embvm::basicDisplay.

References assert.

◆ scrollStop()

void ssd1306::scrollStop ( )
finalvirtualnoexcept

Stop scrolling.

Stop the scrolling of graphics on the display.

Implements embvm::basicDisplay.

References command().

◆ scrollVertLeft()

void ssd1306::scrollVertLeft ( coord_t  start,
coord_t  stop 
)
finalvirtualnoexcept

Implements embvm::basicDisplay.

References assert.

◆ scrollVertRight()

void ssd1306::scrollVertRight ( coord_t  start,
coord_t  stop 
)
finalvirtualnoexcept

Implements embvm::basicDisplay.

References assert.

◆ setColumnAddress()

void embdrv::ssd1306::setColumnAddress ( uint8_t  add)
privatenoexcept

Set the column address.

Parameters
addThe address of the column.

◆ setPageAddress()

void embdrv::ssd1306::setPageAddress ( uint8_t  add)
privatenoexcept

Set the page address.

Parameters
addThe address of the page.

◆ start()

◆ start_()

void ssd1306::start_ ( )
finalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Display init sequence These values were inherited from Sparkfun's example

Implements embvm::basicDisplay.

References clear(), COLUMN_OFFSET, command(), cursor(), display(), embvm::basicDisplay::drawColor(), embvm::basicDisplay::drawMode(), fontType(), embvm::basicDisplay::normal, SCREEN_WIDTH, embvm::basicDisplay::white, and x0.

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
true if the driver is running (started), false if not running (stopped).

References embvm::DriverBase::started_.

Referenced by embdrv::aardvarkSPIMaster::configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkGPIOOutput< 5 >::set(), embdrv::vl53l1x::start_(), embdrv::aardvarkAdapter::start_(), and embdrv::aardvarkAdapter::stop_().

◆ stop()

◆ stop_()

void ssd1306::stop_ ( )
finalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::basicDisplay.

References command().

◆ totalFonts()

uint8_t ssd1306::totalFonts ( ) const
noexcept

Get the total number of supported fonts.

Returns
the number of supported fonts

◆ type()

static constexpr embvm::DriverType embvm::basicDisplay::type ( )
inlinestaticnoexceptinherited

Basic Display Driver Type ID.

Returns
Basic Display type ID.

References embvm::BASIC_DISPLAY.

Member Data Documentation

◆ color_

◆ COLUMN_OFFSET

constexpr uint8_t embdrv::ssd1306::COLUMN_OFFSET = 32
staticprivate

The number of columns offset into the display where the active display area starts.

Referenced by start_().

◆ cursorX_

uint8_t embdrv::ssd1306::cursorX_ = 0
private

X-axies position of the cursor.

◆ cursorY_

uint8_t embdrv::ssd1306::cursorY_ = 0
private

Y-axis position of the cursor.

◆ display_buffer_

uint8_t embdrv::ssd1306::display_buffer_[SCREEN_BUFFER_SIZE+1] = {0}
private

OLED screen buffer.

Page buffer is required because in SPI and I2C mode, the host cannot read the SSD1306's GDRAM of the controller. This page buffer serves as a scratch RAM for graphical functions. All drawing function will first be drawn on this page buffer, only upon calling display() function will transfer the page buffer to the actual LCD controller's memory.

The additional byte is to represent the data word byte, which allows us to send the entire buffer in one shot

Referenced by display(), and ssd1306().

◆ fontHeight_

uint8_t embdrv::ssd1306::fontHeight_ = 0
private

Referenced by fontHeight().

◆ fontMapWidth_

uint16_t embdrv::ssd1306::fontMapWidth_ = 0
private

◆ fonts_

const std::array< const uint8_t *, 2 > ssd1306::fonts_ = {font5x7, font8x16}
staticprivate

Array of fonts supported by this driver.

NOTE: the SSD1306 DOES NOT WORK WITH A REPEATED START CONDITION There must be no start between the data byte and the data stream.

◆ fontStartChar_

uint8_t embdrv::ssd1306::fontStartChar_ = 0
private

Referenced by fontStartChar().

◆ fontTotalChar_

uint8_t embdrv::ssd1306::fontTotalChar_ = 0
private

Referenced by fontTotalChar().

◆ fontType_

uint8_t embdrv::ssd1306::fontType_ = 0
private

Referenced by fontType().

◆ fontWidth_

uint8_t embdrv::ssd1306::fontWidth_ = 0
private

Referenced by fontWidth().

◆ i2c_

embvm::i2c::master& embdrv::ssd1306::i2c_
private

The i2c instance this display driver is attached to.

Referenced by display().

◆ i2c_addr_

uint8_t embdrv::ssd1306::i2c_addr_
private

The I2C address for this dispaly.

Referenced by display().

◆ i2c_pool_

etl::variant_pool<128, uint8_t, uint16_t, uint32_t> embdrv::ssd1306::i2c_pool_ {}
private

Static memory pool which is used for display I2C transactions.

◆ mode_

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ screen_buffer_

uint8_t* const embdrv::ssd1306::screen_buffer_ = &display_buffer_[1]
private

Pointer alias to the display_buffer_ which accounts for the single byte reserved for the DATA command value.

◆ SCREEN_BUFFER_SIZE

constexpr size_t embdrv::ssd1306::SCREEN_BUFFER_SIZE = ((SCREEN_WIDTH * SCREEN_HEIGHT) / 8)
staticprivate

The size of the screen buffer We divide by 8 because each byte controls the state of 8 pixels.

◆ SCREEN_HEIGHT

constexpr uint8_t embdrv::ssd1306::SCREEN_HEIGHT = 48
staticprivate

The height of the screen in pixels.

Referenced by screenHeight().

◆ SCREEN_WIDTH

constexpr uint8_t embdrv::ssd1306::SCREEN_WIDTH = 64
staticprivate

The width of the scren in pixels.

Referenced by screenWidth(), and start_().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
protectedinherited

Tracks the driver state.

True if the driver has been started, false if it has been stopped or not yet started.

Referenced by embvm::DriverBase::start(), embvm::DriverBase::started(), and embvm::DriverBase::stop().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().

◆ embdrv::vl53l1x

class embdrv::vl53l1x

ST VL53L1X Time-of-Flight Sensor Driver.

This driver is configured to work with I2C. You must initialize the device with an I2C Master.

Inheritance diagram for embdrv::vl53l1x:
Inheritance graph

Public Types

using rate_cb_t = stdext::inplace_function< void(uint16_t)>
 Alias for signalRate() callback function. More...
 
using status_cb_t = stdext::inplace_function< void(embvm::tof::status)>
 Alias for the rangeStatus() callback function. More...
 
using read_cb_t = stdext::inplace_function< void(uint16_t)>
 ToF Callback function which retuns distance in mm. More...
 

Public Member Functions

 vl53l1x (embvm::i2c::master &i2c, uint8_t address=VL53L1X_DEFAULT_I2C_ADDR) noexcept
 Create a VL53L1X device. More...
 
void read () noexcept final
 Trigger a sensor read. More...
 
void reset () noexcept final
 Reset the ToF sensor. More...
 
embvm::tof::distance_t getMaxRangeForModeDark (embvm::tof::mode m) const noexcept final
 Check the maximum range in the dark. More...
 
embvm::tof::distance_t getMaxRangeForModeStrongLight (embvm::tof::mode m) const noexcept final
 Check the maximum range in strong light conditions. More...
 
embvm::tof::mode mode (embvm::tof::mode m) noexcept final
 Set the ToF ranging mode. More...
 
void signalRate () noexcept
 Get the current signal rate. More...
 
void rangeStatus () noexcept
 Get the ranging status When called, registered range status callbacks will be invoked with the signal rate. More...
 
void registerReadCallback (const read_cb_t &cb) noexcept final
 Register a callback for the read() function. More...
 
void registerReadCallback (read_cb_t &&cb) noexcept final
 Register a callback for the read() function. More...
 
void registerSignalRateCallback (const rate_cb_t &cb) noexcept
 Register a callback for use with the signalRate() function. More...
 
void registerSignalRateCallback (rate_cb_t &&cb) noexcept
 
void registerStatusCallback (const status_cb_t &cb) noexcept
 Register a callback for use with the rangeStatus() function. More...
 
void registerStatusCallback (status_cb_t &&cb) noexcept
 
tof::mode mode () const noexcept
 Get the ToF ranging mode. More...
 
void start () noexcept
 Start the driver. More...
 
void stop () noexcept
 Stop the driver. More...
 
void restart () noexcept
 Restart the driver. More...
 
type_safe::boolean started () const noexcept
 Check if the driver has been started. More...
 
constexpr embvm::DriverType_t DriverType () const noexcept
 Returns the registered type ID of the driver. More...
 
constexpr const std::string_view & name () const noexcept
 Provides a string_view reference of the driver name. More...
 
constexpr const char * name_cstr () const noexcept
 Provides a c-string version of the driver name. More...
 
virtual DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 ToF Driver Type ID. More...
 

Protected Member Functions

void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 

Protected Attributes

tof::mode mode_ = tof::mode::defaultRange
 The configured ranging mode for the ToF sensor. More...
 
type_safe::boolean started_ = false
 Tracks the driver state. More...
 
const std::string_view name_
 Name of the driver instance. More...
 
const embvm::DriverType_t type_
 Type ID of the driver instance. More...
 

Private Member Functions

void readReg (const uint16_t *reg_buf, uint8_t *rx_buffer, size_t rx_size, const embvm::i2c::master::cb_t &cb) noexcept
 Convenience function to read a register from the VL51L1X device. More...
 
void writeReg (uint16_t reg, const uint8_t *tx_buffer, size_t tx_size, const embvm::i2c::master::cb_t &cb) noexcept
 Convenience function to write to a register on the VL51L1X device. More...
 
void checkModelID () noexcept
 Check the model ID of the VL53L1X sensor. More...
 
void readTrim () noexcept
 Read the trim values of the sensor and update the config_block_. More...
 
void startMeasurement () noexcept
 Trigger a range measurement. More...
 
void readOscillatorCal () noexcept
 Read the oscillator calibration and store it in the private variable osc_calibrate_val_. More...
 
void clearInterrupt () noexcept
 Clear the VL53L1X pending interrupt. More...
 
void dataReady () noexcept
 Check if the range data is ready. More...
 
void readData () noexcept
 Read the range data from the device. More...
 
void dataReadyCb (embvm::i2c::op_t op, embvm::i2c::status status) noexcept
 Local driver callback which is invoked when data is ready. More...
 
void kickoffMeasurementOnceFirmwareReady () noexcept
 Function that starts the sensor firmware and begins measurements. More...
 
void rangeStatusCb (uint8_t status) noexcept
 Private callback function to get the range status. More...
 
embvm::tof::status convertStatus (uint8_t status) noexcept
 Convert the raw range status code to the framework ToF statuses. More...
 
template<typename TData >
void destroy (const TData *ptr) noexcept
 
template<typename TData >
TData * create (TData input=0) noexcept
 

Private Attributes

embvm::i2c::masteri2c_
 The I2C master bus that this device is connected to. More...
 
const uint8_t address_
 The I2C address for the VL53L1X. More...
 
uint8_t model_id_ = 0
 The model ID for the VL53L1X, read from the device during start(). More...
 
uint16_t osc_calibrate_val_ = 0
 
etl::generic_pool< sizeof(uint32_t), alignof(uint32_t), 64 > i2c_pool_ {}
 Static memory pool used for I2C transactions. More...
 
std::mutex lock_ {}
 
etl::list< read_cb_t, 2 > read_cb_list_ {}
 List that stores the read() callback functions. More...
 
etl::list< status_cb_t, 2 > status_cb_list_ {}
 List that stores the rangeStatus() callback functions. More...
 
etl::list< rate_cb_t, 2 > rate_cb_list_ {}
 List that stores the signalRate() callback functions. More...
 
std::array< uint8_t, 137 > config_block_
 This is 135 bytes to be written every time to the VL53L1X to initiate a measurement 0x29 is written to memory location 0x01, which is the register for the I2C address which is indeed 0x29. More...
 

Member Typedef Documentation

◆ rate_cb_t

using embdrv::vl53l1x::rate_cb_t = stdext::inplace_function<void(uint16_t)>

Alias for signalRate() callback function.

◆ read_cb_t

using embvm::tof::sensor::read_cb_t = stdext::inplace_function<void(uint16_t)>
inherited

ToF Callback function which retuns distance in mm.

◆ status_cb_t

using embdrv::vl53l1x::status_cb_t = stdext::inplace_function<void(embvm::tof::status)>

Alias for the rangeStatus() callback function.

Constructor & Destructor Documentation

◆ vl53l1x()

embdrv::vl53l1x::vl53l1x ( embvm::i2c::master i2c,
uint8_t  address = VL53L1X_DEFAULT_I2C_ADDR 
)
inlineexplicitnoexcept

Create a VL53L1X device.

Parameters
i2cThe i2c master driver that this device is connected to.
addressThe i2c address of the sensor.

Member Function Documentation

◆ checkModelID()

void vl53l1x::checkModelID ( )
privatenoexcept

Check the model ID of the VL53L1X sensor.

References assert, create(), model_id_, r, and readReg().

Referenced by start_().

◆ clearInterrupt()

void vl53l1x::clearInterrupt ( )
privatenoexcept

Clear the VL53L1X pending interrupt.

References create(), and writeReg().

Referenced by readData().

◆ convertStatus()

embvm::tof::status vl53l1x::convertStatus ( uint8_t  status)
privatenoexcept

Convert the raw range status code to the framework ToF statuses.

Parameters
statusThe raw sensor status code.
Returns
The equivalent framework standard status code.

References embvm::tof::crosstalkSignalError, embvm::tof::hardwareError, embvm::tof::invalidRoi, embvm::tof::noChange, embvm::tof::notReady, embvm::tof::ok, embvm::tof::outOfBoundsError, embvm::tof::processingError, embvm::tof::rangeValidMergedPulse, embvm::tof::rangeValidMinRangeClipped, embvm::tof::sigmaError, and embvm::tof::signalError.

◆ create()

template<typename TData >
TData* embdrv::vl53l1x::create ( TData  input = 0)
inlineprivatenoexcept

◆ dataReady()

void vl53l1x::dataReady ( )
privatenoexcept

Check if the range data is ready.

References create(), dataReadyCb(), and readReg().

Referenced by read().

◆ dataReadyCb()

void vl53l1x::dataReadyCb ( embvm::i2c::op_t  op,
embvm::i2c::status  status 
)
privatenoexcept

Local driver callback which is invoked when data is ready.

References embvm::i2c::ok.

Referenced by dataReady().

◆ destroy()

template<typename TData >
void embdrv::vl53l1x::destroy ( const TData *  ptr)
inlineprivatenoexcept

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
inlinenoexceptinherited

Returns the registered type ID of the driver.

When using DriverBase interfaces, clients can retrieve the registered driver type in order to up-cast to the correct interface.

The type is returned as a embvm::DriverType_t rather than a embvm::DriverType enum to work with custom user-defined types. Enforcing a embvm::DriverType return value would prevent clients from defining and using their own custom types.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ getMaxRangeForModeDark()

embvm::tof::distance_t vl53l1x::getMaxRangeForModeDark ( embvm::tof::mode  m) const
finalvirtualnoexcept

Check the maximum range in the dark.

Returns
the sensor's maximum distance capability (in mm) in the dark.

Implements embvm::tof::sensor.

References embvm::tof::defaultRange, embvm::tof::INVALID_RANGE, embvm::tof::longRange, embvm::tof::medRange, and embvm::tof::shortRange.

◆ getMaxRangeForModeStrongLight()

embvm::tof::distance_t vl53l1x::getMaxRangeForModeStrongLight ( embvm::tof::mode  m) const
finalvirtualnoexcept

Check the maximum range in strong light conditions.

Returns
the sensor's maximum distance capability (in mm) in strong light.

Implements embvm::tof::sensor.

References embvm::tof::defaultRange, embvm::tof::INVALID_RANGE, embvm::tof::longRange, embvm::tof::medRange, and embvm::tof::shortRange.

◆ kickoffMeasurementOnceFirmwareReady()

void vl53l1x::kickoffMeasurementOnceFirmwareReady ( )
privatenoexcept

Function that starts the sensor firmware and begins measurements.

References create(), destroy(), embvm::i2c::ok, r, readReg(), and startMeasurement().

◆ mode() [1/2]

embvm::tof::mode vl53l1x::mode ( embvm::tof::mode  m)
finalvirtualnoexcept

Set the ToF ranging mode.

Parameters
mThe desired ToF ranging mode.
Returns
the active ToF mode.

Implements embvm::tof::sensor.

References embvm::tof::defaultRange, embvm::tof::longRange, embvm::tof::medRange, and embvm::tof::shortRange.

Referenced by FWDemoSimulatorHWPlatform::readAndSetToFMode().

◆ mode() [2/2]

tof::mode embvm::tof::sensor::mode ( ) const
inlinenoexceptinherited

Get the ToF ranging mode.

Returns
the currently configured ToF ranging mode.

References embvm::tof::sensor::mode_.

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ rangeStatus()

void vl53l1x::rangeStatus ( )
noexcept

Get the ranging status When called, registered range status callbacks will be invoked with the signal rate.

To register a callback, use registerStatusCallback().

References create(), destroy(), embvm::i2c::ok, r, rangeStatusCb(), and readReg().

◆ rangeStatusCb()

void vl53l1x::rangeStatusCb ( uint8_t  status)
privatenoexcept

Private callback function to get the range status.

References s.

Referenced by rangeStatus().

◆ read()

void vl53l1x::read ( )
finalvirtualnoexcept

Trigger a sensor read.

Trigger an asynchronous read of the ToF sensor. The result will be provided to consumers through a callback function. When the read() operation completes, the callback will be invoked with the result.

Implements embvm::tof::sensor.

References dataReady().

◆ readData()

void vl53l1x::readData ( )
privatenoexcept

Read the range data from the device.

References clearInterrupt(), create(), embvm::i2c::ok, r, read_cb_list_, and readReg().

◆ readOscillatorCal()

void vl53l1x::readOscillatorCal ( )
privatenoexcept

Read the oscillator calibration and store it in the private variable osc_calibrate_val_.

References create(), osc_calibrate_val_, r, and readReg().

Referenced by start_().

◆ readReg()

void vl53l1x::readReg ( const uint16_t reg_buf,
uint8_t rx_buffer,
size_t  rx_size,
const embvm::i2c::master::cb_t cb 
)
privatenoexcept

Convenience function to read a register from the VL51L1X device.

Parameters
reg_bufthe buffer containing the TX register data.
rx_bufferThe buffer to store the received contents into.
rx_sizethe number of expected RX bytes.
cbThe callback function to invoke when the register read completes.

References t, and embvm::i2c::writeRead.

Referenced by checkModelID(), dataReady(), kickoffMeasurementOnceFirmwareReady(), rangeStatus(), readData(), readOscillatorCal(), readTrim(), and signalRate().

◆ readTrim()

void vl53l1x::readTrim ( )
privatenoexcept

Read the trim values of the sensor and update the config_block_.

References embutil::byteswap(), config_block_, create(), r, and readReg().

Referenced by start_().

◆ registerReadCallback() [1/2]

void embdrv::vl53l1x::registerReadCallback ( const read_cb_t cb)
inlinefinalvirtualnoexcept

Register a callback for the read() function.

The read() function works asynchronously, and the result will be provided to consumers through a callback function. When the read() operation completes, the callback will be invoked with the result.

This function must be implemented by the derived class.

Parameters
cbThe functor which will be called when read() completes.

Implements embvm::tof::sensor.

References read_cb_list_.

◆ registerReadCallback() [2/2]

void embdrv::vl53l1x::registerReadCallback ( read_cb_t &&  cb)
inlinefinalvirtualnoexcept

Register a callback for the read() function.

The read() function works asynchronously, and the result will be provided to consumers through a callback function. When the read() operation completes, the callback will be invoked with the result.

This function must be implemented by the derived class.

Parameters
cbThe functor which will be called when read() completes.

Implements embvm::tof::sensor.

References read_cb_list_.

◆ registerSignalRateCallback() [1/2]

void embdrv::vl53l1x::registerSignalRateCallback ( const rate_cb_t cb)
inlinenoexcept

Register a callback for use with the signalRate() function.

Parameters
cbThe callback to invoke hen signalRate() completes.

References rate_cb_list_.

◆ registerSignalRateCallback() [2/2]

void embdrv::vl53l1x::registerSignalRateCallback ( rate_cb_t &&  cb)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References rate_cb_list_.

◆ registerStatusCallback() [1/2]

void embdrv::vl53l1x::registerStatusCallback ( const status_cb_t cb)
inlinenoexcept

Register a callback for use with the rangeStatus() function.

Parameters
cbThe callback to invoke when rangeStatus() completes.

References status_cb_list_.

◆ registerStatusCallback() [2/2]

void embdrv::vl53l1x::registerStatusCallback ( status_cb_t &&  cb)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References status_cb_list_.

◆ reset()

void vl53l1x::reset ( )
finalvirtualnoexcept

Reset the ToF sensor.

Implements embvm::tof::sensor.

References destroy(), embvm::i2c::ok, UINT8_C, and writeReg().

Referenced by start_().

◆ restart()

void embvm::DriverBase::restart ( )
inlinenoexceptinherited

Restart the driver.

Calls stop() and then start() on the driver. If the driver is not started, then it will be started after the start() function is invoked.

References embvm::DriverBase::start(), and embvm::DriverBase::stop().

◆ signalRate()

void vl53l1x::signalRate ( )
noexcept

Get the current signal rate.

When called, registered signal rate callbacks will be invoked with the signal rate. To register a callback, use registerSignalRateCallback().

References create(), embvm::i2c::ok, r, rate_cb_list_, and readReg().

◆ start()

◆ start_()

void vl53l1x::start_ ( )
finalprotectedvirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::tof::sensor.

References checkModelID(), i2c_, readOscillatorCal(), readTrim(), reset(), embvm::DriverBase::start(), and embvm::DriverBase::started().

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
true if the driver is running (started), false if not running (stopped).

References embvm::DriverBase::started_.

Referenced by embdrv::aardvarkSPIMaster::configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkGPIOOutput< 5 >::set(), start_(), embdrv::aardvarkAdapter::start_(), and embdrv::aardvarkAdapter::stop_().

◆ startMeasurement()

void vl53l1x::startMeasurement ( )
privatenoexcept

Trigger a range measurement.

References address_, config_block_, i2c_, t, and embvm::i2c::write.

Referenced by kickoffMeasurementOnceFirmwareReady().

◆ stop()

◆ stop_()

void vl53l1x::stop_ ( )
finalprotectedvirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::tof::sensor.

◆ type()

static constexpr embvm::DriverType embvm::tof::sensor::type ( )
inlinestaticnoexceptinherited

ToF Driver Type ID.

Returns
ToF type ID.

References embvm::TIME_OF_FLIGHT.

◆ writeReg()

void vl53l1x::writeReg ( uint16_t  reg,
const uint8_t tx_buffer,
size_t  tx_size,
const embvm::i2c::master::cb_t cb 
)
privatenoexcept

Convenience function to write to a register on the VL51L1X device.

Parameters
regThe register to write to.
tx_bufferThe buffer containing the tx data to send to the target register.
tx_sizeThe number of bytes to transmit
cbThe callback function to invoke when the register write completes.

References embutil::byteswap(), t, and embvm::i2c::write.

Referenced by clearInterrupt(), and reset().

Member Data Documentation

◆ address_

const uint8_t embdrv::vl53l1x::address_
private

The I2C address for the VL53L1X.

Referenced by startMeasurement().

◆ config_block_

std::array<uint8_t, 137> embdrv::vl53l1x::config_block_
private
Initial value:
= {
0x00, 0x00, 0x29, 0x02, 0x10, 0x00, 0x28, 0xBC, 0x7A, 0x81,
0x80, 0x07, 0x95, 0x00, 0xED, 0xFF, 0xF7, 0xFD,
0x9E, 0x0E, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00,
0x28, 0x00, 0x0D, 0x0A, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
0x02, 0x00, 0x02, 0x08, 0x00, 0x08, 0x10, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0B, 0x00,
0x00, 0x02, 0x0A, 0x21, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0xC8, 0x00, 0x00, 0x38, 0xFF,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x0F,
0x00, 0xA5, 0x0D, 0x00, 0x80, 0x00, 0x0C, 0x08,
0xB8, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x10, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F,
0x0D, 0x0E, 0x0E, 0x01, 0x00, 0x02, 0xC7, 0xFF,
0x8B, 0x00, 0x00, 0x00, 0x01, 0x01, 0x40
}

This is 135 bytes to be written every time to the VL53L1X to initiate a measurement 0x29 is written to memory location 0x01, which is the register for the I2C address which is indeed 0x29.

So this makes sense. We could evaluate the default register settings of a given device against this set of bytes and write only the ones that are different but it's faster, easier, and perhaps fewer code words to write the config block as is. The block was obtained via inspection of the ST P-NUCLEO-53L1A1 Prepended two bytes to serve as address holding

Referenced by readTrim(), and startMeasurement().

◆ i2c_

embvm::i2c::master& embdrv::vl53l1x::i2c_
private

The I2C master bus that this device is connected to.

Referenced by start_(), and startMeasurement().

◆ i2c_pool_

etl::generic_pool<sizeof(uint32_t), alignof(uint32_t), 64> embdrv::vl53l1x::i2c_pool_ {}
private

Static memory pool used for I2C transactions.

Referenced by create(), and destroy().

◆ lock_

std::mutex embdrv::vl53l1x::lock_ {}
private

◆ mode_

tof::mode embvm::tof::sensor::mode_ = tof::mode::defaultRange
protectedinherited

The configured ranging mode for the ToF sensor.

Referenced by embvm::tof::sensor::mode().

◆ model_id_

uint8_t embdrv::vl53l1x::model_id_ = 0
private

The model ID for the VL53L1X, read from the device during start().

Referenced by checkModelID().

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ osc_calibrate_val_

uint16_t embdrv::vl53l1x::osc_calibrate_val_ = 0
private

Referenced by readOscillatorCal().

◆ rate_cb_list_

etl::list<rate_cb_t, 2> embdrv::vl53l1x::rate_cb_list_ {}
private

List that stores the signalRate() callback functions.

Referenced by registerSignalRateCallback(), and signalRate().

◆ read_cb_list_

etl::list<read_cb_t, 2> embdrv::vl53l1x::read_cb_list_ {}
private

List that stores the read() callback functions.

Referenced by readData(), and registerReadCallback().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
protectedinherited

Tracks the driver state.

True if the driver has been started, false if it has been stopped or not yet started.

Referenced by embvm::DriverBase::start(), embvm::DriverBase::started(), and embvm::DriverBase::stop().

◆ status_cb_list_

etl::list<status_cb_t, 2> embdrv::vl53l1x::status_cb_list_ {}
private

List that stores the rangeStatus() callback functions.

Referenced by registerStatusCallback().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().