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

📄 adcts.c

📁 s3c6400 ADS下官方测试程序
💻 C
📖 第 1 页 / 共 2 页
字号:
}

//////////
// Function Name : ADCTS_StylusTrackingISR
// Function Description : This function is a pen-down interrupt handler of ADCTS_StylusTrackingUsingAutoConversionInPENDNInterruptADCPolling().
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void __irq	ADCTS_StylusTrackingISR(void)
{
	if ( ADCTS_GetXPStylusIntState() == STYLUS_DOWN )
	{
		g_oADCTSInform.ucTouchStatus = ADCTS_TOUCH_DOWN;
	}
	else 
	{
		g_oADCTSInform.ucTouchStatus = ADCTS_TOUCH_UP;
	}
	ADCTS_SetADCClearInt();
	ADCTS_SetADCClearWKInt();
	INTC_ClearVectAddr();
}

/*---------------------------------- APIs of rADCCON ---------------------------------*/
//////////
// Function Name : ADC_InitADCCON
// Function Description : This function initializes an ADCCON register.
// Input : 	NONE 
// Output : 	NONE
// Version : v0.1
void ADC_InitADCCON(void)
{
	u32			uADCCONValue=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	uADCCONValue			= (1<<14)|(ADCTS_PRSCVL<<6)|(0<<2)|(0<<1);;
	ADCTS_SetRegValue(eADCTS_ADCCON, uADCCONValue);	
}

//////////
// Function Name : ADC_IsEOCFlag
// Function Description : This function requests the result of ADC Conversion.
// Input : 	NONE 
// Output : 	TRUE	- End of A/D conversion
//			FALSE 	- A/D conversion in process
// Version : v0.1
bool ADC_IsEOCFlag(void)
{
	u32			uADCCONValue=0;
	u8			ucEOCFlag=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	ucEOCFlag 				= (uADCCONValue & 0x8000) >> 15;

	if ( ucEOCFlag == 1 )
	{
		return true;
	}
	else 
	{
		return false;
	}
}

//////////
// Function Name : ADC_EnablePrescaler
// Function Description : This function enables ADC prescaler.
// Input : 	ucSel	- Enable/Disable Selector
//						0 : Disable
//						1 : Enable
// Output : 	NONE
// Version : v0.1
void ADC_EnablePrescaler(u8 ucSel)
{
	u32			uADCCONValue=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	uADCCONValue			|= (uADCCONValue & ~(1<<14))|(ucSel<<12);
	ADCTS_SetRegValue(eADCTS_ADCCON, uADCCONValue);	
}

//////////
// Function Name : ADC_SetPrescaler
// Function Description : This function configures the value of ADC prescaler.
// Input : 	ucPrscvl	- ADC prescaler value (5~255)
// Output : 	NONE
// Version : v0.1
void ADC_SetPrescaler(u8 ucPrscvl)
{
	u32			uADCCONValue=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	uADCCONValue			|= (uADCCONValue & ~(0xff<<6))|(ucPrscvl<<6);
	ADCTS_SetRegValue(eADCTS_ADCCON, uADCCONValue);
}

//////////
// Function Name : ADC_SelectADCCh
// Function Description : This function chooses one channel of 8 ADC channels.
// Input : 	ucSel	- number of ADC channel
// Output : 	NONE
// Version : v0.1
void ADC_SelectADCCh(u8 ucSel)
{
	u32			uADCCONValue=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	uADCCONValue			|= (uADCCONValue & ~(0x7<<3))|(ucSel<<3);
	ADCTS_SetRegValue(eADCTS_ADCCON, uADCCONValue);
}

//////////
// Function Name : ADC_SelectStandbyMode
// Function Description : This function chooses 'Standby mode'.
// Input : 	ucSel	- Standby mode select value
//						0 : Normal operation mode
//						1 : Standby mode
// Output : 	NONE
// Version : v0.1
void ADC_SelectStandbyMode(u8 ucSel)
{
	u32			uADCCONValue=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	uADCCONValue			|= (uADCCONValue & ~(1<<2))|(ucSel<<2);
	ADCTS_SetRegValue(eADCTS_ADCCON, uADCCONValue);
}

//////////
// Function Name : ADC_EnableReadStart
// Function Description : This function enables ADC start by read.
// Input : 	ucSel	- Enable/Disable Selector
//						0 : Disable start by read operation
//						1 : Enable start by read operation
// Output : 	NONE
// Version : v0.1
void ADC_EnableReadStart(u8 ucSel)
{
	u32			uADCCONValue=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	uADCCONValue			|= (uADCCONValue & ~(1<<1))|(ucSel<<1);
	ADCTS_SetRegValue(eADCTS_ADCCON, uADCCONValue);
}

