rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
hal_comp_lld.h
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
3 Copyright (C) 2017 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 KINETIS/comp_lld.h
20 * @brief KINETIS KE1xF Comparator subsystem low level driver header.
21 * @author andreika <prometheus.pcb@gmail.com>
22 *
23 * @addtogroup COMP
24 * @{
25 */
26
27#ifndef HAL_COMP_LLD_H_
28#define HAL_COMP_LLD_H_
29
30#include "hal.h"
31
32#if HAL_USE_COMP || defined(__DOXYGEN__)
33
34#include "fsl_acmp.h"
35
36/*===========================================================================*/
37/* Driver constants. */
38/*===========================================================================*/
39
40
41/*===========================================================================*/
42/* Driver pre-compile time settings. */
43/*===========================================================================*/
44
45/**
46 * @name Configuration options
47 * @{
48 */
49
50/**
51 * @brief COMPD1 driver enable switch.
52 * @details If set to @p TRUE the support for COMPD1 is included.
53 * @note The default is @p FALSE.
54 */
55#if !defined(KINETIS_COMP_USE_COMP1) || defined(__DOXYGEN__)
56#define KINETIS_COMP_USE_COMP1 FALSE
57#endif
58
59/**
60 * @brief COMPD2 driver enable switch.
61 * @details If set to @p TRUE the support for COMPD2 is included.
62 * @note The default is @p FALSE.
63 */
64#if !defined(KINETIS_COMP_USE_COMP2) || defined(__DOXYGEN__)
65#define KINETIS_COMP_USE_COMP2 FALSE
66#endif
67
68/**
69 * @brief COMPD3 driver enable switch.
70 * @details If set to @p TRUE the support for COMPD3 is included.
71 * @note The default is @p FALSE.
72 */
73#if !defined(KINETIS_COMP_USE_COMP3) || defined(__DOXYGEN__)
74#define KINETIS_COMP_USE_COMP3 FALSE
75#endif
76
77/**
78 * @brief COMPD4 driver enable switch.
79 * @details If set to @p TRUE the support for COMPD4 is included.
80 * @note The default is @p FALSE.
81 */
82#if !defined(KINETIS_COMP_USE_COMP4) || defined(__DOXYGEN__)
83#define KINETIS_COMP_USE_COMP4 FALSE
84#endif
85
86/**
87 * @brief COMPD5 driver enable switch.
88 * @details If set to @p TRUE the support for COMPD4 is included.
89 * @note The default is @p FALSE.
90 */
91#if !defined(KINETIS_COMP_USE_COMP5) || defined(__DOXYGEN__)
92#define KINETIS_COMP_USE_COMP5 FALSE
93#endif
94
95/**
96 * @brief COMPD6 driver enable switch.
97 * @details If set to @p TRUE the support for COMPD4 is included.
98 * @note The default is @p FALSE.
99 */
100#if !defined(KINETIS_COMP_USE_COMP6) || defined(__DOXYGEN__)
101#define KINETIS_COMP_USE_COMP6 FALSE
102#endif
103
104/**
105 * @brief COMPD7 driver enable switch.
106 * @details If set to @p TRUE the support for COMPD4 is included.
107 * @note The default is @p FALSE.
108 */
109#if !defined(KINETIS_COMP_USE_COMP7) || defined(__DOXYGEN__)
110#define KINETIS_COMP_USE_COMP7 FALSE
111#endif
112
113/** @} */
114
115/*===========================================================================*/
116/* Derived constants and error checks. */
117/*===========================================================================*/
118
119#if KINETIS_COMP_USE_COMP0 && !KINETIS_HAS_COMP0
120#error "COMP1 not present in the selected device"
121#endif
122
123#if KINETIS_COMP_USE_COMP1 && !KINETIS_HAS_COMP1
124#error "COMP2 not present in the selected device"
125#endif
126
127#if KINETIS_COMP_USE_COMP2 && !KINETIS_HAS_COMP2
128#error "COMP3 not present in the selected device"
129#endif
130
131#if !KINETIS_COMP_USE_COMP0 && !KINETIS_COMP_USE_COMP1 && !KINETIS_COMP_USE_COMP2
132#error "COMP driver activated but no COMP peripheral assigned"
133#endif
134
135/*===========================================================================*/
136/* Driver data structures and types. */
137/*===========================================================================*/
138
139/**
140 * @brief COMP output mode.
141 */
146
147/**
148 * @brief COMP interrupt mode.
149 */
155
156/**
157 * @brief Driver configuration structure.
158 * @note It could be empty on some architectures.
159 */
160typedef struct {
161 /**
162 * @brief Ouput mode.
163 */
165
166 /**
167 * @brief Ouput mode.
168 */
170
171 /**
172 * @brief Callback.
173 */
174 compcallback_t cb;
175
176 /* End of the mandatory fields.*/
177 /**
178 * @brief COMP CSR register initialization data.
179 * @note The value of this field should normally be equal to zero.
180 */
181 /* [andreika]: STM32-compatible field */
182 uint32_t csr;
183} COMPConfig;
184
185/**
186 * @brief Structure representing an COMP driver.
187 */
189 /**
190 * @brief Driver state.
191 */
192 compstate_t state;
193 /**
194 * @brief Current configuration data.
195 */
197#if defined(COMP_DRIVER_EXT_FIELDS)
198 COMP_DRIVER_EXT_FIELDS
199#endif
200 /* End of the mandatory fields.*/
201 /**
202 * @brief Pointer to the COMPx registers block.
203 */
204 COMP_TypeDef *reg;
205
206#ifdef KE1xF
207 /**
208 * @brief ACMP driver config.
209 */
211
212 /**
213 * @brief ACMP driver channel config.
214 */
216
217 /**
218 * @brief ACMP driver DAC config.
219 */
221
222 uint32_t irq_mask;
223#endif /* KE1xF */
224};
225
226/*===========================================================================*/
227/* Driver macros. */
228/*===========================================================================*/
229
230/*===========================================================================*/
231/* External declarations. */
232/*===========================================================================*/
233
234#if KINETIS_COMP_USE_COMP0 && !defined(__DOXYGEN__)
235extern COMPDriver COMPD1;
236#endif
237
238#if KINETIS_COMP_USE_COMP1 && !defined(__DOXYGEN__)
239extern COMPDriver COMPD2;
240#endif
241
242#if KINETIS_COMP_USE_COMP2 && !defined(__DOXYGEN__)
243extern COMPDriver COMPD3;
244#endif
245
246#ifdef __cplusplus
247extern "C" {
248#endif
249 void comp_lld_init(void);
250 void comp_lld_start(COMPDriver *compp);
251 void comp_lld_stop(COMPDriver *compp);
252 void comp_lld_enable(COMPDriver *compp);
253 void comp_lld_disable(COMPDriver *compp);
254
255 void comp_lld_set_dac_value(COMPDriver *compp, uint32_t value);
256 void comp_lld_channel_enable(COMPDriver *compp, uint32_t channel);
257 void comp_lld_channel_disable(COMPDriver *compp, uint32_t channel);
258 uint32_t comp_lld_get_status(COMPDriver *compp);
259#ifdef __cplusplus
260}
261#endif
262
263#endif /* HAL_USE_COMP */
264
265#endif /* _comp_lld_H_ */
266
267/** @} */
uint16_t channel
Definition adc_inputs.h:104
void comp_lld_channel_disable(COMPDriver *compp, uint32_t channel)
Deactivate an EXT channel (used by comp)
comp_output_mode_t
COMP output mode.
COMPDriver COMPD1
COMPD1 driver identifier.
void comp_lld_set_dac_value(COMPDriver *compp, uint32_t value)
Set the DAC value used by comp.
void comp_lld_enable(COMPDriver *compp)
Enables the output.
void comp_lld_init(void)
Low level COMP driver initialization.
void comp_lld_stop(COMPDriver *compp)
Deactivates the comp peripheral.
void comp_lld_channel_enable(COMPDriver *compp, uint32_t channel)
Configures and activates an EXT channel (used by comp)
uint32_t comp_lld_get_status(COMPDriver *compp)
comp_irq_mode_t
COMP interrupt mode.
COMPDriver COMPD2
COMPD2 driver identifier.
void comp_lld_start(COMPDriver *compp)
Configures and activates the COMP peripheral.
void comp_lld_disable(COMPDriver *compp)
Disables the output.
COMPDriver COMPD3
COMPD3 driver identifier.
@ COMP_OUTPUT_INVERTED
@ COMP_OUTPUT_NORMAL
@ COMP_IRQ_FALLING
@ COMP_IRQ_RISING
@ COMP_IRQ_BOTH
@ kACMP_OutputFallingEventFlag
Definition fsl_acmp.h:46
@ kACMP_OutputRisingEventFlag
Definition fsl_acmp.h:45
Configuration for channel.
Definition fsl_acmp.h:131
Configuration for ACMP.
Definition fsl_acmp.h:113
Configuration for DAC.
Definition fsl_acmp.h:152
Driver configuration structure.
compcallback_t cb
Callback.
comp_irq_mode_t irq_mode
Ouput mode.
uint32_t csr
COMP CSR register initialization data.
comp_output_mode_t output_mode
Ouput mode.
Structure representing an COMP driver.
COMP_DRIVER_EXT_FIELDS COMP_TypeDef * reg
Pointer to the COMPx registers block.
compstate_t state
Driver state.
acmp_channel_config_t acmpChannelCfg
ACMP driver channel config.
uint32_t irq_mask
acmp_config_t acmpCfg
ACMP driver config.
acmp_dac_config_t acmpDacCfg
ACMP driver DAC config.
const COMPConfig * config
Current configuration data.