本文整理汇总了C++中i2c_read_bytes函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_read_bytes函数的具体用法?C++ i2c_read_bytes怎么用?C++ i2c_read_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2c_read_bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gt927_config_read_proc
static int gt927_config_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
{
char *ptr = page;
char temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0};
int i;
ptr += sprintf(ptr, "==== GT927 config init value====\n");
for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
{
ptr += sprintf(ptr, "0x%02X ", config[i + 2]);
if (i % 8 == 7)
ptr += sprintf(ptr, "\n");
}
ptr += sprintf(ptr, "\n");
ptr += sprintf(ptr, "==== GT927 config real value====\n");
i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, temp_data, GTP_CONFIG_MAX_LENGTH);
for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
{
ptr += sprintf(ptr, "0x%02X ", temp_data[i]);
if (i % 8 == 7)
ptr += sprintf(ptr, "\n");
}
i2c_read_bytes(i2c_client_point, GTP_REG_VERSION, temp_data, 6);
ptr += sprintf(ptr, "PID: %c%c%c%c VID: 0x%02X%02X\n", temp_data[0],temp_data[1],temp_data[2],temp_data[3],temp_data[5],temp_data[4]);
*eof = 1;
return (ptr - page);
}
示例2: si70xx_get_serial
uint64_t si70xx_get_serial(si70xx_t *dev)
{
uint8_t out[2];
uint8_t in_first[8] = { 0 };
uint8_t in_second[8] = { 0 };
/* read the lower bytes */
out[0] = SI70XX_READ_ID_FIRST_A;
out[1] = SI70XX_READ_ID_FIRST_B;
i2c_acquire(dev->i2c_dev);
i2c_write_bytes(dev->i2c_dev, dev->address, (char *) out, 2);
i2c_read_bytes(dev->i2c_dev, dev->address, (char *) in_first, 8);
/* read the higher bytes */
out[0] = SI70XX_READ_ID_SECOND_A;
out[1] = SI70XX_READ_ID_SECOND_B;
i2c_write_bytes(dev->i2c_dev, dev->address, (char *) out, 2);
i2c_read_bytes(dev->i2c_dev, dev->address, (char *) in_second, 8);
i2c_release(dev->i2c_dev);
/* calculate the ID */
uint32_t id_first = ((uint32_t)in_first[0] << 24) + ((uint32_t)in_first[2] << 16) +
(in_first[4] << 8) + (in_first[6] << 0);
uint32_t id_second = ((uint32_t)in_second[0] << 24) + ((uint32_t)in_second[2] << 16) +
(in_second[4] << 8) + (in_second[6] << 0);
return (((uint64_t) id_first) << 32) + id_second;
}
示例3: ps8640_get_edid
int ps8640_get_edid(uint8_t bus, uint8_t chip, struct edid *out)
{
int ret;
u8 edid[EDID_LENGTH * 2];
u32 edid_size;
i2c_writeb(bus, chip + 2, PAGE2_I2C_BYPASS,
EDID_I2C_ADDR | I2C_BYPASS_EN);
ret = i2c_read_bytes(bus, EDID_I2C_ADDR, 0, edid, EDID_LENGTH);
if (ret != 0) {
printk(BIOS_INFO, "Failed to read EDID.\n");
return -1;
}
/* check if edid have extension flag, and read additional EDID data */
if (edid[EDID_EXTENSION_FLAG]) {
edid_size += EDID_LENGTH;
ret = i2c_read_bytes(bus, EDID_I2C_ADDR, EDID_LENGTH,
&edid[EDID_LENGTH], EDID_LENGTH);
if (ret != 0) {
printk(BIOS_INFO, "Failed to read EDID ext block.\n");
return -1;
}
}
if (decode_edid(edid, edid_size, out)) {
printk(BIOS_INFO, "Failed to decode EDID.\n");
return -1;
}
return 0;
}
示例4: guitar_nvram_recall
static u8 guitar_nvram_recall( struct goodix_ts_data *ts )
{
int ret;
u8 inbuf[3] = {REG_NVRCS_H,REG_NVRCS_L,0};
ret = i2c_read_bytes( ts->client, inbuf, 3 );
if ( ret < 0 )
{
return fail;
}
if ( ( inbuf[2]&BIT_NVRAM_LOCK) == BIT_NVRAM_LOCK )
{
return fail;
}
inbuf[2] = ( 1 << BIT_NVRAM_RECALL ); //recall command
ret = i2c_write_bytes( ts->client , inbuf, 3);
if (ret <= 0)
{
return fail;
}
return success;
}
示例5: gt_i2c_read_bytes
static int gt_i2c_read_bytes(struct i2c_client *client, uint8_t *buf, int len)
{
if (i2c_read_bytes(client, buf[0] << 8 | buf[1], &buf[2], len - ADDR_LENGTH))
{
return -1;
}
return 2;
#if 0
struct i2c_msg msgs[2];
int ret=-1;
//дַ
msgs[0].flags=!I2C_M_RD; //дϢ
msgs[0].addr=client->addr;
msgs[0].len=2;
msgs[0].buf=&buf[0];
//
msgs[1].flags=I2C_M_RD;//Ϣ
msgs[1].addr=client->addr;
msgs[1].len=len-2;
msgs[1].buf=&buf[2];
ret=i2c_transfer(client->adapter,msgs, 2);
return ret;
#endif
}
示例6: ak8975a_read_raw_data
void ak8975a_read_raw_data(int16_t *val)
{
start:
// Launch the first acquisition
i2c_write_byte(AK8975A_ADDRESS, AK8975A_CNTL, 0x01);
//nrf_delay_ms(1);
// Wait for a data to become available
while ((i2c_read_byte(AK8975A_ADDRESS, AK8975A_ST1) & 0x01) == 0);
// If there is no overflow
if((i2c_read_byte(AK8975A_ADDRESS, AK8975A_ST2) & 0x0C)==0) {
int16_t v[3];
// Read the six raw data registers sequentially into data array
// WARNING : code valid for little endian only !
i2c_read_bytes(AK8975A_ADDRESS, AK8975A_XOUT_L, 6, (uint8_t *)v);
// WARNING, magnetometer axis are not the same as the accel / gyro ones
// Thus : x <--> y, and z <--> -z
val[0] = v[1];
val[1] = v[0];
val[2] = -v[2];
return;
}
goto start;
}
示例7: bmp085_read_calibration_data
int8_t bmp085_read_calibration_data(uint8_t *cdata) {
uint8_t data[] = {BMP085_ADDRESS_WRITE, BMP085_REG_CAL_START};
/* Set I2C driver to normal mode */
if(i2c_set_mode(I2C_MODE_NORMAL) != I2C_OK) {
return BMP085_ERROR_MODE_CHANGE;
}
/* Write module address, control register address and control register data */
if(i2c_write_bytes(data, 2, true, false) != I2C_OK) {
return BMP085_ERROR_I2C;
}
/* Send read */
data[0] = BMP085_ADDRESS_READ;
if(i2c_write_bytes(data, 1, true, false) != I2C_OK) {
return BMP085_ERROR_I2C;
}
/* Read 22 bytes */
if(i2c_read_bytes(cdata, 22, false, true) != I2C_OK) {
return BMP085_ERROR_I2C;
}
/* Swap endianess to make correct values */
for(data[0] = 0; data[0] < 11; data[0]++) {
data[1] = cdata[data[0] * 2 + 1];
cdata[data[0] * 2 + 1] = cdata[data[0] * 2];
cdata[data[0] * 2] = data[1];
}
return BMP085_OK;
}
示例8: bh1750fvi_sample
uint16_t bh1750fvi_sample(const bh1750fvi_t *dev)
{
uint32_t tmp;
uint8_t raw[2];
/* power on the device and send single H-mode measurement command */
DEBUG("[bh1750fvi] sample: triggering a conversion\n");
i2c_acquire(dev->i2c);
i2c_write_byte(dev->i2c, dev->addr, OP_POWER_ON, 0);
i2c_write_byte(dev->i2c, dev->addr, OP_SINGLE_HRES1, 0);
i2c_release(dev->i2c);
/* wait for measurement to complete */
xtimer_usleep(DELAY_HMODE);
/* read the results */
DEBUG("[bh1750fvi] sample: reading the results\n");
i2c_acquire(dev->i2c);
i2c_read_bytes(dev->i2c, dev->addr, raw, 2, 0);
i2c_release(dev->i2c);
/* and finally we calculate the actual LUX value */
tmp = ((uint32_t)raw[0] << 24) | ((uint32_t)raw[1] << 16);
tmp /= RES_DIV;
return (uint16_t)(tmp);
}
示例9: i2c_read_regs
int i2c_read_regs(i2c_t dev, uint8_t address, uint8_t reg, void *data, int length)
{
I2C_TypeDef *i2c;
switch (dev) {
#if I2C_0_EN
case I2C_0:
i2c = I2C_0_DEV;
break;
#endif
#if I2C_1_EN
case I2C_1:
i2c = I2C_1_DEV;
break;
#endif
default:
return -1;
}
/* send start condition and slave address */
DEBUG("Send slave address and clear ADDR flag\n");
_start(i2c, address, I2C_FLAG_WRITE);
_clear_addr(i2c);
DEBUG("Write reg into DR\n");
i2c->DR = reg;
_stop(i2c);
DEBUG("Now start a read transaction\n");
return i2c_read_bytes(dev, address, data, length);
}
示例10: guitar_nvram_store
static u8 guitar_nvram_store( struct goodix_ts_data *ts )
{
int ret;
int i;
u8 inbuf[3] = {REG_NVRCS_H,REG_NVRCS_L, 0x18};
ret = i2c_read_bytes(ts->client, inbuf, 3);
if ( ret < 0 )
{
return fail;
}
if ((inbuf[2] & BIT_NVRAM_LOCK ) == BIT_NVRAM_LOCK)
{
return fail;
}
inbuf[2] = 0x18;
inbuf[2] |= (1<<BIT_NVRAM_STROE); //store command
for ( i = 0 ; i < 300 ; i++ )
{
ret = i2c_write_bytes( ts->client, inbuf, 3 );
if ( ret > 0 )
return success;
}
return fail;
}
示例11: gt91xx_config_read_proc
static int gt91xx_config_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
{
char *ptr = page;
char temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0};
int i;
ptr += sprintf(ptr, "==== GT9XX config init value====\n");
for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
{
ptr += sprintf(ptr, "0x%02X ", config[i + 2]);
if (i % 8 == 7)
ptr += sprintf(ptr, "\n");
}
ptr += sprintf(ptr, "\n");
ptr += sprintf(ptr, "==== GT9XX config real value====\n");
i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, temp_data, GTP_CONFIG_MAX_LENGTH);
for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
{
ptr += sprintf(ptr, "0x%02X ", temp_data[i]);
if (i % 8 == 7)
ptr += sprintf(ptr, "\n");
}
/* Touch PID & VID */
ptr += sprintf(ptr, "\n");
ptr += sprintf(ptr, "==== GT9XX Version ID ====\n");
i2c_read_bytes(i2c_client_point, GTP_REG_VERSION, temp_data, 6);
ptr += sprintf(ptr, "PID: %c%c%c VID: 0x%02X%02X\n", temp_data[0], temp_data[1], temp_data[2], temp_data[5], temp_data[4]);
/* Touch Status and Clock Gate */
ptr += sprintf(ptr, "\n");
ptr += sprintf(ptr, "==== Touch Status and Clock Gate ====\n");
ptr += sprintf(ptr, "status: 1: on, 0 :off\n");
ptr += sprintf(ptr, "status:%d\n", (tpd_halt+1)&0x1);
*eof = 1;
return (ptr - page);
}
示例12: si70xx_measure
/**
* @brief Utility method to perform and reconstruct a measurement.
*/
static uint32_t si70xx_measure(si70xx_t *dev, uint8_t command)
{
uint8_t result[2];
i2c_acquire(dev->i2c_dev);
i2c_write_byte(dev->i2c_dev, dev->address, command);
i2c_read_bytes(dev->i2c_dev, dev->address, (char *) result, 2);
i2c_release(dev->i2c_dev);
/* reconstruct raw result */
return ((uint32_t)result[0] << 8) + (result[1] & 0xfc);
}
示例13: sht21_read_temperature
uint16_t sht21_read_temperature(void)
{
uint8_t sht21_temperature[2];
uint16_t temperature;
// Read the current temperature according to the datasheet (pag. 8, fig. 15)
i2c_write_byte(SHT21_ADDRESS, SHT21_TEMPERATURE_HM_CMD);
i2c_read_bytes(SHT21_ADDRESS, sht21_temperature, sizeof(sht21_temperature));
temperature = (sht21_temperature[1] << 8) | sht21_temperature[0];
return temperature;
}
示例14: sht21_read_humidity
uint16_t sht21_read_humidity(void)
{
uint8_t sht21_humidity[2];
uint16_t humidity;
// Read the current humidity according to the datasheet (pag. 8, fig. 15)
i2c_write_byte(SHT21_ADDRESS, SHT21_HUMIDITY_HM_CMD);
i2c_read_bytes(SHT21_ADDRESS, sht21_humidity, sizeof(sht21_humidity));
humidity = (sht21_humidity[1] << 8) | sht21_humidity[0];
return humidity;
}
示例15: goodix_init_panel
static int goodix_init_panel(struct gt818_ts_data *ts)
{
int ret = -1;
int i = 0;
#if 1
u8 config_info[] = {
0x06,0xA2,
0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,
0x10,0x12,0x00,0x00,0x10,0x00,0x20,0x00,
0x30,0x00,0x40,0x00,0x50,0x00,0x60,0x00,
0xE0,0x00,0xD0,0x00,0xC0,0x00,0xB0,0x00,
0xA0,0x00,0x90,0x00,0x80,0x00,0x70,0x00,
0xF0,0x00,0x13,0x13,0x90,0x90,0x90,0x27,
0x27,0x27,0x0F,0x0E,0x0A,0x40,0x30,0x01,
0x03,0x00,MAX_FINGER_NUM,0x00,0x14,0xFA,0x1B,0x00,
0x00,0x66,0x5A,0x6A,0x5E,0x00,0x00,0x05,
0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x14,0x10,0xEF,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0x20,0x40,0x70,0x90,0x0F,0x40,
0x30,0x3C,0x28,0x00,0x00,0x00,0x00,0x00,
0x00,0x01
};
#endif
u8 read_config_info[sizeof(config_info)] = {0};
read_config_info[0] = 0x06;
read_config_info[1] = 0xa2;
ret = i2c_write_bytes(ts->client, config_info, (sizeof(config_info)/sizeof(config_info[0])));
if (ret < 0) {
printk("config gt818 fail\n");
return ret;
}
ret = i2c_read_bytes(ts->client, read_config_info, (sizeof(config_info)/sizeof(config_info[0])));
if (ret < 0){
printk("read gt818 config fail\n");
return ret;
}
for(i = 2; i < 106; i++){
if(read_config_info[i] != config_info[i]){
printk("write gt818 config error\n");
ret = -1;
return ret;
}
}
msleep(10);
return 0;
}