semf
semf::SpiSlaveHardware Class Referenceabstract

Class for using spi hardware in slave mode. In order of being a SPI slave IO-operations will not get executed before the CS-Signal is LOW. After calling an IO-operation successfully, the hardware state will change to busy while executing the IO call. The hardware state will change to ready after IO-operation is done. When the IO-operation got executed successfully one of the signals dataWritten or dataAvailable gets emitted. The signal handlers can start the next IO-operation as in all other classes deriving from CommunicationHardware. More...

#include <spislavehardware.h>

Inheritance diagram for semf::SpiSlaveHardware:
Inheritance graph
Collaboration diagram for semf::SpiSlaveHardware:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Read_IsBusy ,
  Read_BufferIsNullptr , Read_BufferSizeIsZero , SetFormat_IsBusy , StopWrite_IsNotWriting ,
  StopRead_IsNotReading , WriteRead_IsBusy , WriteRead_WriteDataIsNullptr , WriteRead_ReadBufferIsNullptr ,
  WriteRead_SizeIsZero
}
 Error IDs for this class. Error ID identify a unique error() / onError call (excluding transferring). More...
 
- Public Types inherited from semf::Spi
enum class  TransmissionMode : uint8_t { Mode0 , Mode1 , Mode2 , Mode3 }
 
enum class  WireMode : uint8_t { FullDuplexWires , HalfDuplexWires , WriteOnlyWires , ReadOnlyWires }
 
- Public Types inherited from semf::CommunicationHardware
enum class  Type { SynchronousMaster = 1 , SynchronousSlave , Asynchronous }
 
enum class  Frame : uint8_t { First = 0x01 , Next = 0x08 , Last = 0x10 , FirstAndLast = 0x11 }
 

Public Member Functions

virtual ~SpiSlaveHardware ()=default
 
void write (const uint8_t data[], size_t dataSize) override
 For writing data, dataWritten signal will be emitted after successful write. More...
 
void read (uint8_t buffer[], size_t bufferSize) override
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
bool isBusyReading () const override
 Communication hardware is busy reading at the moment. More...
 
bool isBusyWriting () const override
 Communication hardware is busy writing at the moment. More...
 
void stopRead () override
 
void stopWrite () override
 
void setFrame (Frame frame) override
 Sets the selected usage of start and stop condition. More...
 
void writeRead (const uint8_t writeData[], uint8_t readBuffer[], size_t size) override
 For writing and reading data parallel through the communication hardware 1) For interrupt or one shot dma mode, dataAvailable signal will be fired after successful read/write. 2) For cyclic dma mode, do not use this function. More...
 
void setFormat (uint8_t bits, TransmissionMode transmission, WireMode wire) override
 Sets the format for the spi slave device. More...
 
- Public Member Functions inherited from semf::Spi
virtual ~Spi ()=default
 
virtual void writeRead (const uint8_t writeData[], uint8_t readBuffer[], size_t size)=0
 For writing and reading data parallel through the communication hardware 1) For interrupt or one shot dma mode, dataAvailable signal will be fired after successful read/write. 2) For cyclic dma mode, do not use this function. More...
 
virtual void setFormat (uint8_t bits, TransmissionMode transmission, WireMode wire)=0
 Sets the format for the spi slave device. More...
 
- Public Member Functions inherited from semf::CommunicationHardwareSynchronousSlave
virtual ~CommunicationHardwareSynchronousSlave ()=default
 
Type type () const override
 Returns the hardware type. More...
 
- Public Member Functions inherited from semf::CommunicationHardware
virtual ~CommunicationHardware ()=default
 
virtual void init ()=0
 
virtual void deinit ()=0
 
virtual Type type () const =0
 Returns the hardware type. More...
 
virtual void setFrame (Frame frame)=0
 Sets the selected usage of start and stop condition. More...
 
- Public Member Functions inherited from semf::app::Communication
virtual ~Communication ()=default
 
virtual void write (const uint8_t data[], size_t dataSize)=0
 For writing data, dataWritten signal will be emitted after successful write. More...
 
virtual void read (uint8_t buffer[], size_t bufferSize)=0
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
virtual void stopRead ()=0
 
virtual void stopWrite ()=0
 
virtual bool isBusyReading () const =0
 Communication hardware is busy reading at the moment. More...
 
virtual bool isBusyWriting () const =0
 Communication hardware is busy writing at the moment. More...
 

Protected Member Functions

void onError (Error thrown)
 Error routine, emits the error signal. More...
 
void onDataAvailable ()
 
void onDataWritten ()
 
void setBusy (bool busy)
 Sets the flag m_isBusy. More...
 
virtual void writeHardware (const uint8_t data[], size_t dataSize)=0
 Accesses the spi hardware in order to write dataSize bytes of data. More...
 
virtual void readHardware (uint8_t buffer[], size_t bufferSize)=0
 Accesses the spi hardware in order to read bufferSize bytes and stores them in buffer. More...
 
