ql_gpio.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. 
  2. /*================================================================
  3. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  4. Quectel Wireless Solutions Proprietary and Confidential.
  5. =================================================================*/
  6. /*=================================================================
  7. EDIT HISTORY FOR MODULE
  8. This section contains comments describing changes made to the module.
  9. Notice that changes are listed in reverse chronological order.
  10. WHEN WHO WHAT, WHERE, WHY
  11. ------------ ------- -------------------------------------------------------------------------------
  12. =================================================================*/
  13. #ifndef QL_GPIO_H
  14. #define QL_GPIO_H
  15. #include "ql_api_common.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /*===========================================================================
  20. * Macro Definition
  21. ===========================================================================*/
  22. #define QL_GPIO_ERRCODE_BASE (QL_COMPONENT_BSP_GPIO<<16)
  23. /*===========================================================================
  24. * Enum
  25. ===========================================================================*/
  26. /**
  27. * GPIO errcode
  28. */
  29. typedef enum
  30. {
  31. QL_GPIO_SUCCESS = QL_SUCCESS,
  32. QL_GPIO_EXECUTE_ERR = 1|QL_GPIO_ERRCODE_BASE,
  33. QL_GPIO_INVALID_PARAM_ERR,
  34. QL_GPIO_OPEN_ERR,
  35. QL_GPIO_CONFIG_ERR,
  36. QL_GPIO_CALLBACK_ERR,
  37. QL_GPIO_LEVEL_TRIGGER_ERR,
  38. QL_GPIO_MEM_NULL_ERR,
  39. QL_GPIO_SET_DRVING_ERR,
  40. }ql_errcode_gpio;
  41. /**
  42. * GPIO number
  43. */
  44. typedef enum
  45. {
  46. GPIO_0 = 0,
  47. GPIO_1,
  48. GPIO_2,
  49. GPIO_3,
  50. GPIO_4,
  51. GPIO_5,
  52. GPIO_6,
  53. GPIO_7,
  54. GPIO_8,
  55. GPIO_9,
  56. GPIO_10,
  57. GPIO_11,
  58. GPIO_12,
  59. GPIO_13,
  60. GPIO_14,
  61. GPIO_15,
  62. GPIO_16,
  63. GPIO_17,
  64. GPIO_18,
  65. GPIO_19,
  66. GPIO_20,
  67. GPIO_21,
  68. GPIO_22,
  69. GPIO_23,
  70. GPIO_24,
  71. GPIO_25,
  72. GPIO_26,
  73. GPIO_27,
  74. GPIO_28,
  75. GPIO_29,
  76. GPIO_30,
  77. GPIO_31,
  78. GPIO_32,
  79. GPIO_33,
  80. GPIO_34,
  81. GPIO_35,
  82. GPIO_36,
  83. GPIO_37,
  84. GPIO_38,
  85. GPIO_39,
  86. GPIO_40,
  87. GPIO_41,
  88. GPIO_42,
  89. GPIO_43,
  90. GPIO_44,
  91. GPIO_45,
  92. GPIO_46,
  93. GPIO_47,
  94. GPIO_MAX
  95. }ql_GpioNum;
  96. /**
  97. * GPIO direction
  98. */
  99. typedef enum
  100. {
  101. GPIO_INPUT,
  102. GPIO_OUTPUT
  103. }ql_GpioDir;
  104. /**
  105. * GPIO output level
  106. */
  107. typedef enum
  108. {
  109. LVL_LOW,
  110. LVL_HIGH
  111. }ql_LvlMode;
  112. /**
  113. * GPIO input pull mode
  114. */
  115. typedef enum
  116. {
  117. PULL_NONE,
  118. PULL_DOWN,
  119. PULL_UP
  120. }ql_PullMode;
  121. /**
  122. * GPIO interrupt trigger
  123. */
  124. typedef enum
  125. {
  126. EDGE_TRIGGER,
  127. LEVEL_TRIGGER
  128. }ql_TriggerMode;
  129. /**
  130. * GPIO interrupt debounce
  131. */
  132. typedef enum
  133. {
  134. DEBOUNCE_DIS,
  135. DEBOUNCE_EN
  136. }ql_DebounceMode;
  137. /**
  138. * GPIO edge-trigger mode
  139. */
  140. typedef enum
  141. {
  142. EDGE_RISING,
  143. EDGE_FALLING,
  144. EDGE_BOTH
  145. }ql_EdgeMode;
  146. /*===========================================================================
  147. * Functions declaration
  148. ===========================================================================*/
  149. /**
  150. * @brief GPIO initialize
  151. * @param gpio_num : GPIO number
  152. * @param gpio_dir : GPIO direction
  153. * @param gpio_pull : GPIO input pull
  154. * @param gpio_lvl : GPIO output level
  155. * @return
  156. * QL_GPIO_INVALID_PARAM_ERR
  157. * QL_GPIO_OPEN_ERR
  158. * QL_GPIO_CONFIG_ERR
  159. * QL_GPIO_SUCCESS
  160. */
  161. ql_errcode_gpio ql_gpio_init(ql_GpioNum gpio_num, ql_GpioDir gpio_dir, ql_PullMode gpio_pull, ql_LvlMode gpio_lvl);
  162. /**
  163. * @brief GPIO de-initialize
  164. * @param gpio_num : GPIO number
  165. * @return
  166. * QL_GPIO_INVALID_PARAM_ERR
  167. * QL_GPIO_SUCCESS
  168. */
  169. ql_errcode_gpio ql_gpio_deinit(ql_GpioNum gpio_num);
  170. /**
  171. * @brief GPIO set output level
  172. * @param gpio_num : GPIO number
  173. * @param gpio_lvl : GPIO set output level
  174. * @return
  175. * QL_GPIO_INVALID_PARAM_ERR
  176. * QL_GPIO_SUCCESS
  177. */
  178. ql_errcode_gpio ql_gpio_set_level(ql_GpioNum gpio_num, ql_LvlMode gpio_lvl);
  179. /**
  180. * @brief GPIO get output level
  181. * @param gpio_num : GPIO number
  182. * @param gpio_lvl : GPIO get output level
  183. * @return
  184. * QL_GPIO_INVALID_PARAM_ERR
  185. * QL_GPIO_SUCCESS
  186. */
  187. ql_errcode_gpio ql_gpio_get_level(ql_GpioNum gpio_num, ql_LvlMode *gpio_lvl);
  188. /**
  189. * @brief GPIO set direction
  190. * @param gpio_num : GPIO number
  191. * @param gpio_dir : GPIO set direction
  192. * @return
  193. * QL_GPIO_INVALID_PARAM_ERR
  194. * QL_GPIO_SUCCESS
  195. */
  196. ql_errcode_gpio ql_gpio_set_direction(ql_GpioNum gpio_num, ql_GpioDir gpio_dir);
  197. /**
  198. * @brief GPIO get direction
  199. * @param gpio_num : GPIO number
  200. * @param gpio_dir : GPIO get direction
  201. * @return
  202. * QL_GPIO_INVALID_PARAM_ERR
  203. * QL_GPIO_SUCCESS
  204. */
  205. ql_errcode_gpio ql_gpio_get_direction(ql_GpioNum gpio_num, ql_GpioDir *gpio_dir);
  206. /**
  207. * @brief GPIO set pull
  208. * @param gpio_num : GPIO number
  209. * @param gpio_pull : GPIO set input pull
  210. * @return
  211. * QL_GPIO_INVALID_PARAM_ERR
  212. * QL_GPIO_CONFIG_ERR
  213. * QL_GPIO_SUCCESS
  214. */
  215. ql_errcode_gpio ql_gpio_set_pull(ql_GpioNum gpio_num, ql_PullMode gpio_pull);
  216. /**
  217. * @brief GPIO get pull
  218. * @param gpio_num : GPIO number
  219. * @param gpio_pull : GPIO get input pull
  220. * @return
  221. * QL_GPIO_INVALID_PARAM_ERR
  222. * QL_GPIO_CONFIG_ERR
  223. * QL_GPIO_SUCCESS
  224. */
  225. ql_errcode_gpio ql_gpio_get_pull(ql_GpioNum gpio_num, ql_PullMode *gpio_pull);
  226. /**
  227. * @brief GPIO interrupt register
  228. * @param gpio_num : GPIO number
  229. * @param gpio_trigger : GPIO interrupt trigger mode
  230. * @param gpio_debounce : GPIO interrupt trigger debounce enable/disable
  231. * @param gpio_edge : GPIO interrupt edge/level trigger configure
  232. * @param gpio_pull : GPIO get input pull
  233. * @param int_cb : GPIO interrupt cb
  234. * @param cb_ctx : GPIO interrupt cb_ctx
  235. * @return
  236. * QL_GPIO_INVALID_PARAM_ERR
  237. * QL_GPIO_LEVEL_TRIGGER_ERR
  238. * QL_GPIO_OPEN_ERR
  239. * QL_GPIO_CONFIG_ERR
  240. * QL_GPIO_CALLBACK_ERR
  241. * QL_GPIO_SUCCESS
  242. * Attention:
  243. 1. it is forbidden to block the interrupt;
  244. 2. it is forbidden to call Audio start/stop/close, file write/read,CFW(releated to RPC)in interrupt;
  245. 3. it is forbidden to enter critical in interrupt
  246. 4. it is suggested for users to perform simple operations , or send event(no timeout) to inform your task in interrupt
  247. */
  248. ql_errcode_gpio ql_int_register(ql_GpioNum gpio_num, ql_TriggerMode gpio_trigger, ql_DebounceMode gpio_debounce,
  249. ql_EdgeMode gpio_edge, ql_PullMode gpio_pull,
  250. void *int_cb, void *cb_ctx);
  251. /**
  252. * @brief GPIO interrupt unregister
  253. * @param gpio_num : GPIO number
  254. * @return
  255. * QL_GPIO_INVALID_PARAM_ERR
  256. * QL_GPIO_SUCCESS
  257. */
  258. ql_errcode_gpio ql_int_unregister(ql_GpioNum gpio_num);
  259. /**
  260. * @brief GPIO interrupt enable
  261. * @param gpio_num : GPIO number
  262. * @return
  263. * QL_GPIO_INVALID_PARAM_ERR
  264. * QL_GPIO_CONFIG_ERR
  265. * QL_GPIO_CALLBACK_ERR
  266. * QL_GPIO_SUCCESS
  267. */
  268. ql_errcode_gpio ql_int_enable(ql_GpioNum gpio_num);
  269. /**
  270. * @brief GPIO interrupt disable
  271. * @param gpio_num : GPIO number
  272. * @return
  273. * QL_GPIO_INVALID_PARAM_ERR
  274. * QL_GPIO_SUCCESS
  275. */
  276. ql_errcode_gpio ql_int_disable(ql_GpioNum gpio_num);
  277. /**
  278. * @brief Pin function seclect
  279. * @param pin_num : Pin number
  280. * @param func_sel : seclected Pin function
  281. * @return
  282. * QL_GPIO_INVALID_PARAM_ERR
  283. * QL_GPIO_SUCCESS
  284. */
  285. ql_errcode_gpio ql_pin_set_func(uint8_t pin_num, uint8_t func_sel);
  286. /**
  287. * @brief Seclected Pin function get
  288. * @param pin_num : Pin number
  289. * @param func_sel : seclected Pin function
  290. * @return
  291. * QL_GPIO_INVALID_PARAM_ERR
  292. * QL_GPIO_SUCCESS
  293. */
  294. ql_errcode_gpio ql_pin_get_func(uint8_t pin_num, uint8_t *func_sel);
  295. /**
  296. * @brief
  297. * @param pin_num : Pin number
  298. * @return
  299. * QL_GPIO_INVALID_PARAM_ERR
  300. * QL_GPIO_SUCCESS
  301. */
  302. ql_errcode_gpio ql_pin_set_gpio(uint8_t pin_num);
  303. /**
  304. * @brief set pin drive capability
  305. * @param pin_num : Pin number
  306. * @param drving : drive capability:8850:
  307. 2bit: 0-2ma,1-4ma,2-6ma,3-8ma,
  308. 4bit: 0-2.4ma,1-5.5ma,2-7.5ma,3-10.4ma, 4-12.4ma,5-15ma,6-17.4ma,7-20ma,
  309. 8-24.6ma,9-27.8ma,10-29.6ma,11-32ma, 12-34.2ma,13-37ma,14-39ma,15-42ma
  310. * @return
  311. * QL_GPIO_INVALID_PARAM_ERR
  312. * QL_GPIO_SUCCESS
  313. */
  314. ql_errcode_gpio ql_pin_set_drving(uint8_t pin_num, char drving);
  315. #ifdef __cplusplus
  316. } /*"C" */
  317. #endif
  318. #endif /* QL_GPIO_H */