当前位置: 首页>>代码示例>>C++>>正文


C++ i2c_smbus_write_i2c_block_data函数代码示例

本文整理汇总了C++中i2c_smbus_write_i2c_block_data函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_smbus_write_i2c_block_data函数的具体用法?C++ i2c_smbus_write_i2c_block_data怎么用?C++ i2c_smbus_write_i2c_block_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了i2c_smbus_write_i2c_block_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lp5521_load_program

static int lp5521_load_program(struct lp5521_chip *chip, u8 *pattern)
{
	struct i2c_client *client = chip->client;
	int ret = 0;

	/* Enter load program mode for all led channels */
	ret |= lp5521_write(client, LP5521_REG_OP_MODE, 0x15); /* 0001 0101 */
	if (ret)
		return ret;

	if (chip->red)
		ret |= i2c_smbus_write_i2c_block_data(client,
						      LP5521_REG_R_PROG_MEM,
						      LP5521_PROGRAM_LENGTH,
						      pattern);
	if (chip->green)
		ret |= i2c_smbus_write_i2c_block_data(client,
						      LP5521_REG_G_PROG_MEM,
						      LP5521_PROGRAM_LENGTH,
						      pattern);
	if (chip->blue)
		ret |= i2c_smbus_write_i2c_block_data(client,
						      LP5521_REG_B_PROG_MEM,
						      LP5521_PROGRAM_LENGTH,
						      pattern);

	return ret;
}
开发者ID:embest-tech,项目名称:rowboat-kernel,代码行数:28,代码来源:lp5521.c

示例2: bcmpmu_i2c_write_device_direct_bulk

static int bcmpmu_i2c_write_device_direct_bulk(struct bcmpmu *bcmpmu, int map, int addr, unsigned int *val, int len)
{
	int err;
	struct bcmpmu_i2c *acc = (struct bcmpmu_i2c *)bcmpmu->accinfo;
	u8 *uval = (u8 *)val;
	int i;

	if (addr + len > acc->pagesize) return -ENODEV;

	for (i = 0; i < len; i++)
		uval[i] = (u8)val[i];


	bcmpmu_i2c_lock(acc);
	err = bcmpmu_i2c_retry(bcmpmu);
	if (err < 0)
		goto err;

	if (map == 0)
		err = i2c_smbus_write_i2c_block_data(acc->i2c_client, addr, len, uval);
	else if (map == 1)
		err = i2c_smbus_write_i2c_block_data(acc->i2c_client1, addr, len, uval);
	else err = -EIO;
	last_i2c_trans = I2C_TRANS_WRITE;
	bcmpmu_i2c_unlock(acc);
err:
	if (err < 0) return err;
	return 0;
}
开发者ID:emreharbutoglu,项目名称:i9105Sammy,代码行数:29,代码来源:bcmpmu-i2c.c

示例3: bq27541_authenticate

