GPIO驅動程序及測試程序.doc
《GPIO驅動程序及測試程序.doc》由會員分享,可在線閱讀,更多相關《GPIO驅動程序及測試程序.doc(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 SET break; case IO_CTL_GPIO_A_DAT_OUTPUT: v_pIOPregs->GPADAT= *(DWORD*)pBufIn; //GPADAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_B_CON: v_pIOPregs->GPBCON= *(DWORD*)pBufIn;//GPBCON SET break; case IO_CTL_GPIO_B_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPBDAT; //GPBDAT SET (INPUT) also for Functional Pin break; case IO_CTL_GPIO_B_DAT_OUTPUT: v_pIOPregs->GPBDAT= *(DWORD*)pBufIn; //GPBDAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_B_UP: v_pIOPregs->GPBUP= *(DWORD*)pBufIn;//GPBUP SET break; case IO_CTL_GPIO_C_CON: v_pIOPregs->GPCCON= *(DWORD*)pBufIn;//GPCCON SET break; case IO_CTL_GPIO_C_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPCDAT; //GPCDAT SET (INPUT) also for Functional Pin break; case IO_CTL_GPIO_C_DAT_OUTPUT: v_pIOPregs->GPCDAT= *(DWORD*)pBufIn; //GPCDAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_C_UP: v_pIOPregs->GPCUP= *(DWORD*)pBufIn;//GPCUP SET break; case IO_CTL_GPIO_D_CON: v_pIOPregs->GPDCON= *(DWORD*)pBufIn;//GPDCON SET break; case IO_CTL_GPIO_D_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPDDAT; //GPDDAT SET (INPUT) also for Functional Pin break; case IO_CTL_GPIO_D_DAT_OUTPUT: v_pIOPregs->GPDDAT= *(DWORD*)pBufIn; //GPDDAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_D_UP: v_pIOPregs->GPDUP= *(DWORD*)pBufIn;//GPDUP SET break; case IO_CTL_GPIO_E_CON: v_pIOPregs->GPECON= *(DWORD*)pBufIn;//GPECON SET break; case IO_CTL_GPIO_E_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPEDAT; //GPEDAT SET (INPUT) also for Functional Pin break; case IO_CTL_GPIO_E_DAT_OUTPUT: v_pIOPregs->GPEDAT= *(DWORD*)pBufIn; //GPEDAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_E_UP: v_pIOPregs->GPEUP= *(DWORD*)pBufIn;//GPEUP SET break; case IO_CTL_GPIO_F_CON: v_pIOPregs->GPFCON= *(DWORD*)pBufIn;//GPFCON SET break; case IO_CTL_GPIO_F_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPFDAT; //GPFDAT SET (INPUT) also for Functional Pin break; case IO_CTL_GPIO_F_DAT_OUTPUT: v_pIOPregs->GPFDAT= *(DWORD*)pBufIn; //GPFDAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_F_UP: v_pIOPregs->GPFUP= *(DWORD*)pBufIn;//GPFUP SET break; case IO_CTL_GPIO_G_CON: v_pIOPregs->GPGCON= *(DWORD*)pBufIn;//GPGCON SET break; case IO_CTL_GPIO_G_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPGDAT; //GPGDAT SET (INPUT) also for Functional Pin break; case IO_CTL_GPIO_G_DAT_OUTPUT: v_pIOPregs->GPGDAT= *(DWORD*)pBufIn; //GPGDAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_G_UP: v_pIOPregs->GPGUP= *(DWORD*)pBufIn;//GPGUP SET break; case IO_CTL_GPIO_H_CON: v_pIOPregs->GPHCON= *(DWORD*)pBufIn;//GPHCON SET break; case IO_CTL_GPIO_H_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPHDAT; //GPHDAT SET (INPUT) also for Functional Pin break; case IO_CTL_GPIO_H_DAT_OUTPUT: v_pIOPregs->GPHDAT= *(DWORD*)pBufIn; //GPHDAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_H_UP: v_pIOPregs->GPHUP= *(DWORD*)pBufIn;//GPHUP SET break; case IO_CTL_GPIO_J_CON: v_pIOPregs->GPJCON= *(DWORD*)pBufIn;//GPJCON SET break; case IO_CTL_GPIO_J_DAT_INPUT: *(DWORD*)pBufOut=v_pIOPregs->GPJDAT; //GPJDAT SET (INPUT) also for Functional Pin break; case IO_CTL_GPIO_J_DAT_OUTPUT: v_pIOPregs->GPJDAT= *(DWORD*)pBufIn; //GPJDAT SET (OUTPUT) also for Functional Pin break; case IO_CTL_GPIO_J_UP: v_pIOPregs->GPJUP= *(DWORD*)pBufIn;//GPJUP SET break; default: break; } RETAILMSG(0,(TEXT("GPIO_Control:Ioctl code = 0x%x\r\n"), dwCode)); return TRUE; } 測試程序,封裝了2個輸入輸出GPIO函數,調用十分方便: #include "stdafx.h" #include "Relay2.h" #include "Relay2Dlg.h" #include "GPIO_Driver.h" #ifdef _DEBUG #define new DEBUG_NEW #endif DWORD 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_MAP ON_BN_CLICKED(IDC_BUTTON1, &CRelay2Dlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CRelay2Dlg::OnBnClickedButton2) END_MESSAGE_MAP() // CRelay2Dlg 消息處理程序 BOOL CRelay2Dlg::OnInitDialog() { CDialog::OnInitDialog(); // 設置此對話框的圖標。當應用程序主窗口不是對話框時,框架將自動 // 執(zhí)行此操作 SetIcon(m_hIcon, TRUE);// 設置大圖標 SetIcon(m_hIcon, FALSE);// 設置小圖標 // TODO: 在此添加額外的初始化代碼 gpiodriver=CreateFile(L"GIO1:",GENERIC_READ | GENERIC_WRITE, 0,NULL,OPEN_EXISTING,0,NULL );//gpiodriver init if(!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)); } } #endif DWORD 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 &=~(1<- 配套講稿:
如PPT文件的首頁顯示word圖標,表示該PPT已包含配套word講稿。雙擊word圖標可打開word文檔。
- 特殊限制:
部分文檔作品中含有的國旗、國徽等圖片,僅作為作品整體效果示例展示,禁止商用。設計者僅對作品中獨創(chuàng)性部分享有著作權。
- 關 鍵 詞:
- GPIO 驅動程序 測試 程序
裝配圖網所有資源均是用戶自行上傳分享,僅供網友學習交流,未經上傳用戶書面授權,請勿作他用。
鏈接地址:http://www.szxfmmzy.com/p-6615342.html