...
 
Commits (4)
......@@ -46,6 +46,9 @@ void I2C::sendMessage(i2c_message_t msg)
void I2C::txDone()
{
if(_msg.status != nullptr)
*_msg.status = MsgStatus::dataTransmitted;
if(!_msgRingBuffer.isEmpty())
sendMessageToHardware();
else
......@@ -63,6 +66,17 @@ void I2C::rxDone()
_i2cState = I2CState::I2CTransmissionPossible;
}
void I2C::errorCallback()
{
if(_msg.status != nullptr)
*_msg.status = MsgStatus::timedOut;
HAL_I2C_DeInit(_i2cHandler);
HAL_I2C_Init(_i2cHandler);
_i2cState = I2CState::I2CTransmissionPossible;
}
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
for(uint8_t i=0; i<i2cNumber; ++i){
......@@ -81,6 +95,15 @@ void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)
}
}
void HAL_I2C_ErrorCallback (I2C_HandleTypeDef * hi2c)
{
for(uint8_t i=0; i<i2cNumber; ++i){
if(asyncI2CArray[i]->getI2CHandler() == hi2c){
asyncI2CArray[i]->errorCallback();
}
}
}
/* Définition Fonctions privees (static) -------------------------------------*/
void I2C::sendMessageToHardware()
......
......@@ -97,6 +97,19 @@ public:
*/
void rxDone();
/*!
* @brief void errorCallback
*
* Handle errors happening on the link, commonly used to take care of AF (Acknowledgement failure)
* it will return a failure state to the message, which hereafter should trigger a reaction from the
* upper class that was sending the message. A reset might be needed since the failure wasn't expected
*
* I2C will by default be reseted to be in a functioning state for the next packet.
*
* @return Nothing
*/
void errorCallback();
I2C_HandleTypeDef* getI2CHandler() { return _i2cHandler; };
private:
......
......@@ -14,6 +14,7 @@
enum MsgStatus {
inUse = 0,
dataValid,
dataTransmitted,
dataUsed,
timedOut
};
......