gpio.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2013 Semtech
  8. Description: Generic GPIO driver implementation
  9. Comment: Relies on the specific board GPIO implementation as well as on
  10. IO expander driver implementation if one is available on the target
  11. board.
  12. License: Revised BSD License, see LICENSE.TXT file include in the project
  13. Maintainer: Miguel Luis and Gregory Cristian
  14. */
  15. #ifndef __GPIO_H__
  16. #define __GPIO_H__
  17. #include "pinName-board.h"
  18. #include "pinName-ioe.h"
  19. /*!
  20. * Board GPIO pin names
  21. */
  22. typedef enum
  23. {
  24. MCU_PINS,
  25. IOE_PINS,
  26. // Not connected
  27. NC = (int)0xFFFFFFFF
  28. }PinNames;
  29. /*!
  30. * Operation Mode for the GPIO
  31. */
  32. typedef enum
  33. {
  34. PIN_INPUT = 0,
  35. PIN_OUTPUT,
  36. PIN_ALTERNATE_FCT,
  37. PIN_ANALOGIC
  38. }PinModes;
  39. /*!
  40. * Add a pull-up, a pull-down or nothing on the GPIO line
  41. */
  42. typedef enum
  43. {
  44. PIN_NO_PULL = 0,
  45. PIN_PULL_UP,
  46. PIN_PULL_DOWN
  47. }PinTypes;
  48. /*!
  49. * Define the GPIO as Push-pull type or Open Drain
  50. */
  51. typedef enum
  52. {
  53. PIN_PUSH_PULL = 0,
  54. PIN_OPEN_DRAIN
  55. }PinConfigs;
  56. /*!
  57. * Define the GPIO IRQ on a rising, falling or both edges
  58. */
  59. typedef enum
  60. {
  61. NO_IRQ = 0,
  62. IRQ_RISING_EDGE,
  63. IRQ_FALLING_EDGE,
  64. IRQ_RISING_FALLING_EDGE
  65. }IrqModes;
  66. /*!
  67. * Define the IRQ priority on the GPIO
  68. */
  69. typedef enum
  70. {
  71. IRQ_VERY_LOW_PRIORITY = 0,
  72. IRQ_LOW_PRIORITY,
  73. IRQ_MEDIUM_PRIORITY,
  74. IRQ_HIGH_PRIORITY,
  75. IRQ_VERY_HIGH_PRIORITY
  76. }IrqPriorities;
  77. /*!
  78. * Structure for the GPIO
  79. */
  80. typedef struct
  81. {
  82. PinNames pin;
  83. uint16_t pinIndex;
  84. void *port;
  85. uint16_t portIndex;
  86. }Gpio_t;
  87. /*!
  88. * GPIO IRQ handler function prototype
  89. */
  90. typedef void( GpioIrqHandler )( void );
  91. /*!
  92. * \brief Initializes the given GPIO object
  93. *
  94. * \param [IN] obj Pointer to the GPIO object
  95. * \param [IN] pin Pin name ( please look in pinName-board.h file )
  96. * \param [IN] mode Pin mode [PIN_INPUT, PIN_OUTPUT,
  97. * PIN_ALTERNATE_FCT, PIN_ANALOGIC]
  98. * \param [IN] config Pin config [PIN_PUSH_PULL, PIN_OPEN_DRAIN]
  99. * \param [IN] type Pin type [PIN_NO_PULL, PIN_PULL_UP, PIN_PULL_DOWN]
  100. * \param [IN] value Default output value at initialisation
  101. */
  102. void GpioInit( Gpio_t *obj, PinNames pin, PinModes mode, PinConfigs config, PinTypes type, uint32_t value );
  103. /*!
  104. * \brief GPIO IRQ Initialization
  105. *
  106. * \param [IN] obj Pointer to the GPIO object
  107. * \param [IN] irqMode IRQ mode [NO_IRQ, IRQ_RISING_EDGE,
  108. * IRQ_FALLING_EDGE, IRQ_RISING_FALLING_EDGE]
  109. * \param [IN] irqPriority IRQ priority [IRQ_VERY_LOW_PRIORITY, IRQ_LOW_PRIORITY
  110. * IRQ_MEDIUM_PRIORITY, IRQ_HIGH_PRIORITY
  111. * IRQ_VERY_HIGH_PRIORITY]
  112. * \param [IN] irqHandler Callback function pointer
  113. */
  114. void GpioSetInterrupt( Gpio_t *obj, IrqModes irqMode, IrqPriorities irqPriority, GpioIrqHandler *irqHandler );
  115. /*!
  116. * \brief Removes the interrupt from the object
  117. *
  118. * \param [IN] obj Pointer to the GPIO object
  119. */
  120. void GpioRemoveInterrupt( Gpio_t *obj );
  121. /*!
  122. * \brief Writes the given value to the GPIO output
  123. *
  124. * \param [IN] obj Pointer to the GPIO object
  125. * \param [IN] value New GPIO output value
  126. */
  127. void GpioWrite( Gpio_t *obj, uint32_t value );
  128. /*!
  129. * \brief Reads the current GPIO input value
  130. *
  131. * \param [IN] obj Pointer to the GPIO object
  132. * \retval value Current GPIO input value
  133. */
  134. uint32_t GpioRead( Gpio_t *obj );
  135. #endif // __GPIO_H__