Statistics
| Branch: | Tag: | Revision:

amiro-os / os / hal / src / hal_qei.c @ 76ca5065

History | View | Annotate | Download (4.317 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
/**
20
 * @file    hal_qei.c
21
 * @brief   QEI Driver code.
22
 *
23
 * @addtogroup QEI
24
 * @{
25
 */
26

    
27
#include "hal.h"
28
#include "hal_qei.h"
29

    
30
#if HAL_USE_QEI || defined(__DOXYGEN__)
31

    
32
/*===========================================================================*/
33
/* Driver local definitions.                                                 */
34
/*===========================================================================*/
35

    
36
/*===========================================================================*/
37
/* Driver exported variables.                                                */
38
/*===========================================================================*/
39

    
40
/*===========================================================================*/
41
/* Driver local variables.                                                   */
42
/*===========================================================================*/
43

    
44
/*===========================================================================*/
45
/* Driver local functions.                                                   */
46
/*===========================================================================*/
47

    
48
/*===========================================================================*/
49
/* Driver exported functions.                                                */
50
/*===========================================================================*/
51

    
52
/**
53
 * @brief   QEI Driver initialization.
54
 * @note    This function is implicitly invoked by @p halInit(), there is
55
 *          no need to explicitly initialize the driver.
56
 *
57
 * @init
58
 */
59
void qeiInit(void) {
60

    
61
  qei_lld_init();
62
}
63

    
64
/**
65
 * @brief   Initializes the standard part of a @p QEIDriver structure.
66
 *
67
 * @param[out] qeip     pointer to the @p QEIDriver object
68
 *
69
 * @init
70
 */
71
void qeiObjectInit(QEIDriver *qeip) {
72

    
73
  qeip->state  = QEI_STOP;
74
  qeip->config = NULL;
75
}
76

    
77
/**
78
 * @brief   Configures and activates the QEI peripheral.
79
 *
80
 * @param[in] qeip      pointer to the @p QEIDriver object
81
 * @param[in] config    pointer to the @p QEIConfig object
82
 *
83
 * @api
84
 */
85
void qeiStart(QEIDriver *qeip, const QEIConfig *config) {
86

    
87
  chDbgCheck((qeip != NULL) && (config != NULL) /*, "qeiStart"*/);
88

    
89
  chSysLock();
90
  chDbgAssert((qeip->state == QEI_STOP) || (qeip->state == QEI_READY),
91
              "qeiStart(), #1" /*, "invalid state"*/);
92
  qeip->config = config;
93
  qei_lld_start(qeip);
94
  qeip->state = QEI_READY;
95
  chSysUnlock();
96
}
97

    
98
/**
99
 * @brief   Deactivates the QEI peripheral.
100
 *
101
 * @param[in] qeip      pointer to the @p QEIDriver object
102
 *
103
 * @api
104
 */
105
void qeiStop(QEIDriver *qeip) {
106

    
107
  chDbgCheck(qeip != NULL /*, "qeiStop"*/);
108

    
109
  chSysLock();
110
  chDbgAssert((qeip->state == QEI_STOP) || (qeip->state == QEI_READY),
111
              "qeiStop(), #1" /*, "invalid state"*/);
112
  qei_lld_stop(qeip);
113
  qeip->state = QEI_STOP;
114
  chSysUnlock();
115
}
116

    
117
/**
118
 * @brief   Enables the quadrature encoder.
119
 *
120
 * @param[in] qeip      pointer to the @p QEIDriver object
121
 *
122
 * @api
123
 */
124
void qeiEnable(QEIDriver *qeip) {
125

    
126
  chDbgCheck(qeip != NULL /*, "qeiEnable"*/);
127

    
128
  chSysLock();
129
  chDbgAssert(qeip->state == QEI_READY, "qeiEnable(), #1" /*, "invalid state"*/);
130
  qei_lld_enable(qeip);
131
  qeip->state = QEI_ACTIVE;
132
  chSysUnlock();
133
}
134

    
135
/**
136
 * @brief   Disables the quadrature encoder.
137
 *
138
 * @param[in] qeip      pointer to the @p QEIDriver object
139
 *
140
 * @api
141
 */
142
void qeiDisable(QEIDriver *qeip) {
143

    
144
  chDbgCheck(qeip != NULL /*, "qeiDisable"*/);
145

    
146
  chSysLock();
147
  chDbgAssert((qeip->state == QEI_READY) || (qeip->state == QEI_ACTIVE),
148
              "qeiDisable(), #1" /*, "invalid state"*/);
149
  qei_lld_disable(qeip);
150
  qeip->state = QEI_READY;
151
  chSysUnlock();
152
}
153

    
154
#endif /* HAL_USE_QEI */
155

    
156
/** @} */