static bool bq27541_authenticate(struct i2c_client *client)
{
#ifdef CONFIG_MACH_FIND7OP
    return true;
#else
    char recv_buf[MESSAGE_LEN]= {0x0};
    char send_buf[MESSAGE_LEN]= {0x0};
    char result[MESSAGE_LEN]= {0x0};
    char Key[KEY_LEN]= {0x77,0x30,0xa1,0x28,0x0a,0xa1,0x13,0x20,0xef,0xcd,0xab,0x89,0x67,0x45,0x23,0x01};
    char checksum_buf[1] = {0x0};
    char authen_cmd_buf[1] = {0x00};
    int i,rc;
    pr_info("%s Enter\n",__func__);

    // step 0: produce 20 bytes random data and checksum
    get_random_bytes(send_buf,20);
    for(i = 0; i < 20; i++) {
        checksum_buf[0] = checksum_buf[0] + send_buf[i];
    }
    checksum_buf[0] = 0xff - (checksum_buf[0]&0xff);

    /* step 1: unseal mode->write 0x01 to blockdatactrl
    authen_cmd_buf[0] = 0x01;
    rc = i2c_smbus_write_i2c_block_data(client,BLOCKDATACTRL,1,&authen_cmd_buf[0]);
    }	*/

    // step 1: seal mode->write 0x00 to dataflashblock
    rc = i2c_smbus_write_i2c_block_data(client,DATAFLASHBLOCK,1,&authen_cmd_buf[0]);
    if( rc < 0 ) {
        pr_info("%s i2c write error\n",__func__);
        return false;
    }
    // step 2: write 20 bytes to authendata_reg
    i2c_smbus_write_i2c_block_data(client,AUTHENDATA,MESSAGE_LEN,&send_buf[0]);
    msleep(1);
    // step 3: write checksum to authenchecksum_reg for compute
    i2c_smbus_write_i2c_block_data(client,AUTHENCHECKSUM,1,&checksum_buf[0]);
    msleep(50);
    // step 4: read authendata
    i2c_smbus_read_i2c_block_data(client,AUTHENDATA,MESSAGE_LEN,&recv_buf[0]);
    // step 5: phone do hmac(sha1-generic) algorithm
    BQ27541_HMACSHA1_authenticate(send_buf,Key,result);
    // step 6: compare recv_buf from bq27541 and result by phone
    rc = strncmp(recv_buf,result,MESSAGE_LEN);
    if(rc == 0) {
        pr_info("bq27541_authenticate success\n");
        return true;
    }
    pr_info("bq27541_authenticate error,dump buf:\n");
    for(i = 0; i < 20; i++) {
        pr_info("send_buf[%d]:0x%x,recv_buf[%d]:0x%x ?= result[%d]:0x%x\n",i,send_buf[i],i,recv_buf[i],i,result[i]);
    }
    return false;
#endif
}
开发者ID:laperry1,项目名称:cm_kernel_oneplus_msm8974,代码行数:55,代码来源:bq27541_fuelgauger.c

示例4: pic16f_fw_write

static int pic16f_fw_write(unsigned char *data_buf,unsigned int offset,unsigned int length)
{
	unsigned int count = 0;
	unsigned char zero_buf[1] = {0};
	unsigned char temp_buf[1] = {0};
	unsigned char addr_buf[2] = {0x00,0x00};
	unsigned char temp;
	int i,rc;

	count = offset;
	//write data begin
	while(count < (offset + length))
	{
		addr_buf[0] = data_buf[count + 1];
		addr_buf[1] = data_buf[count];
		//printk("%s write data addr_buf[0]:0x%x,addr_buf[1]:0x%x\n",__func__,addr_buf[0],addr_buf[1]);
		rc = i2c_smbus_write_i2c_block_data(pic16F_client,0x01,2,&addr_buf[0]);
		if(rc < 0){
			pr_err("%s i2c_write 0x01 error\n",__func__);
			return -1;
		}

		//byte_count = buf[count];
		//swap low byte and high byte begin
		//because LSB is before MSB in buf,but pic16F receive MSB first
		for(i = 0;i < 2 * BYTES_TO_WRITE;i = (i+2)){
			temp = data_buf[count+BYTE_OFFSET+i];
			data_buf[count+BYTE_OFFSET+i] = data_buf[count+BYTE_OFFSET+i+1];
			data_buf[count+BYTE_OFFSET+i+1] = temp;
		}
		//swap low byte and high byte end
		//write 16 bytes data to pic16F
		i2c_smbus_write_i2c_block_data(pic16F_client,0x02,BYTES_TO_WRITE,&data_buf[count+BYTE_OFFSET]);
			
		i2c_smbus_write_i2c_block_data(pic16F_client,0x05,1,&zero_buf[0]);
		i2c_smbus_read_i2c_block_data(pic16F_client,0x05,1,&temp_buf[0]);
		//printk("lfc read 0x05,temp_buf[0]:0x%x\n",temp_buf[0]);

		//write 16 bytes data to pic16F again
		i2c_smbus_write_i2c_block_data(pic16F_client,0x02,BYTES_TO_WRITE,&data_buf[count+BYTE_OFFSET+BYTES_TO_WRITE]);
			
		i2c_smbus_write_i2c_block_data(pic16F_client,0x05,1,&zero_buf[0]);
		i2c_smbus_read_i2c_block_data(pic16F_client,0x05,1,&temp_buf[0]);
		//printk("lfc read again 0x05,temp_buf[0]:0x%x\n",temp_buf[0]);
				
		count = count + BYTE_OFFSET + 2 * BYTES_TO_WRITE;

		msleep(2);
		//pr_err("%s count:%d,offset:%d,length:%d\n",__func__,count,offset,length);
		if(count > (offset + length - 1)){
			break;
		}
	}
	return 0;
}
开发者ID:Reachseysear,项目名称:Find7-kernel-source,代码行数:55,代码来源:pic16F1503_fastcg.c

