Skip to content

Commit c5cb4ca

Browse files
committed
tests: drivers: adc: adc_emul: write test for raw func set
write test for raw value func set function Signed-off-by: Nathan Olff <[email protected]>
1 parent 374662a commit c5cb4ca

File tree

1 file changed

+35
-0
lines changed
  • tests/drivers/adc/adc_emul/src

1 file changed

+35
-0
lines changed

tests/drivers/adc/adc_emul/src/main.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,41 @@ ZTEST_USER(adc_emul, test_adc_emul_custom_function)
364364
check_empty_samples(samples);
365365
}
366366

367+
/** @brief Test setting one channel with custom function raw value. */
368+
ZTEST_USER(adc_emul, test_adc_emul_custom_function_raw_value)
369+
{
370+
struct handle_seq_params channel1_param;
371+
const uint16_t raw_value = 1000;
372+
const uint16_t input_mV = (raw_value * ADC_REF_INTERNAL_MV / BIT(ADC_RESOLUTION));
373+
const int samples = 4;
374+
int ret, i;
375+
376+
for (i = 0; i < BUFFER_SIZE; ++i) {
377+
m_sample_buffer[i] = INVALID_ADC_VALUE;
378+
}
379+
380+
/* Generic ADC setup */
381+
const struct device *adc_dev = get_adc_device();
382+
383+
channel_setup(adc_dev, ADC_REF_INTERNAL, ADC_GAIN_1, ADC_1ST_CHANNEL_ID);
384+
385+
/* ADC emulator-specific setup */
386+
channel1_param.value = raw_value;
387+
388+
ret = adc_emul_raw_value_func_set(adc_dev, ADC_1ST_CHANNEL_ID, handle_seq, &channel1_param);
389+
zassert_ok(ret, "adc_emul_value_func_set() failed with code %d", ret);
390+
391+
/* Test sampling */
392+
start_adc_read(adc_dev, BIT(ADC_1ST_CHANNEL_ID), samples);
393+
394+
/* Check samples */
395+
check_samples(samples, input_mV,
396+
(SEQUENCE_STEP * ADC_REF_INTERNAL_MV / BIT(ADC_RESOLUTION)), 1 /* channels */,
397+
0 /* first channel data */, ADC_REF_INTERNAL_MV, ADC_GAIN_1);
398+
399+
check_empty_samples(samples);
400+
}
401+
367402
/**
368403
* @brief Test setting two channels with custom function and different
369404
* params.

0 commit comments

Comments
 (0)