![]() |
m2mb API docs
25.21.002
m2mb API sets documentation
|
I2C library implementation. More...
Go to the source code of this file.
Data Structures | |
| struct | M2MB_I2C_MSG |
| struct | M2MB_I2C_RDWR_IOCTL_DATA |
| struct | M2MB_I2C_CFG_T |
Macros | |
| #define | NULL 0 |
| #define | I2C_M_WR 0x0000 /* write data, from master to slave */ |
| #define | I2C_M_RD 0x0001 /* read data, from slave to master */ |
Enumerations | |
| enum | M2MB_I2C_IOCTL_REQUEST { M2MB_I2C_IOCTL_SET_CFG, M2MB_I2C_IOCTL_GET_CFG, M2MB_I2C_IOCTL_RDWR } |
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 from an I2C device More... | |
| SSIZE_T | m2mb_i2c_write (INT32 fd, const void *buf, SIZE_T nbyte) |
| write to an 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: m2m/m2m_generic/common/m2mb_inc/m2mb_types.h
@changes Enrico Perini
| INT32 m2mb_i2c_close | ( | INT32 | fd | ) |
close an I2C device
This function closes a I2C device (from 1 to 10)
| [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 parameters depend on request code: if request == M2MB_I2C_IOCTL_SET_CFG: SDA and SCL pins are mapped on GPIOs, and the register of the device from which reading or to which writing is set; in struct M2MB_I2C_CFG_T, sdaPin, sclPin and registerId are mandatory if request == M2MB_I2C_IOCTL_RDWR: reading and writing through I2C combined format; in struct M2MB_I2C_CFG_T, rw_param is mandatory if request == M2MB_I2C_IOCTL_GET_CFG: a pointer to the structure M2MB_I2C_CFG_T previously set is got |
Example
| INT32 m2mb_i2c_open | ( | const CHAR * | path, |
| INT32 | flags, | ||
| ... | |||
| ) |
open an I2C device
This function opens a I2C device (from 1 to 10)
| [in] | path | the path has a string of this type: /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 |
Example
| SSIZE_T m2mb_i2c_read | ( | INT32 | fd, |
| void * | buf, | ||
| SIZE_T | nbyte | ||
| ) |
read from an I2C device
This function reads nbyte Bytes from a I2C device into the array pointed to by buf
| [in] | fd | file descriptor returned by m2mb_i2c_open |
| [in] | buf | destination buffer, previously allocated |
| [in] | nbyte | length of destination buffer in Bytes |
Example
| SSIZE_T m2mb_i2c_write | ( | INT32 | fd, |
| const void * | buf, | ||
| SIZE_T | nbyte | ||
| ) |
write to an I2C device
This function writes nbyte Bytes from the array pointed to by buf to a I2C device
| [in] | fd | file descriptor returned by m2mb_i2c_open |
| [in] | buf | source buffer, previously allocated |
| [in] | nbyte | length of source buffer in Bytes |
Example