示例5: i2c_smbus_write_i2c_block_data

void i2c_access::write(const unsigned int data_addr, const unsigned char *values, size_t length)
{
    int ret;
    std::string error_msg;

    if (fd < 0) {
        error_msg = "member is not initialized";
        throw error_msg;
    }

    if (data_addr < 0 || data_addr > 0xff) {
        error_msg = "Data address invalid!";
        throw error_msg;
    }

    for (unsigned int i=0; i<=retry_times; i++) {
        ret = i2c_smbus_write_i2c_block_data(fd, data_addr, (__u8)length, (__u8*)values);
        if (ret == 0) {
            break;
        } else {
            if (i < retry_times) {
                usleep(10000);
            }
        }
    }
    if (ret < 0) {
        char addr_str[256] = {0};
        snprintf(addr_str, sizeof(addr_str), "data_addr=0x%02x, length=%d, ", data_addr, length);
        error_msg = "I2C bus write failed : ";
        error_msg.append(addr_str);
        error_msg.append(strerror(ret * -1));
        throw error_msg;
    }
}
开发者ID:suzutsuki0220,项目名称:I2C_LCD,代码行数:34,代码来源:i2c_access.cpp

示例6: i2c_block_write

static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length,
		const u8 *values)
{
	struct i2c_client *i2c = stmpe->client;

	return i2c_smbus_write_i2c_block_data(i2c, reg, length, values);
}
开发者ID:MaxChina,项目名称:linux,代码行数:7,代码来源:stmpe-i2c.c

示例7: k3g_resume

static int k3g_resume(struct device *dev)
{
	int err = 0;
	struct i2c_client *client = to_i2c_client(dev);
	struct k3g_data *k3g_data = i2c_get_clientdata(client);
	struct k3g_platform_data *pdata;

	if(DEBUG_FUNC_TRACE & debug_mask)
		printk(KERN_INFO "%s: line %d\n", __func__, __LINE__);

	pdata = client->dev.platform_data;	

	if (pdata->power_on){	
		if(DEBUG_GEN_INFO & debug_mask)
			printk(KERN_INFO "%s: goes to resume, power on\n", __func__);
		pdata->power_on(1<<SENSOR_TYPE_GYROSCOPE);
		mdelay(1);
	}

	if (k3g_data->enable) {
		mutex_lock(&k3g_data->lock);
		mdelay(300);
		k3g_restart_fifo(k3g_data);
		if (!k3g_data->interruptible)
			hrtimer_start(&k3g_data->timer,
				k3g_data->polling_delay, HRTIMER_MODE_REL);
		err = i2c_smbus_write_i2c_block_data(client,
				CTRL_REG1 | AC, sizeof(k3g_data->ctrl_regs),
							k3g_data->ctrl_regs);
		mutex_unlock(&k3g_data->lock);
	}

	return err;
}
开发者ID:TeamRegular,项目名称:android_kernel_lge_iproj,代码行数:34,代码来源:k3g.c

示例8: bebot_base_pass

static int bebot_base_pass(struct senseact_device *senseact, unsigned int type, unsigned int index, unsigned int count, int *values)
{
	struct bebot_base_device *base = senseact_get_drvdata(senseact);
	struct i2c_client *client = base->client;
	int buffer[SETSPEED_COUNT];
	int i, n, rc;

	for (i = 0; i < count; i++) {
		switch (type) {
		case SENSEACT_TYPE_SPEED:
			if ((index + i) < SETSPEED_COUNT) {
				base->speed[index + i] = SPEED_TO_REG(values[i]);
			}
			break;

		case SENSEACT_TYPE_SYNC:
			rc = i2c_smbus_write_i2c_block_data(client, SETSPEED_REG, SETSPEED_SIZE, base->speed);
			if (rc < 0)
				return rc;

			for (n = 0; n < SETSPEED_COUNT; n++)
				buffer[n] = SPEED_FROM_REG((int) base->speed[n]);

			senseact_pass_actions(senseact, SENSEACT_TYPE_SPEED, SENSEACT_PREFIX_MILLI, 0, SETSPEED_COUNT, buffer);
			senseact_sync(senseact, SENSEACT_SYNC_ACTOR);

			break;
		}
	}

	return 0;
}
开发者ID:BackupTheBerlios,项目名称:openrobotix-svn,代码行数:32,代码来源:bebot-base.c

