semf
semf::SpiMasterHardware Class Referenceabstract

Class for using SPI hardware in master mode. More...

#include <spimasterhardware.h>

Inheritance diagram for semf::SpiMasterHardware:
Inheritance graph
Collaboration diagram for semf::SpiMasterHardware:
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_IsReadOnly ,
  StopRead_IsWriteOnly , WriteRead_IsBusy , WriteRead_WriteDataIsNullptr , WriteRead_ReadBufferIsNullptr ,
  WriteRead_SizeIsZero , SetChipSelectPin_IsBusy
}
 Error codes 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

 SpiMasterHardware ()=default
 
 SpiMasterHardware (Gpio &chipSelectPin)
 
virtual ~SpiMasterHardware ()=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 setFrame (CommunicationHardware::Frame frame) override
 Sets the selected usage of start and stop condition. More...
 
void setFormat (uint8_t bits, TransmissionMode transmission, WireMode wire) override
 Sets the format for the spi slave device. More...
 
void stopWrite () override
 
void stopRead () override
 
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...
 
virtual void setChipSelectPin (Gpio &chipSelectPin)
 Sets a new chip select pin read and write operations. More...
 
void enableChipSelect ()
 
void disableChipSelect ()
 
virtual void setFrequency (uint32_t hz)=0
 Sets the speed. 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::CommunicationHardwareSynchronousMaster
virtual ~CommunicationHardwareSynchronousMaster ()=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 setBusy (bool isBusy)
 Sets the busy flag. More...
 
CommunicationHardware::Frame frame () const
 Returns the actual frame mode setting. More...
 
virtual void writeHardware (const uint8_t data[], size_t dataSize)=0
 Hardware will write data. More...
 
virtual void readHardware (uint8_t buffer[], size_t bufferSize)=0
 Hardware will read data. More...
 
virtual void writeReadHardware (const uint8_t writeData[], uint8_t readBuffer[], size_t size)=0
 Hardware will read and write data parallel. More...
 
virtual void setFormatHardware (uint8_t bits, TransmissionMode transmission, WireMode wire)=0
 Configures the hardware for insuring the given configuration. More...
 
virtual void stopWriteHardware ()=0
 
virtual void stopReadHardware ()=0
 
void onDataWritten ()
 
void onDataAvailable ()
 
void onError (Error thrown)
 Is called if an error occurred by hardware read or write access. Will throw error signal. More...
 
void setTransmissionMode (TransmissionMode mode)
 Sets the transmission mode. More...
 
void setWireMode (WireMode mode)
 Sets the wire 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 master mode.

Definition at line 21 of file spimasterhardware.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::SpiMasterHardware::ErrorCode : uint8_t
strong

Error codes 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_IsReadOnly 
StopRead_IsWriteOnly 
WriteRead_IsBusy 
WriteRead_WriteDataIsNullptr 
WriteRead_ReadBufferIsNullptr 
WriteRead_SizeIsZero 
SetChipSelectPin_IsBusy 

Definition at line 27 of file spimasterhardware.h.

Constructor & Destructor Documentation

◆ SpiMasterHardware() [1/2]

semf::SpiMasterHardware::SpiMasterHardware ( )
default

◆ SpiMasterHardware() [2/2]

semf::SpiMasterHardware::SpiMasterHardware ( Gpio chipSelectPin)
explicit

Constructor

Parameters
chipSelectPinChip select pin for choosing the target device.

Definition at line 16 of file spimasterhardware.cpp.

◆ ~SpiMasterHardware()

virtual semf::SpiMasterHardware::~SpiMasterHardware ( )
virtualdefault

Member Function Documentation

◆ disableChipSelect()

void semf::SpiMasterHardware::disableChipSelect ( )

Disables chip select after read or write operation, if chip select was set in the past.

Definition at line 219 of file spimasterhardware.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enableChipSelect()

void semf::SpiMasterHardware::enableChipSelect ( )

Enables chip select for read or write operation, if chip select was set in the past.

Definition at line 210 of file spimasterhardware.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ frame()

CommunicationHardware::Frame semf::SpiMasterHardware::frame ( ) const
protected

Returns the actual frame mode setting.

Returns
Frame mode for setting start and stop condition.

Definition at line 233 of file spimasterhardware.cpp.

Here is the caller graph for this function:

◆ isBusyReading()

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

Communication hardware is busy reading at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 80 of file spimasterhardware.cpp.

Here is the caller graph for this function:

◆ isBusyWriting()

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

Communication hardware is busy writing at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 85 of file spimasterhardware.cpp.

Here is the caller graph for this function:

◆ onDataAvailable()

void semf::SpiMasterHardware::onDataAvailable ( )
protected

Is called after data is available in the hardware. Will emit dataAvailable signal.

Definition at line 245 of file spimasterhardware.cpp.

Here is the caller graph for this function:

