kbi.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /******************************************************************************
  2. **
  3. * @brief header file for KBI.
  4. *
  5. *******************************************************************************
  6. *
  7. * provide APIs for accessing KBI
  8. ******************************************************************************/
  9. #ifndef _KBI_H_
  10. #define _KBI_H_
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /******************************************************************************
  15. * Includes
  16. ******************************************************************************/
  17. /******************************************************************************
  18. * Constants
  19. ******************************************************************************/
  20. /*!
  21. * @brief KBI MODE select enum.
  22. *
  23. */
  24. typedef enum
  25. {
  26. KBI_MODE_EDGE_ONLY = 0, /*!< select edge only mode */
  27. KBI_MODE_EDGE_LEVEL /*!< select both edge and level mode */
  28. }KBI_ModeType;
  29. /*!
  30. * @brief KBI Edge select enum.
  31. *
  32. */
  33. typedef enum
  34. {
  35. KBI_FALLING_EDGE_LOW_LEVEL = 0, /*!< select falling edge and/or low level */
  36. KBI_RISING_EDGE_HIGH_LEVEL /*!< select rising edge and/or high level */
  37. }KBI_EdgeType;
  38. /******************************************************************************
  39. * Macros
  40. ******************************************************************************/
  41. /******************************************************************************
  42. * KBI module max number and port pins definition
  43. *
  44. *//*! @addtogroup kbi_macro
  45. * @{
  46. *******************************************************************************/
  47. #define KBI_MAX_NO 2 /*!< max number of modules */
  48. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  49. #define KBI_MAX_PINS_PER_PORT 8 /*!< max number of pins */
  50. #elif defined(CPU_NV32M4)
  51. #define KBI_MAX_PINS_PER_PORT 32 /*!< max number of pins */
  52. #endif
  53. /*! @} End of kbi_macro */
  54. /******************************************************************************
  55. * Types
  56. ******************************************************************************/
  57. /*! @brief KBI_CALLBACK function declaration */
  58. typedef void (*KBI_CallbackType)(void);
  59. /*! @} End of kbi_callback */
  60. /******************************************************************************
  61. * KBI pin config struct
  62. *
  63. *//*! @addtogroup kbi_pinconfigstruct
  64. * @{
  65. *******************************************************************************/
  66. /*!
  67. * @brief KBI pin enable and edge select struct.
  68. *
  69. */
  70. typedef struct
  71. {
  72. uint8_t bEdge : 1; /*!< edge/level select bit */
  73. uint8_t bEn : 1; /*!< pin enable bit */
  74. uint8_t bRsvd : 6; /*!< reserved */
  75. } KBI_PinConfigType;
  76. /*! @} End of kbi_pinconfigstruct */
  77. /******************************************************************************
  78. * KBI config struct
  79. *
  80. *//*! @addtogroup kbi_configstruct
  81. * @{
  82. *******************************************************************************/
  83. /*!
  84. * @brief KBI status and control struct.
  85. *
  86. */
  87. typedef struct
  88. {
  89. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  90. struct
  91. {
  92. uint8_t bMode : 1; /*!< KBI detection mode select */
  93. uint8_t bIntEn : 1; /*!< KBI interrupt enable bit */
  94. uint8_t bRsvd : 6; /*!< reserved */
  95. } sBits;
  96. #elif defined(CPU_NV32M4)
  97. struct
  98. {
  99. uint32_t bMode : 1; /*!< KBI detection mode select */
  100. uint32_t bIntEn : 1; /*!< KBI interrupt enable bit */
  101. uint32_t bRsvd2 : 2; /*!< reserved */
  102. uint32_t bKbspEn : 1; /*!<Real KBI_SP register enable*/
  103. uint32_t bRstKbsp: 1; /*!<Reset KBI_SP register*/
  104. uint32_t bRsvd26 : 26; /*!< reserved */
  105. } sBits;
  106. #endif
  107. KBI_PinConfigType sPin[KBI_MAX_PINS_PER_PORT];
  108. } KBI_ConfigType, *KBI_ConfigTypePtr;
  109. /*! @} End of kbi_configstruct */
  110. /******************************************************************************
  111. * Global variables
  112. ******************************************************************************/
  113. /*!
  114. * inline functions
  115. */
  116. /******************************************************************************
  117. * KBI api list
  118. *
  119. *//*! @addtogroup kbi_api_list
  120. * @{
  121. *******************************************************************************/
  122. /*****************************************************************************//*!
  123. *
  124. * @brief set detect falling edge only.
  125. *
  126. * @param[in] pKBI pointer to KBI module.
  127. * @param[in] PinMasks indicate pin numbers.
  128. *
  129. * @return none.
  130. *
  131. * @ Pass/ Fail criteria: none.
  132. *
  133. * @see KBI_DetectRisingEdge.
  134. *
  135. *****************************************************************************/
  136. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  137. __STATIC_INLINE void KBI_DetectFallingEdge(KBI_Type *pKBI, uint8_t PinMasks)
  138. #elif defined(CPU_NV32M4)
  139. __STATIC_INLINE void KBI_DetectFallingEdge(KBI_Type *pKBI, uint32_t PinMasks)
  140. #endif
  141. {
  142. pKBI->SC &= ~KBI_SC_KBMOD_MASK;
  143. pKBI->ES &= ~(PinMasks);
  144. }
  145. /*****************************************************************************//*!
  146. *
  147. * @brief set detect falling edge only.
  148. *
  149. * @param[in] pKBI pointer to KBI module.
  150. * @param[in] PinMasks indicate pin numbers.
  151. *
  152. * @return none.
  153. *
  154. * @ Pass/ Fail criteria: none.
  155. *
  156. * @see KBI_DetectFallingEdge.
  157. *
  158. *****************************************************************************/
  159. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  160. __STATIC_INLINE void KBI_DetectRisingEdge(KBI_Type *pKBI, uint8_t PinMasks)
  161. #elif defined(CPU_NV32M4)
  162. __STATIC_INLINE void KBI_DetectRisingEdge(KBI_Type *pKBI, uint32_t PinMasks)
  163. #endif
  164. {
  165. pKBI->SC &= ~KBI_SC_KBMOD_MASK;
  166. pKBI->ES |= (PinMasks);
  167. }
  168. /*****************************************************************************//*!
  169. *
  170. * @brief set detect falling edge only.
  171. *
  172. * @param[in] pKBI pointer to KBI module.
  173. * @param[in] PinMasks indicate pin number/mask.
  174. *
  175. * @return none.
  176. *
  177. * @ Pass/ Fail criteria: none.
  178. *
  179. * @see KBI_DetectFallingEdgeLowLevel.
  180. *
  181. *****************************************************************************/
  182. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  183. __STATIC_INLINE void KBI_DetectRisingEdgeHighLevel(KBI_Type *pKBI, uint8_t PinMasks)
  184. #elif defined(CPU_NV32M4)
  185. __STATIC_INLINE void KBI_DetectRisingEdgeHighLevel(KBI_Type *pKBI, uint32_t PinMasks)
  186. #endif
  187. {
  188. pKBI->SC |= KBI_SC_KBMOD_MASK;
  189. pKBI->ES |= (PinMasks);
  190. }
  191. /*****************************************************************************//*!
  192. *
  193. * @brief set detect falling edge only.
  194. *
  195. * @param[in] pKBI pointer to KBI module.
  196. * @param[in] PinMasks indicate pin number/mask.
  197. *
  198. * @return none.
  199. *
  200. * @ Pass/ Fail criteria: none.
  201. *
  202. * @see KBI_DetectRisingEdgeHighLevel.
  203. *
  204. *****************************************************************************/
  205. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  206. __STATIC_INLINE void KBI_DetectFallingEdgeLowLevel(KBI_Type *pKBI, uint8_t PinMasks)
  207. #elif defined(CPU_NV32M4)
  208. __STATIC_INLINE void KBI_DetectFallingEdgeLowLevel(KBI_Type *pKBI, uint32_t PinMasks)
  209. #endif
  210. {
  211. pKBI->SC |= KBI_SC_KBMOD_MASK;
  212. pKBI->ES &= ~(PinMasks);
  213. }
  214. /*****************************************************************************//*!
  215. *
  216. * @brief enable the pin specified.
  217. *
  218. * @param[in] pKBI pointer to KBI module.
  219. * @param[in] PinMasks indicate pin number/mask.
  220. *
  221. * @return none.
  222. *
  223. * @ Pass/ Fail criteria: none.
  224. *
  225. * @see KBI_Disable.
  226. *
  227. *****************************************************************************/
  228. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  229. __STATIC_INLINE void KBI_Enable(KBI_Type *pKBI, uint8_t PinMasks)
  230. #elif defined(CPU_NV32M4)
  231. __STATIC_INLINE void KBI_Enable(KBI_Type *pKBI, uint32_t PinMasks)
  232. #endif
  233. {
  234. pKBI->PE |= (PinMasks);
  235. }
  236. /*****************************************************************************//*!
  237. *
  238. * @brief disable the pin specified.
  239. *
  240. * @param[in] pKBI pointer to KBI module.
  241. * @param[in] PinMasks indicate pin number/mask.
  242. *
  243. * @return none.
  244. *
  245. * @ Pass/ Fail criteria: none.
  246. *
  247. * @see KBI_Enable.
  248. *
  249. *****************************************************************************/
  250. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  251. __STATIC_INLINE void KBI_Disable(KBI_Type *pKBI, uint8_t PinMasks)
  252. #elif defined(CPU_NV32M4)
  253. __STATIC_INLINE void KBI_Disable(KBI_Type *pKBI, uint32_t PinMasks)
  254. #endif
  255. {
  256. pKBI->PE &= ~(PinMasks);
  257. }
  258. /*****************************************************************************//*!
  259. *
  260. * @brief enable the corresponding interrupt.
  261. *
  262. * @param[in] pKBI pointer to KBI module.
  263. *
  264. * @return none.
  265. *
  266. * @ Pass/ Fail criteria: none.
  267. *
  268. * @see KBI_DisableInt.
  269. *
  270. *****************************************************************************/
  271. __STATIC_INLINE void KBI_EnableInt(KBI_Type *pKBI)
  272. {
  273. pKBI->SC |= KBI_SC_KBIE_MASK;
  274. }
  275. /*****************************************************************************//*!
  276. *
  277. * @brief disable the corresponding interrupt.
  278. *
  279. * @param[in] pKBI pointer to KBI module.
  280. *
  281. * @return none.
  282. *
  283. * @ Pass/ Fail criteria: none
  284. *
  285. * @see KBI_EnableInt.
  286. *
  287. *****************************************************************************/
  288. __STATIC_INLINE void KBI_DisableInt(KBI_Type *pKBI)
  289. {
  290. pKBI->SC &= ~KBI_SC_KBIE_MASK;
  291. }
  292. /*****************************************************************************//*!
  293. *
  294. * @brief Get the corresponding status flag bits.
  295. *
  296. * @param[in] pKBI pointer to KBI module.
  297. *
  298. * @return uint8_t.
  299. *
  300. * @ Pass/ Fail criteria: none.
  301. *
  302. * @see KBI_ClrFlags.
  303. *
  304. *****************************************************************************/
  305. #if defined(CPU_NV32)|| defined(CPU_NV32M3)
  306. __STATIC_INLINE uint8_t KBI_GetFlags(KBI_Type *pKBI)
  307. #elif defined(CPU_NV32M4)
  308. __STATIC_INLINE uint32_t KBI_GetFlags(KBI_Type *pKBI)
  309. #endif
  310. {
  311. return (pKBI->SC & KBI_SC_KBF_MASK);
  312. }
  313. /*****************************************************************************//*!
  314. *
  315. * @brief clear the corresponding status flag bits.
  316. *
  317. * @param[in] pKBI pointer to KBI module
  318. *
  319. * @return none.
  320. *
  321. * @ Pass/ Fail criteria: none
  322. *
  323. * @see KBI_GetFlags.
  324. *
  325. *****************************************************************************/
  326. __STATIC_INLINE void KBI_ClrFlags(KBI_Type *pKBI)
  327. {
  328. pKBI->SC |= KBI_SC_KBACK_MASK;
  329. }
  330. #if defined(CPU_NV32M4)
  331. /*****************************************************************************//*!
  332. *
  333. * @brief Real KBI_SP register enable.
  334. *
  335. * @param[in] pKBI pointer to KBI module
  336. *
  337. * @return none.
  338. *
  339. * @ Pass/ Fail criteria: none
  340. *
  341. * @see The real ETMe value of Keyboard source pin to be read.
  342. *
  343. *****************************************************************************/
  344. __STATIC_INLINE void KBI_SPEnable(KBI_Type *pKBI)
  345. {
  346. pKBI->SC |= KBI_SC_KBSPEN_MASK;
  347. }
  348. /*****************************************************************************//*!
  349. *
  350. * @brief Get KBI source pin register fields.
  351. *
  352. * @param[in] pKBI pointer to KBI module.
  353. *
  354. * @return uint32_t.
  355. *
  356. * @ Pass/ Fail criteria: none.
  357. *
  358. * @see KBI_GetSP.
  359. *
  360. *****************************************************************************/
  361. __STATIC_INLINE uint32_t KBI_GetSP(KBI_Type *pKBI)
  362. {
  363. return (pKBI->SP & KBI_SP_SP_MASK);
  364. }
  365. /*****************************************************************************//*!
  366. *
  367. * @brief Reset KBI_SP register.
  368. *
  369. * @param[in] pKBI pointer to KBI module
  370. *
  371. * @return none.
  372. *
  373. * @ Pass/ Fail criteria: none
  374. *
  375. * @see KBI_RstSP.
  376. *
  377. *****************************************************************************/
  378. __STATIC_INLINE void KBI_RstSP(KBI_Type *pKBI)
  379. {
  380. pKBI->SC |= KBI_SC_RSTKBSP_MASK;
  381. }
  382. #endif
  383. /*! @} End of kbi_api_list */
  384. /******************************************************************************
  385. * Global functions
  386. ******************************************************************************/
  387. void KBI_Init(KBI_Type *pKBI, KBI_ConfigType *pConfig);
  388. void KBI_SetCallback(KBI_Type *pKBI, KBI_CallbackType pfnCallback);
  389. #ifdef __cplusplus
  390. }
  391. #endif
  392. #endif