//////////
// Function Name : ADC_EnableStart
// Function Description : This function enables ADC start by enable.
//					  If READ_START bit is enabled, this value is not valid.
// Input : 	ucSel	- Enable/Disable Selector
//						0 : No operation
//						1 : Enable(A/D conversion starts and this bit is cleared automatically after the start-up.)
// Output : 	NONE
// Version : v0.1
void ADC_EnableStart(u8 ucSel)
{
	u32			uADCCONValue=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	uADCCONValue			|= (uADCCONValue & ~(1<<0))|(ucSel<<0);
	ADCTS_SetRegValue(eADCTS_ADCCON, uADCCONValue);
}

//////////
// Function Name : ADC_IsAfterStartup
// Function Description : This function requests the result of ADC Enable Start.
// Input : 	NONE 
// Output : 	TRUE	- ADC Enable Started.(ENABLE_START bit of rADCCON is 0)
//			FALSE 	- A/D conversion starts in process
// Version : v0.1
bool ADC_IsAfterStartup(void)
{
	u32			uADCCONValue=0;
	u8			ucEnableStartFlag=0;

	uADCCONValue			= ADCTS_GetRegValue(eADCTS_ADCCON);
	ucEnableStartFlag			= (uADCCONValue & 0x1) ;

	if ( ucEnableStartFlag == 0 )
	{
		return true;
	}
	else 
	{
		return false;
	}
}
/*---------------------------------- APIs of rADCTSC ---------------------------------*/
//////////
// Function Name : ADCTS_SetMeasureMode
// Function Description : This function chooses the measurement mode of TouchScreen's position.
// Input : 	ucMeasureMode - X/Y Position Measurement mode of TouchScreen
// Output : 	NONE
// Version : v0.1
void ADCTS_SetMeasureMode(u8 ucMeasureMode)
{
	u32			uADCTSCValue=0;

	uADCTSCValue	= ADCTS_GetRegValue(eADCTS_ADCTSC);
	
	switch(ucMeasureMode)
	{
		case eADCTS_MEASURE_NOP :
			break;
		case eADCTS_MEASURE_MANUAL_X :
			uADCTSCValue	=	0x68;
			break;
		case eADCTS_MEASURE_MANUAL_Y :
			uADCTSCValue	=	0x98;
			break;
		case eADCTS_MEASURE_AUTO_SEQ :
			uADCTSCValue	=	0x04;
			break;
		case eADCTS_MEASURE_FOR_STYLUS :
			uADCTSCValue	=	0xd3;
			break;
	}

	ADCTS_SetRegValue(eADCTS_ADCTSC, uADCTSCValue);
}

//////////
// Function Name : ADCTS_SetStylusDetectMode
// Function Description : This function select the method of  the result of ADC Enable Start.
// Input : 	ucMeasureMode - X/Y Position Measurement mode of TouchScreen
// Output : 	NONE
// Version : v0.1
void ADCTS_SetStylusDetectMode(u8 ucStylusDetectMode)
{
	u32			uADCTSCValue=0;

	uADCTSCValue	= ADCTS_GetRegValue(eADCTS_ADCTSC);
	uADCTSCValue	|= (uADCTSCValue& ~(1<<8))|(ucStylusDetectMode<<8);

	ADCTS_SetRegValue(eADCTS_ADCTSC, uADCTSCValue);
}

/*---------------------------------- APIs of rADCDLY ---------------------------------*/
//////////
// Function Name : ADCTS_SetDelayClkSrc
// Function Description : This function chooses the source of delay Clock.
// Input : 	uClkSrc - Clock Source Selection Number
//				0 - External input clock
//				1 - RTC clock
// Output : 	NONE
// Version : v0.1
void ADCTS_SetDelayClkSrc(u8 uClkSrc)
{
	u32			uADCDLYValue=0;

	uADCDLYValue	= ADCTS_GetRegValue(eADCTS_ADCDLY);
	uADCDLYValue	|= (uADCDLYValue& ~(1<<16))|(uClkSrc<<16);

	ADCTS_SetRegValue(eADCTS_ADCDLY, uADCDLYValue);	
}

//////////
// Function Name : ADCTS_SetDelay
// Function Description : This function sets ADC start or interval delay.
// Input : 	uDelayNum - Clock Source Selection Number
// Output : 	NONE
// Version : v0.1
void ADCTS_SetDelay(u32 uDelayNum)
{
	u32			uADCDLYValue=0;

	uADCDLYValue	= ADCTS_GetRegValue(eADCTS_ADCDLY);
	uADCDLYValue	= (uADCDLYValue& ~(0xffff))|(uDelayNum&0xffff);

	ADCTS_SetRegValue(eADCTS_ADCDLY, uADCDLYValue);	
}

