The friendly Operating System for the Internet of Things

Low-level I2C peripheral driver. More...

Detailed Description

Files

file  i2c.h
 Low-level I2C peripheral driver interface definition.
 

Macros

#define I2C_FLAG_WRITE   0
 Flag signaling a write operation on the bus. More...
 
#define I2C_FLAG_READ   1
 Flag signaling a read operation on the bus.
 

Functions

int i2c_init_master (i2c_t dev, i2c_speed_t speed)
 Initialize an I2C device to run as bus master. More...
 
int i2c_acquire (i2c_t dev)
 Get mutually exclusive access to the given I2C bus. More...
 
int i2c_release (i2c_t dev)
 Release the given I2C device to be used by others. More...
 
int i2c_read_byte (i2c_t dev, uint8_t address, void *data)
 Read one byte from an I2C device with the given address. More...
 
int i2c_read_bytes (i2c_t dev, uint8_t address, void *data, int length)
 Read multiple bytes from an I2C device with the given address. More...
 
int i2c_read_reg (i2c_t dev, uint8_t address, uint8_t reg, void *data)
 Read one byte from a register at the I2C slave with the given address. More...
 
int i2c_read_regs (i2c_t dev, uint8_t address, uint8_t reg, void *data, int length)
 Read multiple bytes from a register at the I2C slave with the given address. More...
 
int i2c_write_byte (i2c_t dev, uint8_t address, uint8_t data)
 Write one byte to an I2C device with the given address. More...
 
int i2c_write_bytes (i2c_t dev, uint8_t address, const void *data, int length)
 Write multiple bytes to an I2C device with the given address. More...
 
int i2c_write_reg (i2c_t dev, uint8_t address, uint8_t reg, uint8_t data)
 Write one byte to a register at the I2C slave with the given address. More...
 
int i2c_write_regs (i2c_t dev, uint8_t address, uint8_t reg, const void *data, int length)
 Write multiple bytes to a register at the I2C slave with the given address. More...
 
void i2c_poweron (i2c_t dev)
 Power on the given I2C peripheral. More...
 
void i2c_poweroff (i2c_t dev)
 Power off the given I2C peripheral. More...
 
#define I2C_DEV(x)   (x)
 Default I2C device access macro.
 
#define I2C_UNDEF   (UINT_MAX)
 Default I2C undefined value.
 
typedef unsigned int i2c_t
 Default i2c_t type definition.
 
enum  i2c_speed_t {
  I2C_SPEED_LOW = 0x01, I2C_SPEED_NORMAL = TWI_FREQUENCY_FREQUENCY_K100, I2C_SPEED_FAST = TWI_FREQUENCY_FREQUENCY_K400, I2C_SPEED_FAST_PLUS = 0x02,
  I2C_SPEED_HIGH = 0x03, I2C_SPEED_LOW = 0, I2C_SPEED_NORMAL, I2C_SPEED_FAST,
  I2C_SPEED_FAST_PLUS, I2C_SPEED_HIGH
}
 Default mapping of I2C bus speed values. More...
 

Macro Definition Documentation

#define I2C_FLAG_WRITE   0
Todo:
Remove dev_enums.h include once all platforms are ported to the updated periph interface

Definition at line 74 of file i2c.h.

Enumeration Type Documentation

Enumerator
I2C_SPEED_LOW 

not supported

I2C_SPEED_NORMAL 

100kbit/s

I2C_SPEED_FAST 

400kbit/s

I2C_SPEED_FAST_PLUS 

not supported

I2C_SPEED_HIGH 

not supported

I2C_SPEED_LOW 

low speed mode: ~10kbit/s

I2C_SPEED_NORMAL 

normal mode: ~100kbit/s

I2C_SPEED_FAST 

fast mode: ~400kbit/sj

I2C_SPEED_FAST_PLUS 

fast plus mode: ~1Mbit/s

I2C_SPEED_HIGH 

high speed mode: ~3.4Mbit/s

Definition at line 113 of file i2c.h.

Function Documentation

int i2c_acquire ( i2c_t  dev)

In case the I2C device is busy, this function will block until the bus is free again.

Parameters
[in]devI2C device to access
Returns
0 on success
-1 on error
int i2c_init_master ( i2c_t  dev,
i2c_speed_t  speed 
)
Parameters
[in]devthe device to initialize
[in]speedthe selected bus speed
Returns
0 on successful initialization
-1 on undefined device given
-2 on unsupported speed value
void i2c_poweroff ( i2c_t  dev)
Parameters
[in]devthe I2C device to power off
void i2c_poweron ( i2c_t  dev)
Parameters
[in]devthe I2C device to power on
int i2c_read_byte ( i2c_t  dev,
uint8_t  address,
void *  data 
)
Parameters
[in]devI2C peripheral device
[in]addressbus address of the target device
[out]datathe result that was read
Returns
the number of bytes that were read
-1 on undefined device given
-2 on invalid address
int i2c_read_bytes ( i2c_t  dev,
uint8_t  address,
void *  data,
int  length 
)
Parameters
[in]devI2C peripheral device
[in]addressbus address of the target device
[out]dataarray holding the received bytes
[in]lengththe number of bytes to read into data
Returns
the number of bytes that were read
-1 on undefined device given
int i2c_read_reg ( i2c_t  dev,
uint8_t  address,
uint8_t  reg,
void *  data 
)
Parameters
[in]devI2C peripheral device
[in]addressbus address of the target device
[in]regthe register address on the targeted I2C device
[out]datathe result that was read
Returns
the number of bytes that were read
-1 on undefined device given
int i2c_read_regs ( i2c_t  dev,
uint8_t  address,
uint8_t  reg,
void *  data,
int  length 
)
Parameters
[in]devI2C peripheral device
[in]addressbus address of the target device
[in]regthe register address on the targeted I2C device
[out]dataarray holding the received bytes
[in]lengththe number of bytes to read into data
Returns
the number of bytes that were read
-1 on undefined device given
int i2c_release ( i2c_t  dev)
Parameters
[in]devI2C device to release
Returns
0 on success
-1 on error
int i2c_write_byte ( i2c_t  dev,
uint8_t  address,
uint8_t  data 
)
Parameters
[in]devI2C peripheral device
[in]addressbus address of the target device
[in]databyte to write to the device
Returns
the number of bytes that were written
-1 on undefined device given
int i2c_write_bytes ( i2c_t  dev,
uint8_t  address,
const void *  data,
int  length 
)
Parameters
[in]devI2C peripheral device
[in]addressbus address of the target device
[in]dataarray with bytes to write to the target device
[in]lengthnumber of bytes to write to the target device
Returns
the number of bytes that were written
-1 on undefined device given
int i2c_write_reg ( i2c_t  dev,
uint8_t  address,
uint8_t  reg,
uint8_t  data 
)
Parameters
[in]devI2C peripheral device
[in]addressbus address of the target device
[in]regthe register address on the targeted I2C device
[in]databyte to write to the device
Returns
the number of bytes that were written
-1 on undefined device given
int i2c_write_regs ( i2c_t  dev,
uint8_t  address,
uint8_t  reg,
const void *  data,
int  length 
)
Parameters
[in]devI2C peripheral device
[in]addressbus address of the target device
[in]regthe register address on the targeted I2C device
[in]dataarray with bytes to write to the target device
[in]lengthnumber of bytes to write to the target device
Returns
the number of bytes that were written
-1 on undefined device given