Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

192 lines
4.3 KiB

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