Skip to content

Commit 60ad0db

Browse files
mstasiaknordicmasz-nordic
authored andcommitted
[nrf fromlist] drivers: adc: nrfx_saadc: align to errno codes in nrfx
NRFX drivers now return errno codes, aligned driver. Upstream PR #: 99399 Signed-off-by: Michał Stasiak <[email protected]>
1 parent c956709 commit 60ad0db

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

drivers/adc/adc_nrfx_saadc.c

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ static int adc_nrfx_channel_setup(const struct device *dev,
273273
m_data.divide_single_ended_value &= ~BIT(channel_cfg->channel_id);
274274
}
275275

276-
nrfx_err_t ret = nrfx_saadc_channel_config(&cfg);
276+
err = nrfx_saadc_channel_config(&cfg);
277277

278-
if (ret != NRFX_SUCCESS) {
279-
LOG_ERR("Cannot configure channel %d: 0x%08x", channel_cfg->channel_id, ret);
280-
return -EINVAL;
278+
if (err != 0) {
279+
LOG_ERR("Cannot configure channel %d: %d", channel_cfg->channel_id, err);
280+
return err;
281281
}
282282

283283
return 0;
@@ -288,10 +288,10 @@ static void adc_context_start_sampling(struct adc_context *ctx)
288288
if (ctx->sequence.calibrate) {
289289
nrfx_saadc_offset_calibrate(event_handler);
290290
} else {
291-
nrfx_err_t ret = nrfx_saadc_mode_trigger();
291+
int ret = nrfx_saadc_mode_trigger();
292292

293-
if (ret != NRFX_SUCCESS) {
294-
LOG_ERR("Cannot start sampling: 0x%08x", ret);
293+
if (ret != 0) {
294+
LOG_ERR("Cannot start sampling: %d", ret);
295295
adc_context_complete(ctx, -EIO);
296296
}
297297
}
@@ -316,10 +316,9 @@ static void adc_context_update_buffer_pointer(struct adc_context *ctx, bool repe
316316
return;
317317
}
318318

319-
nrfx_err_t nrfx_err =
320-
nrfx_saadc_buffer_set(samples_buffer, m_data.active_channel_cnt);
321-
if (nrfx_err != NRFX_SUCCESS) {
322-
LOG_ERR("Failed to set buffer: 0x%08x", nrfx_err);
319+
error = nrfx_saadc_buffer_set(samples_buffer, m_data.active_channel_cnt);
320+
if (error != 0) {
321+
LOG_ERR("Failed to set buffer: %d", error);
323322
adc_context_complete(ctx, -EIO);
324323
}
325324
}
@@ -330,10 +329,10 @@ static inline void adc_context_enable_timer(struct adc_context *ctx)
330329
if (!m_data.internal_timer_enabled) {
331330
k_timer_start(&m_data.timer, K_NO_WAIT, K_USEC(ctx->options.interval_us));
332331
} else {
333-
nrfx_err_t ret = nrfx_saadc_mode_trigger();
332+
int ret = nrfx_saadc_mode_trigger();
334333

335-
if (ret != NRFX_SUCCESS) {
336-
LOG_ERR("Cannot start sampling: 0x%08x", ret);
334+
if (ret != 0) {
335+
LOG_ERR("Cannot start sampling: %d", ret);
337336
adc_context_complete(&m_data.ctx, -EIO);
338337
}
339338
}
@@ -503,7 +502,6 @@ static inline uint16_t interval_to_cc(uint16_t interval_us)
503502
static int start_read(const struct device *dev,
504503
const struct adc_sequence *sequence)
505504
{
506-
nrfx_err_t nrfx_err;
507505
int error;
508506
uint32_t selected_channels = sequence->channels;
509507
nrf_saadc_resolution_t resolution;
@@ -561,21 +559,21 @@ static int start_read(const struct device *dev,
561559

562560
m_data.internal_timer_enabled = true;
563561

564-
nrfx_err = nrfx_saadc_advanced_mode_set(selected_channels, resolution, &adv_config,
565-
event_handler);
562+
error = nrfx_saadc_advanced_mode_set(selected_channels, resolution, &adv_config,
563+
event_handler);
566564
} else {
567565
m_data.internal_timer_enabled = false;
568566

569-
nrfx_err = nrfx_saadc_simple_mode_set(selected_channels, resolution, oversampling,
570-
event_handler);
567+
error = nrfx_saadc_simple_mode_set(selected_channels, resolution, oversampling,
568+
event_handler);
571569
}
572570

573-
if (nrfx_err != NRFX_SUCCESS) {
574-
return -EINVAL;
571+
if (error != 0) {
572+
return error;
575573
}
576574

577575
error = check_buffer_size(sequence, active_channel_cnt);
578-
if (error) {
576+
if (error != 0) {
579577
return error;
580578
}
581579

@@ -596,14 +594,13 @@ static int start_read(const struct device *dev,
596594
/* Buffer is filled in chunks, each chunk composed of number of samples equal to number
597595
* of active channels. Buffer pointer is advanced and reloaded after each chunk.
598596
*/
599-
nrfx_err = nrfx_saadc_buffer_set(
600-
samples_buffer,
601-
(m_data.internal_timer_enabled
602-
? (1 + sequence->options->extra_samplings)
603-
: active_channel_cnt));
604-
if (nrfx_err != NRFX_SUCCESS) {
605-
LOG_ERR("Failed to set buffer: 0x%08x", nrfx_err);
606-
return -EINVAL;
597+
error = nrfx_saadc_buffer_set(samples_buffer,
598+
(m_data.internal_timer_enabled
599+
? (1 + sequence->options->extra_samplings)
600+
: active_channel_cnt));
601+
if (error != 0) {
602+
LOG_ERR("Failed to set buffer: %d", error);
603+
return error;
607604
}
608605

609606
adc_context_start_read(&m_data.ctx, sequence);
@@ -651,7 +648,7 @@ static int adc_nrfx_read_async(const struct device *dev,
651648

652649
static void event_handler(const nrfx_saadc_evt_t *event)
653650
{
654-
nrfx_err_t err;
651+
int err;
655652

656653
if (event->type == NRFX_SAADC_EVT_DONE) {
657654
dmm_buffer_in_release(
@@ -670,8 +667,8 @@ static void event_handler(const nrfx_saadc_evt_t *event)
670667
adc_context_on_sampling_done(&m_data.ctx, DEVICE_DT_INST_GET(0));
671668
} else if (event->type == NRFX_SAADC_EVT_CALIBRATEDONE) {
672669
err = nrfx_saadc_mode_trigger();
673-
if (err != NRFX_SUCCESS) {
674-
LOG_ERR("Cannot start sampling: 0x%08x", err);
670+
if (err != 0) {
671+
LOG_ERR("Cannot start sampling: %d", err);
675672
adc_context_complete(&m_data.ctx, -EIO);
676673
}
677674
} else if (event->type == NRFX_SAADC_EVT_FINISHED) {
@@ -688,13 +685,13 @@ static int saadc_pm_handler(const struct device *dev, enum pm_device_action acti
688685

689686
static int init_saadc(const struct device *dev)
690687
{
691-
nrfx_err_t err;
688+
int err;
692689

693690
k_timer_init(&m_data.timer, external_timer_expired_handler, NULL);
694691

695692
/* The priority value passed here is ignored (see nrfx_glue.h). */
696693
err = nrfx_saadc_init(0);
697-
if (err != NRFX_SUCCESS) {
694+
if (err != 0) {
698695
LOG_ERR("Failed to initialize device: %s", dev->name);
699696
return -EIO;
700697
}

0 commit comments

Comments
 (0)