Skip to content

Commit f7febfb

Browse files
committed
tests: drivers: adc: adc_emul: add test for const raw value function
write test for raw const adc emul function Signed-off-by: Nathan Olff <[email protected]>
1 parent 0c9039e commit f7febfb

File tree

1 file changed

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

1 file changed

+62
-0
lines changed

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,68 @@ ZTEST_USER(adc_emul, test_adc_emul_single_value)
216216
/* Test sampling */
217217
start_adc_read(adc_dev, BIT(ADC_1ST_CHANNEL_ID), samples);
218218

219+
/* Check samples */
220+
check_samples(samples, input_mv, 0 /* step */, 1 /* channels */, 0 /* first channel data */,
221+
ADC_REF_INTERNAL_MV, ADC_GAIN_1);
222+
223+
check_empty_samples(samples);
224+
}
225+
226+
/** @brief Test setting one channel with constant raw output. */
227+
ZTEST_USER(adc_emul, test_adc_emul_single_raw_value_half_reference)
228+
{
229+
const uint16_t input_raw_value = (1 << ADC_RESOLUTION) / 2;
230+
const uint16_t input_mv = ADC_REF_INTERNAL_MV / 2;
231+
const int samples = 4;
232+
int ret, i;
233+
234+
for (i = 0; i < BUFFER_SIZE; ++i) {
235+
m_sample_buffer[i] = INVALID_ADC_VALUE;
236+
}
237+
238+
/* Generic ADC setup */
239+
const struct device *adc_dev = get_adc_device();
240+
241+
channel_setup(adc_dev, ADC_REF_INTERNAL, ADC_GAIN_1, ADC_1ST_CHANNEL_ID);
242+
243+
/* ADC emulator-specific setup */
244+
ret = adc_emul_const_raw_value_set(adc_dev, ADC_1ST_CHANNEL_ID, input_raw_value);
245+
zassert_ok(ret, "adc_emul_const_value_set() failed with code %d", ret);
246+
247+
/* Test sampling */
248+
start_adc_read(adc_dev, BIT(ADC_1ST_CHANNEL_ID), samples);
249+
250+
/* Check samples */
251+
check_samples(samples, input_mv, 0 /* step */, 1 /* channels */, 0 /* first channel data */,
252+
ADC_REF_INTERNAL_MV, ADC_GAIN_1);
253+
254+
check_empty_samples(samples);
255+
}
256+
257+
/** @brief Test setting one channel with constant raw output. */
258+
ZTEST_USER(adc_emul, test_adc_emul_single_raw_value_quarter_reference)
259+
{
260+
const uint16_t input_raw_value = (1 << ADC_RESOLUTION) / 4;
261+
const uint16_t input_mv = ADC_REF_INTERNAL_MV / 4;
262+
const int samples = 4;
263+
int ret, i;
264+
265+
for (i = 0; i < BUFFER_SIZE; ++i) {
266+
m_sample_buffer[i] = INVALID_ADC_VALUE;
267+
}
268+
269+
/* Generic ADC setup */
270+
const struct device *adc_dev = get_adc_device();
271+
272+
channel_setup(adc_dev, ADC_REF_INTERNAL, ADC_GAIN_1, ADC_1ST_CHANNEL_ID);
273+
274+
/* ADC emulator-specific setup */
275+
ret = adc_emul_const_raw_value_set(adc_dev, ADC_1ST_CHANNEL_ID, input_raw_value);
276+
zassert_ok(ret, "adc_emul_const_value_set() failed with code %d", ret);
277+
278+
/* Test sampling */
279+
start_adc_read(adc_dev, BIT(ADC_1ST_CHANNEL_ID), samples);
280+
219281
/* Check samples */
220282
check_samples(samples, input_mv, 0 /* step */, 1 /* channels */,
221283
0 /* first channel data */, ADC_REF_INTERNAL_MV,

0 commit comments

Comments
 (0)