예제 #1
0
int mi2c_i2c_write_reg(unsigned int device_id, unsigned char reg,
		unsigned char val) {
	unsigned char cmd[1];
	int i = 0;
	cmd[0] = reg;
	i = mi2c_i2c_write(device_id, cmd, 1);
	cmd[0] = val;
	i += mi2c_i2c_write(device_id, cmd, 1);
	if (i !=2 ){
		dev_err(&(mi2c_i2c_client[device_id]->dev), "I2C WRITE error\n");
	}
	return i == 2;
}
예제 #2
0
파일: mi2c-char.c 프로젝트: andatche/mi2c
/* 
 * See the arduino_i2c_slave.pde under the arduino_i2c_slave directory
 * for the arduino code. Basically, the arduino is running a simple program
 * where he responds to 1 byte commands with a two-byte response.
 */
static int arduino_run_command(unsigned char cmd, unsigned int *val) 
{
	int result;
	unsigned char buff[2];

	buff[0] = cmd;

	/* We know the Arduino is device_id 2. It's just a demo... */
	result = mi2c_i2c_write(2, buff, 1);

	if (result != 1)
		return result;

	buff[0] = 0;
	buff[1] = 0;

	result = mi2c_i2c_read(2, buff, 2);

	if (result != 2)
		return result;

	*val = (buff[0] << 8) | buff[1];

	return 0;
}
예제 #3
0
파일: mi2c-char.c 프로젝트: andatche/mi2c
static int blinkm_read_rgb(unsigned int device_id, unsigned char *val) 
{
	int result;
	unsigned char buff[4];

	buff[0] = GET_CURRENT_RGB_COLOR;

	result = mi2c_i2c_write(device_id, buff, 1);

	if (result != 1)
		return result;

	buff[0] = 0;
	buff[1] = 0;
	buff[2] = 0;

	result = mi2c_i2c_read(device_id, buff, 3);

	if (result != 3)
		return result;

	val[0] = buff[0];
	val[1] = buff[1];
	val[2] = buff[2];

	return 0;
}
예제 #4
0
int mi2c_i2c_read_reg(unsigned int device_id, unsigned char reg,
		unsigned char *val) {
	unsigned char cmd[1];
	int i = 0;
	cmd[0] = reg;
	i = mi2c_i2c_write(device_id, cmd, 1);
	i += mi2c_i2c_read(device_id, val, 1);
	if (i !=2 )
			dev_err(&(mi2c_i2c_client[device_id]->dev), "I2C READ error\n");
	return i == 2;
}