#include #if false namespace sta { STM32I2cDevice::STM32I2cDevice(I2C_HandleTypeDef* i2cHandle, uint16_t address, Mutex* mutex, bool master, bool blocking) : I2cDevice(address, mutex, master, blocking) { this->master = master; } bool STM32I2cDevice::transmit(uint8_t* data, uint16_t size) { HAL_StatusTypeDef res; if (this->blocking) { if (!this->master) { res = HAL_I2C_Master_Transmit(i2cHandle, address, data, size, this->timeout); } else { res = HAL_I2C_Slave_Transmit(i2cHandle , data, size, this->timeout); } } else { if (!this->master) { res = HAL_I2C_Master_Transmit_IT(i2cHandle, address, data, size); } else { res = HAL_I2C_Slave_Transmit_IT(i2cHandle , data, size); } } return res == HAL_OK; } bool STM32I2cDevice::receive(uint8_t* data, uint16_t size) { HAL_StatusTypeDef res; if (this->blocking) { if (!this->master) { res = HAL_I2C_Master_Receive(i2cHandle, address, data, size, this->timeout); } else { res = HAL_I2C_Slave_Receive(i2cHandle , data, size, this->timeout); } } else { if (!this->master) { res = HAL_I2C_Master_Receive_IT(i2cHandle, address, data, size); } else { res = HAL_I2C_Slave_Receive_IT(i2cHandle , data, size); } } return res == HAL_OK; } bool STM32I2cDevice::deviceReady() { HAL_StatusTypeDef res = HAL_I2C_IsDeviceReady(this->i2cHandle, this->address, 8, this->timeout); return res == HAL_OK; } } #endif // false