drivers: adc: add API to support calibration

Add a flag to the sequence structure that tells the driver it should
calibrate the ADC prior to initiating the sample.

Implement this for nRF SAADC.  The implementation supports the
workarounds for PAN-86 and PAN-178.

Relates-to: issue #11922
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2019-04-26 12:15:42 -05:00 committed by Anas Nashif
parent a9c99a60f0
commit d6c61513a5
2 changed files with 30 additions and 5 deletions

View file

@ -130,12 +130,14 @@ static int adc_nrfx_channel_setup(struct device *dev,
static void adc_context_start_sampling(struct adc_context *ctx)
{
ARG_UNUSED(ctx);
nrf_saadc_enable();
nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);
if (ctx->sequence.calibrate) {
nrf_saadc_task_trigger(NRF_SAADC_TASK_CALIBRATEOFFSET);
} else {
nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);
}
}
static void adc_context_update_buffer_pointer(struct adc_context *ctx,
@ -365,6 +367,17 @@ static void saadc_irq_handler(void *param)
nrf_saadc_disable();
adc_context_on_sampling_done(&m_data.ctx, dev);
} else if (nrf_saadc_event_check(NRF_SAADC_EVENT_CALIBRATEDONE)) {
nrf_saadc_event_clear(NRF_SAADC_EVENT_CALIBRATEDONE);
/*
* The workaround for Nordic nRF52832 anomalies 86 and
* 178 is an explicit STOP after CALIBRATEOFFSET
* before issuing START.
*/
nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP);
nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);
}
}
@ -373,7 +386,9 @@ DEVICE_DECLARE(adc_0);
static int init_saadc(struct device *dev)
{
nrf_saadc_event_clear(NRF_SAADC_EVENT_END);
nrf_saadc_int_enable(NRF_SAADC_INT_END);
nrf_saadc_event_clear(NRF_SAADC_EVENT_CALIBRATEDONE);
nrf_saadc_int_enable(NRF_SAADC_INT_END
| NRF_SAADC_INT_CALIBRATEDONE);
NRFX_IRQ_ENABLE(DT_NORDIC_NRF_SAADC_ADC_0_IRQ);
IRQ_CONNECT(DT_NORDIC_NRF_SAADC_ADC_0_IRQ,

View file

@ -253,6 +253,16 @@ struct adc_sequence {
* a specific mode (e.g. when sampling multiple channels).
*/
u8_t oversampling;
/**
* Perform calibration before the reading is taken if requested.
*
* The impact of channel configuration on the calibration
* process is specific to the underlying hardware. ADC
* implementations that do not support calibration should
* ignore this flag.
*/
bool calibrate;
};