My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

lpc17xx_qei.h 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /**********************************************************************
  2. * $Id$ lpc17xx_qei.h 2010-05-21
  3. *//**
  4. * @file lpc17xx_qei.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for QEI firmware library on LPC17xx
  7. * @version 2.0
  8. * @date 21. May. 2010
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2010, 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 LPC1700CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef LPC17XX_QEI_H_
  38. #define LPC17XX_QEI_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC17xx.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. /* QEI Reset types */
  51. #define QEI_RESET_POS QEI_CON_RESP /**< Reset position counter */
  52. #define QEI_RESET_POSOnIDX QEI_CON_RESPI /**< Reset Posistion Counter on Index */
  53. #define QEI_RESET_VEL QEI_CON_RESV /**< Reset Velocity */
  54. #define QEI_RESET_IDX QEI_CON_RESI /**< Reset Index Counter */
  55. /* QEI Direction Invert Type Option */
  56. #define QEI_DIRINV_NONE ((uint32_t)(0)) /**< Direction is not inverted */
  57. #define QEI_DIRINV_CMPL ((uint32_t)(1)) /**< Direction is complemented */
  58. /* QEI Signal Mode Option */
  59. #define QEI_SIGNALMODE_QUAD ((uint32_t)(0)) /**< Signal operation: Quadrature phase mode */
  60. #define QEI_SIGNALMODE_CLKDIR ((uint32_t)(1)) /**< Signal operation: Clock/Direction mode */
  61. /* QEI Capture Mode Option */
  62. #define QEI_CAPMODE_2X ((uint32_t)(0)) /**< Capture mode: Only Phase-A edges are counted (2X) */
  63. #define QEI_CAPMODE_4X ((uint32_t)(1)) /**< Capture mode: BOTH PhA and PhB edges are counted (4X)*/
  64. /* QEI Invert Index Signal Option */
  65. #define QEI_INVINX_NONE ((uint32_t)(0)) /**< Invert Index signal option: None */
  66. #define QEI_INVINX_EN ((uint32_t)(1)) /**< Invert Index signal option: Enable */
  67. /* QEI timer reload option */
  68. #define QEI_TIMERRELOAD_TICKVAL ((uint8_t)(0)) /**< Reload value in absolute value */
  69. #define QEI_TIMERRELOAD_USVAL ((uint8_t)(1)) /**< Reload value in microsecond value */
  70. /* QEI Flag Status type */
  71. #define QEI_STATUS_DIR ((uint32_t)(1<<0)) /**< Direction status */
  72. /* QEI Compare Position channel option */
  73. #define QEI_COMPPOS_CH_0 ((uint8_t)(0)) /**< QEI compare position channel 0 */
  74. #define QEI_COMPPOS_CH_1 ((uint8_t)(1)) /**< QEI compare position channel 1 */
  75. #define QEI_COMPPOS_CH_2 ((uint8_t)(2)) /**< QEI compare position channel 2 */
  76. /* QEI interrupt flag type */
  77. #define QEI_INTFLAG_INX_Int ((uint32_t)(1<<0)) /**< index pulse was detected interrupt */
  78. #define QEI_INTFLAG_TIM_Int ((uint32_t)(1<<1)) /**< Velocity timer over flow interrupt */
  79. #define QEI_INTFLAG_VELC_Int ((uint32_t)(1<<2)) /**< Capture velocity is less than compare interrupt */
  80. #define QEI_INTFLAG_DIR_Int ((uint32_t)(1<<3)) /**< Change of direction interrupt */
  81. #define QEI_INTFLAG_ERR_Int ((uint32_t)(1<<4)) /**< An encoder phase error interrupt */
  82. #define QEI_INTFLAG_ENCLK_Int ((uint32_t)(1<<5)) /**< An encoder clock pulse was detected interrupt */
  83. #define QEI_INTFLAG_POS0_Int ((uint32_t)(1<<6)) /**< position 0 compare value is equal to the
  84. current position interrupt */
  85. #define QEI_INTFLAG_POS1_Int ((uint32_t)(1<<7)) /**< position 1 compare value is equal to the
  86. current position interrupt */
  87. #define QEI_INTFLAG_POS2_Int ((uint32_t)(1<<8)) /**< position 2 compare value is equal to the
  88. current position interrupt */
  89. #define QEI_INTFLAG_REV_Int ((uint32_t)(1<<9)) /**< Index compare value is equal to the current
  90. index count interrupt */
  91. #define QEI_INTFLAG_POS0REV_Int ((uint32_t)(1<<10)) /**< Combined position 0 and revolution count interrupt */
  92. #define QEI_INTFLAG_POS1REV_Int ((uint32_t)(1<<11)) /**< Combined position 1 and revolution count interrupt */
  93. #define QEI_INTFLAG_POS2REV_Int ((uint32_t)(1<<12)) /**< Combined position 2 and revolution count interrupt */
  94. /**
  95. * @}
  96. */
  97. /* Private Macros ------------------------------------------------------------- */
  98. /** @defgroup QEI_Private_Macros QEI Private Macros
  99. * @{
  100. */
  101. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  102. /* Quadrature Encoder Interface Control Register Definition --------------------- */
  103. /*********************************************************************//**
  104. * Macro defines for QEI Control register
  105. **********************************************************************/
  106. #define QEI_CON_RESP ((uint32_t)(1<<0)) /**< Reset position counter */
  107. #define QEI_CON_RESPI ((uint32_t)(1<<1)) /**< Reset Posistion Counter on Index */
  108. #define QEI_CON_RESV ((uint32_t)(1<<2)) /**< Reset Velocity */
  109. #define QEI_CON_RESI ((uint32_t)(1<<3)) /**< Reset Index Counter */
  110. #define QEI_CON_BITMASK ((uint32_t)(0x0F)) /**< QEI Control register bit-mask */
  111. /*********************************************************************//**
  112. * Macro defines for QEI Configuration register
  113. **********************************************************************/
  114. #define QEI_CONF_DIRINV ((uint32_t)(1<<0)) /**< Direction Invert */
  115. #define QEI_CONF_SIGMODE ((uint32_t)(1<<1)) /**< Signal mode */
  116. #define QEI_CONF_CAPMODE ((uint32_t)(1<<2)) /**< Capture mode */
  117. #define QEI_CONF_INVINX ((uint32_t)(1<<3)) /**< Invert index */
  118. #define QEI_CONF_BITMASK ((uint32_t)(0x0F)) /**< QEI Configuration register bit-mask */
  119. /*********************************************************************//**
  120. * Macro defines for QEI Status register
  121. **********************************************************************/
  122. #define QEI_STAT_DIR ((uint32_t)(1<<0)) /**< Direction bit */
  123. #define QEI_STAT_BITMASK ((uint32_t)(1<<0)) /**< QEI status register bit-mask */
  124. /* Quadrature Encoder Interface Interrupt registers definitions --------------------- */
  125. /*********************************************************************//**
  126. * Macro defines for QEI Interrupt Status register
  127. **********************************************************************/
  128. #define QEI_INTSTAT_INX_Int ((uint32_t)(1<<0)) /**< Indicates that an index pulse was detected */
  129. #define QEI_INTSTAT_TIM_Int ((uint32_t)(1<<1)) /**< Indicates that a velocity timer overflow occurred */
  130. #define QEI_INTSTAT_VELC_Int ((uint32_t)(1<<2)) /**< Indicates that capture velocity is less than compare velocity */
  131. #define QEI_INTSTAT_DIR_Int ((uint32_t)(1<<3)) /**< Indicates that a change of direction was detected */
  132. #define QEI_INTSTAT_ERR_Int ((uint32_t)(1<<4)) /**< Indicates that an encoder phase error was detected */
  133. #define QEI_INTSTAT_ENCLK_Int ((uint32_t)(1<<5)) /**< Indicates that and encoder clock pulse was detected */
  134. #define QEI_INTSTAT_POS0_Int ((uint32_t)(1<<6)) /**< Indicates that the position 0 compare value is equal to the
  135. current position */
  136. #define QEI_INTSTAT_POS1_Int ((uint32_t)(1<<7)) /**< Indicates that the position 1compare value is equal to the
  137. current position */
  138. #define QEI_INTSTAT_POS2_Int ((uint32_t)(1<<8)) /**< Indicates that the position 2 compare value is equal to the
  139. current position */
  140. #define QEI_INTSTAT_REV_Int ((uint32_t)(1<<9)) /**< Indicates that the index compare value is equal to the current
  141. index count */
  142. #define QEI_INTSTAT_POS0REV_Int ((uint32_t)(1<<10)) /**< Combined position 0 and revolution count interrupt. Set when
  143. both the POS0_Int bit is set and the REV_Int is set */
  144. #define QEI_INTSTAT_POS1REV_Int ((uint32_t)(1<<11)) /**< Combined position 1 and revolution count interrupt. Set when
  145. both the POS1_Int bit is set and the REV_Int is set */
  146. #define QEI_INTSTAT_POS2REV_Int ((uint32_t)(1<<12)) /**< Combined position 2 and revolution count interrupt. Set when
  147. both the POS2_Int bit is set and the REV_Int is set */
  148. #define QEI_INTSTAT_BITMASK ((uint32_t)(0x1FFF)) /**< QEI Interrupt Status register bit-mask */
  149. /*********************************************************************//**
  150. * Macro defines for QEI Interrupt Set register
  151. **********************************************************************/
  152. #define QEI_INTSET_INX_Int ((uint32_t)(1<<0)) /**< Set Bit Indicates that an index pulse was detected */
  153. #define QEI_INTSET_TIM_Int ((uint32_t)(1<<1)) /**< Set Bit Indicates that a velocity timer overflow occurred */
  154. #define QEI_INTSET_VELC_Int ((uint32_t)(1<<2)) /**< Set Bit Indicates that capture velocity is less than compare velocity */
  155. #define QEI_INTSET_DIR_Int ((uint32_t)(1<<3)) /**< Set Bit Indicates that a change of direction was detected */
  156. #define QEI_INTSET_ERR_Int ((uint32_t)(1<<4)) /**< Set Bit Indicates that an encoder phase error was detected */
  157. #define QEI_INTSET_ENCLK_Int ((uint32_t)(1<<5)) /**< Set Bit Indicates that and encoder clock pulse was detected */
  158. #define QEI_INTSET_POS0_Int ((uint32_t)(1<<6)) /**< Set Bit Indicates that the position 0 compare value is equal to the
  159. current position */
  160. #define QEI_INTSET_POS1_Int ((uint32_t)(1<<7)) /**< Set Bit Indicates that the position 1compare value is equal to the
  161. current position */
  162. #define QEI_INTSET_POS2_Int ((uint32_t)(1<<8)) /**< Set Bit Indicates that the position 2 compare value is equal to the
  163. current position */
  164. #define QEI_INTSET_REV_Int ((uint32_t)(1<<9)) /**< Set Bit Indicates that the index compare value is equal to the current
  165. index count */
  166. #define QEI_INTSET_POS0REV_Int ((uint32_t)(1<<10)) /**< Set Bit that combined position 0 and revolution count interrupt */
  167. #define QEI_INTSET_POS1REV_Int ((uint32_t)(1<<11)) /**< Set Bit that Combined position 1 and revolution count interrupt */
  168. #define QEI_INTSET_POS2REV_Int ((uint32_t)(1<<12)) /**< Set Bit that Combined position 2 and revolution count interrupt */
  169. #define QEI_INTSET_BITMASK ((uint32_t)(0x1FFF)) /**< QEI Interrupt Set register bit-mask */
  170. /*********************************************************************//**
  171. * Macro defines for QEI Interrupt Clear register
  172. **********************************************************************/
  173. #define QEI_INTCLR_INX_Int ((uint32_t)(1<<0)) /**< Clear Bit Indicates that an index pulse was detected */
  174. #define QEI_INTCLR_TIM_Int ((uint32_t)(1<<1)) /**< Clear Bit Indicates that a velocity timer overflow occurred */
  175. #define QEI_INTCLR_VELC_Int ((uint32_t)(1<<2)) /**< Clear Bit Indicates that capture velocity is less than compare velocity */
  176. #define QEI_INTCLR_DIR_Int ((uint32_t)(1<<3)) /**< Clear Bit Indicates that a change of direction was detected */
  177. #define QEI_INTCLR_ERR_Int ((uint32_t)(1<<4)) /**< Clear Bit Indicates that an encoder phase error was detected */
  178. #define QEI_INTCLR_ENCLK_Int ((uint32_t)(1<<5)) /**< Clear Bit Indicates that and encoder clock pulse was detected */
  179. #define QEI_INTCLR_POS0_Int ((uint32_t)(1<<6)) /**< Clear Bit Indicates that the position 0 compare value is equal to the
  180. current position */
  181. #define QEI_INTCLR_POS1_Int ((uint32_t)(1<<7)) /**< Clear Bit Indicates that the position 1compare value is equal to the
  182. current position */
  183. #define QEI_INTCLR_POS2_Int ((uint32_t)(1<<8)) /**< Clear Bit Indicates that the position 2 compare value is equal to the
  184. current position */
  185. #define QEI_INTCLR_REV_Int ((uint32_t)(1<<9)) /**< Clear Bit Indicates that the index compare value is equal to the current
  186. index count */
  187. #define QEI_INTCLR_POS0REV_Int ((uint32_t)(1<<10)) /**< Clear Bit that combined position 0 and revolution count interrupt */
  188. #define QEI_INTCLR_POS1REV_Int ((uint32_t)(1<<11)) /**< Clear Bit that Combined position 1 and revolution count interrupt */
  189. #define QEI_INTCLR_POS2REV_Int ((uint32_t)(1<<12)) /**< Clear Bit that Combined position 2 and revolution count interrupt */
  190. #define QEI_INTCLR_BITMASK ((uint32_t)(0x1FFF)) /**< QEI Interrupt Clear register bit-mask */
  191. /*********************************************************************//**
  192. * Macro defines for QEI Interrupt Enable register
  193. **********************************************************************/
  194. #define QEI_INTEN_INX_Int ((uint32_t)(1<<0)) /**< Enabled Interrupt Bit Indicates that an index pulse was detected */
  195. #define QEI_INTEN_TIM_Int ((uint32_t)(1<<1)) /**< Enabled Interrupt Bit Indicates that a velocity timer overflow occurred */
  196. #define QEI_INTEN_VELC_Int ((uint32_t)(1<<2)) /**< Enabled Interrupt Bit Indicates that capture velocity is less than compare velocity */
  197. #define QEI_INTEN_DIR_Int ((uint32_t)(1<<3)) /**< Enabled Interrupt Bit Indicates that a change of direction was detected */
  198. #define QEI_INTEN_ERR_Int ((uint32_t)(1<<4)) /**< Enabled Interrupt Bit Indicates that an encoder phase error was detected */
  199. #define QEI_INTEN_ENCLK_Int ((uint32_t)(1<<5)) /**< Enabled Interrupt Bit Indicates that and encoder clock pulse was detected */
  200. #define QEI_INTEN_POS0_Int ((uint32_t)(1<<6)) /**< Enabled Interrupt Bit Indicates that the position 0 compare value is equal to the
  201. current position */
  202. #define QEI_INTEN_POS1_Int ((uint32_t)(1<<7)) /**< Enabled Interrupt Bit Indicates that the position 1compare value is equal to the
  203. current position */
  204. #define QEI_INTEN_POS2_Int ((uint32_t)(1<<8)) /**< Enabled Interrupt Bit Indicates that the position 2 compare value is equal to the
  205. current position */
  206. #define QEI_INTEN_REV_Int ((uint32_t)(1<<9)) /**< Enabled Interrupt Bit Indicates that the index compare value is equal to the current
  207. index count */
  208. #define QEI_INTEN_POS0REV_Int ((uint32_t)(1<<10)) /**< Enabled Interrupt Bit that combined position 0 and revolution count interrupt */
  209. #define QEI_INTEN_POS1REV_Int ((uint32_t)(1<<11)) /**< Enabled Interrupt Bit that Combined position 1 and revolution count interrupt */
  210. #define QEI_INTEN_POS2REV_Int ((uint32_t)(1<<12)) /**< Enabled Interrupt Bit that Combined position 2 and revolution count interrupt */
  211. #define QEI_INTEN_BITMASK ((uint32_t)(0x1FFF)) /**< QEI Interrupt Enable register bit-mask */
  212. /*********************************************************************//**
  213. * Macro defines for QEI Interrupt Enable Set register
  214. **********************************************************************/
  215. #define QEI_IESET_INX_Int ((uint32_t)(1<<0)) /**< Set Enable Interrupt Bit Indicates that an index pulse was detected */
  216. #define QEI_IESET_TIM_Int ((uint32_t)(1<<1)) /**< Set Enable Interrupt Bit Indicates that a velocity timer overflow occurred */
  217. #define QEI_IESET_VELC_Int ((uint32_t)(1<<2)) /**< Set Enable Interrupt Bit Indicates that capture velocity is less than compare velocity */
  218. #define QEI_IESET_DIR_Int ((uint32_t)(1<<3)) /**< Set Enable Interrupt Bit Indicates that a change of direction was detected */
  219. #define QEI_IESET_ERR_Int ((uint32_t)(1<<4)) /**< Set Enable Interrupt Bit Indicates that an encoder phase error was detected */
  220. #define QEI_IESET_ENCLK_Int ((uint32_t)(1<<5)) /**< Set Enable Interrupt Bit Indicates that and encoder clock pulse was detected */
  221. #define QEI_IESET_POS0_Int ((uint32_t)(1<<6)) /**< Set Enable Interrupt Bit Indicates that the position 0 compare value is equal to the
  222. current position */
  223. #define QEI_IESET_POS1_Int ((uint32_t)(1<<7)) /**< Set Enable Interrupt Bit Indicates that the position 1compare value is equal to the
  224. current position */
  225. #define QEI_IESET_POS2_Int ((uint32_t)(1<<8)) /**< Set Enable Interrupt Bit Indicates that the position 2 compare value is equal to the
  226. current position */
  227. #define QEI_IESET_REV_Int ((uint32_t)(1<<9)) /**< Set Enable Interrupt Bit Indicates that the index compare value is equal to the current
  228. index count */
  229. #define QEI_IESET_POS0REV_Int ((uint32_t)(1<<10)) /**< Set Enable Interrupt Bit that combined position 0 and revolution count interrupt */
  230. #define QEI_IESET_POS1REV_Int ((uint32_t)(1<<11)) /**< Set Enable Interrupt Bit that Combined position 1 and revolution count interrupt */
  231. #define QEI_IESET_POS2REV_Int ((uint32_t)(1<<12)) /**< Set Enable Interrupt Bit that Combined position 2 and revolution count interrupt */
  232. #define QEI_IESET_BITMASK ((uint32_t)(0x1FFF)) /**< QEI Interrupt Enable Set register bit-mask */
  233. /*********************************************************************//**
  234. * Macro defines for QEI Interrupt Enable Clear register
  235. **********************************************************************/
  236. #define QEI_IECLR_INX_Int ((uint32_t)(1<<0)) /**< Clear Enabled Interrupt Bit Indicates that an index pulse was detected */
  237. #define QEI_IECLR_TIM_Int ((uint32_t)(1<<1)) /**< Clear Enabled Interrupt Bit Indicates that a velocity timer overflow occurred */
  238. #define QEI_IECLR_VELC_Int ((uint32_t)(1<<2)) /**< Clear Enabled Interrupt Bit Indicates that capture velocity is less than compare velocity */
  239. #define QEI_IECLR_DIR_Int ((uint32_t)(1<<3)) /**< Clear Enabled Interrupt Bit Indicates that a change of direction was detected */
  240. #define QEI_IECLR_ERR_Int ((uint32_t)(1<<4)) /**< Clear Enabled Interrupt Bit Indicates that an encoder phase error was detected */
  241. #define QEI_IECLR_ENCLK_Int ((uint32_t)(1<<5)) /**< Clear Enabled Interrupt Bit Indicates that and encoder clock pulse was detected */
  242. #define QEI_IECLR_POS0_Int ((uint32_t)(1<<6)) /**< Clear Enabled Interrupt Bit Indicates that the position 0 compare value is equal to the
  243. current position */
  244. #define QEI_IECLR_POS1_Int ((uint32_t)(1<<7)) /**< Clear Enabled Interrupt Bit Indicates that the position 1compare value is equal to the
  245. current position */
  246. #define QEI_IECLR_POS2_Int ((uint32_t)(1<<8)) /**< Clear Enabled Interrupt Bit Indicates that the position 2 compare value is equal to the
  247. current position */
  248. #define QEI_IECLR_REV_Int ((uint32_t)(1<<9)) /**< Clear Enabled Interrupt Bit Indicates that the index compare value is equal to the current
  249. index count */
  250. #define QEI_IECLR_POS0REV_Int ((uint32_t)(1<<10)) /**< Clear Enabled Interrupt Bit that combined position 0 and revolution count interrupt */
  251. #define QEI_IECLR_POS1REV_Int ((uint32_t)(1<<11)) /**< Clear Enabled Interrupt Bit that Combined position 1 and revolution count interrupt */
  252. #define QEI_IECLR_POS2REV_Int ((uint32_t)(1<<12)) /**< Clear Enabled Interrupt Bit that Combined position 2 and revolution count interrupt */
  253. #define QEI_IECLR_BITMASK ((uint32_t)(0x1FFF)) /**< QEI Interrupt Enable Clear register bit-mask */
  254. /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
  255. /* Macro check QEI peripheral */
  256. #define PARAM_QEIx(n) ((n==LPC_QEI))
  257. /* Macro check QEI reset type */
  258. #define PARAM_QEI_RESET(n) ((n==QEI_CON_RESP) \
  259. || (n==QEI_RESET_POSOnIDX) \
  260. || (n==QEI_RESET_VEL) \
  261. || (n==QEI_RESET_IDX))
  262. /* Macro check QEI Direction invert mode */
  263. #define PARAM_QEI_DIRINV(n) ((n==QEI_DIRINV_NONE) || (n==QEI_DIRINV_CMPL))
  264. /* Macro check QEI signal mode */
  265. #define PARAM_QEI_SIGNALMODE(n) ((n==QEI_SIGNALMODE_QUAD) || (n==QEI_SIGNALMODE_CLKDIR))
  266. /* Macro check QEI Capture mode */
  267. #define PARAM_QEI_CAPMODE(n) ((n==QEI_CAPMODE_2X) || (n==QEI_CAPMODE_4X))
  268. /* Macro check QEI Invert index mode */
  269. #define PARAM_QEI_INVINX(n) ((n==QEI_INVINX_NONE) || (n==QEI_INVINX_EN))
  270. /* Macro check QEI Direction invert mode */
  271. #define PARAM_QEI_TIMERRELOAD(n) ((n==QEI_TIMERRELOAD_TICKVAL) || (n==QEI_TIMERRELOAD_USVAL))
  272. /* Macro check QEI status type */
  273. #define PARAM_QEI_STATUS(n) ((n==QEI_STATUS_DIR))
  274. /* Macro check QEI combine position type */
  275. #define PARAM_QEI_COMPPOS_CH(n) ((n==QEI_COMPPOS_CH_0) || (n==QEI_COMPPOS_CH_1) || (n==QEI_COMPPOS_CH_2))
  276. /* Macro check QEI interrupt flag type */
  277. #define PARAM_QEI_INTFLAG(n) ((n==QEI_INTFLAG_INX_Int) \
  278. || (n==QEI_INTFLAG_TIM_Int) \
  279. || (n==QEI_INTFLAG_VELC_Int) \
  280. || (n==QEI_INTFLAG_DIR_Int) \
  281. || (n==QEI_INTFLAG_ERR_Int) \
  282. || (n==QEI_INTFLAG_ENCLK_Int) \
  283. || (n==QEI_INTFLAG_POS0_Int) \
  284. || (n==QEI_INTFLAG_POS1_Int) \
  285. || (n==QEI_INTFLAG_POS2_Int) \
  286. || (n==QEI_INTFLAG_REV_Int) \
  287. || (n==QEI_INTFLAG_POS0REV_Int) \
  288. || (n==QEI_INTFLAG_POS1REV_Int) \
  289. || (n==QEI_INTFLAG_POS2REV_Int))
  290. /**
  291. * @}
  292. */
  293. /* Public Types --------------------------------------------------------------- */
  294. /** @defgroup QEI_Public_Types QEI Public Types
  295. * @{
  296. */
  297. /**
  298. * @brief QEI Configuration structure type definition
  299. */
  300. typedef struct {
  301. uint32_t DirectionInvert :1; /**< Direction invert option:
  302. - QEI_DIRINV_NONE: QEI Direction is normal
  303. - QEI_DIRINV_CMPL: QEI Direction is complemented
  304. */
  305. uint32_t SignalMode :1; /**< Signal mode Option:
  306. - QEI_SIGNALMODE_QUAD: Signal is in Quadrature phase mode
  307. - QEI_SIGNALMODE_CLKDIR: Signal is in Clock/Direction mode
  308. */
  309. uint32_t CaptureMode :1; /**< Capture Mode Option:
  310. - QEI_CAPMODE_2X: Only Phase-A edges are counted (2X)
  311. - QEI_CAPMODE_4X: BOTH Phase-A and Phase-B edges are counted (4X)
  312. */
  313. uint32_t InvertIndex :1; /**< Invert Index Option:
  314. - QEI_INVINX_NONE: the sense of the index input is normal
  315. - QEI_INVINX_EN: inverts the sense of the index input
  316. */
  317. } QEI_CFG_Type;
  318. /**
  319. * @brief Timer Reload Configuration structure type definition
  320. */
  321. typedef struct {
  322. uint8_t ReloadOption; /**< Velocity Timer Reload Option, should be:
  323. - QEI_TIMERRELOAD_TICKVAL: Reload value in absolute value
  324. - QEI_TIMERRELOAD_USVAL: Reload value in microsecond value
  325. */
  326. uint8_t Reserved[3];
  327. uint32_t ReloadValue; /**< Velocity Timer Reload Value, 32-bit long, should be matched
  328. with Velocity Timer Reload Option
  329. */
  330. } QEI_RELOADCFG_Type;
  331. /**
  332. * @}
  333. */
  334. /* Public Functions ----------------------------------------------------------- */
  335. /** @defgroup QEI_Public_Functions QEI Public Functions
  336. * @{
  337. */
  338. void QEI_Reset(LPC_QEI_TypeDef *QEIx, uint32_t ulResetType);
  339. void QEI_Init(LPC_QEI_TypeDef *QEIx, QEI_CFG_Type *QEI_ConfigStruct);
  340. void QEI_ConfigStructInit(QEI_CFG_Type *QIE_InitStruct);
  341. void QEI_DeInit(LPC_QEI_TypeDef *QEIx);
  342. FlagStatus QEI_GetStatus(LPC_QEI_TypeDef *QEIx, uint32_t ulFlagType);
  343. uint32_t QEI_GetPosition(LPC_QEI_TypeDef *QEIx);
  344. void QEI_SetMaxPosition(LPC_QEI_TypeDef *QEIx, uint32_t ulMaxPos);
  345. void QEI_SetPositionComp(LPC_QEI_TypeDef *QEIx, uint8_t bPosCompCh, uint32_t ulPosComp);
  346. uint32_t QEI_GetIndex(LPC_QEI_TypeDef *QEIx);
  347. void QEI_SetIndexComp(LPC_QEI_TypeDef *QEIx, uint32_t ulIndexComp);
  348. void QEI_SetTimerReload(LPC_QEI_TypeDef *QEIx, QEI_RELOADCFG_Type *QEIReloadStruct);
  349. uint32_t QEI_GetTimer(LPC_QEI_TypeDef *QEIx);
  350. uint32_t QEI_GetVelocity(LPC_QEI_TypeDef *QEIx);
  351. uint32_t QEI_GetVelocityCap(LPC_QEI_TypeDef *QEIx);
  352. void QEI_SetVelocityComp(LPC_QEI_TypeDef *QEIx, uint32_t ulVelComp);
  353. void QEI_SetDigiFilter(LPC_QEI_TypeDef *QEIx, uint32_t ulSamplingPulse);
  354. FlagStatus QEI_GetIntStatus(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType);
  355. void QEI_IntCmd(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType, FunctionalState NewState);
  356. void QEI_IntSet(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType);
  357. void QEI_IntClear(LPC_QEI_TypeDef *QEIx, uint32_t ulIntType);
  358. uint32_t QEI_CalculateRPM(LPC_QEI_TypeDef *QEIx, uint32_t ulVelCapValue, uint32_t ulPPR);
  359. /**
  360. * @}
  361. */
  362. #ifdef __cplusplus
  363. }
  364. #endif
  365. #endif /* LPC17XX_QEI_H_ */
  366. /**
  367. * @}
  368. */
  369. /* --------------------------------- End Of File ------------------------------ */