int gpio_i2c_readX_KeyPad_Fix( int Grp, unsigned char Dev, void (*Func[2])(void)) { int rxdata; I2C_LOCK(Grp); if(Func[0]) { (*Func[0])(); } i2c_start_bit(Grp); i2c_send_byte(Grp, (unsigned char)(Dev) | 1); i2c_receive_ack(Grp); rxdata = i2c_receive_byte(Grp); i2c_receive_ack(Grp); i2c_stop_bit(Grp); if(Func[1]) { (*Func[1])(); } I2C_UNLOCK(Grp); return (unsigned char)rxdata; }
int gpio_i2c_readX(int Grp, unsigned char devaddress, unsigned char address) { int rxdata; I2C_LOCK(Grp); i2c_start_bit(Grp); i2c_send_byte(Grp, (unsigned char)(devaddress)); i2c_receive_ack(Grp); i2c_send_byte(Grp, address); i2c_receive_ack(Grp); i2c_start_bit(Grp); i2c_send_byte(Grp, (unsigned char)(devaddress) | 1); i2c_receive_ack(Grp); rxdata = i2c_receive_byte(Grp); i2c_stop_bit(Grp); I2C_UNLOCK(Grp); return (unsigned char)rxdata; }
int gpio_i2c_wr_arr(int Grp, unsigned char dev, unsigned char rarr[], int rsize, unsigned char darr[], int dsize) { int i; I2C_LOCK(Grp); i2c_start_bit(Grp); i2c_send_byte(Grp, dev); i2c_receive_ack(Grp); for(i = 0; i < rsize; i ++) { i2c_send_byte(Grp, rarr[i]); i2c_receive_ack(Grp); } if(dsize > 0) { for(i = 0; i < dsize-1; i ++) { i2c_send_byte(Grp, darr[i]); i2c_receive_ack(Grp); } i2c_send_byte(Grp, darr[i]); } i2c_stop_bit(Grp); I2C_UNLOCK(Grp); return 0; }
void gpio_i2c_write(unsigned char devaddress, unsigned char address, unsigned char data) { i2c_start_bit(); i2c_send_byte((unsigned char)(devaddress)); i2c_receive_ack(); i2c_send_byte(address); i2c_receive_ack(); i2c_send_byte(data); // i2c_receive_ack();//add by hyping for tw2815 i2c_stop_bit(); }
int gpio_i2c_probeX(int Grp, unsigned char devaddress) { int ret; I2C_LOCK(Grp); i2c_start_bit(Grp); i2c_send_byte(Grp, (unsigned char)(devaddress)); ret = i2c_receive_ack(Grp); i2c_stop_bit(Grp); I2C_UNLOCK(Grp); return ret; }
int gpio_i2c_write(unsigned char devaddress, unsigned char address, unsigned char data) { int Grp = 0; I2C_LOCK(Grp); i2c_start_bit(Grp); i2c_send_byte(Grp, (unsigned char)(devaddress)); i2c_receive_ack(Grp); i2c_send_byte(Grp, address); i2c_receive_ack(Grp); i2c_send_byte(Grp, data); i2c_stop_bit(Grp); I2C_UNLOCK(Grp); return 0 ; }
unsigned char gpio_i2c_read(unsigned char devaddress, unsigned char address) { int rxdata; i2c_start_bit(); i2c_send_byte((unsigned char)(devaddress)); i2c_receive_ack(); i2c_send_byte(address); i2c_receive_ack(); i2c_start_bit(); i2c_send_byte((unsigned char)(devaddress) | 1); i2c_receive_ack(); rxdata = i2c_receive_byte(); //i2c_send_ack(); i2c_stop_bit(); return rxdata; }
int gpio_i2c_writeX_KeyPad_Fix( int Grp, unsigned char Dev, unsigned char rarr[], int rsize, unsigned char darr[], int dsize, void (*Func[2])(void)) { int i; I2C_LOCK(Grp); if(Func[0]) { (*Func[0])(); } i2c_start_bit(Grp); i2c_send_byte(Grp, Dev); i2c_receive_ack(Grp); for(i = 0; i < rsize; i ++) { i2c_send_byte(Grp, rarr[i]); i2c_receive_ack(Grp); } for(i = 0; i < dsize; i ++) { i2c_send_byte(Grp, darr[i]); i2c_receive_ack(Grp); } i2c_stop_bit(Grp); if(Func[1]) { (*Func[1])(); } I2C_UNLOCK(Grp); return 0; }