virtual void writeReadHardware (const uint8_t writeData[], uint8_t readBuffer[], size_t size)=0
 Accesses the spi hardware in order to perform a full duplex read/write. More...
 
virtual void stopReadHardware ()=0
 
virtual void stopWriteHardware ()=0
 
virtual void setFormatHardware (uint8_t bits, TransmissionMode transmission, WireMode wire)=0
 Configures the hardware for insuring the given configuration. More...
 
void setWireMode (WireMode mode)
 Sets the wire mode. More...
 
void setTransmissionMode (TransmissionMode mode)
 Sets the transmission mode. More...
 

Additional Inherited Members

- Public Attributes inherited from semf::app::Communication
Signal dataWritten
 
Signal dataAvailable
 
Signal writeStopped
 
Signal readStopped
 
Signal< Errorerror
 

Detailed Description

Class for using spi hardware in slave mode. In order of being a SPI slave IO-operations will not get executed before the CS-Signal is LOW. After calling an IO-operation successfully, the hardware state will change to busy while executing the IO call. The hardware state will change to ready after IO-operation is done. When the IO-operation got executed successfully one of the signals dataWritten or dataAvailable gets emitted. The signal handlers can start the next IO-operation as in all other classes deriving from CommunicationHardware.

Definition at line 24 of file spislavehardware.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::SpiSlaveHardware::ErrorCode : uint8_t
strong

Error IDs for this class. Error ID identify a unique error() / onError call (excluding transferring).

Enumerator
Write_IsBusy 
Write_DataIsNullptr 
Write_DataSizeIsZero 
Read_IsBusy 
Read_BufferIsNullptr 
Read_BufferSizeIsZero 
SetFormat_IsBusy 
StopWrite_IsNotWriting 
StopRead_IsNotReading 
WriteRead_IsBusy 
WriteRead_WriteDataIsNullptr 
WriteRead_ReadBufferIsNullptr 
WriteRead_SizeIsZero 

Definition at line 30 of file spislavehardware.h.

Constructor & Destructor Documentation

◆ ~SpiSlaveHardware()

virtual semf::SpiSlaveHardware::~SpiSlaveHardware ( )
virtualdefault

Member Function Documentation

◆ isBusyReading()

bool semf::SpiSlaveHardware::isBusyReading ( ) const
overridevirtual

Communication hardware is busy reading at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 66 of file spislavehardware.cpp.

Here is the caller graph for this function:

◆ isBusyWriting()

bool semf::SpiSlaveHardware::isBusyWriting ( ) const
overridevirtual

Communication hardware is busy writing at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 71 of file spislavehardware.cpp.

Here is the caller graph for this function:

◆ onDataAvailable()

void semf::SpiSlaveHardware::onDataAvailable ( )
protected

Data available routine, emits the dataAvailable signal.

Definition at line 160 of file spislavehardware.cpp.

◆ onDataWritten()

void semf::SpiSlaveHardware::onDataWritten ( )
protected

Data written routine, emits the dataWritten signal.

Definition at line 167 of file spislavehardware.cpp.

◆ onError()

void semf::SpiSlaveHardware::onError ( Error  thrown)
protected

Error routine, emits the error signal.

Parameters
thrownA thrown error object.

Definition at line 153 of file spislavehardware.cpp.

Here is the caller graph for this function:

◆ read()

void semf::SpiSlaveHardware::read ( uint8_t  buffer[],
size_t  bufferSize 
)
overridevirtual

For reading data, dataAvailable signal will be emitted after successful read.

Parameters
bufferBuffer to store received bytes in.
bufferSizeSize of receive buffer.
Exceptions
Read_IsBusyIf is busy.
Read_BufferIsNullptrIf buffer is nullptr.
Read_BufferSizeIsZeroIf bufferSize is zero.

Implements semf::app::Communication.

Definition at line 41 of file spislavehardware.cpp.

Here is the call graph for this function:

◆ readHardware()

virtual void semf::SpiSlaveHardware::readHardware ( uint8_t  buffer[],
size_t  bufferSize 
)
protectedpure virtual

Accesses the spi hardware in order to read bufferSize bytes and stores them in buffer.

Parameters
bufferBuffer location.
bufferSizeSize of the buffer.

Implemented in semf::Stm32SpiSlave.

Here is the caller graph for this function:

◆ setBusy()

void semf::SpiSlaveHardware::setBusy ( bool  busy)
protected

Sets the flag m_isBusy.

Parameters
busyNew value of the flag m_isBusyWriting.

Definition at line 174 of file spislavehardware.cpp.

Here is the caller graph for this function:

◆ setFormat()

void semf::SpiSlaveHardware::setFormat ( uint8_t  bits,
TransmissionMode  transmission,
WireMode  wire 
)
overridevirtual

Sets the format for the spi slave device.

Parameters
bitsnumber of bits per frame
transmissiontransmission mode (polarity and phase setting)
wirewire transmission setting
Exceptions
SetFormat_IsBusyIf this is busy.

