aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/hal/src/hal_opamp.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/hal/src/hal_opamp.c')
-rw-r--r--lib/chibios-contrib/os/hal/src/hal_opamp.c155
1 files changed, 155 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/src/hal_opamp.c b/lib/chibios-contrib/os/hal/src/hal_opamp.c
new file mode 100644
index 000000000..79a5ec8b9
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/src/hal_opamp.c
@@ -0,0 +1,155 @@
1/*
2 ChibiOS - Copyright (C) 2006..2019 Giovanni Di Sirio
3 Copyright (C) 2019 Fabien Poussin (fabien.poussin (at) google's mail)
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18/**
19 * @file hal_opamp.c
20 * @brief OPAMP Driver code.
21 *
22 * @addtogroup OPAMP
23 * @{
24 */
25
26#include "hal_opamp.h"
27
28#if HAL_USE_OPAMP || defined(__DOXYGEN__)
29
30
31/*===========================================================================*/
32/* Driver local definitions. */
33/*===========================================================================*/
34
35/*===========================================================================*/
36/* Driver exported variables. */
37/*===========================================================================*/
38
39/*===========================================================================*/
40/* Driver local variables and types. */
41/*===========================================================================*/
42
43/*===========================================================================*/
44/* Driver local functions. */
45/*===========================================================================*/
46
47/*===========================================================================*/
48/* Driver exported functions. */
49/*===========================================================================*/
50
51/**
52 * @brief OPAMP Driver initialization.
53 * @note This function is implicitly invoked by @p halInit(), there is
54 * no need to explicitly initialize the driver.
55 *
56 * @init
57 */
58void opampInit(void) {
59
60 opamp_lld_init();
61}
62
63/**
64 * @brief Initializes the standard part of a @p OPAMPDriver structure.
65 *
66 * @param[out] opampp pointer to the @p OPAMPDriver object
67 *
68 * @init
69 */
70void opampObjectInit(OPAMPDriver *opampp) {
71
72 opampp->state = OPAMP_STOP;
73 opampp->config = NULL;
74}
75
76/**
77 * @brief Configures and activates the OPAMP peripheral.
78 *
79 * @param[in] opampp pointer to the @p OPAMPDriver object
80 * @param[in] config pointer to the @p OPAMPConfig object
81 *
82 * @api
83 */
84void opampStart(OPAMPDriver *opampp, const OPAMPConfig *config) {
85
86 osalDbgCheck((opampp != NULL) && (config != NULL));
87
88 osalSysLock();
89 osalDbgAssert((opampp->state == OPAMP_STOP) || (opampp->state == OPAMP_ACTIVE),
90 "invalid state");
91 opampp->config = config;
92 opamp_lld_start(opampp);
93 opampp->state = OPAMP_ACTIVE;
94 osalSysUnlock();
95}
96
97/**
98 * @brief Deactivates the OPAMP peripheral.
99 *
100 * @param[in] opampp pointer to the @p OPAMPDriver object
101 *
102 * @api
103 */
104void opampStop(OPAMPDriver *opampp) {
105
106 osalDbgCheck(opampp != NULL);
107
108 osalSysLock();
109 osalDbgAssert((opampp->state == OPAMP_STOP) || (opampp->state == OPAMP_ACTIVE),
110 "invalid state");
111 opamp_lld_stop(opampp);
112 opampp->state = OPAMP_STOP;
113 osalSysUnlock();
114}
115
116/**
117 * @brief Activates the opamp.
118 *
119 * @param[in] opampp pointer to the @p OPAMPDriver object
120 *
121 * @api
122 */
123void opampEnable(OPAMPDriver *opampp) {
124
125 osalDbgCheck(opampp != NULL);
126
127 osalSysLock();
128 osalDbgAssert(opampp->state == OPAMP_ACTIVE, "invalid state");
129 opamp_lld_enable(opampp);
130 opampp->state = OPAMP_ACTIVE;
131 osalSysUnlock();
132}
133
134/**
135 * @brief Deactivates the opamp.
136 *
137 * @param[in] opampp pointer to the @p OPAMPDriver object
138 *
139 * @api
140 */
141void opampDisable(OPAMPDriver *opampp) {
142
143 osalDbgCheck(opampp != NULL);
144
145 osalSysLock();
146 osalDbgAssert((opampp->state == OPAMP_ACTIVE),
147 "invalid state");
148 opamp_lld_disable(opampp);
149 opampp->state = OPAMP_ACTIVE;
150 osalSysUnlock();
151}
152
153#endif /* HAL_USE_OPAMP */
154
155/** @} */