int smb380_init(smb380_t *smb380) 
{
	int comres=0;
	unsigned char data;

	p_smb380 = smb380;																			/* assign smb380 ptr */
	p_smb380->dev_addr = SMB380_I2C_ADDR;										/* preset SM380 I2C_addr */
	comres += p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, SMB380_CHIP_ID__REG, &data, 1);	/* read Chip Id */
	
	p_smb380->chip_id = SMB380_GET_BITSLICE(data, SMB380_CHIP_ID);						/* get bitslice */
		
	comres += p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, SMB380_ML_VERSION__REG, &data, 1); /* read Version reg */
	p_smb380->ml_version = SMB380_GET_BITSLICE(data, SMB380_ML_VERSION);				/* get ML Version */
	p_smb380->al_version = SMB380_GET_BITSLICE(data, SMB380_AL_VERSION);				/* get AL Version */

	return comres;

}
/** get eew-flag
   \param *eew pointer to eew-flag
   \return result of bus communication function
*/
int smb380_get_ee_w(unsigned char *eew)
{
	int comres;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;
  comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, SMB380_EE_W__REG,eew, 1);
	*eew = SMB380_GET_BITSLICE(*eew, SMB380_EE_W);
	return comres;
}
Esempio n. 3
0
int smb380_init(smb380_t *smb380) 
{
	int comres=0;
	unsigned char data;

	p_smb380 = smb380;																			
	p_smb380->dev_addr = SMB380_I2C_ADDR;										
	comres += p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, SMB380_CHIP_ID__REG, &data, 1);	
	
	p_smb380->chip_id = SMB380_GET_BITSLICE(data, SMB380_CHIP_ID);						
		
	comres += p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, SMB380_ML_VERSION__REG, &data, 1); 
	p_smb380->ml_version = SMB380_GET_BITSLICE(data, SMB380_ML_VERSION);				
	p_smb380->al_version = SMB380_GET_BITSLICE(data, SMB380_AL_VERSION);				

	return comres;

}
/** read out offset data from 
   \param xyz select axis x=0, y=1, z=2
   \param *offset pointer to offset value (offset is in offset binary representation
   \return result of bus communication function
   \note use smb380_set_ee_w() function to enable access to offset registers 
*/
int smb380_get_offset(unsigned char xyz, unsigned short *offset) 
{

   int comres;
   unsigned char data;
   if (p_smb380==0)
   		return E_SMB_NULL_PTR;
   comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, (SMB380_OFFSET_X_LSB__REG+xyz), &data, 1);
   data = SMB380_GET_BITSLICE(data, SMB380_OFFSET_X_LSB);
   *offset = data;
   comres += p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, (SMB380_OFFSET_X_MSB__REG+xyz), &data, 1);
   *offset |= (data<<2);
   return comres;
}
/* readout select range from SMB380 
   \param *range pointer to range setting
   \return result of bus communication function
   \see SMB380_RANGE_2G, SMB380_RANGE_4G, SMB380_RANGE_8G		
   \see smb380_set_range()
*/
int smb380_get_range(unsigned char *range) 
{

	int comres = 0;
	

	if (p_smb380==0)
		return E_SMB_NULL_PTR;
	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, SMB380_RANGE__REG, range, 1 );

	*range = SMB380_GET_BITSLICE(*range, SMB380_RANGE);
	
	return comres;

}