⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smb380.c

📁 smb380开发应用和程序(C语言) 包含smb380所有功能的设置函数
💻 C
📖 第 1 页 / 共 3 页
字号:
{
    if (p_smb380==0)
    	return E_SMB_NULL_PTR;	
		return p_smb380->mode;
	
}

/** set SMB380 internal filter bandwidth
   \param bw bandwidth (see bandwidth constants)
   \return result of bus communication function
   \see #define SMB380_BW_25HZ, SMB380_BW_50HZ, SMB380_BW_100HZ, SMB380_BW_190HZ, SMB380_BW_375HZ, SMB380_BW_750HZ, SMB380_BW_1500HZ
   \see smb380_get_bandwidth()
*/
int smb380_set_bandwidth(char bw) 
{
	int comres = 0;
	unsigned char data;


	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	if (bw<8) {

  	  comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, RANGE__REG, &data, 1 );
	  data = SMB380_SET_BITSLICE(data, BANDWIDTH, bw);
	  comres += p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, RANGE__REG, &data, 1 );

	}
    return comres;


}

/** read selected bandwidth from SMB380 
 \param *bw pointer to bandwidth return value
 \return result of bus communication function
 \see #define SMB380_BW_25HZ, SMB380_BW_50HZ, SMB380_BW_100HZ, SMB380_BW_190HZ, SMB380_BW_375HZ, SMB380_BW_750HZ, SMB380_BW_1500HZ
 \see smb380_set_bandwidth()
*/
int smb380_get_bandwidth(unsigned char *bw) {
	int comres = 1;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, BANDWIDTH__REG, bw, 1 );		

	*bw = SMB380_GET_BITSLICE(*bw, BANDWIDTH);
	
	return comres;

}

/** set SMB380 auto wake up pause
  \param wup wake_up_pause parameters
	\return result of bus communication function
	\see SMB380_WAKE_UP_PAUSE_20MS, SMB380_WAKE_UP_PAUSE_80MS, SMB380_WAKE_UP_PAUSE_320MS, SMB380_WAKE_UP_PAUSE_2560MS
	\see smb380_get_wake_up_pause()
*/

int smb380_set_wake_up_pause(unsigned char wup)
{
	int comres=0;
	unsigned char data;

	if (p_smb380==0)
		return E_SMB_NULL_PTR;


	    comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, WAKE_UP_PAUSE__REG, &data, 1 );
		data = SMB380_SET_BITSLICE(data, WAKE_UP_PAUSE, wup);
		comres += p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, WAKE_UP_PAUSE__REG, &data, 1 );
	return comres;
}

/** read SMB380 auto wake up pause from image
  \param *wup wake up pause read back pointer
	\see SMB380_WAKE_UP_PAUSE_20MS, SMB380_WAKE_UP_PAUSE_80MS, SMB380_WAKE_UP_PAUSE_320MS, SMB380_WAKE_UP_PAUSE_2560MS
	\see smb380_set_wake_up_pause()
*/
int smb380_get_wake_up_pause(unsigned char *wup)
{
    int comres = 1;
	unsigned char data;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, WAKE_UP_PAUSE__REG, &data,  1 );		
	
	*wup = SMB380_GET_BITSLICE(data, WAKE_UP_PAUSE);
	
	return comres;

}


/* Thresholds and Interrupt Configuration */


/** set low-g interrupt threshold
   \param th set the threshold
   \note the threshold depends on configured range. A macro \ref SMB380_LG_THRES_IN_G() for range to register value conversion is available.
   \see SMB380_LG_THRES_IN_G()   
   \see smb380_get_low_g_threshold()
*/
int smb380_set_low_g_threshold(unsigned char th) 
{

	int comres;	

	if (p_smb380==0)
		return E_SMB_NULL_PTR;		

	comres = p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, LG_THRES__REG, &th, 1);
	return comres;
	
}


/** get low-g interrupt threshold
   \param *th get the threshold  value from sensor image
   \see smb380_set_low_g_threshold()
*/
int smb380_get_low_g_threshold(unsigned char *th)
{

	int comres=1;	
	if (p_smb380==0)
		return E_SMB_NULL_PTR;	

		comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, LG_THRES__REG, th, 1);		

	return comres;

}


/** set low-g interrupt countdown
   \param cnt get the countdown value from sensor image
   \see smb380_get_low_g_countdown()
*/
int smb380_set_low_g_countdown(unsigned char cnt)
{
	int comres=0;
	unsigned char data;

	if (p_smb380==0)
		return E_SMB_NULL_PTR;
  comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, COUNTER_LG__REG, &data, 1 );
  data = SMB380_SET_BITSLICE(data, COUNTER_LG, cnt);
	comres += p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, COUNTER_LG__REG, &data, 1 );
	return comres;
}


/** get low-g interrupt countdown
   \param cnt get the countdown  value from sensor image
   \see smb380_set_low_g_countdown()
*/
int smb380_get_low_g_countdown(unsigned char *cnt)
{
    int comres = 1;
	unsigned char data;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, COUNTER_LG__REG, &data,  1 );		
	*cnt = SMB380_GET_BITSLICE(data, COUNTER_LG);
	
	return comres;
}

