rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Enumerator | Variables
Adc12

Data Structures

struct  _adc12_config
 Converter configuration. More...
 
struct  _adc12_hardware_compare_config
 Hardware compare configuration. More...
 
struct  _adc12_channel_config
 Channel conversion configuration. More...
 

Typedefs

typedef enum _adc12_clock_divider adc12_clock_divider_t
 Clock divider for the converter.
 
typedef enum _adc12_resolution adc12_resolution_t
 Converter's resolution.
 
typedef enum _adc12_clock_source adc12_clock_source_t
 Conversion clock source.
 
typedef enum _adc12_reference_voltage_source adc12_reference_voltage_source_t
 Reference voltage source.
 
typedef enum _adc12_hardware_average_mode adc12_hardware_average_mode_t
 Hardware average mode.
 
typedef enum _adc12_hardware_compare_mode adc12_hardware_compare_mode_t
 Hardware compare mode.
 
typedef struct _adc12_config adc12_config_t
 Converter configuration.
 
typedef struct _adc12_hardware_compare_config adc12_hardware_compare_config_t
 Hardware compare configuration.
 
typedef struct _adc12_channel_config adc12_channel_config_t
 Channel conversion configuration.
 

Enumerations

enum  _adc12_channel_status_flags { kADC12_ChannelConversionCompletedFlag = ADC_SC1_COCO_MASK }
 Channel status flags' mask. More...
 
enum  _adc12_status_flags { kADC12_ActiveFlag = ADC_SC2_ADACT_MASK , kADC12_CalibrationFailedFlag = (ADC_SC2_ADACT_MASK << 1U) }
 Converter status flags' mask. More...
 
enum  _adc12_clock_divider { kADC12_ClockDivider1 = 0U , kADC12_ClockDivider2 = 1U , kADC12_ClockDivider4 = 2U , kADC12_ClockDivider8 = 3U }
 Clock divider for the converter. More...
 
enum  _adc12_resolution { kADC12_Resolution8Bit = 0U , kADC12_Resolution12Bit = 1U , kADC12_Resolution10Bit = 2U }
 Converter's resolution. More...
 
enum  _adc12_clock_source { kADC12_ClockSourceAlt0 = 0U , kADC12_ClockSourceAlt1 = 1U , kADC12_ClockSourceAlt2 = 2U , kADC12_ClockSourceAlt3 = 3U }
 Conversion clock source. More...
 
enum  _adc12_reference_voltage_source { kADC12_ReferenceVoltageSourceVref = 0U , kADC12_ReferenceVoltageSourceValt = 1U }
 Reference voltage source. More...
 
enum  _adc12_hardware_average_mode {
  kADC12_HardwareAverageCount4 = 0U , kADC12_HardwareAverageCount8 = 1U , kADC12_HardwareAverageCount16 = 2U , kADC12_HardwareAverageCount32 = 3U ,
  kADC12_HardwareAverageDisabled = 4U
}
 Hardware average mode. More...
 
enum  _adc12_hardware_compare_mode { kADC12_HardwareCompareMode0 = 0U , kADC12_HardwareCompareMode1 = 1U , kADC12_HardwareCompareMode2 = 2U , kADC12_HardwareCompareMode3 = 3U }
 Hardware compare mode. More...
 

Variables

adc12_reference_voltage_source_t _adc12_config::referenceVoltageSource
 
adc12_clock_source_t _adc12_config::clockSource
 
adc12_clock_divider_t _adc12_config::clockDivider
 
adc12_resolution_t _adc12_config::resolution
 
uint32_t _adc12_config::sampleClockCount
 
bool _adc12_config::enableContinuousConversion
 
adc12_hardware_compare_mode_t _adc12_hardware_compare_config::hardwareCompareMode
 
int16_t _adc12_hardware_compare_config::value1
 
int16_t _adc12_hardware_compare_config::value2
 
uint32_t _adc12_channel_config::channelNumber
 
bool _adc12_channel_config::enableInterruptOnConversionCompleted
 

Initialization

void ADC12_Init (ADC_Type *base, const adc12_config_t *config)
 Initialize the ADC12 module.
 
void ADC12_Deinit (ADC_Type *base)
 De-initialize the ADC12 module.
 
void ADC12_GetDefaultConfig (adc12_config_t *config)
 Gets an available pre-defined settings for converter's configuration.
 

Basic Operations

void ADC12_SetChannelConfig (ADC_Type *base, uint32_t channelGroup, const adc12_channel_config_t *config)
 Configure the conversion channel.
 
static uint32_t ADC12_GetChannelConversionValue (ADC_Type *base, uint32_t channelGroup)
 Get the conversion value.
 
uint32_t ADC12_GetChannelStatusFlags (ADC_Type *base, uint32_t channelGroup)
 Get the status flags of channel.
 

