📄 plato_nled.cpp
字号:
ApplyCurrentLEDSettings(RED_LED_INDEX);
ApplyCurrentLEDSettings(KEYBOARD_BACKLIGHT_INDEX);
ApplyCurrentLEDSettings(VIBRATOR_INDEX);
fRetVal = TRUE;
ExitInit:
if(!fRetVal)
{
NLedDriverDeInitialize();
}
return (fRetVal);
}
// The NLED MDD calls this routine to deinitialize the underlying NLED
// hardware as the NLED driver is unloaded. It should return TRUE if
// successful. If there's a problem this routine should return FALSE
// and call SetLastError() to pass back the reason for the failure.
BOOL WINAPI
NLedDriverDeInitialize(
VOID
)
{
DEBUGMSG(ZONE_PDD, (_T("NLedDriverDeInitialize: invoked\r\n")));
if(g_pGPIORegisters)
{
MmUnmapIoSpace( (PVOID) g_pGPIORegisters, sizeof(XLLP_GPIO_T));
g_pGPIORegisters = NULL;
}
if(INVALID_HANDLE_VALUE != g_hPCF)
{
CloseHandle(g_hPCF);
g_hPCF = INVALID_HANDLE_VALUE;
}
if(g_hKbdBacklightThread)
{
g_fExitKbdBacklightThread = TRUE;
SetEvent(g_hKbdBacklightUpdateEvent);
WaitForSingleObject(g_hKbdBacklightThread, INFINITE);
g_hKbdBacklightThread = NULL;
}
if(g_hKbdBacklightUpdateEvent)
{
CloseHandle(g_hKbdBacklightUpdateEvent);
g_hKbdBacklightUpdateEvent = NULL;
}
return (TRUE);
}
// This routine retrieves information about the NLED device(s) that
// this driver supports. The nInfoId parameter indicates what specific
// information is being queried and pOutput is a buffer to be filled in.
// The size of pOutput depends on the type of data being requested. This
// routine returns TRUE if successful, or FALSE if there's a problem -- in
// which case it also calls SetLastError() to pass back more complete
// error information. The NLED MDD invokes this routine when an application
// calls NLedGetDeviceInfo().
BOOL
WINAPI
NLedDriverGetDeviceInfo(
INT nInfoId,
PVOID pOutput
)
{
BOOL fRetVal = TRUE;
SETFNAME(_T("NLedDriverGetDeviceInfo"));
//
// No need for __try __except, that is handled at the mdd layer.
//
switch(nInfoId)
{
case NLED_COUNT_INFO_ID:
{
struct NLED_COUNT_INFO *p = (struct NLED_COUNT_INFO*) pOutput;
p -> cLeds = NUM_LEDS;
}
break;
case NLED_SUPPORTS_INFO_ID:
{
struct NLED_SUPPORTS_INFO *p = (struct NLED_SUPPORTS_INFO*)pOutput;
if(MAX_INDEX_LEDS < p->LedNum)
{
fRetVal = FALSE;
SetLastError(ERROR_INVALID_PARAMETER);
}
else
{
memcpy(pOutput, &g_LEDSupportsInfo[p->LedNum], sizeof(NLED_SUPPORTS_INFO));
}
}
break;
case NLED_SETTINGS_INFO_ID:
{
struct NLED_SETTINGS_INFO *p = (struct NLED_SETTINGS_INFO*)pOutput;
if(MAX_INDEX_LEDS < p->LedNum)
{
fRetVal = FALSE;
SetLastError(ERROR_INVALID_PARAMETER);
}
else
{
memcpy(pOutput, &g_CurrentLEDSettings[p->LedNum], sizeof(NLED_SETTINGS_INFO));
}
}
break;
default:
{
fRetVal = FALSE;
SetLastError(ERROR_INVALID_PARAMETER);
}
}
DEBUGMSG(ZONE_PDD || (!fRetVal && ZONE_WARN),
(_T("%s: returning %d\r\n"), pszFname, fRetVal));
return (fRetVal);
}
BOOL CheckBlinkTimings(struct NLED_SETTINGS_INFO *p)
{
BOOL fRetVal = FALSE;
SETFNAME(_T("CheckBlinkTimings"));
if(2 != p->OffOnBlink)
{
// don't bother checking
fRetVal = TRUE;
goto CheckBlinkTimingsExit;
}
if((TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustTotalCycleTime) &&
(0 >= p->TotalCycleTime))
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) Negitive or Zero TotalCycleTime (%duSec) time.\r\n"), pszFname, p->LedNum, p->TotalCycleTime));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
if((TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustOnTime) &&
(0 >= p->OnTime))
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) Negitive or Zero OnTime (%duSec) time.\r\n"), pszFname, p->LedNum, p->OnTime));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
if((TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustOffTime) &&
(0 >= p->OffTime))
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) Negitive or Zero OffTime (%duSec) time.\r\n"), pszFname, p->LedNum, p->OffTime));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
if(TRUE == g_LEDSupportsInfo[p->LedNum].fMetaCycleOn)
{
if(0 > p->MetaCycleOn)
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) Negitive MetaCycleOn (%duSec) time.\r\n"), pszFname, p->LedNum, p->MetaCycleOn));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
}
else
{
if(0 != p->MetaCycleOn)
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) MetaCycle not supported and MetaCycleOn is set (%duSec).\r\n"), pszFname, p->LedNum, p->MetaCycleOn));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
}
if(TRUE == g_LEDSupportsInfo[p->LedNum].fMetaCycleOff)
{
if(0 > p->MetaCycleOff)
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) Negitive MetaCycleOff (%duSec) time.\r\n"), pszFname, p->LedNum, p->MetaCycleOff));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
}
else
{
if(0 != p->MetaCycleOff)
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) MetaCycle not supported and MetaCycleOff is set (%duSec).\r\n"), pszFname, p->LedNum, p->MetaCycleOff));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
}
// *This code relies on all the variables
// fAdjustTotalCycleTime, fAdjustOnTime or fAdjustOffTime
// never to be set to TRUE simultaionously.
if((TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustTotalCycleTime) &&
(TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustOnTime))
{
if(p->TotalCycleTime < p->OnTime)
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) OnTime (%duSec) greater TotalCycleTime (%duSec)\r\n"), pszFname, p->LedNum, p->OnTime, p->TotalCycleTime));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
}
else if((TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustTotalCycleTime) &&
(TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustOffTime))
{
if(p->TotalCycleTime < p->OffTime)
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) OffTime (%duSec) greater TotalCycleTime (%duSec)\r\n"), pszFname, p->LedNum, p->OffTime, p->TotalCycleTime));
SetLastError(ERROR_INVALID_PARAMETER);
goto CheckBlinkTimingsExit;
}
}
fRetVal = TRUE;
CheckBlinkTimingsExit:
return fRetVal;
}
// This routine changes the configuration of an LED. The nInfoId parameter
// indicates what kind of configuration information is being changed.
// Currently only the NLED_SETTINGS_INFO_ID value is supported. The pInput
// parameter points to a buffer containing the data to be updated. The size
// of the buffer depends on the value of nInfoId. This routine returns TRUE
// if successful or FALSE if there's a problem -- in which case it also calls
// SetLastError(). The NLED MDD invokes this routine when an application
// calls NLedSetDevice().
BOOL
WINAPI
NLedDriverSetDevice(
INT nInfoId,
PVOID pInput
)
{
BOOL fRetVal = FALSE;
SETFNAME(_T("NLedDriverSetDevice"));
if(NLED_SETTINGS_INFO_ID == nInfoId)
{
struct NLED_SETTINGS_INFO *p = (struct NLED_SETTINGS_INFO*)pInput;
//
// No need for __try __except, that is handled at the mdd layer.
//
if(MAX_INDEX_LEDS < p->LedNum)
{
DEBUGMSG(ZONE_WARN,
(_T("%s: Invalid LED index %d\r\n"), pszFname, p->LedNum));
SetLastError(ERROR_INVALID_PARAMETER);
}
else if((0 > p->OffOnBlink) || (2 < p->OffOnBlink))
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) Invalid OffOnBlink state 0x%x\r\n"), pszFname, p->LedNum, p->OffOnBlink));
SetLastError(ERROR_INVALID_PARAMETER);
}
else if((2 == p->OffOnBlink) &&
(-1 == g_LEDSupportsInfo[p->LedNum].lCycleAdjust))
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) Vibrator does not support blinking\r\n"), pszFname, p->LedNum));
SetLastError(ERROR_INVALID_PARAMETER);
}
else if((p->OnTime % g_LEDSupportsInfo[p->LedNum].lCycleAdjust) ||
(p->OffTime % g_LEDSupportsInfo[p->LedNum].lCycleAdjust))
{
DEBUGMSG(ZONE_WARN,
(_T("%s: LED(%d) Invalid Granularity of OnTime (%duSec) or OffTime(%duSec) time.\r\n"), pszFname, p->LedNum, p->OnTime, p->OffTime));
SetLastError(ERROR_INVALID_PARAMETER);
}
else if(CheckBlinkTimings(p))
{
// its OK save the settings
memcpy(&g_CurrentLEDSettings[p->LedNum], pInput, sizeof(NLED_SETTINGS_INFO));
fRetVal = TRUE;
}
// Cleanup:
//nledtest expects that if metacycles are not supported
//that the saved LED state clear any metacycle data
//
if((FALSE == g_LEDSupportsInfo[p->LedNum].fMetaCycleOn) &&
(0 != p->MetaCycleOn))
{
g_CurrentLEDSettings[p->LedNum].MetaCycleOn = 0;
}
if((FALSE == g_LEDSupportsInfo[p->LedNum].fMetaCycleOff) &&
(0 != p->MetaCycleOff))
{
g_CurrentLEDSettings[p->LedNum].MetaCycleOff = 0;
}
//nledtest expects all blink variables stored for the LED state to add up
//
// *This code relies on all the variables
// fAdjustTotalCycleTime, fAdjustOnTime or fAdjustOffTime
// never to be set to TRUE simultaionously.
if((TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustTotalCycleTime) &&
(TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustOnTime))
{
g_CurrentLEDSettings[p->LedNum].OffTime = g_CurrentLEDSettings[p->LedNum].TotalCycleTime - g_CurrentLEDSettings[p->LedNum].OnTime;
}
else if((TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustTotalCycleTime) &&
(TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustOffTime))
{
g_CurrentLEDSettings[p->LedNum].OnTime = g_CurrentLEDSettings[p->LedNum].TotalCycleTime - g_CurrentLEDSettings[p->LedNum].OffTime;
}
else if((TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustOnTime) &&
(TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustOffTime))
{
g_CurrentLEDSettings[p->LedNum].TotalCycleTime = g_CurrentLEDSettings[p->LedNum].OnTime + g_CurrentLEDSettings[p->LedNum].OffTime;
}
else if(TRUE == g_LEDSupportsInfo[p->LedNum].fAdjustTotalCycleTime)
{
//duty cycle not supported
g_CurrentLEDSettings[p->LedNum].OnTime = 0;
g_CurrentLEDSettings[p->LedNum].OffTime = 0;
}
else
{
//blinking not supported
g_CurrentLEDSettings[p->LedNum].TotalCycleTime = 0;
g_CurrentLEDSettings[p->LedNum].OnTime = 0;
g_CurrentLEDSettings[p->LedNum].OffTime = 0;
}
//apply the settings
if(fRetVal)
{
ApplyCurrentLEDSettings(p->LedNum);
}
}
return (fRetVal);
}
// This routine is invoked by the driver MDD when the system suspends or
// resumes. The power_down flag indicates whether the system is powering
// up or powering down.
VOID WINAPI
NLedDriverPowerDown(
BOOL power_down
)
{
XLLP_UINT32_T pins[3] = {2, KEYBOARD_BACKLIGHT_GPIO_PIN, VIBRATE_GPIO_PIN};
if(g_pGPIORegisters)
{
if(power_down)
{
//ensure keyboard backlight and vibrator are off on powerdown
XllpGpioSetOutput0(g_pGPIORegisters, pins);
}
else
{
//re-apply keyboard backlight and vibrator settings
ApplyCurrentLEDSettings(KEYBOARD_BACKLIGHT_INDEX);
ApplyCurrentLEDSettings(VIBRATOR_INDEX);
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -