aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/drivers/inc/fsl_adc16_driver.h
blob: 3b851664182b4863063a0dc7844d859262958a49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __FSL_ADC16_DRIVER_H__
#define __FSL_ADC16_DRIVER_H__

#include <stdint.h>
#include <stdbool.h>
#include "fsl_adc16_hal.h"
#if FSL_FEATURE_SOC_ADC16_COUNT

/*!
 * @addtogroup adc16_driver
 * @{
 */

/*******************************************************************************
 * Definitions
 ******************************************************************************/
#if FSL_FEATURE_ADC16_HAS_CALIBRATION

/*!
 * @brief Defines the structure to configure the ADC16 module calibration.
 *
 * This structure holds the configuration for the ADC16 module internal calibration.
 */
typedef struct Adc16CalibrationParam
{
    /* PG. */
    uint16_t plusSideGainValue; /*!< Plus-side gain value. */

    /* MG. */
#if FSL_FEATURE_ADC16_HAS_DIFF_MODE
    uint16_t minusSideGainValue; /*!< Minus-side gain value. */
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */

    /* Offset value. */
#if FSL_FEATURE_ADC16_HAS_OFFSET_CORRECTION
    uint16_t offsetValue; /*!< Offset error from correction value. */
#endif /* FSL_FEATURE_ADC16_HAS_OFFSET_CORRECTION */

} adc16_calibration_param_t;

#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */

/*!
 * @brief Defines the type of event flags.
 */
typedef enum _adc16_flag_t
{
    kAdcConvActiveFlag = 0U, /*!< Indicates if a conversion or hardware averaging is in progress. */
#if FSL_FEATURE_ADC16_HAS_CALIBRATION
    kAdcCalibrationFailedFlag = 1U, /*!< Indicates if the calibration failed. */
    kAdcCalibrationActiveFlag = 2U, /*!< Indicates if the calibration is activated.*/
#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
    kAdcChnConvCompleteFlag = 3U /*!< Indicates if the channel group A is ready.*/
} adc16_flag_t;

/*! @brief Table of base addresses for ADC16 instances. */
extern ADC_Type * const g_adcBase[];

/*! @brief Table to save ADC IRQ enum numbers defined in the CMSIS header file. */
extern const IRQn_Type g_adcIrqId[ADC_INSTANCE_COUNT];

