Byggern
SPI::SPI Class Reference

An SPI driver which implements the AVR SPI interface. More...

#include <spi.h>

Inheritance diagram for SPI::SPI:
Stream

Public Member Functions

 SPI (const SPI &)=delete
 
void operator= (const SPI &)=delete
 
void SetDevice (PIN pin)
 
void Initialize (PIN *pins, uint8_t number_of_pins, bool clock_polarity_falling, bool clock_phase_trailing)
 
void WriteByte (uint8_t byte, bool wait)
 
void WriteByteAndThrowAwayData (uint8_t byte, bool wait)
 
- Public Member Functions inherited from Stream
 Stream (uint16_t input_stream_size, uint16_t output_stream_size)
 
virtual void Write (uint8_t *string, uint16_t size)
 
virtual uint16_t Read (uint8_t *string, uint16_t size)
 
virtual bool ReadByte (uint8_t &byte)
 
virtual void WriteByte (uint8_t byte)
 
virtual uint8_t GetAvailableWriteBytes ()
 
virtual uint8_t GetAvailableReadBytes ()
 
virtual bool CheckInputOverflowFlag ()
 
virtual bool CheckOutputOverflowFlag ()
 
virtual uint16_t GetInputBufferLength ()
 
virtual uint16_t GetOutputBufferLength ()
 
virtual void FlushInputBuffer ()
 
virtual void FlushOutputBuffer ()
 

Static Public Member Functions

static SPIGetInstance ()
 

Public Attributes

PIN current_pin
 

Private Member Functions

 SPI ()
 
void InitializeTransmission ()
 

Private Attributes

volatile bool ongoing_transmission = false
 
uint8_t throw_away_data_count = 0
 

Friends

void SPI_STC_vect ()
 

Additional Inherited Members

- Protected Member Functions inherited from Stream
virtual uint16_t ReadFromBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, uint8_t *string, uint16_t &string_size)
 
virtual void WriteToBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, bool &overflow_flag, uint8_t *string, uint16_t &string_size, void(*cb)(Stream *stream))
 
virtual bool ReadByteFromBuffer (uint8_t &byte, uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty)
 
virtual void WriteByteToBuffer (uint8_t *buffer, uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty, bool &overflow_flag, uint8_t &byte, void(*cb)(Stream *stream))
 
virtual void WriteByteToInputStream (uint8_t &byte)
 
virtual bool ReadByteFromOutputStream (uint8_t &byte)
 
virtual void WriteToInputStream (uint8_t *string, uint16_t size)
 
virtual uint16_t ReadFromOutputStream (uint8_t *string, uint16_t size)
 
virtual uint16_t CalculateLength (uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty)
 
virtual void FlushStream (uint16_t &start_index, uint16_t &stop_index, uint16_t &buffer_size, bool &empty)
 
- Protected Attributes inherited from Stream
uint8_t * input_buffer
 
uint8_t * output_buffer
 
uint16_t input_buffer_start_index = 0
 
uint16_t output_buffer_start_index = 0
 
uint16_t input_buffer_stop_index
 
uint16_t output_buffer_stop_index
 
uint16_t input_buffer_size
 
uint16_t output_buffer_size
 
void(* event_input_buffer_not_empty )(Stream *stream) = nullptr
 
void(* event_output_buffer_not_empty )(Stream *stream) = nullptr
 
bool input_buffer_empty = true
 
bool output_buffer_empty = true
 
bool input_buffer_overflowed = false
 
bool output_buffer_overflowed = false
 

Detailed Description

An SPI driver which implements the AVR SPI interface.

An SPI driver which implements the AVR SPI interface. Uses the STREAM class as both input and output buffer. Supports all four modes of SPI (please see the Initialize function). Uses interrupt for when a transfer is complete

Constructor & Destructor Documentation

§ SPI() [1/2]

SPI::SPI::SPI ( )
private

Initializer for SPI. Not used because of singleton

§ SPI() [2/2]

SPI::SPI::SPI ( const SPI )
delete

Because of singleton - makes sure its not copied etc.

Member Function Documentation

§ GetInstance()

static SPI& SPI::SPI::GetInstance ( )
inlinestatic

A Singleton implementation of this class

§ Initialize()

void SPI::SPI::Initialize ( PIN pins,
uint8_t  number_of_pins,
bool  clock_polarity_falling = 0,
bool  clock_phase_trailing = 0 
)

Initializes the SPI.

Parameters
pinsAn array with PIN structs, where each struct is a pin that is used by the SPI
number_of_pinsNumber of PIN structs in the pins array
clock_polarity_fallingIf enabled, SCK is high when idle. Defaults to disabled (SCK low when idle)
clock_phase_trailingIf enabled, samples on the trailing edge of SCK: Defaults to disabled (sample on the leading edge)

§ InitializeTransmission()

void SPI::SPI::InitializeTransmission ( )
private

Send the data in the output buffer onto the SPI.

§ operator=()

void SPI::SPI::operator= ( const SPI )
delete

Because of singleton - makes sure its not copied etc.

§ SetDevice()

void SPI::SPI::SetDevice ( PIN  pin)

Sets the device the SPI driver is going to use. This must be called in order for it to function. The device passed into set device must also have been initialized in the Initialize function when initializing the SPI driver

Parameters
pinThe PIN the SPI is going to use

§ WriteByte()

void SPI::SPI::WriteByte ( uint8_t  byte,
bool  wait 
)

Writes a byte to the output stream. Puts the returned data into the input stream

Parameters
byteThe byte to be sent
waitIf set, the SPI driver will not start the transmission of the output buffer

§ WriteByteAndThrowAwayData()

void SPI::SPI::WriteByteAndThrowAwayData ( uint8_t  byte,
bool  wait 
)

Writes a byte to the output stream. Throws away the returned data

Parameters
byteThe byte to be sent
waitIf set, the SPI driver will not start the transmission of the output buffer

Friends And Related Function Documentation

§ SPI_STC_vect

void SPI_STC_vect ( )
friend

The interrupt vector for when a transmission is complete.

Member Data Documentation

§ current_pin

PIN SPI::SPI::current_pin

A struct of the type PIN which indicates which pin is currently selected.

§ ongoing_transmission

volatile bool SPI::SPI::ongoing_transmission = false
private

A bool indicating wether or not an outgoing transmission is ongoing

§ throw_away_data_count

uint8_t SPI::SPI::throw_away_data_count = 0
private

A flag indicating how many transfer we are going to not care about the data received


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