示例9: d2041_i2c_write_device

static int d2041_i2c_write_device(struct d2041 * const d2041, char const reg,
				   int const bytes, const u8 *src /*void * const src*/)
{
    int ret = 0;

    // Redundant. It already checked in d2041_reg_read & write function
    //if ((reg + bytes) > D2041_MAX_REGISTER_CNT) {
    //    printk(KERN_ERR "Bad input to d2041_i2c_write_device(0x%x, %d)\n", reg, bytes);
    //    return -EINVAL;
    //}

#ifdef CONFIG_D2041_USE_SMBUS_API
    if(bytes > 1)
        ret = i2c_smbus_write_i2c_block_data(d2041->i2c_client, reg, bytes, src);
    else
        ret = i2c_smbus_write_byte_data(d2041->i2c_client, reg, *src);

    return ret;
#else
    u8 msg[bytes + 1];
    
    msg[0] = reg;
    memcpy(&msg[1], src, bytes);

    ret = i2c_master_send(d2041->i2c_client, msg, bytes + 1);
    if (ret < 0)
        return ret;
    if (ret != bytes + 1)
        return -EIO;
    
    return 0;
#endif /* CONFIG_D2041_USE_SMBUS_API */
}
开发者ID:foxsake,项目名称:infuzion-sgp,代码行数:33,代码来源:d2041-i2c.c

示例10: leds_i2c_write_all

static int leds_i2c_write_all(struct i2c_client *client)
{
	struct an30259a_data *data = i2c_get_clientdata(client);
	int ret;

	/*we need to set all the configs setting first, then LEDON later*/
	mutex_lock(&data->mutex);
	ret = i2c_smbus_write_i2c_block_data(client,
			AN30259A_REG_SEL | AN30259A_CTN_RW_FLG,
			AN30259A_REG_MAX - AN30259A_REG_SEL,
			&data->shadow_reg[AN30259A_REG_SEL]);
	if (ret < 0) {
		dev_err(&client->adapter->dev,
			"%s: failure on i2c block write\n",
			__func__);
		goto exit;
	}
	ret = i2c_smbus_write_byte_data(client, AN30259A_REG_LEDON,
					data->shadow_reg[AN30259A_REG_LEDON]);
	if (ret < 0) {
		dev_err(&client->adapter->dev,
			"%s: failure on i2c byte write\n",
			__func__);
		goto exit;
	}
	mutex_unlock(&data->mutex);
	return 0;

exit:
	mutex_unlock(&data->mutex);
	return ret;
}
开发者ID:davidmueller13,项目名称:efficientkernel,代码行数:32,代码来源:leds-an30259a.c

示例11: silead_ts_load_fw

static int silead_ts_load_fw(struct i2c_client *client)
{
	struct device *dev = &client->dev;
	struct silead_ts_data *data = i2c_get_clientdata(client);
	unsigned int fw_size, i;
	const struct firmware *fw;
	struct silead_fw_data *fw_data;
	int ret;

	ret = request_firmware(&fw, data->fw_name, dev);
	if (ret) {
		dev_err(dev, "Firmware request error %d\n", ret);
		return ret;
	}

	fw_size = fw->size / sizeof(*fw_data);
	fw_data = (struct silead_fw_data *)fw->data;

	for (i = 0; i < fw_size; i++) {
		ret = i2c_smbus_write_i2c_block_data(client, fw_data[i].offset,
						     4, (u8 *)&fw_data[i].val);
		if (ret) {
			dev_err(dev, "Firmware load error %d\n", ret);
			goto release_fw_err;
		}
	}

	release_firmware(fw);
	return 0;

release_fw_err:
	release_firmware(fw);
	return ret;
}
开发者ID:tinocyngn,项目名称:sofia-kernel,代码行数:34,代码来源:silead.c