◆ onDataWritten()

void semf::SpiMasterHardware::onDataWritten ( )
protected

Is called after data are written by the hardware. Will emit dataWritten signal.

Definition at line 238 of file spimasterhardware.cpp.

Here is the caller graph for this function:

◆ onError()

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

Is called if an error occurred by hardware read or write access. Will throw error signal.

Parameters
thrownA thrown error object.

Definition at line 252 of file spimasterhardware.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read()

void semf::SpiMasterHardware::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 this is busy.
Read_BufferIsNullptrIf buffer is nullptr.
Read_BufferSizeIsZeroIf bufferSize is zero.

Implements semf::app::Communication.

Definition at line 50 of file spimasterhardware.cpp.

Here is the call graph for this function:

◆ readHardware()

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

Hardware will read data.

Parameters
bufferdata array
bufferSizedata array size

Implemented in semf::Stm32SpiMaster.

Here is the caller graph for this function:

◆ setBusy()

void semf::SpiMasterHardware::setBusy ( bool  isBusy)
protected

Sets the busy flag.

Note
in the functions write(), read() and writeRead() busy is set to true. In onDataAvailable(), onDataWritten() and onError() is busy reseted to false.
Parameters
isBusytrue for busy, false for idle.

Definition at line 228 of file spimasterhardware.cpp.

Here is the caller graph for this function:

◆ setChipSelectPin()

void semf::SpiMasterHardware::setChipSelectPin ( Gpio chipSelectPin)
virtual

Sets a new chip select pin read and write operations.

Parameters
chipSelectPinDigital out chip select pin.
Exceptions
SetChipSelectPin_IsBusyIf this is busy.

Definition at line 198 of file spimasterhardware.cpp.

◆ setFormat()

void semf::SpiMasterHardware::setFormat ( uint8_t  bits,
SpiMasterHardware::TransmissionMode  transmission,
SpiMasterHardware::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 111 of file spimasterhardware.cpp.

Here is the call graph for this function:

◆ setFormatHardware()

virtual void semf::SpiMasterHardware::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::Stm32SpiMaster.

Here is the caller graph for this function:

◆ setFrame()

void semf::SpiMasterHardware::setFrame ( CommunicationHardware::Frame  frame)
overridevirtual

Sets the selected usage of start and stop condition.

Parameters
frameframe mode

Implements semf::CommunicationHardware.

Definition at line 90 of file spimasterhardware.cpp.

Here is the call graph for this function:

◆ setFrequency()

virtual void semf::SpiMasterHardware::setFrequency ( uint32_t  hz)
pure virtual

Sets the speed.

Parameters
hzFrequency in hz.

Implemented in semf::Stm32SpiMaster.

◆ setTransmissionMode()

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

Sets the transmission mode.

Parameters
modeThe new transmission mode.

Definition at line 260 of file spimasterhardware.cpp.

◆ setWireMode()

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

Sets the wire mode.

Parameters
modeThe new wire mode:

Definition at line 265 of file spimasterhardware.cpp.

◆ stopRead()

void semf::SpiMasterHardware::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_IsWriteOnlyIf master is configured as write only.

Implements semf::app::Communication.

Definition at line 145 of file spimasterhardware.cpp.

Here is the call graph for this function:

◆ stopReadHardware()

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

Forces the hardware to stop a reading process

Implemented in semf::Stm32SpiMaster.

Here is the caller graph for this function:

◆ stopWrite()

void semf::SpiMasterHardware::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_IsReadOnlyIf master is configured as read only.

Implements semf::app::Communication.

Definition at line 128 of file spimasterhardware.cpp.

Here is the call graph for this function:

◆ stopWriteHardware()

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

Forces the hardware to stop a writing process.

Implemented in semf::Stm32SpiMaster.

Here is the caller graph for this function:

◆ write()

void semf::SpiMasterHardware::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 this is busy.
Write_DataIsNullptrIf data is nullptr.
Write_DataSizeIsZeroIf dataSize is zero.

Implements semf::app::Communication.

Definition at line 21 of file spimasterhardware.cpp.

Here is the call graph for this function:

◆ writeHardware()

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

Hardware will write data.

Parameters
datadata array
dataSizedata array size

Implemented in semf::Stm32SpiMaster.

Here is the caller graph for this function:

◆ writeRead()

void semf::SpiMasterHardware::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 nullptr.
WriteRead_ReadBufferIsNullptrIf readBuffer is nullptr.
Write_Read_Size_Is_ZeroIf size is zero.

Implements semf::Spi.

Definition at line 162 of file spimasterhardware.cpp.

Here is the call graph for this function:

◆ writeReadHardware()

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

Hardware will read and write data parallel.

Parameters
writeDatamemory where to write from
readBuffermemory where to store read data
sizedata array size

Implemented in semf::Stm32SpiMaster.

Here is the caller graph for this function: