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

📄 motion_sensor_custom.c

📁 MTK 加速传感器驱动 MXC6202..
💻 C
📖 第 1 页 / 共 2 页
字号:
*	
* RETURNS
*	None
*/    
void acc_sensor_pwr_up(void)
{
	//signed char i,j;
	kal_int32 i,j;
   #ifdef ACC_KAL_DEBUG	
	dbg_printWithTime("# acc_sensor_pwr_up() - MotionSensor.c #\r\n");
	#endif

/*----- START -----*/
	SET_I2C_DATA_OUTPUT;
	SET_I2C_CLK_OUTPUT; 
	SET_I2C_DATA_HIGH;	
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_short;j++);		
	SET_I2C_DATA_LOW;
	for(j=0;j<delay_short;j++);		
	SET_I2C_CLK_LOW;


/*----- SEND -----*/
//----- 1ST --------
	for (i=7;i>=0;i--)
	{	/* data bit 7~0 */
		if (MXC6202_I2C_SLAVE_ADDR & (1<<i))     /* 0x20 -> slave address & write */
		{
			SET_I2C_DATA_HIGH;
		}
		else
		{
			SET_I2C_DATA_LOW;
		}
		SET_I2C_CLK_HIGH;
		for(j=0;j<delay_long;j++);		
		SET_I2C_CLK_LOW;
	}
	
	/* don't care bit, 9th bit */
	SET_I2C_DATA_LOW;
	SET_I2C_DATA_INPUT;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_long;j++);		 
	SET_I2C_CLK_LOW;
	SET_I2C_DATA_OUTPUT;	


//----- 2ND --------
	for (i=7;i>=0;i--)
	{	/* data bit 7~0 */
		if (0x00 & (1<<i))     /* 0x00 -> internal register */
		{
			SET_I2C_DATA_HIGH;
		}
		else
		{
			SET_I2C_DATA_LOW;
		}
		SET_I2C_CLK_HIGH;
		for(j=0;j<delay_long;j++);		
		SET_I2C_CLK_LOW;
	}	

	/* don't care bit, 9th bit */
	SET_I2C_DATA_LOW;
	SET_I2C_DATA_INPUT;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_LOW;
	SET_I2C_DATA_OUTPUT;	


//----- 3RD --------
	for (i=7;i>=0;i--)
	{	/* data bit 7~0 */
		if (0x00 & (1<<i))     /* power-up */
		//if (0x08 & (1<<i))     /* power-up with temperature */
		{
			SET_I2C_DATA_HIGH; 
		}
		else
		{
			SET_I2C_DATA_LOW;
		}
		SET_I2C_CLK_HIGH;
		for(j=0;j<delay_long;j++);		
		SET_I2C_CLK_LOW;
	}

	/* don't care bit, 9th bit */
	SET_I2C_DATA_LOW; 
	SET_I2C_DATA_INPUT;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_LOW;
	SET_I2C_DATA_OUTPUT;	


/*----- STOP -----*/	
	SET_I2C_CLK_OUTPUT;
	SET_I2C_DATA_OUTPUT;
	SET_I2C_CLK_LOW;
	SET_I2C_DATA_LOW;
	for(j=0;j<delay_short;j++);		
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_short;j++);		
	SET_I2C_DATA_HIGH;
	
}
/*
* FUNCTION                                                            
*	acc_sensor_pwr_down
*
* DESCRIPTION                                                           
*   	This function is to power down acceleration
*
* CALLS  
*
* PARAMETERS
*	None
*	
* RETURNS
*	None
*/ 
void acc_sensor_pwr_down(void)
{
	//signed char i,j;
	kal_int32 i,j;
   #ifdef ACC_KAL_DEBUG	
	dbg_printWithTime("# acc_sensor_pwr_down() - MotionSensor.c #\r\n");
   #endif
/*----- START -----*/
	SET_I2C_DATA_OUTPUT;
	SET_I2C_CLK_OUTPUT; 
	SET_I2C_DATA_HIGH;	
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_short;j++);		
	SET_I2C_DATA_LOW;
	for(j=0;j<delay_short;j++);		
	SET_I2C_CLK_LOW;


/*----- SEND -----*/
//----- 1ST --------
	for (i=7;i>=0;i--)
	{	/* data bit 7~0 */
		if (MXC6202_I2C_SLAVE_ADDR & (1<<i))     /* 0x20 -> slave address & write */
		{
			SET_I2C_DATA_HIGH;
		}
		else
		{
			SET_I2C_DATA_LOW;
		}
		SET_I2C_CLK_HIGH;
		for(j=0;j<delay_long;j++);		
		SET_I2C_CLK_LOW;
	}
	
	/* don't care bit, 9th bit */
	SET_I2C_DATA_LOW;
	SET_I2C_DATA_INPUT;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_LOW;
	SET_I2C_DATA_OUTPUT;	


