gpio.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*++
  2. Copyright (c) 2015 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. gpio.h
  5. Abstract:
  6. This header contains definitions for the General Purpose Input/Output
  7. library and those wanting to consume (use) GPIO resources.
  8. Author:
  9. Evan Green 4-Aug-2015
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. //
  15. // ---------------------------------------------------------------- Definitions
  16. //
  17. //
  18. // Interface UUID for GPIO access.
  19. //
  20. #define UUID_GPIO_ACCESS \
  21. {{0x7495B584, 0xC84D4BDB, 0xBCD458A1, 0x5B290E85}}
  22. //
  23. // Define GPIO settings flags.
  24. //
  25. //
  26. // This flag is set to indicate the GPIO should be an output. If this flag is
  27. // not set, then the pin should be set as an input.
  28. //
  29. #define GPIO_OUTPUT 0x00000001
  30. //
  31. // This flag indicates that the initial output state for the GPIO pin should be
  32. // set to high. If this is not set and the GPIO is configured to be an output,
  33. // then the initial state is assumed to be low. This flag is used to prevent
  34. // momentary glitches during configuration.
  35. //
  36. #define GPIO_OUTPUT_HIGH 0x00000002
  37. //
  38. // This flag is set to indicate the GPIO should be enabled as an interrupt
  39. // source. In this case the GPIO output flag will not be set.
  40. //
  41. #define GPIO_INTERRUPT 0x00000004
  42. //
  43. // This flag is set to indicate that the GPIO interrupt is edge triggered. If
  44. // this is clear, then the interrupt is level triggered.
  45. //
  46. #define GPIO_INTERRUPT_EDGE_TRIGGERED 0x00000008
  47. //
  48. // This flag is set to indicate the GPIO interrupt configuration should be set
  49. // for edge triggered mode, and interrupt on the rising edge. If this flag and
  50. // the falling edge flag are not set, then the interrupt should be level
  51. // triggered.
  52. //
  53. #define GPIO_INTERRUPT_RISING_EDGE 0x00000010
  54. //
  55. // This flag is set to indicate the GPIO interrupt should trigger on the
  56. // falling edge. This may be set alone or with the rising edge flag to
  57. // indicate the interrupt should trigger on both rising and falling edges.
  58. //
  59. #define GPIO_INTERRUPT_FALLING_EDGE 0x00000020
  60. //
  61. // This flag is set to indicate interrupts should occur when the GPIO level is
  62. // low. If not set, then the interrupt is active high.
  63. //
  64. #define GPIO_INTERRUPT_ACTIVE_LOW GPIO_INTERRUPT_FALLING_EDGE
  65. //
  66. // This flag is set to enable the internal pull-up resistor in the GPIO pin.
  67. //
  68. #define GPIO_PULL_UP 0x00000040
  69. //
  70. // This flag is set to enable the internal pull-down resistor in the GPIO pin.
  71. //
  72. #define GPIO_PULL_DOWN 0x00000080
  73. //
  74. // This flag is set to disable the interall pull-up and pull-down resistors in
  75. // the GPIO pin.
  76. //
  77. #define GPIO_PULL_NONE 0x000000C0
  78. //
  79. // This flag is set if the GPIO pin should be enabled as a wake source.
  80. //
  81. #define GPIO_INTERRUPT_WAKE 0x00000100
  82. //
  83. // This flag is set to enable debouncing.
  84. //
  85. #define GPIO_ENABLE_DEBOUNCE 0x00000200
  86. //
  87. // Define default values for the output drive strength and debounce timeout.
  88. //
  89. #define GPIO_OUTPUT_DRIVE_DEFAULT (-1)
  90. #define GPIO_DEBOUNCE_TIMEOUT_DEFAULT (-1)
  91. //
  92. // ------------------------------------------------------ Data Type Definitions
  93. //
  94. typedef struct _GPIO_ACCESS_INTERFACE
  95. GPIO_ACCESS_INTERFACE, *PGPIO_ACCESS_INTERFACE;
  96. typedef PVOID GPIO_PIN_HANDLE, *PGPIO_PIN_HANDLE;
  97. /*++
  98. Structure Description:
  99. This structure defines the pin configuration for a GPIO pin.
  100. Members:
  101. Flags - Stores the GPIO pin configuration flags. See GPIO_* definitions.
  102. OutputDriveStrength - Stores the output drive strength in microamps.
  103. DebounceTimeout - Stores the interrupt debounce timeout in microseconds.
  104. --*/
  105. typedef struct _GPIO_PIN_CONFIGURATION {
  106. ULONG Flags;
  107. ULONG OutputDriveStrength;
  108. ULONG DebounceTimeout;
  109. } GPIO_PIN_CONFIGURATION, *PGPIO_PIN_CONFIGURATION;
  110. typedef
  111. KSTATUS
  112. (*PGPIO_OPEN_PIN) (
  113. PGPIO_ACCESS_INTERFACE Interface,
  114. ULONG Pin,
  115. PGPIO_PIN_HANDLE PinHandle
  116. );
  117. /*++
  118. Routine Description:
  119. This routine opens a new connection to a GPIO pin.
  120. Arguments:
  121. Interface - Supplies a pointer to the interface handle.
  122. Pin - Supplies the zero-based pin number to open.
  123. PinHandle - Supplies a pointer where a GPIO pin handle will be returned on
  124. success.
  125. Return Value:
  126. Status code.
  127. --*/
  128. typedef
  129. VOID
  130. (*PGPIO_CLOSE_PIN) (
  131. PGPIO_ACCESS_INTERFACE Interface,
  132. GPIO_PIN_HANDLE PinHandle
  133. );
  134. /*++
  135. Routine Description:
  136. This routine closes a previously opened GPIO pin handle.
  137. Arguments:
  138. Interface - Supplies a pointer to the interface handle.
  139. PinHandle - Supplies the GPIO pin handle to close.
  140. Return Value:
  141. None.
  142. --*/
  143. typedef
  144. KSTATUS
  145. (*PGPIO_PIN_SET_CONFIGURATION) (
  146. GPIO_PIN_HANDLE PinHandle,
  147. PGPIO_PIN_CONFIGURATION Configuration
  148. );
  149. /*++
  150. Routine Description:
  151. This routine sets the complete configuration for a GPIO pin.
  152. Arguments:
  153. PinHandle - Supplies the pin handle previously opened with the open pin
  154. interface function.
  155. Configuration - Supplies a pointer to the new configuration to set.
  156. Return Value:
  157. Status code.
  158. --*/
  159. typedef
  160. KSTATUS
  161. (*PGPIO_PIN_SET_DIRECTION) (
  162. GPIO_PIN_HANDLE PinHandle,
  163. ULONG Flags
  164. );
  165. /*++
  166. Routine Description:
  167. This routine sets the complete configuration for an open GPIO pin.
  168. Arguments:
  169. PinHandle - Supplies the pin handle previously opened with the open pin
  170. interface function.
  171. Flags - Supplies the GPIO_* configuration flags to set. Only GPIO_OUTPUT
  172. and GPIO_OUTPUT_HIGH are observed, all other flags are ignored.
  173. Return Value:
  174. Status code.
  175. --*/
  176. typedef
  177. VOID
  178. (*PGPIO_PIN_SET_VALUE) (
  179. GPIO_PIN_HANDLE PinHandle,
  180. ULONG Value
  181. );
  182. /*++
  183. Routine Description:
  184. This routine sets the output value on a GPIO pin.
  185. Arguments:
  186. PinHandle - Supplies the pin handle previously opened with the open pin
  187. interface function.
  188. Value - Supplies the value to set on the pin: zero for low, non-zero for
  189. high.
  190. Return Value:
  191. None.
  192. --*/
  193. typedef
  194. ULONG
  195. (*PGPIO_PIN_GET_VALUE) (
  196. GPIO_PIN_HANDLE PinHandle
  197. );
  198. /*++
  199. Routine Description:
  200. This routine gets the input value on a GPIO pin.
  201. Arguments:
  202. PinHandle - Supplies the pin handle previously opened with the open pin
  203. interface function.
  204. Return Value:
  205. 0 if the value was low.
  206. 1 if the value was high.
  207. -1 on error.
  208. --*/
  209. /*++
  210. Structure Description:
  211. This structure defines the interface to a GPIO pin.
  212. Members:
  213. Context - Stores an opaque pointer to additinal data that the interface
  214. producer uses to identify this interface instance.
  215. OpenPin - Stores a pointer to a function used to open a particular pin on
  216. a GPIO controller.
  217. ClosePin - Stores a pointer to a function used to close a previously
  218. opened GPIO pin.
  219. SetConfiguration - Stores a pointer to a function used to set the pin
  220. configuration for a GPIO pin.
  221. SetDirection - Stores a pointer to a function used to set the direction
  222. of an open GPIO pin.
  223. SetValue - Stores a pointer to a function used to set the output value of
  224. a GPIO pin.
  225. GetValue - Stores a pointer to a function used to get the input value of an
  226. open GPIO pin.
  227. --*/
  228. struct _GPIO_ACCESS_INTERFACE {
  229. PVOID Context;
  230. PGPIO_OPEN_PIN OpenPin;
  231. PGPIO_CLOSE_PIN ClosePin;
  232. PGPIO_PIN_SET_CONFIGURATION SetConfiguration;
  233. PGPIO_PIN_SET_DIRECTION SetDirection;
  234. PGPIO_PIN_SET_VALUE SetValue;
  235. PGPIO_PIN_GET_VALUE GetValue;
  236. };
  237. //
  238. // -------------------------------------------------------------------- Globals
  239. //
  240. //
  241. // -------------------------------------------------------- Function Prototypes
  242. //