GPB5 |
红色指示灯控制 |
初始化置1,置0时红色指示灯亮 |
GPB6 |
绿色指示灯控制 |
初始化置1,置0时绿色指示灯亮 |
GPB7 |
蓝色指示灯控制 |
初始化置1,置0时蓝色指示灯亮 |
#define IOP_BASE 0xB1600000 // 0x56000000 虚拟地址和物理地址
typedefstruct {
unsigned int rGPACON; //00
unsigned int rGPADAT;
unsigned int rPAD1[2];
unsigned int rGPBCON; //10
unsigned int rGPBDAT;
unsigned int rGPBUP;
unsigned int rPAD2;
unsigned int rGPCCON; //20
unsigned int rGPCDAT;
unsigned int rGPCUP;
unsigned int rPAD3;
unsigned int rGPDCON; //30
unsigned int rGPDDAT;
unsigned int rGPDUP;
unsigned int rPAD4;
unsigned int rGPECON; //40
unsigned int rGPEDAT;
unsigned int rGPEUP;
unsigned int rPAD5;
unsigned int rGPFCON; //50
unsigned int rGPFDAT;
unsigned int rGPFUP;
unsigned int rPAD6;
unsigned int rGPGCON; //60
unsigned int rGPGDAT;
unsigned int rGPGUP;
unsigned int rPAD7;
unsigned int rGPHCON; //70
unsigned int rGPHDAT;
unsigned int rGPHUP;
unsignedint rPAD8;
unsigned int rMISCCR; //80
unsigned int rDCKCON;
unsigned int rEXTINT0;
unsigned int rEXTINT1;
unsigned int rEXTINT2; //90
unsigned int rEINTFLT0;
unsigned int rEINTFLT1;
unsigned int rEINTFLT2;
unsigned int rEINTFLT3; //A0
unsigned int rEINTMASK;
unsigned int rEINTPEND;
unsigned int rGSTATUS0; //AC
unsigned int rGSTATUS1; //B0
unsigned int rGSTATUS2; //B4 ;;; SHL
unsigned int rGSTATUS3; //B8
unsigned int rGSTATUS4; //BC
unsigned int rFLTOUT; //C0
unsigned int rDSC0;
unsigned int rDSC1;
unsigned int rMSLCON;
unsigned int rGPJCON; //D0
unsigned int rGPJDAT;
unsigned int rGPJUP;
unsigned int rPAD9;
}IOPreg;
LIBRARY LED_driver
EXPORTS
LED_Close //实现
LED_Deinit
LED_Init //实现
LED_IOControl //实现
LED_Open
LED_PowerDown
LED_PowerUp
LED_Read
LED_Seek
LED_Write
1、将LED_driver.dll和注册表文件拷贝到掌机上
2、用DM驱动调试助手加载驱动并激活。
3、然后直接打开测试程序,点击相应的按钮,可以看到LED的灯颜色的变化。
// LEDDriverTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "LEDDriverTest.h"
#include "LEDDriverTestDlg.h"
extern HANDLE hSerial;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CLEDDriverTestDlg dialog
CLEDDriverTestDlg::CLEDDriverTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLEDDriverTestDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CLEDDriverTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CLEDDriverTestDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON_OPEN_RED, &CLEDDriverTestDlg::OnBnClickedButtonOpenRed)
ON_BN_CLICKED(IDC_BUTTON_CLOSE_RED, &CLEDDriverTestDlg::OnBnClickedButtonCloseRed)
ON_BN_CLICKED(IDC_BUTTON_OPEN_GREEN, &CLEDDriverTestDlg::OnBnClickedButtonOpenGreen)
ON_BN_CLICKED(IDC_BUTTON_CLOSE_GREEN, &CLEDDriverTestDlg::OnBnClickedButtonCloseGreen)
ON_BN_CLICKED(IDC_BUTTON_OPEN_BLUE, &CLEDDriverTestDlg::OnBnClickedButtonOpenBlue)
ON_BN_CLICKED(IDC_BUTTONC_LOSE_BLUE, &CLEDDriverTestDlg::OnBnClickedButtoncLoseBlue)
ON_BN_CLICKED(IDC_BUTTON_ALL_ON, &CLEDDriverTestDlg::OnBnClickedButtonAllOn)
ON_BN_CLICKED(IDC_BUTTON_ALL_OFF, &CLEDDriverTestDlg::OnBnClickedButtonAllOff)
END_MESSAGE_MAP()
// CLEDDriverTestDlg message handlers
BOOL CLEDDriverTestDlg::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
hSerial = INVALID_HANDLE_VALUE;全局变量在.h文件中声明
// TODO: Add extra initialization here
hSerial = CreateFile(L"LED1:", GENERIC_READ | GENERIC_WRITE, 0x00, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hSerial == INVALID_HANDLE_VALUE)
{
return false;
}
return TRUE; // return TRUE unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CLEDDriverTestDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
DRA::RelayoutDialog(
AfxGetInstanceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_LEDDRIVERTEST_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_LEDDRIVERTEST_DIALOG));
}
#endif
void CLEDDriverTestDlg::OnBnClickedButtonOpenRed()
{
// TODO: Add your control notification handler code here
if (hSerial == INVALID_HANDLE_VALUE)
{
return ;
}
else
{
DeviceIoControl(hSerial, 0x01, NULL, NULL, NULL, NULL, NULL, NULL);
}
}
void CLEDDriverTestDlg::OnBnClickedButtonCloseRed()
{
// TODO: Add your control notification handler code here
if (hSerial == INVALID_HANDLE_VALUE)
{
return ;
}
else
{
DeviceIoControl(hSerial, 0x05, NULL, NULL, NULL, NULL, NULL, NULL);
}
}
void CLEDDriverTestDlg::OnBnClickedButtonOpenGreen()
{
// TODO: Add your control notification handler code here
if (hSerial == INVALID_HANDLE_VALUE)
{
return ;
}
else
{
DeviceIoControl(hSerial, 0x02, NULL, NULL, NULL, NULL, NULL, NULL);
}
}
void CLEDDriverTestDlg::OnBnClickedButtonCloseGreen()
{
// TODO: Add your control notification handler code here
if (hSerial == INVALID_HANDLE_VALUE)
{
return ;
}
else
{
DeviceIoControl(hSerial, 0x06, NULL, NULL, NULL, NULL, NULL, NULL);
}
}
void CLEDDriverTestDlg::OnBnClickedButtonOpenBlue()
{
// TODO: Add your control notification handler code here
if (hSerial == INVALID_HANDLE_VALUE)
{
return ;
}
else
{
DeviceIoControl(hSerial, 0x03, NULL, NULL, NULL, NULL, NULL, NULL);
}
}
void CLEDDriverTestDlg::OnBnClickedButtoncLoseBlue()
{
// TODO: Add your control notification handler code here
if (hSerial == INVALID_HANDLE_VALUE)
{
return ;
}
else
{
DeviceIoControl(hSerial, 0x07, NULL, NULL, NULL, NULL, NULL, NULL);
}
}
void CLEDDriverTestDlg::OnBnClickedButtonAllOn()
{
// TODO: Add your control notification handler code here
if (hSerial == INVALID_HANDLE_VALUE)
{
return ;
}
else
{
DeviceIoControl(hSerial, 0x04, NULL, NULL, NULL, NULL, NULL, NULL);
}
}
void CLEDDriverTestDlg::OnBnClickedButtonAllOff()
{
// TODO: Add your control notification handler code here
if (hSerial == INVALID_HANDLE_VALUE)
{
return ;
}
else
{
DeviceIoControl(hSerial, 0x08, NULL, NULL, NULL, NULL, NULL, NULL);
}
}
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\LEDdriver]
"Index"=dword:1
"Prefix"="LED"
"Dll"="LED_driver.dll"
#include <windows.h>
//#include <ceddk.h>
#include <nkintr.h>
#include <pm.h>
#include "pmplatform.h"
#include "Pkfuncs.h"
#include "s2440.h"
#define IO_CTL_LED_1_ON 0x01
#define IO_CTL_LED_2_ON 0x02
#define IO_CTL_LED_3_ON 0x03
//#define IO_CTL_LED_4_ON 0x04
#define IO_CTL_LED_ALL_ON 0x04
#define IO_CTL_LED_1_OFF 0x05
#define IO_CTL_LED_2_OFF 0x06
#define IO_CTL_LED_3_OFF 0x07
//#define IO_CTL_LED_4_OFF 0x09
#define IO_CTL_LED_ALL_OFF 0x08
volatile IOPreg *s2440IOP = (IOPreg *)IOP_BASE;
volatile INTreg *s2440INT = (INTreg *)INT_BASE;
#ifdef DEBUG
DBGPARAM dpCurSettings = {
TEXT("LED"), {
TEXT("Error"), TEXT("Warn"), TEXT("Init"), TEXT("Open"),
TEXT("Read"), TEXT("Write"), TEXT("IOCTL"), TEXT("IST"),
TEXT("Power"), TEXT("9"), TEXT("10"), TEXT("11"),
TEXT("12"), TEXT("13"), TEXT("14"), TEXT("Trace"),
},
0x0003 // ZONE_WRN|ZONE_ERR
};
#endif // DEBUG
BOOL mInitialized;
void Virtual_Alloc(); // Virtual allocation
void Virtual_Alloc()
{
// GPIO Virtual alloc
s2440IOP = (volatile IOPreg *) VirtualAlloc(0,sizeof(IOPreg),MEM_RESERVE, PAGE_NOACCESS);
if(s2440IOP == NULL) {
RETAILMSG(1,(TEXT("For s2440IOP: VirtualAlloc faiLED!\r\n")));
}
else {
if(!VirtualCopy((PVOID)s2440IOP,(PVOID)(IOP_BASE),sizeof(IOPreg),PAGE_READWRITE | PAGE_NOCACHE )) {
RETAILMSG(1,(TEXT("For s2440IOP: VirtualCopy faiLED!\r\n")));
}
}
}
BOOL WINAPI
DllEntry(HANDLE hinstDLL,
DWORD dwReason,
LPVOID /* lpvReserved */)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
DEBUGREGISTER((HINSTANCE)hinstDLL);
return TRUE;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
#ifdef UNDER_CE
case DLL_PROCESS_EXITING:
break;
case DLL_SYSTEM_STARTED:
break;
#endif
}
return TRUE;
}
BOOL LED_Deinit(DWORD hDeviceContext)
{
BOOL bRet = TRUE;
RETAILMSG(1,(TEXT("USERLED: LED_Deinit\r\n")));
return TRUE;
}
BOOL LEDGpioInit()
{
RETAILMSG(1,(TEXT("LED_Gpio_Setting----\r\n")));