inti2c_master_recv (struct i2c_client *client, char *buf, int count)
int i2c_master_recv (struct i2c_client *client, char *buf, int count)//reads data from the chip and deposits it in BUF {
struct I2c_adapter *adap=client->adapter;//Obtain the adapter structure of the device
struct I2C_MSG msg;//obtains a structure for reading and writing data, as detailed below
int ret;
MSG.ADDR = client->addr;//Read the chip address from the client
Msg.flags = client->flags & i2c_m_ten;//This is a temporary unknown.
Msg.flags |= i2c_m_rd;
Msg.len = count;//Maximum number of bytes written
Msg.buf = buf;//Read or write buf
ret = I2c_transfer (ADAP, &msg, 1);//Call Function Pass data
/* If everything went ok (i.e 1 MSG transmitted), return #bytes
Transmitted, else error code. */
return (ret = 1)? count:ret;//see if it's done.
}
Export_symbol (I2C_MASTER_RECV);//Export symbol
Name
struct I2c_msg-an I2C transaction segment beginning with START Synopsis
struct I2c_msg {
__u16 addr;
__U16 flags;
#define I2c_m_ten 0x0010
#define I2C_M_RD 0x0001
#define I2c_m_nostart 0x4000
#define I2C _M_REV_DIR_ADDR 0x2000
#define I2C_M_IGNORE_NAK 0x1000
#define I2c_m_no_rd_ack 0x0800
#define I2c_m_recv_len 0x0400
__u16 LEN;
__U8 * BUF;
};
MembersAddr
Slave address, either seven or ten bits. When it is a ten bit address, I2c_m_ten must are set in flags and the adapter must support. Flags
I2C_M_RD is handled by all adapters. No Other flags may be provided unless the adapter exported the relevant i2c_func_* flags through i2c_check_functionality. Len
Number of data bytes in buf being "read from or written to" I2C address. For read transactions where I2c_m_recv_len are set, the caller guarantees that this buffer can hold up to bytes in Addit Ion to the initial length byte sent by the slave (plus, if used, the SMBus PEC); And this value is incremented by the number of block data bytes received. Buf
The buffer into which data are read, or from which it's written. Description
An i2c_msg are the low level representation of one segment of I2C transaction. It is visible to drivers in the i2c_transfer () procedure, to userspace from I2c-dev, and to I2C adapter drivers-through th E I2c_adapter.master_xfer () method.
Except when I2C "protocol mangling" are used, all I2C adapters implement the Standard Rules for I2C transactions. Each transaction begins with a START. That's followed by the slave address, and a bit encoding read versus write. Then follow all of the data bytes, possibly including a byte with SMBus PEC. The transfer terminates with a NAK, or as all those bytes have been transferred and acked. If This is the last message in a group, it's followed by a STOP. Otherwise it is followed to the next i2c_msg transaction segment, beginning with a (repeated) START.
Alternatively, then the adapter supports i2c_func_protocol_mangling then passing certain flags may have changed those Stan DARD protocol behaviors. Those flags are only for use with broken/nonconforming slaves, and with adapters which are known to support the specific m Angling options They need (one or more of Ignore_nak, No_rd_ack, Nostart, and REV_DIR_ADDR).