Win CE5.0背光驱动

 在大多2440开发板BSP中的SMDK2440/DRIVERS/backlite目录下一般都有背光驱动。在注册表中添加如下函数的时候,开机时确实可以打印"!!!!!!!!!!!! BACKLIGHT ON !!!!!!!!!!!!,如果没有操作大概1分钟后也可以打印!!!!!!!!!!!! BACKLIGHT OFF !!!!!!!!!!!!。但打印("!!!!!!!!!!!! BACKLIGHT OFF !!!!!!!!!!!!后,就算有触发事件(在触摸屏上点击,或者移动鼠标)也不会打印"!!!!!!!!!!!! BACKLIGHT ON !!!!!!!!!!!!。


[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/BAK]
    "Index"=dword:1
    "Prefix"="BAK"
    "Dll"="backlight.dll"
    "Order"=dword:1
    "IClass"="{A32942B7-920C-486b-B0E6-92A702A99B35}" 

 

当你好好分析驱动中的以下这3个Event时:

g_evtSignal[0] = CreateEvent(NULL, FALSE, FALSE, szevtBacklightChange); 
g_evtSignal[1] = CreateEvent(NULL, FALSE, FALSE, szevtUserInput); 
g_evtSignal[BL_POWEREVT] = CreateEvent(NULL, FALSE, FALSE, szevtPowerChanged);

尤其是第二个,好像又没有问题。

