qei.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //*****************************************************************************
  2. //
  3. // qei.h - Prototypes for the Quadrature Encoder Driver.
  4. //
  5. // Copyright (c) 2005-2020 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. #ifndef __DRIVERLIB_QEI_H__
  40. #define __DRIVERLIB_QEI_H__
  41. //*****************************************************************************
  42. //
  43. // If building with a C++ compiler, make all of the definitions in this header
  44. // have a C binding.
  45. //
  46. //*****************************************************************************
  47. #ifdef __cplusplus
  48. extern "C"
  49. {
  50. #endif
  51. //*****************************************************************************
  52. //
  53. // Values that can be passed to QEIConfigure as the ui32Config paramater.
  54. //
  55. //*****************************************************************************
  56. #define QEI_CONFIG_CAPTURE_A 0x00000000 // Count on ChA edges only
  57. #define QEI_CONFIG_CAPTURE_A_B 0x00000008 // Count on ChA and ChB edges
  58. #define QEI_CONFIG_NO_RESET 0x00000000 // Do not reset on index pulse
  59. #define QEI_CONFIG_RESET_IDX 0x00000010 // Reset position on index pulse
  60. #define QEI_CONFIG_QUADRATURE 0x00000000 // ChA and ChB are quadrature
  61. #define QEI_CONFIG_CLOCK_DIR 0x00000004 // ChA and ChB are clock and dir
  62. #define QEI_CONFIG_NO_SWAP 0x00000000 // Do not swap ChA and ChB
  63. #define QEI_CONFIG_SWAP 0x00000002 // Swap ChA and ChB
  64. //*****************************************************************************
  65. //
  66. // Values that can be passed to QEIFilterConfigure as the ui32PreDiv
  67. // parameter.
  68. //
  69. //*****************************************************************************
  70. #define QEI_FILTCNT_2 0x00000000 // Filter Count of 2 System Clocks
  71. #define QEI_FILTCNT_3 0x00010000 // Filter Count of 3 System Clocks
  72. #define QEI_FILTCNT_4 0x00020000 // Filter Count of 4 System Clocks
  73. #define QEI_FILTCNT_5 0x00030000 // Filter Count of 5 System Clocks
  74. #define QEI_FILTCNT_6 0x00040000 // Filter Count of 6 System Clocks
  75. #define QEI_FILTCNT_7 0x00050000 // Filter Count of 7 System Clocks
  76. #define QEI_FILTCNT_8 0x00060000 // Filter Count of 8 System Clocks
  77. #define QEI_FILTCNT_9 0x00070000 // Filter Count of 9 System Clocks
  78. #define QEI_FILTCNT_10 0x00080000 // Filter Count of 10 System Clocks
  79. #define QEI_FILTCNT_11 0x00090000 // Filter Count of 11 System Clocks
  80. #define QEI_FILTCNT_12 0x000A0000 // Filter Count of 12 System Clocks
  81. #define QEI_FILTCNT_13 0x000B0000 // Filter Count of 13 System Clocks
  82. #define QEI_FILTCNT_14 0x000C0000 // Filter Count of 14 System Clocks
  83. #define QEI_FILTCNT_15 0x000D0000 // Filter Count of 15 System Clocks
  84. #define QEI_FILTCNT_16 0x000E0000 // Filter Count of 16 System Clocks
  85. #define QEI_FILTCNT_17 0x000F0000 // Filter Count of 17 System Clocks
  86. //*****************************************************************************
  87. //
  88. // Values that can be passed to QEIVelocityConfigure as the ui32PreDiv
  89. // parameter.
  90. //
  91. //*****************************************************************************
  92. #define QEI_VELDIV_1 0x00000000 // Predivide by 1
  93. #define QEI_VELDIV_2 0x00000040 // Predivide by 2
  94. #define QEI_VELDIV_4 0x00000080 // Predivide by 4
  95. #define QEI_VELDIV_8 0x000000C0 // Predivide by 8
  96. #define QEI_VELDIV_16 0x00000100 // Predivide by 16
  97. #define QEI_VELDIV_32 0x00000140 // Predivide by 32
  98. #define QEI_VELDIV_64 0x00000180 // Predivide by 64
  99. #define QEI_VELDIV_128 0x000001C0 // Predivide by 128
  100. //*****************************************************************************
  101. //
  102. // Values that can be passed to QEIEnableInts, QEIDisableInts, and QEIClearInts
  103. // as the ui32IntFlags parameter, and returned by QEIGetIntStatus.
  104. //
  105. //*****************************************************************************
  106. #define QEI_INTERROR 0x00000008 // Phase error detected
  107. #define QEI_INTDIR 0x00000004 // Direction change
  108. #define QEI_INTTIMER 0x00000002 // Velocity timer expired
  109. #define QEI_INTINDEX 0x00000001 // Index pulse detected
  110. //*****************************************************************************
  111. //
  112. // Prototypes for the APIs.
  113. //
  114. //*****************************************************************************
  115. extern void QEIEnable(uint32_t ui32Base);
  116. extern void QEIDisable(uint32_t ui32Base);
  117. extern void QEIConfigure(uint32_t ui32Base, uint32_t ui32Config,
  118. uint32_t ui32MaxPosition);
  119. extern uint32_t QEIPositionGet(uint32_t ui32Base);
  120. extern void QEIPositionSet(uint32_t ui32Base, uint32_t ui32Position);
  121. extern int32_t QEIDirectionGet(uint32_t ui32Base);
  122. extern bool QEIErrorGet(uint32_t ui32Base);
  123. extern void QEIFilterEnable(uint32_t ui32Base);
  124. extern void QEIFilterDisable(uint32_t ui32Base);
  125. extern void QEIFilterConfigure(uint32_t ui32Base, uint32_t ui32FiltCnt);
  126. extern void QEIVelocityEnable(uint32_t ui32Base);
  127. extern void QEIVelocityDisable(uint32_t ui32Base);
  128. extern void QEIVelocityConfigure(uint32_t ui32Base, uint32_t ui32PreDiv,
  129. uint32_t ui32Period);
  130. extern uint32_t QEIVelocityGet(uint32_t ui32Base);
  131. extern void QEIIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
  132. extern void QEIIntUnregister(uint32_t ui32Base);
  133. extern void QEIIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
  134. extern void QEIIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
  135. extern uint32_t QEIIntStatus(uint32_t ui32Base, bool bMasked);
  136. extern void QEIIntClear(uint32_t ui32Base, uint32_t ui32IntFlags);
  137. //*****************************************************************************
  138. //
  139. // Mark the end of the C bindings section for C++ compilers.
  140. //
  141. //*****************************************************************************
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif // __DRIVERLIB_QEI_H__