📄 pmicpdk.cpp
字号:
data = CSP_BITFVAL(MC13783_ADC0_TSMOD, mode) |
CSP_BITFVAL(MC13783_ADC0_ADREFMOD, MC13783_ADC0_DISABLE) |
CSP_BITFVAL(MC13783_ADC0_ADREFEN, MC13783_ADC0_DISABLE);
}
mask = CSP_BITFMASK(MC13783_ADC0_TSMOD) |
CSP_BITFMASK(MC13783_ADC0_ADREFMOD) |
CSP_BITFMASK(MC13783_ADC0_ADREFEN);
SetRegister(addr, data, mask);
if (mode == TM_INTERRUPT)
{
// MC13783 workaround for Pass 2.0 and 2.1
addr = MC13783_ADC1_ADDR;
data = CSP_BITFVAL(MC13783_ADC1_AD_SEL, MC13783_ADC1_AD_SEL_GROUP1) |
CSP_BITFVAL(MC13783_ADC1_ADEN, MC13783_ADC1_ADEN_ENABLE) |
CSP_BITFVAL(MC13783_ADC1_RAND, MC13783_ADC1_RAND_1CHAN_8X) |
CSP_BITFVAL(MC13783_ADC1_ATO, MC13783_ADC_DEFAULT_ATO_SETTING) |
CSP_BITFVAL(MC13783_ADC1_ATOX, MC13783_ADC1_ATOX_DELAY_FIRST) |
CSP_BITFVAL(MC13783_ADC1_ADTRIGIGN, MC13783_ADC1_ADTRIGIGN_IGNORE);
mask = MC13783_ADC_REGISTER_MASK_ALL;
SetRegister(addr, data, mask);
// Request ADC conversion
if (PmicADCConvert() != PMIC_SUCCESS)
{
ERRORMSG(1, (_T("PmicADCConvert failed!\r\n")));
goto cleanUp;
}
}
rc = TRUE;
cleanUp:
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: PMICIoctlAdcSetMode
//
// This function sets the mode for the PMIC ADC.
//
// Parameters:
// pBufIn
// [in] Points to requested PMIC_TOUCH_MODE.
//
// dwLenIn
// [in] Unused.
//
// pBufOut
// [out] Unused.
//
// dwLenOut
// [out] Unused.
//
// Returns:
// TRUE if the successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL PMICIoctlAdcSetMode(PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut,
DWORD dwLenOut)
{
BOOL rc = FALSE;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s() %d\r\n"), __WFUNCTION__));
EnterCriticalSection(&adcCs);
rc = PMICAdcSetMode(*((PMIC_TOUCH_MODE *) pBufIn));
LeaveCriticalSection(&adcCs);
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: CheckIntIdValid
//
// This is a helper function that checks the parameter range.
//
// Parameters:
// IntID
// [in] Interrupt ID.
//
// Returns:
// TRUE if valid range, FALSE otherwise.
//
//-----------------------------------------------------------------------------
static BOOL CheckIntIdValid(UINT32 IntID)
{
// Check low and high
if ((IntID < 0) || (IntID > PMIC_INT_MAX_ID))
{
DEBUGMSG(ZONE_ERROR, (_T("Invalid Input Parameter.\r\n")));
return FALSE;
}
// Check lower half
if (IntID < PMIC_MC13783_INT_ID_OFFSET)
{
// Check range
if ((PMIC_INTS0_TO_AP & (1 << IntID)) == 0)
{
DEBUGMSG(ZONE_ERROR, (_T("Invalid Input Parameter.\r\n")));
return FALSE;
}
}
// Check upper half
else
{
// Check range
if ((PMIC_INTS1_TO_AP & (1 << (IntID - PMIC_MC13783_INT_ID_OFFSET))) == 0)
{
DEBUGMSG(ZONE_ERROR, (_T("Invalid Input Parameter.\r\n")));
return FALSE;
}
}
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PMICIoctlIntEnable
//
// This function enables the selected PMIC interrupt.
//
// Parameters:
// IntID
// [in] Interrupt ID.
//
// EnableFlag
// [in] Flag set to TRUE = enable, FALSE = disable
//
// Returns:
// TRUE if the successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
extern "C" BOOL PMICIoctlIntEnable(UINT32 IntID, BOOL EnableFlag)
{
if (CheckIntIdValid(IntID))
{
EnterCriticalSection(&intRegCs);
// Check lower half
if (IntID < PMIC_MC13783_INT_ID_OFFSET)
{
if (EnableFlag)
{
SetRegister(MC13783_INT_STAT0_ADDR, 1 << IntID, 1 << IntID);
// Unmask the interrupt
SetRegister(MC13783_INT_MSK0_ADDR, 0, 1 << IntID);
}
else
// Mask the interrupt
SetRegister(MC13783_INT_MSK0_ADDR, 1 << IntID, 1 << IntID);
}
else
{ // Check upper half
IntID -= PMIC_MC13783_INT_ID_OFFSET;
if (EnableFlag)
{
SetRegister(MC13783_INT_STAT1_ADDR, 1 << IntID, 1 << IntID);
// Unmask the interrupt
SetRegister(MC13783_INT_MSK1_ADDR, 0, 1 << IntID);
}
else
// Mask the interrupt
SetRegister(MC13783_INT_MSK1_ADDR, 1 << IntID, 1 << IntID);
}
LeaveCriticalSection(&intRegCs);
return TRUE;
} // CheckIntIdValid
else
return FALSE;
}
//-----------------------------------------------------------------------------
//
// Function: PMICIoctlAdcTouchRead
//
// This function places the PMIC in touch position mode and acquires
// touch samples.
//
// Parameters:
// pBufIn
// [in] Unused.
//
// dwLenIn
// [in] Unused.
//
// pBufOut
// [out] Points to data buffer to hold touch samples.
//
// dwLenOut
// [out] Unused.
//
// Returns:
// TRUE if the successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
static BOOL PMICIoctlAdcTouchRead(PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut,
DWORD dwLenOut)
{
BOOL rc = FALSE;
UINT32 addr, data, mask;
UINT16* pData = (UINT16*) pBufOut;
// Grab critical section, ADC can only handle one set of conversions
// at a time
EnterCriticalSection(&adcCs);
// Place the ADC in touch position mode
if (!PMICAdcSetMode(TM_POSITION))
{
ERRORMSG(1, (_T("PMICAdcSetMode failed\r\n")));
goto cleanUp;
}
// Set AD_SEL to 1 for second set of converters;
// Enable A/D and set RAND to 0 for converting multiple channels
addr = MC13783_ADC1_ADDR;
data = CSP_BITFVAL(MC13783_ADC1_AD_SEL, MC13783_ADC1_AD_SEL_GROUP1) |
CSP_BITFVAL(MC13783_ADC1_ADEN, MC13783_ADC1_ADEN_ENABLE) |
CSP_BITFVAL(MC13783_ADC1_RAND, MC13783_ADC1_RAND_1CHAN_8X) |
CSP_BITFVAL(MC13783_ADC1_ATO, MC13783_ADC_DEFAULT_ATO_SETTING) |
CSP_BITFVAL(MC13783_ADC1_ATOX, MC13783_ADC1_ATOX_DELAY_FIRST) |
CSP_BITFVAL(MC13783_ADC1_ADTRIGIGN, MC13783_ADC1_ADTRIGIGN_IGNORE);
mask = MC13783_ADC_REGISTER_MASK_ALL;
SetRegister(addr, data, mask);
// We select 1 channel and 8 samples. So we set non-automatic
// increment mode.
addr = MC13783_ADC0_ADDR;
data = CSP_BITFVAL(MC13783_ADC0_ADREFMOD, MC13783_ADC0_ENABLE) |
CSP_BITFVAL(MC13783_ADC0_ADREFEN, MC13783_ADC0_ENABLE) |
CSP_BITFVAL(MC13783_ADC0_ADINC1, MC13783_ADC0_ADINC_NO_INCR) |
CSP_BITFVAL(MC13783_ADC0_ADINC2, MC13783_ADC0_ADINC_NO_INCR);
mask = CSP_BITFMASK(MC13783_ADC0_ADINC1) |
CSP_BITFMASK(MC13783_ADC0_ADINC2) |
CSP_BITFMASK(MC13783_ADC0_ADREFMOD) |
CSP_BITFMASK(MC13783_ADC0_ADREFEN);
SetRegister(addr, data, mask);
// Request ADC conversion
if (PmicADCConvert() != PMIC_SUCCESS)
{
ERRORMSG(1, (_T("PmicADCConvert failed!\r\n")));
goto cleanUp;
}
// read out the eight values and place in area pointed to by pData
PmicReadEightValues(pData);
// Disable the ADC
PmicADCDisable();
rc = TRUE;
cleanUp:
// Place the ADC in inactive mode
if (!PMICAdcSetMode(TM_INACTIVE))
{
ERRORMSG(1, (_T("PMICAdcSetMode failed\r\n")));
}
LeaveCriticalSection(&adcCs);
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: PmicIoctlADCGetHandsetCurrent
//
// This function gets handset battery current measurement values.
//
// Parameters:
// pBufIn
// [in] Points to requested ADC converter mode:
// ADC_8CHAN_1X or ADC_1CHAN_8X.
//
// dwLenIn
// [in] Unused.
//
// pBufOut
// [out] pointer to the handset battery current measurement
// value(s).
//
// dwLenOut
// [out] Unused.
//
// Returns:
// TRUE if the successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
static BOOL PmicIoctlADCGetHandsetCurrent(PBYTE pBufIn, DWORD dwLenIn,
PBYTE pBufOut, DWORD dwLenOut)
{
BOOL rc = FALSE;
UINT32 addr, data, mask;
PMIC_ADC_CONVERTOR_MODE mode = *((PMIC_ADC_CONVERTOR_MODE*)pBufIn);
UINT16* pData = (UINT16*)pBufOut;
// Grab critical section, ADC can only handle one set of
// conversions at a time
EnterCriticalSection(&adcCs);
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
addr = MC13783_ADC1_ADDR;
// enable A/D
data = CSP_BITFVAL(MC13783_ADC1_ADEN, MC13783_ADC1_ADEN_ENABLE) |
CSP_BITFVAL(MC13783_ADC1_AD_SEL, MC13783_ADC1_AD_SEL_GROUP0) |
// set ATO delay only before first conversion
CSP_BITFVAL(MC13783_ADC1_ATOX, MC13783_ADC1_ATOX_DELAY_FIRST) |
CSP_BITFVAL(MC13783_ADC1_ATO, MC13783_ADC_DEFAULT_ATO_SETTING) |
CSP_BITFVAL(MC13783_ADC1_ADA1, MC13783_ADC1_ADA_SEL0_BATTISNS) |
// ignore ADTRIG input
CSP_BITFVAL(MC13783_ADC1_ADTRIGIGN, MC13783_ADC1_ADTRIGIGN_IGNORE);
switch (mode)
{
// Set RAND = 0, i.e. read 8 channels, 1 time sample
case ADC_8CHAN_1X: // RAND = 0
data |= CSP_BITFVAL(MC13783_ADC1_RAND, MC13783_ADC1_RAND_8CHAN_1X);
break;
// Set RAND = 1, i.e. read 1 channel, 8 times sample
case ADC_1CHAN_8X: // RAND = 1
data |= CSP_BITFVAL(MC13783_ADC1_RAND, MC13783_ADC1_RAND_1CHAN_8X);
break;
}
mask = MC13783_ADC_REGISTER_MASK_ALL;
SetRegister(addr, data, mask);
addr = MC13783_ADC0_ADDR;
data = CSP_BITFVAL(MC13783_ADC0_ADINC1, MC13783_ADC0_ADINC_NO_INCR) |
CSP_BITFVAL(MC13783_ADC0_ADINC2, MC13783_ADC0_ADINC_NO_INCR) |
CSP_BITFVAL(MC13783_ADC0_BATICON, MC13783_ADC0_ENABLE);
mask = CSP_BITFMASK(MC13783_ADC0_ADINC1) |
CSP_BITFMASK(MC13783_ADC0_ADINC2) |
CSP_BITFMASK(MC13783_ADC0_BATICON);
SetRegister(addr, data, mask);
// Request ADC conversion
if (PmicADCConvert() != PMIC_SUCCESS)
{
ERRORMSG(1, (_T("PmicADCConvert failed!\r\n")));
goto cleanUp;
}
// When in this mode, we only return one value (BATTISNS)
if (mode == ADC_8CHAN_1X)
{
// Set reading channel to ADA
addr = MC13783_ADC1_ADDR;
data = CSP_BITFVAL(MC13783_ADC1_ASC, MC13783_ADC1_ASC_ADC_IDLE) |
CSP_BITFVAL(MC13783_ADC1_ADA1, MC13783_ADC1_ADA_SEL0_BATTISNS);
mask = CSP_BITFMASK(MC13783_ADC1_ADA1) |
CSP_BITFMASK(MC13783_ADC1_ASC);
SetRegister(addr, data, mask);
// Read channel data
addr = MC13783_ADC2_ADDR;
GetRegist
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -