i2c.h File Reference

I2C generic driver functions (interface). More...

#include "cfg/cfg_i2c.h"
#include <cfg/compiler.h>

Go to the source code of this file.


Defines

#define I2C_BACKEND_BUILTIN   0
 I2C Backends.
#define I2C_BACKEND_BITBANG   1
 Uses emulated bitbang driver.

Functions

bool i2c_send (const void *_buf, size_t count)
 Send a sequence of bytes in master transmitter mode to the selected slave device through the I2C bus.
bool i2c_recv (void *_buf, size_t count)
 Receive a sequence of one or more bytes from the selected slave device in master receive mode through the I2C bus.
void i2c_builtin_init (void)
 I2c builtin prototypes.
bool i2c_builtin_start_w (uint8_t id)
 Send START condition and select slave for write.
bool i2c_builtin_start_r (uint8_t id)
 Send START condition and select slave for read.
void i2c_builtin_stop (void)
 Send STOP condition.
bool i2c_builtin_put (uint8_t _data)
 Put a single byte in master transmitter mode to the selected slave device through the TWI bus.
int i2c_builtin_get (bool ack)
 Get 1 byte from slave in master transmitter mode to the selected slave device through the TWI bus.
void i2c_bitbang_init (void)
 I2c bitbang prototypes.

Detailed Description

I2C generic driver functions (interface).

Version:
$Id$
Author:
Francesco Sacchi <batt@develer.com>

Definition in file i2c.h.


Define Documentation

#define I2C_BACKEND_BUILTIN   0

I2C Backends.

Sometimes your cpu does not have a builtin i2c driver or you don't want, for some reason, to use that. With this you can choose, at compile time, which backend to use. Uses cpu builtin i2c driver

Definition at line 54 of file i2c.h.


Function Documentation

void i2c_bitbang_init ( void   ) 

I2c bitbang prototypes.

Same thing here: do NOT use these function directly, instead, you can call the ones named without "_bitbang_" and specify in cfg_i2c.h (

See also:
CONFIG_I2C_BACKEND) that you want the bitbang backend.

Definition at line 172 of file i2c_bitbang.c.

int i2c_builtin_get ( bool  ack  ) 

Get 1 byte from slave in master transmitter mode to the selected slave device through the TWI bus.

If ack is true issue a ACK after getting the byte, otherwise a NACK is issued.

Returns:
the byte read if ok, EOF on errors.

Definition at line 184 of file i2c_avr.c.

void i2c_builtin_init ( void   ) 

I2c builtin prototypes.

Do NOT use these function directly, instead, you can call the ones named without "_builtin_" and specify in cfg_i2c.h (

See also:
CONFIG_I2C_BACKEND) that you want the builtin backend.

Definition at line 215 of file i2c_avr.c.

bool i2c_builtin_put ( const uint8_t  data  ) 

Put a single byte in master transmitter mode to the selected slave device through the TWI bus.

Returns:
true on success, false on error.

Definition at line 163 of file i2c_avr.c.

bool i2c_builtin_start_r ( uint8_t  id  ) 

Send START condition and select slave for read.

id is the device id comprehensive of address left shifted by 1. The LSB of id is ignored and set to 1 for read operation.

Returns:
true on success, false otherwise.

Definition at line 130 of file i2c_avr.c.

bool i2c_builtin_start_w ( uint8_t  id  ) 

Send START condition and select slave for write.

id is the device id comprehensive of address left shifted by 1. The LSB of id is ignored and reset to 0 for write operation.

Returns:
true on success, false otherwise.

Definition at line 90 of file i2c_avr.c.

bool i2c_recv ( void *  _buf,
size_t  count 
)

Receive a sequence of one or more bytes from the selected slave device in master receive mode through the I2C bus.

Received data is placed in buf.

Note:
a NACK is automatically given on the last received byte.
Returns:
true on success, false on error

Definition at line 71 of file i2c.c.

bool i2c_send ( const void *  _buf,
size_t  count 
)

Send a sequence of bytes in master transmitter mode to the selected slave device through the I2C bus.

Returns:
true on success, false on error.

Definition at line 47 of file i2c.c.