Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Stm32SpiPixelStrip Class Reference

Public Member Functions

 Stm32SpiPixelStrip (SPI_TypeDef *spi, unsigned num_pixels, uint8_t *backing_data)
 Initializes the SPI peripheral.
 
void hw_init (uint32_t spi_prescaler)
 Opens and initializes the SPI hardware.
 
void update_sync ()
 Updates the hardware from the backing data.
 

Private Member Functions

void clear_iteration ()
 Starts a new iteration over the strip.
 
bool next_bit ()
 
bool eof ()
 

Private Attributes

SPI_TypeDef * spi_
 SPI peripheral pointer.
 
SPI_HandleTypeDef spiHandle_
 Stm32 HAL device structure.
 
unsigned numPixels_
 Number of pixels to drive.
 
uint8_t * data_
 Backing framebuffer to use.
 
unsigned currentByte_
 Controls iteration over the data sequence when producing the output.
 
uint8_t nextBit_
 Controls iteration over the data sequence when producing the output.
 

Detailed Description

Definition at line 45 of file Stm32SpiPixelStrip.hxx.

Constructor & Destructor Documentation

◆ Stm32SpiPixelStrip()

Stm32SpiPixelStrip::Stm32SpiPixelStrip ( SPI_TypeDef *  spi,
unsigned  num_pixels,
uint8_t *  backing_data 
)
inline

Initializes the SPI peripheral.

Parameters
spithe SPI peripheral instance, e.g. SPI0.
num_pixelsthe number of RGB pixels to drive.
backing_dataarray of 3*num_pixels which stores the RGB data to be sent to the devices. Note that the byte order is G R B in the storage.

Definition at line 54 of file Stm32SpiPixelStrip.hxx.

Member Function Documentation

◆ clear_iteration()

void Stm32SpiPixelStrip::clear_iteration ( )
inlineprivate

Starts a new iteration over the strip.

Call next_bit() repeatedly to get the bits in transmission order.

Definition at line 135 of file Stm32SpiPixelStrip.hxx.

◆ eof()

bool Stm32SpiPixelStrip::eof ( )
inlineprivate
Returns
true when the iteration is at eof of the string.

Definition at line 153 of file Stm32SpiPixelStrip.hxx.

◆ hw_init()

void Stm32SpiPixelStrip::hw_init ( uint32_t  spi_prescaler)
inline

Opens and initializes the SPI hardware.

Parameters
spi_prescalerSPI_BAUDRATEPRESCALER_32 or a similar constant to match the necessary output timing.

Definition at line 66 of file Stm32SpiPixelStrip.hxx.

◆ next_bit()

bool Stm32SpiPixelStrip::next_bit ( )
inlineprivate
Returns
true if the next bit in the iteration should be 1.

Definition at line 141 of file Stm32SpiPixelStrip.hxx.

◆ update_sync()

void Stm32SpiPixelStrip::update_sync ( )
inline

Updates the hardware from the backing data.

The update is synchronous, this call returns when all bytes are sent, or at least enqueued in the SPI peripheral's TX FIFO.

Todo:
use DMA instead of a critical section here.

Definition at line 95 of file Stm32SpiPixelStrip.hxx.

Member Data Documentation

◆ currentByte_

unsigned Stm32SpiPixelStrip::currentByte_
private

Controls iteration over the data sequence when producing the output.

This is the index of the current byte.

Definition at line 169 of file Stm32SpiPixelStrip.hxx.

◆ data_

uint8_t* Stm32SpiPixelStrip::data_
private

Backing framebuffer to use.

Definition at line 165 of file Stm32SpiPixelStrip.hxx.

◆ nextBit_

uint8_t Stm32SpiPixelStrip::nextBit_
private

Controls iteration over the data sequence when producing the output.

This is the mask of the next bit to use.

Definition at line 172 of file Stm32SpiPixelStrip.hxx.

◆ numPixels_

unsigned Stm32SpiPixelStrip::numPixels_
private

Number of pixels to drive.

Definition at line 163 of file Stm32SpiPixelStrip.hxx.

◆ spi_

SPI_TypeDef* Stm32SpiPixelStrip::spi_
private

SPI peripheral pointer.

Definition at line 159 of file Stm32SpiPixelStrip.hxx.

◆ spiHandle_

SPI_HandleTypeDef Stm32SpiPixelStrip::spiHandle_
private

Stm32 HAL device structure.

Definition at line 161 of file Stm32SpiPixelStrip.hxx.


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