//----- 2ND --------
	for (i=7;i>=0;i--)
	{	/* data bit 7~0 */
		if (0x00 & (1<<i))     /* 0x00 -> internal register */
		{
			SET_I2C_DATA_HIGH;
		}
		else
		{
			SET_I2C_DATA_LOW;
		}
		SET_I2C_CLK_HIGH;
		for(j=0;j<delay_long;j++);		
		SET_I2C_CLK_LOW;
	}	

	/* don't care bit, 9th bit */
	SET_I2C_DATA_LOW;
	SET_I2C_DATA_INPUT;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_LOW;
	SET_I2C_DATA_OUTPUT;	


//----- 3RD --------
	for (i=7;i>=0;i--)
	{	/* data bit 7~0 */
		if (0x01 & (1<<i))     /* power-down */
		{
			SET_I2C_DATA_HIGH;
		}
		else
		{
			SET_I2C_DATA_LOW;
		}
		SET_I2C_CLK_HIGH;
		for(j=0;j<delay_long;j++);		
		SET_I2C_CLK_LOW;
	}

	/* don't care bit, 9th bit */
	SET_I2C_DATA_LOW;
	SET_I2C_DATA_INPUT;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_long;j++);		
	SET_I2C_CLK_LOW;
	SET_I2C_DATA_OUTPUT;	


/*----- STOP -----*/	
	SET_I2C_CLK_OUTPUT;
	SET_I2C_DATA_OUTPUT;
	SET_I2C_CLK_LOW;
	SET_I2C_DATA_LOW;
	for(j=0;j<delay_short;j++);		
	SET_I2C_CLK_HIGH;
	for(j=0;j<delay_short;j++);		
	SET_I2C_DATA_HIGH;
	
}
/*
* FUNCTION                                                            
*	acc_sensor_init
*
* DESCRIPTION                                                           
*   	This function is to initialize acceleration module
*
* CALLS  
*
* PARAMETERS
*	None
*	
* RETURNS
*	None
*/ 
void acc_sensor_init(void)
{
	
	//static unsigned char p_flag=0;	
	static kal_uint8 p_flag=0;
	#ifdef ACC_KAL_DEBUG	
	dbg_printWithTime("# acc_sensor_init() - MotionSensor.c\r\n");
   #endif         
   /*initial sensor*/
#ifndef __CUST_NEW__
	GPIO_ModeSetup(ACC_SENSOR_SCK, 0x00);
#endif /* __CUST_NEW__ */
	SET_I2C_CLK_OUTPUT;
	SET_I2C_CLK_HIGH;

#ifndef __CUST_NEW__
	GPIO_ModeSetup(ACC_SENSOR_SDA, 0x00);
#endif /* __CUST_NEW__ */
	SET_I2C_DATA_OUTPUT;
	SET_I2C_DATA_HIGH;

	//for( j=0; j<5; j++) get_byte[j] = 0;

	if( p_flag == 0 )
	{
	   #ifdef ACC_KAL_DEBUG	   		
		dbg_printWithTime("*** Power down~~!! ***\r\n");
		#endif
		acc_sensor_pwr_down();
		//Power down again, because the first doesn't take effect
		acc_sensor_pwr_down();
		p_flag = 1;
	}
	else
	{
	   #ifdef ACC_KAL_DEBUG		
		dbg_printWithTime("*** Power up~~!! ***\r\n");
		#endif
		acc_sensor_pwr_up();
		p_flag = 0; 
	}
	
}

/*
* FUNCTION                                                            
*	ms_get_data
*
* DESCRIPTION                                                           
*   	This function is to get customization data
*
* CALLS  
*
* PARAMETERS
*	None
*	
* RETURNS
*	customization data
*/ 
MotionSensor_custom_data_struct *ms_get_data(void) 
{
   return (&ms_custom_data_def);
} 
    
 
/*
* FUNCTION                                                            
*	ms_GetFunc
*
* DESCRIPTION                                                           
*   	This function is to enable to customization function pointer
*
* CALLS  
*
* PARAMETERS
*	None
*	
* RETURNS
*	function pointer
*/  
MotionSensor_customize_function_struct *ms_GetFunc(void)
{
   return (&ms_custom_func);  
} 
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
#endif

⌨️ 快捷键说明

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