amiro-os / hal / src / qei.c @ b8085493
History | View | Annotate | Download (3.544 KB)
1 | 3f899f5d | Thomas Schöpping | /**
|
---|---|---|---|
2 | * @file qei.c
|
||
3 | * @brief QEI Driver code.
|
||
4 | *
|
||
5 | * @addtogroup QEI
|
||
6 | * @{
|
||
7 | */
|
||
8 | |||
9 | 58fe0e0b | Thomas Schöpping | #include "ch.h" |
10 | #include "hal.h" |
||
11 | #include "qei.h" |
||
12 | |||
13 | #if HAL_USE_QEI || defined(__DOXYGEN__)
|
||
14 | |||
15 | /*===========================================================================*/
|
||
16 | /* Driver local definitions. */
|
||
17 | /*===========================================================================*/
|
||
18 | |||
19 | /*===========================================================================*/
|
||
20 | /* Driver exported variables. */
|
||
21 | /*===========================================================================*/
|
||
22 | |||
23 | /*===========================================================================*/
|
||
24 | /* Driver local variables. */
|
||
25 | /*===========================================================================*/
|
||
26 | |||
27 | /*===========================================================================*/
|
||
28 | /* Driver local functions. */
|
||
29 | /*===========================================================================*/
|
||
30 | |||
31 | /*===========================================================================*/
|
||
32 | /* Driver exported functions. */
|
||
33 | /*===========================================================================*/
|
||
34 | |||
35 | /**
|
||
36 | * @brief QEI Driver initialization.
|
||
37 | * @note This function is implicitly invoked by @p halInit(), there is
|
||
38 | * no need to explicitly initialize the driver.
|
||
39 | *
|
||
40 | * @init
|
||
41 | */
|
||
42 | void qeiInit(void) { |
||
43 | |||
44 | qei_lld_init(); |
||
45 | } |
||
46 | |||
47 | /**
|
||
48 | * @brief Initializes the standard part of a @p QEIDriver structure.
|
||
49 | *
|
||
50 | * @param[out] qeip pointer to the @p QEIDriver object
|
||
51 | *
|
||
52 | * @init
|
||
53 | */
|
||
54 | void qeiObjectInit(QEIDriver *qeip) {
|
||
55 | |||
56 | qeip->state = QEI_STOP; |
||
57 | qeip->config = NULL;
|
||
58 | } |
||
59 | |||
60 | /**
|
||
61 | * @brief Configures and activates the QEI peripheral.
|
||
62 | *
|
||
63 | * @param[in] qeip pointer to the @p QEIDriver object
|
||
64 | * @param[in] config pointer to the @p QEIConfig object
|
||
65 | *
|
||
66 | * @api
|
||
67 | */
|
||
68 | void qeiStart(QEIDriver *qeip, const QEIConfig *config) { |
||
69 | |||
70 | chDbgCheck((qeip != NULL) && (config != NULL), "qeiStart"); |
||
71 | |||
72 | chSysLock(); |
||
73 | chDbgAssert((qeip->state == QEI_STOP) || (qeip->state == QEI_READY), |
||
74 | "qeiStart(), #1", "invalid state"); |
||
75 | qeip->config = config; |
||
76 | qei_lld_start(qeip); |
||
77 | qeip->state = QEI_READY; |
||
78 | chSysUnlock(); |
||
79 | } |
||
80 | |||
81 | /**
|
||
82 | * @brief Deactivates the QEI peripheral.
|
||
83 | *
|
||
84 | * @param[in] qeip pointer to the @p QEIDriver object
|
||
85 | *
|
||
86 | * @api
|
||
87 | */
|
||
88 | void qeiStop(QEIDriver *qeip) {
|
||
89 | |||
90 | chDbgCheck(qeip != NULL, "qeiStop"); |
||
91 | |||
92 | chSysLock(); |
||
93 | chDbgAssert((qeip->state == QEI_STOP) || (qeip->state == QEI_READY), |
||
94 | "qeiStop(), #1", "invalid state"); |
||
95 | qei_lld_stop(qeip); |
||
96 | qeip->state = QEI_STOP; |
||
97 | chSysUnlock(); |
||
98 | } |
||
99 | |||
100 | /**
|
||
101 | * @brief Enables the quadrature encoder.
|
||
102 | *
|
||
103 | * @param[in] qeip pointer to the @p QEIDriver object
|
||
104 | *
|
||
105 | * @api
|
||
106 | */
|
||
107 | void qeiEnable(QEIDriver *qeip) {
|
||
108 | |||
109 | chDbgCheck(qeip != NULL, "qeiEnable"); |
||
110 | |||
111 | chSysLock(); |
||
112 | chDbgAssert(qeip->state == QEI_READY, "qeiEnable(), #1", "invalid state"); |
||
113 | qei_lld_enable(qeip); |
||
114 | qeip->state = QEI_ACTIVE; |
||
115 | chSysUnlock(); |
||
116 | } |
||
117 | |||
118 | /**
|
||
119 | * @brief Disables the quadrature encoder.
|
||
120 | *
|
||
121 | * @param[in] qeip pointer to the @p QEIDriver object
|
||
122 | *
|
||
123 | * @api
|
||
124 | */
|
||
125 | void qeiDisable(QEIDriver *qeip) {
|
||
126 | |||
127 | chDbgCheck(qeip != NULL, "qeiDisable"); |
||
128 | |||
129 | chSysLock(); |
||
130 | chDbgAssert((qeip->state == QEI_READY) || (qeip->state == QEI_ACTIVE), |
||
131 | "qeiDisable(), #1", "invalid state"); |
||
132 | qei_lld_disable(qeip); |
||
133 | qeip->state = QEI_READY; |
||
134 | chSysUnlock(); |
||
135 | } |
||
136 | |||
137 | #endif /* HAL_USE_QEI */ |
||
138 | |||
139 | 3f899f5d | Thomas Schöpping | /** @} */ |