Skip to content

Commit 616ec75

Browse files
ananglkartben
authored andcommitted
drivers: adc_nrfx_saadc: Remove dead and misleading code
For a long time (since version 3.3.0) nrfx contained an incorrectly defined symbol NRF_SAADC_8BIT_SAMPLE_WIDTH that was set to 8 for nRF54L and nRF54H Series SoCs, which was probably only true for very early engineering revisions of those. Based on this, the adc_nrfx_saadc driver was incorrectly writing consecutive 8-bit samples in supplied buffers, cutting off the highest 8 bits of the results. And for sequences with multiple channels, it was even causing that the results written as 16-bit words by hardware were partially overwritten in next iteration. In nrfx 3.12.0 (see commit f46798f) this was finally corrected - the symbol is now deprecated and it is always set to 16. This commit is a follow-up to the above and removes parts of adc_nrfx_saadc that now became dead code to prevent further confusion regarding 8-bit sampling. Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
1 parent f089959 commit 616ec75

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

drivers/adc/adc_nrfx_saadc.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,8 @@ static struct driver_data m_data = {
141141
};
142142

143143
/* Helper function to convert number of samples to the byte representation. */
144-
static uint32_t samples_to_bytes(const struct adc_sequence *sequence, uint16_t number_of_samples)
144+
static uint32_t samples_to_bytes(uint16_t number_of_samples)
145145
{
146-
if (NRF_SAADC_8BIT_SAMPLE_WIDTH == 8 && sequence->resolution == 8) {
147-
return number_of_samples;
148-
}
149-
150146
return number_of_samples * 2;
151147
}
152148

@@ -410,11 +406,11 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx,
410406
if (!repeat) {
411407
#if defined(ADC_BUFFER_IN_RAM)
412408
m_data.user_buffer = (uint8_t *)m_data.user_buffer +
413-
samples_to_bytes(&ctx->sequence, nrfy_saadc_amount_get(NRF_SAADC));
409+
samples_to_bytes(nrfy_saadc_amount_get(NRF_SAADC));
414410
#else
415411
nrf_saadc_value_t *buffer =
416412
(uint8_t *)nrf_saadc_buffer_pointer_get(NRF_SAADC) +
417-
samples_to_bytes(&ctx->sequence, nrfy_saadc_amount_get(NRF_SAADC));
413+
samples_to_bytes(nrfy_saadc_amount_get(NRF_SAADC));
418414
nrfy_saadc_buffer_pointer_set(NRF_SAADC, buffer);
419415
#endif
420416
}
@@ -501,7 +497,7 @@ static int check_buffer_size(const struct adc_sequence *sequence,
501497
{
502498
size_t needed_buffer_size;
503499

504-
needed_buffer_size = samples_to_bytes(sequence, active_channels);
500+
needed_buffer_size = samples_to_bytes(active_channels);
505501

506502
if (sequence->options) {
507503
needed_buffer_size *= (1 + sequence->options->extra_samplings);
@@ -546,7 +542,6 @@ static int start_read(const struct device *dev,
546542
{
547543
int error;
548544
uint32_t selected_channels = sequence->channels;
549-
uint8_t resolution = sequence->resolution;
550545
uint8_t active_channels;
551546
uint8_t channel_id;
552547
nrf_saadc_burst_t burst;
@@ -576,22 +571,6 @@ static int start_read(const struct device *dev,
576571
channel_id);
577572
return -EINVAL;
578573
}
579-
/* Signal an error if the channel is configured as
580-
* single ended with a resolution which is identical
581-
* to the sample bit size. The SAADC's "single ended"
582-
* mode is really differential mode with the
583-
* negative input tied to ground. We can therefore
584-
* observe negative values if the positive input falls
585-
* below ground. If the sample bitsize is larger than
586-
* the resolution, we can detect negative values and
587-
* correct them to 0 after the sequencen has ended.
588-
*/
589-
if ((m_data.single_ended_channels & BIT(channel_id)) &&
590-
(NRF_SAADC_8BIT_SAMPLE_WIDTH == 8 && resolution == 8)) {
591-
LOG_ERR("Channel %u invalid single ended resolution",
592-
channel_id);
593-
return -EINVAL;
594-
}
595574
/* When oversampling is used, the burst mode needs to
596575
* be activated. Unfortunately, this mode cannot be
597576
* activated permanently in the channel setup, because
@@ -713,7 +692,7 @@ static void saadc_irq_handler(const struct device *dev)
713692

714693
#if defined(ADC_BUFFER_IN_RAM)
715694
memcpy(m_data.user_buffer, m_data.samples_buffer,
716-
samples_to_bytes(&m_data.ctx.sequence, m_data.active_channels));
695+
samples_to_bytes(m_data.active_channels));
717696
#endif
718697

719698
adc_context_on_sampling_done(&m_data.ctx, dev);

0 commit comments

Comments
 (0)