GpioClass.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /////////////////////////////////////////////////////////////////////////////////
  2. /// Copyright (c) 2012 China Merchants Bank, all rights reserved ///
  3. /// Adapter Interface for Gpio. ///
  4. /// ///
  5. ////////////////////////////////////////////////////////////////////////////////
  6. #ifndef __GPIO_CLASS_H
  7. #define __GPIO_CLASS_H
  8. #pragma once
  9. #include "DeviceBaseClass.h"
  10. //1 Port means 8 adjancent pins.
  11. //Port 0: pin 0~7
  12. //Port 1: pin 8~15
  13. //Port 2: pin 16~23
  14. //The first two port s(pin 0~15) are used as input,port 2 is used as output.
  15. //
  16. //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;
  17. const int MAX_PORT_NUM = 4; //max number of gpio ports (1 port = 8 pins)
  18. struct GpioInitParam
  19. {
  20. DWORD dwPort;
  21. DWORD dwBaudRate;
  22. DWORD dwPortNum; //number of port to set
  23. bool dir[MAX_PORT_NUM]; //port input/output direction. true:output;false:input
  24. //ex. dir[0]=true means configure port 0 as output
  25. //port 0 = pin 1~8,port 1 = pin 9~16 ...
  26. };
  27. class GpioClass : public DeviceBaseClass
  28. {
  29. public:
  30. //
  31. // Device initialization.
  32. // Configure port input/output direction.
  33. //
  34. virtual ErrorCodeEnum DevOpen(GpioInitParam initParam) = 0;
  35. //
  36. // Set ports output.
  37. // Arguments:
  38. // - dwPort:port serial number,0~MAX_PORT_NUM-1
  39. // - btData:output value
  40. // bit value 1/0 means voltage high or low
  41. // ex.dwPort=0 btData=10001010 means set port 0's the 2nd,4th,8th pin output high
  42. //
  43. virtual ErrorCodeEnum WritePort(DWORD dwPort,BYTE btData) = 0;
  44. //
  45. // Get port input.
  46. // Arguments:
  47. // - dwPort:port serial number,0~MAX_PORT_NUM-1
  48. // - btStatus:input value
  49. // ex.dwPort=0 btStatus=10001010 means port 0's the 2nd,4th,8th pin with high level
  50. //
  51. virtual ErrorCodeEnum ReadPort(DWORD dwPort,BYTE &btStatus) = 0;
  52. };
  53. #endif //__GPIO_CLASS_H