Implements semf::Spi.

Definition at line 136 of file spislavehardware.cpp.

Here is the call graph for this function:

◆ setFormatHardware()

virtual void semf::SpiSlaveHardware::setFormatHardware ( uint8_t  bits,
TransmissionMode  transmission,
WireMode  wire 
)
protectedpure virtual

Configures the hardware for insuring the given configuration.

Parameters
bitsNumber of bits per frame.
transmissionTransmission mode (polarity and phase setting).
wireWire transmission setting.

Implemented in semf::Stm32SpiSlave.

Here is the caller graph for this function:

◆ setFrame()

void semf::SpiSlaveHardware::setFrame ( Frame  frame)
overridevirtual

Sets the selected usage of start and stop condition.

Parameters
frameframe mode

Implements semf::CommunicationHardware.

Definition at line 98 of file spislavehardware.cpp.

◆ setTransmissionMode()

void semf::SpiSlaveHardware::setTransmissionMode ( SpiSlaveHardware::TransmissionMode  mode)
protected

Sets the transmission mode.

Parameters
modeThe new transmission mode.

Definition at line 184 of file spislavehardware.cpp.

◆ setWireMode()

void semf::SpiSlaveHardware::setWireMode ( SpiSlaveHardware::WireMode  mode)
protected

Sets the wire mode.

Parameters
modeThe new wire mode.

Definition at line 179 of file spislavehardware.cpp.

◆ stopRead()

void semf::SpiSlaveHardware::stopRead ( )
overridevirtual

Stops the read process as fast as possible without destroying anything. The readStopped Signal gets emitted if the call was successful.

Exceptions
StopRead_IsNotReadingIf slave is not currently reading.

Implements semf::app::Communication.

Definition at line 76 of file spislavehardware.cpp.

Here is the call graph for this function:

◆ stopReadHardware()

virtual void semf::SpiSlaveHardware::stopReadHardware ( )
protectedpure virtual

Stops the hardware to read.

Implemented in semf::Stm32SpiSlave.

Here is the caller graph for this function:

◆ stopWrite()

void semf::SpiSlaveHardware::stopWrite ( )
overridevirtual

Stops the write process as fast as possible without destroying anything. The writeStopped Signal gets emitted if the call was successful.

Exceptions
StopWrite_IsNotWritingIf slave is not currently reading.

Implements semf::app::Communication.

Definition at line 87 of file spislavehardware.cpp.

Here is the call graph for this function:

◆ stopWriteHardware()

virtual void semf::SpiSlaveHardware::stopWriteHardware ( )
protectedpure virtual

Stop the hardware to write.

Implemented in semf::Stm32SpiSlave.

Here is the caller graph for this function:

◆ write()

void semf::SpiSlaveHardware::write ( const uint8_t  data[],
size_t  dataSize 
)
overridevirtual

For writing data, dataWritten signal will be emitted after successful write.

Parameters
dataArray, containing data to write.
dataSizeSize of write data.
Exceptions
Write_IsBusyIf write is busy.
Write_DataIsNullptrIf data is nullptr.
Write_DataSizeIsZeroIf dataSize is zero.

Implements semf::app::Communication.

Definition at line 15 of file spislavehardware.cpp.

Here is the call graph for this function:

◆ writeHardware()

virtual void semf::SpiSlaveHardware::writeHardware ( const uint8_t  data[],
size_t  dataSize 
)
protectedpure virtual

Accesses the spi hardware in order to write dataSize bytes of data.

Parameters
dataData location.
dataSizeSize of data.

Implemented in semf::Stm32SpiSlave.

Here is the caller graph for this function:

◆ writeRead()

void semf::SpiSlaveHardware::writeRead ( const uint8_t  writeData[],
uint8_t  readBuffer[],
size_t  size 
)
overridevirtual

For writing and reading data parallel through the communication hardware 1) For interrupt or one shot dma mode, dataAvailable signal will be fired after successful read/write. 2) For cyclic dma mode, do not use this function.

Parameters
writeDatadata array for write data
readBufferdata array for read data
sizedata array size
Exceptions
WriteRead_IsBusyIf this is busy.
WriteRead_WriteDataIsNullptrIf writeData is a nullptr.
WriteRead_ReadBufferIsNullptrIf readBuffer is a nullptr.
WriteRead_SizeIsZeroIf size is zero.

Implements semf::Spi.

Definition at line 104 of file spislavehardware.cpp.

Here is the call graph for this function:

◆ writeReadHardware()

virtual void semf::SpiSlaveHardware::writeReadHardware ( const uint8_t  writeData[],
uint8_t  readBuffer[],
size_t  size 
)
protectedpure virtual

Accesses the spi hardware in order to perform a full duplex read/write.

Parameters
writeDataData to write.
readBufferBuffer to read.
sizeSize of both buffers.

Implemented in semf::Stm32SpiSlave.

Here is the caller graph for this function: