dev_gpio.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /* ------------------------------------------
  2. * Copyright (c) 2016, Synopsys, Inc. All rights reserved.
  3. * Redistribution and use in source and binary forms, with or without modification,
  4. * are permitted provided that the following conditions are met:
  5. * 1) Redistributions of source code must retain the above copyright notice, this
  6. * list of conditions and the following disclaimer.
  7. * 2) Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation and/or
  9. * other materials provided with the distribution.
  10. * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
  11. * be used to endorse or promote products derived from this software without
  12. * specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * \version 2016.05
  25. * \date 2014-06-17
  26. * \author Huaqi Fang(Huaqi.Fang@synopsys.com)
  27. --------------------------------------------- */
  28. /**
  29. * \defgroup DEVICE_HAL_GPIO GPIO Device HAL Interface
  30. * \ingroup DEVICE_HAL_DEF
  31. * \brief definitions for gpio device hardware layer (\ref dev_gpio.h)
  32. * \details provide interfaces for gpio driver to implement
  33. * Here is a diagram for the gpio interface.
  34. *
  35. * \htmlonly
  36. * <div class="imagebox">
  37. * <div style="width: 600px">
  38. * <img src="pic/dev_gpio_hal.jpg" alt="GPIO Device HAL Interface Diagram"/>
  39. * <p>GPIO Device HAL Interface Diagram</p>
  40. * </div>
  41. * </div>
  42. * \endhtmlonly
  43. *
  44. * @{
  45. *
  46. * \file
  47. * \brief gpio device hardware layer definitions
  48. * \details Provide common definitions for gpio device,
  49. * then the software developer can develop gpio driver
  50. * following these definitions, and the applications
  51. * can directly call this definition to realize functions
  52. *
  53. */
  54. #ifndef _DEVICE_HAL_GPIO_H_
  55. #define _DEVICE_HAL_GPIO_H_
  56. #include "device/device_hal/inc/dev_common.h"
  57. /**
  58. * \defgroup DEVICE_HAL_GPIO_DEFDIR GPIO Port Direction Definition
  59. * \ingroup DEVICE_HAL_GPIO
  60. * \brief Define macros to indicate gpio directions
  61. * @{
  62. */
  63. /*
  64. * defines for gpio directions
  65. */
  66. #define GPIO_DIR_INPUT (0) /*!< gpio works as input */
  67. #define GPIO_DIR_OUTPUT (1) /*!< gpio works as output */
  68. /** @} */
  69. /**
  70. * \defgroup DEVICE_HAL_GPIO_CTRLCMD GPIO Device Control Commands
  71. * \ingroup DEVICE_HAL_GPIO
  72. * \brief Definitions for gpio control command, used in \ref dev_gpio::gpio_control "GPIO IO Control"
  73. * \details These commands defined here can be used in user code directly.
  74. * - Parameters Usage
  75. * - For passing parameters like integer, just use uint32_t/int32_t to directly pass values
  76. * - For passing parameters for a structure, please use pointer to pass values
  77. * - For getting some data, please use pointer to store the return data
  78. * - Common Return Values
  79. * - \ref E_OK, Control device successfully
  80. * - \ref E_CLSED, Device is not opened
  81. * - \ref E_OBJ, Device object is not valid or not exists
  82. * - \ref E_PAR, Parameter is not valid for current control command
  83. * - \ref E_SYS, Control device failed, due to hardware issues such as device is disabled
  84. * - \ref E_NOSPT, Control command is not supported or not valid
  85. * @{
  86. */
  87. /**
  88. * Set the \ref dev_gpio_info::direction "direction" of masked bits of gpio port into \ref GPIO_DIR_INPUT "input"
  89. * - Param type : uint32_t
  90. * - Param usage : 1 in each bit will be masked.
  91. * - Return value explanation :
  92. */
  93. #define GPIO_CMD_SET_BIT_DIR_INPUT DEV_SET_SYSCMD(0)
  94. /**
  95. * Set the \ref dev_gpio_info::direction "direction" of masked bits of gpio port into \ref GPIO_DIR_OUTPUT "output"
  96. * - Param type : uint32_t
  97. * - Param usage : 1 in each bit will be masked.
  98. * - Return value explanation :
  99. */
  100. #define GPIO_CMD_SET_BIT_DIR_OUTPUT DEV_SET_SYSCMD(1)
  101. /**
  102. * Get \ref dev_gpio_info::direction "gpio port direction".
  103. * - Param type : uint32_t
  104. * - Param usage : 1 bit for 1 bit of gpio port, 0 for input, 1 for output
  105. * - Return value explanation :
  106. */
  107. #define GPIO_CMD_GET_BIT_DIR DEV_SET_SYSCMD(2)
  108. /**
  109. * Set gpio interrupt configuration for each bit.
  110. * - Param type : \ref DEV_GPIO_INT_CFG *
  111. * - Param usage : store gpio interrupt configuration for each bit.
  112. * - Return value explanation :
  113. */
  114. #define GPIO_CMD_SET_BIT_INT_CFG DEV_SET_SYSCMD(3)
  115. /**
  116. * Get gpio interrupt configuration for each bit.
  117. * - Param type : \ref DEV_GPIO_INT_CFG *
  118. * - Param usage : First set int_bit_mask in DEV_GPIO_INT_CFG structure to
  119. * the mask of which bit of GPIO you want to get. And the interrupt configuration
  120. * will be stored in the structure DEV_GPIO_INT_CFG, each bit stand for each bit of port.
  121. * - Return value explanation :
  122. */
  123. #define GPIO_CMD_GET_BIT_INT_CFG DEV_SET_SYSCMD(4)
  124. /**
  125. * Set gpio service routine for each bit.
  126. * - Param type : \ref DEV_GPIO_BIT_ISR *
  127. * - Param usage : store gpio handler information for each bit, int handler's param will be DEV_GPIO *.
  128. * - Return value explanation :
  129. */
  130. #define GPIO_CMD_SET_BIT_ISR DEV_SET_SYSCMD(5)
  131. /**
  132. * Get gpio service routine for each bit.
  133. * - Param type : \ref DEV_GPIO_BIT_ISR *
  134. * - Param usage : By passing int_bit_ofs in DEV_GPIO_BIT_ISR,
  135. * it will return interrupt handler for this bit and store it in int_bit_handler.
  136. * - Return value explanation :
  137. */
  138. #define GPIO_CMD_GET_BIT_ISR DEV_SET_SYSCMD(6)
  139. /**
  140. * Enable gpio interrupt of the masked bits.
  141. * - Param type : uint32_t
  142. * - Param usage : 1 in each bit will be masked.
  143. * - Return value explanation :
  144. */
  145. #define GPIO_CMD_ENA_BIT_INT DEV_SET_SYSCMD(7)
  146. /**
  147. * Disable gpio interrupt of the masked bits.
  148. * - Param type : uint32_t
  149. * - Param usage : 1 in each bit will be masked.
  150. * - Return value explanation :
  151. */
  152. #define GPIO_CMD_DIS_BIT_INT DEV_SET_SYSCMD(8)
  153. /**
  154. * Get \ref dev_gpio_info::method "gpio interrupt enable status".
  155. * - Param type : uint32_t *
  156. * - Param usage : 1 bit for 1 bit of gpio port, 0 for poll, 1 for interrupt
  157. * - Return value explanation :
  158. */
  159. #define GPIO_CMD_GET_BIT_MTHD DEV_SET_SYSCMD(9)
  160. /* @} */
  161. /**
  162. * \defgroup DEVICE_HAL_GPIO_INT_CFG_SET GPIO Device Int Configuration Settings
  163. * \ingroup DEVICE_HAL_GPIO
  164. * \brief definition of gpio interrupt type
  165. * @{
  166. */
  167. /* GPIO Mask Defintions */
  168. /** Mask none bits of the max 32bits */
  169. #define GPIO_BITS_MASK_NONE (0)
  170. /** Mask all bits of the max 32bits */
  171. #define GPIO_BITS_MASK_ALL (0XFFFFFFFF)
  172. /* GPIO Interrupt Type Related Definitions */
  173. /** Level sensitive interrupt type for 1 bit */
  174. #define GPIO_INT_LEVEL_TRIG (0)
  175. /** Edge sensitive interrupt type for 1 bit */
  176. #define GPIO_INT_EDGE_TRIG (1)
  177. /** Level sensitive interrupt type for all 32 bits */
  178. #define GPIO_INT_LEVEL_TRIG_ALL (0)
  179. /** Edge sensitive interrupt type for all 32 bits */
  180. #define GPIO_INT_EDGE_TRIG_ALL (0XFFFFFFFF)
  181. /* For bit settings */
  182. /** Set bit interrupt type of gpio into level sensitive */
  183. #define GPIO_INT_BIT_LEVEL_TRIG(bit_ofs) (GPIO_INT_LEVEL_TRIG<<(bit_ofs))
  184. /** Set bit interrupt type of gpio into edge sensitive */
  185. #define GPIO_INT_BIT_EDGE_TRIG(bit_ofs) (GPIO_INT_EDGE_TRIG<<(bit_ofs))
  186. /* For bits settings */
  187. /** Set interrupt type of masked bits of gpio into level sensitive */
  188. #define GPIO_INT_BITS_LEVEL_TRIG(bit_mask) (GPIO_INT_LEVEL_TRIG_ALL&(bit_mask))
  189. /** Set bit interrupt type of gpio into edge sensitive */
  190. #define GPIO_INT_BITS_EDGE_TRIG(bit_mask) (GPIO_INT_EDGE_TRIG_ALL&(bit_mask))
  191. /* GPIO Interrupt Polarity Related Definitions */
  192. /** GPIO Interrupt polarity type enum */
  193. typedef enum gpio_int_polarity {
  194. /* Polarity for 1 bit */
  195. GPIO_INT_ACTIVE_LOW = 0, /*!< Active low for level-sensitive interrupt for 1 bit */
  196. GPIO_INT_FALLING_EDGE = 0, /*!< Falling-edge for edge-sensitive interrupt for 1 bit */
  197. GPIO_INT_ACTIVE_HIGH = 1, /*!< Active high for level-sensitive interrupt for 1 bit */
  198. GPIO_INI_RISING_EDGE = 1, /*!< Rising-edge for edge-sensitive interrupt for 1 bit */
  199. /* Polartiy for all 32 bits */
  200. GPIO_INT_ACTIVE_LOW_ALL = 0, /*!< Active low for level-sensitive interrupt for all bits */
  201. GPIO_INT_FALLING_EDGE_ALL = 0, /*!< Falling-edge for edge-sensitive interrupt for all bits */
  202. GPIO_INT_ACTIVE_HIGH_ALL = 0XFFFFFFFF, /*!< Active high for level-sensitive interrupt for all bits */
  203. GPIO_INI_RISING_EDGE_ALL = 0XFFFFFFFF /*!< Rising-edge for edge-sensitive interrupt for all bits */
  204. } GPIO_INT_POLARITY;
  205. /* For bit settings */
  206. /** Set bit polarity of gpio into active low */
  207. #define GPIO_INT_BIT_POL_ACT_LOW(bit_ofs) (GPIO_INT_ACTIVE_LOW<<(bit_ofs))
  208. /** Set bit polarity of gpio into active high */
  209. #define GPIO_INT_BIT_POL_ACT_HIGH(bit_ofs) (GPIO_INT_ACTIVE_HIGH<<(bit_ofs))
  210. /** Set bit polarity of gpio into falling edge */
  211. #define GPIO_INT_BIT_POL_FALL_EDGE(bit_ofs) (GPIO_INT_FALLING_EDGE<<(bit_ofs))
  212. /** Set bit polarity of gpio into rising edge */
  213. #define GPIO_INT_BIT_POL_RISE_EDGE(bit_ofs) (GPIO_INI_RISING_EDGE<<(bit_ofs))
  214. /* For bits settings */
  215. /** Set polarity of masked bits of gpio into active low */
  216. #define GPIO_INT_BITS_POL_ACT_LOW(bit_mask) (GPIO_INT_ACTIVE_LOW_ALL&(bit_mask))
  217. /** Set polarity of masked bits of gpio into active high */
  218. #define GPIO_INT_BITS_POL_ACT_HIGH(bit_mask) (GPIO_INT_ACTIVE_HIGH_ALL&(bit_mask))
  219. /** Set polarity of masked bits of gpio into falling edge */
  220. #define GPIO_INT_BITS_POL_FALL_EDGE(bit_mask) (GPIO_INT_FALLING_EDGE_ALL&(bit_mask))
  221. /** Set polarity of masked bits of gpio into rising edge */
  222. #define GPIO_INT_BITS_POL_RISE_EDGE(bit_mask) (GPIO_INI_RISING_EDGE_ALL&(bit_mask))
  223. /* GPIO Interrupt Debounce Related Definitions */
  224. /* For bit settings */
  225. /** Disable debounce circuitry for 1 bit */
  226. #define GPIO_INT_NO_DEBOUNCE (0)
  227. /** Enable debounce circuitry for 1 bit */
  228. #define GPIO_INT_DEBOUNCE (1)
  229. /* For bits settings */
  230. /** Disable debounce circuitry for all bits */
  231. #define GPIO_INT_NO_DEBOUNCE_ALL (0)
  232. /** Enable debounce circuitry for all bits */
  233. #define GPIO_INT_DEBOUNCE_ALL (0XFFFFFFFF)
  234. /* For bit settings */
  235. /** Set bit interrupt debounce of gpio into enabled */
  236. #define GPIO_INT_BIT_ENA_DEBOUNCE(bit_ofs) (GPIO_INT_DEBOUNCE<<(bit_ofs))
  237. /** Set bit interrupt debounce of gpio into disabled */
  238. #define GPIO_INT_BIT_DIS_DEBOUNCE(bit_ofs) (GPIO_INT_NO_DEBOUNCE<<(bit_ofs))
  239. /* For bits settings */
  240. /** Set bit interrupt debounce of gpio into enabled */
  241. #define GPIO_INT_BITS_ENA_DEBOUNCE(bit_mask) (GPIO_INT_DEBOUNCE_ALL&(bit_mask))
  242. /** Set bit interrupt debounce of gpio into disabled */
  243. #define GPIO_INT_BITS_DIS_DEBOUNCE(bit_mask) (GPIO_INT_NO_DEBOUNCE_ALL&(bit_mask))
  244. /** GPIO interrupt configuration */
  245. typedef struct dev_gpio_int_cfg {
  246. uint32_t int_bit_mask; /*!< interrupt bit mask for gpio */
  247. uint32_t int_bit_type; /*!< \ref GPIO_INT_LEVEL_TRIG "level sensitive" or \ref GPIO_INT_EDGE_TRIG "edge sensitive" for each gpio bit */
  248. uint32_t int_bit_polarity; /*!< active high or low, refer to \ref GPIO_INT_POLARITY for each gpio bit */
  249. uint32_t int_bit_debounce; /*!< \ref GPIO_INT_DEBOUNCE "enable" or \ref GPIO_INT_NO_DEBOUNCE "disable" debounce logic for each gpio bit */
  250. } DEV_GPIO_INT_CFG, * DEV_GPIO_INT_CFG_PTR;
  251. /** Default interrupt configuration for all gpio bits */
  252. static const DEV_GPIO_INT_CFG gpio_int_cfg_default = \
  253. {GPIO_BITS_MASK_ALL, GPIO_INT_LEVEL_TRIG_ALL, \
  254. GPIO_INT_ACTIVE_LOW_ALL, GPIO_INT_NO_DEBOUNCE_ALL};
  255. /** GPIO interrupt handler or Interrupt Service Routine(ISR) */
  256. typedef void (*DEV_GPIO_HANDLER) (void *ptr);
  257. /** interrupt handler for each port bit */
  258. typedef struct dev_gpio_bit_isr {
  259. uint32_t int_bit_ofs; /*!< int bit offset */
  260. DEV_GPIO_HANDLER int_bit_handler; /*!< interrupt handler */
  261. } DEV_GPIO_BIT_ISR, * DEV_GPIO_BIT_ISR_PTR;
  262. /* @} */
  263. /**
  264. * \defgroup DEVICE_HAL_GPIO_DEVSTRUCT GPIO Device Interface Definition
  265. * \ingroup DEVICE_HAL_GPIO
  266. * \brief contains definitions of gpio device structure.
  267. * \details This structure will be used in user implemented code, which was called
  268. * \ref DEVICE_IMPL "Device Driver Implement Layer" for gpio to use in implementation code.
  269. * Application developer should use the GPIO API provided here to access to GPIO devices.
  270. * BSP developer should follow the API definition to implement GPIO device drivers.
  271. * @{
  272. */
  273. /**
  274. * \brief gpio information struct definition
  275. * \details informations about gpio open count, working status
  276. * gpio registers and control block, gpio io direction and interrupt/poll for each bit of gpio
  277. * \note Only available for gpio with max 32bits
  278. */
  279. typedef struct dev_gpio_info {
  280. void *gpio_ctrl; /*!< gpio control related pointer, implemented by bsp developer, and this should be set during gpio object implementation */
  281. uint32_t opn_cnt; /*!< gpio open count, open it will increase 1, close it will decrease 1, 0 for close, >0 for open */
  282. uint32_t direction; /*!< each bit direction of this GPIO, default all \ref GPIO_DIR_INPUT "input" for first open */
  283. uint32_t method; /*!< int/poll method for each bit of GPIO, 0 for poll, 1 for interrupt, default all \ref DEV_POLL_METHOD "poll" for first open */
  284. void * extra; /*!< a extra pointer to get hook to applications which should not used by bsp developer,
  285. this should be NULL for first open and you can \ref DEV_GPIO_INFO_SET_EXTRA_OBJECT "set"
  286. or \ref DEV_GPIO_INFO_GET_EXTRA_OBJECT "get" the extra information pointer */
  287. } DEV_GPIO_INFO, * DEV_GPIO_INFO_PTR;
  288. /** Set extra information pointer of gpio info */
  289. #define DEV_GPIO_INFO_SET_EXTRA_OBJECT(gpio_info_ptr, extra_info) (gpio_info_ptr)->extra = (void *)(extra_info)
  290. /** Get extra information pointer of gpio info */
  291. #define DEV_GPIO_INFO_GET_EXTRA_OBJECT(gpio_info_ptr) ((gpio_info_ptr)->extra)
  292. /** Method of all gpio bits set to poll */
  293. #define DEV_GPIO_BITS_MTHD_POLL (0)
  294. /** Method of all gpio bits set to interrupt */
  295. #define DEV_GPIO_BITS_MTHD_INTERRUPT (0xFFFFFFFF)
  296. /** Default method of all gpio bits should be poll for first open */
  297. #define DEV_GPIO_BITS_MTHD_DEFAULT (DEV_GPIO_BITS_MTHD_POLL)
  298. /**
  299. * \brief gpio device interface definition
  300. * \details define gpio device interface, like gpio information structure,
  301. * fuctions to open/close/control gpio, write or read data via gpio
  302. * \note all this details are implemented by user in user porting code
  303. */
  304. typedef struct dev_gpio {
  305. DEV_GPIO_INFO gpio_info; /*!< gpio device information */
  306. int32_t (*gpio_open) (uint32_t dir); /*!< open gpio device with pre-defined gpio direction */
  307. int32_t (*gpio_close) (void); /*!< close gpio device */
  308. int32_t (*gpio_control) (uint32_t ctrl_cmd, void *param); /*!< control gpio device */
  309. int32_t (*gpio_write) (uint32_t val, uint32_t mask); /*!< write gpio device with val, only write the masked bits */
  310. int32_t (*gpio_read) (uint32_t *val, uint32_t mask); /*!< read gpio device val, only read the masked bits */
  311. } DEV_GPIO, * DEV_GPIO_PTR;
  312. /**
  313. * \fn int32_t (* dev_gpio::gpio_open) (uint32_t dir)
  314. * \details Open a gpio device with pre-defined io direction.
  315. * \param[in] dir gpio direction for each bit
  316. * \retval E_OK Open successfully without any issues
  317. * \retval E_OPNED If device was opened before with different parameters,
  318. * then just increase the \ref dev_gpio_info::opn_cnt "opn_cnt" and return \ref E_OPNED
  319. * \retval E_OBJ Device object is not valid
  320. * \retval E_PAR Parameter is not valid
  321. * \retval E_NOSPT Open settings are not supported
  322. */
  323. /**
  324. * \fn int32_t (* dev_gpio::gpio_close) (void)
  325. * \details Close an gpio device, just decrease the \ref dev_gpio_info::opn_cnt "opn_cnt",
  326. * if \ref dev_gpio_info::opn_cnt "opn_cnt" equals 0, then close the device
  327. * \retval E_OK Close successfully without any issues(including scenario that device is already closed)
  328. * \retval E_OPNED Device is still opened, the device \ref dev_gpio_info::opn_cnt "opn_cnt" decreased by 1
  329. * \retval E_OBJ Device object is not valid
  330. */
  331. /**
  332. * \fn int32_t (* dev_gpio::gpio_control) (uint32_t ctrl_cmd, void *param)
  333. * \details Control an gpio device by \ref ctrl_cmd, with passed \ref param.
  334. * you can control gpio device using predefined gpio control commands defined using \ref DEV_SET_SYSCMD
  335. * (which must be implemented by bsp developer), such as \ref GPIO_CMD_SET_BIT_DIR_INPUT
  336. * "change masked gpio direction to input", and \ref DEVICE_HAL_GPIO_CTRLCMD "more".
  337. * And you can also control gpio device using your own specified commands defined using \ref DEV_SET_USRCMD,
  338. * but these specified commands should be defined in your own gpio device driver implementation.
  339. * \param[in] ctrl_cmd \ref DEVICE_HAL_GPIO_CTRLCMD "control command", to change or get some thing related to gpio
  340. * \param[in,out] param parameters that maybe argument of the command, or return values of the command
  341. * \retval E_OK Control device successfully
  342. * \retval E_CLSED Device is not opened
  343. * \retval E_OBJ Device object is not valid or not exists
  344. * \retval E_PAR Parameter is not valid for current control command
  345. * \retval E_SYS Control device failed, due to hardware issues
  346. * \retval E_CTX Control device failed, due to different reasons like in transfer state
  347. * \retval E_NOSPT Control command is not supported or not valid, such as interrupt is not supported
  348. */
  349. /**
  350. * \fn int32_t (* dev_gpio::gpio_write) (uint32_t val, uint32_t mask)
  351. * \details Write gpio with \ref val, and only change the masked bits of gpio.
  352. * \param[in] val the data that need to write to gpio
  353. * \param[in] mask gpio bit mask
  354. * \retval E_OK Write gpio with specified value successfully
  355. * \retval E_OBJ Device object is not valid or not exists
  356. * \retval E_PAR Parameter is not valid
  357. */
  358. /**
  359. * \fn int32_t (* dev_gpio::gpio_read) (uint32_t *val, uint32_t mask)
  360. * \details Read the masked gpio value
  361. * \param[out] val pointer to data need to read from gpio
  362. * \param[in] mask gpio bit mask
  363. * \retval E_OK Read gpio data successfully
  364. * \retval E_OBJ Device object is not valid or not exists
  365. * \retval E_PAR Parameter is not valid
  366. */
  367. /** @} */
  368. #ifdef __cplusplus
  369. extern "C" {
  370. #endif
  371. /**
  372. * \brief get an \ref dev_gpio "gpio device" by gpio device id.
  373. * For how to use gpio device hal refer to \ref dev_gpio "Functions in gpio device structure"
  374. * \param[in] gpio_id id of gpio, defined by user
  375. * \retval !NULL pointer to an \ref dev_gpio "gpio device structure"
  376. * \retval NULL failed to find the gpio device by \ref gpio_id
  377. * \note need to implemented by user in user code
  378. */
  379. extern DEV_GPIO_PTR gpio_get_dev(int32_t gpio_id);
  380. #ifdef __cplusplus
  381. }
  382. #endif
  383. /** @} */
  384. #endif /* _DEVICE_HAL_GPIO_H_ */