Skip to content

Commit 44de6d4

Browse files
committed
MIMXRT1050: Update the drivers to SDK 2.6
Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 8c673ba commit 44de6d4

File tree

133 files changed

+22670
-9004
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+22670
-9004
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/drivers/fsl_adc.c

Lines changed: 128 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
/*
2-
* The Clear BSD License
32
* Copyright (c) 2016, Freescale Semiconductor, Inc.
43
* Copyright 2016-2017 NXP
54
* All rights reserved.
6-
*
7-
* Redistribution and use in source and binary forms, with or without modification,
8-
* are permitted (subject to the limitations in the disclaimer below) provided
9-
* that the following conditions are met:
105
*
11-
* o Redistributions of source code must retain the above copyright notice, this list
12-
* of conditions and the following disclaimer.
13-
*
14-
* o Redistributions in binary form must reproduce the above copyright notice, this
15-
* list of conditions and the following disclaimer in the documentation and/or
16-
* other materials provided with the distribution.
17-
*
18-
* o Neither the name of the copyright holder nor the names of its
19-
* contributors may be used to endorse or promote products derived from this
20-
* software without specific prior written permission.
21-
*
22-
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6+
* SPDX-License-Identifier: BSD-3-Clause
337
*/
348

359
#include "fsl_adc.h"
@@ -39,7 +13,6 @@
3913
#define FSL_COMPONENT_ID "platform.drivers.adc_12b1msps_sar"
4014
#endif
4115

42-
4316
/*******************************************************************************
4417
* Prototypes
4518
******************************************************************************/
@@ -56,8 +29,10 @@ static uint32_t ADC_GetInstance(ADC_Type *base);
5629
/*! @brief Pointers to ADC bases for each instance. */
5730
static ADC_Type *const s_adcBases[] = ADC_BASE_PTRS;
5831

32+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
5933
/*! @brief Pointers to ADC clocks for each instance. */
6034
static const clock_ip_name_t s_adcClocks[] = ADC_CLOCKS;
35+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
6136

6237
/*******************************************************************************
6338
* Code
@@ -80,14 +55,22 @@ static uint32_t ADC_GetInstance(ADC_Type *base)
8055
return instance;
8156
}
8257

58+
/*!
59+
* brief Initialize the ADC module.
60+
*
61+
* param base ADC peripheral base address.
62+
* param config Pointer to "adc_config_t" structure.
63+
*/
8364
void ADC_Init(ADC_Type *base, const adc_config_t *config)
8465
{
8566
assert(NULL != config);
8667

8768
uint32_t tmp32;
8869

70+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
8971
/* Enable the clock. */
9072
CLOCK_EnableClock(s_adcClocks[ADC_GetInstance(base)]);
73+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
9174
/* ADCx_CFG */
9275
tmp32 = base->CFG & (ADC_CFG_AVGS_MASK | ADC_CFG_ADTRG_MASK); /* Reserve AVGS and ADTRG bits. */
9376
tmp32 |= ADC_CFG_REFSEL(config->referenceVoltageSource) | ADC_CFG_ADSTS(config->samplePeriodMode) |
@@ -123,33 +106,90 @@ void ADC_Init(ADC_Type *base, const adc_config_t *config)
123106
base->GC = tmp32;
124107
}
125108

109+
/*!
110+
* brief De-initializes the ADC module.
111+
*
112+
* param base ADC peripheral base address.
113+
*/
126114
void ADC_Deinit(ADC_Type *base)
127115
{
116+
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
128117
/* Disable the clock. */
129118
CLOCK_DisableClock(s_adcClocks[ADC_GetInstance(base)]);
119+
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
130120
}
131121

