Exemple #1
0
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;
}
Exemple #2
0
/* 
 * 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;
}
Exemple #3
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;
}