Byggern
|
An SPI driver which implements the AVR SPI interface. More...
#include <spi.h>
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) |
![]() | |
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 SPI & | GetInstance () |
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 | |
![]() | |
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) |
![]() | |
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 |
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
|
private |
Initializer for SPI. Not used because of singleton
|
delete |
Because of singleton - makes sure its not copied etc.
|
inlinestatic |
A Singleton implementation of this class
void SPI::SPI::Initialize | ( | PIN * | pins, |
uint8_t | number_of_pins, | ||
bool | clock_polarity_falling = 0 , |
||
bool | clock_phase_trailing = 0 |
||
) |
Initializes the SPI.
pins | An array with PIN structs, where each struct is a pin that is used by the SPI |
number_of_pins | Number of PIN structs in the pins array |
clock_polarity_falling | If enabled, SCK is high when idle. Defaults to disabled (SCK low when idle) |
clock_phase_trailing | If enabled, samples on the trailing edge of SCK: Defaults to disabled (sample on the leading edge) |
|
private |
Send the data in the output buffer onto the SPI.
|
delete |
Because of singleton - makes sure its not copied etc.
void SPI::SPI::SetDevice | ( | PIN | pin | ) |
void SPI::SPI::WriteByte | ( | uint8_t | byte, |
bool | wait | ||
) |
Writes a byte to the output stream. Puts the returned data into the input stream
byte | The byte to be sent |
wait | If set, the SPI driver will not start the transmission of the output buffer |
void SPI::SPI::WriteByteAndThrowAwayData | ( | uint8_t | byte, |
bool | wait | ||
) |
Writes a byte to the output stream. Throws away the returned data
byte | The byte to be sent |
wait | If set, the SPI driver will not start the transmission of the output buffer |
|
friend |
The interrupt vector for when a transmission is complete.
|
private |
A bool indicating wether or not an outgoing transmission is ongoing
|
private |
A flag indicating how many transfer we are going to not care about the data received