13#if defined(STM32) && defined(HAL_I2C_MODULE_ENABLED)
17LinkedQueue<Stm32I2cMaster> Stm32I2cMaster::m_queue;
19: m_hwHandle(&hwHandle)
22 canceled.
connect(m_canceledSlot);
28 HAL_StatusTypeDef state = HAL_I2C_Init(m_hwHandle);
31 if (state == HAL_ERROR)
36 else if (state == HAL_BUSY)
41 else if (state == HAL_TIMEOUT)
53 HAL_StatusTypeDef state = HAL_I2C_DeInit(m_hwHandle);
56 if (state == HAL_ERROR)
61 else if (state == HAL_BUSY)
66 else if (state == HAL_TIMEOUT)
83 HAL_StatusTypeDef state = HAL_I2C_Master_Abort_IT(m_hwHandle,
address());
86 if (state == HAL_ERROR)
91 else if (state == HAL_BUSY)
96 else if (state == HAL_TIMEOUT)
113 HAL_StatusTypeDef state = HAL_I2C_Master_Abort_IT(m_hwHandle,
address());
116 if (state == HAL_ERROR)
121 else if (state == HAL_BUSY)
126 else if (state == HAL_TIMEOUT)
190 if (&i2c != m_hwHandle)
199 if (&i2c != m_hwHandle)
208 if (&i2c != m_hwHandle)
217 if (&i2c != m_hwHandle)
237 mode = I2C_FIRST_FRAME;
241 mode = I2C_NEXT_FRAME;
245 mode = I2C_LAST_FRAME;
250 mode = I2C_FIRST_AND_LAST_FRAME;
258 SEMF_INFO(
"data %p, size %p", buffer, bufferSize);
259 __HAL_UNLOCK(m_hwHandle);
260 HAL_StatusTypeDef state;
263 state = HAL_I2C_Master_Receive_IT(m_hwHandle,
static_cast<uint16_t
>(
address() << 1), buffer,
static_cast<uint16_t
>(bufferSize));
268 HAL_I2C_Master_Seq_Receive_IT(m_hwHandle,
static_cast<uint16_t
>(
address() << 1), buffer,
static_cast<uint16_t
>(bufferSize),
hardwareFrame(
frame()));
272 if (state == HAL_ERROR)
277 else if (state == HAL_BUSY)
282 else if (state == HAL_TIMEOUT)
293 SEMF_INFO(
"data %p, size %u", data, dataSize);
294 __HAL_UNLOCK(m_hwHandle);
295 HAL_StatusTypeDef state;
298 state = HAL_I2C_Master_Transmit_IT(m_hwHandle,
static_cast<uint16_t
>(
address() << 1),
const_cast<uint8_t*
>(data),
static_cast<uint16_t
>(dataSize));
302 state = HAL_I2C_Master_Seq_Transmit_IT(m_hwHandle,
static_cast<uint16_t
>(
address() << 1),
const_cast<uint8_t*
>(data),
static_cast<uint16_t
>(dataSize),
308 if (state == HAL_ERROR)
313 else if (state == HAL_BUSY)
318 else if (state == HAL_TIMEOUT)
327void Stm32I2cMaster::onAddressChecked()
@ FirstAndLast
start AND stop condition
@ Next
no start AND no stop condition
@ First
start condition, but no stop condition
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
void setAddress(uint8_t address) override
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.
uint8_t address() const override
Returns the I2C slave device address.
void onError(Error thrown)
Is called if an error occurred by hardware read or write access. Will emit error signal.
bool isBusyWriting() const override
Communication hardware is busy writing at the moment.
void setBusy(bool isBusy)
Sets the busy flag.
semf::Signal addressFound
LinkedQueue is an managed single linked queue implementation.
void connect(SlotBase< Arguments... > &slot)
Connect a method to the signal.
void disconnect(SlotBase< Arguments... > &slot)
Disonnect a method from the signal.
I2cMasterHardware implementation for STM32.
void isrError(I2C_HandleTypeDef &i2c)
Interrupt service routine for i2c object error.
void writeHardware(const uint8_t data[], size_t dataSize) override
Hardware will write data. After finished write operation, onDataWritten() function will be called.
I2C_HandleTypeDef * hardwareHandle()
Returns the hardware handle.
virtual uint32_t hardwareFrame(CommunicationHardware::Frame frame) const
Converts the frame information from semf to STM.
void checkAddress(uint8_t address) override
Checks if the given address is available on the bus. Emits address found if successful (ACK)....
void stopWrite() override
@ ReadHardware_HalTimeout
void isrWritten(I2C_HandleTypeDef &i2c)
Interrupt service routine for i2c object transmit.
static void systemIsrWritten(I2C_HandleTypeDef &i2c)
System-wide interrupt service routine for i2c transmit.
static LinkedQueue< Stm32I2cMaster > * queue()
Get the list with all i2c.
void readHardware(uint8_t buffer[], size_t bufferSize) override
Hardware will read data. After finished read operation, onDataAvailable() function will be called.
void setFrequency(uint32_t hz) override
Sets the speed (I2C baud rate).
void isrRead(I2C_HandleTypeDef &i2c)
Interrupt service routine for i2c object receive.
static void systemIsrError(I2C_HandleTypeDef &i2c)
System-wide interrupt service routine for i2c error.
void isrAbort(I2C_HandleTypeDef &i2c)
Interrupt service routine for i2c object abort.
Stm32I2cMaster(I2C_HandleTypeDef &hwHandle)
Constructor.
static void systemIsrAbort(I2C_HandleTypeDef &i2c)
System-wide interrupt service routine for process canceling.
static void systemIsrRead(I2C_HandleTypeDef &i2c)
System-wide interrupt service routine for i2c receive.
#define SEMF_WARNING(...)