如何在windows CE添加LED驱动。

 下面已QQ2440V3开发板的LED控制为例

一、驱动部分

打开目录/WINCE500/PLATFORM/smdk2440/GWE/NLEDDRV,编辑nleddrv.cpp文件,改文件中已有几个函数,我们只需要将GPIO相关设置输入即可。

代码如下:

//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name: 

Abstract: 
    Provides control of the notification LED.
   
Functions:


Notes:


--*/

#include <windows.h>
#include <nled.h>
#include <led_drvr.h>
#include <types.h>
#include <s2440.h>

/*
 PeRP HAS NO LED&apos;s so this module is easy...
*/


/*++

 @doc EXTERNAL DRIVERS

 @func BOOL | NLedDriverGetDeviceInfo | Retrieves information about the notification LED.

 @parm INT | nInfoId |  Id number of the information to retrieve.

 @parm PVOID | pOutput | Buffer to put the information.

 @comm This is the function interface to the driver..

 @xref
--*/
BOOL WINAPI NLedDriverGetDeviceInfo(INT nInfoId,  PVOID pOutput)
{
 if ( nInfoId == NLED_COUNT_INFO_ID )
  {
  struct NLED_COUNT_INFO *p = (struct NLED_COUNT_INFO*)pOutput;

  p -> cLeds = 4;
  return TRUE;
  }

 SetLastError(ERROR_GEN_FAILURE);
 return FALSE;
}


/*++

 @doc EXTERNAL DRIVERS

 @func BOOL | NLedDriverSetDevice | Changes setting of the notification LED.

 @parm INT | nInfoId |  Id number of the setting.

 @parm PVOID | pInput | Buffer which has the new settings.

 @comm This is the function interface to the driver..

 @xref
--*/
BOOL WINAPI NLedDriverSetDevice(INT nInfoId, PVOID pInput)
{
 volatile IOPreg * s2410IOP = (IOPreg * )IOP_BASE;
 struct NLED_SETTINGS_INFO *p = (struct NLED_SETTINGS_INFO*)pInput;
 if((p->LedNum)==0)
 {
  if((p->OffOnBlink)==0)
  {
   s2410IOP->rGPBDAT|=0x100;
   return TRUE;
  }
  else if((p->OffOnBlink)==1)
  {
   s2410IOP->rGPBDAT&=0x6FF;
   return TRUE;
  }
 }
 else if((p->LedNum)==1)
 {
  if((p->OffOnBlink)==0)
  {
   s2410IOP->rGPBDAT|=0x80;
   return TRUE;
  }
  else if((p->OffOnBlink)==1)
  {
   s2410IOP->rGPBDAT&=0x77F;
   return TRUE;
  }
 }
 else if((p->LedNum)==2)
 {
  if((p->OffOnBlink)==0)
  {
   s2410IOP->rGPBDAT|=0x40;
   return TRUE;
  }
  else if((p->OffOnBlink)==1)
  {
   s2410IOP->rGPBDAT&=0x7BF;
   return TRUE;
  }
 }
 else if((p->LedNum)==0)
 {
  if((p->OffOnBlink)==0)
  {
   s2410IOP->rGPBDAT|=0x20;
   return TRUE;
  }
  else if((p->OffOnBlink)==1)
  {
   s2410IOP->rGPBDAT&=0x7DF;
   return TRUE;
  }
 }
 SetLastError(ERROR_GEN_FAILURE);
 return FALSE;
}


/*++

 @doc     EXTERNAL DRIVERS

 @func    VOID | NLedDriverPowerDown | Power up/down notification to the LED device(s).

 @parm    BOOL | power_down | TRUE = Power down, FALSE = power up.

--*/
VOID NLedDriverPowerDown(BOOL power_down)
{
 return;
}

 


BOOL NLedDriverInitialize(VOID)
{
  
 RETAILMSG(1,(TEXT("NLedDriverInitialize")));
 int i;
 volatile IOPreg *s2410IOP = (IOPreg *)IOP_BASE;
 s2410IOP->rGPBCON &=0x3C03FF;
 s2410IOP->rGPBCON |=0x15400;
 s2410IOP->rGPBUP &=0x61F;
 s2410IOP->rGPBDAT &=0x61F;
 for(i=0;i<100000;i++);
 s2410IOP->rGPBDAT|=0x1E0;
 return TRUE;
}


/*++

 @doc     EXTERNAL DRIVERS

 @func    BOOL |  NLedDriverDllEntry | This is the entry/exit point for the dll.

 @parm    HANDLE | hinstDll    | Instance handle of the Dll.

 @parm    DWORD  | fdwReason   | The reason why the function was called.

 @parm    LPVOID | lpvReserved | Reserved, not used.

 @rdesc   If the function was successful TRUE is returned; otherwise, FALSE.

--*/
BOOL
NLedDriverDllEntry(
   HANDLE hinstDll,
   DWORD fdwReason,
   LPVOID lpvReserved
   )
{
 return TRUE;
}

///

sources文件修改如下

!if 0
Copyright (c) Microsoft Corporation.  All rights reserved.
!endif
!if 0
Use of this source code is subject to the terms of the Microsoft end-user
license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
If you did not accept the terms of the EULA, you are not authorized to use
this source code. For a copy of the EULA, please see the LICENSE.RTF on your
install media.
!endif

SYNCHRONIZE_DRAIN=1

TARGETNAME=nleddrv
RELEASETYPE=PLATFORM
TARGETTYPE=LIBRARY
SOURCES=nleddrv.cpp
INCLUDES=../../inc

 

二、打开EVC,编写控制软件。

1、首先添加两个外部变量

extern "C" {
BOOL WINAPI NLedGetDeviceInfo( UINT nInfoId, void *pOutput );
BOOL WINAPI NLedSetDevice( UINT nDeviceId, void *pInput );
//BOOL NLedDriverInitialize();
};

2、在程序中添加下面两个函数。

//下面的函数可以取得设备上LED总数
int CCtLEDDlg::GetLedCount()
{
 NLED_COUNT_INFO nci;
 int wCount = 0;
    if(NLedGetDeviceInfo(NLED_COUNT_INFO_ID, (PVOID) &nci))
   wCount = (int) nci.cLeds;
    return wCount;
}

//下面的函数设置LED状态
void CCtLEDDlg::SetLedStatus(int wLed, int wStatus)
{
 NLED_SETTINGS_INFO nsi;     
 nsi.LedNum = (INT) wLed;
 nsi.OffOnBlink = (INT) wStatus;
 NLedSetDevice(NLED_SETTINGS_INFO_ID, &nsi);
}

3. 获得LED的数量

void CCtLEDDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 CString str;
 int cLED=GetLedCount();
 str.Format(L"%d",cLED);
 MessageBox(str);
}

4、打开和关闭LED

SetLedStatus(1, 1);//打开LED

SetLedStatus(1, 0);//关闭LED

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值