Main data structures and functions.
More...
|
struct i2cd * | i2cd_open (const char *path) |
| Open the I2C character device specified by path . More...
|
|
struct i2cd * | i2cd_open_by_name (const char *name) |
| Open the I2C character device specified by name . More...
|
|
struct i2cd * | i2cd_open_by_number (unsigned int num) |
| Open the I2C character device specified by num . More...
|
|
void | i2cd_close (struct i2cd *dev) |
| Close an I2C character device handle and free associated memory. More...
|
|
const char * | i2cd_get_path (struct i2cd *dev) |
| Get the path used to open the I2C character device handle. More...
|
|
int | i2cd_set_retries (struct i2cd *dev, unsigned long retries) |
| Set the number of times a slave address should be polled when not acknowledging. More...
|
|
int | i2cd_set_timeout (struct i2cd *dev, unsigned long timeout) |
| Set the timeout in units of 10ms. More...
|
|
int | i2cd_get_functionality (struct i2cd *dev, unsigned long *funcs) |
| Get the adapter functionality mask. More...
|
|
int | i2cd_transfer (struct i2cd *dev, struct i2c_msg msgs[], size_t nmsgs) |
| Transfer one or more low-level messages terminated with a single STOP condition. More...
|
|
int | i2cd_read (struct i2cd *dev, uint16_t addr, void *buf, size_t len) |
| Read bytes from a slave device. More...
|
|
int | i2cd_write (struct i2cd *dev, uint16_t addr, const void *buf, size_t len) |
| Write bytes to a slave device. More...
|
|
int | i2cd_write_read (struct i2cd *dev, uint16_t addr, const void *write_buf, size_t write_len, void *read_buf, size_t read_len) |
| Write and read bytes from a slave device using a repeated START condition. More...
|
|
Main data structures and functions.
#include <i2cd.h>
◆ i2cd_close()
void i2cd_close |
( |
struct i2cd * |
dev | ) |
|
Close an I2C character device handle and free associated memory.
- Parameters
-
dev | Pointer to an I2C character device handle. |
Once closed, dev
is no longer valid for use.
◆ i2cd_get_functionality()
int i2cd_get_functionality |
( |
struct i2cd * |
dev, |
|
|
unsigned long * |
funcs |
|
) |
| |
Get the adapter functionality mask.
- Parameters
-
dev | Pointer to an I2C character device handle. |
funcs | Pointer to a buffer to receive a mask. |
- Returns
- 0 on success, or -1 on error with
errno
set appropriately.
Adapter functionality can be determined by comparing the returned mask to values defined by the I2C_FUNC_*
macros in linux/i2c.h
.
This function corresponds to the I2C_FUNCS
ioctl()
request.
◆ i2cd_get_path()
const char* i2cd_get_path |
( |
struct i2cd * |
dev | ) |
|
Get the path used to open the I2C character device handle.
- Parameters
-
dev | Pointer to an I2C character device handle. |
- Returns
- The path used to open the I2C character device handle.
◆ i2cd_open()
struct i2cd* i2cd_open |
( |
const char * |
path | ) |
|
Open the I2C character device specified by path
.
- Parameters
-
path | Path to the I2C character device to open. |
- Returns
- Pointer to an I2C character device handle, or
NULL
on error with errno
set appropriately.
◆ i2cd_open_by_name()
struct i2cd* i2cd_open_by_name |
( |
const char * |
name | ) |
|
Open the I2C character device specified by name
.
- Parameters
-
name | Name of the I2C character device to open. |
- Returns
- Pointer to an I2C character device handle, or
NULL
on error with errno
set appropriately.
This function is equivalent to calling:
char path[PATH_MAX];
snprintf(path, sizeof(path), "/dev/%s", name);
◆ i2cd_open_by_number()
struct i2cd* i2cd_open_by_number |
( |
unsigned int |
num | ) |
|
Open the I2C character device specified by num
.
- Parameters
-
num | Number of the I2C character device to open. |
- Returns
- Pointer to an I2C character device handle, or
NULL
on error with errno
set appropriately.
This function is equivalent to calling:
char path[PATH_MAX];
snprintf(path, sizeof(path), "/dev/i2c-%u", num);
◆ i2cd_read()
int i2cd_read |
( |
struct i2cd * |
dev, |
|
|
uint16_t |
addr, |
|
|
void * |
buf, |
|
|
size_t |
len |
|
) |
| |
Read bytes from a slave device.
- Parameters
-
dev | Pointer to an I2C character device handle. |
addr | I2C slave address. |
buf | Pointer to a buffer to receive bytes. |
len | Number of bytes to read. |
- Returns
- Number of messages transferred on success, or -1 on error with
errno
set appropriately.
◆ i2cd_set_retries()
int i2cd_set_retries |
( |
struct i2cd * |
dev, |
|
|
unsigned long |
retries |
|
) |
| |
Set the number of times a slave address should be polled when not acknowledging.
- Parameters
-
dev | Pointer to an I2C character device handle. |
retries | Number of times to retry. |
- Returns
- 0 on success, or -1 on error with
errno
set appropriately.
This function corresponds to the I2C_RETRIES
ioctl()
request.
◆ i2cd_set_timeout()
int i2cd_set_timeout |
( |
struct i2cd * |
dev, |
|
|
unsigned long |
timeout |
|
) |
| |
Set the timeout in units of 10ms.
- Parameters
-
dev | Pointer to an I2C character device handle. |
timeout | Timeout in units of 10ms. |
- Returns
- 0 on success, or -1 on error with
errno
set appropriately.
This function corresponds to the I2C_TIMEOUT
ioctl()
request.
◆ i2cd_transfer()
int i2cd_transfer |
( |
struct i2cd * |
dev, |
|
|
struct i2c_msg |
msgs[], |
|
|
size_t |
nmsgs |
|
) |
| |
Transfer one or more low-level messages terminated with a single STOP condition.
- Parameters
-
dev | Pointer to an I2C character device handle. |
msgs | Array of messages to transfer. |
nmsgs | Number of messages to transfer. |
- Returns
- Number of messages transferred on success, or -1 on error with
errno
set appropriately.
This function corresponds to the I2C_RDWR
ioctl()
request.
◆ i2cd_write()
int i2cd_write |
( |
struct i2cd * |
dev, |
|
|
uint16_t |
addr, |
|
|
const void * |
buf, |
|
|
size_t |
len |
|
) |
| |
Write bytes to a slave device.
- Parameters
-
dev | Pointer to an I2C character device handle. |
addr | I2C slave address. |
buf | Pointer to a buffer to send bytes. |
len | Number of bytes to send. |
- Returns
- Number of messages transferred on success, or -1 on error with
errno
set appropriately.
◆ i2cd_write_read()
int i2cd_write_read |
( |
struct i2cd * |
dev, |
|
|
uint16_t |
addr, |
|
|
const void * |
write_buf, |
|
|
size_t |
write_len, |
|
|
void * |
read_buf, |
|
|
size_t |
read_len |
|
) |
| |
Write and read bytes from a slave device using a repeated START condition.
- Parameters
-
dev | Pointer to an I2C character device handle. |
addr | I2C slave address. |
write_buf | Pointer to a buffer to send bytes. |
write_len | Number of bytes to send. |
read_buf | Pointer to a buffer to receive bytes. |
read_len | Number of bytes to receive. |
- Returns
- Number of messages transferred on success, or -1 on error with
errno
set appropriately.
struct i2cd * i2cd_open(const char *path)
Open the I2C character device specified by path.