Difference between revisions of "I2c library for C"

From Tuxamito
Jump to: navigation, search
(Created page with "This library was created to make communication with I2C devices from C language. Up to know it has work fine for in Raspberry Pi boards (and similar ones!). Download: File...")
 
Line 2: Line 2:
  
 
Download: [[File:i2c-driver.tar.gz]]
 
Download: [[File:i2c-driver.tar.gz]]
 +
 +
= Usage =
 +
 +
<syntaxhighlight lang="cpp">
 +
int i2c_dev_open(struct i2c_dev *dev, int adapter);
 +
int i2c_dev_close(struct i2c_dev *dev);
 +
 +
int i2c_dev_write(struct i2c_dev *dev, uint8_t *buf, int n);
 +
int i2c_dev_read(struct i2c_dev *dev, uint8_t *buf, int n);
 +
int i2c_dev_wrrs(struct i2c_dev *dev, uint8_t *wbuf, int wn, uint8_t *rbuf, int rn);
 +
</syntaxhighlight>
 +
 +
=== Set Up I2C device ===
 +
<syntaxhighlight lang="cpp">
 +
int i2c_dev_open(struct i2c_dev *dev, int adapter);
 +
</syntaxhighlight>
 +
 +
=== Close I2C device ===
 +
<syntaxhighlight lang="cpp">
 +
int i2c_dev_close(struct i2c_dev *dev);
 +
</syntaxhighlight>
 +
 +
=== Write to device ===
 +
<syntaxhighlight lang="cpp">
 +
int i2c_dev_write(struct i2c_dev *dev, uint8_t *buf, int n);
 +
</syntaxhighlight>
 +
 +
 +
=== Read from device ===
 +
<syntaxhighlight lang="cpp">
 +
int i2c_dev_read(struct i2c_dev *dev, uint8_t *buf, int n);
 +
</syntaxhighlight>
 +
 +
=== Combined Write/Read ===
 +
<syntaxhighlight lang="cpp">
 +
int i2c_dev_wrrs(struct i2c_dev *dev, uint8_t *wbuf, int wn, uint8_t *rbuf, int rn);
 +
</syntaxhighlight>
 +
 +
= Example =

Revision as of 13:37, 11 November 2015

This library was created to make communication with I2C devices from C language. Up to know it has work fine for in Raspberry Pi boards (and similar ones!).

Download: File:I2c-driver.tar.gz

Usage

int i2c_dev_open(struct i2c_dev *dev, int adapter);
int i2c_dev_close(struct i2c_dev *dev);

int i2c_dev_write(struct i2c_dev *dev, uint8_t *buf, int n);
int i2c_dev_read(struct i2c_dev *dev, uint8_t *buf, int n);
int i2c_dev_wrrs(struct i2c_dev *dev, uint8_t *wbuf, int wn, uint8_t *rbuf, int rn);

Set Up I2C device

int i2c_dev_open(struct i2c_dev *dev, int adapter);

Close I2C device

int i2c_dev_close(struct i2c_dev *dev);

Write to device

int i2c_dev_write(struct i2c_dev *dev, uint8_t *buf, int n);


Read from device

int i2c_dev_read(struct i2c_dev *dev, uint8_t *buf, int n);

Combined Write/Read

int i2c_dev_wrrs(struct i2c_dev *dev, uint8_t *wbuf, int wn, uint8_t *rbuf, int rn);

Example