/*---------------------------------- APIs of rADCDATx ---------------------------------*/
//////////
// Function Name : ADCTS_GetXPStylusIntState
// Function Description : This function gets the state of Stylus interrupt (Up/Down).
// Input : 	NONE
// Output : 	ucXPState - Stylus state of XP
// Version : v0.1
u8 ADCTS_GetXPStylusIntState(void)
{
	u32			uADCDAT0Value=0;
	u8			ucXPState=0;

	uADCDAT0Value			= ADCTS_GetRegValue(eADCTS_ADCDAT0);
	ucXPState				= (uADCDAT0Value& (1<<15)) >> 15;

	return ucXPState;
}

//////////
// Function Name : ADCTS_GetYPStylusIntState
// Function Description : This function gets the state of Stylus interrupt (Up/Down).
// Input : 	NONE
// Output : 	ucYPState - Stylus state of YP
// Version : v0.1
u8 ADCTS_GetYPStylusIntState(void)
{
	u32			uADCDAT1Value=0;
	u8			ucYPState=0;

	uADCDAT1Value			= ADCTS_GetRegValue(eADCTS_ADCDAT1);
	ucYPState				= (uADCDAT1Value& (1<<15)) >> 15;

	return ucYPState;
}

//////////
// Function Name : ADCTS_GetXPData
// Function Description : This function gets ADC Conversion data of X-Position.
// Input : 	NONE
// Output : 	(uADCDAT0Value & 0x3ff) - X-Position Conversiondata value(0~3FF)
// Version : v0.1
u32 ADCTS_GetXPData(void)
{
	u32			uADCDAT0Value=0;

	uADCDAT0Value	= ADCTS_GetRegValue(eADCTS_ADCDAT0);

	return (uADCDAT0Value & 0x3ff);
}

//////////
// Function Name : ADCTS_GetYPData
// Function Description : This function gets ADC Conversion data of Y-Position.
// Input : 	NONE
// Output : 	(uADCDAT1Value & 0x3ff) - Y-Position Conversiondata value(0~3FF)
// Version : v0.1
u32 ADCTS_GetYPData(void)
{
	u32			uADCDAT1Value=0;

	uADCDAT1Value	= ADCTS_GetRegValue(eADCTS_ADCDAT1);

	return (uADCDAT1Value & 0x3ff);
}

/*---------------------------------- APIs of INT Clear Registers ---------------------------------*/
//////////
// Function Name : ADCTS_SetADCClearInt
// Function Description : This function clears ADC Interrupt.
// Input : 	NONE
// Output : 	NONE
// Version : v0.1
void ADCTS_SetADCClearInt(void)
{
	u32			uADCCLRINTValue=0;

	uADCCLRINTValue	= ADCTS_GetRegValue(eADCTS_ADCCLRINT);
	uADCCLRINTValue	|= 0;
	ADCTS_SetRegValue(eADCTS_ADCCLRINT, uADCCLRINTValue);	
}

//////////
// Function Name : ADCTS_SetADCClearWKInt
// Function Description : This function clears ADCTS WakeUp Interrupt.
// Input : 	NONE
// Output : 	NONE
// Version : v0.1
void ADCTS_SetADCClearWKInt(void)
{
	u32			uADCCLRWKValue=0;

	uADCCLRWKValue	= ADCTS_GetRegValue(eADCTS_ADCCLRWK);
	uADCCLRWKValue	|= 0;
	ADCTS_SetRegValue(eADCTS_ADCCLRWK, uADCCLRWKValue);	
}

/*---------------------------------- APIs of general ADCTS ---------------------------------*/
//////////
// Function Name : ADCTS_GetRegValue
// Function Description : This function gets the value of ADCTS Registers.
// Input : 	ucADCTSRegId	- the Id of ADCTS Registers
// Output : 	*puADCTSReg	- the value of specified register
// Version : v0.1
u32 ADCTS_GetRegValue(u8 ucADCTSRegId)
{
	volatile u32 *	puADCTSBaseAddr;
	volatile u32 *	puADCTSReg;	

	puADCTSBaseAddr			= &(ADCTS->rADCCON);
	puADCTSReg				= puADCTSBaseAddr + ucADCTSRegId;

	return *puADCTSReg;	
}

//////////
// Function Name : ADCTS_SetRegValue
// Function Description : This function sets the value of ADCTS Registers.
// Input : 	ucADCTSRegId	- the Id of ADCTS Registers
//			uValue			- the value of register
// Output : 	NONE
// Version : v0.1
void ADCTS_SetRegValue(u8 ucADCTSRegId, u32 uValue)
{
	volatile u32 *	puADCTSBaseAddr;
	volatile u32 *	puADCTSReg;	

	puADCTSBaseAddr		= &(ADCTS->rADCCON);
	puADCTSReg			= puADCTSBaseAddr + ucADCTSRegId;

	*puADCTSReg		= uValue;
}

⌨️ 快捷键说明

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