1 //*****************************************************************************
2 //
3 // qei.h - Prototypes for the Quadrature Encoder Driver.
4 //
5 // Copyright (c) 2005-2012 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 9453 of the Stellaris Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 #ifndef __QEI_H__
41 #define __QEI_H__
42 
43 //*****************************************************************************
44 //
45 // If building with a C++ compiler, make all of the definitions in this header
46 // have a C binding.
47 //
48 //*****************************************************************************
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
53 
54 //*****************************************************************************
55 //
56 // Values that can be passed to QEIConfigure as the ulConfig paramater.
57 //
58 //*****************************************************************************
59 #define QEI_CONFIG_CAPTURE_A    0x00000000  // Count on ChA edges only
60 #define QEI_CONFIG_CAPTURE_A_B  0x00000008  // Count on ChA and ChB edges
61 #define QEI_CONFIG_NO_RESET     0x00000000  // Do not reset on index pulse
62 #define QEI_CONFIG_RESET_IDX    0x00000010  // Reset position on index pulse
63 #define QEI_CONFIG_QUADRATURE   0x00000000  // ChA and ChB are quadrature
64 #define QEI_CONFIG_CLOCK_DIR    0x00000004  // ChA and ChB are clock and dir
65 #define QEI_CONFIG_NO_SWAP      0x00000000  // Do not swap ChA and ChB
66 #define QEI_CONFIG_SWAP         0x00000002  // Swap ChA and ChB
67 
68 //*****************************************************************************
69 //
70 // Values that can be passed to QEIVelocityConfigure as the ulPreDiv parameter.
71 //
72 //*****************************************************************************
73 #define QEI_VELDIV_1            0x00000000  // Predivide by 1
74 #define QEI_VELDIV_2            0x00000040  // Predivide by 2
75 #define QEI_VELDIV_4            0x00000080  // Predivide by 4
76 #define QEI_VELDIV_8            0x000000C0  // Predivide by 8
77 #define QEI_VELDIV_16           0x00000100  // Predivide by 16
78 #define QEI_VELDIV_32           0x00000140  // Predivide by 32
79 #define QEI_VELDIV_64           0x00000180  // Predivide by 64
80 #define QEI_VELDIV_128          0x000001C0  // Predivide by 128
81 
82 //*****************************************************************************
83 //
84 // Values that can be passed to QEIEnableInts, QEIDisableInts, and QEIClearInts
85 // as the ulIntFlags parameter, and returned by QEIGetIntStatus.
86 //
87 //*****************************************************************************
88 #define QEI_INTERROR            0x00000008  // Phase error detected
89 #define QEI_INTDIR              0x00000004  // Direction change
90 #define QEI_INTTIMER            0x00000002  // Velocity timer expired
91 #define QEI_INTINDEX            0x00000001  // Index pulse detected
92 
93 //*****************************************************************************
94 //
95 // Prototypes for the APIs.
96 //
97 //*****************************************************************************
98 extern void QEIEnable(unsigned long ulBase);
99 extern void QEIDisable(unsigned long ulBase);
100 extern void QEIConfigure(unsigned long ulBase, unsigned long ulConfig,
101                          unsigned long ulMaxPosition);
102 extern unsigned long QEIPositionGet(unsigned long ulBase);
103 extern void QEIPositionSet(unsigned long ulBase, unsigned long ulPosition);
104 extern long QEIDirectionGet(unsigned long ulBase);
105 extern tBoolean QEIErrorGet(unsigned long ulBase);
106 extern void QEIVelocityEnable(unsigned long ulBase);
107 extern void QEIVelocityDisable(unsigned long ulBase);
108 extern void QEIVelocityConfigure(unsigned long ulBase, unsigned long ulPreDiv,
109                                  unsigned long ulPeriod);
110 extern unsigned long QEIVelocityGet(unsigned long ulBase);
111 extern void QEIIntRegister(unsigned long ulBase, void (*pfnHandler)(void));
112 extern void QEIIntUnregister(unsigned long ulBase);
113 extern void QEIIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
114 extern void QEIIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
115 extern unsigned long QEIIntStatus(unsigned long ulBase, tBoolean bMasked);
116 extern void QEIIntClear(unsigned long ulBase, unsigned long ulIntFlags);
117 
118 //*****************************************************************************
119 //
120 // Mark the end of the C bindings section for C++ compilers.
121 //
122 //*****************************************************************************
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif // __QEI_H__
128