Advanced Operations

status_t ADC12_DoAutoCalibration (ADC_Type *base)
 Automate the hardware calibration.
 
static void ADC12_SetOffsetValue (ADC_Type *base, uint32_t value)
 Set the offset value for the conversion result.
 
static void ADC12_SetGainValue (ADC_Type *base, uint32_t value)
 Set the gain value for the conversion result.
 
static void ADC12_EnableDMA (ADC_Type *base, bool enable)
 Enable generating the DMA trigger when conversion is completed.
 
static void ADC12_EnableHardwareTrigger (ADC_Type *base, bool enable)
 Enable of disable the hardware trigger mode.
 
void ADC12_SetHardwareCompareConfig (ADC_Type *base, const adc12_hardware_compare_config_t *config)
 Configure the hardware compare mode.
 
void ADC12_SetHardwareAverage (ADC_Type *base, adc12_hardware_average_mode_t mode)
 Set the hardware average mode.
 
uint32_t ADC12_GetStatusFlags (ADC_Type *base)
 Get the status flags of the converter.
 

Detailed Description

Typedef Documentation

◆ adc12_channel_config_t

Channel conversion configuration.

◆ adc12_clock_divider_t

Clock divider for the converter.

◆ adc12_clock_source_t

Conversion clock source.

◆ adc12_config_t

typedef struct _adc12_config adc12_config_t

Converter configuration.

◆ adc12_hardware_average_mode_t

Hardware average mode.

◆ adc12_hardware_compare_config_t

Hardware compare configuration.

◆ adc12_hardware_compare_mode_t

Hardware compare mode.

◆ adc12_reference_voltage_source_t

Reference voltage source.

◆ adc12_resolution_t

Converter's resolution.

Enumeration Type Documentation

◆ _adc12_channel_status_flags

Channel status flags' mask.

Enumerator
kADC12_ChannelConversionCompletedFlag 

Conversion done.

Definition at line 28 of file fsl_adc12.h.

29{
30 kADC12_ChannelConversionCompletedFlag = ADC_SC1_COCO_MASK, /*!< Conversion done. */
31};
@ kADC12_ChannelConversionCompletedFlag
Definition fsl_adc12.h:30

◆ _adc12_clock_divider

Clock divider for the converter.

Enumerator
kADC12_ClockDivider1 

For divider 1 from the input clock to the module.

kADC12_ClockDivider2 

For divider 2 from the input clock to the module.

kADC12_ClockDivider4 

For divider 4 from the input clock to the module.

kADC12_ClockDivider8 

For divider 8 from the input clock to the module.

Definition at line 45 of file fsl_adc12.h.

