semf
|
Class for using SPI hardware in master mode. More...
#include <spimasterhardware.h>
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< Error > | error |
Class for using SPI hardware in master mode.
Definition at line 21 of file spimasterhardware.h.
|
strong |
Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring).
Definition at line 27 of file spimasterhardware.h.
|
default |
|
explicit |
Constructor
chipSelectPin | Chip select pin for choosing the target device. |
Definition at line 16 of file spimasterhardware.cpp.
|
virtualdefault |
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.
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.
|
protected |
Returns the actual frame mode setting.
Definition at line 233 of file spimasterhardware.cpp.
|
overridevirtual |
Communication hardware is busy reading at the moment.
Implements semf::app::Communication.
Definition at line 80 of file spimasterhardware.cpp.
|
overridevirtual |
Communication hardware is busy writing at the moment.
Implements semf::app::Communication.
Definition at line 85 of file spimasterhardware.cpp.
|
protected |
Is called after data is available in the hardware. Will emit dataAvailable
signal.
Definition at line 245 of file spimasterhardware.cpp.
|
protected |
Is called after data are written by the hardware. Will emit dataWritten
signal.
Definition at line 238 of file spimasterhardware.cpp.
|
protected |
Is called if an error occurred by hardware read or write access. Will throw error
signal.
thrown | A thrown error object. |
Definition at line 252 of file spimasterhardware.cpp.
|
overridevirtual |
For reading data, dataAvailable
signal will be emitted after successful read.
buffer | Buffer to store received bytes in. |
bufferSize | Size of receive buffer. |
Read_IsBusy | If this is busy. |
Read_BufferIsNullptr | If buffer is nullptr. |
Read_BufferSizeIsZero | If bufferSize is zero. |
Implements semf::app::Communication.
Definition at line 50 of file spimasterhardware.cpp.
|
protectedpure virtual |
Hardware will read data.
buffer | data array |
bufferSize | data array size |
Implemented in semf::Stm32SpiMaster.
|
protected |
Sets the busy flag.
write()
, read()
and writeRead()
busy is set to true
. In onDataAvailable()
, onDataWritten()
and onError()
is busy reseted to false
. isBusy | true for busy, false for idle. |
Definition at line 228 of file spimasterhardware.cpp.
|
virtual |
Sets a new chip select pin read and write operations.
chipSelectPin | Digital out chip select pin. |
SetChipSelectPin_IsBusy | If this is busy. |
Definition at line 198 of file spimasterhardware.cpp.
|
overridevirtual |
Sets the format for the spi slave device.
bits | number of bits per frame |
transmission | transmission mode (polarity and phase setting) |
wire | wire transmission setting |
SetFormat_IsBusy | If this is busy |
Implements semf::Spi.
Definition at line 111 of file spimasterhardware.cpp.
|
protectedpure virtual |
Configures the hardware for insuring the given configuration.
bits | Number of bits per frame. |
transmission | Transmission mode (polarity and phase setting). |
wire | Wire transmission setting. |
Implemented in semf::Stm32SpiMaster.
|
overridevirtual |
Sets the selected usage of start and stop condition.
frame | frame mode |
Implements semf::CommunicationHardware.
Definition at line 90 of file spimasterhardware.cpp.
|
pure virtual |
|
protected |
Sets the transmission mode.
mode | The new transmission mode. |
Definition at line 260 of file spimasterhardware.cpp.
|
protected |
Sets the wire mode.
mode | The new wire mode: |
Definition at line 265 of file spimasterhardware.cpp.
|
overridevirtual |
Stops the read process as fast as possible without destroying anything. The readStopped
Signal gets emitted if the call was successful.
StopRead_IsWriteOnly | If master is configured as write only. |
Implements semf::app::Communication.
Definition at line 145 of file spimasterhardware.cpp.
|
protectedpure virtual |
Forces the hardware to stop a reading process
Implemented in semf::Stm32SpiMaster.
|
overridevirtual |
Stops the write process as fast as possible without destroying anything. The writeStopped
Signal gets emitted if the call was successful.
StopWrite_IsReadOnly | If master is configured as read only. |
Implements semf::app::Communication.
Definition at line 128 of file spimasterhardware.cpp.
|
protectedpure virtual |
Forces the hardware to stop a writing process.
Implemented in semf::Stm32SpiMaster.
|
overridevirtual |
For writing data, dataWritten
signal will be emitted after successful write.
data | Array, containing data to write. |
dataSize | Size of write data. |
Write_IsBusy | If this is busy. |
Write_DataIsNullptr | If data is nullptr. |
Write_DataSizeIsZero | If dataSize is zero. |
Implements semf::app::Communication.
Definition at line 21 of file spimasterhardware.cpp.
|
protectedpure virtual |
Hardware will write data.
data | data array |
dataSize | data array size |
Implemented in semf::Stm32SpiMaster.
|
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.
writeData | data array for write data |
readBuffer | data array for read data |
size | data array size |
WriteRead_IsBusy | If this is busy. |
WriteRead_WriteDataIsNullptr | If writeData is nullptr. |
WriteRead_ReadBufferIsNullptr | If readBuffer is nullptr. |
Write_Read_Size_Is_Zero | If size is zero. |
Implements semf::Spi.
Definition at line 162 of file spimasterhardware.cpp.
|
protectedpure virtual |
Hardware will read and write data parallel.
writeData | memory where to write from |
readBuffer | memory where to store read data |
size | data array size |
Implemented in semf::Stm32SpiMaster.