Skip to content
Permalink
Browse files

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>
  • Loading branch information...
pabigot authored and nashif committed Apr 26, 2019
1 parent a9c99a6 commit d6c61513a5b3f54ad9c9dd85e186354cc25339c9
Showing with 30 additions and 5 deletions.
  1. +20 −5 drivers/adc/adc_nrfx_saadc.c
  2. +10 −0 include/adc.h
@@ -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,
@@ -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;
};


0 comments on commit d6c6151

Please sign in to comment.
You can’t perform that action at this time.