int i2c_read(int bus, unsigned char slave, int address, int len, unsigned char *data)
{
    int ret;
    mutex_lock(&i2c_mtx[bus]);
    ret = i2c_rd(bus, slave, address, len, data);
    mutex_unlock(&i2c_mtx[bus]);
    return ret;
}
Exemplo n.º 2
0
/**
@brief Check for HMC5883L presence on I2C
@return True on present, false otherwise
*/
uint8_t hmc_present(void)
{
	uint8_t b[3] = {10};

	if( i2c_wr(hmcDev, HMC_I2C_ADDR, b, 1) ) { return 0; }

	if( i2c_rd(hmcDev, HMC_I2C_ADDR, b, 3) ) { return 0; }

	return (b[0] == 'H') && (b[1] == '4') && (b[2] == '3');
}
Exemplo n.º 3
0
void jsi2cRead(JshI2CInfo *inf, unsigned char address, int nBytes, unsigned char *data, bool sendStop) {
  if (inf->pinSCL==PIN_UNDEFINED || inf->pinSDA==PIN_UNDEFINED)
    return;
  i2cInfo d;
  i2c_initstruct(&d, inf);
  i2c_start(&d);
  i2c_wr(&d, 1|(address<<1));
  int i;
  for (i=0;i<nBytes;i++)
    data[i] = i2c_rd(&d, i==nBytes-1);
  if (sendStop) i2c_stop(&d);
  inf->started = d.started;
}
Exemplo n.º 4
0
/**
@brief Read acc. values.
@param[out]	x	Pointer to x
@param[out]	y	Pointer to y
@param[out]	z	Pointer to z
@return True on success, false otherwise
*/
uint8_t hmc_read(int16_t* x, int16_t* y, int16_t* z)
{
	uint8_t b[6] = {3};

	if( i2c_wr(hmcDev, HMC_I2C_ADDR, b, 1) ) { return 0; }

	if( i2c_rd(hmcDev, HMC_I2C_ADDR, b, 6) ) { return 0; }

	*x = (((int16_t)b[0]) << 8) | b[1];
	*z = (((int16_t)b[2]) << 8) | b[3];
	*y = (((int16_t)b[4]) << 8) | b[5];

	return 1;
}
/*
 * preinit
 */
int pmu_rd_multiple(int address, int count, unsigned char* buffer)
{
    return i2c_rd(0, 0xe6, address, count, buffer);
}