![]() |
m2mb API docs
25.30.003
m2mb API sets documentation
|
I2C library implementation. More...
Go to the source code of this file.
Data Structures | |
| struct | M2MB_I2C_MSG |
| Structure to be used as container for a write or read operation in I2C Combined mode (M2MB_I2C_IOCTL_RDWR call) More... | |
| struct | M2MB_I2C_RDWR_IOCTL_DATA |
| Structure to be used with the M2MB_I2C_IOCTL_RDWR option in m2mb_i2c_ioctl call. More... | |
| struct | M2MB_I2C_CFG_T |
| I2C device configuration structure. More... | |
Macros | |
| #define | NULL 0 |
| #define | I2C_M_WR 0x0000 |
| #define | I2C_M_RD 0x0001 |
Enumerations | |
| enum | M2MB_I2C_IOCTL_REQUEST { M2MB_I2C_IOCTL_SET_CFG, M2MB_I2C_IOCTL_GET_CFG, M2MB_I2C_IOCTL_RDWR } |
| enum used to access I2C configuration More... | |
Functions | |
| INT32 | m2mb_i2c_open (const CHAR *path, INT32 flags,...) |
| open an I2C device More... | |
| INT32 | m2mb_i2c_close (INT32 fd) |
| Close an I2C device. More... | |
| INT32 | m2mb_i2c_ioctl (INT32 fd, INT32 request,...) |
| configure, read from and/or write to an I2C device More... | |
| SSIZE_T | m2mb_i2c_read (INT32 fd, void *buf, SIZE_T nbyte) |
| Read data from a connected I2C device. More... | |
| SSIZE_T | m2mb_i2c_write (INT32 fd, const void *buf, SIZE_T nbyte) |
| Write data to a connected I2C device. More... | |
I2C library implementation.
m2m/m2m_generic/common/m2mb_inc/m2mb_i2c.h
The following functions are implemented: m2mb_i2c_ioctl m2mb_i2c_open m2mb_i2c_read m2mb_i2c_write m2mb_i2c_close
@notes Dependencies: m2mb_types.h
@changes Enrico Perini
| #define I2C_M_RD 0x0001 |
read data, from slave to master
| #define I2C_M_WR 0x0000 |
write data, from master to slave
| INT32 m2mb_i2c_close | ( | INT32 | fd | ) |
Close an I2C device.
This function closes an opened file descriptor.
| [in] | fd | File descriptor returned by m2mb_i2c_open |
| INT32 m2mb_i2c_ioctl | ( | INT32 | fd, |
| INT32 | request, | ||
| ... | |||
| ) |
configure, read from and/or write to an I2C device
Depending on request parameter, this function can configure an I2C device, or can send and/or receive data through I2C combined format
| [in] | fd | file descriptor returned by m2mb_i2c_open |
| [in] | request | required operation (see M2MB_I2C_IOCTL_REQUEST) |
| [in] | cfg | pointer to the configuration struct M2MB_I2C_CFG_T casted to void* The parameter depend on request code: if request == M2MB_I2C_IOCTL_SET_CFG: in struct M2MB_I2C_CFG_T sdaPin, sclPin and registerId are mandatory SDA and SCL pins are mapped on GPIOs, the slave device register Id from which to read (or to which to write) is set if request == M2MB_I2C_IOCTL_GET_CFG: a pointer to the structure M2MB_I2C_CFG_T previously set is got if request == M2MB_I2C_IOCTL_RDWR: in struct M2MB_I2C_CFG_T, sdaPin, sclPin, rw_param are mandatory SDA and SCL pins are mapped on GPIOs, rw_param will contain the buffers and parameters required to read and write through I2C combined format |
Example of config
Example of Combined mode write access
Example of Combined mode read access
| INT32 m2mb_i2c_open | ( | const CHAR * | path, |
| INT32 | flags, | ||
| ... | |||
| ) |
open an I2C device
This function opens a file descriptor to communicate with an I2C device, given its address.
| [in] | path | Path for the device address, in the format "/dev/I2C-#" where # is in decimal format I2C address is in 8 bit format, where last bit is the R/W flag |
| [in] | flags | currently unused |
| SSIZE_T m2mb_i2c_read | ( | INT32 | fd, |
| void * | buf, | ||
| SIZE_T | nbyte | ||
| ) |
Read data from a connected I2C device.
This function will try to read the requested amount of data from the specified I2C device. Read is performed with a write request for the register on the I2C bus, followed by a second Start Sequence and the read request. The register address for the operation must be previously set with m2mb_i2c_ioctl.
| [in] | fd | File descriptor, returned by m2mb_i2c_open |
| [in] | buf | destination buffer, previously allocated |
| [in] | nbyte | length of destination buffer in Bytes |
| SSIZE_T m2mb_i2c_write | ( | INT32 | fd, |
| const void * | buf, | ||
| SIZE_T | nbyte | ||
| ) |
Write data to a connected I2C device.
This function will try to write the requested amount of data to the specified I2C device. The register address for the operation must be previously set with m2mb_i2c_ioctl.
| [in] | fd | File descriptor, returned by m2mb_i2c_open |
| [in] | buf | input buffer, previously allocated |
| [in] | nbyte | number of bytes to be written, in Bytes. |