lpc_qei.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /**********************************************************************
  2. * $Id$ lpc_qei.h 2011-06-02
  3. *//**
  4. * @file lpc_qei.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for QEI firmware library on LPC
  7. * @version 1.0
  8. * @date 02. June. 2011
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2011, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup QEI QEI (Quadrature Encoder Interface)
  34. * @ingroup LPC_CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef __LPC17X_8X_QEI_H_
  38. #define __LPC17X_8X_QEI_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC407x_8x_177x_8x.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Public Macros -------------------------------------------------------------- */
  47. /** @defgroup QEI_Public_Macros QEI Public Macros
  48. * @{
  49. */
  50. #define QEI_0 (0)
  51. /* QEI Reset types */
  52. /** QEI Reset types - Reset position counter */
  53. #define QEI_RESET_POS QEI_CON_RESP
  54. /** QEI Reset types - Reset Posistion Counter on Index */
  55. #define QEI_RESET_POSOnIDX QEI_CON_RESPI
  56. /** QEI Reset types - Reset Velocity */
  57. #define QEI_RESET_VEL QEI_CON_RESV
  58. /** QEI Reset types - Reset Index Counter */
  59. #define QEI_RESET_IDX QEI_CON_RESI
  60. /* QEI Direction Invert Type Option */
  61. /** QEI Direction Invert Type Option - Direction is not inverted */
  62. #define QEI_DIRINV_NONE ((uint32_t)(0))
  63. /** QEI Direction Invert Type Option - Direction is complemented */
  64. #define QEI_DIRINV_CMPL ((uint32_t)(1))
  65. /* QEI Signal Mode Option */
  66. /** Signal operation: Quadrature phase mode */
  67. #define QEI_SIGNALMODE_QUAD ((uint32_t)(0))
  68. /** Signal operation: Clock/Direction mode */
  69. #define QEI_SIGNALMODE_CLKDIR ((uint32_t)(1))
  70. /* QEI Capture Mode Option */
  71. /** Capture mode: Only Phase-A edges are counted (2X) */
  72. #define QEI_CAPMODE_2X ((uint32_t)(0))
  73. /** Capture mode: BOTH PhA and PhB edges are counted (4X)*/
  74. #define QEI_CAPMODE_4X ((uint32_t)(1))
  75. /* QEI Invert Index Signal Option */
  76. /** Invert Index signal option: None */
  77. #define QEI_INVINX_NONE ((uint32_t)(0))
  78. /** Invert Index signal option: Enable */
  79. #define QEI_INVINX_EN ((uint32_t)(1))
  80. /* QEI timer reload option */
  81. /** Reload value in absolute value */
  82. #define QEI_TIMERRELOAD_TICKVAL ((uint8_t)(0))
  83. /** Reload value in microsecond value */
  84. #define QEI_TIMERRELOAD_USVAL ((uint8_t)(1))
  85. /* QEI Flag Status type */
  86. /** Direction status */
  87. #define QEI_STATUS_DIR ((uint32_t)(1<<0))
  88. /* QEI Compare Position channel option */
  89. /** QEI compare position channel 0 */
  90. #define QEI_COMPPOS_CH_0 ((uint8_t)(0))
  91. /** QEI compare position channel 1 */
  92. #define QEI_COMPPOS_CH_1 ((uint8_t)(1))
  93. /** QEI compare position channel 2 */
  94. #define QEI_COMPPOS_CH_2 ((uint8_t)(2))
  95. /* QEI interrupt flag type */
  96. /** index pulse was detected interrupt */
  97. #define QEI_INTFLAG_INX_Int ((uint32_t)(1<<0))
  98. /** Velocity timer over flow interrupt */
  99. #define QEI_INTFLAG_TIM_Int ((uint32_t)(1<<1))
  100. /** Capture velocity is less than compare interrupt */
  101. #define QEI_INTFLAG_VELC_Int ((uint32_t)(1<<2))
  102. /** Change of direction interrupt */
  103. #define QEI_INTFLAG_DIR_Int ((uint32_t)(1<<3))
  104. /** An encoder phase error interrupt */
  105. #define QEI_INTFLAG_ERR_Int ((uint32_t)(1<<4))
  106. /** An encoder clock pulse was detected interrupt */
  107. #define QEI_INTFLAG_ENCLK_Int ((uint32_t)(1<<5))
  108. /** position 0 compare value is equal to the current position interrupt */
  109. #define QEI_INTFLAG_POS0_Int ((uint32_t)(1<<6))
  110. /** position 1 compare value is equal to the current position interrupt */
  111. #define QEI_INTFLAG_POS1_Int ((uint32_t)(1<<7))
  112. /** position 2 compare value is equal to the current position interrupt */
  113. #define QEI_INTFLAG_POS2_Int ((uint32_t)(1<<8))
  114. /** Index compare value is equal to the current index count interrupt */
  115. #define QEI_INTFLAG_REV_Int ((uint32_t)(1<<9))
  116. /** Combined position 0 and revolution count interrupt */
  117. #define QEI_INTFLAG_POS0REV_Int ((uint32_t)(1<<10))
  118. /** Combined position 1 and revolution count interrupt */
  119. #define QEI_INTFLAG_POS1REV_Int ((uint32_t)(1<<11))
  120. /** Combined position 2 and revolution count interrupt */
  121. #define QEI_INTFLAG_POS2REV_Int ((uint32_t)(1<<12))
  122. /**
  123. * @}
  124. */
  125. /* Private Macros ------------------------------------------------------------- */
  126. /** @defgroup QEI_Private_Macros QEI Private Macros
  127. * @{
  128. */
  129. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  130. /* Quadrature Encoder Interface Control Register Definition --------------------- */
  131. /*********************************************************************//**
  132. * Macro defines for QEI Control register
  133. **********************************************************************/
  134. /** Reset position counter */
  135. #define QEI_CON_RESP ((uint32_t)(1<<0))
  136. /** Reset Posistion Counter on Index */
  137. #define QEI_CON_RESPI ((uint32_t)(1<<1))
  138. /** Reset Velocity */
  139. #define QEI_CON_RESV ((uint32_t)(1<<2))
  140. /** Reset Index Counter */
  141. #define QEI_CON_RESI ((uint32_t)(1<<3))
  142. /** QEI Control register bit-mask */
  143. #define QEI_CON_BITMASK ((uint32_t)(0x0F))
  144. /*********************************************************************//**
  145. * Macro defines for QEI Configuration register
  146. **********************************************************************/
  147. /** Direction Invert */
  148. #define QEI_CONF_DIRINV ((uint32_t)(1<<0))
  149. /** Signal mode */
  150. #define QEI_CONF_SIGMODE ((uint32_t)(1<<1))
  151. /** Capture mode */
  152. #define QEI_CONF_CAPMODE ((uint32_t)(1<<2))
  153. /** Invert index */
  154. #define QEI_CONF_INVINX ((uint32_t)(1<<3))
  155. /** QEI Configuration register bit-mask */
  156. #define QEI_CONF_BITMASK ((uint32_t)(0x0F))
  157. /*********************************************************************//**
  158. * Macro defines for QEI Status register
  159. **********************************************************************/
  160. /** Direction bit */
  161. #define QEI_STAT_DIR ((uint32_t)(1<<0))
  162. /** QEI status register bit-mask */
  163. #define QEI_STAT_BITMASK ((uint32_t)(1<<0))
  164. /* Quadrature Encoder Interface Interrupt registers definitions --------------------- */
  165. /*********************************************************************//**
  166. * Macro defines for QEI Interrupt Status register
  167. **********************************************************************/
  168. /** Indicates that an index pulse was detected */
  169. #define QEI_INTSTAT_INX_Int ((uint32_t)(1<<0))
  170. /** Indicates that a velocity timer overflow occurred */
  171. #define QEI_INTSTAT_TIM_Int ((uint32_t)(1<<1))
  172. /** Indicates that capture velocity is less than compare velocity */
  173. #define QEI_INTSTAT_VELC_Int ((uint32_t)(1<<2))
  174. /** Indicates that a change of direction was detected */
  175. #define QEI_INTSTAT_DIR_Int ((uint32_t)(1<<3))
  176. /** Indicates that an encoder phase error was detected */
  177. #define QEI_INTSTAT_ERR_Int ((uint32_t)(1<<4))
  178. /** Indicates that and encoder clock pulse was detected */
  179. #define QEI_INTSTAT_ENCLK_Int ((uint32_t)(1<<5))
  180. /** Indicates that the position 0 compare value is equal to the current position */
  181. #define QEI_INTSTAT_POS0_Int ((uint32_t)(1<<6))
  182. /** Indicates that the position 1compare value is equal to the current position */
  183. #define QEI_INTSTAT_POS1_Int ((uint32_t)(1<<7))
  184. /** Indicates that the position 2 compare value is equal to the current position */
  185. #define QEI_INTSTAT_POS2_Int ((uint32_t)(1<<8))
  186. /** Indicates that the index compare value is equal to the current index count */
  187. #define QEI_INTSTAT_REV_Int ((uint32_t)(1<<9))
  188. /** Combined position 0 and revolution count interrupt. Set when
  189. * both the POS0_Int bit is set and the REV_Int is set */
  190. #define QEI_INTSTAT_POS0REV_Int ((uint32_t)(1<<10))
  191. /** Combined position 1 and revolution count interrupt. Set when
  192. both the POS1_Int bit is set and the REV_Int is set */
  193. #define QEI_INTSTAT_POS1REV_Int ((uint32_t)(1<<11))
  194. /** Combined position 2 and revolution count interrupt. Set when
  195. both the POS2_Int bit is set and the REV_Int is set */
  196. #define QEI_INTSTAT_POS2REV_Int ((uint32_t)(1<<12))
  197. /** QEI Interrupt Status register bit-mask */
  198. #define QEI_INTSTAT_BITMASK ((uint32_t)(0x1FFF))
  199. /*********************************************************************//**
  200. * Macro defines for QEI Interrupt Set register
  201. **********************************************************************/
  202. /** Set Bit Indicates that an index pulse was detected */
  203. #define QEI_INTSET_INX_Int ((uint32_t)(1<<0))
  204. /** Set Bit Indicates that a velocity timer overflow occurred */
  205. #define QEI_INTSET_TIM_Int ((uint32_t)(1<<1))
  206. /** Set Bit Indicates that capture velocity is less than compare velocity */
  207. #define QEI_INTSET_VELC_Int ((uint32_t)(1<<2))
  208. /** Set Bit Indicates that a change of direction was detected */
  209. #define QEI_INTSET_DIR_Int ((uint32_t)(1<<3))
  210. /** Set Bit Indicates that an encoder phase error was detected */
  211. #define QEI_INTSET_ERR_Int ((uint32_t)(1<<4))
  212. /** Set Bit Indicates that and encoder clock pulse was detected */
  213. #define QEI_INTSET_ENCLK_Int ((uint32_t)(1<<5))
  214. /** Set Bit Indicates that the position 0 compare value is equal to the current position */
  215. #define QEI_INTSET_POS0_Int ((uint32_t)(1<<6))
  216. /** Set Bit Indicates that the position 1compare value is equal to the current position */
  217. #define QEI_INTSET_POS1_Int ((uint32_t)(1<<7))
  218. /** Set Bit Indicates that the position 2 compare value is equal to the current position */
  219. #define QEI_INTSET_POS2_Int ((uint32_t)(1<<8))
  220. /** Set Bit Indicates that the index compare value is equal to the current index count */
  221. #define QEI_INTSET_REV_Int ((uint32_t)(1<<9))
  222. /** Set Bit that combined position 0 and revolution count interrupt */
  223. #define QEI_INTSET_POS0REV_Int ((uint32_t)(1<<10))
  224. /** Set Bit that Combined position 1 and revolution count interrupt */
  225. #define QEI_INTSET_POS1REV_Int ((uint32_t)(1<<11))
  226. /** Set Bit that Combined position 2 and revolution count interrupt */
  227. #define QEI_INTSET_POS2REV_Int ((uint32_t)(1<<12))
  228. /** QEI Interrupt Set register bit-mask */
  229. #define QEI_INTSET_BITMASK ((uint32_t)(0x1FFF))
  230. /*********************************************************************//**
  231. * Macro defines for QEI Interrupt Clear register
  232. **********************************************************************/
  233. /** Clear Bit Indicates that an index pulse was detected */
  234. #define QEI_INTCLR_INX_Int ((uint32_t)(1<<0))
  235. /** Clear Bit Indicates that a velocity timer overflow occurred */
  236. #define QEI_INTCLR_TIM_Int ((uint32_t)(1<<1))
  237. /** Clear Bit Indicates that capture velocity is less than compare velocity */
  238. #define QEI_INTCLR_VELC_Int ((uint32_t)(1<<2))
  239. /** Clear Bit Indicates that a change of direction was detected */
  240. #define QEI_INTCLR_DIR_Int ((uint32_t)(1<<3))
  241. /** Clear Bit Indicates that an encoder phase error was detected */
  242. #define QEI_INTCLR_ERR_Int ((uint32_t)(1<<4))
  243. /** Clear Bit Indicates that and encoder clock pulse was detected */
  244. #define QEI_INTCLR_ENCLK_Int ((uint32_t)(1<<5))
  245. /** Clear Bit Indicates that the position 0 compare value is equal to the current position */
  246. #define QEI_INTCLR_POS0_Int ((uint32_t)(1<<6))
  247. /** Clear Bit Indicates that the position 1compare value is equal to the current position */
  248. #define QEI_INTCLR_POS1_Int ((uint32_t)(1<<7))
  249. /** Clear Bit Indicates that the position 2 compare value is equal to the current position */
  250. #define QEI_INTCLR_POS2_Int ((uint32_t)(1<<8))
  251. /** Clear Bit Indicates that the index compare value is equal to the current index count */
  252. #define QEI_INTCLR_REV_Int ((uint32_t)(1<<9))
  253. /** Clear Bit that combined position 0 and revolution count interrupt */
  254. #define QEI_INTCLR_POS0REV_Int ((uint32_t)(1<<10))
  255. /** Clear Bit that Combined position 1 and revolution count interrupt */
  256. #define QEI_INTCLR_POS1REV_Int ((uint32_t)(1<<11))
  257. /** Clear Bit that Combined position 2 and revolution count interrupt */
  258. #define QEI_INTCLR_POS2REV_Int ((uint32_t)(1<<12))
  259. /** QEI Interrupt Clear register bit-mask */
  260. #define QEI_INTCLR_BITMASK ((uint32_t)(0xFFFF))
  261. /*********************************************************************//**
  262. * Macro defines for QEI Interrupt Enable register
  263. **********************************************************************/
  264. /** Enabled Interrupt Bit Indicates that an index pulse was detected */
  265. #define QEI_INTEN_INX_Int ((uint32_t)(1<<0))
  266. /** Enabled Interrupt Bit Indicates that a velocity timer overflow occurred */
  267. #define QEI_INTEN_TIM_Int ((uint32_t)(1<<1))
  268. /** Enabled Interrupt Bit Indicates that capture velocity is less than compare velocity */
  269. #define QEI_INTEN_VELC_Int ((uint32_t)(1<<2))
  270. /** Enabled Interrupt Bit Indicates that a change of direction was detected */
  271. #define QEI_INTEN_DIR_Int ((uint32_t)(1<<3))
  272. /** Enabled Interrupt Bit Indicates that an encoder phase error was detected */
  273. #define QEI_INTEN_ERR_Int ((uint32_t)(1<<4))
  274. /** Enabled Interrupt Bit Indicates that and encoder clock pulse was detected */
  275. #define QEI_INTEN_ENCLK_Int ((uint32_t)(1<<5))
  276. /** Enabled Interrupt Bit Indicates that the position 0 compare value is equal to the current position */
  277. #define QEI_INTEN_POS0_Int ((uint32_t)(1<<6))
  278. /** Enabled Interrupt Bit Indicates that the position 1compare value is equal to the current position */
  279. #define QEI_INTEN_POS1_Int ((uint32_t)(1<<7))
  280. /** Enabled Interrupt Bit Indicates that the position 2 compare value is equal to the current position */
  281. #define QEI_INTEN_POS2_Int ((uint32_t)(1<<8))
  282. /** Enabled Interrupt Bit Indicates that the index compare value is equal to the current index count */
  283. #define QEI_INTEN_REV_Int ((uint32_t)(1<<9))
  284. /** Enabled Interrupt Bit that combined position 0 and revolution count interrupt */
  285. #define QEI_INTEN_POS0REV_Int ((uint32_t)(1<<10))
  286. /** Enabled Interrupt Bit that Combined position 1 and revolution count interrupt */
  287. #define QEI_INTEN_POS1REV_Int ((uint32_t)(1<<11))
  288. /** Enabled Interrupt Bit that Combined position 2 and revolution count interrupt */
  289. #define QEI_INTEN_POS2REV_Int ((uint32_t)(1<<12))
  290. /** QEI Interrupt Enable register bit-mask */
  291. #define QEI_INTEN_BITMASK ((uint32_t)(0x1FFF))
  292. /*********************************************************************//**
  293. * Macro defines for QEI Interrupt Enable Set register
  294. **********************************************************************/
  295. /** Set Enable Interrupt Bit Indicates that an index pulse was detected */
  296. #define QEI_IESET_INX_Int ((uint32_t)(1<<0))
  297. /** Set Enable Interrupt Bit Indicates that a velocity timer overflow occurred */
  298. #define QEI_IESET_TIM_Int ((uint32_t)(1<<1))
  299. /** Set Enable Interrupt Bit Indicates that capture velocity is less than compare velocity */
  300. #define QEI_IESET_VELC_Int ((uint32_t)(1<<2))
  301. /** Set Enable Interrupt Bit Indicates that a change of direction was detected */
  302. #define QEI_IESET_DIR_Int ((uint32_t)(1<<3))
  303. /** Set Enable Interrupt Bit Indicates that an encoder phase error was detected */
  304. #define QEI_IESET_ERR_Int ((uint32_t)(1<<4))
  305. /** Set Enable Interrupt Bit Indicates that and encoder clock pulse was detected */
  306. #define QEI_IESET_ENCLK_Int ((uint32_t)(1<<5))
  307. /** Set Enable Interrupt Bit Indicates that the position 0 compare value is equal to
  308. * the current position */
  309. #define QEI_IESET_POS0_Int ((uint32_t)(1<<6))
  310. /** Set Enable Interrupt Bit Indicates that the position 1compare value is equal to
  311. * the current position */
  312. #define QEI_IESET_POS1_Int ((uint32_t)(1<<7))
  313. /** Set Enable Interrupt Bit Indicates that the position 2 compare value is equal to
  314. * the current position */
  315. #define QEI_IESET_POS2_Int ((uint32_t)(1<<8))
  316. /** Set Enable Interrupt Bit Indicates that the index compare value is equal to the
  317. * current index count */
  318. #define QEI_IESET_REV_Int ((uint32_t)(1<<9))
  319. /** Set Enable Interrupt Bit that combined position 0 and revolution count interrupt */
  320. #define QEI_IESET_POS0REV_Int ((uint32_t)(1<<10))
  321. /** Set Enable Interrupt Bit that Combined position 1 and revolution count interrupt */
  322. #define QEI_IESET_POS1REV_Int ((uint32_t)(1<<11))
  323. /** Set Enable Interrupt Bit that Combined position 2 and revolution count interrupt */
  324. #define QEI_IESET_POS2REV_Int ((uint32_t)(1<<12))
  325. /** QEI Interrupt Enable Set register bit-mask */
  326. #define QEI_IESET_BITMASK ((uint32_t)(0x1FFF))
  327. /*********************************************************************//**
  328. * Macro defines for QEI Interrupt Enable Clear register
  329. **********************************************************************/
  330. /** Clear Enabled Interrupt Bit Indicates that an index pulse was detected */
  331. #define QEI_IECLR_INX_Int ((uint32_t)(1<<0))
  332. /** Clear Enabled Interrupt Bit Indicates that a velocity timer overflow occurred */
  333. #define QEI_IECLR_TIM_Int ((uint32_t)(1<<1))
  334. /** Clear Enabled Interrupt Bit Indicates that capture velocity is less than compare velocity */
  335. #define QEI_IECLR_VELC_Int ((uint32_t)(1<<2))
  336. /** Clear Enabled Interrupt Bit Indicates that a change of direction was detected */
  337. #define QEI_IECLR_DIR_Int ((uint32_t)(1<<3))
  338. /** Clear Enabled Interrupt Bit Indicates that an encoder phase error was detected */
  339. #define QEI_IECLR_ERR_Int ((uint32_t)(1<<4))
  340. /** Clear Enabled Interrupt Bit Indicates that and encoder clock pulse was detected */
  341. #define QEI_IECLR_ENCLK_Int ((uint32_t)(1<<5))
  342. /** Clear Enabled Interrupt Bit Indicates that the position 0 compare value is equal to the
  343. * current position */
  344. #define QEI_IECLR_POS0_Int ((uint32_t)(1<<6))
  345. /** Clear Enabled Interrupt Bit Indicates that the position 1compare value is equal to the
  346. * current position */
  347. #define QEI_IECLR_POS1_Int ((uint32_t)(1<<7))
  348. /** Clear Enabled Interrupt Bit Indicates that the position 2 compare value is equal to the
  349. * current position */
  350. #define QEI_IECLR_POS2_Int ((uint32_t)(1<<8))
  351. /** Clear Enabled Interrupt Bit Indicates that the index compare value is equal to the current
  352. * index count */
  353. #define QEI_IECLR_REV_Int ((uint32_t)(1<<9))
  354. /** Clear Enabled Interrupt Bit that combined position 0 and revolution count interrupt */
  355. #define QEI_IECLR_POS0REV_Int ((uint32_t)(1<<10))
  356. /** Clear Enabled Interrupt Bit that Combined position 1 and revolution count interrupt */
  357. #define QEI_IECLR_POS1REV_Int ((uint32_t)(1<<11))
  358. /** Clear Enabled Interrupt Bit that Combined position 2 and revolution count interrupt */
  359. #define QEI_IECLR_POS2REV_Int ((uint32_t)(1<<12))
  360. /** QEI Interrupt Enable Clear register bit-mask */
  361. #define QEI_IECLR_BITMASK ((uint32_t)(0xFFFF))
  362. /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
  363. /* Macro check QEI peripheral */
  364. #define PARAM_QEIx(n) ((n==LPC_QEI))
  365. /* Macro check QEI reset type */
  366. #define PARAM_QEI_RESET(n) ((n==QEI_CON_RESP) \
  367. || (n==QEI_RESET_POSOnIDX) \
  368. || (n==QEI_RESET_VEL) \
  369. || (n==QEI_RESET_IDX))
  370. /* Macro check QEI Direction invert mode */
  371. #define PARAM_QEI_DIRINV(n) ((n==QEI_DIRINV_NONE) || (n==QEI_DIRINV_CMPL))
  372. /* Macro check QEI signal mode */
  373. #define PARAM_QEI_SIGNALMODE(n) ((n==QEI_SIGNALMODE_QUAD) || (n==QEI_SIGNALMODE_CLKDIR))
  374. /* Macro check QEI Capture mode */
  375. #define PARAM_QEI_CAPMODE(n) ((n==QEI_CAPMODE_2X) || (n==QEI_CAPMODE_4X))
  376. /* Macro check QEI Invert index mode */
  377. #define PARAM_QEI_INVINX(n) ((n==QEI_INVINX_NONE) || (n==QEI_INVINX_EN))
  378. /* Macro check QEI Direction invert mode */
  379. #define PARAM_QEI_TIMERRELOAD(n) ((n==QEI_TIMERRELOAD_TICKVAL) || (n==QEI_TIMERRELOAD_USVAL))
  380. /* Macro check QEI status type */
  381. #define PARAM_QEI_STATUS(n) ((n==QEI_STATUS_DIR))
  382. /* Macro check QEI combine position type */
  383. #define PARAM_QEI_COMPPOS_CH(n) ((n==QEI_COMPPOS_CH_0) || (n==QEI_COMPPOS_CH_1) || (n==QEI_COMPPOS_CH_2))
  384. /* Macro check QEI interrupt flag type */
  385. #define PARAM_QEI_INTFLAG(n) ((n==QEI_INTFLAG_INX_Int) \
  386. || (n==QEI_INTFLAG_TIM_Int) \
  387. || (n==QEI_INTFLAG_VELC_Int) \
  388. || (n==QEI_INTFLAG_DIR_Int) \
  389. || (n==QEI_INTFLAG_ERR_Int) \
  390. || (n==QEI_INTFLAG_ENCLK_Int) \
  391. || (n==QEI_INTFLAG_POS0_Int) \
  392. || (n==QEI_INTFLAG_POS1_Int) \
  393. || (n==QEI_INTFLAG_POS2_Int) \
  394. || (n==QEI_INTFLAG_REV_Int) \
  395. || (n==QEI_INTFLAG_POS0REV_Int) \
  396. || (n==QEI_INTFLAG_POS1REV_Int) \
  397. || (n==QEI_INTFLAG_POS2REV_Int))
  398. /**
  399. * @}
  400. */
  401. /* Public Types --------------------------------------------------------------- */
  402. /** @defgroup QEI_Public_Types QEI Public Types
  403. * @{
  404. */
  405. /**
  406. * @brief QEI Configuration structure type definition
  407. */
  408. typedef struct
  409. {
  410. uint32_t DirectionInvert :1; /**< Direction invert option:
  411. - QEI_DIRINV_NONE: QEI Direction is normal
  412. - QEI_DIRINV_CMPL: QEI Direction is complemented
  413. */
  414. uint32_t SignalMode :1; /**< Signal mode Option:
  415. - QEI_SIGNALMODE_QUAD: Signal is in Quadrature phase mode
  416. - QEI_SIGNALMODE_CLKDIR: Signal is in Clock/Direction mode
  417. */
  418. uint32_t CaptureMode :1; /**< Capture Mode Option:
  419. - QEI_CAPMODE_2X: Only Phase-A edges are counted (2X)
  420. - QEI_CAPMODE_4X: BOTH Phase-A and Phase-B edges are counted (4X)
  421. */
  422. uint32_t InvertIndex :1; /**< Invert Index Option:
  423. - QEI_INVINX_NONE: the sense of the index input is normal
  424. - QEI_INVINX_EN: inverts the sense of the index input
  425. */
  426. } QEI_CFG_Type;
  427. /**
  428. * @brief Timer Reload Configuration structure type definition
  429. */
  430. typedef struct
  431. {
  432. uint8_t ReloadOption; /**< Velocity Timer Reload Option, should be:
  433. - QEI_TIMERRELOAD_TICKVAL: Reload value in absolute value
  434. - QEI_TIMERRELOAD_USVAL: Reload value in microsecond value
  435. */
  436. uint8_t Reserved[3];
  437. uint32_t ReloadValue; /**< Velocity Timer Reload Value, 32-bit long, should be matched
  438. with Velocity Timer Reload Option
  439. */
  440. } QEI_RELOADCFG_Type;
  441. /**
  442. * @brief Filter Settings for QEI registers on PHA, PHB and IDX
  443. */
  444. typedef struct
  445. {
  446. uint32_t PHA_FilterVal;/**< Digital Filter Register on PHA input */
  447. uint32_t PHB_FilterVal;/**< Digital Filter Register on PHB input */
  448. uint32_t INX_FilterVal;/**< Digital Filter Register on IDX input */
  449. } st_Qei_FilterCfg;
  450. /**
  451. * @}
  452. */
  453. /* Public Functions ----------------------------------------------------------- */
  454. /** @defgroup QEI_Public_Functions QEI Public Functions
  455. * @{
  456. */
  457. void QEI_Reset(uint8_t qeiId, uint32_t ulResetType);
  458. void QEI_Init(uint8_t qeiId, QEI_CFG_Type *QEI_ConfigStruct);
  459. void QEI_GetCfgDefault(QEI_CFG_Type *QIE_InitStruct);
  460. void QEI_DeInit(uint8_t qeiId);
  461. FlagStatus QEI_GetStatus(uint8_t qeiId, uint32_t ulFlagType);
  462. uint32_t QEI_GetPosition(uint8_t qeiId);
  463. void QEI_SetMaxPosition(uint8_t qeiId, uint32_t ulMaxPos);
  464. void QEI_SetPositionComp(uint8_t qeiId, uint8_t bPosCompCh, uint32_t ulPosComp);
  465. uint32_t QEI_GetIndex(uint8_t qeiId);
  466. void QEI_SetIndexComp(uint8_t qeiId, uint32_t ulIndexComp);
  467. void QEI_SetTimerReload(uint8_t qeiId, QEI_RELOADCFG_Type *QEIReloadStruct);
  468. uint32_t QEI_GetTimer(uint8_t qeiId);
  469. uint32_t QEI_GetVelocity(uint8_t qeiId);
  470. uint32_t QEI_GetVelocityCap(uint8_t qeiId);
  471. void QEI_SetVelocityComp(uint8_t qeiId, uint32_t ulVelComp);
  472. void QEI_SetDigiFilter(uint8_t qeiId, st_Qei_FilterCfg FilterVal);
  473. FlagStatus QEI_GetIntStatus(uint8_t qeiId, uint32_t ulIntType);
  474. void QEI_IntCmd(uint8_t qeiId, uint32_t ulIntType, FunctionalState NewState);
  475. void QEI_IntSet(uint8_t qeiId, uint32_t ulIntType);
  476. void QEI_IntClear(uint8_t qeiId, uint32_t ulIntType);
  477. uint32_t QEI_CalculateRPM(uint8_t qeiId, uint32_t ulVelCapValue, uint32_t ulPPR);
  478. /**
  479. * @}
  480. */
  481. #ifdef __cplusplus
  482. }
  483. #endif
  484. #endif /* __LPC_QEI_H_ */
  485. /**
  486. * @}
  487. */
  488. /* --------------------------------- End Of File ------------------------------ */