HRI board firmware  v2.1
Microcontroller firmware of the board used during the HRI labs.
Macros | Functions | Variables
i2c.c File Reference
#include "i2c.h"
#include "stm32f4xx_i2c.h"
#include "../lib/utils.h"

Macros

#define WAIT_WITH_TIMEOUT(x)
 Repeats until the expression returns false, or the timeout is reached. More...
 

Functions

void i2c_Init (void)
 Initializes the I2C bus. More...
 
void i2c_Reset (void)
 Performs a stop condition, to abort the current transaction. More...
 
void i2c_WriteRegister (uint8_t slaveAddress, uint8_t registerAddress, uint8_t registerValue, bool *ok)
 Writes a 8-bit value to a register. More...
 
void i2c_WriteMultiBytesRegister (uint8_t slaveAddress, uint8_t registerAddress, uint8_t const *registerValue, uint8_t registerSize, bool *ok)
 Writes several bytes to a register. More...
 
uint8_t i2c_ReadRegister (uint8_t slaveAddress, uint8_t registerAddress, bool *ok)
 Reads a 8-bit value from a register. More...
 
void i2c_ReadMultiBytesRegister (uint8_t slaveAddress, uint8_t registerAddress, uint8_t *readData, uint8_t registerSize, bool *ok)
 Reads a multi bytes value from a register. More...
 

Variables

const uint32_t TIMEOUT = 1000
 Approximate maximum time for a I2C operation to complete (approx. 100us). More...
 

Macro Definition Documentation

◆ WAIT_WITH_TIMEOUT

#define WAIT_WITH_TIMEOUT (   x)
Value:
do \
{ \
uint32_t duration = 0;\
while((x)) \
{ \
if(duration++ > TIMEOUT) \
{ \
i2c_Reset(); \
if(ok != NULL) \
*ok = false; \
return; \
} \
} \
} while(0)
const uint32_t TIMEOUT
Approximate maximum time for a I2C operation to complete (approx. 100us).
Definition: i2c.c:23

Repeats until the expression returns false, or the timeout is reached.

Function Documentation

◆ i2c_Reset()

void i2c_Reset ( void  )

Performs a stop condition, to abort the current transaction.

Variable Documentation

◆ TIMEOUT

const uint32_t TIMEOUT = 1000

Approximate maximum time for a I2C operation to complete (approx. 100us).