///////////////////////////////////////////////////////////////////////////////// /// Copyright (c) 2012 China Merchants Bank, all rights reserved /// /// Adapter Interface for Gpio. /// /// /// //////////////////////////////////////////////////////////////////////////////// #ifndef __GPIO_CLASS_H #define __GPIO_CLASS_H #pragma once #include "DeviceBaseClass.h" //1 Port means 8 adjancent pins. //Port 0: pin 0~7 //Port 1: pin 8~15 //Port 2: pin 16~23 //The first two port s(pin 0~15) are used as input,port 2 is used as output. // //Remarks:the pin number marked on the physical device is a little different from pin number used here(in program).It marked begin from number 1 not number 0; const int MAX_PORT_NUM = 4; //max number of gpio ports (1 port = 8 pins) struct GpioInitParam { DWORD dwPort; DWORD dwBaudRate; DWORD dwPortNum; //number of port to set bool dir[MAX_PORT_NUM]; //port input/output direction. true:output;false:input //ex. dir[0]=true means configure port 0 as output //port 0 = pin 1~8,port 1 = pin 9~16 ... }; class GpioClass : public DeviceBaseClass { public: // // Device initialization. // Configure port input/output direction. // virtual ErrorCodeEnum DevOpen(GpioInitParam initParam) = 0; // // Set ports output. // Arguments: // - dwPort:port serial number,0~MAX_PORT_NUM-1 // - btData:output value // bit value 1/0 means voltage high or low // ex.dwPort=0 btData=10001010 means set port 0's the 2nd,4th,8th pin output high // virtual ErrorCodeEnum WritePort(DWORD dwPort,BYTE btData) = 0; // // Get port input. // Arguments: // - dwPort:port serial number,0~MAX_PORT_NUM-1 // - btStatus:input value // ex.dwPort=0 btStatus=10001010 means port 0's the 2nd,4th,8th pin with high level // virtual ErrorCodeEnum ReadPort(DWORD dwPort,BYTE &btStatus) = 0; }; #endif //__GPIO_CLASS_H