其实这个驱动大体是正确的,只是当键盘鼠标或触摸屏输入时候gwes 发送“PowerManager/ActivityTimer/UserActivity” event,而不是原驱动中的“("UserInputEvent");”修改后的源程序如下(SMDK2440/DRIVERS/backlite目录下bak_hw.cpp文件)。

 

 

  1. //
  2. // Copyright (c) Microsoft Corporation.  All rights reserved.
  3. //
  4. //
  5. // Use of this source code is subject to the terms of the Microsoft end-user
  6. // license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
  7. // If you did not accept the terms of the EULA, you are not authorized to use
  8. // this source code. For a copy of the EULA, please see the LICENSE.RTF on your
  9. // install media.
  10. //
  11. /*
  12. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  13. ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  14. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  15. PARTICULAR PURPOSE.
  16. */
  17. #include <windows.h>
  18. #include <nkintr.h>
  19. #include <pm.h>
  20. #include "s2440.h"
  21. #include <nkintr.h>
  22. #include "oalintr.h"
  23. #include "drv_glob.h"
  24. #include "pmplatform.h"
  25. #include "bak_hw.h"
  26. //  Globals
  27. const TCHAR szevtBacklightChange[] = TEXT("BackLightChangeEvent");
  28. const TCHAR szevtPowerChanged[] = TEXT("PowerChangedEvent");
  29. const TCHAR szevtUserInput[] = TEXT("PowerManager/ActivityTimer/UserActivity");
  30. const TCHAR szregRootKey[] = TEXT("ControlPanel//Backlight");
  31. const TCHAR szregBatteryTimeout[] = TEXT("BatteryTimeout");
  32. const TCHAR szregACTimeout[] = TEXT("ACTimeout");
  33. const TCHAR szregBatteryAuto[] = TEXT("BacklightOnTap");
  34. const TCHAR szregACAuto[] = TEXT("ACBacklightOnTap");
  35. HANDLE   g_evtSignal[NUM_EVENTS];
  36. /* GPIO 寄存器对应的虚拟地址 */
  37. volatile IOPreg * v_pIOPregs = (IOPreg * )IOP_BASE;
  38. //  Global structure
  39. BLStruct g_BLInfo;
  40. // Perform all one-time initialization of the backlight
  41. //
  42. BOOL 
  43. BacklightInitialize()
  44. {
  45.     BOOL    bRet = TRUE;
  46.     RETAILMSG(1, (TEXT("BacklightInitialize/r/n")));
  47.     BL_PowerOn(TRUE);
  48.     v_pIOPregs->rGPBCON &=0x3C03FF;
  49.     v_pIOPregs->rGPBCON |=0x15400;
  50.     v_pIOPregs->rGPBUP &=0x61F;
  51.     return bRet;
  52. }
  53. //  Utility function to read from registry for the parameters
  54. void BL_ReadRegistry(BLStruct *pBLInfo)
  55. {
  56.     HKEY    hKey;
  57.     LONG    lResult;
  58.     DWORD   dwType;
  59.     DWORD   dwVal;
  60.     DWORD   dwLen;
  61.     lResult = RegOpenKeyEx(HKEY_CURRENT_USER, szregRootKey, 0, KEY_ALL_ACCESS, &hKey);
  62.     if(ERROR_SUCCESS == lResult) {
  63.         dwType = REG_DWORD;
  64.         dwLen = sizeof(DWORD);
  65.         lResult = RegQueryValueEx(hKey, szregBatteryTimeout, NULL, &dwType, 
  66.                                   (LPBYTE)&dwVal, &dwLen);
  67.         if(ERROR_SUCCESS == lResult) {
  68.             pBLInfo->m_dwBatteryTimeout = dwVal;
  69.         }
  70.         lResult = RegQueryValueEx(hKey, szregACTimeout, NULL, &dwType, (LPBYTE)&dwVal,
  71.                                   &dwLen);
  72.         if(ERROR_SUCCESS == lResult) {
  73.             pBLInfo->m_dwACTimeout = dwVal;
  74.         }
  75.         lResult = RegQueryValueEx(hKey, szregBatteryAuto, NULL, &dwType, (LPBYTE)&dwVal,
  76.                                   &dwLen);
  77.         if(ERROR_SUCCESS == lResult) {
  78.             pBLInfo->m_bBatteryAuto = (BOOL) dwVal;
  79.         }
  80.         lResult = RegQueryValueEx(hKey, szregACAuto, NULL, &dwType, (LPBYTE)&dwVal,
  81.                                   &dwLen);
  82.         if(ERROR_SUCCESS == lResult) {
  83.             pBLInfo->m_bACAuto = (BOOL) dwVal;
  84.         }
  85.         RegCloseKey(hKey);
  86.     }
  87.     else {
  88.         RETAILMSG(1, (TEXT("BAK : HKEY_CURRENT_USER//%s key doesn't exist!/r/n"), szregRootKey));
  89.     }
  90. }
  91. // uninitialize the backlight
  92. void BL_Deinit()
  93. {
  94.     int i;
  95.     RETAILMSG(1, (TEXT("BAK : BL_Deinit!/r/n")));
  96.     //  Clean up
  97.     for(i=0; i<NUM_EVENTS; i++) {
  98.         if(g_evtSignal[i]) {
  99.             CloseHandle(g_evtSignal[i]);
  100.         }
  101.     }
  102. }
  103. //
  104. // initialize the backlight
  105. //
  106. BOOL BL_Init()
  107. {
  108.     //  Set up all the events we need. 
  109.     g_evtSignal[0] = CreateEvent(NULL, FALSE, FALSE, szevtBacklightChange);
  110.     g_evtSignal[1] = CreateEvent(NULL, FALSE, FALSE, szevtUserInput);
  111.     g_evtSignal[BL_POWEREVT] = CreateEvent(NULL, FALSE, FALSE, szevtPowerChanged);
  112.     if(!g_evtSignal[0] || !g_evtSignal[1] || !g_evtSignal[2]) {
  113.         BL_Deinit();
  114.         return FALSE;
  115.     }
  116.     DEBUGMSG (1,(TEXT("BL_Init()  and  SetGPIO/n/r"))); 
  117.     return TRUE;
  118. }
  119. //
  120. //  find out if AC power is plugged in
  121. //
  122. BOOL IsACOn()
  123. {
  124. //    if (g_pDriverGlobals->power.ACLineStatus == AC_LINE_ONLINE)
  125. //      return TRUE;
  126. //    else
  127.         return FALSE;
  128. }
  129. //
  130. // turn on/off the backlight
  131. //
  132. void BL_On(BOOL bOn)
  133. {
  134.     if(bOn) {
  135.         if (g_BLInfo.m_dwStatus != BL_ON)
  136.         {
  137.             g_BLInfo.m_dwStatus = BL_ON;
  138.             v_pIOPregs->rGPBDAT&=0x6FF;//打开LED
  139.             RETAILMSG(1,(TEXT("!!!!!!!!!!!! BACKLIGHT ON !!!!!!!!!!!!/r/n")));
  140.         }
  141.     }
  142.     else {
  143.         if (g_BLInfo.m_dwStatus != BL_OFF)
  144.         {
  145.             g_BLInfo.m_dwStatus = BL_OFF;
  146.             v_pIOPregs->rGPBDAT|=0x100;//关闭LED
  147.             RETAILMSG(1,(TEXT("!!!!!!!!!!!! BACKLIGHT OFF !!!!!!!!!!!!/r/n")));
  148.         }
  149.     }
  150. }
  151. //
  152. // restore power to the backlight
  153. //
  154. void BL_PowerOn(BOOL bInit)
  155. {
  156.     //
  157.     //  Add power-on GPIO register setting
  158.     //
  159.     BL_On(TRUE);
  160. }
  161. // The backlight handling is done by a thread, which monitors those 
  162. // three event and performs some actions based on the parameters specified
  163. // in HKLM/ControlPanel/Backlight
  164. //
  165. // backlight service thread
  166. //
  167. DWORD BL_MonitorThread(PVOID pParms)
  168. {
  169.     DWORD   dwResult;
  170.     DWORD   dwTimeout;
  171.     
  172.     //  Initialization stuff is here
  173.     //
  174.     //  Initialize the events
  175.     //  Initialize the BLInfo data structure
  176.     //  Those are default values. Modify them if necessary
  177.     g_BLInfo.m_bACAuto = TRUE;
  178.     g_BLInfo.m_bBatteryAuto = TRUE;
  179.     g_BLInfo.m_dwBatteryTimeout = 20;   // 20 Seconds
  180.     g_BLInfo.m_dwACTimeout = 60;       // 1 minutes
  181.     //  Now read from the registry to see what they say
  182.     BL_ReadRegistry(&g_BLInfo);
  183.     //  Initialize BL
  184.     if(!BL_Init()) {
  185.         RETAILMSG(1, (TEXT("BL_Init() Failed! Exit from BL_MonitorThread!/r/n")));
  186.         return 0;
  187.     }
  188.     while(1) {
  189.         __try { 
  190.             //  If we are using AC now, use m_dwACTimeout as the timeout
  191.             //  otherwise, use m_dwBatteryTimeout
  192.             if(IsACOn()) {
  193.                 dwTimeout = g_BLInfo.m_dwACTimeout * 1000;
  194.             }
  195.             else {
  196.                 dwTimeout = g_BLInfo.m_dwBatteryTimeout * 1000;
  197.             }
  198.             //  However, if user wants BL on all the time, we have to let him
  199.             //  do that. Or if we come back here, and BL is off, we want to 
  200.             //  put this thread to sleep until other event happens.
  201.             if(dwTimeout == 0 || g_BLInfo.m_dwStatus == BL_OFF) {
  202.                 dwTimeout = INFINITE;
  203.             }
  204.             //  Now let's wait for either there is an update on registry, or
  205.             //  there is user action on the device, or there is activity on
  206.             //  AC power supply.
  207.             dwResult = WaitForMultipleObjects(NUM_EVENTS, &g_evtSignal[0], FALSE, dwTimeout);
  208.             //  If we are signaled by registry event
  209.             if(WAIT_OBJECT_0 == dwResult) {
  210.                 //  All we need to do is to read from registry and update the tick count
  211.                 BL_ReadRegistry(&g_BLInfo);
  212.                 RETAILMSG(1, (TEXT("BackLightChangeEvent! m_dwACTimeout=%d, m_dwBatteryTimeout=%d/r/n"),g_BLInfo.m_dwACTimeout,g_BLInfo.m_dwBatteryTimeout));
  213.                 //  Always turn on the Backlight after a change to registry
  214.                 BL_On(TRUE);
  215.             }
  216.             else if(dwResult == WAIT_OBJECT_0+1) {
  217.                 //  User activity, depending on the situation, we may / may not update 
  218.                 //  the tick count
  219.                 //RETAILMSG(1, (TEXT("2...WAIT_OBJECT_0+1!/r/n")));
  220.                 if(IsACOn()) {
  221.                     if(g_BLInfo.m_bACAuto) {
  222.                         //  Turn on backlight
  223.                         BL_On(TRUE);
  224.                     }
  225.                 }
  226.                 else {
  227.                     if(g_BLInfo.m_bBatteryAuto) {
  228.                         BL_On(TRUE);
  229.                     }
  230.                 }  
  231.             }
  232.             else if(dwResult == WAIT_OBJECT_0+2) {
  233.                 //  When AC is plugged or un-plugged, we don't really need to do anything
  234.                 //  We continue the loop. The correct timeout value will be assigned at
  235.                 //  the top of the while loop.
  236.                 RETAILMSG(1, (TEXT("BackLight Thread: power changed!/r/n")));
  237.             }
  238.             else if(dwResult == WAIT_TIMEOUT) {
  239.                 //  Time out, let's turn the device off
  240.                 RETAILMSG(1, (TEXT("Timeout, turn off the backlight!/r/n")));
  241.                 BL_On(FALSE);
  242.             }
  243.         }
  244.         __except(EXCEPTION_EXECUTE_HANDLER){
  245.             // do nothing
  246.             RETAILMSG(1, (TEXT("an exception is raised in BL_MonitorThread... /r/n")));
  247.         }
  248.     }
  249. }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值