122+
/*!
123+
* brief Gets an available pre-defined settings for the converter's configuration.
124+
*
125+
* This function initializes the converter configuration structure with available settings. The default values are:
126+
* code
127+
* config->enableAsynchronousClockOutput = true;
128+
* config->enableOverWrite = false;
129+
* config->enableContinuousConversion = false;
130+
* config->enableHighSpeed = false;
131+
* config->enableLowPower = false;
132+
* config->enableLongSample = false;
133+
* config->referenceVoltageSource = kADC_ReferenceVoltageSourceAlt0;
134+
* config->samplePeriodMode = kADC_SamplePeriod2or12Clocks;
135+
* config->clockSource = kADC_ClockSourceAD;
136+
* config->clockDriver = kADC_ClockDriver1;
137+
* config->resolution = kADC_Resolution12Bit;
138+
* endcode
139+
* param base ADC peripheral base address.
140+
* param config Pointer to the configuration structure.
141+
*/
132142
void ADC_GetDefaultConfig(adc_config_t *config)
133143
{
134144
assert(NULL != config);
135145

146+
/* Initializes the configure structure to zero. */
147+
memset(config, 0, sizeof(*config));
148+
136149
config->enableAsynchronousClockOutput = true;
137-
config->enableOverWrite = false;
138-
config->enableContinuousConversion = false;
139-
config->enableHighSpeed = false;
140-
config->enableLowPower = false;
141-
config->enableLongSample = false;
142-
config->referenceVoltageSource = kADC_ReferenceVoltageSourceAlt0;
143-
config->samplePeriodMode = kADC_SamplePeriod2or12Clocks;
144-
config->clockSource = kADC_ClockSourceAD;
145-
config->clockDriver = kADC_ClockDriver1;
146-
config->resolution = kADC_Resolution12Bit;
150+
config->enableOverWrite = false;
151+
config->enableContinuousConversion = false;
152+
config->enableHighSpeed = false;
153+
config->enableLowPower = false;
154+
config->enableLongSample = false;
155+
config->referenceVoltageSource = kADC_ReferenceVoltageSourceAlt0;
156+
config->samplePeriodMode = kADC_SamplePeriod2or12Clocks;
157+
config->clockSource = kADC_ClockSourceAD;
158+
config->clockDriver = kADC_ClockDriver1;
159+
config->resolution = kADC_Resolution12Bit;
147160
}
148161

