GPIO驅(qū)動程序及測試程序_第1頁
GPIO驅(qū)動程序及測試程序_第2頁
GPIO驅(qū)動程序及測試程序_第3頁
免費預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、GPIO驅(qū)動程序,主要是GIO_Cont:BOOLGIO_IOControl(DWORDhOpenContext,DWORDdwCode,PBYTEpBufIn,DWORDdwLenIn,PBYTEpBufOut,DWORDdwLenOut,PDWORDpdwActualOut)switch(dwCode)caseIO_CTL_GPIO_A_CON:v_plOPregs->GPACON=*(DWORD*)pBufln;/GPACONSETbreak;caseIO_CTL_GPIO_A_DAT_OUTPUT:v_pIOPregs->GPADAT=*(DWORD*)pBufln;/GP

2、ADATSET(OUTPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_B_CON:v_pIOPregs->GPBCON=*(DWORD*)pBufln;/GPBCONSETbreak;caseIO_CTL_GPIO_B_DAT_INPUT:*(DWORD*)pBufOut=v_plOPregs->GPBDAT;/GPBDATSET(INPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_B_DAT_OUTPUT:v_pIOPregs->GPBDAT=*(DWORD*)pBufln;/GPBDA

3、TSET(OUTPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_B_UP:v_pIOPregs->GPBUP=*(DWORD*)pBufln;/GPBUPSETbreak;caseIO_CTL_GPIO_C_CON:v_pIOPregs->GPCCON=*(DWORD*)pBufln;/GPCCONSETbreak;caseIO_CTL_GPIO_C_DAT_INPUT:*(DWORD*)pBufOut=v_plOPregs->GPCDAT;/GPCDATSET(INPUT)alsoforFunctionalPinbreak;cas

4、eIO_CTL_GPIO_C_DAT_OUTPUT:v_pIOPregs->GPCDAT=*(DWORD*)pBufln;/GPCDATSET(OUTPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_C_UP:v_pIOPregs->GPCUP=*(DWORD*)pBufIn;/GPCUPSETbreak;caseIO_CTL_GPIO_D_CON:v_plOPregs->GPDCON=*(DWORD*)pBufln;/GPDCONSETbreak;caseIO_CTL_GPIO_D_DAT_INPUT:*(DWORD*)pBufOu

5、t=v_plOPregs->GPDDAT;/GPDDATSET(INPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_D_DAT_OUTPUT:v_pIOPregs->GPDDAT=*(DWORD*)pBufln;/GPDDATSET(OUTPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_D_UP:v_plOPregs->GPDUP=*(DWORD*)pBufln;/GPDUPSETbreak;caseIO_CTL_GPIO_E_CON:v_plOPregs->GPECON=*(DWO

6、RD*)pBufln;/GPECONSETbreak;caseIO_CTL_GPIO_E_DAT_INPUT:*(DWORD*)pBufOut=v_plOPregs->GPEDAT;/GPEDATSET(INPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_E_DAT_OUTPUT:v_pIOPregs->GPEDAT=*(DWORD*)pBufln;/GPEDATSET(OUTPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_E_UP:v_pIOPregs->GPEUP=*(DWORD*)p

7、Bufln;/GPEUPSETbreak;caseIO_CTL_GPIO_F_CON:v_plOPregs->GPFCON=*(DWORD*)pBufln;/GPFCONSETbreak;caseIO_CTL_GPIO_F_DAT_INPUT:*(DWORD*)pBufOut=v_plOPregs->GPFDAT;/GPFDATSET(INPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_F_DAT_OUTPUT:v_pIOPregs->GPFDAT=*(DWORD*)pBufln;/GPFDATSET(OUTPUT)alsoforF

8、unctionalPinbreak;caseIO_CTL_GPIO_F_UP:v_pIOPregs->GPFUP=*(DWORD*)pBufln;/GPFUPSETbreak;caseIO_CTL_GPIO_G_CON:v_plOPregs->GPGCON=*(DWORD*)pBufln;/GPGCONSETbreak;caseIO_CTL_GPIO_G_DAT_INPUT:*(DWORD*)pBufOut=v_plOPregs->GPGDAT;/GPGDATSET(INPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_G_DAT_O

9、UTPUT:v_pIOPregs->GPGDAT=*(DWORD*)pBufln;/GPGDATSET(OUTPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_G_UP:v_plOPregs->GPGUP=*(DWORD*)pBufln;/GPGUPSETbreak;caseIO_CTL_GPIO_H_CON:v_plOPregs->GPHCON=*(DWORD*)pBufln;/GPHCONSETbreak;caseIO_CTL_GPIO_H_DAT_INPUT:*(DWORD*)pBufOut=v_plOPregs->GPH

10、DAT;/GPHDATSET(INPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_H_DAT_OUTPUT:v_pIOPregs->GPHDAT=*(DWORD*)pBufln;/GPHDATSET(OUTPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_H_UP:v_pIOPregs->GPHUP=*(DWORD*)pBufln;/GPHUPSETbreak;caseIO_CTL_GPIO_J_CON:v_plOPregs->GPJCON=*(DWORD*)pBufln;/GPJCONSE

11、Tbreak;caseIO_CTL_GPIO_J_DAT_INPUT:*(DWORD*)pBufOut=v_plOPregs->GPJDAT;/GPJDATSET(INPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_J_DAT_OUTPUT:v_pIOPregs->GPJDAT=*(DWORD*)pBufln;/GPJDATSET(OUTPUT)alsoforFunctionalPinbreak;caseIO_CTL_GPIO_J_UP:v_pIOPregs->GPJUP=*(DWORD*)pBufln;/GPJUPSETbreak

12、;default:break;RETAILMSG(O,(TEXT("GPIO_Control:loctlcode=Ox%xrn"),dwCode);returnTRUE;測試程序,封裝了2個輸入輸出GPIO函數(shù),調(diào)用十分方便:#include"stdafx.h"#include"Relay2.h"#include"Relay2Dlg.h"#include"GPIO_Driver.h"#ifdef_DEBUG#definenewDEBUG_NEW#endifDWORDRData,BUFCON,BU

13、FOUT,BUFIN;structGPIODWORDGPIOCON;DWORDGPIOIN;DWORDGPIOOUT;structGPIOGPA=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;/defineandchoose

14、GPIO/CRelay2Dlg對話框CRelay2Dlg:CRelay2Dlg(CWnd*pParent/*=NULL*/):CDialog(CRelay2Dlg:IDD,pParent)m_hlcon=AfxGetApp()->Loadlcon(IDR_MAINFRAME);voidCRelay2Dlg:DoDataExchange(CDataExchange*pDX)CDialog:DoDataExchange(pDX);BEGIN_MESSAGE_MAP(CRelay2Dlg,CDialog)#ifdefined(_DEVICE_RESOLUTION_AWARE)&&

15、;!defined(WIN32_PLATFORM_WFSP)ON_WM_SIZE()#endifAFX_MSG_MAPON_BN_CLICKED(IDC_BUTTON1,&CRelay2Dlg:OnBnClickedButton1)ON_BN_CLICKED(IDC_BUTTON2,&CRelay2Dlg:OnBnClickedButton2)END_MESSAGE_MAP()/CRelay2Dlg消息處理程序BOOLCRelay2Dlg:OnlnitDialog()CDialog:OnInitDialog();/設(shè)置此對話框的圖標(biāo)。當(dāng)應(yīng)用程序主窗口不是對話框時,框架將自動/執(zhí)

16、行此操作Setlcon(m_hlcon,TRUE);/設(shè)置大圖標(biāo)Setlcon(m_hlcon,FALSE);/設(shè)置小圖標(biāo)/TODO:在此添加額外的初始化代碼gpiodriver=CreateFile(L"GIO1:",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);/gpiodriverinitif(!gpiodriver)MessageBox(L"打開GPIO設(shè)備失敗!”);returnTRUE;/除非將焦點設(shè)置到控件,否則返回TRUE#ifdefined(_DEVICE_RESOLUTION_A

17、WARE)&&!defined(WIN32_PLATFORM_WFSP)voidCRelay2Dlg:OnSize(UINT/*nType*/,int/*cx*/,int/*cy*/)if(AfxlsDRAEnabled()DRA:RelayoutDialog(AfxGetResourceHandle(),this->m_hWnd,DRA:GetDisplayMode()!=DRA:Portrait?MAKEINTRESOURCE(IDD_RELAY2_DIALOG_WIDE):MAKEINTRESOURCE(IDD_RELAY2_DIALOG);#endifDWORDC

18、Relay2Dlg:GPIOINPUT(DWORDGPIOCONQWORDGPIOINQWORDBUFCONQWORDBUFOUT)/thefunctionisusedforGPIOINPUTDWORDRData;DeviceloControl(gpiodriver,GPIOCON,&BUFCON,4,NULL,0,NULL,NULL);DeviceloControl(gpiodriver,GPIOIN,NULL,0,&BUFOUT,4,NULL,NULL);memcpy(&RData,&BUFOUT,4);returnRData;DWORDCRelay2Dlg

19、:GPIOINPUT1(structGPIOGP,USHORTNUM)/thefunctionisusedforGPIOINPUTBETTERBUFCON&=(3<v(2*NUM);DeviceloControl(gpiodriver,GP.GPIOCON,&BUFCON,4,NULL,0,NULL,NULL);DeviceloControl(gpiodriver,GP.GPIOIN,NULL,0,&BUFOUT,4,NULL,NULL);memcpy(&RData,&BUFOUT,4);returnRData;VOIDCRelay2Dlg:GPI

20、OOUTPUT(DWORDGPIOCONQWORDGPIOOUTQWORDBUFCON,DWORDBUFIN)/thefunctionisusedforGPIOOUTPUTDeviceloControl(gpiodriver,GPIOCON,&BUFCON,4,NULL,0,NULL,NULL);DeviceloControl(gpiodriver,GPIOOUT,&BUFIN,4,NULL,0,NULL,0);/thefunction/thefunctionVOIDCRelay2Dlg:GPIOOUTPUT1(structGPIOGP,USHORTNUM,BYTEPINSTATE)isusedforGPIOOUTPUTbetterif(GP.GPIOIN!=NULL)BUFCON=(BUFCON

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論