46{
47 kADC12_ClockDivider1 = 0U, /*!< For divider 1 from the input clock to the module. */
48 kADC12_ClockDivider2 = 1U, /*!< For divider 2 from the input clock to the module. */
49 kADC12_ClockDivider4 = 2U, /*!< For divider 4 from the input clock to the module. */
50 kADC12_ClockDivider8 = 3U, /*!< For divider 8 from the input clock to the module. */
enum _adc12_clock_divider adc12_clock_divider_t
Clock divider for the converter.
@ kADC12_ClockDivider2
Definition fsl_adc12.h:48
@ kADC12_ClockDivider1
Definition fsl_adc12.h:47
@ kADC12_ClockDivider4
Definition fsl_adc12.h:49
@ kADC12_ClockDivider8
Definition fsl_adc12.h:50

◆ _adc12_clock_source

Conversion clock source.

Enumerator
kADC12_ClockSourceAlt0 

Alternate clock 1 (ADC_ALTCLK1).

kADC12_ClockSourceAlt1 

Alternate clock 2 (ADC_ALTCLK2).

kADC12_ClockSourceAlt2 

Alternate clock 3 (ADC_ALTCLK3).

kADC12_ClockSourceAlt3 

Alternate clock 4 (ADC_ALTCLK4).

Definition at line 66 of file fsl_adc12.h.

67{
68 kADC12_ClockSourceAlt0 = 0U, /*!< Alternate clock 1 (ADC_ALTCLK1). */
69 kADC12_ClockSourceAlt1 = 1U, /*!< Alternate clock 2 (ADC_ALTCLK2). */
70 kADC12_ClockSourceAlt2 = 2U, /*!< Alternate clock 3 (ADC_ALTCLK3). */
71 kADC12_ClockSourceAlt3 = 3U, /*!< Alternate clock 4 (ADC_ALTCLK4). */
enum _adc12_clock_source adc12_clock_source_t
Conversion clock source.
@ kADC12_ClockSourceAlt1
Definition fsl_adc12.h:69
@ kADC12_ClockSourceAlt3
Definition fsl_adc12.h:71
@ kADC12_ClockSourceAlt2
Definition fsl_adc12.h:70
@ kADC12_ClockSourceAlt0
Definition fsl_adc12.h:68

◆ _adc12_hardware_average_mode

Hardware average mode.

Enumerator
kADC12_HardwareAverageCount4 

For hardware average with 4 samples.

kADC12_HardwareAverageCount8 

For hardware average with 8 samples.

kADC12_HardwareAverageCount16 

For hardware average with 16 samples.

kADC12_HardwareAverageCount32 

For hardware average with 32 samples.

kADC12_HardwareAverageDisabled 

Disable the hardware average feature.

Definition at line 86 of file fsl_adc12.h.

87{
88 kADC12_HardwareAverageCount4 = 0U, /*!< For hardware average with 4 samples. */
89 kADC12_HardwareAverageCount8 = 1U, /*!< For hardware average with 8 samples. */
90 kADC12_HardwareAverageCount16 = 2U, /*!< For hardware average with 16 samples. */
91 kADC12_HardwareAverageCount32 = 3U, /*!< For hardware average with 32 samples. */
92 kADC12_HardwareAverageDisabled = 4U, /*!< Disable the hardware average feature.*/
enum _adc12_hardware_average_mode adc12_hardware_average_mode_t
Hardware average mode.
@ kADC12_HardwareAverageDisabled
Definition fsl_adc12.h:92
@ kADC12_HardwareAverageCount32
Definition fsl_adc12.h:91
@ kADC12_HardwareAverageCount4
Definition fsl_adc12.h:88
@ kADC12_HardwareAverageCount16
Definition fsl_adc12.h:90
@ kADC12_HardwareAverageCount8
Definition fsl_adc12.h:89

◆ _adc12_hardware_compare_mode

Hardware compare mode.

Enumerator
kADC12_HardwareCompareMode0 

x < value1.

kADC12_HardwareCompareMode1 

x > value1.

kADC12_HardwareCompareMode2 

if value1 <= value2, then x < value1 || x > value2; else, value1 > x > value2.

kADC12_HardwareCompareMode3 

if value1 <= value2, then value1 <= x <= value2; else x >= value1 || x <= value2.

Definition at line 98 of file fsl_adc12.h.

99{
100 kADC12_HardwareCompareMode0 = 0U, /*!< x < value1. */
101 kADC12_HardwareCompareMode1 = 1U, /*!< x > value1. */
102 kADC12_HardwareCompareMode2 = 2U, /*!< if value1 <= value2, then x < value1 || x > value2;
103 else, value1 > x > value2. */
104 kADC12_HardwareCompareMode3 = 3U, /*!< if value1 <= value2, then value1 <= x <= value2;
105 else x >= value1 || x <= value2. */
enum _adc12_hardware_compare_mode adc12_hardware_compare_mode_t
Hardware compare mode.
@ kADC12_HardwareCompareMode0
Definition fsl_adc12.h:100
@ kADC12_HardwareCompareMode2
Definition fsl_adc12.h:102
@ kADC12_HardwareCompareMode3
Definition fsl_adc12.h:104
@ kADC12_HardwareCompareMode1
Definition fsl_adc12.h:101

◆ _adc12_reference_voltage_source

Reference voltage source.

Enumerator
kADC12_ReferenceVoltageSourceVref 

For external pins pair of VrefH and VrefL.

kADC12_ReferenceVoltageSourceValt 

For alternate reference pair of ValtH and ValtL.

Definition at line 77 of file fsl_adc12.h.

78{
79 kADC12_ReferenceVoltageSourceVref = 0U, /*!< For external pins pair of VrefH and VrefL. */
80 kADC12_ReferenceVoltageSourceValt = 1U, /*!< For alternate reference pair of ValtH and ValtL. */
enum _adc12_reference_voltage_source adc12_reference_voltage_source_t
Reference voltage source.
@ kADC12_ReferenceVoltageSourceVref
Definition fsl_adc12.h:79
@ kADC12_ReferenceVoltageSourceValt
Definition fsl_adc12.h:80

◆ _adc12_resolution

Converter's resolution.

Enumerator
kADC12_Resolution8Bit 

8 bit resolution.

kADC12_Resolution12Bit 

12 bit resolution.

kADC12_Resolution10Bit 

10 bit resolution.

Definition at line 56 of file fsl_adc12.h.

57{
58 kADC12_Resolution8Bit = 0U, /*!< 8 bit resolution. */
59 kADC12_Resolution12Bit = 1U, /*!< 12 bit resolution. */
60 kADC12_Resolution10Bit = 2U, /*!< 10 bit resolution. */
enum _adc12_resolution adc12_resolution_t
Converter's resolution.
@ kADC12_Resolution10Bit
Definition fsl_adc12.h:60
@ kADC12_Resolution8Bit
Definition fsl_adc12.h:58
@ kADC12_Resolution12Bit
Definition fsl_adc12.h:59

◆ _adc12_status_flags

Converter status flags' mask.

Enumerator
kADC12_ActiveFlag 

Converter is active.

kADC12_CalibrationFailedFlag 

Calibration is failed.

Definition at line 36 of file fsl_adc12.h.

37{
38 kADC12_ActiveFlag = ADC_SC2_ADACT_MASK, /*!< Converter is active. */
39 kADC12_CalibrationFailedFlag = (ADC_SC2_ADACT_MASK << 1U), /*!< Calibration is failed. */
40};
@ kADC12_CalibrationFailedFlag
Definition fsl_adc12.h:39
@ kADC12_ActiveFlag
Definition fsl_adc12.h:38

Function Documentation

◆ ADC12_Deinit()

void ADC12_Deinit ( ADC_Type *  base)

De-initialize the ADC12 module.

Parameters
baseADC12 peripheral base address.

brief De-initialize the ADC12 module.

param base ADC12 peripheral base address.

Definition at line 174 of file fsl_adc12.c.

175{
176#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
177 /* Disable the clock. */
179#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
180}
static uint32_t ADC12_GetInstance(ADC_Type *base)
Get instance number for ADC12 module.
Definition fsl_adc12.c:74
static const clock_ip_name_t s_adc12Clocks[]
Pointers to ADC12 clocks for each instance.
Definition fsl_adc12.c:68
static void CLOCK_DisableClock(clock_ip_name_t name)
Disable the clock for specific IP.
Definition fsl_clock.h:653

Referenced by adc_lld_stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC12_DoAutoCalibration()

status_t ADC12_DoAutoCalibration ( ADC_Type *  base)

Automate the hardware calibration.

This auto calibration helps to adjust the gain automatically according to the converter's working environment. Execute the calibration before conversion. Note that the software trigger should be used during calibration.

Note
The calibration function has bug in the SOC. The calibration failed flag may be set after calibration process even if you configure the ADC12 as the reference manual correctly. It is a known issue now and may be fixed in the future.
Parameters
baseADC12 peripheral base address.
Return values
kStatus_SuccessCalibration is done successfully.
kStatus_FailCalibration is failed.

brief Automate the hardware calibration.

This auto calibration helps to adjust the gain automatically according to the converter's working environment. Execute the calibration before conversion. Note that the software trigger should be used during calibration.

note The calibration function has bug in the SOC. The calibration failed flag may be set after calibration process even if you configure the ADC12 as the reference manual correctly. It is a known issue now and may be fixed in the future.

param base ADC12 peripheral base address. retval kStatus_Success Calibration is done successfully. retval kStatus_Fail Calibration is failed.

Definition at line 292 of file fsl_adc12.c.

293{
294 bool enabledHardwareTrigger = false;
295 bool enabledHardwareAverage = false;
296 uint32_t averageMode;
297 uint32_t tmp32;
298 uint32_t saveCFG1;
300
301 /* Save current clock divider. */
302 saveCFG1 = base->CFG1;
303 /* Set ADCK (ADC clock) to half the maximum specified frequency for calibration. */
304 base->CFG1 |= ADC_CFG1_ADIV(1);
305
306 /* Save current trigger mode. Then set to software trigger mode. */
307 tmp32 = base->SC2;
308 if (ADC_SC2_ADTRG_MASK == (tmp32 & ADC_SC2_ADTRG_MASK))
309 {
310 enabledHardwareTrigger = true;
311 tmp32 &= ~ADC_SC2_ADTRG_MASK;
312 base->SC2 = tmp32;
313 }
314 /* Save current average mode. Then enable hardware average and set average number to be maximum value. */
315 tmp32 = base->SC3;
316 averageMode = ((tmp32 & ADC_SC3_AVGS_MASK) >> ADC_SC3_AVGS_SHIFT);
317 if (ADC_SC3_AVGE_MASK == (tmp32 & ADC_SC3_AVGE_MASK))
318 {
319 enabledHardwareAverage = true;
320 }
321 tmp32 &= ~ADC_SC3_AVGS_MASK;
322 tmp32 |= (ADC_SC3_AVGE_MASK | ADC_SC3_AVGS(ADC_SC3_AVGS_MASK >> ADC_SC3_AVGS_SHIFT));
323
324 /* Trigger calibration and wait until it complete. */
325 tmp32 |= ADC_SC3_CAL_MASK;
326 base->SC3 = tmp32;
329 {
330 }
331
333 {
334 error = kStatus_Fail;
335 }
336 /* Clear conversion done flag. */
338
339 /* Restore original trigger mode. */
340 if (true == enabledHardwareTrigger)
341 {
342 base->SC2 |= ADC_SC2_ADTRG_MASK;
343 }
344 /* Restore original average mode. */
345 tmp32 = base->SC3;
346 if (false == enabledHardwareAverage)
347 {
348 tmp32 &= ~ADC_SC3_AVGE_MASK;
349 }
350 tmp32 |= ADC_SC3_AVGS(averageMode);
351 base->SC3 = tmp32;
352
353 /* Restore adc clock divider. */
354 base->CFG1 = saveCFG1;
355
356 return error;
357}
uint32_t ADC12_GetChannelStatusFlags(ADC_Type *base, uint32_t channelGroup)
Get the status flags of channel.
Definition fsl_adc12.c:262
uint32_t ADC12_GetStatusFlags(ADC_Type *base)
Get the status flags of the converter.
Definition fsl_adc12.c:445
static uint32_t ADC12_GetChannelConversionValue(ADC_Type *base, uint32_t channelGroup)
Get the conversion value.
Definition fsl_adc12.h:228
int32_t status_t
Type used for all status and error return values.
Definition fsl_common.h:169
@ kStatus_Success
Definition fsl_common.h:159
@ kStatus_Fail
Definition fsl_common.h:160

Referenced by calibrate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC12_EnableDMA()

static void ADC12_EnableDMA ( ADC_Type *  base,
bool  enable 
)
inlinestatic

Enable generating the DMA trigger when conversion is completed.

Parameters
baseADC12 peripheral base address.
enableSwitcher of DMA feature. "true" means to enable, "false" means to disable.

Definition at line 303 of file fsl_adc12.h.

304{
305 if (enable)
306 {
307 base->SC2 |= ADC_SC2_DMAEN_MASK;
308 }
309 else
310 {
311 base->SC2 &= ~ADC_SC2_DMAEN_MASK;
312 }
313}
static void enable(const char *param)
Definition settings.cpp:441
Here is the call graph for this function:

◆ ADC12_EnableHardwareTrigger()

static void ADC12_EnableHardwareTrigger ( ADC_Type *  base,
bool  enable 
)
inlinestatic

Enable of disable the hardware trigger mode.

Parameters
baseADC12 peripheral base address.
enableSwitcher of hardware trigger feature. "true" means to enable, "false" means not.

Definition at line 322 of file fsl_adc12.h.

323{
324 if (enable)
325 {
326 base->SC2 |= ADC_SC2_ADTRG_MASK;
327 }
328 else
329 {
330 base->SC2 &= ~ADC_SC2_ADTRG_MASK;
331 }
332}

Referenced by adc_lld_start_conversion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC12_GetChannelConversionValue()

static uint32_t ADC12_GetChannelConversionValue ( ADC_Type *  base,
uint32_t  channelGroup 
)
inlinestatic

Get the conversion value.

Parameters
baseADC12 peripheral base address.
channelGroupChannel group index.
Returns
Conversion value.

Definition at line 228 of file fsl_adc12.h.

229{
230 assert(channelGroup < ADC_R_COUNT);
231
232 return base->R[channelGroup];
233}

Referenced by ADC12_DoAutoCalibration(), and adc_lld_irq_handler().

Here is the caller graph for this function:

◆ ADC12_GetChannelStatusFlags()

uint32_t ADC12_GetChannelStatusFlags ( ADC_Type *  base,
uint32_t  channelGroup 
)

Get the status flags of channel.

Parameters
baseADC12 peripheral base address.
channelGroupChannel group index.
Returns
Flags' mask if indicated flags are asserted. See to "_adc12_channel_status_flags".

brief Get the status flags of channel.

param base ADC12 peripheral base address. param channelGroup Channel group index.

return Flags' mask if indicated flags are asserted. See to "_adc12_channel_status_flags".

Definition at line 262 of file fsl_adc12.c.

263{
264 assert(channelGroup < ADC_SC1_COUNT);
265
266 uint32_t tmp32 = base->SC1[channelGroup];
267 uint32_t result = 0U;
268
269 /* ADCx_SC1n. */
270 if (ADC_SC1_COCO_MASK == (tmp32 & ADC_SC1_COCO_MASK))
271 {
273 }
274
275 return result;
276}

Referenced by ADC12_DoAutoCalibration().

Here is the caller graph for this function:

◆ ADC12_GetDefaultConfig()

void ADC12_GetDefaultConfig ( adc12_config_t config)

Gets an available pre-defined settings for converter's configuration.

This function initializes the converter configuration structure with an available settings. The default values are:

Example:

config->referenceVoltageSource = kADC12_ReferenceVoltageSourceVref;
config->clockDivider = kADC12_ClockDivider1;
config->sampleClockCount = 12U;
config->enableContinuousConversion = false;
static constexpr persistent_config_s * config
Parameters
configPointer to "adc12_config_t" structure.

brief Gets an available pre-defined settings for converter's configuration.

This function initializes the converter configuration structure with an available settings. The default values are:

Example: code config->referenceVoltageSource = kADC12_ReferenceVoltageSourceVref; config->clockSource = kADC12_ClockSourceAlt0; config->clockDivider = kADC12_ClockDivider1; config->resolution = kADC12_Resolution8Bit; config->sampleClockCount = 12U; config->enableContinuousConversion = false; endcode param config Pointer to "adc12_config_t" structure.

Definition at line 198 of file fsl_adc12.c.

199{
200 assert(config);
201
202 /* Initializes the configure structure to zero. */
203 memset(config, 0, sizeof(*config));
204
205 config->referenceVoltageSource = kADC12_ReferenceVoltageSourceVref;
206 config->clockSource = kADC12_ClockSourceAlt0;
207 config->clockDivider = kADC12_ClockDivider1;
208 config->resolution = kADC12_Resolution8Bit;
209 config->sampleClockCount = 13U;
210 config->enableContinuousConversion = false;
211}

Referenced by adc_lld_start().

Here is the caller graph for this function:

◆ ADC12_GetStatusFlags()

uint32_t ADC12_GetStatusFlags ( ADC_Type *  base)

Get the status flags of the converter.

Parameters
baseADC12 peripheral base address.
Returns
Flags' mask if indicated flags are asserted. See to "_adc12_status_flags".

brief Get the status flags of the converter.

param base ADC12 peripheral base address.

return Flags' mask if indicated flags are asserted. See to "_adc12_status_flags".

Definition at line 445 of file fsl_adc12.c.

446{
447 uint32_t result = 0;
448
449 /* ADCx_SC2. */
450 if (ADC_SC2_ADACT_MASK == (base->SC2 & ADC_SC2_ADACT_MASK))
451 {
452 result |= kADC12_ActiveFlag;
453 }
454
456 {
458 }
459
460 return result;
461}
static status_t ADC12_GetCalibrationStatus(ADC_Type *base)
Check calibration failed status.
Definition fsl_adc12.c:92

Referenced by ADC12_DoAutoCalibration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC12_Init()

void ADC12_Init ( ADC_Type *  base,
const adc12_config_t config 
)

Initialize the ADC12 module.

Parameters
baseADC12 peripheral base address.
configPointer to "adc12_config_t" structure.

brief Initialize the ADC12 module.

param base ADC12 peripheral base address. param config Pointer to "adc12_config_t" structure.

Definition at line 133 of file fsl_adc12.c.

134{
135 assert(config);
136
137 uint32_t tmp32;
138
139#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
140 /* Enable the clock. */
142#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
143
144 /* ADCx_CFG1. */
145 tmp32 = (base->CFG1 & ~(ADC_CFG1_ADICLK_MASK | ADC_CFG1_ADIV_MASK | ADC_CFG1_MODE_MASK));
146 tmp32 |= (ADC_CFG1_ADICLK(config->clockSource) | ADC_CFG1_ADIV(config->clockDivider) |
147 ADC_CFG1_MODE(config->resolution));
148 base->CFG1 = tmp32;
149
150 /* ADCx_CFG2. */
151 tmp32 = (base->CFG2 & ~ADC_CFG2_SMPLTS_MASK);
152 tmp32 |= ADC_CFG2_SMPLTS(config->sampleClockCount - 1U);
153 base->CFG2 = tmp32;
154
155 /* ADCx_SC2. */
156 tmp32 = (base->SC2 & ~ADC_SC2_REFSEL_MASK);
157 tmp32 |= ADC_SC2_REFSEL(config->referenceVoltageSource);
158 base->SC2 = tmp32;
159
160 /* ADCx_SC3. */
161 tmp32 = (base->SC3 & ~ADC_SC3_ADCO_MASK);
162 if (true == config->enableContinuousConversion)
163 {
164 tmp32 |= ADC_SC3_ADCO_MASK;
165 }
166 base->SC3 = tmp32;
167}
static void CLOCK_EnableClock(clock_ip_name_t name)
Enable the clock for specific IP.
Definition fsl_clock.h:641

Referenced by adc_lld_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ADC12_SetChannelConfig()

void ADC12_SetChannelConfig ( ADC_Type *  base,
uint32_t  channelGroup,
const adc12_channel_config_t config 
)

Configure the conversion channel.

This operation triggers the conversion in software trigger mode. In hardware trigger mode, this API configures the channel while the external trigger source helps to trigger the conversion.

Note that the "Channel Group" has a detailed description. To allow sequential conversions of the ADC to be triggered by internal peripherals, the ADC can have more than one group of status and control register, one for each conversion. The channel group parameter indicates which group of registers are used, channel group 0 is for Group A registers and channel group 1 is for Group B registers. The channel groups are used in a "ping-pong" approach to control the ADC operation. At any time, only one of the channel groups is actively controlling ADC conversions. Channel group 0 is used for both software and hardware trigger modes of operation. Channel groups 1 and greater indicate potentially multiple channel group registers for use only in hardware trigger mode. See the chip configuration information in the MCU reference manual about the number of SC1n registers (channel groups) specific to this device. None of the channel groups 1 or greater are used for software trigger operation and therefore writes to these channel groups do not initiate a new conversion. Updating channel group 0 while a different channel group is actively controlling a conversion is allowed and vice versa. Writing any of the channel group registers while that specific channel group is actively controlling a conversion aborts the current conversion.

Parameters
baseADC12 peripheral base address.
channelGroupChannel group index.
configPointer to "adc12_channel_config_t" structure.

brief Configure the conversion channel.

This operation triggers the conversion in software trigger mode. In hardware trigger mode, this API configures the channel while the external trigger source helps to trigger the conversion.

Note that the "Channel Group" has a detailed description. To allow sequential conversions of the ADC to be triggered by internal peripherals, the ADC can have more than one group of status and control register, one for each conversion. The channel group parameter indicates which group of registers are used, channel group 0 is for Group A registers and channel group 1 is for Group B registers. The channel groups are used in a "ping-pong" approach to control the ADC operation. At any time, only one of the channel groups is actively controlling ADC conversions. Channel group 0 is used for both software and hardware trigger modes of operation. Channel groups 1 and greater indicate potentially multiple channel group registers for use only in hardware trigger mode. See the chip configuration information in the MCU reference manual about the number of SC1n registers (channel groups) specific to this device. None of the channel groups 1 or greater are used for software trigger operation and therefore writes to these channel groups do not initiate a new conversion. Updating channel group 0 while a different channel group is actively controlling a conversion is allowed and vice versa. Writing any of the channel group registers while that specific channel group is actively controlling a conversion aborts the current conversion.

param base ADC12 peripheral base address. param channelGroup Channel group index. param config Pointer to "adc12_channel_config_t" structure.

Definition at line 237 of file fsl_adc12.c.

238{
239 assert(channelGroup < ADC_SC1_COUNT);
240 assert(config);
241
242 uint32_t tmp32;
243
244 /* ADCx_SC1n. */
245 tmp32 = (base->SC1[channelGroup] & ~(ADC_SC1_ADCH_MASK | ADC_SC1_AIEN_MASK));
246 tmp32 |= ADC_SC1_ADCH(config->channelNumber);
247 if (true == config->enableInterruptOnConversionCompleted)
248 {
249 tmp32 |= ADC_SC1_AIEN_MASK;
250 }
251 base->SC1[channelGroup] = tmp32;
252}

Referenced by adc_lld_irq_handler(), and adc_lld_start_conversion().

Here is the caller graph for this function:

◆ ADC12_SetGainValue()

static void ADC12_SetGainValue ( ADC_Type *  base,
uint32_t  value 
)
inlinestatic

Set the gain value for the conversion result.

This gain value takes effect on the conversion result. If the gain value is not zero, the conversion result is amplified as it.

Parameters
baseADC12 peripheral base address.
valueGain value.

Definition at line 291 of file fsl_adc12.h.

292{
293 base->UG = (value & ADC_UG_UG_MASK);
294}

◆ ADC12_SetHardwareAverage()

void ADC12_SetHardwareAverage ( ADC_Type *  base,
adc12_hardware_average_mode_t  mode 
)

Set the hardware average mode.

Hardware average mode provides a way to process the conversion result automatically by hardware. The multiple conversion results are accumulated and averaged internally. This aids to get more accurate conversion result.

Parameters
baseADC12 peripheral base address.
modeSetting hardware average mode. See to "adc12_hardware_average_mode_t".

brief Set the hardware average mode.

Hardware average mode provides a way to process the conversion result automatically by hardware. The multiple conversion results are accumulated and averaged internally. This aids to get more accurate conversion result.

param base ADC12 peripheral base address. param mode Setting hardware average mode. See to "adc12_hardware_average_mode_t".

Definition at line 416 of file fsl_adc12.c.

417{
418 uint32_t tmp32 = base->SC3;
419
420 /* ADCx_SC3. */
421 tmp32 &= ~(ADC_SC3_AVGS_MASK | ADC_SC3_AVGE_MASK);
422 switch (mode)
423 {
428 tmp32 |= (ADC_SC3_AVGS(mode) | ADC_SC3_AVGE_MASK);
429 break;
431 break;
432 default:
433 break;
434 }
435 base->SC3 = tmp32;
436}

◆ ADC12_SetHardwareCompareConfig()

void ADC12_SetHardwareCompareConfig ( ADC_Type *  base,
const adc12_hardware_compare_config_t config 
)

Configure the hardware compare mode.

The hardware compare mode provides a way to process the conversion result automatically by hardware. Only the result in compare range is available. To compare the range, see "adc12_hardware_compare_mode_t", or the reference manual document for more detailed information.

Parameters
baseADC12 peripheral base address.
configPointer to "adc12_hardware_compare_config_t" structure. Pass "NULL" to disable the feature.

brief Configure the hardware compare mode.

The hardware compare mode provides a way to process the conversion result automatically by hardware. Only the result in compare range is available. To compare the range, see "adc12_hardware_compare_mode_t", or the reference manual document for more detailed information.

param base ADC12 peripheral base address. param config Pointer to "adc12_hardware_compare_config_t" structure. Pass "NULL" to disable the feature.

Definition at line 369 of file fsl_adc12.c.

370{
371 uint32_t tmp32;
372
373 /* Disable hardware compare. */
374 if (NULL == config)
375 {
376 base->SC2 &= ~(ADC_SC2_ACFE_MASK | ADC_SC2_ACFGT_MASK | ADC_SC2_ACREN_MASK);
377 }
378 else
379 {
380 /* Set the compare mode. */
381 tmp32 = (base->SC2 & ~(ADC_SC2_ACFE_MASK | ADC_SC2_ACFGT_MASK | ADC_SC2_ACREN_MASK));
382 switch (config->hardwareCompareMode)
383 {
385 break;
387 tmp32 |= ADC_SC2_ACFGT_MASK;
388 break;
390 tmp32 |= ADC_SC2_ACREN_MASK;
391 break;
393 tmp32 |= (ADC_SC2_ACFGT_MASK | ADC_SC2_ACREN_MASK);
394 break;
395 default:
396 break;
397 }
398 tmp32 |= ADC_SC2_ACFE_MASK;
399 base->SC2 = tmp32;
400
401 /* Set the compare value. */
402 base->CV1 = config->value1;
403 base->CV2 = config->value2;
404 }
405}

◆ ADC12_SetOffsetValue()

static void ADC12_SetOffsetValue ( ADC_Type *  base,
uint32_t  value 
)
inlinestatic

Set the offset value for the conversion result.

This offset value takes effect on the conversion result. If the offset value is not zero, the conversion result is substracted by it.

Parameters
baseADC12 peripheral base address.
valueOffset value.

Definition at line 277 of file fsl_adc12.h.

278{
279 base->USR_OFS = (value & ADC_USR_OFS_USR_OFS_MASK);
280}

Variable Documentation

◆ channelNumber

uint32_t _adc12_channel_config::channelNumber

Setting the conversion channel number. The available range is 0-31. See channel connection information for each chip in Reference Manual document.

Definition at line 137 of file fsl_adc12.h.

◆ clockDivider

adc12_clock_divider_t _adc12_config::clockDivider

Select the divider of input clock source.

Definition at line 115 of file fsl_adc12.h.

◆ clockSource

adc12_clock_source_t _adc12_config::clockSource

Select the input clock source to converter.

Definition at line 114 of file fsl_adc12.h.

◆ enableContinuousConversion

bool _adc12_config::enableContinuousConversion

Enable continuous conversion mode.

Definition at line 119 of file fsl_adc12.h.

◆ enableInterruptOnConversionCompleted

bool _adc12_channel_config::enableInterruptOnConversionCompleted

Generate a interrupt request once the conversion is completed.

Definition at line 140 of file fsl_adc12.h.

◆ hardwareCompareMode

adc12_hardware_compare_mode_t _adc12_hardware_compare_config::hardwareCompareMode

Select the hardware compare mode.

Definition at line 127 of file fsl_adc12.h.

◆ referenceVoltageSource

adc12_reference_voltage_source_t _adc12_config::referenceVoltageSource

Select the reference voltage source.

Definition at line 113 of file fsl_adc12.h.

◆ resolution

adc12_resolution_t _adc12_config::resolution

Select the sample resolution mode.

Definition at line 116 of file fsl_adc12.h.

◆ sampleClockCount

uint32_t _adc12_config::sampleClockCount

Select the sample clock count. Add its value may improve the stability of the conversion result.

Definition at line 117 of file fsl_adc12.h.

◆ value1

int16_t _adc12_hardware_compare_config::value1

Setting value1 for hardware compare mode.

Definition at line 128 of file fsl_adc12.h.

◆ value2

int16_t _adc12_hardware_compare_config::value2

Setting value2 for hardware compare mode.

Definition at line 129 of file fsl_adc12.h.