unsigned int ReadRanger(void) { unsigned int range =0; i2c_read_data(ranger_addr, 2, Data, 2); // read two bytes, starting at reg 2 range = (((unsigned int)Data[0] << 8) | Data[1]); //concatenate the two bytes. return range; }
/* Read bytes */ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) { uint offset; int i; debug("i2c_read: chip=0x%x, addr=0x%x, len=0x%x\n", chip, addr, len); if (!i2c_addr_ok(addr, alen)) { debug("i2c_read: Bad address %x.%d.\n", addr, alen); return 1; } for (offset = 0; offset < len; offset++) { if (alen) { uchar data[alen]; for (i = 0; i < alen; i++) { data[alen - i - 1] = (addr + offset) >> (8 * i); } if (i2c_write_data(chip, data, alen)) { debug("i2c_read: error sending (0x%x)\n", addr); return 1; } } if (i2c_read_data(chip, buffer + offset, 1)) { debug("i2c_read: error reading (0x%x)\n", addr); return 1; } } return 0; }
/******************************************************************************* * Function : raysens_ctpm_fw_online * Description : entry online mode and check * Parameters : none * Return : 0: successful ; error: -1 *******************************************************************************/ static int raysens_ctpm_fw_online(struct i2c_client *client) { int i; unsigned char IICBufOnlineR[10]; //由正常工作切换到在线编程模式 i2c_write_bytes(client, Register[18], 1); //进入在线编程的握手指令 i2c_write_bytes(client, Register[0], 10); //4 i2c_read_data(client, IICBufOnlineR, 10); for (i = 0; i < 10; i++) { if (IICBufOnlineR[i] != Register[0][i]) { TS_DBG("ONLINE_HANDLE error! \n"); strcpy(fw_status,"***err: ONLINE_HANDLE error!***\n"); return -1; } TS_DBG("ONLINE_HANDLE ok! \n"); } //开始在线编程的命令 i2c_write_bytes(client, Register[1], 10); //4 TS_DBG("ONLINE_BEGIN data \n"); msleep(20); //判断是否已进入在线编程 i2c_write_bytes(client, Register[2], 3); //i2c_read_interface(I2C_CTPM_ADDRESS, IICBufOnlineR, 10);// i2c_read_data(client, IICBufOnlineR, 4); pr_info("IICBufOnlineR = %x, %x, %x, %x \n", IICBufOnlineR[0], IICBufOnlineR[1], IICBufOnlineR[2], IICBufOnlineR[3]); if ((IICBufOnlineR[0] == Register[3][0]) && (IICBufOnlineR[1] == Register[3][1]) && (IICBufOnlineR[2] == Register[3][2]) && (IICBufOnlineR[3] == Register[3][3])) { //如果读到的数不是 0xab9d573b TS_DBG("ONLINE_BEG_CHECK ok \n"); } else { TS_DBG("ONLINE_BEG_CHECK error \n"); strcpy(fw_status,"***err: ONLINE_BEG_CHECK error!***\n"); return -1; } return 1; }
unsigned int read_ranger() { unsigned char Data[2]; unsigned int range = 0; unsigned char addr = 0xE0; // the address of the ranger is 0xE0 i2c_read_data(addr, 2, Data, 2); // read two bytes, starting at reg 2 range = (((unsigned int)Data[0] << 8) | Data[1]); return range; }
unsigned char read_ranger(void) { unsigned int range = 0; unsigned char slave_reg = 2; //start at register 2 unsigned char num_bytes = 2; //read 2 bytes i2c_read_data(addr, slave_reg, Data, num_bytes); // read two bytes, starting at reg 2 range = (((unsigned int) Data[0] << 8) | Data[1]); // Store high and low bytes of Data in variable range return range; }
unsigned int Read_Compass() { unsigned char addr = 0xC0; // Address the compass heading will be written to unsigned char Data[2]; // Data array to store heading data unsigned int heading; // Variable to store heading data i2c_read_data(addr, 2, Data, 2); // Read data from compass registers, store it in Data buffer heading = (((unsigned int) Data[0] << 8) | Data[1]); //Take high data byte, convert to int, //shift left 8 bits, and copy lower compass byte to first half of int take_heading = 0; return heading; // Return data heading between 0 and 3599 }
int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) { #ifdef SANSA_FUZEV2 bitclr32(&CCU_IO, 1<<12); #endif int ret = i2c_read_data(fm_i2c_bus, address, -1, buf, count); #ifdef SANSA_FUZEV2 bitset32(&CCU_IO, 1<<12); #endif return ret; }
/******************************************************************************* * Function : static RRS_BYTE* CTS12_read_flash(struct i2c_client *client,uint8_t *address, uint8_t *direction, int len,RRS_BYTE* pbt_buf,char type) * Description : read program form flash * Parameters : address : start address direction : +1/-1 len: length pbt_buf: data save in buffer type: para or bin * Return : 0: successful ; error: -1 *******************************************************************************/ static RRS_BYTE* CTS12_read_flash(struct i2c_client *client, uint8_t *address, uint8_t *direction, int len, RRS_BYTE* pbt_buf, char type) { int i; unsigned char IICBufOnlineR[10]; i2c_write_bytes(client, address, 7); TS_DBG("PROG_READ_START ok \n"); #if (defined(CTS13_PARA)|| defined(CTS13_BIN)) if (type == para) { for (i = 0; i < 254; i++) { i2c_write_bytes(client, Register[8], 7); //address -1 } } #endif i2c_write_bytes(client, Register[10], 7); i2c_write_bytes(client, Register[11], 7); for (i = 0; i < len; i++) { i2c_write_bytes(client, Register[12], 7); i2c_read_data(client, IICBufOnlineR, 4); pbt_buf[i * 4 + 0] = IICBufOnlineR[0]; pbt_buf[i * 4 + 1] = IICBufOnlineR[1]; pbt_buf[i * 4 + 2] = IICBufOnlineR[2]; pbt_buf[i * 4 + 3] = IICBufOnlineR[3]; pr_info("i == %d ,IICBufOnlineR = %x, %x, %x, %x \n", i, IICBufOnlineR[0], IICBufOnlineR[1], IICBufOnlineR[2], IICBufOnlineR[3]); i2c_write_bytes(client, direction, 7); } i2c_write_bytes(client, Register[13], 7); i2c_write_bytes(client, Register[14], 7); TS_DBG("PROG_READ_FLSH ok \n"); return pbt_buf; }
unsigned int ReadRanger() { //Reads ranger, returns distance i2c_read_data(range_and_ping_addr, 2, comp_and_range_Data, 2); // read two bytes, starting at reg 2 return (((unsigned int)comp_and_range_Data[0] << 8) | comp_and_range_Data[1]); }//end readRanger
//******************************************************************** //Compas and Ranger read functions //******************************************************************** unsigned int ReadCompass() { //Reads Compass, returns heading i2c_read_data(comp_addr, 2, comp_and_range_Data, 2); //read two byte, starting at reg 2 return (unsigned int)(comp_and_range_Data[0]<<8 | comp_and_range_Data[1]); //combine the two values //the combined integer returned in degrees between 0 and 3599, has units of 1/10 of a degree }//end read compass
int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) { return i2c_read_data(fm_i2c_bus, address, -1, buf, count); }