本帖最后由 forlinx2013 于 2014-1-24 09:42 编辑
欢迎大家来到飞凌爱板网专区,对嵌入式技术感兴趣的朋友不妨多多关注一下,我们提供了公司所有开发板的所有资料,也会更新大量技术文章,欢迎大家一块学习提高!!!
Wince 下的红外驱动,不加任何遥控协议,只是一个简单的功能测试,升级版本,等下一次更新在发给大家,好了 废话少说现在告诉大家方法。 本产品以ok6410为例,介绍如何新建和修改ce6下的红外驱动和红外测试程序 只要按照步骤执行下去,即可建立一个红外驱动。并做驱动介绍。完成驱动开发的准备工作。 硬件平台:飞凌OK6410-A 操作系统:飞凌光盘中的BSP,WINCE6.0 编译工具:VS2005 + WINCE6.0 + BSP 在上述所有工具安装完成后,直接用BSP的快捷方式打开。 驱动主要在文件夹PLATFORM/SMDK6410/src/drivers下 建立过程: 1.在drivers文件夹上点击右键,选择add->New Source Subproject->WCE Dynamic-Link Library在name框中输入IRS,下一步。 选择A simple Windows Embedded CE DLL subproject完成。 2,打开PLATFORM/SMDK6410/src/drivers/IRS文件夹 里面已经替你建好了如下文件:makefile,source,StdAfx.cpp,StdAfx.h,XXX.cpp,XXX.def 用文本编辑器打开XXX.def文件,添加如下代码 LIBRARY IRS_DRV EXPORTS IRS_Init
IRS_Deinit
IRS_Open
IRS_Close
IRS_Read
IRS_Write
IRS_Seek
IRS_PowerDown
IRS_PowerUp
IRS_IOControl 3.打开IRS.cpp文件加入如下代码:
#include "stdafx.h" #include <s3c6410.h> #include <DrvLib.h> #include <winuser.h>
#include "IRS.h"
// GPIO virtual address static volatile S3C6410_GPIO_REG *v_pIOPregs ;
//----------------------------------------------------------------------------// // DLL entry // //----------------------------------------------------------------------------// BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: OutputDebugString(L"\nIRS - DLL_PROCESS_ATTACH\n"); RETAILMSG(1,(TEXT("IRS - DLL_PROCESS_ATTACH\n"))); break; case DLL_PROCESS_DETACH: //RETAILMSG(1,(TEXT("LED - DLL_PROCESS_DETACH\n"))); //OutputDebugString(L"LED - DLL_PROCESS_DETACH\n"); break; case DLL_THREAD_ATTACH: //RETAILMSG(1,(TEXT("LED - DLL_THREAD_ATTACH\n"))); //OutputDebugString(L"LED - DLL_THREAD_ATTACH\n"); break; case DLL_THREAD_DETACH: //RETAILMSG(1,(TEXT("LED - DLL_THREAD_DETACH\n"))); //OutputDebugString(L"LED - DLL_THREAD_DETACH\n"); break; default: break; }
return TRUE; }
//----------------------------------------------------------------------------// // IRS initial // //----------------------------------------------------------------------------// DWORD IRS_Init(LPCTSTR pContext, LPCVOID lpvBusContext) { //Virtual address mapping v_pIOPregs = (volatile S3C6410_GPIO_REG*)DrvLib_MapIoSpace(S3C6410_BASE_REG_PA_GPIO, sizeof(S3C6410_GPIO_REG), FALSE); return 1; }
//----------------------------------------------------------------------------// // IRS deinit // //----------------------------------------------------------------------------// BOOL IRS_Deinit(DWORD hDeviceContext) { VirtualFree((PVOID)v_pIOPregs, 0, MEM_RELEASE); v_pIOPregs = NULL; return TRUE; }
//----------------------------------------------------------------------------// // IRS open // //----------------------------------------------------------------------------// DWORD IRS_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode) { OutputDebugString(L"IRS - IRS Open\n"); return 1; }
//----------------------------------------------------------------------------// // IRS close // //----------------------------------------------------------------------------// BOOL IRS_Close(DWORD hOpenContext) { OutputDebugString(L"IRS - IRS Close\n"); return TRUE; }
//----------------------------------------------------------------------------// // IRS read // //----------------------------------------------------------------------------// DWORD IRS_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count) { return 1; }
//----------------------------------------------------------------------------// // IRS write // //----------------------------------------------------------------------------// DWORD IRS_Write(DWORD hOpenContext, LPCVOID pBuffer, DWORD Count) { return 1; }
//----------------------------------------------------------------------------// // IRS power up // //----------------------------------------------------------------------------// VOID IRS_PowerUp(DWORD hDeviceContext) { }
//----------------------------------------------------------------------------// // IRS down // //----------------------------------------------------------------------------// VOID IRS_PowerDown(DWORD hDeviceContext) { }
//----------------------------------------------------------------------------// // IRS seek // //----------------------------------------------------------------------------// DWORD IRS_Seek(DWORD hOpenContext, long Amount, DWORD Type) { return 0; }
//----------------------------------------------------------------------------// // IRS IO control // //----------------------------------------------------------------------------// BOOL IRS_IOControl(DWORD Handle, DWORD dwIoControlCode, PBYTE pInBuf, DWORD nInBufSize, PBYTE pOutBuf, DWORD nOutBufSize, PDWORD pBytesReturned) { switch (dwIoControlCode) {
case IOCTL_COL0: v_pIOPregs->GPECON &= (~0xf); //直接将gpe1配置成输入,然后读取他的状态,放到pOutBuf[0] if ((v_pIOPregs->GPEDAT) & (0x01<< 1)) { pOutBuf[0] = 1;
} else { pOutBuf[0] = 0;
} break;
return TRUE; }
} 4.在IRS.h中添加 #define IOCTL_COL0 0x1000
5.添加C:\WINCE600\PLATFORM\SMDK6410\FILES\platform.reg
;================ IRS =========== [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\IRS] " refix"="IRS" "Dll"="IRS.dll" "Order"=dword:35 "Index"=dword:1
6.添加C:\WINCE600\PLATFORM\SMDK6410\FILES\platform.bib
;------------- IRS Driver ------------------------------------------------------------- ;IF BSP_NOIRS ! IRS.dll $(_FLATRELEASEDIR)\IRS.dll NK SHK ;ENDIF BSP_NOIRS ! ;--------------------------------------------------------------------------------------- 7.打开PLATFORM/SMDK6410/src/drivers/IRS文件夹,打开irs文件夹,找到sourse文件,用一下代码替换原有代码: !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
!if "$(BSP_NOLED)" == "1" SKIPBUILD=1 !endif
RELEASETYPE=PLATFORM
PREPROCESSDEFFILE=1
TARGETNAME=IRS
SOURCES= \ IRS.cpp \
TARGETTYPE=DYNLINK DLLENTRY=DllMain CDEFINES=$(CDEFINES) -DLED_EXPORTS TARGETLIBS= \ $(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\coredll.lib \ $(_WINCEROOT)\PLATFORM\SMDK6410\lib\ARMV4I\retail\DriverLib.lib \
INCLUDES= \ $(_WINCEROOT)\PUBLIC\COMMON\OAK\INC;$(_WINCEROOT)\PLATFORM\COMMON\SRC\INC;$(_WINCEROOT)\PUBLIC\COMMON\DDK\INC;$(_WINCEROOT)\PLATFORM\COMMON\SRC\SOC\S3C6410_SEC_V1\OAL\INC;$(_WINCEROOT)\PLATFORM\SMDK6410\SRC\INC \
8.然后clean sysgen
应用程序编写 新建一个工程,取名IRS,然后在,窗体中创建一个如图所示的窗体: file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps_clip_image-2152.png 在 IRSDlg.cpp中添加如下代码: // IRSDlg.cpp : implementation file //
#include "stdafx.h" #include "IRS.h" #include "IRSDlg.h"
#ifdef _DEBUG #define new DEBUG_NEW #endif
#define IOCTL_COL0 0x1000
// CIRSDlg dialog
CIRSDlg::CIRSDlg(CWnd* pParent /*=NULL*/) : CDialog(CIRSDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }
void CIRSDlg: oDataExchange(CDataExchange* pDX) { CDialog: oDataExchange(pDX); }
BEGIN_MESSAGE_MAP(CIRSDlg, CDialog) #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) ON_WM_SIZE() #endif //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CIRSDlg::OnBnClickedButton1) END_MESSAGE_MAP()
// CIRSDlg message handlers
BOOL CIRSDlg::OnInitDialog() { CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control }
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) void CIRSDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA: ortrait ? MAKEINTRESOURCE(IDD_IRS_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_IRS_DIALOG)); } } #endif
void CIRSDlg::OnBnClickedButton1() { HANDLE hLed; CString str1; int hot = 0;
hLed = CreateFile(TEXT("IRS1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if (hLed == INVALID_HANDLE_VALUE) { printf ("can't open IRS1\r\n"); } else { printf ("\rOpen IRS1\r\n"); }
while(1){ DWORD dwReturn = 0;
DeviceIoControl(hLed, IOCTL_COL0, NULL, sizeof(DWORD), &dwReturn, 0, NULL, NULL);
if (dwReturn){ //SetDlgItemTextW(IDC_EDIT1,str1);
}else{ hot++; str1.Format(L"%d",hot); SetDlgItemTextW(IDC_EDIT1,str1);
} Sleep(100); }
} 然后编译,将测试程序下载到开发板中,会看到当我们打开测试程序,点击开始读取后,按下手中遥控器的按键会有键值的增加,还有一个现象就是,当我们打开测试程序,测试的时候,会感觉开发板很卡,原因是我们用的是查询的方式,所以占用的系统资源很大,故,此程序仅供参考!!!!!
|