2440 ARM 的ADC驱动是和touch screen共用的吗?
2440的ADC端口和touch screen端口公用一个端口,那windowsce里面是不是也可以用touch 驱动程序来读出ADC的值?
目前我在开发板的软件包里面,找不到ADC驱动,我发现触摸屏的驱动里面有ADC的代码,但是我的这个触摸屏驱动的code不太完整,而且从code中看这个touch screen的设备名字应该叫做“TSP”。但是我在windows ce启动起来后,在注册表以下2个分支都找不到对应的TSP设备,但是触摸屏又确实可以使用。
HKEY_LOCAL_MACHINE\Drivers\BuiltIn
HKEY_LOCAL_MACHINE\Drivers
这个看你的硬件电话的设计吧。
如果你的触摸屏电路和ADC电路(比如电池电路的采集)都集成在一个芯片里面,且在该IC里面可以通过却换,那么ADC和触摸屏都是一个驱动,其实就是读取触摸屏的功能接口的对应寄存器。
比如WM9713,就是触摸屏和ADC采集功能在SPI接口,所以驱动都在一起。
1. touch driver不会去一驱动的形式调用adc driver,一般都是以lib的方式去调用adc的一些功能
所以,在HKEY_LOCAL_MACHINE\Drivers\BuiltIn 找不到adc的驱动是正常的
2. code中看这个touch screen的设备名字应该叫做“TSP”。
这部分的代码粘贴出来看一看
通常分成两个驱动比较好,看起来也比较明朗,可以加临界段来防止ADC共用的冲突
我给出部分代码吧,eeworld对帖子的尺寸有限制的
static int GetADCValue()
{
int Value = -1;
if (Ain0AllocADC()) {
v_pADCregs->ADCCON = (1<<14) | (ADCPRS<< 6) | (0<<3);
v_pADCregs->ADCCON |= (1 << 0); /* Start Auto conversion */
while (v_pADCregs->ADCCON & 0x1); /* check if Enable_start is low */
while (!(v_pADCregs->ADCCON & (1 << 15))); /* Check ECFLG */
Value = v_pADCregs->ADCDAT0 & 0x3FF;
v_pADCregs->ADCCON = 0x3FC4; // Reset it to initial
FreeADC();
}
RETAILMSG(TS_DBGON, (L"Done...ADC is %d\n\r", Value));
return Value;
}
static void FreeADC()
{
AdcOwner = ADC_OWN_BY_NONE;
}
static bool TsAllocADC()
{
long ret = InterlockedCompareExchange(&AdcOwner, ADC_OWN_BY_TS, ADC_OWN_BY_NONE);
switch (ret) {
case ADC_OWN_BY_TS:
RETAILMSG(1, (TEXT("Warning: Alloc ADC Again\r\n")));
return true;
case ADC_OWN_BY_NONE:
return true;
default:
return false;
}
}
PUBLIC VOID
DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS * pTipStateFlags,
INT * pUncalX,
INT * pUncalY)
{
static INT PrevX=0;
static INT PrevY=0;
INT TmpX = 0;
INT TmpY = 0;
RETAILMSG(TS_DBGON,(TEXT("DdsiTouchPanelGetPoint:: *pUncalX=%d, *pUncalY=%d\r\n"),*pUncalX,*pUncalY));
if (v_pINTregs->SUBSRCPND & (1<
{
*pTipStateFlags = TouchSampleValidFlag;
if ( (v_pADCregs->ADCDAT0 & (1 << 15)) ||
(v_pADCregs->ADCDAT1 & (1 << 15)) )
{
bTSP_DownFlag = FALSE;
DEBUGMSG(ZONE_TIPSTATE, (TEXT("up\r\n")));
RETAILMSG(TS_DBGON,(TEXT("up\r\n")));
v_pADCregs->ADCTSC = 0xD3;
*pUncalX = PrevX;
*pUncalY = PrevY;
RETAILMSG(TS_DBGON,(TEXT("*pUncalX=%d,*pUncalY=%d\r\n"),*pUncalX,*pUncalY));
v_pADCregs->ADCCON = 0x3FC4; // Reset it to initial
FreeADC();
TSP_SampleStop();
}
else
{
if (!TsAllocADC()) {
RETAILMSG(1,(TEXT("AllocADC Failed\r\n")));
return;
}
bTSP_DownFlag = TRUE;
*pTipStateFlags |= TouchSampleIgnore;
//if (!TSP_GetXY(&x, &y))
// *pTipStateFlags = TouchSampleIgnore;
//TSP_TransXY(&x, &y);
*pUncalX = PrevX;
*pUncalY = PrevY;
*pTipStateFlags |= TouchSampleDownFlag;
//DEBUGMSG(ZONE_TIPSTATE, (TEXT("down %x %x\r\n"), x, y));
RETAILMSG(TS_DBGON, (TEXT("down %d %d\r\n"), *pUncalX, *pUncalY));
v_pADCregs->ADCCON = (1<<14) | (ADCPRS<< 6) | (7<<3);
TSP_SampleStart();
}
v_pINTregs->SUBSRCPND |= (1<
v_pINTregs->INTSUBMSK &= ~(1<
InterruptDone(gIntrTouch);
}
else /* SYSINTR_TOUCH_CHANGED Interrupt Case */
{
// TSP_SampleStart();
if (bTSP_DownFlag)
{
if (!TSP_GetXY(&TmpX, &TmpY))
*pTipStateFlags = TouchSampleIgnore;
else
{
TSP_TransXY(&TmpX, &TmpY);
if(Touch_Pen_Filtering(&TmpX, &TmpY))
{
RETAILMSG(TS_DBGON,(TEXT("Valid Touch Pen\r\n")));
*pTipStateFlags = TouchSampleValidFlag | TouchSampleDownFlag;
*pTipStateFlags &= ~TouchSampleIgnore;
}
else // Invalid touch pen
{
RETAILMSG(TS_DBGON, (TEXT("invalid touch pen\r\n")));
*pTipStateFlags = TouchSampleValidFlag;
*pTipStateFlags |= TouchSampleIgnore;
}
*pUncalX = PrevX = TmpX;
*pUncalY = PrevY = TmpY;
RETAILMSG(TS_DBGON,(TEXT("*Final:*pUncalX=%d, *pUncalY=%d\r\n"),*pUncalX,*pUncalY));
}
}
else
{
*pTipStateFlags = TouchSampleIgnore;
RETAILMSG(TS_DBGON,(TEXT("TSP_SampleStop()\r\n")));
TSP_SampleStop();
}
InterruptDone(gIntrTouchChanged);
}
}
Touch Panel的驱动跟ADC驱动不是一码的。
只不过Touch Panel的原理也是ADC 采集的。只能说是ADC的一种应用而已。跟一般的有差距,详细看Spec
BSP中Touch Panel driver的ADC 代码只是为Touch Panel用的,不能跟一般的ADC混用。