Ejemplo n.º 1
0
//*************************** low level operation **************************************//
static int bma020_detect(void)
{
	int comres = 0;
	unsigned char data;
	/* get chip info. */
	bma_dev.dev_addr = BMA020_I2C_ADDR;	/* preset SM380 I2C_addr */
	comres |= i2c_bma020_read_buf(CHIP_ID__REG, &data, 1);/* read Chip Id */
	bma_dev.chip_id = BMA020_GET_BITSLICE(data, CHIP_ID);	/* get bitslice */
	comres |= i2c_bma020_read_buf(ML_VERSION__REG, &data, 1); /* read Version reg */
	bma_dev.ml_version = BMA020_GET_BITSLICE(data, ML_VERSION);	/* get ML Version */
	bma_dev.al_version = BMA020_GET_BITSLICE(data, AL_VERSION);/* get AL Version */

	return comres;
}
Ejemplo n.º 2
0
/* readout select range from BMA020
\param *range pointer to range setting
\return result of bus communication function
\see BMA020_RANGE_2G, BMA020_RANGE_4G, BMA020_RANGE_8G
\see bma020_set_range()
*/
int bma020_get_range(unsigned char *range)
{
	int comres = 0;

	comres = i2c_bma020_read_buf(RANGE__REG, range, 1);
	*range = BMA020_GET_BITSLICE(*range, RANGE);
	return comres;
}
Ejemplo n.º 3
0
int bma020_init(bma020_t *bma020) 
{
	int comres=0;
	unsigned char data;

	p_bma020 = bma020;															/* assign bma020 ptr */
	p_bma020->dev_addr = BMA020_I2C_ADDR;										/* preset SM380 I2C_addr */
	comres += p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, CHIP_ID__REG, &data, 1);	/* read Chip Id */
	
	p_bma020->chip_id = BMA020_GET_BITSLICE(data, CHIP_ID);			/* get bitslice */
		
	comres += p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, ML_VERSION__REG, &data, 1); /* read Version reg */
	p_bma020->ml_version = BMA020_GET_BITSLICE(data, ML_VERSION);	/* get ML Version */
	p_bma020->al_version = BMA020_GET_BITSLICE(data, AL_VERSION);	/* get AL Version */

	return comres;

}
Ejemplo n.º 4
0
int bma020_init(bma020_t *bma020) 
{
	int comres=0;
	unsigned char data;

	p_bma020 = bma020;															/* assign bma020 ptr */
	p_bma020->dev_addr = BMA020_I2C_ADDR;										/* preset SM380 I2C_addr */
	comres += p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, CHIP_ID__REG, &data, 1);	/* read Chip Id */
	
	p_bma020->chip_id = BMA020_GET_BITSLICE(data, CHIP_ID);			/* get bitslice */
		
	comres += p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, ML_VERSION__REG, &data, 1); /* read Version reg */
	p_bma020->ml_version = BMA020_GET_BITSLICE(data, ML_VERSION);	/* get ML Version */
	p_bma020->al_version = BMA020_GET_BITSLICE(data, AL_VERSION);	/* get AL Version */

	// make sure the default value of the interrupt enable register
	data = 0x00; // All interrupt disable
	p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, 0x0b, &data, 1 );

	return comres;

}
Ejemplo n.º 5
0
int bma020_get_range(unsigned char *range) 
{
	int comres = 0;
	

	if (p_bma020==0)
		return E_BMA020_NULL_PTR;
	
	comres = p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, RANGE__REG, range, 1 );

	*range = BMA020_GET_BITSLICE(*range, RANGE);
	
	return comres;

}
Ejemplo n.º 6
0
int bma020_get_offset(unsigned char xyz, unsigned short *offset) 
{
   int comres;
   unsigned char data;
   
   if (p_bma020==0)
   		return E_BMA020_NULL_PTR;
   
   comres = p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, (OFFSET_X_LSB__REG+xyz), &data, 1);
   data = BMA020_GET_BITSLICE(data, OFFSET_X_LSB);
   *offset = data;
   comres += p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, (OFFSET_X_MSB__REG+xyz), &data, 1);
   *offset |= (data<<2);
   
   return comres;
}