GPIO驱动程序及测试程序.doc

上传人:w****2 文档编号:6615342 上传时间:2020-02-29 格式:DOC 页数:8 大小:25KB
返回 下载 相关 举报
GPIO驱动程序及测试程序.doc_第1页
第1页 / 共8页
GPIO驱动程序及测试程序.doc_第2页
第2页 / 共8页
GPIO驱动程序及测试程序.doc_第3页
第3页 / 共8页
点击查看更多>>
资源描述
GPIO驱动程序,主要是GIO_Control:BOOL GIO_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)switch(dwCode)case IO_CTL_GPIO_A_CON: v_pIOPregs-GPACON= *(DWORD*)pBufIn;/GPACON SETbreak; case IO_CTL_GPIO_A_DAT_OUTPUT:v_pIOPregs-GPADAT= *(DWORD*)pBufIn; /GPADAT SET (OUTPUT) also for Functional Pinbreak; case IO_CTL_GPIO_B_CON: v_pIOPregs-GPBCON= *(DWORD*)pBufIn;/GPBCON SETbreak;case IO_CTL_GPIO_B_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs-GPBDAT; /GPBDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_B_DAT_OUTPUT:v_pIOPregs-GPBDAT= *(DWORD*)pBufIn; /GPBDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_B_UP:v_pIOPregs-GPBUP= *(DWORD*)pBufIn;/GPBUP SETbreak; case IO_CTL_GPIO_C_CON: v_pIOPregs-GPCCON= *(DWORD*)pBufIn;/GPCCON SETbreak;case IO_CTL_GPIO_C_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs-GPCDAT; /GPCDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_C_DAT_OUTPUT:v_pIOPregs-GPCDAT= *(DWORD*)pBufIn; /GPCDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_C_UP:v_pIOPregs-GPCUP= *(DWORD*)pBufIn;/GPCUP SETbreak; case IO_CTL_GPIO_D_CON: v_pIOPregs-GPDCON= *(DWORD*)pBufIn;/GPDCON SETbreak;case IO_CTL_GPIO_D_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs-GPDDAT; /GPDDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_D_DAT_OUTPUT:v_pIOPregs-GPDDAT= *(DWORD*)pBufIn; /GPDDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_D_UP:v_pIOPregs-GPDUP= *(DWORD*)pBufIn;/GPDUP SETbreak; case IO_CTL_GPIO_E_CON: v_pIOPregs-GPECON= *(DWORD*)pBufIn;/GPECON SETbreak;case IO_CTL_GPIO_E_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs-GPEDAT; /GPEDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_E_DAT_OUTPUT:v_pIOPregs-GPEDAT= *(DWORD*)pBufIn; /GPEDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_E_UP:v_pIOPregs-GPEUP= *(DWORD*)pBufIn;/GPEUP SETbreak;case IO_CTL_GPIO_F_CON: v_pIOPregs-GPFCON= *(DWORD*)pBufIn;/GPFCON SETbreak;case IO_CTL_GPIO_F_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs-GPFDAT; /GPFDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_F_DAT_OUTPUT:v_pIOPregs-GPFDAT= *(DWORD*)pBufIn; /GPFDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_F_UP:v_pIOPregs-GPFUP= *(DWORD*)pBufIn;/GPFUP SETbreak; case IO_CTL_GPIO_G_CON: v_pIOPregs-GPGCON= *(DWORD*)pBufIn;/GPGCON SETbreak;case IO_CTL_GPIO_G_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs-GPGDAT; /GPGDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_G_DAT_OUTPUT:v_pIOPregs-GPGDAT= *(DWORD*)pBufIn; /GPGDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_G_UP:v_pIOPregs-GPGUP= *(DWORD*)pBufIn;/GPGUP SETbreak; case IO_CTL_GPIO_H_CON: v_pIOPregs-GPHCON= *(DWORD*)pBufIn;/GPHCON SETbreak;case IO_CTL_GPIO_H_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs-GPHDAT; /GPHDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_H_DAT_OUTPUT:v_pIOPregs-GPHDAT= *(DWORD*)pBufIn; /GPHDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_H_UP:v_pIOPregs-GPHUP= *(DWORD*)pBufIn;/GPHUP SETbreak; case IO_CTL_GPIO_J_CON: v_pIOPregs-GPJCON= *(DWORD*)pBufIn;/GPJCON SETbreak;case IO_CTL_GPIO_J_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs-GPJDAT; /GPJDAT SET (INPUT) also for Functional Pinbreak; case IO_CTL_GPIO_J_DAT_OUTPUT:v_pIOPregs-GPJDAT= *(DWORD*)pBufIn; /GPJDAT SET (OUTPUT) also for Functional Pinbreak;case IO_CTL_GPIO_J_UP:v_pIOPregs-GPJUP= *(DWORD*)pBufIn;/GPJUP SETbreak; default:break; RETAILMSG(0,(TEXT(GPIO_Control:Ioctl code = 0x%xrn), dwCode);return TRUE;测试程序,封装了2个输入输出GPIO函数,调用十分方便:#include stdafx.h#include Relay2.h#include Relay2Dlg.h#include GPIO_Driver.h#ifdef _DEBUG#define new DEBUG_NEW#endifDWORD RData,BUFCON,BUFOUT,BUFIN;struct GPIO DWORD GPIOCON; DWORD GPIOIN;DWORD GPIOOUT; ;struct GPIO GPA=gpacon,NULL,gpaout , GPB=gpbcon,gpbin,gpbout ,GPC=gpccon,gpcin,gpcout ,GPD=gpdcon,gpdin,gpdout ,GPE=gpecon,gpein,gpeout , GPF=gpfcon,gpfin,gpfout ,GPG=gpgcon,gpgin,gpgout ,GPH=gphcon,gphin,gphout ,GPJ=gpjcon,gpjin,gpjout ; /define and choose GPIO / CRelay2Dlg 对话框CRelay2Dlg:CRelay2Dlg(CWnd* pParent /*=NULL*/): CDialog(CRelay2Dlg:IDD, pParent)m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CRelay2Dlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);BEGIN_MESSAGE_MAP(CRelay2Dlg, CDialog)#if defined(_DEVICE_RESOLUTION_AWARE) & !defined(WIN32_PLATFORM_WFSP)ON_WM_SIZE()#endif/AFX_MSG_MAPON_BN_CLICKED(IDC_BUTTON1, &CRelay2Dlg:OnBnClickedButton1)ON_BN_CLICKED(IDC_BUTTON2, &CRelay2Dlg:OnBnClickedButton2)END_MESSAGE_MAP()/ CRelay2Dlg 消息处理程序BOOL CRelay2Dlg:OnInitDialog()CDialog:OnInitDialog();/ 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动/ 执行此操作SetIcon(m_hIcon, TRUE);/ 设置大图标SetIcon(m_hIcon, FALSE);/ 设置小图标/ TODO: 在此添加额外的初始化代码gpiodriver=CreateFile(LGIO1:,GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_EXISTING,0,NULL );/gpiodriver initif(!gpiodriver)MessageBox(L打开GPIO设备失败!);return TRUE; / 除非将焦点设置到控件,否则返回 TRUE#if defined(_DEVICE_RESOLUTION_AWARE) & !defined(WIN32_PLATFORM_WFSP)void CRelay2Dlg:OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)if (AfxIsDRAEnabled()DRA:RelayoutDialog(AfxGetResourceHandle(),this-m_hWnd,DRA:GetDisplayMode() != DRA:Portrait ?MAKEINTRESOURCE(IDD_RELAY2_DIALOG_WIDE) :MAKEINTRESOURCE(IDD_RELAY2_DIALOG);#endifDWORD CRelay2Dlg:GPIOINPUT(DWORD GPIOCON,DWORD GPIOIN,DWORD BUFCON,DWORD BUFOUT ) /the function is used for GPIO INPUT DWORD RData; DeviceIoControl(gpiodriver,GPIOCON,&BUFCON,4,NULL,0,NULL,NULL); DeviceIoControl(gpiodriver,GPIOIN,NULL,0,&BUFOUT,4,NULL,NULL);memcpy(&RData,&BUFOUT,4);return RData;DWORD CRelay2Dlg:GPIOINPUT1(struct GPIO GP,USHORT NUM ) /the function is used for GPIO INPUT BETTER BUFCON &=(3(2*NUM); DeviceIoControl(gpiodriver,GP.GPIOCON,&BUFCON,4,NULL,0,NULL,NULL); DeviceIoControl(gpiodriver,GP.GPIOIN,NULL,0,&BUFOUT,4,NULL,NULL); memcpy(&RData,&BUFOUT,4);return RData;VOID CRelay2Dlg:GPIOOUTPUT(DWORD GPIOCON,DWORD GPIOOUT,DWORD BUFCON,DWORD BUFIN ) /the function is used for GPIO OUTPUT DeviceIoControl(gpiodriver,GPIOCON,&BUFCON,4,NULL,0,NULL,NULL); DeviceIoControl(gpiodriver,GPIOOUT,&BUFIN,4,NULL,0,NULL,0);VOID CRelay2Dlg:GPIOOUTPUT1(struct GPIO GP,USHORT NUM,BYTE PINSTATE ) /the function is used for GPIO OUTPUT better if(GP.GPIOIN!=NULL) BUFCON=(BUFCON &(3(2*NUM)|(1(2*NUM);else BUFCON &=(1NUM);if(PINSTATE)BUFIN |=(1NUM);elseBUFIN &=(1NUM); DeviceIoControl(gpiodriver,GP.GPIOCON,&BUFCON,4,NULL,0,NULL,NULL); DeviceIoControl(gpiodriver,GP.GPIOOUT,&BUFIN,4,NULL,0,NULL,0);void CRelay2Dlg:OnBnClickedButton1()/ TODO: 在此添加控件通知处理程序代码 GPIOOUTPUT1(GPB,8,1);GPIOINPUT1(GPB,7);GPIOOUTPUT1(GPB,6,0);GPIOOUTPUT1(GPB,5,0); / GPIOOUTPUT1(GPF,3,1); /GPF3 OUTPUT 1 GPIOOUTPUT1(GPF,2,0); /GPIOOUTPUT1(GPG,5,0);/GPIOOUTPUT1(GPG,7,1); void CRelay2Dlg:OnBnClickedButton2()/ TODO: 在此添加控件通知处理程序代码 DWORD GetData; GetData =GPIOINPUT1(GPF,6); /GPF4 INPUTif(GetData&=(16)MessageBox(_T(1); elseMessageBox(_T(0);
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 临时分类 > 人文社科


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!