WL865E4-P  36.07.001

This section describes the M2MB APIs to perform various I2C operations. More...

#define I2C_FLAG_START   0x00000001
 
#define I2C_FLAG_STOP   0x00000002
 
#define I2C_FLAG_WRITE   0x00000004
 
#define I2C_FLAG_READ   0x00000008
 
enum  M2MB_I2C_IOCTL_REQUEST {
  M2MB_I2C_IOCTL_SET_CFG,
  M2MB_I2C_IOCTL_GET_CFG
}
 
typedef enum M2MB_I2C_IOCTL_REQUEST M2MB_I2C_IOCTL_REQUEST_T
 
typedef void * M2MB_I2C_ID_T
 
INT32 m2mb_i2c_open (const CHAR *path, INT32 flags,...)
 Open an I2C device. More...
 
INT32 m2mb_i2c_close (INT32 fd)
 Closes an I2C device. More...
 
INT32 m2mb_i2c_ioctl (INT32 fd, M2MB_I2C_IOCTL_REQUEST_T request,...)
 Configure the I2C device. More...
 
SSIZE_T m2mb_i2c_read (INT32 fd, void *buf, SIZE_T nbyte)
 Read the I2C device. More...
 
SSIZE_T m2mb_i2c_write (INT32 fd, const void *buf, SIZE_T nbyte)
 Write to I2C device. More...
 

Detailed Description

This section describes the M2MB APIs to perform various I2C operations.

Macro Definition Documentation

◆ I2C_FLAG_READ

#define I2C_FLAG_READ   0x00000008

Must be set to indicate a READ transfer.

Definition at line 58 of file m2mb_i2c.h.

◆ I2C_FLAG_START

#define I2C_FLAG_START   0x00000001

Specifies that the transfer begins with a START bit - S.

Definition at line 55 of file m2mb_i2c.h.

◆ I2C_FLAG_STOP

#define I2C_FLAG_STOP   0x00000002

Specifies that the transfer ends with a STOP bit - P.

Definition at line 56 of file m2mb_i2c.h.

◆ I2C_FLAG_WRITE

#define I2C_FLAG_WRITE   0x00000004

Must be set to indicate a WRITE transfer.

Definition at line 57 of file m2mb_i2c.h.

Typedef Documentation

◆ M2MB_I2C_ID_T

typedef void* M2MB_I2C_ID_T

Definition at line 71 of file m2mb_i2c.h.

◆ M2MB_I2C_IOCTL_REQUEST_T

Enumeration Type Documentation

◆ M2MB_I2C_IOCTL_REQUEST

Enumerator
M2MB_I2C_IOCTL_SET_CFG 

set i2c device configuration

M2MB_I2C_IOCTL_GET_CFG 

get i2c device configuration

Definition at line 63 of file m2mb_i2c.h.

Function Documentation

◆ m2mb_i2c_close()

INT32 m2mb_i2c_close ( INT32  fd)

Closes an I2C device.

This API closes the requested I2C device

Parameters
[in]fdFile Descriptor of I2C device
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API frees the allocated memory to the configuration of type M2MB_I2C_CFG_T and releases the I2C device. On successful closing of the I2C port, allocated memory to the configuration is freed. In case of an error, memory allocation to configuration is not freed. Allowed From De-initialization and tasks Preemption Possible No

Example

INT32 fd;
INT32 status;
status = m2mb_i2c_close( fd );
if(status == -1)
app_dbg_printf("ERROR CLOSING I2C port\r\n");

◆ m2mb_i2c_ioctl()

INT32 m2mb_i2c_ioctl ( INT32  fd,
M2MB_I2C_IOCTL_REQUEST_T  request,
  ... 
)

Configure the I2C device.

This API set/get the I2C device configuration

Parameters
[in]fdFile Descriptor of I2C device
[in]requestrequired operation set/get configuration(see M2MB_I2C_IOCTL_REQUEST)
Returns
0 on SUCCESS
-1 on FAILURE
Note
This API allows to read/write the I2C configuration of type M2MB_I2C_CFG_T. On successful configuration, the requested operation (set/get configuration) is done. In case of an error, the requested operation (set/get configuration) could not be completed. Allowed From Events and tasks Preemption Possible No

Example

INT32 fd;
INT32 status;
M2MB_I2C_CFG_T *P_CFG, *P_ReadCFG;
fd = m2mb_i2c_open("/dev/i2c-1", 0);
if(fd == -1)
app_dbg_printf("ERROR OPENING I2C port\r\n");
P_CFG->bus_Frequency_KHz = I2C_SLAVE_FREQ;
P_CFG->slave_Address = I2C_SLAVE_ADDR;
P_CFG->SMBUS_Mode = 0;
P_CFG->core_Configuration1 = 0;
P_CFG->core_Configuration2 = 0;
status = m2mb_i2c_ioctl( fd, M2MB_I2C_IOCTL_SET_CFG, P_CFG );
if(status == -1)
app_dbg_printf("ERROR IN SET I2C\r\n");
status = m2mb_i2c_ioctl( fd, M2MB_I2C_IOCTL_GET_CFG, P_ReadCFG );
if(status == -1)
app_dbg_printf("ERROR IN GET I2C\r\n");

◆ m2mb_i2c_open()

INT32 m2mb_i2c_open ( const CHAR path,
INT32  flags,
  ... 
)

Open an I2C device.

This API opens the requested I2C device

Parameters
[in]pathPointer to an I2C device to open
[in]flagscurrently unused
Returns
File Descriptor on SUCCESS
-1 on FAILURE
Note
This API allocates memory to the configuration of type M2MB_I2C_CFG_T. After successful opening of the I2C port, the File Descriptor points to M2MB_I2C_CFG_T. In case of an error in memory allocation or opening of the I2C port, it returns -1 Allowed From Initialization and tasks Preemption Possible No

Example

INT32 fd;
fd = m2mb_i2c_open("/dev/i2c-1", 0);
if(fd == -1)
app_dbg_printf("ERROR OPENING I2C port\r\n");

◆ m2mb_i2c_read()

SSIZE_T m2mb_i2c_read ( INT32  fd,
void *  buf,
SIZE_T  nbyte 
)

Read the I2C device.

This API reads the data bytes from the I2C device

Parameters
[in]fdFile Descriptor of I2C device
[in,out]bufreference to the data to be read
[in]nbytenumber of data bytes to be read
Returns
number of data bytes read on SUCCESS
-1 on FAILURE
Note
This API reads the data bytes from the I2C device. On success, the read data bytes are updated in the reference provided. In case of an error, data bytes are not read from the I2C device. Allowed From Events and tasks Preemption Possible No

Example

INT32 fd;
fd = m2mb_i2c_open("/dev/i2c-1", 0);
if(fd == -1)
app_dbg_printf("ERROR OPENING I2C port\r\n");
bytecnt = m2mb_i2c_read( fd, (void* )P_ReadByte, 1);

◆ m2mb_i2c_write()

SSIZE_T m2mb_i2c_write ( INT32  fd,
const void *  buf,
SIZE_T  nbyte 
)

Write to I2C device.

This API writes the data bytes to the I2C device

Parameters
[in]fdFile Descriptor of the I2C device
[in]bufreference to the data to be written
[in]nbytenumber of data bytes to be write
Returns
number of data bytes written on SUCCESS
-1 on FAILURE
Note
This API writes the data bytes to the I2C device. On success, the data bytes are successfully written to the I2C device. In case of an error, write data bytes to the I2C device has failed. Every API allowed from events and tasks preemption possible No

Example

bytecnt = m2mb_i2c_write( fd, (void* )P_WriteByte, size);