/** set high-g interrupt countdown
   \param cnt get the countdown value from sensor image
   \see smb380_get_high_g_countdown()
*/
int smb380_set_high_g_countdown(unsigned char cnt)
{
	int comres=1;
	unsigned char data;

	if (p_smb380==0)
		return E_SMB_NULL_PTR;


        comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, COUNTER_HG__REG, &data, 1 );
	data = SMB380_SET_BITSLICE(data, COUNTER_HG, cnt);
	comres += p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, COUNTER_HG__REG, &data, 1 );
	return comres;
}

/** get high-g interrupt countdown
   \param cnt get the countdown  value from sensor image
   \see smb380_set_high_g_countdown()
*/
int smb380_get_high_g_countdown(unsigned char *cnt)
{
    int comres = 0;
	unsigned char data;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;
	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, COUNTER_HG__REG, &data,  1 );		
	
	*cnt = SMB380_GET_BITSLICE(data, COUNTER_HG);
	
	return comres;

}


/** configure low-g duration value
	\param dur low-g duration in miliseconds
	\see smb380_get_low_g_duration(), smb380_get_high_g_duration(), smb380_set_high_g_duration()
	
*/
int smb380_set_low_g_duration(unsigned char dur) 
{
	int comres=0;	
	if (p_smb380==0)
		return E_SMB_NULL_PTR;
	
	
	comres = p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, LG_DUR__REG, &dur, 1);

	return comres;
}




/** read out low-g duration value from sensor image
	\param dur low-g duration in miliseconds
	\see smb380_set_low_g_duration(), smb380_get_high_g_duration(), smb380_set_high_g_duration()
	
*/
int smb380_get_low_g_duration(unsigned char *dur) {
	
	int comres=0;	
	if (p_smb380==0)
		return E_SMB_NULL_PTR;



	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, LG_DUR__REG, dur, 1);				  
	return comres;

}




/** set low-g interrupt threshold
   \param th set the threshold
   \note the threshold depends on configured range. A macro \ref SMB380_HG_THRES_IN_G() for range to register value conversion is available.
   \see SMB380_HG_THRES_IN_G()   
   \see smb380_get_high_g_threshold()
*/
int smb380_set_high_g_threshold(unsigned char th) 
{

	int comres=0;	

	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	comres = p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, HG_THRES__REG, &th, 1);
	return comres;
	
}

/** get high-g interrupt threshold
   \param *th get the threshold  value from sensor image
   \see smb380_set_high_g_threshold()
*/
int smb380_get_high_g_threshold(unsigned char *th)
{

	int comres=0;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, HG_THRES__REG, th, 1);		

	return comres;

}



/** configure high-g duration value
	\param dur high-g duration in miliseconds
	\see  smb380_get_high_g_duration(), smb380_set_low_g_duration(), smb380_get_low_g_duration()
	
*/
int smb380_set_high_g_duration(unsigned char dur) 
{
	int comres=0;	

	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	comres = p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, HG_DUR__REG, &dur, 1);
	return comres;
}


/** read out high-g duration value from sensor image
	\param dur high-g duration in miliseconds
	\see  smb380_set_high_g_duration(), smb380_get_low_g_duration(), smb380_set_low_g_duration(),
	
*/
int smb380_get_high_g_duration(unsigned char *dur) {	
	
	int comres=0;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;
			
        comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, HG_DUR__REG, dur, 1);		

	return comres;

}




/**  set threshold value for any_motion feature
		\param th set the threshold a macro \ref SMB380_ANY_MOTION_THRES_IN_G()  is available for that
		\see SMB380_ANY_MOTION_THRES_IN_G()
*/
int smb380_set_any_motion_threshold(unsigned char th) 
{
	int comres=0;	

	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	comres = p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, ANY_MOTION_THRES__REG, &th, 1);

	return comres;
}


/**  get threshold value for any_motion feature
		\param *th read back any_motion threshold from image register 
		\see SMB380_ANY_MOTION_THRES_IN_G()
*/
int smb380_get_any_motion_threshold(unsigned char *th)
{

	int comres=0;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;
	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, ANY_MOTION_THRES__REG, th, 1);		

	return comres;

}

/**  set counter value for any_motion feature 
		\param amc set the counter value, constants are available for that
		\see SMB380_ANY_MOTION_DUR_1, SMB380_ANY_MOTION_DUR_3, SMB380_ANY_MOTION_DUR_5, SMB380_ANY_MOTION_DUR_7
*/
int smb380_set_any_motion_count(unsigned char amc)
{
	int comres=0;	
	unsigned char data;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;

 	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, ANY_MOTION_DUR__REG, &data, 1 );
	data = SMB380_SET_BITSLICE(data, ANY_MOTION_DUR, amc);
	comres = p_smb380->SMB380_BUS_WRITE_FUNC(p_smb380->dev_addr, ANY_MOTION_DUR__REG, &data, 1 );
	return comres;
}


/**  get counter value for any_motion feature from image register
		\param *amc readback pointer for counter value
		\see SMB380_ANY_MOTION_DUR_1, SMB380_ANY_MOTION_DUR_3, SMB380_ANY_MOTION_DUR_5, SMB380_ANY_MOTION_DUR_7
*/
int smb380_get_any_motion_count(unsigned char *amc)
{
    int comres = 0;
	unsigned char data;
	if (p_smb380==0)
		return E_SMB_NULL_PTR;

	comres = p_smb380->SMB380_BUS_READ_FUNC(p_smb380->dev_addr, ANY_MOTION_DUR__REG, &data,  1 );		
	
	*amc = SMB380_GET_BITSLICE(data, ANY_MOTION_DUR);
	return comres;

}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -