本文整理汇总了C++中i2c_read_bytes函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_read_bytes函数的具体用法?C++ i2c_read_bytes怎么用?C++ i2c_read_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2c_read_bytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:ramgar,项目名称:CATB15Kernel,代码行数:35,代码来源:gt927_driver.c
示例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;
}
开发者ID:AdamRLukaitis,项目名称:RIOT,代码行数:30,代码来源:si70xx.c
示例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;
}
开发者ID:nobodyweird,项目名称:coreboot,代码行数:33,代码来源:ps8640.c
示例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;
}
开发者ID:CoreTech-Development,项目名称:buildroot-linux-kernel-m3,代码行数:25,代码来源:guitar_update.c
示例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
}
开发者ID:4Fwolf,项目名称:motorola-hawk-kernel-3.4.67,代码行数:28,代码来源:guitar_update.c
示例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;
}
开发者ID:Books305,项目名称:twiz-fw,代码行数:27,代码来源:ak8975a.c
示例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;
}
开发者ID:mefurth,项目名称:Senior-Project,代码行数:33,代码来源:bmp085-driver.c
示例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);
}
开发者ID:A-Paul,项目名称:RIOT,代码行数:26,代码来源:bh1750fvi.c
示例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);
}
开发者ID:kerneltask,项目名称:RIOT,代码行数:30,代码来源:i2c.c
示例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;
}
开发者ID:CoreTech-Development,项目名称:buildroot-linux-kernel-m3,代码行数:29,代码来源:guitar_update.c
示例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);
}
开发者ID:huyparody,项目名称:OT_7047D,代码行数:44,代码来源:gt9xx_driver.c
示例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);
}
开发者ID:AdamRLukaitis,项目名称:RIOT,代码行数:15,代码来源:si70xx.c
示例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;
}
开发者ID:engalex,项目名称:6TiSCH,代码行数:13,代码来源:sht21.c
示例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;
}
开发者ID:engalex,项目名称:6TiSCH,代码行数:13,代码来源:sht21.c
示例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;
}
开发者ID:Astralix,项目名称:rk29_kernel_308,代码行数:50,代码来源:gt818_ts.c
示例16: mpu6050_updateQuaternion
/*
* update quaternion
*/
void mpu6050_updateQuaternion(char address) {
short ax = 0;
short ay = 0;
short az = 0;
short gx = 0;
short gy = 0;
short gz = 0;
double axg = 0;
double ayg = 0;
double azg = 0;
double gxrs = 0;
double gyrs = 0;
double gzrs = 0;
//get raw data
while(1) {
i2c_read_bit(address, MPU6050_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, (unsigned char *)buffer);
if(buffer[0])
break;
delay_us(10);
}
i2c_read_bytes(address, MPU6050_ACCEL_XOUT_H, 14, (unsigned char *)buffer);
ax = (((short)buffer[0]) << 8) | buffer[1];
ay = (((short)buffer[2]) << 8) | buffer[3];
az = (((short)buffer[4]) << 8) | buffer[5];
gx = (((short)buffer[8]) << 8) | buffer[9];
gy = (((short)buffer[10]) << 8) | buffer[11];
gz = (((short)buffer[12]) << 8) | buffer[13];
#if MPU6050_CALIBRATEDACCGYRO == 1
axg = (double)(ax-MPU6050_AXOFFSET)/MPU6050_AXGAIN;
ayg = (double)(ay-MPU6050_AYOFFSET)/MPU6050_AYGAIN;
azg = (double)(az-MPU6050_AZOFFSET)/MPU6050_AZGAIN;
gxrs = (double)(gx-MPU6050_GXOFFSET)/MPU6050_GXGAIN*0.01745329; //degree to radians
gyrs = (double)(gy-MPU6050_GYOFFSET)/MPU6050_GYGAIN*0.01745329; //degree to radians
gzrs = (double)(gz-MPU6050_GZOFFSET)/MPU6050_GZGAIN*0.01745329; //degree to radians
#else
axg = (double)(ax)/MPU6050_AGAIN;
ayg = (double)(ay)/MPU6050_AGAIN;
azg = (double)(az)/MPU6050_AGAIN;
gxrs = (double)(gx)/MPU6050_GGAIN*0.01745329; //degree to radians
gyrs = (double)(gy)/MPU6050_GGAIN*0.01745329; //degree to radians
gzrs = (double)(gz)/MPU6050_GGAIN*0.01745329; //degree to radians
#endif
//compute data
mpu6050_mahonyUpdate(gxrs, gyrs, gzrs, axg, ayg, azg);
}
开发者ID:WilcoBrink,项目名称:MotionSuitTransmitter,代码行数:52,代码来源:mpu6050.c
示例17: i2c_read_regs
int i2c_read_regs(i2c_t dev, uint16_t addr, uint16_t reg,
void *data, size_t len, uint8_t flags)
{
if (flags & (I2C_NOSTOP | I2C_NOSTART)) {
return -EOPNOTSUPP;
}
/* First set ADDR and register with no stop */
int ret = i2c_write_bytes(dev, addr, ®, (flags & I2C_REG16) ? 2 : 1,
flags | I2C_NOSTOP);
if (ret < 0) {
return ret;
}
/* Then get the data from device */
return i2c_read_bytes(dev, addr, data, len, flags);
}
开发者ID:A-Paul,项目名称:RIOT,代码行数:15,代码来源:i2c.c
示例18: mcp23017_read
int mcp23017_read(int bus, uint8_t addr, uint8_t reg, uint8_t *data)
{
uint8_t res_data = 0;
int result = -1;
if (i2c_write_bytes(bus, addr, ®, 1) < 0) {
return -1;
}
if (i2c_read_bytes(bus, addr, &res_data, 1) > 0) {
*data = res_data;
result = 1;
}
return result;
}
开发者ID:skoths,项目名称:spirits_pumps,代码行数:15,代码来源:io_23017.c
示例19: goodix_read_version
static int goodix_read_version(struct gt818_ts_data *ts)
{
int ret;
u8 version_data[5] = {0}; //store touchscreen version infomation
memset(version_data, 0, 5);
version_data[0] = 0x07;
version_data[1] = 0x17;
msleep(2);
ret = i2c_read_bytes(ts->client, version_data, 4);
if (ret < 0)
return ret;
dev_info(&ts->client->dev," Guitar Version: %d.%d\n",version_data[3],version_data[2]);
return 0;
}
开发者ID:Astralix,项目名称:rk29_kernel_308,代码行数:15,代码来源:gt818_ts.c
示例20: cmd_read
int cmd_read(int argc, char **argv)
{
int res;
uint8_t addr;
int length;
char data[BUFSIZE];
if (i2c_dev < 0) {
puts("Error: no I2C device initialized");
return 1;
}
if (argc < 3) {
puts("Error: not enough arguments given");
printf("Usage:\n%s ADDR LENGTH]\n", argv[0]);
return 1;
}
addr = (uint8_t)atoi(argv[1]);
length = atoi(argv[2]);
if (length < 1 || length > BUFSIZE) {
puts("Error: invalid LENGTH parameter given\n");
return 1;
}
else if (length == 1) {
printf("i2c_read_byte(I2C_%i, 0x%02x, char *res)\n", i2c_dev, addr);
res = i2c_read_byte(i2c_dev, addr, data);
}
else {
printf("i2c_read_bytes(I2C_%i, 0x%02x, char *res, %i)\n", i2c_dev, addr, length);
res = i2c_read_bytes(i2c_dev, addr, data, length);
}
if (res < 1) {
puts("Error: no bytes were read");
return 1;
}
else {
printf("I2C_%i: successfully read %i bytes:\n [", i2c_dev, res);
for (int i = 0; i < res; i++) {
printf("0x%02x, ", (unsigned int)data[i]);
}
puts("])");
return 0;
}
}
开发者ID:bumpy-b,项目名称:RIOT,代码行数:46,代码来源:main.c
注:本文中的i2c_read_bytes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论