36#error "Your architecture doesn't support I2C"
69#ifdef _ARCH_CORTEXM7_STM32F7
117 bool MSBFirst =
false;
135 I2CDriver(I2C_TypeDef* i2c, miosix::GpioPin scl, miosix::GpioPin sda);
160 const size_t& nBytes);
174 const void* buffer,
const size_t& nBytes,
175 bool generateStop =
true);
236 const uint8_t* buffWrite;
253 void setupPeripheral(
const I2CSlaveConfig& slaveConfig);
255#ifdef _ARCH_CORTEXM7_STM32F7
260 inline void setupTransaction();
266 inline void setupReload();
280 [[nodiscard]]
bool doOperation(
const I2CSlaveConfig& slaveConfig);
295 inline bool IRQwaitForOperationCompletion(
296 miosix::FastInterruptDisableLock& dLock);
303 inline void IRQwakeUpWaitingThread();
314 bool reStarting =
false;
315 miosix::Thread* waiting{};
316 I2CTransaction transaction;
Low level driver for I2C peripherals.
I2CDriver & operator=(const I2CDriver &)=delete
I2CDriver(const I2CDriver &)=delete
bool read(const I2CSlaveConfig &slaveConfig, void *buffer, const size_t &nBytes)
Read operation to read nBytes. In case of an error during the communication, this method returns fals...
void flushBus()
Performs the recovery from the locked state if necessary.
I2CDriver & operator=(I2CDriver &&)=delete
uint16_t getLastError()
Returns the last errors happened in the communication.
Errors
Error enums with a value that makes it possible to keep the "or-red" value to store more errors.
@ BUS_LOCKED
Detected a locked state on the bus.
@ BERR
External Start or stop condition detected.
@ NO_ERROR
The bus didn't have any error.
@ ADDR_ERROR
Address sent but peripheral in wrong state.
@ OVR
Overrun/underrun error.
@ SB_NOT_SENT
Start bit not sent.
I2CDriver(I2CDriver &&)=delete
I2CDriver(I2C_TypeDef *i2c, miosix::GpioPin scl, miosix::GpioPin sda)
Constructor for the I2C low-level driver.
bool write(const I2CSlaveConfig &slaveConfig, const void *buffer, const size_t &nBytes, bool generateStop=true)
Write operation to write nBytes. In case of an error during the communication, this method returns fa...
~I2CDriver()
Disables the peripheral, the interrupts in the NVIC and the peripheral's clock.
void IRQhandleInterrupt()
Handles the interrupt for events of the specific peripheral.
void IRQhandleErrInterrupt()
Handles the interrupt for the errors in the specific peripheral.
static PrintLogger getLogger(const string &name)
This file includes all the types the logdecoder script will decode.
Configuration struct for a slave device. This will be used for configuring the bus in order to commun...
uint16_t slaveAddress
Addressing mode of the device.