示例12: i2c_lcd_puts

int i2c_lcd_puts( char *str )
{
    i2c_smbus_write_i2c_block_data( i2c_fd, LCD_RS_DATA_WRITE, strlen(str), (unsigned char *)str );
    usleep(30);

    return 1;
}
开发者ID:toru-ver4,项目名称:raspberry,代码行数:7,代码来源:libi2clcd.c

示例13: get_fw_version

int get_fw_version()
{
	__u8 READ_CMD[11]={0x0B,0x00,0x00,0x00,0x52,0x00,0x00,0x40,0x00,0x10, 0xAD};
	__u8 FW_VER[2]={0};
	int fw=0;
	int ret=0;
	int i=0;
	ret=i2c_smbus_write_i2c_block_data(i2c_fd, 0x0B, 10, &READ_CMD[1]);

	i2c_smbus_read_i2c_block_data(i2c_fd, FC_CMD_READ_ACK, &FC_RX_INFO[0]);

	if (FC_RX_INFO[0]!=FC_CMD_READ_ACK ){//Check Return 0xFC
			printf("FC_RX_INFO[0]=%x\n",FC_RX_INFO[0]);
			return -1;
		}
	
	//printf("%s\n",&FC_RX_INFO[0]);

	for(i=0;i<2;i++)
		FW_VER[i]=FC_RX_INFO[i+1];
		
	fw=(int)(FW_VER[0]*100)+(int)FW_VER[1];
	
	return fw;
	
}
开发者ID:Casperkings,项目名称:FastBoot,代码行数:26,代码来源:mcu_update.c

示例14: ds1682_store

static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,
			    const char *buf, size_t count)
{
	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
	struct i2c_client *client = to_i2c_client(dev);
	u64 val;
	__le32 val_le;
	int rc;

	dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name);

	/* Decode input */
	rc = kstrtoull(buf, 0, &val);
	if (rc < 0) {
		dev_dbg(dev, "input string not a number\n");
		return -EINVAL;
	}

	/* Special case: the 32 bit regs are time values with 1/4s
	 * resolution, scale input down to quarter-seconds */
	if (sattr->nr == 4)
		do_div(val, 250);

	/* write out the value */
	val_le = cpu_to_le32(val);
	rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr,
					    (u8 *) & val_le);
	if (rc < 0) {
		dev_err(dev, "register write failed; reg=0x%x, size=%i\n",
			sattr->index, sattr->nr);
		return -EIO;
	}

	return count;
}
开发者ID:AlexShiLucky,项目名称:linux,代码行数:35,代码来源:ds1682.c

示例15: HalSmbusWriteBlock

/**
 * @brief Write a series of bytes to an I2c device using SMBus protocol.
 *
 *****************************************************************************/
halReturn_t HalSmbusWriteBlock(uint8_t command, uint8_t const *blockData,
								  uint8_t length)
{
	halReturn_t		retStatus;
	int32_t			status;
	
	retStatus = I2cAccessCheck();
	if (retStatus != HAL_RET_SUCCESS)
	{
		return retStatus;
	}

	if(length > I2C_SMBUS_BLOCK_MAX)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"HalSmbusWriteBlock, bufferLen param too big (%d) max size (%d)!\n",
    			length, I2C_SMBUS_BLOCK_MAX);
        return HAL_RET_PARAMETER_ERROR;

	}
	status = i2c_smbus_write_i2c_block_data(gMhlDevice.pI2cClient, command,
											length, blockData);
	if (status < 0)
	{
    	SII_DEBUG_PRINT(SII_OSAL_DEBUG_TRACE,
    			"i2c_smbus_write_i2c_block_data returned error: %d\n",status);
		return HAL_RET_FAILURE;
	}

	return HAL_RET_SUCCESS;
}
开发者ID:Mrchenkeyu,项目名称:android_kernel_zte_pluto,代码行数:35,代码来源:sii_hal_linux_i2c.c


注:本文中的i2c_smbus_write_i2c_block_data函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。