ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_interface_i2c.h File Reference

Interface for I2C operations. More...

#include "ruuvi_driver_enabled_modules.h"
#include "ruuvi_driver_error.h"
#include "ruuvi_interface_gpio.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ri_i2c_init_config_t
 

Enumerations

enum  ri_i2c_frequency_t { RI_I2C_FREQUENCY_100k , RI_I2C_FREQUENCY_250k , RI_I2C_FREQUENCY_400k }
 

Functions

rd_status_t ri_i2c_init (const ri_i2c_init_config_t *const config)
 Initialize I2C driver with given settings. More...
 
rd_status_t ri_i2c_uninit (void)
 Uninitialize I2C. More...
 
bool ri_i2c_is_init ()
 Check if i2c driver is initialized. More...
 
rd_status_t ri_i2c_read_blocking (const uint8_t address, uint8_t *const p_rx, const size_t rx_len)
 I2C read function. More...
 
rd_status_t ri_i2c_write_blocking (const uint8_t address, uint8_t *const p_tx, const size_t tx_len, const bool stop)
 I2C read function. More...
 

Detailed Description

Interface for I2C operations.

Author
Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net
Date
2020-01-21

Definition in file ruuvi_interface_i2c.h.

Enumeration Type Documentation

◆ ri_i2c_frequency_t

Clock speed

Enumerator
RI_I2C_FREQUENCY_100k 

100 kbps.

RI_I2C_FREQUENCY_250k 

250 kbps.

RI_I2C_FREQUENCY_400k 

400 kbps.

Definition at line 32 of file ruuvi_interface_i2c.h.

Function Documentation

◆ ri_i2c_init()

rd_status_t ri_i2c_init ( const ri_i2c_init_config_t *const  config)

Initialize I2C driver with given settings.

Parameters
[in]configConfiguration of the I2C peripheral.
Returns
error code from the stack, RD_SUCCESS if no error occurred

◆ ri_i2c_is_init()

bool ri_i2c_is_init ( )

Check if i2c driver is initialized.

Returns
true if I2C is initialized, false otherwise.

◆ ri_i2c_read_blocking()

rd_status_t ri_i2c_read_blocking ( const uint8_t  address,
uint8_t *const  p_rx,
const size_t  rx_len 
)

I2C read function.

Function is blocking and will not sleep while transaction is ongoing.

Parameters
[in]address7-bit I2C address of the device, without R/W bit.
[out]p_rxpointer to data to be received
[in]rx_lenlength of data to be received

◆ ri_i2c_uninit()

rd_status_t ri_i2c_uninit ( void  )

Uninitialize I2C.

Returns
error code from the stack, RD_SUCCESS if no error occurred

◆ ri_i2c_write_blocking()

rd_status_t ri_i2c_write_blocking ( const uint8_t  address,
uint8_t *const  p_tx,
const size_t  tx_len,
const bool  stop 
)

I2C read function.

Function is blocking and will not sleep while transaction is ongoing.

Parameters
[in]address7-bit I2C address of the device, without R/W bit.
[out]p_txpointer to data to be transmitted
[in]tx_lenlength of data to be transmitted
[in]stoptrue to transmit stop condition after read, false to hold bus active.