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