gpio.h 7.7 KB

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