MiraBox User Guide
–page
24
/
29
/*i2c_led.c*GTI--Globalscaletechnologies.,INC**/
#include <stdio.h>
#include <linux/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <errno.h>
#define I2C_RETRIES 0x0701
#define I2C_TIMEOUT 0x0702
#define I2C_RDWR 0x0707
#define I2C_M_RD 0x0001
#define I2C_M_NOSTART
0x4000
/* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_REV_DIR_ADDR 0x2000
/* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_IGNORE_NAK 0x1000
/* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_NO_RD_ACK
0x0800
/* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_RECV_LEN
0x0400
/* length will be first received byte */
/*********define struct i2c_rdwr_ioctl_data and struct i2c_msg
,
they must be consistent to kernel*******/
struct i2c_msg
{
unsigned short addr;
unsigned short flags;
#define I2C_M_TEN 0x0010
unsigned short len;
unsigned char *buf;
};
struct i2c_rdwr_ioctl_data
{
struct i2c_msg *msgs;
intnmsgs;/* the nmsgs decide the num of start signal*/
};
/***********the main program***********/
int main()
{
intfd,ret;