本文整理汇总了C++中i2c_write_bytes函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_write_bytes函数的具体用法?C++ i2c_write_bytes怎么用?C++ i2c_write_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2c_write_bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: i2c_write_regs
int i2c_write_regs(i2c_t dev, uint16_t addr, uint16_t reg,
const 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 write data to the device */
return i2c_write_bytes(dev, addr, data, len, flags | I2C_NOSTART);
}
示例4: gt_i2c_write_bytes
/*Function as i2c_master_send */
static int gt_i2c_write_bytes(struct i2c_client *client,uint8_t *buf,int len)
{
int ret = 1;
if (len <= ADDR_LENGTH)
{
if (i2c_enable_commands(client, buf[0] << 8 | buf[1]))
{
ret = -1;
}
}
else
{
if (i2c_write_bytes(client, buf[0] << 8 | buf[1], &buf[2], len - ADDR_LENGTH))
{
ret = -1;
}
}
return ret;
#if 0
struct i2c_msg msg;
int ret=-1;
//豸ַ
msg.flags=!I2C_M_RD;//дϢ
msg.addr=client->addr;
msg.len=len;
msg.buf=data;
ret=i2c_transfer(client->adapter,&msg, 1);
return ret;
#endif
}
示例5: adxl346_init
void adxl346_init(void) {
uint8_t config[2];
config[0] = ADXL346_BW_RATE_ADDR;
config[1] = (ADXL346_BW_RATE_RATE(11));
i2c_write_bytes(ADXL346_ADDRESS, config, sizeof(config));
config[0] = ADXL346_DATA_FORMAT_ADDR;
config[1] = (ADXL346_DATA_FORMAT_FULL_RES |
ADXL346_DATA_FORMAT_RANGE_PM_16g);
i2c_write_bytes(ADXL346_ADDRESS, config, sizeof(config));
config[0] = ADXL346_POWER_CTL_ADDR;
config[1] = ADXL346_POWER_CTL_MEASURE;
i2c_write_bytes(ADXL346_ADDRESS, config, sizeof(config));
}
示例6: 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;
}
示例7: goodix_ts_power
static int goodix_ts_power(struct gt818_ts_data * ts, int on)
{
int ret = -1;
struct gt818_platform_data *pdata = ts->client->dev.platform_data;
unsigned char i2c_control_buf[3] = {0x06,0x92,0x01}; //suspend cmd
if(ts != NULL && !ts->use_irq)
return -2;
switch(on)
{
case 0:
i2c_pre_cmd(ts);
// set the io port high level to avoid level change which might stop gt818 from sleeping
gpio_direction_output(pdata->gpio_reset, 1);
gpio_direction_output(pdata->gpio_pendown, 1);
msleep(5);
ret = i2c_write_bytes(ts->client, i2c_control_buf, 3);
if(ret < 0)
{
printk(KERN_INFO"**gt818 suspend fail**\n");
}
else
{
//printk(KERN_INFO"**gt818 suspend**\n");
ret = 0;
}
// i2c_end_cmd(ts);
return ret;
case 1:
gpio_pull_updown(pdata->gpio_pendown, 1);
gpio_direction_output(pdata->gpio_pendown, 0);
msleep(1);
gpio_direction_output(pdata->gpio_pendown, 1);
msleep(1);
gpio_direction_input(pdata->gpio_pendown);
gpio_pull_updown(pdata->gpio_pendown, 0);
/*
msleep(2);
gpio_pull_updown(pdata->gpio_reset, 1);
gpio_direction_output(pdata->gpio_reset, 0);
msleep(2);
gpio_direction_input(pdata->gpio_reset);
gpio_pull_updown(pdata->gpio_reset, 0);
msleep(30);
*/
msleep(1);
ret = i2c_pre_cmd(ts);
//printk(KERN_INFO"**gt818 reusme**\n");
ret = i2c_end_cmd(ts);
return ret;
default:
printk(KERN_DEBUG "%s: Cant't support this command.", gt818_ts_name);
return -EINVAL;
}
}
示例8: tpd_enable_ps
static s32 tpd_enable_ps(s32 enable)
{
u8 state;
s32 ret = -1;
// u8 buffer[3] = {0x80,0x42};
mutex_lock(&i2c_access);
if (enable)
{
// buffer[2] = 1;
state = 1;
tpd_proximity_flag = 1;
GTP_INFO("TPD proximity function to be on.");
}
else
{
// buffer[2] = 0;
state = 0;
//tpd_proximity_detect = 1;
tpd_proximity_flag = 0;
GTP_INFO("TPD proximity function to be off.");
}
ret = i2c_write_bytes(i2c_client_point, TPD_PROXIMITY_ENABLE_REG, &state, 1);
//ret = gtp_i2c_write(i2c_client_point, buffer, sizeof(buffer));
mutex_unlock(&i2c_access);
if (ret < 0)
{
GTP_ERROR("TPD %s proximity cmd failed.", state ? "enable" : "disable");
//GTP_ERROR("TPD %s proximity cmd failed.", buffer[2] ? "enable" : "disable");
return ret;
}
GTP_INFO("TPD proximity function %s success.", state ? "enable" : "disable");
//GTP_INFO("TPD proximity function %s success.", buffer[2] ? "enable" : "disable");
return 0;
}
示例9: u8x8_byte_riotos_hw_i2c
uint8_t u8x8_byte_riotos_hw_i2c(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
static uint8_t buffer[255];
static uint8_t index;
i2c_t dev = (i2c_t) u8g2->dev;
switch (msg) {
case U8X8_MSG_BYTE_SEND:
memcpy(&buffer[index], arg_ptr, arg_int);
index += arg_int;
break;
case U8X8_MSG_BYTE_INIT:
i2c_init_master(dev, I2C_SPEED_FAST);
break;
case U8X8_MSG_BYTE_SET_DC:
break;
case U8X8_MSG_BYTE_START_TRANSFER:
i2c_acquire(dev);
index = 0;
break;
case U8X8_MSG_BYTE_END_TRANSFER:
i2c_write_bytes(dev, u8x8_GetI2CAddress(u8g2), buffer, index);
i2c_release(dev);
break;
default:
return 0;
}
return 1;
}
示例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: tpd_enable_ps
static s32 tpd_enable_ps(s32 enable)
{
u8 state;
s32 ret = -1;
if (enable)
{
state = 1;
tpd_proximity_flag = 1;
GTP_INFO("TPD proximity function to be on.");
}
else
{
state = 0;
tpd_proximity_flag = 0;
GTP_INFO("TPD proximity function to be off.");
}
ret = i2c_write_bytes(i2c_client_point, TPD_PROXIMITY_ENABLE_REG, &state, 1);
if (ret < 0)
{
GTP_ERROR("TPD %s proximity cmd failed.", state ? "enable" : "disable");
return ret;
}
GTP_INFO("TPD proximity function %s success.", state ? "enable" : "disable");
return 0;
}
示例12: clear_mix_flag
static u8 clear_mix_flag(struct goodix_ts_data *ts)
{
s32 i = 0;
u8 buf[3];
buf[0] = 0x14;
buf[1] = 0x00;
buf[2] = 0x80;
for (i = 0; i < 5; i++)
{
if (i2c_write_bytes(ts->client, buf, 3) > 0)
{
break;
}
}
i2c_end_cmd(ts);
if (i >= 5)
{
DEBUG_UPDATE("Clear mix flag failed!\n");
return fail;
}
return success;
}
示例13: i2c_end_cmd
/*******************************************************
功能:
发送后缀命令
ts: client私有数据结构体
return:
执行结果码,0表示正常执行
*******************************************************/
static int i2c_end_cmd(struct goodix_ts_data *ts)
{
int ret;
u8 end_cmd_data[2]={0x80, 0x00};
ret=i2c_write_bytes(ts->client,end_cmd_data,2);
return ret;//*/
}
示例14: raysens_ctpm_fw_online
/*******************************************************************************
* 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;
}
示例15: i2c_end_cmd
static int i2c_end_cmd(struct gt818_ts_data *ts)
{
int ret;
u8 end_cmd_data[2] = {0};
end_cmd_data[0] = 0x80;
end_cmd_data[1] = 0x00;
ret = i2c_write_bytes(ts->client,end_cmd_data,2);
udelay(20);
return ret;
}