Ejemplo n.º 1
0
int bma020_get_image(bma020regs_t *bma020Image)
{
	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, EE_W__REG,&data, 1);
	data = BMA020_SET_BITSLICE(data, EE_W, BMA020_EE_W_ON);
	comres = p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, EE_W__REG, &data, 1);
	comres = p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, BMA020_IMAGE_BASE, (unsigned char *)bma020Image, BMA020_IMAGE_LEN);
	data = BMA020_SET_BITSLICE(data, EE_W, BMA020_EE_W_OFF);
	comres = p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, EE_W__REG, &data, 1);
	
	return comres;
}
Ejemplo n.º 2
0
/** Perform soft reset of BMA020 via bus command
*/
int bma020_soft_reset(void)
{
	int comres;
	unsigned char data = 0;
	data = BMA020_SET_BITSLICE(data, SOFT_RESET, 1);
	comres = i2c_bma020_write_buf(SOFT_RESET__REG, &data, 1);
	return comres;
}
Ejemplo n.º 3
0
/**	start BMA020s integrated selftest function
\param st 1 = selftest0, 3 = selftest1 (see also)
\return result of bus communication function
\see BMA020_SELF_TEST0_ON
\see BMA020_SELF_TEST1_ON
*/
int bma020_selftest(unsigned char st)
{
	int comres;
	unsigned char data;
	comres = i2c_bma020_read_buf(SELF_TEST__REG, &data, 1);
	data = BMA020_SET_BITSLICE(data, SELF_TEST, st);
	comres |= i2c_bma020_write_buf(SELF_TEST__REG, &data, 1);
	return comres;
}
Ejemplo n.º 4
0
int bma020_selftest(unsigned char st)
{
	int comres;
	unsigned char data;
	
	comres = p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, SELF_TEST__REG, &data, 1);
	data = BMA020_SET_BITSLICE(data, SELF_TEST, st);
	comres += p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, SELF_TEST__REG, &data, 1);  
	
	return comres;  

}
Ejemplo n.º 5
0
/**	set bma020s range
\param range
\return  result of bus communication function
\see BMA020_RANGE_2G
\see BMA020_RANGE_4G
\see BMA020_RANGE_8G
*/
int bma020_set_range(char range)
{
	int comres = 0;
	unsigned char data;

	if (range < 3) {
		comres = i2c_bma020_read_buf(RANGE__REG, &data, 1);
		data = BMA020_SET_BITSLICE(data, RANGE, range);
		comres |= i2c_bma020_write_buf(RANGE__REG, &data, 1);
	}
	return comres;
}
Ejemplo n.º 6
0
int bma020_update_image() 
{
	int comres;
	unsigned char data=0;
	
	if (p_bma020==0) 
		return E_BMA020_NULL_PTR;
	
	data = BMA020_SET_BITSLICE(data, UPDATE_IMAGE, 1);
    comres = p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, UPDATE_IMAGE__REG, &data,1); 
	
	return comres;
}
Ejemplo n.º 7
0
int bma020_soft_reset(void) 
{
	int comres;
	unsigned char data=0;
	
	if (p_bma020==0) 
		return E_BMA020_NULL_PTR;
	
	data = BMA020_SET_BITSLICE(data, SOFT_RESET, 1);
    comres = p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, SOFT_RESET__REG, &data,1); 
	
	return comres;
}
Ejemplo n.º 8
0
int bma020_set_ee_w(unsigned char eew)
{
    unsigned char data;
	int comres;
	
	if (p_bma020==0)
		return E_BMA020_NULL_PTR;
    
	comres = p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, EE_W__REG,&data, 1);
	data = BMA020_SET_BITSLICE(data, EE_W, eew);
	comres = p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, EE_W__REG, &data, 1);
	
	return comres;
}
Ejemplo n.º 9
0
/** set BMA020s operation mode
\param mode 0 = normal, 2 = sleep, 3 = auto wake up
\return result of bus communication function
\note Available constants see below
\see BMA020_MODE_NORMAL, BMA020_MODE_SLEEP, BMA020_MODE_WAKE_UP
\see bma020_get_mode()
*/
int bma020_set_mode(unsigned char mode)
{
	int comres = 0;
	unsigned char data1, data2;

	if (mode < 4 || mode != 1) {
		comres = i2c_bma020_read_buf(WAKE_UP__REG, &data1, 1);
		data1  = BMA020_SET_BITSLICE(data1, WAKE_UP, mode);
		comres |= i2c_bma020_read_buf(SLEEP__REG, &data2, 1);
		data2  = BMA020_SET_BITSLICE(data2, SLEEP, (mode >> 1));

		comres |= i2c_bma020_write_buf(WAKE_UP__REG, &data1, 1);
		comres |= i2c_bma020_write_buf(SLEEP__REG, &data2, 1);
		bma_dev.mode = mode;
	}
Ejemplo n.º 10
0
int bma020_set_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_SET_BITSLICE(data, OFFSET_X_LSB, offset);
   comres += p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, (OFFSET_X_LSB__REG+xyz), &data, 1);
   data = (offset&0x3ff)>>2;
   comres += p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, (OFFSET_X_MSB__REG+xyz), &data, 1);
   
   return comres;
}
Ejemplo n.º 11
0
int bma020_set_mode(unsigned char mode) {
	
	int comres=0;
	unsigned char data1, data2;

	if (p_bma020==0)
		return E_BMA020_NULL_PTR;

	if (mode<4 || mode!=1) 
	{
		comres = p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, WAKE_UP__REG, &data1, 1 );
		data1  = BMA020_SET_BITSLICE(data1, WAKE_UP, mode);		  
        comres += p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, SLEEP__REG, &data2, 1 );
		data2  = BMA020_SET_BITSLICE(data2, SLEEP, (mode>>1));
    	comres += p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, WAKE_UP__REG, &data1, 1);
	  	comres += p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, SLEEP__REG, &data2, 1);
	  	p_bma020->mode = mode;
	} 
Ejemplo n.º 12
0
int bma020_set_range(char range) 
{			
   int comres = 0;
   unsigned char data;

   if (p_bma020==0)
	    return E_BMA020_NULL_PTR;

   if (range<3) 
   {	
	 	comres = p_bma020->BMA020_BUS_READ_FUNC(p_bma020->dev_addr, RANGE__REG, &data, 1 );
	 	data = BMA020_SET_BITSLICE(data, RANGE, range);		  	
		comres += p_bma020->BMA020_BUS_WRITE_FUNC(p_bma020->dev_addr, RANGE__REG, &data, 1);
   }
   
   return comres;

}