4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
6
6
7
- #define DT_DRV_COMPAT renesas_ra_adc
8
-
9
7
#include <zephyr/drivers/adc.h>
10
8
#include <zephyr/drivers/clock_control.h>
11
9
#include <zephyr/drivers/pinctrl.h>
@@ -29,9 +27,6 @@ LOG_MODULE_REGISTER(adc_ra, CONFIG_ADC_LOG_LEVEL);
29
27
#define ADC_AVERAGE_8 ADC_ADD_AVERAGE_EIGHT
30
28
#define ADC_AVERAGE_16 ADC_ADD_AVERAGE_SIXTEEN
31
29
32
- #define ADC_RES_12 ADC_RESOLUTION_12_BIT
33
- #define ADC_RES_16 ADC_RESOLUTION_16_BIT
34
-
35
30
#define ADC_VARIANT_ADC12 12
36
31
#define ADC_VARIANT_ADC16 16
37
32
@@ -399,7 +394,7 @@ static int adc_ra_init(const struct device *dev)
399
394
400
395
#define IRQ_CONFIGURE_DEFINE (idx ) .irq_configure = adc_ra_configure_func_##idx
401
396
402
- #define ADC_RA_INIT (idx ) \
397
+ #define ADC_RA_INIT_VARIANT (idx , VARIANT , RES_NUM , RES_ENUM ) \
403
398
IRQ_CONFIGURE_FUNC(idx) \
404
399
PINCTRL_DT_INST_DEFINE(idx); \
405
400
static adc_extended_cfg_t g_adc_cfg_extend_##idx = { \
@@ -422,9 +417,9 @@ static int adc_ra_init(const struct device *dev)
422
417
IF_ENABLED(CONFIG_ADC_ASYNC, (.read_async = adc_ra_read_async))}; \
423
418
static const struct adc_ra_config adc_ra_config_##idx = { \
424
419
.channel_available_mask = DT_INST_PROP(idx, channel_available_mask), \
425
- .variant = DT_INST_PROP(idx, variant), \
420
+ .variant = VARIANT, \
426
421
.reference = DT_INST_ENUM_IDX(idx, reference), \
427
- .resolution = DT_INST_PROP(idx, variant), \
422
+ .resolution = RES_NUM, \
428
423
.sampling_time_ns = DT_INST_PROP_OR(idx, sampling_time_ns, UNSPECIFIED), \
429
424
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
430
425
IRQ_CONFIGURE_DEFINE(idx), \
@@ -438,7 +433,7 @@ static int adc_ra_init(const struct device *dev)
438
433
{ \
439
434
.unit = DT_INST_PROP(idx, unit), \
440
435
.mode = ADC_MODE_SINGLE_SCAN, \
441
- .resolution = UTIL_CAT(ADC_RES_, DT_INST_PROP(idx, variant)), \
436
+ .resolution = RES_ENUM, \
442
437
.alignment = (adc_alignment_t)ADC_ALIGNMENT_RIGHT, \
443
438
.trigger = 0, \
444
439
.p_callback = renesas_ra_adc_callback, \
@@ -464,4 +459,10 @@ static int adc_ra_init(const struct device *dev)
464
459
DEVICE_DT_INST_DEFINE(idx, adc_ra_init, NULL, &adc_ra_data_##idx, &adc_ra_config_##idx, \
465
460
POST_KERNEL, CONFIG_ADC_INIT_PRIORITY, &adc_ra_api_##idx)
466
461
467
- DT_INST_FOREACH_STATUS_OKAY (ADC_RA_INIT );
462
+ #define DT_DRV_COMPAT renesas_ra_adc12
463
+ DT_INST_FOREACH_STATUS_OKAY_VARGS (ADC_RA_INIT_VARIANT , ADC_VARIANT_ADC12 , 12 , ADC_RESOLUTION_12_BIT )
464
+ #undef DT_DRV_COMPAT
465
+
466
+ #define DT_DRV_COMPAT renesas_ra_adc16
467
+ DT_INST_FOREACH_STATUS_OKAY_VARGS (ADC_RA_INIT_VARIANT , ADC_VARIANT_ADC16 , 16 , ADC_RESOLUTION_16_BIT )
468
+ #undef DT_DRV_COMPAT
0 commit comments