![]() |
i2c
1.4.2
RoadNarrows Robotics I2C Package
|
Low-level I2C communication level implementation. More...
#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/errno.h>#include <sys/ioctl.h>#include "rnr/rnrconfig.h"#include "rnr/i2c-dev.h"#include "rnr/i2c.h"Go to the source code of this file.
Functions | |
| static int | i2c_select_device (i2c_t *i2c, i2c_addr_t addr) |
| Selects the I2C device on a given I2C Bus. More... | |
| int | i2c_open (i2c_t *i2c, char const *device) |
| Open the host I2C Bus device. More... | |
| void | i2c_close (i2c_t *i2c) |
| Closes an I2C Bus. More... | |
| int | i2c_read (i2c_t *i2c, i2c_addr_t addr, byte_t *buf, uint_t len) |
| Read from an I2C device. More... | |
| int | i2c_write (i2c_t *i2c, i2c_addr_t addr, const byte_t *buf, uint_t len) |
| Write to an I2C device. More... | |
| int | i2c_transfer (i2c_t *i2c, i2c_addr_t addr, const byte_t *write_buf, uint_t write_len, byte_t *read_buf, uint_t read_len) |
| Perform a transfer with an I2C device. More... | |
| int | i2c_exists (i2c_t *i2c, i2c_addr_t addr) |
| Test the existance of a device at the given address on the given I2C Bus. More... | |
| int | i2c_scan (i2c_t *i2c, int(*callback)(i2c_t *i2c, i2c_addr_t addr, void *context), void *context) |
| Scans the given I2C Bus to find all connected devices. More... | |
Low-level I2C communication level implementation.
This file has been modified from the original i2ccom.c source (see below).
Definition in file i2ccom.c.
| void i2c_close | ( | i2c_t * | i2c | ) |
Closes an I2C Bus.
| [in,out] | i2c | Pointer to I2C Bus handle. |
Definition at line 137 of file i2ccom.c.
References i2c_struct::addr, i2c_struct::fd, and I2C_ADDR_NONE.
Referenced by execQuit(), and i2ccore_close().
| int i2c_exists | ( | i2c_t * | i2c, |
| i2c_addr_t | addr | ||
| ) |
Test the existance of a device at the given address on the given I2C Bus.
| [in] | i2c | Pointer to I2C Bus handle. |
| addr | I2C device's 7/10-bit address. |
Definition at line 199 of file i2ccom.c.
References i2c_msg_struct::addr, i2c_msg_struct::buf, i2c_struct::fd, i2c_msg_struct::flags, I2C_M_NOFLAGS, I2C_RDWR, i2c_msg_struct::len, i2c_rdwr_ioctl_data_struct::msgs, and i2c_rdwr_ioctl_data_struct::nmsgs.
Referenced by execCheck(), i2c_scan(), and i2ccore_check().
| int i2c_open | ( | i2c_t * | i2c, |
| const char * | device | ||
| ) |
Open the host I2C Bus device.
| [out] | i2c | Pointer to I2C Bus handle. Note: This descriptor must be allocated by the caller. |
| device | A null-terminated string of the device name. If NULL, then the default '/dev/i2c/0' is used. |
Definition at line 118 of file i2ccom.c.
References i2c_struct::addr, i2c_struct::fd, and I2C_ADDR_NONE.
Referenced by i2ccore_open(), and MainInit().
| int i2c_read | ( | i2c_t * | i2c, |
| i2c_addr_t | addr, | ||
| byte_t * | buf, | ||
| uint_t | len | ||
| ) |
Read from an I2C device.
The i2c_read() primitive reads data from a device at the given address on the given I2C Bus.
| [in,out] | i2c | Pointer to I2C Bus handle. |
| addr | I2C device's 7/10-bit address. | |
| [out] | buf | Pointer to the buffer that will receive the data bytes. |
| len | Size of the buffer in bytes. |
Definition at line 147 of file i2ccom.c.
References i2c_struct::fd, and i2c_select_device().
Referenced by execRead(), and i2ccore_read().
| int i2c_scan | ( | i2c_t * | i2c, |
| int(*)(i2c_t *i2c, i2c_addr_t addr, void *context) | callback, | ||
| void * | context | ||
| ) |
Scans the given I2C Bus to find all connected devices.
For each device found, the provided callback function is called.
| [in] | i2c | Pointer to I2C Bus handle. |
| callback | A callback function called when a device is found. If this callback function returns a value <0 the bus scan stops immedialety and the value is used as return value by i2c_scan(). | |
| context | A user defined value or a pointer passed to the callback function. |
Definition at line 219 of file i2ccom.c.
References I2C_ADDR_DEV_HIGH, I2C_ADDR_DEV_LOW, and i2c_exists().
Referenced by execScan().
|
static |
Selects the I2C device on a given I2C Bus.
| [in,out] | i2c | Pointer to I2C Bus handle. |
| addr | I2C device's 7/10-bit address. |
Definition at line 97 of file i2ccom.c.
References i2c_struct::addr, i2c_struct::fd, and I2C_SLAVE.
Referenced by i2c_read(), and i2c_write().
| int i2c_transfer | ( | i2c_t * | i2c, |
| i2c_addr_t | addr, | ||
| const byte_t * | write_buf, | ||
| uint_t | write_len, | ||
| byte_t * | read_buf, | ||
| uint_t | read_len | ||
| ) |
Perform a transfer with an I2C device.
The i2c_transfer() primitive writes data to and then reads data from a device at the given address on the given I2C Bus. It is optimize to reduce start/stop sequences.
| [in] | i2c | Pointer to I2C Bus handle. |
| addr | I2C device's 7/10-bit address. | |
| write_buf | Pointer to the buffer that contains the data to be written. | |
| write_len | Number of bytes to write. The data are in the write buffer. | |
| [out] | read_buf | Pointer to the buffer that will receive the data. |
| read_len | Size of the read buffer in bytes. |
Definition at line 171 of file i2ccom.c.
References i2c_msg_struct::addr, i2c_msg_struct::buf, i2c_struct::fd, i2c_msg_struct::flags, I2C_M_NOFLAGS, I2C_M_RD, I2C_RDWR, i2c_msg_struct::len, i2c_rdwr_ioctl_data_struct::msgs, and i2c_rdwr_ioctl_data_struct::nmsgs.
Referenced by execTrans(), execTransaction(), and i2ccore_transfer().
| int i2c_write | ( | i2c_t * | i2c, |
| i2c_addr_t | addr, | ||
| const byte_t * | buf, | ||
| uint_t | len | ||
| ) |
Write to an I2C device.
The i2c_write() primitive writes data to a device at the given address on the given I2C Bus.
| [in,out] | i2c | Pointer to I2C Bus handle. |
| addr | I2C device's 7/10-bit address. | |
| buf | Pointer to the buffer that will be written. | |
| len | Number of bytes to write. |
Definition at line 159 of file i2ccom.c.
References i2c_struct::fd, and i2c_select_device().
Referenced by execWrite(), and i2ccore_write().