diff --git a/drivers/adc/Kconfig.mcux b/drivers/adc/Kconfig.mcux index a7a714b8284..6137652ce64 100644 --- a/drivers/adc/Kconfig.mcux +++ b/drivers/adc/Kconfig.mcux @@ -11,3 +11,37 @@ config ADC_MCUX_ADC16 depends on HAS_MCUX_ADC16 help Enable the MCUX ADC16 driver. + +if ADC_MCUX_ADC16 + +choice + prompt "Clock Divide Selection" + default ADC_MCUX_ADC16_CLK_DIV_RATIO_1 + +config ADC_MCUX_ADC16_CLK_DIV_RATIO_1 + bool "Divide ratio is 1" + +config ADC_MCUX_ADC16_CLK_DIV_RATIO_2 + bool "Divide ratio is 2" + +config ADC_MCUX_ADC16_CLK_DIV_RATIO_4 + bool "Divide ratio is 4" + +config ADC_MCUX_ADC16_CLK_DIV_RATIO_8 + bool "Divide ratio is 8" + +endchoice + +choice + prompt "Voltage Reference Selection" + default ADC_MCUX_ADC16_VREF_DEFAULT + +config ADC_MCUX_ADC16_VREF_DEFAULT + bool "Default voltage reference pair V_REFH and V_REFL" + +config ADC_MCUX_ADC16_VREF_ALTERNATE + bool "Alternate reference pair" + +endchoice + +endif # ADC_MCUX_ADC16 diff --git a/drivers/adc/adc_mcux_adc16.c b/drivers/adc/adc_mcux_adc16.c index 0ff461428db..6bab12e01f2 100644 --- a/drivers/adc/adc_mcux_adc16.c +++ b/drivers/adc/adc_mcux_adc16.c @@ -199,7 +199,29 @@ static int mcux_adc16_init(struct device *dev) adc16_config_t adc_config; ADC16_GetDefaultConfig(&adc_config); + +#if CONFIG_ADC_MCUX_ADC16_VREF_DEFAULT + adc_config.referenceVoltageSource = kADC16_ReferenceVoltageSourceVref; +#else /* CONFIG_ADC_MCUX_ADC16_VREF_ALTERNATE */ + adc_config.referenceVoltageSource = kADC16_ReferenceVoltageSourceValt; +#endif + +#if CONFIG_ADC_MCUX_ADC16_CLK_DIV_RATIO_1 + adc_config.clockDivider = kADC16_ClockDivider1; +#elif CONFIG_ADC_MCUX_ADC16_CLK_DIV_RATIO_2 + adc_config.clockDivider = kADC16_ClockDivider2; +#elif CONFIG_ADC_MCUX_ADC16_CLK_DIV_RATIO_4 + adc_config.clockDivider = kADC16_ClockDivider4; +#else /* CONFIG_ADC_MCUX_ADC16_CLK_DIV_RATIO_8 */ + adc_config.clockDivider = kADC16_ClockDivider8; +#endif + ADC16_Init(base, &adc_config); +#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && \ + FSL_FEATURE_ADC16_HAS_CALIBRATION + ADC16_SetHardwareAverage(base, kADC16_HardwareAverageCount32); + ADC16_DoAutoCalibration(base); +#endif ADC16_EnableHardwareTrigger(base, false);