#if defined(__cplusplus)
extern "C" {
#endif

/******************************************************************************
 * API
 *****************************************************************************/

#if FSL_FEATURE_ADC16_HAS_CALIBRATION
/*!
 * @brief Gets the calibration parameters by auto calibration.
 *
 * This function executes auto calibration and fetches the calibration parameters
 * that are kept in the "adc16_calibration_param_t" type variable.
 *
 * @param instance ADC16 instance ID.
 * @param paramPtr Pointer to the parameter structure. See the "adc16_calibration_param_t".
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_GetAutoCalibrationParam(uint32_t instance, adc16_calibration_param_t *paramPtr);

/*!
 * @brief Sets the calibration parameters.
 *
 * This function sets the calibration parameters.
 *
 * @param instance ADC16 instance ID.
 * @param paramPtr Pointer to parameter structure. See the "adc16_calibration_param_t".
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_SetCalibrationParam(uint32_t instance, const adc16_calibration_param_t *paramPtr);

#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */

/*!
 * @brief Fills the initial user configuration by default for a one-time trigger mode.
 *
 * This function fills the initial user configuration by default for a one-time
 * trigger mode. Calling the initialization function with the filled parameter
 * configures the ADC module work as one-time trigger mode. The settings are:
 * \n
 *
 * \li.lowPowerEnable = true;
 * \li.clkDividerMode = kAdc16ClkDividerOf8;
 * \li.longSampleTimeEnable = true;
 * \li.resolutionMode = kAdc16ResolutionBitOfSingleEndAs12;
 * \li.clkSrc = kAdc16ClkSrcOfAsynClk
 * \li.asyncClkEnable = true;
 * \li.highSpeedEnable = false;
 * \li.longSampleCycleMode = kAdc16LongSampleCycleOf24;
 * \li.hwTriggerEnable = false;
 * \li.refVoltSrc = kAdcRefVoltSrcOfVref;
 * \li.continuousConvEnable = false;
 * \li.dmaEnable = false;
 *
 * @param userConfigPtr Pointer to the user configuration structure. See the "adc16_converter_config_t".
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_StructInitUserConfigDefault(adc16_converter_config_t *userConfigPtr);

/*!
 * @brief Initializes the ADC module converter.
 *
 * This function initializes the converter in the ADC module.
 *
 * @param instance ADC16 instance ID.
 * @param userConfigPtr Pointer to the initialization structure. See the "adc16_converter_config_t".
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_Init(uint32_t instance, const adc16_converter_config_t *userConfigPtr);

/*!
 * @brief De-initializes the ADC module converter.
 *
 * This function de-initializes and gates the ADC module. When ADC is no longer used, calling
 * this API function shuts down the device to reduce the power consumption.
 *
 * @param instance ADC16 instance ID.
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_Deinit(uint32_t instance);

/*!
 * @brief Configures the hardware compare feature.
 *
 * This function configures the hardware compare feature with indicated configuration.
 *
 * @param instance ADC16 instance ID.
 * @param configPtr Pointer to configuration structure. See the "adc16_hw_cmp_config_t".
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_ConfigHwCompare(uint32_t instance, const adc16_hw_cmp_config_t *configPtr);

#if FSL_FEATURE_ADC16_HAS_HW_AVERAGE

/*!
 * @brief Configures the hardware averaging feature.
 *
 * This function configures the hardware averaging feature with an indicated configuration.
 *
 * @param instance ADC16 instance ID.
 * @param configPtr Pointer to configuration structure. See to "adc16_hw_average_config_t".
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_ConfigHwAverage(uint32_t instance, const adc16_hw_average_config_t *configPtr);

#endif /* FSL_FEATURE_ADC16_HAS_HW_AVERAGE */

#if FSL_FEATURE_ADC16_HAS_PGA

/*!
 * @brief Configures the Programmable Gain Amplifier (PGA) feature.
 *
 * This function configures the PGA feature.
 *
 * @param instance ADC16 instance ID.
 * @param configPtr Pointer to configuration structure. See the "adc16_pga_config_t".
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_ConfigPga(uint32_t instance, const adc16_pga_config_t *configPtr);

#endif /* FSL_FEATURE_ADC16_HAS_PGA */

#if FSL_FEATURE_ADC16_HAS_MUX_SELECT
/*!
 * @brief Switches the channel mux.
 *
 * This function switches the channel mux. For some channels share the same
 * channel index with different channel mux, like AD4a and AD4b, could be switched
 * to each group by calling this function.
 *
 * @param instance ADC16 instance ID.
 * @param chnMuxMode Setting channel mux. See the "adc16_chn_mux_mode_t".
 */
void ADC16_DRV_SetChnMux(uint32_t instance, adc16_chn_mux_mode_t chnMuxMode);
#endif /* FSL_FEATURE_ADC16_HAS_MUX_SELECT */

/*!
 * @brief Configure the conversion channel by software.
 *
 * This function configures the conversion channel. When the ADC16 module has
 * been initialized by enabling the software trigger (disable hardware trigger),
 * calling this API triggers the conversion.
 *
 * @param instance ADC16 instance ID.
 * @param chnGroup Selection of the configuration group.
 * @param configPtr Pointer to configuration structure. See the "adc16_chn_config_t".
 * @return Execution status.
 */
adc16_status_t ADC16_DRV_ConfigConvChn(uint32_t instance, uint32_t chnGroup, const adc16_chn_config_t *configPtr);

/*!
 * @brief Waits for the latest conversion to be complete.
 *
 * This function waits for the latest conversion to be complete. When
 * triggering  the conversion by configuring the available channel, the converter is
 * launched. This API function should be called to wait for the conversion to be
 * complete when no interrupt or DMA mode is used for the ADC16 module. After the
 * waiting period, the available data from the conversion result are fetched.
 * The complete flag is not cleared until the result data is read.
 *
 * @param instance ADC16 instance ID.
 * @param chnGroup Selection of configuration group.
 */
void ADC16_DRV_WaitConvDone(uint32_t instance, uint32_t chnGroup);

/*!
 * @brief Pauses the current conversion by software.
 *
 * This function pauses the current conversion setting by software.
 *
 * @param instance ADC16 instance ID.
 * @param chnGroup Selection of configuration group.
 */
void ADC16_DRV_PauseConv(uint32_t instance, uint32_t chnGroup);

/*!
 * @brief Gets the latest conversion value with no format.
 *
 * This function gets the conversion value from the ADC16 module.
 *
 * @param instance ADC16 instance ID.
 * @param chnGroup Selection of configuration group.
 * @return Unformatted conversion value.
 */
uint16_t ADC16_DRV_GetConvValueRAW(uint32_t instance, uint32_t chnGroup);

/*!
 * @brief Gets the latest conversion value with signed.
 *
 * This function gets the conversion value from the ADC16 module with signed.
 *
 * @param instance ADC16 instance ID.
 * @param chnGroup Selection of configuration group.
 * @return Signed conversion value.
 */
int16_t ADC16_DRV_GetConvValueSigned(uint32_t instance, uint32_t chnGroup);

/*!
 * @brief Gets the event status of the ADC16 module.
 *
 * This function gets the event status of the ADC16 converter.
 * If the event is asserted, it returns "true". Otherwise, it is "false".
 *
 * @param instance ADC16 instance ID.
 * @param flag Indicated event.
 * @return Assertion of event flag.
 */
bool ADC16_DRV_GetConvFlag(uint32_t instance, adc16_flag_t flag);

/*!
 * @brief Gets the event status of each channel group.
 *
 * This function gets the event status of each channel group.
 * If the event is asserted, it returns "true". Otherwise, it is "false".
 *
 * @param instance ADC16 instance ID.
 * @param chnGroup ADC16 channel group number.
 * @param flag Indicated event.
 * @return Assertion of event flag.
 */
bool ADC16_DRV_GetChnFlag(uint32_t instance, uint32_t chnGroup, adc16_flag_t flag);

#if defined(__cplusplus)
}
#endif


/*!
 *@}
 */

#endif
#endif /* __FSL_ADC16_DRIVER_H__ */

/******************************************************************************
 * EOF
 *****************************************************************************/