diff --git a/include/adc.h b/include/adc.h index f4dee8e401183..dbbff357a58e3 100644 --- a/include/adc.h +++ b/include/adc.h @@ -4,6 +4,7 @@ */ /* + * Copyright (c) 2018 Nordic Semiconductor ASA * Copyright (c) 2015 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 @@ -26,121 +27,316 @@ extern "C" { * @{ */ + +/** @brief ADC channel gain factors. */ +enum adc_gain +{ + ADC_GAIN_1_6, /**< x 1/6. */ + ADC_GAIN_1_5, /**< x 1/5. */ + ADC_GAIN_1_4, /**< x 1/4. */ + ADC_GAIN_1_3, /**< x 1/3. */ + ADC_GAIN_1_2, /**< x 1/2. */ + ADC_GAIN_1, /**< x 1. */ + ADC_GAIN_2, /**< x 2. */ + ADC_GAIN_3, /**< x 3. */ + ADC_GAIN_4, /**< x 4. */ + ADC_GAIN_8, /**< x 8. */ + ADC_GAIN_16, /**< x 16. */ + ADC_GAIN_32, /**< x 32. */ + ADC_GAIN_64, /**< x 64. */ +}; + +/** @brief ADC references. */ +enum adc_reference +{ + ADC_REF_VDD_1, /**< VDD. */ + ADC_REF_VDD_1_2, /**< VDD/2. */ + ADC_REF_VDD_1_3, /**< VDD/3. */ + ADC_REF_VDD_1_4, /**< VDD/4. */ + ADC_REF_INTERNAL, /**< Internal. */ + ADC_REF_EXTERNAL0, /**< External, input 0. */ + ADC_REF_EXTERNAL1, /**< External, input 1. */ +}; + +#define ADC_ACQ_TIME_TICKS (0u) +#define ADC_ACQ_TIME_MICROSECONDS (1u) +#define ADC_ACQ_TIME_NANOSECONDS (2u) +#define ADC_ACQ_TIME(unit, value) (((unit) << 14) | \ + ((value) & ((1u << 14)-1))) +#define ADC_ACQ_TIME_UNIT(time) (((time) >> 14) & 3u) +#define ADC_ACQ_TIME_VALUE(time) ((time) & ((1u << 14)-1) + /** - * @brief ADC driver Sequence entry - * - * This structure defines a sequence entry used - * to define a sample from a specific channel. + * @brief Structure for specifying configuration of an ADC channel. */ -struct adc_seq_entry { - /** Clock ticks delay before sampling the ADC. */ - s32_t sampling_delay; +struct adc_channel_cfg { + /** Gain selection. */ + enum adc_gain gain; + + /** Reference selection. */ + enum adc_reference reference; - /** Buffer pointer where the sample is written.*/ - u8_t *buffer; + /** + * Acquisition time. + * Use the ADC_ACQ_TIME macro to compose the value for this field. + * Particular drivers do not necessarily support all the possible units. + * Value range is 0-16383 for a given unit. + */ + u16_t acquisition_time; - /** Length of the sampling buffer.*/ - u32_t buffer_length; + /** Channel identifier (0-31). */ + u8_t channel_id : 5; - /** Channel ID that should be sampled from the ADC */ - u8_t channel_id; + /** Channel type: single-ended or differential. */ + bool differential : 1; - u8_t stride[3]; + /** Positive converter input. */ + u8_t input_positive; + + /** Negative converter input (used only for differential channels). */ + u8_t input_negative; }; + /** - * @brief ADC driver Sequence table + * @brief ADC triggers. + */ +enum adc_trigger +{ + ADC_TRIGGER_DELAY_TICKS, + ADC_TRIGGER_DELAY_US, + ADC_TRIGGER_DELAY_MS, + + ADC_TRIGGER_SAMPLE_RATE, + + /* more to be added */ +}; + +/* Forward declaration of the adc_sequence structure. */ +struct adc_sequence; + +/** + * @brief Actions to be performed after a sampling is done. + */ +enum adc_action +{ + ADC_ACTION_CONTINUE = 0, + /**< The sequence should be continued normally. */ + + ADC_ACTION_REPEAT, + /**< The sampling should be repeated. New samples should be read from + * the ADC and written in the same place in as the recent ones. + */ + + ADC_ACTION_FINISH, + /**< The sequence should be finished immediately. */ +}; + +/** + * @brief Type definition of the optional callback function to be called after + * a requested sampling is done. + * + * @param dev Pointer to the device structure for the driver + * instance. + * @param sequence Pointer to the sequence structure that triggered the + * sampling. + * @param sampling_index Index (0-65535) of the sampling done. * - * This structure defines a list of sequence entries - * used to execute a sequence of samplings. + * @returns Action to be performed by the driver. See @ref adc_action. + */ +typedef enum adc_action (*adc_sequence_callback)( + struct device *dev, + const struct adc_sequence *sequence, + u16_t sampling_index); + +/** + * @brief Structure specifying additional options for an ADC sampling sequence. */ -struct adc_seq_table { - /* Pointer to a sequence entry array. */ - struct adc_seq_entry *entries; +struct adc_sequence_options { + /** Type of trigger that starts consecutive samplings. */ + enum adc_trigger trigger_type; + /** + * Parameter for the selected trigger: number of ticks, + * microseconds, etc. + */ + union { + u32_t value; + void *pointer; + } trigger_param; - /* Number of entries in the sequence entry array. */ - u8_t num_entries; - u8_t stride[3]; + /** + * Callback to be called after each sampling is done. + * Optional - set to NULL if it is not needed. + */ + adc_sequence_callback callback; + + /** + * Number of extra samplings to perform (the total number is equal to: + * 1 + extra_samplings). + */ + u16_t extra_samplings; }; +/** + * @brief Structure defining an ADC sampling sequence. + */ +struct adc_sequence { + /** + * Pointer to a structure defining additional options for the sequence. + * If NULL, the sequence consists of a single sampling. + */ + const struct adc_sequence_options *options; + + /** + * Bit-mask indicating the channels to be included in each sampling + * of this sequence. + * All selected channels must be configured with adc_channel_setup() + * before they are used in a sequence. + */ + u32_t channels; + + /** + * Pointer to a buffer where the samples are to be written. Samples + * from subsequent samplings are written sequentially in the buffer. + * The number of samples written for each sampling is determined by + * the number of channels selected in the 'channels' field. + * The buffer must be of an appropriate size, taking into account + * the number of selected channels and the ADC resolution used + * as well as the number of samplings contained in the sequence. + */ + void *buffer; + + /** + * Specifies the actual size of the buffer pointed by the 'buffer' + * field (in bytes). The driver must ensure that samples are not + * written beyond the limit and it must return an error if the buffer + * turns out to be not large enough to hold all the requested samples. + */ + size_t buffer_size; + + /** + * ADC resolution. + * For single-ended channels the sample values are from range: + * 0 .. 2^resolution - 1, + * for differential ones: + * -2^(resolution-1) .. 2^(resolution-1) - 1. + */ + u8_t resolution; + + /** + * Oversampling setting. + * Each sample is averaged from 2^oversampling results. + */ + u8_t oversampling; +}; + + +/** + * @brief Type definition of ADC API function for configuring a channel. + * See adc_channel_setup() for argument descriptions. + */ +typedef int (*adc_api_channel_setup)(struct device *dev, + const struct adc_channel_cfg *channel_cfg); + +/** + * @brief Type definition of ADC API function for setting a read request. + * See adc_read() for argument descriptions. + */ +typedef int (*adc_api_read)(struct device *dev, + const struct adc_sequence *sequence); + +#ifdef CONFIG_ADC_ASYNC +/** + * @brief Type definition of ADC API function for setting an asynchronous + * read request. + * See adc_read_async() for argument descriptions. + */ +typedef int (*adc_api_read_async)(struct device *dev, + const struct adc_sequence *sequence, + struct k_poll_signal *async); +#endif + /** * @brief ADC driver API * - * This structure holds all API function pointers. + * This is the mandatory API any ADC driver needs to expose. */ struct adc_driver_api { - /** Pointer to the enable routine. */ - void (*enable)(struct device *dev); - - /** Pointer to the disable routine. */ - void (*disable)(struct device *dev); - - /** Pointer to the read routine. */ - int (*read)(struct device *dev, struct adc_seq_table *seq_table); + adc_api_channel_setup channel_setup; + adc_api_read read; +#ifdef CONFIG_ADC_ASYNC + adc_api_read_async read_async; +#endif }; /** - * @brief Enable ADC hardware +l * @brief Configure a converter channel. * - * This routine enables the ADC hardware block for data sampling for the - * specified device. + * It is required to call this function and configure each channel before it is + * selected for a read request. * - * @param dev Pointer to the device structure for the driver instance. + * @param dev Pointer to the device structure for the driver instance. + * @param channel_cfg Channel configuration. * - * @return N/A + * @returns 0 on success, negative errno code otherwise. */ -__syscall void adc_enable(struct device *dev); +__syscall int adc_channel_setup(struct device *dev, + const struct adc_channel_cfg *channel_cfg); -static inline void _impl_adc_enable(struct device *dev) +static inline +int _impl_adc_channel_setup(struct device *dev, + const struct adc_channel_cfg *channel_cfg) { const struct adc_driver_api *api = dev->driver_api; - api->enable(dev); + return api->channel_setup(dev, channel_cfg); } /** - * @brief Disable ADC hardware - * - * This routine disables the ADC hardware block for data sampling for the - * specified device. + * @brief Set a read request. * - * @param dev Pointer to the device structure for the driver instance. + * @param dev Pointer to the device structure for the driver instance. + * @param sequence Structure specifying requested sequence of samplings. * - * @return N/A + * @returns 0 on success, negative errno code otherwise. */ -__syscall void adc_disable(struct device *dev); +__syscall int adc_read(struct device *dev, + const struct adc_sequence *sequence); -static inline void _impl_adc_disable(struct device *dev) +static inline int _impl_adc_read(struct device *dev, + const struct adc_sequence *sequence) { const struct adc_driver_api *api = dev->driver_api; - api->disable(dev); + return api->read(dev, sequence); } +#ifdef CONFIG_ADC_ASYNC /** - * @brief Set a read request. - * - * This routine sends a read or sampling request to the ADC hardware block. - * A sequence table describes the read request. - * The routine returns once the ADC completes the read sequence. - * The sample data can be retrieved from the memory buffers in - * the sequence table structure. + * @brief Set an asynchronous read request. * - * @param dev Pointer to the device structure for the driver instance. - * @param seq_table Pointer to the structure representing the sequence table. + * @param dev Pointer to the device structure for the driver instance. + * @param sequence Structure specifying requested sequence of samplings. + * @param async Pointer to a valid and ready to be signaled struct + * k_poll_signal. (Note: if NULL this function will not notify + * the end of the transaction, and whether it went successfully + * or not). * - * @retval 0 On success - * @retval else Otherwise. + * @returns 0 on success, negative errno code otherwise. */ -__syscall int adc_read(struct device *dev, struct adc_seq_table *seq_table); +__syscall int adc_read_async(struct device *dev, + const struct adc_sequence *sequence, + struct k_poll_signal *signal); -static inline int _impl_adc_read(struct device *dev, - struct adc_seq_table *seq_table) +static inline int _impl_adc_read_async(struct device *dev, + const struct adc_sequence *sequence, + struct k_poll_signal *async) { const struct adc_driver_api *api = dev->driver_api; - return api->read(dev, seq_table); + return api->read_async(dev, sequence, async); } +#endif /* CONFIG_ADC_ASYNC */ /** * @} diff --git a/tests/drivers/adc/adc_api/CMakeLists.txt b/tests/drivers/adc/adc_api/CMakeLists.txt index 92a4288bc1d85..e7f7cfb0f451a 100644 --- a/tests/drivers/adc/adc_api/CMakeLists.txt +++ b/tests/drivers/adc/adc_api/CMakeLists.txt @@ -1,3 +1,11 @@ +macro(set_conf_file) + if(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf) + set(CONF_FILE "prj_base.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf") + else() + set(CONF_FILE "prj_base.conf") + endif() +endmacro() + include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(NONE) diff --git a/tests/drivers/adc/adc_api/boards/nrf52840_pca10056.conf b/tests/drivers/adc/adc_api/boards/nrf52840_pca10056.conf new file mode 100644 index 0000000000000..5e67fe93e4f9d --- /dev/null +++ b/tests/drivers/adc/adc_api/boards/nrf52840_pca10056.conf @@ -0,0 +1 @@ +CONFIG_ADC_NRFX=y diff --git a/tests/drivers/adc/adc_api/prj.conf b/tests/drivers/adc/adc_api/prj.conf deleted file mode 100644 index c286916189532..0000000000000 --- a/tests/drivers/adc/adc_api/prj.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_ADC=y -CONFIG_ZTEST=y diff --git a/tests/drivers/adc/adc_api/prj_base.conf b/tests/drivers/adc/adc_api/prj_base.conf new file mode 100644 index 0000000000000..3f3d94cf56214 --- /dev/null +++ b/tests/drivers/adc/adc_api/prj_base.conf @@ -0,0 +1,4 @@ +CONFIG_ZTEST=y +CONFIG_ADC=y +CONFIG_ADC_0=y +CONFIG_ADC_0_IRQ_PRI=1 diff --git a/tests/drivers/adc/adc_api/src/main.c b/tests/drivers/adc/adc_api/src/main.c index fca46436cc220..d9b864df1919a 100644 --- a/tests/drivers/adc/adc_api/src/main.c +++ b/tests/drivers/adc/adc_api/src/main.c @@ -11,7 +11,10 @@ * @} */ -extern void test_adc_sample(void); +extern void test_adc_sample_one_channel(void); +extern void test_adc_sample_two_channels(void); +extern void test_adc_sample_with_delay_trigger(void); +extern void test_adc_repeated_samplings(void); #include #include @@ -19,6 +22,9 @@ extern void test_adc_sample(void); void test_main(void) { ztest_test_suite(adc_basic_test, - ztest_unit_test(test_adc_sample)); + ztest_unit_test(test_adc_sample_one_channel), + ztest_unit_test(test_adc_sample_two_channels), + ztest_unit_test(test_adc_sample_with_delay_trigger), + ztest_unit_test(test_adc_repeated_samplings)); ztest_run_test_suite(adc_basic_test); } diff --git a/tests/drivers/adc/adc_api/src/test_adc.c b/tests/drivers/adc/adc_api/src/test_adc.c index 84b75f07f1a98..45bdb9a0beb5d 100644 --- a/tests/drivers/adc/adc_api/src/test_adc.c +++ b/tests/drivers/adc/adc_api/src/test_adc.c @@ -1,4 +1,5 @@ /* + * Copyright (c) 2018 Nordic Semiconductor ASA * Copyright (c) 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 @@ -8,19 +9,7 @@ * @addtogroup test_adc_basic_operations * @{ * @defgroup t_adc_basic_basic_operations test_adc_sample - * @brief TestPurpose: verify ADC works well with different resolutions - * and sample mode - * @details - * - Test Steps - * -# Connect A0 to VCC3.3. - * -# Prepare ADC sequence table. - * -# Bind ADC device. - * -# Enable ADC device. - * -# Call adc_read() to fetch ADC sample. - * -# Dump the sample results. - * - Expected Results - * -# ADC will return the sample result for VCC3.3. Different resolutions - * will all return almost the biggest value in each sample width. + * @brief TestPurpose: verify ADC driver handles different sampling scenarios * @} */ @@ -28,78 +17,269 @@ #include #include -#define BUFFER_SIZE 5 - -#if defined(CONFIG_BOARD_FRDM_K64F) -#define ADC_DEV_NAME CONFIG_ADC_1_NAME -#define ADC_CHANNEL 14 -#elif defined(CONFIG_BOARD_FRDM_KL25Z) -#define ADC_DEV_NAME CONFIG_ADC_0_NAME -#define ADC_CHANNEL 12 -#elif defined(CONFIG_BOARD_FRDM_KW41Z) -#define ADC_DEV_NAME CONFIG_ADC_0_NAME -#define ADC_CHANNEL 3 -#elif defined(CONFIG_BOARD_HEXIWEAR_K64) -#define ADC_DEV_NAME CONFIG_ADC_0_NAME -#define ADC_CHANNEL 16 -#elif defined(CONFIG_BOARD_HEXIWEAR_KW40Z) -#define ADC_DEV_NAME CONFIG_ADC_0_NAME -#define ADC_CHANNEL 1 +#if defined(CONFIG_BOARD_NRF52840_PCA10056) +#define TEST_ADC_DEV_NAME CONFIG_ADC_0_NAME +#define TEST_ADC_CH_0_INPUT 1 +#define TEST_ADC_CH_2_INPUT 2 +#define TEST_ADC_RESOLUTION 10 +#define TEST_ADC_ACQ_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10) +#define TEST_ADC_GAIN ADC_GAIN_1_6 +#define TEST_ADC_REFERENCE ADC_REF_INTERNAL #else -#define ADC_DEV_NAME CONFIG_ADC_0_NAME -#define ADC_CHANNEL 10 +#error "Unsupported board." #endif -static u16_t seq_buffer[BUFFER_SIZE]; +#define BUFFER_SIZE 6 -static struct adc_seq_entry entry = { - .sampling_delay = 30, - .channel_id = ADC_CHANNEL, - .buffer = (void *)seq_buffer, - .buffer_length = BUFFER_SIZE * sizeof(seq_buffer[0]) -}; +static s16_t m_sample_buffer[BUFFER_SIZE]; -static struct adc_seq_table table = { - .entries = &entry, - .num_entries = 1, +static const struct adc_channel_cfg m_channel_0_cfg = { + .gain = TEST_ADC_GAIN, + .reference = TEST_ADC_REFERENCE, + .acquisition_time = TEST_ADC_ACQ_TIME, + .channel_id = 0, + .differential = false, + .input_positive = TEST_ADC_CH_0_INPUT, +}; +static const struct adc_channel_cfg m_channel_2_cfg = { + .gain = TEST_ADC_GAIN, + .reference = TEST_ADC_REFERENCE, + .acquisition_time = TEST_ADC_ACQ_TIME, + .channel_id = 2, + .differential = false, + .input_positive = TEST_ADC_CH_2_INPUT, }; -static int test_task(void) +static void show_samples(void) { int i; + + TC_PRINT("Samples read: "); + for (i = 0; i < BUFFER_SIZE; i++) { + TC_PRINT("0x%04x ", m_sample_buffer[i]); + } + TC_PRINT("\n"); +} + +/******************************************************************************* + * test_adc_sample_one_channel + */ +static int test_task_one_channel(void) +{ int ret; - struct device *adc_dev = device_get_binding(ADC_DEV_NAME); + const struct adc_sequence sequence = { + .options = NULL, + .channels = (1U << 0), + .buffer = m_sample_buffer, + .buffer_size = sizeof(m_sample_buffer), + .resolution = TEST_ADC_RESOLUTION, + .oversampling = 0, + }; + + struct device *adc_dev = device_get_binding(TEST_ADC_DEV_NAME); if (!adc_dev) { TC_PRINT("Cannot get ADC device\n"); return TC_FAIL; } - /* 1. Verify adc_enable() */ - adc_enable(adc_dev); + ret = adc_channel_setup(adc_dev, &m_channel_0_cfg); + if (ret != 0) { + TC_PRINT("Setting up of channel 0 failed with code %d\n", ret); + return TC_FAIL; + } - k_sleep(500); + memset(m_sample_buffer, 0, sizeof(m_sample_buffer)); - /* 2. Verify adc_read() */ - ret = adc_read(adc_dev, &table); + ret = adc_read(adc_dev, &sequence); if (ret != 0) { - TC_PRINT("Failed to fetch sample data from ADC controller\n"); + TC_PRINT("adc_read() failed with code %d\n", ret); return TC_FAIL; } - TC_PRINT("Channel %d ADC Sample: ", ADC_CHANNEL); - for (i = 0; i < BUFFER_SIZE; i++) { - TC_PRINT("%d ", seq_buffer[i]); + show_samples(); + + return TC_PASS; +} +void test_adc_sample_one_channel(void) +{ + zassert_true(test_task_one_channel() == TC_PASS, NULL); +} + +/******************************************************************************* + * test_adc_sample_two_channels + */ +static int test_task_two_channels(void) +{ + int ret; + const struct adc_sequence sequence = { + .options = NULL, + .channels = (1U << 0) | (1U << 2), + .buffer = m_sample_buffer, + .buffer_size = sizeof(m_sample_buffer), + .resolution = TEST_ADC_RESOLUTION, + .oversampling = 0, + }; + + struct device *adc_dev = device_get_binding(TEST_ADC_DEV_NAME); + + if (!adc_dev) { + TC_PRINT("Cannot get ADC device\n"); + return TC_FAIL; } - TC_PRINT("\n"); - /* 3. Verify adc_disable() */ - adc_disable(adc_dev); + ret = adc_channel_setup(adc_dev, &m_channel_0_cfg); + if (ret != 0) { + TC_PRINT("Setting up of channel 0 failed with code %d\n", ret); + return TC_FAIL; + } + + ret = adc_channel_setup(adc_dev, &m_channel_2_cfg); + if (ret != 0) { + TC_PRINT("Setting up of channel 2 failed with code %d\n", ret); + return TC_FAIL; + } + + memset(m_sample_buffer, 0, sizeof(m_sample_buffer)); + + ret = adc_read(adc_dev, &sequence); + if (ret != 0) { + TC_PRINT("adc_read() failed with code %d\n", ret); + return TC_FAIL; + } + + show_samples(); return TC_PASS; } +void test_adc_sample_two_channels(void) +{ + zassert_true(test_task_two_channels() == TC_PASS, NULL); +} -void test_adc_sample(void) + +/******************************************************************************* + * test_adc_sample_with_delay_trigger + */ +static enum adc_action delay_trigger_callback( + struct device *dev, + const struct adc_sequence *sequence, + u16_t sampling_index) +{ + TC_PRINT("delay_trigger_callback: sampling %d\n", sampling_index); + return ADC_ACTION_CONTINUE; +} +static int test_task_delay_trigger(void) +{ + int ret; + const struct adc_sequence_options options = { + .trigger_type = ADC_TRIGGER_DELAY_MS, + .trigger_param.value = 100, + .callback = delay_trigger_callback, + .extra_samplings = 4, + }; + const struct adc_sequence sequence = { + .options = &options, + .channels = (1U << 0), + .buffer = m_sample_buffer, + .buffer_size = sizeof(m_sample_buffer), + .resolution = TEST_ADC_RESOLUTION, + .oversampling = 0, + }; + + struct device *adc_dev = device_get_binding(TEST_ADC_DEV_NAME); + + if (!adc_dev) { + TC_PRINT("Cannot get ADC device\n"); + return TC_FAIL; + } + + ret = adc_channel_setup(adc_dev, &m_channel_0_cfg); + if (ret != 0) { + TC_PRINT("Setting up of channel 0 failed with code %d\n", ret); + return TC_FAIL; + } + + memset(m_sample_buffer, 0, sizeof(m_sample_buffer)); + + ret = adc_read(adc_dev, &sequence); + if (ret != 0) { + TC_PRINT("adc_read() failed with code %d\n", ret); + return TC_FAIL; + } + + show_samples(); + + return TC_PASS; +} +void test_adc_sample_with_delay_trigger(void) +{ + zassert_true(test_task_delay_trigger() == TC_PASS, NULL); +} + + +/******************************************************************************* + * test_adc_repeated_samplings + */ +static u8_t m_samplings_done = 0; +static enum adc_action repeated_samplings_callback( + struct device *dev, + const struct adc_sequence *sequence, + u16_t sampling_index) +{ + ++m_samplings_done; + TC_PRINT("repeated_samplings_callback: done %d\n", m_samplings_done); + show_samples(); + return (m_samplings_done < 10) ? ADC_ACTION_REPEAT : ADC_ACTION_FINISH; +} +static int test_task_repeated_samplings(void) +{ + int ret; + const struct adc_sequence_options options = { + .trigger_type = ADC_TRIGGER_DELAY_MS, + .trigger_param.value = 100, + .callback = repeated_samplings_callback, + .extra_samplings = 0, + }; + const struct adc_sequence sequence = { + .options = &options, + .channels = (1U << 0) | (1U << 2), + .buffer = m_sample_buffer, + .buffer_size = sizeof(m_sample_buffer), + .resolution = TEST_ADC_RESOLUTION, + .oversampling = 0, + }; + + struct device *adc_dev = device_get_binding(TEST_ADC_DEV_NAME); + + if (!adc_dev) { + TC_PRINT("Cannot get ADC device\n"); + return TC_FAIL; + } + + ret = adc_channel_setup(adc_dev, &m_channel_0_cfg); + if (ret != 0) { + TC_PRINT("Setting up of channel 0 failed with code %d\n", ret); + return TC_FAIL; + } + + ret = adc_channel_setup(adc_dev, &m_channel_2_cfg); + if (ret != 0) { + TC_PRINT("Setting up of channel 2 failed with code %d\n", ret); + return TC_FAIL; + } + + memset(m_sample_buffer, 0, sizeof(m_sample_buffer)); + + ret = adc_read(adc_dev, &sequence); + if (ret != 0) { + TC_PRINT("adc_read() failed with code %d\n", ret); + return TC_FAIL; + } + + return TC_PASS; +} +void test_adc_repeated_samplings(void) { - zassert_true(test_task() == TC_PASS, NULL); + zassert_true(test_task_repeated_samplings() == TC_PASS, NULL); }