162+
/*!
163+
* brief Configures the conversion channel.
164+
*
165+
* This operation triggers the conversion when in software trigger mode. When in hardware trigger mode, this API
166+
* configures the channel while the external trigger source helps to trigger the conversion.
167+
*
168+
* Note that the "Channel Group" has a detailed description.
169+
* To allow sequential conversions of the ADC to be triggered by internal peripherals, the ADC has more than one
170+
* group of status and control registers, one for each conversion. The channel group parameter indicates which group of
171+
* registers are used, for example channel group 0 is for Group A registers and channel group 1 is for Group B
172+
* registers. The
173+
* channel groups are used in a "ping-pong" approach to control the ADC operation. At any point, only one of
174+
* the channel groups is actively controlling ADC conversions. The channel group 0 is used for both software and
175+
* hardware
176+
* trigger modes. Channel groups 1 and greater indicate potentially multiple channel group registers for
177+
* use only in hardware trigger mode. See the chip configuration information in the appropriate MCU reference manual
178+
* about the
179+
* number of SC1n registers (channel groups) specific to this device. None of the channel groups 1 or greater are used
180+
* for software trigger operation. Therefore, writing to these channel groups does not initiate a new conversion.
181+
* Updating the channel group 0 while a different channel group is actively controlling a conversion is allowed and
182+
* vice versa. Writing any of the channel group registers while that specific channel group is actively controlling a
183+
* conversion aborts the current conversion.
184+
*
185+
* param base ADC peripheral base address.
186+
* param channelGroup Channel group index.
187+
* param config Pointer to the "adc_channel_config_t" structure for the conversion channel.
188+
*/
149189
void ADC_SetChannelConfig(ADC_Type *base, uint32_t channelGroup, const adc_channel_config_t *config)
150190
{
151191
assert(NULL != config);
152-
assert(channelGroup < ADC_HC_COUNT);
192+
assert(channelGroup < FSL_FEATURE_ADC_CONVERSION_CONTROL_COUNT);
153193

154194
uint32_t tmp32;
155195

@@ -168,6 +208,19 @@ void ADC_SetChannelConfig(ADC_Type *base, uint32_t channelGroup, const adc_chann
168208
* 3. Check the status of CALF bit in ADC_GS and the CAL bit in ADC_GC.
169209
* 4. When CAL bit becomes '0' then check the CALF status and COCO[0] bit status.
170210
*/
211+
/*!
212+
* brief Automates the hardware calibration.
213+
*
214+
* This auto calibration helps to adjust the plus/minus side gain automatically.
215+
* Execute the calibration before using the converter. Note that the software trigger should be used
216+
* during calibration.
217+
*
218+
* param base ADC peripheral base address.
219+
*
220+
* return Execution status.
221+
* retval kStatus_Success Calibration is done successfully.
222+
* retval kStatus_Fail Calibration has failed.
223+
*/
171224
status_t ADC_DoAutoCalibration(ADC_Type *base)
172225
{
173226
status_t status = kStatus_Success;
@@ -222,6 +275,12 @@ status_t ADC_DoAutoCalibration(ADC_Type *base)
222275
return status;
223276
}
224277

278+
/*!
279+
* brief Set user defined offset.
280+
*
281+
* param base ADC peripheral base address.
282+
* param config Pointer to "adc_offest_config_t" structure.
283+
*/
225284
void ADC_SetOffsetConfig(ADC_Type *base, const adc_offest_config_t *config)
226285
{
227286
assert(NULL != config);
@@ -236,6 +295,19 @@ void ADC_SetOffsetConfig(ADC_Type *base, const adc_offest_config_t *config)
236295
base->OFS = tmp32;
237296
}
238297

298+
/*!
299+
* brief Configures the hardware compare mode.
300+
*
301+
* The hardware compare mode provides a way to process the conversion result automatically by using hardware. Only the
302+
* result
303+
* in the compare range is available. To compare the range, see "adc_hardware_compare_mode_t" or the appopriate
304+
* reference
305+
* manual for more information.
306+
*
307+
* param base ADC peripheral base address.
308+
* param Pointer to "adc_hardware_compare_config_t" structure.
309+
*
310+
*/
239311
void ADC_SetHardwareCompareConfig(ADC_Type *base, const adc_hardware_compare_config_t *config)
240312
{
241313
uint32_t tmp32;
@@ -269,10 +341,20 @@ void ADC_SetHardwareCompareConfig(ADC_Type *base, const adc_hardware_compare_con
269341
base->GC = tmp32;
270342

271343
/* Load the compare values. */
272-
tmp32 = ADC_CV_CV1(config->value1) | ADC_CV_CV2(config->value2);
344+
tmp32 = ADC_CV_CV1(config->value1) | ADC_CV_CV2(config->value2);
273345
base->CV = tmp32;
274346
}
275347

348+
/*!
349+
* brief Configures the hardware average mode.
350+
*
351+
* The hardware average mode provides a way to process the conversion result automatically by using hardware. The
352+
* multiple
353+
* conversion results are accumulated and averaged internally making them easier to read.
354+
*
355+
* param base ADC peripheral base address.
356+
* param mode Setting the hardware average mode. See "adc_hardware_average_mode_t".
357+
*/
276358
void ADC_SetHardwareAverageConfig(ADC_Type *base, adc_hardware_average_mode_t mode)
277359
{
278360
uint32_t tmp32;
@@ -290,6 +372,12 @@ void ADC_SetHardwareAverageConfig(ADC_Type *base, adc_hardware_average_mode_t mo
290372
}
291373
}
292374

375+
/*!
376+
* brief Clears the converter's status falgs.
377+
*
378+
* param base ADC peripheral base address.
379+
* param mask Mask value for the cleared flags. See "adc_status_flags_t".
380+
*/
293381
void ADC_ClearStatusFlags(ADC_Type *base, uint32_t mask)
294382
{
295383
uint32_t tmp32 = 0;

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/drivers/fsl_adc.h

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
/*
2-
* The Clear BSD License
32
* Copyright (c) 2016, Freescale Semiconductor, Inc.
43
* Copyright 2016-2017 NXP
54
* All rights reserved.
6-
*
7-
* Redistribution and use in source and binary forms, with or without modification,
8-
* are permitted (subject to the limitations in the disclaimer below) provided
9-
* that the following conditions are met:
105
*
11-
* o Redistributions of source code must retain the above copyright notice, this list
12-
* of conditions and the following disclaimer.
13-
*
14-
* o Redistributions in binary form must reproduce the above copyright notice, this
15-
* list of conditions and the following disclaimer in the documentation and/or
16-
* other materials provided with the distribution.
17-
*
18-
* o Neither the name of the copyright holder nor the names of its
19-
* contributors may be used to endorse or promote products derived from this
20-
* software without specific prior written permission.
21-
*
22-
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6+
* SPDX-License-Identifier: BSD-3-Clause
337
*/
348

359
#ifndef _FSL_ADC_H_
@@ -43,20 +17,20 @@
4317
*/
4418

4519
/*******************************************************************************
46-
* Definitions
47-
******************************************************************************/
20+
* Definitions
21+
******************************************************************************/
4822
/*! @brief ADC driver version */
49-
#define FSL_ADC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
23+
#define FSL_ADC_DRIVER_VERSION (MAKE_VERSION(2, 0, 2)) /*!< Version 2.0.2. */
5024

5125
/*!
5226
* @brief Converter's status flags.
5327
*/
5428
typedef enum _adc_status_flags
5529
{
56-
kADC_ConversionActiveFlag = ADC_GS_ADACT_MASK, /*!< Conversion is active,not support w1c. */
57-
kADC_CalibrationFailedFlag = ADC_GS_CALF_MASK, /*!< Calibration is failed,support w1c. */
30+
kADC_ConversionActiveFlag = ADC_GS_ADACT_MASK, /*!< Conversion is active,not support w1c. */
31+
kADC_CalibrationFailedFlag = ADC_GS_CALF_MASK, /*!< Calibration is failed,support w1c. */
5832
kADC_AsynchronousWakeupInterruptFlag =
59-
ADC_GS_AWKST_MASK, /*!< Asynchronous wakeup interrupt occured, support w1c. */
33+
ADC_GS_AWKST_MASK, /*!< Asynchronous wakeup interrupt occurred, support w1c. */
6034
} adc_status_flags_t;
6135

6236
/*!
@@ -95,7 +69,7 @@ typedef enum _adc_sample_period_mode
9569
*/
9670
typedef enum _adc_clock_source
9771
{
98-
kADC_ClockSourceIPG = 0U, /*!< Select IPG clock to generate ADCK. */
72+
kADC_ClockSourceIPG = 0U, /*!< Select IPG clock to generate ADCK. */
9973
kADC_ClockSourceIPGDiv2 = 1U, /*!< Select IPG clock divided by 2 to generate ADCK. */
10074
#if !(defined(FSL_FEATURE_ADC_SUPPORT_ALTCLK_REMOVE) && FSL_FEATURE_ADC_SUPPORT_ALTCLK_REMOVE)
10175
kADC_ClockSourceALT = 2U, /*!< Select alternate clock to generate ADCK. */
@@ -119,7 +93,7 @@ typedef enum _adc_clock_drvier
11993
*/
12094
typedef enum _adc_resolution
12195
{
122-
kADC_Resolution8Bit = 0U, /*!< Single End 8-bit resolution. */
96+
kADC_Resolution8Bit = 0U, /*!< Single End 8-bit resolution. */
12397
kADC_Resolution10Bit = 1U, /*!< Single End 10-bit resolution. */
12498
kADC_Resolution12Bit = 2U, /*!< Single End 12-bit resolution. */
12599
} adc_resolution_t;
@@ -146,10 +120,10 @@ typedef enum _adc_hardware_compare_mode
146120
*/
147121
typedef enum _adc_hardware_average_mode
148122
{
149-
kADC_HardwareAverageCount4 = 0U, /*!< For hardware average with 4 samples. */
150-
kADC_HardwareAverageCount8 = 1U, /*!< For hardware average with 8 samples. */
151-
kADC_HardwareAverageCount16 = 2U, /*!< For hardware average with 16 samples. */
152-
kADC_HardwareAverageCount32 = 3U, /*!< For hardware average with 32 samples. */
123+
kADC_HardwareAverageCount4 = 0U, /*!< For hardware average with 4 samples. */
124+
kADC_HardwareAverageCount8 = 1U, /*!< For hardware average with 8 samples. */
125+
kADC_HardwareAverageCount16 = 2U, /*!< For hardware average with 16 samples. */
126+
kADC_HardwareAverageCount32 = 3U, /*!< For hardware average with 32 samples. */
153127
kADC_HardwareAverageDiasable = 4U, /*!< Disable the hardware average function. */
154128
} adc_hardware_average_mode_t;
155129

@@ -214,8 +188,8 @@ typedef struct _adc_channel_config
214188
bool enableInterruptOnConversionCompleted; /*!< Generate an interrupt request once the conversion is completed. */
215189
} adc_channel_config_t;
216190
/*******************************************************************************
217-
* API
218-
******************************************************************************/
191+
* API
192+
******************************************************************************/
219193
#if defined(__cplusplus)
220194
extern "C" {
221195
#endif
@@ -301,7 +275,7 @@ void ADC_SetChannelConfig(ADC_Type *base, uint32_t channelGroup, const adc_chann
301275
*/
302276
static inline uint32_t ADC_GetChannelConversionValue(ADC_Type *base, uint32_t channelGroup)
303277
{
304-
assert(channelGroup < ADC_R_COUNT);
278+
assert(channelGroup < FSL_FEATURE_ADC_CONVERSION_CONTROL_COUNT);
305279

306280
return base->R[channelGroup];
307281
}
@@ -325,7 +299,7 @@ static inline uint32_t ADC_GetChannelConversionValue(ADC_Type *base, uint32_t ch
325299
*/
326300
static inline uint32_t ADC_GetChannelStatusFlags(ADC_Type *base, uint32_t channelGroup)
327301
{
328-
assert(channelGroup < ADC_HC_COUNT);
302+
assert(channelGroup < FSL_FEATURE_ADC_CONVERSION_CONTROL_COUNT);
329303

330304
/* If flag is set,return 1,otherwise, return 0. */
331305
return (((base->HS) & (1U << channelGroup)) >> channelGroup);

0 commit comments

Comments
 (0)