semf
i2cmasterhardware.h
Go to the documentation of this file.
1
10#ifndef SEMF_COMMUNICATION_I2CMASTERHARDWARE_H_
11#define SEMF_COMMUNICATION_I2CMASTERHARDWARE_H_
12
15
16namespace semf
17{
22{
23public:
27 enum class ErrorCode : uint8_t
28 {
29 Write_IsBusy = 0,
30 Write_DataIsNullptr,
31 Write_DataSizeIsZero,
32 Read_IsBusy,
33 Read_BufferIsNullptr,
34 Read_BufferSizeIsZero,
35 SetAddress_IsBusy
36 };
37
38 virtual ~I2cMasterHardware() = default;
39
45 virtual void checkAddress(uint8_t address) = 0;
52 void write(const uint8_t data[], size_t dataSize) override;
59 void read(uint8_t buffer[], size_t bufferSize) override;
60 bool isBusyReading() const override;
61 bool isBusyWriting() const override;
66 uint8_t address() const override;
71 void setAddress(uint8_t address) override;
73
76
77protected:
85 void setBusy(bool isBusy);
97 virtual void writeHardware(const uint8_t data[], size_t dataSize) = 0;
104 virtual void readHardware(uint8_t buffer[], size_t bufferSize) = 0;
109 virtual void setFrequencyHardware(uint32_t hz) = 0;
111 void onDataWritten();
113 void onDataAvailable();
118 void onError(Error thrown);
119
120private:
122 uint8_t m_address = 0;
124 bool m_isBusy = false;
128 static constexpr Error::ClassID kSemfClassId = Error::ClassID::I2cMasterHardware;
129};
130} /* namespace semf */
131#endif /* SEMF_COMMUNICATION_I2CMASTERHARDWARE_H_ */
@ FirstAndLast
start AND stop condition
This interface standardized the read and write interface for synchronous master hardware,...
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
Definition: error.h:22
ClassID
Semf class IDs.
Definition: error.h:28
Interface for I2C specific functionalities, which are not solved in a generic way in CommunicationHar...
Definition: i2c.h:25
For using the I2C in master mode.
void setAddress(uint8_t address) override
void write(const uint8_t data[], size_t dataSize) override
For writing data, dataWritten signal will be emitted after successful write.
void setFrame(CommunicationHardware::Frame frame) override
Sets the selected usage of start and stop condition.
virtual void setFrequencyHardware(uint32_t hz)=0
Configures the frequency of the bus.
bool isBusyReading() const override
Communication hardware is busy reading at the moment.
CommunicationHardware::Frame frame() const
Returns the actual frame mode setting.
virtual void checkAddress(uint8_t address)=0
Checks if the given address is available on the bus. Emits address found if successful (ACK)....
uint8_t address() const override
Returns the I2C slave device address.
virtual ~I2cMasterHardware()=default
void onError(Error thrown)
Is called if an error occurred by hardware read or write access. Will emit error signal.
virtual void writeHardware(const uint8_t data[], size_t dataSize)=0
Hardware will write data. After finished write operation, onDataWritten() function will be called.
bool isBusyWriting() const override
Communication hardware is busy writing at the moment.
virtual void readHardware(uint8_t buffer[], size_t bufferSize)=0
Hardware will read data. After finished read operation, onDataAvailable() function will be called.
ErrorCode
Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring...
void setBusy(bool isBusy)
Sets the busy flag.
void read(uint8_t buffer[], size_t bufferSize) override
For reading data, dataAvailable signal will be emitted after successful read.
Signal for lightweight signal/slot implementation. One signal can be connected to multiple slots and ...
Definition: signal.h:41