From 76dafc85887cccf899ae891a870cc31fe2437d27 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Thu, 28 Aug 2025 12:02:22 +0200 Subject: [PATCH 1/7] [nrf fromtree] dts: bindings: comparator: nordic: Change inputs type to int Unify external analog inputs type to be consistent in COMP, LPCOMP and SAADC nordic drivers. Signed-off-by: Jakub Zymelka (cherry picked from commit d85bdb7ee913e1106709290e2ecb1da1693fb475) --- dts/bindings/comparator/nordic,nrf-comp.yaml | 32 ++++--------------- .../comparator/nordic,nrf-lpcomp.yaml | 20 +++--------- .../zephyr/dt-bindings/comparator/nrf-comp.h | 21 ++++++++++++ 3 files changed, 31 insertions(+), 42 deletions(-) create mode 100644 include/zephyr/dt-bindings/comparator/nrf-comp.h diff --git a/dts/bindings/comparator/nordic,nrf-comp.yaml b/dts/bindings/comparator/nordic,nrf-comp.yaml index e4f6838d204..f1405a6de2c 100644 --- a/dts/bindings/comparator/nordic,nrf-comp.yaml +++ b/dts/bindings/comparator/nordic,nrf-comp.yaml @@ -25,7 +25,7 @@ description: | &comp { status = "okay"; main-mode = "SE"; - psel = "AIN0"; + psel = ; refsel = "INT_1V2"; sp-mode = "NORMAL"; th-up = <36>; @@ -39,7 +39,7 @@ description: | &comp { ... refsel = "AREF"; - extrefsel = "AIN1"; + extrefsel = ; ... }; @@ -49,8 +49,8 @@ description: | &comp { status = "okay"; main-mode = "DIFF"; - psel = "AIN0"; - extrefsel = "AIN1"; + psel = ; + extrefsel = ; sp-mode = "NORMAL"; enable-hyst; isource = "DISABLED"; @@ -68,30 +68,10 @@ properties: - "DIFF" psel: - type: string - enum: - - "AIN0" - - "AIN1" - - "AIN2" - - "AIN3" - - "AIN4" - - "AIN5" - - "AIN6" - - "AIN7" - - "VDD_DIV2" - - "VDDH_DIV5" + type: int extrefsel: - type: string - enum: - - "AIN0" - - "AIN1" - - "AIN2" - - "AIN3" - - "AIN4" - - "AIN5" - - "AIN6" - - "AIN7" + type: int refsel: type: string diff --git a/dts/bindings/comparator/nordic,nrf-lpcomp.yaml b/dts/bindings/comparator/nordic,nrf-lpcomp.yaml index 64a30b330d8..4995155ed76 100644 --- a/dts/bindings/comparator/nordic,nrf-lpcomp.yaml +++ b/dts/bindings/comparator/nordic,nrf-lpcomp.yaml @@ -21,7 +21,7 @@ description: | &comp { status = "okay"; - psel = "AIN0"; + psel = ; refsel = "VDD_4_8"; enable-hyst; }; @@ -32,7 +32,7 @@ description: | &comp { ... refsel = "AREF"; - extrefsel = "AIN1"; + extrefsel = ; ... }; @@ -42,22 +42,10 @@ include: base.yaml properties: psel: - type: string - enum: - - "AIN0" - - "AIN1" - - "AIN2" - - "AIN3" - - "AIN4" - - "AIN5" - - "AIN6" - - "AIN7" + type: int extrefsel: - type: string - enum: - - "AIN0" - - "AIN1" + type: int refsel: type: string diff --git a/include/zephyr/dt-bindings/comparator/nrf-comp.h b/include/zephyr/dt-bindings/comparator/nrf-comp.h new file mode 100644 index 00000000000..1a5407554a1 --- /dev/null +++ b/include/zephyr/dt-bindings/comparator/nrf-comp.h @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2025 Nordic Semiconductor ASA + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_COMP_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_COMP_H_ + +#define NRF_COMP_AIN0 0 /** AIN0 external input */ +#define NRF_COMP_AIN1 1 /** AIN1 external input */ +#define NRF_COMP_AIN2 2 /** AIN2 external input */ +#define NRF_COMP_AIN3 3 /** AIN3 external input */ +#define NRF_COMP_AIN4 4 /** AIN4 external input */ +#define NRF_COMP_AIN5 5 /** AIN5 external input */ +#define NRF_COMP_AIN6 6 /** AIN6 external input */ +#define NRF_COMP_AIN7 7 /** AIN7 external input */ +#define NRF_COMP_AIN_VDD_DIV2 8 /** VDD / 2 */ +#define NRF_COMP_AIN_VDDH_DIV5 9 /** VDDH / 5 */ + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_COMP_H_ */ From d097f0939fb66759426d0600749be73dbd918719 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Thu, 28 Aug 2025 12:04:57 +0200 Subject: [PATCH 2/7] [nrf fromtree] drivers comparator: nordic: Align drivers to changed analog input types External analog input types changed from `string` to `int`. Signed-off-by: Jakub Zymelka (cherry picked from commit e5ecbd2112d01bd0970ed6a3298fef9b95447ed2) --- drivers/comparator/comparator_nrf_comp.c | 131 +++++++++--------- drivers/comparator/comparator_nrf_lpcomp.c | 54 +++++--- include/zephyr/drivers/comparator/nrf_comp.h | 61 ++------ .../zephyr/drivers/comparator/nrf_lpcomp.h | 37 +---- 4 files changed, 108 insertions(+), 175 deletions(-) diff --git a/drivers/comparator/comparator_nrf_comp.c b/drivers/comparator/comparator_nrf_comp.c index 311a864303b..6c5acdf5c08 100644 --- a/drivers/comparator/comparator_nrf_comp.c +++ b/drivers/comparator/comparator_nrf_comp.c @@ -19,8 +19,7 @@ #define SHIM_NRF_COMP_DT_INST_REFSEL_IS_AREF(inst) \ DT_INST_ENUM_HAS_VALUE(inst, refsel, aref) -#define SHIM_NRF_COMP_DT_INST_EXTREFSEL(inst) \ - _CONCAT(COMP_NRF_COMP_EXTREFSEL_, DT_INST_STRING_TOKEN(inst, extrefsel)) +#define SHIM_NRF_COMP_DT_INST_EXTREFSEL(inst) DT_INST_PROP(inst, extrefsel) #define SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(inst) \ DT_INST_ENUM_HAS_VALUE(inst, main_mode, se) @@ -43,8 +42,7 @@ #define SHIM_NRF_COMP_DT_INST_ISOURCE(inst) \ _CONCAT(COMP_NRF_COMP_ISOURCE_, DT_INST_STRING_TOKEN(inst, isource)) -#define SHIM_NRF_COMP_DT_INST_PSEL(inst) \ - _CONCAT(COMP_NRF_COMP_PSEL_, DT_INST_STRING_TOKEN(inst, psel)) +#define SHIM_NRF_COMP_DT_INST_PSEL(inst) DT_INST_PROP(inst, psel) #if defined(COMP_HYST_HYST_Hyst40mV) #define NRF_COMP_HYST_ENABLED NRF_COMP_HYST_40MV @@ -73,35 +71,50 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64); BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64); #endif -#if NRF_COMP_HAS_AIN_AS_PIN -BUILD_ASSERT((COMP_NRF_COMP_PSEL_AIN0 == 0)); -BUILD_ASSERT((COMP_NRF_COMP_PSEL_AIN7 == 7)); -BUILD_ASSERT((COMP_NRF_COMP_EXTREFSEL_AIN0 == 0)); -BUILD_ASSERT((COMP_NRF_COMP_EXTREFSEL_AIN7 == 7)); +#if (NRF_COMP_HAS_AIN_AS_PIN) +BUILD_ASSERT(NRF_COMP_AIN0 == 0); +BUILD_ASSERT(NRF_COMP_AIN7 == 7); #else -#ifndef COMP_PSEL_PSEL_AnalogInput4 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN4); +BUILD_ASSERT((NRF_COMP_AIN0 == NRF_COMP_INPUT_0) && + (NRF_COMP_AIN1 == NRF_COMP_INPUT_1) && + (NRF_COMP_AIN2 == NRF_COMP_INPUT_2) && + (NRF_COMP_AIN3 == NRF_COMP_INPUT_3) && +#if defined(COMP_PSEL_PSEL_AnalogInput4) + (NRF_COMP_AIN4 == NRF_COMP_INPUT_4) && #endif - -#ifndef COMP_PSEL_PSEL_AnalogInput5 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN5); +#if defined(COMP_PSEL_PSEL_AnalogInput5) + (NRF_COMP_AIN5 == NRF_COMP_INPUT_5) && #endif - -#ifndef COMP_PSEL_PSEL_AnalogInput6 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN6); +#if defined(COMP_PSEL_PSEL_AnalogInput6) + (NRF_COMP_AIN6 == NRF_COMP_INPUT_6) && #endif - -#ifndef COMP_PSEL_PSEL_AnalogInput7 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN7); +#if defined(COMP_PSEL_PSEL_AnalogInput7) + (NRF_COMP_AIN7 == NRF_COMP_INPUT_7) && #endif + (NRF_COMP_AIN0 == NRF_COMP_EXT_REF_0) && + (NRF_COMP_AIN1 == NRF_COMP_EXT_REF_1) && + (NRF_COMP_AIN2 == NRF_COMP_EXT_REF_2) && + (NRF_COMP_AIN3 == NRF_COMP_EXT_REF_3) && +#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) + (NRF_COMP_AIN4 == NRF_COMP_EXT_REF_4) && #endif - -#ifndef COMP_PSEL_PSEL_VddDiv2 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_VDD_DIV2); +#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) + (NRF_COMP_AIN5 == NRF_COMP_EXT_REF_5) && #endif - -#ifndef COMP_PSEL_PSEL_VddhDiv5 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_VDDH_DIV5); +#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) + (NRF_COMP_AIN6 == NRF_COMP_EXT_REF_6) && +#endif +#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) + (NRF_COMP_AIN7 == NRF_COMP_EXT_REF_7) && +#endif +#if defined(COMP_PSEL_PSEL_VddDiv2) + (NRF_COMP_VDD_DIV2 == NRF_COMP_VDD_DIV2) && +#endif +#if defined(COMP_PSEL_PSEL_VddhDiv5) + (NRF_COMP_VDDH_DIV5 == NRF_COMP_VDDH_DIV5) && +#endif + 1, + "Definitions from nrf-comp.h do not match those from HAL"); #endif #ifndef COMP_MODE_SP_Normal @@ -122,24 +135,6 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_ISOURCE(0) != COMP_NRF_COMP_ISOURCE_10UA); #endif #endif -#if SHIM_NRF_COMP_DT_INST_REFSEL_IS_AREF(0) -#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference4 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN4); -#endif - -#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference5 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN5); -#endif - -#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference6 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN6); -#endif - -#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference7 -BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN7); -#endif -#endif - #if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(0) #ifndef COMP_REFSEL_REFSEL_Int1V8 BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_REFSEL(0) != COMP_NRF_COMP_REFSEL_INT_1V8); @@ -246,69 +241,69 @@ static int shim_nrf_comp_pm_callback(const struct device *dev, enum pm_device_ac } #if (NRF_COMP_HAS_AIN_AS_PIN) -static int shim_nrf_comp_psel_to_nrf(enum comp_nrf_comp_psel shim, +static int shim_nrf_comp_psel_to_nrf(uint8_t shim, nrf_comp_input_t *nrf) { if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { return -EINVAL; } - *nrf = shim_nrf_comp_ain_map[(uint32_t)shim]; + *nrf = shim_nrf_comp_ain_map[shim]; return 0; } #else -static int shim_nrf_comp_psel_to_nrf(enum comp_nrf_comp_psel shim, +static int shim_nrf_comp_psel_to_nrf(uint8_t shim, nrf_comp_input_t *nrf) { switch (shim) { - case COMP_NRF_COMP_PSEL_AIN0: + case NRF_COMP_AIN0: *nrf = NRF_COMP_INPUT_0; break; - case COMP_NRF_COMP_PSEL_AIN1: + case NRF_COMP_AIN1: *nrf = NRF_COMP_INPUT_1; break; - case COMP_NRF_COMP_PSEL_AIN2: + case NRF_COMP_AIN2: *nrf = NRF_COMP_INPUT_2; break; - case COMP_NRF_COMP_PSEL_AIN3: + case NRF_COMP_AIN3: *nrf = NRF_COMP_INPUT_3; break; #if defined(COMP_PSEL_PSEL_AnalogInput4) - case COMP_NRF_COMP_PSEL_AIN4: + case NRF_COMP_AIN4: *nrf = NRF_COMP_INPUT_4; break; #endif #if defined(COMP_PSEL_PSEL_AnalogInput5) - case COMP_NRF_COMP_PSEL_AIN5: + case NRF_COMP_AIN5: *nrf = NRF_COMP_INPUT_5; break; #endif #if defined(COMP_PSEL_PSEL_AnalogInput6) - case COMP_NRF_COMP_PSEL_AIN6: + case NRF_COMP_AIN6: *nrf = NRF_COMP_INPUT_6; break; #endif #if defined(COMP_PSEL_PSEL_AnalogInput7) - case COMP_NRF_COMP_PSEL_AIN7: + case NRF_COMP_AIN7: *nrf = NRF_COMP_INPUT_7; break; #endif #if defined(COMP_PSEL_PSEL_VddDiv2) - case COMP_NRF_COMP_PSEL_VDD_DIV2: + case NRF_COMP_AIN_VDD_DIV2: *nrf = NRF_COMP_VDD_DIV2; break; #endif #if defined(COMP_PSEL_PSEL_VddhDiv5) - case COMP_NRF_COMP_PSEL_VDDH_DIV5: + case NRF_COMP_AIN_VDDH_DIV5: *nrf = NRF_COMP_VDDH_DIV5; break; #endif @@ -382,57 +377,57 @@ static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim, #endif #if (NRF_COMP_HAS_AIN_AS_PIN) -static int shim_nrf_comp_extrefsel_to_nrf(enum comp_nrf_comp_extrefsel shim, +static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim, nrf_comp_ext_ref_t *nrf) { if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { return -EINVAL; } - *nrf = shim_nrf_comp_ain_map[(uint32_t)shim]; + *nrf = shim_nrf_comp_ain_map[shim]; return 0; } #else -static int shim_nrf_comp_extrefsel_to_nrf(enum comp_nrf_comp_extrefsel shim, +static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim, nrf_comp_ext_ref_t *nrf) { switch (shim) { - case COMP_NRF_COMP_EXTREFSEL_AIN0: + case NRF_COMP_AIN0: *nrf = NRF_COMP_EXT_REF_0; break; - case COMP_NRF_COMP_EXTREFSEL_AIN1: + case NRF_COMP_AIN1: *nrf = NRF_COMP_EXT_REF_1; break; - case COMP_NRF_COMP_EXTREFSEL_AIN2: + case NRF_COMP_AIN2: *nrf = NRF_COMP_EXT_REF_2; break; - case COMP_NRF_COMP_EXTREFSEL_AIN3: + case NRF_COMP_AIN3: *nrf = NRF_COMP_EXT_REF_3; break; #if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) - case COMP_NRF_COMP_EXTREFSEL_AIN4: + case NRF_COMP_AIN4: *nrf = NRF_COMP_EXT_REF_4; break; #endif #if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) - case COMP_NRF_COMP_EXTREFSEL_AIN5: + case NRF_COMP_AIN5: *nrf = NRF_COMP_EXT_REF_5; break; #endif #if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) - case COMP_NRF_COMP_EXTREFSEL_AIN6: + case NRF_COMP_AIN6: *nrf = NRF_COMP_EXT_REF_6; break; #endif #if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) - case COMP_NRF_COMP_EXTREFSEL_AIN7: + case NRF_COMP_AIN7: *nrf = NRF_COMP_EXT_REF_7; break; #endif diff --git a/drivers/comparator/comparator_nrf_lpcomp.c b/drivers/comparator/comparator_nrf_lpcomp.c index 623c7adacd4..6faba2b8669 100644 --- a/drivers/comparator/comparator_nrf_lpcomp.c +++ b/drivers/comparator/comparator_nrf_lpcomp.c @@ -21,14 +21,12 @@ #define SHIM_NRF_LPCOMP_DT_INST_REFSEL_IS_AREF(inst) \ DT_INST_ENUM_HAS_VALUE(inst, refsel, aref) -#define SHIM_NRF_LPCOMP_DT_INST_EXTREFSEL(inst) \ - _CONCAT(COMP_NRF_LPCOMP_EXTREFSEL_, DT_INST_STRING_TOKEN(inst, extrefsel)) +#define SHIM_NRF_LPCOMP_DT_INST_EXTREFSEL(inst) DT_INST_PROP(inst, extrefsel) #define SHIM_NRF_LPCOMP_DT_INST_ENABLE_HYST(inst) \ DT_INST_PROP(inst, enable_hyst) -#define SHIM_NRF_LPCOMP_DT_INST_PSEL(inst) \ - _CONCAT(COMP_NRF_LPCOMP_PSEL_, DT_INST_STRING_TOKEN(inst, psel)) +#define SHIM_NRF_LPCOMP_DT_INST_PSEL(inst) DT_INST_PROP(inst, psel) struct shim_nrf_lpcomp_data { nrfx_lpcomp_config_t config; @@ -40,10 +38,20 @@ struct shim_nrf_lpcomp_data { }; #if (NRF_LPCOMP_HAS_AIN_AS_PIN) -BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN0 == 0); -BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN7 == 7); -BUILD_ASSERT(COMP_NRF_LPCOMP_EXTREFSEL_AIN0 == 0); -BUILD_ASSERT(COMP_NRF_LPCOMP_EXTREFSEL_AIN1 == 1); +BUILD_ASSERT(NRF_COMP_AIN0 == 0); +BUILD_ASSERT(NRF_COMP_AIN7 == 7); +#else +BUILD_ASSERT((NRF_COMP_AIN0 == NRF_LPCOMP_INPUT_0) && + (NRF_COMP_AIN1 == NRF_LPCOMP_INPUT_1) && + (NRF_COMP_AIN2 == NRF_LPCOMP_INPUT_2) && + (NRF_COMP_AIN3 == NRF_LPCOMP_INPUT_3) && + (NRF_COMP_AIN4 == NRF_LPCOMP_INPUT_4) && + (NRF_COMP_AIN5 == NRF_LPCOMP_INPUT_5) && + (NRF_COMP_AIN6 == NRF_LPCOMP_INPUT_6) && + (NRF_COMP_AIN7 == NRF_LPCOMP_INPUT_7) && + (NRF_COMP_AIN0 == NRF_LPCOMP_EXT_REF_REF0) && + (NRF_COMP_AIN1 == NRF_LPCOMP_EXT_REF_REF1), + "Definitions from nrf-comp.h do not match those from HAL"); #endif #if (LPCOMP_REFSEL_RESOLUTION == 8) @@ -126,50 +134,50 @@ static int shim_nrf_lpcomp_pm_callback(const struct device *dev, enum pm_device_ } #if (NRF_LPCOMP_HAS_AIN_AS_PIN) -static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim, +static int shim_nrf_lpcomp_psel_to_nrf(uint8_t shim, nrf_lpcomp_input_t *nrf) { if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { return -EINVAL; } - *nrf = shim_nrf_comp_ain_map[(uint32_t)shim]; + *nrf = shim_nrf_comp_ain_map[shim]; return 0; } #else -static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim, +static int shim_nrf_lpcomp_psel_to_nrf(uint8_t shim, nrf_lpcomp_input_t *nrf) { switch (shim) { - case COMP_NRF_LPCOMP_PSEL_AIN0: + case NRF_COMP_AIN0: *nrf = NRF_LPCOMP_INPUT_0; break; - case COMP_NRF_LPCOMP_PSEL_AIN1: + case NRF_COMP_AIN1: *nrf = NRF_LPCOMP_INPUT_1; break; - case COMP_NRF_LPCOMP_PSEL_AIN2: + case NRF_COMP_AIN2: *nrf = NRF_LPCOMP_INPUT_2; break; - case COMP_NRF_LPCOMP_PSEL_AIN3: + case NRF_COMP_AIN3: *nrf = NRF_LPCOMP_INPUT_3; break; - case COMP_NRF_LPCOMP_PSEL_AIN4: + case NRF_COMP_AIN4: *nrf = NRF_LPCOMP_INPUT_4; break; - case COMP_NRF_LPCOMP_PSEL_AIN5: + case NRF_COMP_AIN5: *nrf = NRF_LPCOMP_INPUT_5; break; - case COMP_NRF_LPCOMP_PSEL_AIN6: + case NRF_COMP_AIN6: *nrf = NRF_LPCOMP_INPUT_6; break; - case COMP_NRF_LPCOMP_PSEL_AIN7: + case NRF_COMP_AIN7: *nrf = NRF_LPCOMP_INPUT_7; break; @@ -182,7 +190,7 @@ static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim, #endif #if (NRF_LPCOMP_HAS_AIN_AS_PIN) -static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim, +static int shim_nrf_lpcomp_extrefsel_to_nrf(uint8_t shim, nrf_lpcomp_ext_ref_t *nrf) { if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { @@ -193,15 +201,15 @@ static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim, return 0; } #else -static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim, +static int shim_nrf_lpcomp_extrefsel_to_nrf(uint8_t shim, nrf_lpcomp_ext_ref_t *nrf) { switch (shim) { - case COMP_NRF_LPCOMP_EXTREFSEL_AIN0: + case NRF_COMP_AIN0: *nrf = NRF_LPCOMP_EXT_REF_REF0; break; - case COMP_NRF_LPCOMP_EXTREFSEL_AIN1: + case NRF_COMP_AIN1: *nrf = NRF_LPCOMP_EXT_REF_REF1; break; diff --git a/include/zephyr/drivers/comparator/nrf_comp.h b/include/zephyr/drivers/comparator/nrf_comp.h index 59e1cbbb3ce..09c870f9a33 100644 --- a/include/zephyr/drivers/comparator/nrf_comp.h +++ b/include/zephyr/drivers/comparator/nrf_comp.h @@ -7,56 +7,13 @@ #ifndef ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_COMP_H_ #define ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_COMP_H_ +#include #include #ifdef __cplusplus extern "C" { #endif -/** Positive input selection */ -enum comp_nrf_comp_psel { - /** AIN0 external input */ - COMP_NRF_COMP_PSEL_AIN0, - /** AIN1 external input */ - COMP_NRF_COMP_PSEL_AIN1, - /** AIN2 external input */ - COMP_NRF_COMP_PSEL_AIN2, - /** AIN3 external input */ - COMP_NRF_COMP_PSEL_AIN3, - /** AIN4 external input */ - COMP_NRF_COMP_PSEL_AIN4, - /** AIN5 external input */ - COMP_NRF_COMP_PSEL_AIN5, - /** AIN6 external input */ - COMP_NRF_COMP_PSEL_AIN6, - /** AIN7 external input */ - COMP_NRF_COMP_PSEL_AIN7, - /** VDD / 2 */ - COMP_NRF_COMP_PSEL_VDD_DIV2, - /** VDDH / 5 */ - COMP_NRF_COMP_PSEL_VDDH_DIV5, -}; - -/** External reference selection */ -enum comp_nrf_comp_extrefsel { - /** AIN0 external input */ - COMP_NRF_COMP_EXTREFSEL_AIN0, - /** AIN1 external input */ - COMP_NRF_COMP_EXTREFSEL_AIN1, - /** AIN2 external input */ - COMP_NRF_COMP_EXTREFSEL_AIN2, - /** AIN3 external input */ - COMP_NRF_COMP_EXTREFSEL_AIN3, - /** AIN4 external input */ - COMP_NRF_COMP_EXTREFSEL_AIN4, - /** AIN5 external input */ - COMP_NRF_COMP_EXTREFSEL_AIN5, - /** AIN6 external input */ - COMP_NRF_COMP_EXTREFSEL_AIN6, - /** AIN7 external input */ - COMP_NRF_COMP_EXTREFSEL_AIN7, -}; - /** Reference selection */ enum comp_nrf_comp_refsel { /** Internal 1.2V reference */ @@ -103,14 +60,14 @@ enum comp_nrf_comp_isource { * @note Hysteresis up in volts = ((th_up + 1) / 64) * ref */ struct comp_nrf_comp_se_config { - /** Positive input selection */ - enum comp_nrf_comp_psel psel; + /** Positive input selection defined by the NRF_COMP_AIN defines */ + uint8_t psel; /** Speed mode selection */ enum comp_nrf_comp_sp_mode sp_mode; /** Current source configuration */ enum comp_nrf_comp_isource isource; - /** External reference selection */ - enum comp_nrf_comp_extrefsel extrefsel; + /** External reference input selection defined by the NRF_COMP_AIN defines */ + uint8_t extrefsel; /** Reference selection */ enum comp_nrf_comp_refsel refsel; /** Hysteresis down threshold configuration */ @@ -133,14 +90,14 @@ int comp_nrf_comp_configure_se(const struct device *dev, /** Differential mode configuration structure */ struct comp_nrf_comp_diff_config { - /** Positive input selection */ - enum comp_nrf_comp_psel psel; + /** Positive input selection defined by the NRF_COMP_AIN defines */ + uint8_t psel; /** Speed mode selection */ enum comp_nrf_comp_sp_mode sp_mode; /** Current source configuration */ enum comp_nrf_comp_isource isource; - /** Negative input selection */ - enum comp_nrf_comp_extrefsel extrefsel; + /** Negative input selection defined by the NRF_COMP_AIN defines */ + uint8_t extrefsel; /** Hysteresis configuration */ bool enable_hyst; }; diff --git a/include/zephyr/drivers/comparator/nrf_lpcomp.h b/include/zephyr/drivers/comparator/nrf_lpcomp.h index e1f2343a8de..1cae4caae33 100644 --- a/include/zephyr/drivers/comparator/nrf_lpcomp.h +++ b/include/zephyr/drivers/comparator/nrf_lpcomp.h @@ -7,40 +7,13 @@ #ifndef ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_ #define ZEPHYR_INCLUDE_DRIVERS_COMP_NRF_LPCOMP_H_ +#include #include #ifdef __cplusplus extern "C" { #endif -/** Positive input selection */ -enum comp_nrf_lpcomp_psel { - /** AIN0 external input */ - COMP_NRF_LPCOMP_PSEL_AIN0, - /** AIN1 external input */ - COMP_NRF_LPCOMP_PSEL_AIN1, - /** AIN2 external input */ - COMP_NRF_LPCOMP_PSEL_AIN2, - /** AIN3 external input */ - COMP_NRF_LPCOMP_PSEL_AIN3, - /** AIN4 external input */ - COMP_NRF_LPCOMP_PSEL_AIN4, - /** AIN5 external input */ - COMP_NRF_LPCOMP_PSEL_AIN5, - /** AIN6 external input */ - COMP_NRF_LPCOMP_PSEL_AIN6, - /** AIN7 external input */ - COMP_NRF_LPCOMP_PSEL_AIN7, -}; - -/** External reference selection */ -enum comp_nrf_lpcomp_extrefsel { - /** AIN0 external input */ - COMP_NRF_LPCOMP_EXTREFSEL_AIN0, - /** AIN1 external input */ - COMP_NRF_LPCOMP_EXTREFSEL_AIN1, -}; - /** Reference selection */ enum comp_nrf_lpcomp_refsel { /** Use (VDD * (1/8)) as reference */ @@ -83,10 +56,10 @@ enum comp_nrf_lpcomp_refsel { * @note extrefsel is only used if refsel == COMP_NRF_LPCOMP_REFSEL_AREF */ struct comp_nrf_lpcomp_config { - /** Positive input selection */ - enum comp_nrf_lpcomp_psel psel; - /** External reference selection */ - enum comp_nrf_lpcomp_extrefsel extrefsel; + /** Positive input selection defined by the NRF_COMP_AIN defines */ + uint8_t psel; + /** External reference input selection defined by the NRF_COMP_AIN defines */ + uint8_t extrefsel; /** Reference selection */ enum comp_nrf_lpcomp_refsel refsel; /** Hysteresis configuration */ From a25165022615254f016fb6d4dc5b90936df4ee07 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Thu, 28 Aug 2025 13:26:21 +0200 Subject: [PATCH 3/7] [nrf fromtree] tests: comparator: nordic: Align boards overlays for changed input types Align samples and tests boards overlays for changed comparator input types. Signed-off-by: Jakub Zymelka (cherry picked from commit 6d7f42936943c6d8efdab5fafd57dcb340763f65) --- .../nrf54l15dk_nrf54l15_cpuapp_comparator.overlay | 4 +++- .../boards/bl54l15_dvk_nrf54l15_cpuapp.overlay | 6 ++++-- .../boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay | 6 ++++-- .../comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay | 6 ++++-- .../comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay | 6 ++++-- .../boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay | 6 ++++-- tests/boards/nrf/comp/src/test.c | 14 ++++++-------- .../build_all/comparator/nrf_comp/diff.overlay | 6 ++++-- .../build_all/comparator/nrf_comp/se.overlay | 4 +++- .../build_all/comparator/nrf_comp/se_aref.overlay | 6 ++++-- .../comparator/nrf_lpcomp/ext_ref.overlay | 4 +++- .../comparator/nrf_lpcomp/int_ref.overlay | 6 ++++-- .../boards/bl54l15_dvk_nrf54l15_cpuapp.overlay | 4 +++- .../boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay | 4 +++- .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 4 +++- .../boards/nrf54h20dk_nrf54h20_cpuapp.overlay | 4 +++- .../boards/nrf54l15dk_nrf54l15_cpuapp.overlay | 4 +++- .../boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay | 4 +++- .../boards/bl54l15_dvk_nrf54l15_cpuapp.overlay | 4 +++- .../boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay | 4 +++- .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 4 +++- .../boards/nrf54h20dk_nrf54h20_cpuapp.overlay | 4 +++- .../boards/nrf54l15dk_nrf54l15_cpuapp.overlay | 4 +++- .../boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay | 4 +++- 24 files changed, 83 insertions(+), 39 deletions(-) diff --git a/samples/boards/nordic/system_off/boards/nrf54l15dk_nrf54l15_cpuapp_comparator.overlay b/samples/boards/nordic/system_off/boards/nrf54l15dk_nrf54l15_cpuapp_comparator.overlay index f0b39b45620..ce93cee141a 100644 --- a/samples/boards/nordic/system_off/boards/nrf54l15dk_nrf54l15_cpuapp_comparator.overlay +++ b/samples/boards/nordic/system_off/boards/nrf54l15dk_nrf54l15_cpuapp_comparator.overlay @@ -1,6 +1,8 @@ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN4"; + psel = ; refsel = "VDD_4_8"; status = "okay"; }; diff --git a/tests/boards/nrf/comp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay b/tests/boards/nrf/comp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay index aaf1006300a..c928e7eff24 100644 --- a/tests/boards/nrf/comp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay +++ b/tests/boards/nrf/comp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay @@ -5,6 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + / { aliases { test-comp = ∁ @@ -30,9 +32,9 @@ &comp { status = "okay"; - psel = "AIN4"; + psel = ; refsel = "AREF"; - extrefsel = "AIN3"; + extrefsel = ; sp-mode = "NORMAL"; th-up = <36>; th-down = <30>; diff --git a/tests/boards/nrf/comp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay b/tests/boards/nrf/comp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay index aaf1006300a..c928e7eff24 100644 --- a/tests/boards/nrf/comp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay +++ b/tests/boards/nrf/comp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay @@ -5,6 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + / { aliases { test-comp = ∁ @@ -30,9 +32,9 @@ &comp { status = "okay"; - psel = "AIN4"; + psel = ; refsel = "AREF"; - extrefsel = "AIN3"; + extrefsel = ; sp-mode = "NORMAL"; th-up = <36>; th-down = <30>; diff --git a/tests/boards/nrf/comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/tests/boards/nrf/comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay index 4e9e898ea18..27008ba6760 100644 --- a/tests/boards/nrf/comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay +++ b/tests/boards/nrf/comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + / { aliases { test-comp = ∁ @@ -25,9 +27,9 @@ &comp { status = "okay"; - psel = "AIN5"; + psel = ; refsel = "AREF"; - extrefsel = "AIN1"; + extrefsel = ; sp-mode = "HIGH"; th-up = <36>; th-down = <30>; diff --git a/tests/boards/nrf/comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/tests/boards/nrf/comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay index d6492e37c34..5695f7d90dc 100644 --- a/tests/boards/nrf/comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +++ b/tests/boards/nrf/comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + / { aliases { test-comp = ∁ @@ -29,9 +31,9 @@ &comp { status = "okay"; - psel = "AIN4"; + psel = ; refsel = "AREF"; - extrefsel = "AIN3"; + extrefsel = ; sp-mode = "NORMAL"; th-up = <36>; th-down = <30>; diff --git a/tests/boards/nrf/comp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay b/tests/boards/nrf/comp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay index 45cefc0815b..94087309aee 100644 --- a/tests/boards/nrf/comp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay +++ b/tests/boards/nrf/comp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay @@ -5,6 +5,8 @@ * AIN4 (P1.06) tied to VDD */ +#include + / { aliases { test-comp = ∁ @@ -22,9 +24,9 @@ &comp { status = "okay"; - psel = "AIN4"; + psel = ; refsel = "AREF"; - extrefsel = "AIN3"; + extrefsel = ; sp-mode = "NORMAL"; th-up = <36>; th-down = <30>; diff --git a/tests/boards/nrf/comp/src/test.c b/tests/boards/nrf/comp/src/test.c index 1d1876e76fa..481760da5bd 100644 --- a/tests/boards/nrf/comp/src/test.c +++ b/tests/boards/nrf/comp/src/test.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -13,14 +14,11 @@ static const struct device *test_dev = DEVICE_DT_GET(DT_ALIAS(test_comp)); static const struct gpio_dt_spec test_pin_1 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), first_gpios); static const struct gpio_dt_spec test_pin_2 = GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), second_gpios); -#define TEST_COMP_SE_PSEL_AIN _CONCAT(COMP_NRF_COMP_PSEL_AIN, \ - CONFIG_TEST_COMP_SE_PSEL_AIN_INDEX) -#define TEST_COMP_SE_EXTREFSEL_AIN _CONCAT(COMP_NRF_COMP_EXTREFSEL_AIN, \ - CONFIG_TEST_COMP_SE_EXTREFSEL_AIN_INDEX) -#define TEST_COMP_DIFF_PSEL_AIN _CONCAT(COMP_NRF_COMP_PSEL_AIN, \ - CONFIG_TEST_COMP_DIFF_PSEL_AIN_INDEX) -#define TEST_COMP_DIFF_EXTREFSEL_AIN _CONCAT(COMP_NRF_COMP_EXTREFSEL_AIN, \ - CONFIG_TEST_COMP_DIFF_EXTREFSEL_AIN_INDEX) +#define TEST_COMP_SE_PSEL_AIN _CONCAT(NRF_COMP_AIN, CONFIG_TEST_COMP_SE_PSEL_AIN_INDEX) +#define TEST_COMP_SE_EXTREFSEL_AIN _CONCAT(NRF_COMP_AIN, CONFIG_TEST_COMP_SE_EXTREFSEL_AIN_INDEX) +#define TEST_COMP_DIFF_PSEL_AIN _CONCAT(NRF_COMP_AIN, CONFIG_TEST_COMP_DIFF_PSEL_AIN_INDEX) +#define TEST_COMP_DIFF_EXTREFSEL_AIN \ + _CONCAT(NRF_COMP_AIN, CONFIG_TEST_COMP_DIFF_EXTREFSEL_AIN_INDEX) struct comp_nrf_comp_se_config comp_se_config = { .psel = TEST_COMP_SE_PSEL_AIN, diff --git a/tests/drivers/build_all/comparator/nrf_comp/diff.overlay b/tests/drivers/build_all/comparator/nrf_comp/diff.overlay index 8b8e9a02c2b..56b4249d3c5 100644 --- a/tests/drivers/build_all/comparator/nrf_comp/diff.overlay +++ b/tests/drivers/build_all/comparator/nrf_comp/diff.overlay @@ -4,10 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "DIFF"; - psel = "AIN0"; - extrefsel = "AIN1"; + psel = ; + extrefsel = ; sp-mode = "HIGH"; isource = "DISABLED"; status = "okay"; diff --git a/tests/drivers/build_all/comparator/nrf_comp/se.overlay b/tests/drivers/build_all/comparator/nrf_comp/se.overlay index e4eb56f61a9..67798ab4bcf 100644 --- a/tests/drivers/build_all/comparator/nrf_comp/se.overlay +++ b/tests/drivers/build_all/comparator/nrf_comp/se.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "SE"; - psel = "AIN0"; + psel = ; refsel = "INT_1V2"; sp-mode = "HIGH"; th-up = <36>; diff --git a/tests/drivers/build_all/comparator/nrf_comp/se_aref.overlay b/tests/drivers/build_all/comparator/nrf_comp/se_aref.overlay index 0d36a3e40b4..04216a7ac10 100644 --- a/tests/drivers/build_all/comparator/nrf_comp/se_aref.overlay +++ b/tests/drivers/build_all/comparator/nrf_comp/se_aref.overlay @@ -4,10 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "SE"; - psel = "AIN0"; - extrefsel = "AIN1"; + psel = ; + extrefsel = ; refsel = "AREF"; sp-mode = "HIGH"; th-up = <36>; diff --git a/tests/drivers/build_all/comparator/nrf_lpcomp/ext_ref.overlay b/tests/drivers/build_all/comparator/nrf_lpcomp/ext_ref.overlay index 95e44fbed3d..0d990b2c3f8 100644 --- a/tests/drivers/build_all/comparator/nrf_lpcomp/ext_ref.overlay +++ b/tests/drivers/build_all/comparator/nrf_lpcomp/ext_ref.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN0"; + psel = ; refsel = "VDD_4_8"; status = "okay"; }; diff --git a/tests/drivers/build_all/comparator/nrf_lpcomp/int_ref.overlay b/tests/drivers/build_all/comparator/nrf_lpcomp/int_ref.overlay index 7aadd8b3fae..a42ad2f13a1 100644 --- a/tests/drivers/build_all/comparator/nrf_lpcomp/int_ref.overlay +++ b/tests/drivers/build_all/comparator/nrf_lpcomp/int_ref.overlay @@ -4,10 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN0"; + psel = ; refsel = "AREF"; - extrefsel = "AIN1"; + extrefsel = ; status = "okay"; }; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay index ddcf8d26cad..84d3b9f5759 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay @@ -5,9 +5,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "SE"; - psel = "AIN4"; /* P1.11 */ + psel = ; /* P1.11 */ refsel = "INT_1V2"; sp-mode = "HIGH"; th-up = <63>; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay index ddcf8d26cad..84d3b9f5759 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay @@ -5,9 +5,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "SE"; - psel = "AIN4"; /* P1.11 */ + psel = ; /* P1.11 */ refsel = "INT_1V2"; sp-mode = "HIGH"; th-up = <63>; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf5340dk_nrf5340_cpuapp.overlay index e11bdcd3173..68fea53e2b4 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "SE"; - psel = "AIN0"; /* P0.04 */ + psel = ; /* P0.04 */ refsel = "VDD"; sp-mode = "HIGH"; th-up = <34>; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay index f90c2051255..5923e3ab07c 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "SE"; - psel = "AIN2"; /* P1.02 */ + psel = ; /* P1.02 */ refsel = "INT_1V2"; sp-mode = "HIGH"; th-up = <63>; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay index 3a7a8f0ef81..925417d48ab 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "SE"; - psel = "AIN4"; /* P1.11 */ + psel = ; /* P1.11 */ refsel = "INT_1V2"; sp-mode = "HIGH"; th-up = <63>; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay index 2709df53195..623bfd9c45f 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_comp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { main-mode = "SE"; - psel = "AIN1"; /* P1.31 */ + psel = ; /* P1.31 */ refsel = "INT_1V2"; sp-mode = "HIGH"; th-up = <63>; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay index 58e055a0240..e208b85b2ae 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/bl54l15_dvk_nrf54l15_cpuapp.overlay @@ -5,9 +5,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN4"; /* P1.11 */ + psel = ; /* P1.11 */ refsel = "VDD_4_8"; status = "okay"; }; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay index 58e055a0240..e208b85b2ae 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/bl54l15u_dvk_nrf54l15_cpuapp.overlay @@ -5,9 +5,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN4"; /* P1.11 */ + psel = ; /* P1.11 */ refsel = "VDD_4_8"; status = "okay"; }; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf5340dk_nrf5340_cpuapp.overlay index d35a20dfc22..0c571fa21b8 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN0"; /* P0.04 */ + psel = ; /* P0.04 */ refsel = "VDD_4_8"; status = "okay"; }; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay index 349cd7051f9..66306268a11 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN2"; /* P1.02 */ + psel = ; /* P1.02 */ refsel = "VDD_4_8"; status = "okay"; }; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay index ebb652bdd87..e82d8b98521 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN4"; /* P1.11 */ + psel = ; /* P1.11 */ refsel = "VDD_4_8"; status = "okay"; }; diff --git a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay index 0f51a9951a1..db097a9fd6f 100644 --- a/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay +++ b/tests/drivers/comparator/gpio_loopback/snippets/nrf_lpcomp/boards/nrf54lm20dk_nrf54lm20a_cpuapp.overlay @@ -4,9 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + &comp { compatible = "nordic,nrf-lpcomp"; - psel = "AIN1"; /* P1.31 */ + psel = ; /* P1.31 */ refsel = "VDD_4_8"; status = "okay"; }; From 8fae201074c5c0496f40df46f94d2261c978b695 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 22 Jul 2025 09:59:36 +0200 Subject: [PATCH 4/7] [nrf fromlist] dt-bindings: adc: nrf-saadc: Remove platform dependencies Remove platform dependencies to make dt-bindings more generic. Upstream PR #: 93497 Signed-off-by: Jakub Zymelka --- .../dt-bindings/adc/nrf-saadc-haltium.h | 19 --------- .../zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h | 15 ------- include/zephyr/dt-bindings/adc/nrf-saadc-v2.h | 14 ------- include/zephyr/dt-bindings/adc/nrf-saadc-v3.h | 14 ------- include/zephyr/dt-bindings/adc/nrf-saadc.h | 41 +++++++++++++++---- 5 files changed, 32 insertions(+), 71 deletions(-) delete mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-haltium.h delete mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h delete mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-v2.h delete mode 100644 include/zephyr/dt-bindings/adc/nrf-saadc-v3.h diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-haltium.h b/include/zephyr/dt-bindings/adc/nrf-saadc-haltium.h deleted file mode 100644 index e0552297522..00000000000 --- a/include/zephyr/dt-bindings/adc/nrf-saadc-haltium.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2025 Nordic Semiconductor ASA - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_HALTIUM_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_HALTIUM_H_ - -#include - -#define NRF_SAADC_AIN8 9 -#define NRF_SAADC_AIN9 10 -#define NRF_SAADC_AIN10 11 -#define NRF_SAADC_AIN11 12 -#define NRF_SAADC_AIN12 13 -#define NRF_SAADC_AIN13 14 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_HALTIUM_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h b/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h deleted file mode 100644 index 19da4ff6020..00000000000 --- a/include/zephyr/dt-bindings/adc/nrf-saadc-nrf54l.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Nordic Semiconductor ASA - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ - -#include - -#define NRF_SAADC_AVDD 10 -#define NRF_SAADC_DVDD 11 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_NRF54L_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h b/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h deleted file mode 100644 index f5f72bec829..00000000000 --- a/include/zephyr/dt-bindings/adc/nrf-saadc-v2.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Nordic Semiconductor ASA - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ - -#include - -#define NRF_SAADC_VDD 9 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V2_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h b/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h deleted file mode 100644 index c51bab1a91e..00000000000 --- a/include/zephyr/dt-bindings/adc/nrf-saadc-v3.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * Copyright (c) 2024 Nordic Semiconductor ASA - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ - -#include - -#define NRF_SAADC_VDDHDIV5 13 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_V3_H_ */ diff --git a/include/zephyr/dt-bindings/adc/nrf-saadc.h b/include/zephyr/dt-bindings/adc/nrf-saadc.h index e5a86150cd4..21f9cf9fb2f 100644 --- a/include/zephyr/dt-bindings/adc/nrf-saadc.h +++ b/include/zephyr/dt-bindings/adc/nrf-saadc.h @@ -7,6 +7,21 @@ #ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ #define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ +#define NRF_SAADC_AIN0 0 +#define NRF_SAADC_AIN1 1 +#define NRF_SAADC_AIN2 2 +#define NRF_SAADC_AIN3 3 +#define NRF_SAADC_AIN4 4 +#define NRF_SAADC_AIN5 5 +#define NRF_SAADC_AIN6 6 +#define NRF_SAADC_AIN7 7 +#define NRF_SAADC_AIN8 8 +#define NRF_SAADC_AIN9 9 +#define NRF_SAADC_AIN10 10 +#define NRF_SAADC_AIN11 11 +#define NRF_SAADC_AIN12 12 +#define NRF_SAADC_AIN13 13 + /** * @brief Short ADC negative input to ground * @@ -30,14 +45,22 @@ * zephyr,input-positive = ; * @endcode */ -#define NRF_SAADC_GND 0 -#define NRF_SAADC_AIN0 1 -#define NRF_SAADC_AIN1 2 -#define NRF_SAADC_AIN2 3 -#define NRF_SAADC_AIN3 4 -#define NRF_SAADC_AIN4 5 -#define NRF_SAADC_AIN5 6 -#define NRF_SAADC_AIN6 7 -#define NRF_SAADC_AIN7 8 +#define NRF_SAADC_GND (NRF_SAADC_AIN_VDD_SHIM_OFFSET - 1) + +#define NRF_SAADC_AIN_VDD_SHIM_OFFSET 128 +#define NRF_SAADC_VDD (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 0) +#define NRF_SAADC_VDDDIV2 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 1) +#define NRF_SAADC_AVDD (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 2) +#define NRF_SAADC_DVDD (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 3) +#define NRF_SAADC_VDDHDIV5 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 4) +#define NRF_SAADC_VDDL (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 5) +#define NRF_SAADC_DECB (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 6) +#define NRF_SAADC_VSS (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 7) +#define NRF_SAADC_VDDAO3V0 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 8) +#define NRF_SAADC_VDDAO1V8 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 9) +#define NRF_SAADC_VDDAO0V8 (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 10) +#define NRF_SAADC_VDDRF (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 11) +#define NRF_SAADC_VBAT (NRF_SAADC_AIN_VDD_SHIM_OFFSET + 12) +#define NRF_SAADC_AIN_DISABLED 255 /* UINT8_MAX */ #endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_SAADC_H_ */ From 803bcd7261decfe8cdcbadf68b76c4bea4d94776 Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 22 Jul 2025 10:19:26 +0200 Subject: [PATCH 5/7] [nrf fromlist] dts: nordic: Switch saadc pin definitions for generic ones Switch saadc pin definitions for generic ones defined in nrf-saadc.h Upstream PR #: 93497 Signed-off-by: Jakub Zymelka --- dts/arm/nordic/nrf52805.dtsi | 2 +- dts/arm/nordic/nrf52810.dtsi | 2 +- dts/arm/nordic/nrf52811.dtsi | 2 +- dts/arm/nordic/nrf52832.dtsi | 2 +- dts/arm/nordic/nrf52833.dtsi | 2 +- dts/arm/nordic/nrf52840.dtsi | 2 +- dts/arm/nordic/nrf5340_cpuapp.dtsi | 2 +- dts/arm/nordic/nrf5340_cpuappns.dtsi | 2 +- dts/arm/nordic/nrf91.dtsi | 2 +- dts/arm/nordic/nrf91ns.dtsi | 2 +- dts/vendor/nordic/nrf54h20.dtsi | 2 +- dts/vendor/nordic/nrf54l_05_10_15.dtsi | 2 +- dts/vendor/nordic/nrf54lm20a.dtsi | 2 +- dts/vendor/nordic/nrf9280.dtsi | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dts/arm/nordic/nrf52805.dtsi b/dts/arm/nordic/nrf52805.dtsi index 2134605c9f8..7951c9516ad 100644 --- a/dts/arm/nordic/nrf52805.dtsi +++ b/dts/arm/nordic/nrf52805.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52810.dtsi b/dts/arm/nordic/nrf52810.dtsi index 6e09220e78b..4a1ef2bcedd 100644 --- a/dts/arm/nordic/nrf52810.dtsi +++ b/dts/arm/nordic/nrf52810.dtsi @@ -2,7 +2,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52811.dtsi b/dts/arm/nordic/nrf52811.dtsi index 12d0a0ea4d6..d0321b85736 100644 --- a/dts/arm/nordic/nrf52811.dtsi +++ b/dts/arm/nordic/nrf52811.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52832.dtsi b/dts/arm/nordic/nrf52832.dtsi index eef2297c43b..1513c0da811 100644 --- a/dts/arm/nordic/nrf52832.dtsi +++ b/dts/arm/nordic/nrf52832.dtsi @@ -2,7 +2,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52833.dtsi b/dts/arm/nordic/nrf52833.dtsi index 1b3620aa01c..114399a0c28 100644 --- a/dts/arm/nordic/nrf52833.dtsi +++ b/dts/arm/nordic/nrf52833.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf52840.dtsi b/dts/arm/nordic/nrf52840.dtsi index f19383ba7e7..18354d20197 100644 --- a/dts/arm/nordic/nrf52840.dtsi +++ b/dts/arm/nordic/nrf52840.dtsi @@ -2,7 +2,7 @@ #include #include -#include +#include #include / { diff --git a/dts/arm/nordic/nrf5340_cpuapp.dtsi b/dts/arm/nordic/nrf5340_cpuapp.dtsi index b4c077ea2bf..15d4f487f82 100644 --- a/dts/arm/nordic/nrf5340_cpuapp.dtsi +++ b/dts/arm/nordic/nrf5340_cpuapp.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include / { cpus { diff --git a/dts/arm/nordic/nrf5340_cpuappns.dtsi b/dts/arm/nordic/nrf5340_cpuappns.dtsi index 763e9ca7839..25b2d870c11 100644 --- a/dts/arm/nordic/nrf5340_cpuappns.dtsi +++ b/dts/arm/nordic/nrf5340_cpuappns.dtsi @@ -8,7 +8,7 @@ #include #include -#include +#include / { cpus { diff --git a/dts/arm/nordic/nrf91.dtsi b/dts/arm/nordic/nrf91.dtsi index 7b7d4891651..9bcac2bd929 100644 --- a/dts/arm/nordic/nrf91.dtsi +++ b/dts/arm/nordic/nrf91.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include / { cpus { diff --git a/dts/arm/nordic/nrf91ns.dtsi b/dts/arm/nordic/nrf91ns.dtsi index e44bbcde0a4..9ab22c6f7ca 100644 --- a/dts/arm/nordic/nrf91ns.dtsi +++ b/dts/arm/nordic/nrf91ns.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include / { cpus { diff --git a/dts/vendor/nordic/nrf54h20.dtsi b/dts/vendor/nordic/nrf54h20.dtsi index 4644cb383ec..8a468bd846d 100644 --- a/dts/vendor/nordic/nrf54h20.dtsi +++ b/dts/vendor/nordic/nrf54h20.dtsi @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/dts/vendor/nordic/nrf54l_05_10_15.dtsi b/dts/vendor/nordic/nrf54l_05_10_15.dtsi index 95c27375038..cb2dbf0e467 100644 --- a/dts/vendor/nordic/nrf54l_05_10_15.dtsi +++ b/dts/vendor/nordic/nrf54l_05_10_15.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include /delete-node/ &sw_pwm; diff --git a/dts/vendor/nordic/nrf54lm20a.dtsi b/dts/vendor/nordic/nrf54lm20a.dtsi index d1e6d1b0d28..a49d6b2f914 100644 --- a/dts/vendor/nordic/nrf54lm20a.dtsi +++ b/dts/vendor/nordic/nrf54lm20a.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include /delete-node/ &sw_pwm; diff --git a/dts/vendor/nordic/nrf9280.dtsi b/dts/vendor/nordic/nrf9280.dtsi index fb27488e9dc..e1a448292ef 100644 --- a/dts/vendor/nordic/nrf9280.dtsi +++ b/dts/vendor/nordic/nrf9280.dtsi @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include From 0d31726e976bca5c36261a5701b70d2e6484721c Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 22 Jul 2025 12:40:20 +0200 Subject: [PATCH 6/7] [nrf fromlist] drivers: adc: nrfx_saadc: Remove platform dependencies Make the saadc driver more generic by including a generic header file for analog peripherals and removing platform dependencies. Upstream PR #: 93497 Signed-off-by: Jakub Zymelka --- drivers/adc/adc_nrfx_saadc.c | 176 ++++------------------------------- 1 file changed, 18 insertions(+), 158 deletions(-) diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index 06035e2c3c5..f4b29886609 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -6,9 +6,7 @@ #include "adc_context.h" #include -#include -#include -#include +#include #include #include #include @@ -18,91 +16,22 @@ LOG_MODULE_REGISTER(adc_nrfx_saadc, CONFIG_ADC_LOG_LEVEL); #define DT_DRV_COMPAT nordic_nrf_saadc -#if (NRF_SAADC_HAS_AIN_AS_PIN) - -#if defined(CONFIG_NRF_PLATFORM_HALTIUM) -static const uint32_t saadc_psels[NRF_SAADC_AIN13 + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - [NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - [NRF_SAADC_AIN8] = NRF_PIN_PORT_TO_PIN_NUMBER(0U, 9), - [NRF_SAADC_AIN9] = NRF_PIN_PORT_TO_PIN_NUMBER(1U, 9), - [NRF_SAADC_AIN10] = NRF_PIN_PORT_TO_PIN_NUMBER(2U, 9), - [NRF_SAADC_AIN11] = NRF_PIN_PORT_TO_PIN_NUMBER(3U, 9), - [NRF_SAADC_AIN12] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 9), - [NRF_SAADC_AIN13] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 9), -}; -#elif defined(CONFIG_SOC_NRF54L05) || defined(CONFIG_SOC_NRF54L10) || defined(CONFIG_SOC_NRF54L15) -static const uint32_t saadc_psels[NRF_SAADC_DVDD + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - [NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), - [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), - [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1), - [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1), - [NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD, - [NRF_SAADC_AVDD] = NRF_SAADC_INPUT_AVDD, - [NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD, -}; -#elif defined(NRF54LM20A_ENGA_XXAA) -static const uint32_t saadc_psels[NRF_SAADC_DVDD + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(31U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(30U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(29U, 1), - [NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - [NRF_SAADC_VDD] = NRF_SAADC_INPUT_VDD, - [NRF_SAADC_AVDD] = NRF_SAADC_INPUT_AVDD, - [NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD, -}; -#elif defined(NRF54LV10A_ENGA_XXAA) -static const uint32_t saadc_psels[NRF_SAADC_AIN7 + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - [NRF_SAADC_AIN4] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - [NRF_SAADC_AIN5] = NRF_PIN_PORT_TO_PIN_NUMBER(10U, 1), - [NRF_SAADC_AIN6] = NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), - [NRF_SAADC_AIN7] = NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), -}; -#elif defined(NRF54LS05B_ENGA_XXAA) -static const uint32_t saadc_psels[NRF_SAADC_AIN3 + 1] = { - [NRF_SAADC_AIN0] = NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - [NRF_SAADC_AIN1] = NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - [NRF_SAADC_AIN2] = NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - [NRF_SAADC_AIN3] = NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), -}; -#endif - -#else -BUILD_ASSERT((NRF_SAADC_AIN0 == NRF_SAADC_INPUT_AIN0) && - (NRF_SAADC_AIN1 == NRF_SAADC_INPUT_AIN1) && - (NRF_SAADC_AIN2 == NRF_SAADC_INPUT_AIN2) && - (NRF_SAADC_AIN3 == NRF_SAADC_INPUT_AIN3) && - (NRF_SAADC_AIN4 == NRF_SAADC_INPUT_AIN4) && - (NRF_SAADC_AIN5 == NRF_SAADC_INPUT_AIN5) && - (NRF_SAADC_AIN6 == NRF_SAADC_INPUT_AIN6) && - (NRF_SAADC_AIN7 == NRF_SAADC_INPUT_AIN7) && +BUILD_ASSERT((NRF_SAADC_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0) && + (NRF_SAADC_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1) && + (NRF_SAADC_AIN2 == NRFX_ANALOG_EXTERNAL_AIN2) && + (NRF_SAADC_AIN3 == NRFX_ANALOG_EXTERNAL_AIN3) && + (NRF_SAADC_AIN4 == NRFX_ANALOG_EXTERNAL_AIN4) && + (NRF_SAADC_AIN5 == NRFX_ANALOG_EXTERNAL_AIN5) && + (NRF_SAADC_AIN6 == NRFX_ANALOG_EXTERNAL_AIN6) && + (NRF_SAADC_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7) && #if defined(SAADC_CH_PSELP_PSELP_VDDHDIV5) - (NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5) && + (NRF_SAADC_VDDHDIV5 == NRFX_ANALOG_INTERNAL_VDDHDIV5) && #endif #if defined(SAADC_CH_PSELP_PSELP_VDD) - (NRF_SAADC_VDD == NRF_SAADC_INPUT_VDD) && + (NRF_SAADC_VDD == NRFX_ANALOG_INTERNAL_VDD) && #endif 1, - "Definitions from nrf-adc.h do not match those from nrf_saadc.h"); -#endif + "Definitions from nrf-saadc.h do not match those from nrfx_analog_common.h"); struct driver_data { struct adc_context ctx; @@ -184,46 +113,6 @@ static int acq_time_set(nrf_saadc_channel_config_t *ch_cfg, uint16_t acquisition return 0; } -static int input_assign(nrf_saadc_input_t *pin_p, - nrf_saadc_input_t *pin_n, - const struct adc_channel_cfg *channel_cfg) -{ -#if (NRF_SAADC_HAS_AIN_AS_PIN) - if (channel_cfg->input_positive > ARRAY_SIZE(saadc_psels) || - channel_cfg->input_positive < NRF_SAADC_AIN0) { - LOG_ERR("Invalid analog positive input number: %d", channel_cfg->input_positive); - return -EINVAL; - } - - *pin_p = saadc_psels[channel_cfg->input_positive]; - - if (channel_cfg->differential) { - if (channel_cfg->input_negative > ARRAY_SIZE(saadc_psels) || - (IS_ENABLED(CONFIG_NRF_PLATFORM_HALTIUM) && - (channel_cfg->input_positive > NRF_SAADC_AIN7) != - (channel_cfg->input_negative > NRF_SAADC_AIN7))) { - LOG_ERR("Invalid analog negative input number: %d", - channel_cfg->input_negative); - return -EINVAL; - } - *pin_n = channel_cfg->input_negative == NRF_SAADC_GND ? - NRF_SAADC_INPUT_DISABLED : - saadc_psels[channel_cfg->input_negative]; - } else { - *pin_n = NRF_SAADC_INPUT_DISABLED; - } -#else - *pin_p = channel_cfg->input_positive; - *pin_n = (channel_cfg->differential && (channel_cfg->input_negative != NRF_SAADC_GND)) - ? channel_cfg->input_negative - : NRF_SAADC_INPUT_DISABLED; -#endif - LOG_DBG("ADC positive input: %d", *pin_p); - LOG_DBG("ADC negative input: %d", *pin_n); - - return 0; -} - static int gain_set(nrf_saadc_channel_config_t *ch_cfg, enum adc_gain gain) { #if NRF_SAADC_HAS_CH_GAIN @@ -333,6 +222,11 @@ static int adc_nrfx_channel_setup(const struct device *dev, #endif }, .channel_index = channel_cfg->channel_id, + .pin_p = channel_cfg->input_positive, + .pin_n = (channel_cfg->differential && + (channel_cfg->input_negative != NRF_SAADC_GND)) + ? channel_cfg->input_negative + : NRF_SAADC_AIN_DISABLED, }; if (channel_cfg->channel_id >= SAADC_CH_NUM) { @@ -342,11 +236,6 @@ static int adc_nrfx_channel_setup(const struct device *dev, ch_cfg = &cfg.channel_config; - err = input_assign(&cfg.pin_p, &cfg.pin_n, channel_cfg); - if (err != 0) { - return err; - } - err = gain_set(ch_cfg, channel_cfg->gain); if (err != 0) { return err; @@ -803,38 +692,9 @@ static DEVICE_API(adc, adc_nrfx_driver_api) = { #ifdef CONFIG_ADC_ASYNC .read_async = adc_nrfx_read_async, #endif -#if defined(NRF54LV10A_ENGA_XXAA) - .ref_internal = 1300, -#elif defined(CONFIG_SOC_COMPATIBLE_NRF54LX) - .ref_internal = 900, -#elif defined(CONFIG_NRF_PLATFORM_HALTIUM) - .ref_internal = 1024, -#else - .ref_internal = 600, -#endif + .ref_internal = NRFX_SAADC_REF_INTERNAL_VALUE, }; -#if defined(CONFIG_NRF_PLATFORM_HALTIUM) -/* AIN8-AIN14 inputs are on 3v3 GPIO port and they cannot be mixed with other - * analog inputs (from 1v8 ports) in differential mode. - */ -#define CH_IS_3V3(val) (val >= NRF_SAADC_AIN8) - -#define MIXED_3V3_1V8_INPUTS(node) \ - (DT_NODE_HAS_PROP(node, zephyr_input_negative) && \ - (CH_IS_3V3(DT_PROP_OR(node, zephyr_input_negative, 0)) != \ - CH_IS_3V3(DT_PROP_OR(node, zephyr_input_positive, 0)))) -#else -#define MIXED_3V3_1V8_INPUTS(node) false -#endif - -#define VALIDATE_CHANNEL_CONFIG(node) \ - BUILD_ASSERT(MIXED_3V3_1V8_INPUTS(node) == false, \ - "1v8 inputs cannot be mixed with 3v3 inputs"); - -/* Validate configuration of all channels. */ -DT_FOREACH_CHILD(DT_DRV_INST(0), VALIDATE_CHANNEL_CONFIG) - NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(0)); DEVICE_DT_INST_DEFINE(0, init_saadc, NULL, NULL, NULL, POST_KERNEL, From 9b55912d6848db52a662f5757b6b1a649be8317e Mon Sep 17 00:00:00 2001 From: Jakub Zymelka Date: Tue, 22 Jul 2025 12:44:12 +0200 Subject: [PATCH 7/7] [nrf fromlist] drivers: comparator: nordic: Remove platform dependencies Remove platform dependencies and replace the analog pin mapping method with the generic one from the (LP)COMP driver. Upstream PR #: 93497 Signed-off-by: Jakub Zymelka --- drivers/comparator/comparator_nrf_common.h | 53 ----- drivers/comparator/comparator_nrf_comp.c | 212 ++---------------- drivers/comparator/comparator_nrf_lpcomp.c | 123 +--------- .../zephyr/dt-bindings/comparator/nrf-comp.h | 6 +- 4 files changed, 31 insertions(+), 363 deletions(-) delete mode 100644 drivers/comparator/comparator_nrf_common.h diff --git a/drivers/comparator/comparator_nrf_common.h b/drivers/comparator/comparator_nrf_common.h deleted file mode 100644 index e86fc9f6369..00000000000 --- a/drivers/comparator/comparator_nrf_common.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2025 Nordic Semiconductor ASA - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_ -#define ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_ - -#include - -#if (NRF_COMP_HAS_AIN_AS_PIN || NRF_LPCOMP_HAS_AIN_AS_PIN) -static const uint32_t shim_nrf_comp_ain_map[] = { -#if defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280) - NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), -#elif defined(CONFIG_SOC_NRF54L05) || defined(CONFIG_SOC_NRF54L10) || defined(CONFIG_SOC_NRF54L15) - NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1), -#elif defined(NRF54LM20A_ENGA_XXAA) - NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(31U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(30U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(29U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), -#elif defined(NRF54LV10A_ENGA_XXAA) - NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(10U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1), - NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1), -#endif -}; -#endif - -#endif /* ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_ */ diff --git a/drivers/comparator/comparator_nrf_comp.c b/drivers/comparator/comparator_nrf_comp.c index 6c5acdf5c08..675d5f8dad3 100644 --- a/drivers/comparator/comparator_nrf_comp.c +++ b/drivers/comparator/comparator_nrf_comp.c @@ -9,7 +9,6 @@ #include #include #include -#include "comparator_nrf_common.h" #define DT_DRV_COMPAT nordic_nrf_comp @@ -71,51 +70,22 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64); BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64); #endif -#if (NRF_COMP_HAS_AIN_AS_PIN) -BUILD_ASSERT(NRF_COMP_AIN0 == 0); -BUILD_ASSERT(NRF_COMP_AIN7 == 7); -#else -BUILD_ASSERT((NRF_COMP_AIN0 == NRF_COMP_INPUT_0) && - (NRF_COMP_AIN1 == NRF_COMP_INPUT_1) && - (NRF_COMP_AIN2 == NRF_COMP_INPUT_2) && - (NRF_COMP_AIN3 == NRF_COMP_INPUT_3) && -#if defined(COMP_PSEL_PSEL_AnalogInput4) - (NRF_COMP_AIN4 == NRF_COMP_INPUT_4) && -#endif -#if defined(COMP_PSEL_PSEL_AnalogInput5) - (NRF_COMP_AIN5 == NRF_COMP_INPUT_5) && -#endif -#if defined(COMP_PSEL_PSEL_AnalogInput6) - (NRF_COMP_AIN6 == NRF_COMP_INPUT_6) && -#endif -#if defined(COMP_PSEL_PSEL_AnalogInput7) - (NRF_COMP_AIN7 == NRF_COMP_INPUT_7) && -#endif - (NRF_COMP_AIN0 == NRF_COMP_EXT_REF_0) && - (NRF_COMP_AIN1 == NRF_COMP_EXT_REF_1) && - (NRF_COMP_AIN2 == NRF_COMP_EXT_REF_2) && - (NRF_COMP_AIN3 == NRF_COMP_EXT_REF_3) && -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) - (NRF_COMP_AIN4 == NRF_COMP_EXT_REF_4) && -#endif -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) - (NRF_COMP_AIN5 == NRF_COMP_EXT_REF_5) && -#endif -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) - (NRF_COMP_AIN6 == NRF_COMP_EXT_REF_6) && -#endif -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) - (NRF_COMP_AIN7 == NRF_COMP_EXT_REF_7) && +BUILD_ASSERT((NRF_COMP_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0) && + (NRF_COMP_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1) && + (NRF_COMP_AIN2 == NRFX_ANALOG_EXTERNAL_AIN2) && + (NRF_COMP_AIN3 == NRFX_ANALOG_EXTERNAL_AIN3) && + (NRF_COMP_AIN4 == NRFX_ANALOG_EXTERNAL_AIN4) && + (NRF_COMP_AIN5 == NRFX_ANALOG_EXTERNAL_AIN5) && + (NRF_COMP_AIN6 == NRFX_ANALOG_EXTERNAL_AIN6) && + (NRF_COMP_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7) && +#if defined(COMP_PSEL_PSEL_VddhDiv5) + (NRF_COMP_AIN_VDDH_DIV5 == NRFX_ANALOG_INTERNAL_VDDHDIV5) && #endif #if defined(COMP_PSEL_PSEL_VddDiv2) - (NRF_COMP_VDD_DIV2 == NRF_COMP_VDD_DIV2) && -#endif -#if defined(COMP_PSEL_PSEL_VddhDiv5) - (NRF_COMP_VDDH_DIV5 == NRF_COMP_VDDH_DIV5) && + (NRF_COMP_AIN_VDD_DIV2 == NRFX_ANALOG_INTERNAL_VDDDIV2) && #endif 1, - "Definitions from nrf-comp.h do not match those from HAL"); -#endif + "Definitions from nrf-comp.h do not match those from nrfx_analog_common.h"); #ifndef COMP_MODE_SP_Normal BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_SP_MODE(0) != COMP_NRF_COMP_SP_MODE_NORMAL); @@ -240,82 +210,6 @@ static int shim_nrf_comp_pm_callback(const struct device *dev, enum pm_device_ac return 0; } -#if (NRF_COMP_HAS_AIN_AS_PIN) -static int shim_nrf_comp_psel_to_nrf(uint8_t shim, - nrf_comp_input_t *nrf) -{ - if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { - return -EINVAL; - } - - *nrf = shim_nrf_comp_ain_map[shim]; - return 0; -} -#else -static int shim_nrf_comp_psel_to_nrf(uint8_t shim, - nrf_comp_input_t *nrf) -{ - switch (shim) { - case NRF_COMP_AIN0: - *nrf = NRF_COMP_INPUT_0; - break; - - case NRF_COMP_AIN1: - *nrf = NRF_COMP_INPUT_1; - break; - - case NRF_COMP_AIN2: - *nrf = NRF_COMP_INPUT_2; - break; - - case NRF_COMP_AIN3: - *nrf = NRF_COMP_INPUT_3; - break; - -#if defined(COMP_PSEL_PSEL_AnalogInput4) - case NRF_COMP_AIN4: - *nrf = NRF_COMP_INPUT_4; - break; -#endif - -#if defined(COMP_PSEL_PSEL_AnalogInput5) - case NRF_COMP_AIN5: - *nrf = NRF_COMP_INPUT_5; - break; -#endif - -#if defined(COMP_PSEL_PSEL_AnalogInput6) - case NRF_COMP_AIN6: - *nrf = NRF_COMP_INPUT_6; - break; -#endif - -#if defined(COMP_PSEL_PSEL_AnalogInput7) - case NRF_COMP_AIN7: - *nrf = NRF_COMP_INPUT_7; - break; -#endif - -#if defined(COMP_PSEL_PSEL_VddDiv2) - case NRF_COMP_AIN_VDD_DIV2: - *nrf = NRF_COMP_VDD_DIV2; - break; -#endif - -#if defined(COMP_PSEL_PSEL_VddhDiv5) - case NRF_COMP_AIN_VDDH_DIV5: - *nrf = NRF_COMP_VDDH_DIV5; - break; -#endif - - default: - return -EINVAL; - } - - return 0; -} -#endif - static int shim_nrf_comp_sp_mode_to_nrf(enum comp_nrf_comp_sp_mode shim, nrf_comp_sp_mode_t *nrf) { @@ -376,70 +270,6 @@ static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim, } #endif -#if (NRF_COMP_HAS_AIN_AS_PIN) -static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim, - nrf_comp_ext_ref_t *nrf) -{ - if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { - return -EINVAL; - } - - *nrf = shim_nrf_comp_ain_map[shim]; - return 0; -} -#else -static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim, - nrf_comp_ext_ref_t *nrf) -{ - switch (shim) { - case NRF_COMP_AIN0: - *nrf = NRF_COMP_EXT_REF_0; - break; - - case NRF_COMP_AIN1: - *nrf = NRF_COMP_EXT_REF_1; - break; - - case NRF_COMP_AIN2: - *nrf = NRF_COMP_EXT_REF_2; - break; - - case NRF_COMP_AIN3: - *nrf = NRF_COMP_EXT_REF_3; - break; - -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4) - case NRF_COMP_AIN4: - *nrf = NRF_COMP_EXT_REF_4; - break; -#endif - -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5) - case NRF_COMP_AIN5: - *nrf = NRF_COMP_EXT_REF_5; - break; -#endif - -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6) - case NRF_COMP_AIN6: - *nrf = NRF_COMP_EXT_REF_6; - break; -#endif - -#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7) - case NRF_COMP_AIN7: - *nrf = NRF_COMP_EXT_REF_7; - break; -#endif - - default: - return -EINVAL; - } - - return 0; -} -#endif - static int shim_nrf_comp_refsel_to_nrf(enum comp_nrf_comp_refsel shim, nrf_comp_ref_t *nrf) { @@ -490,9 +320,8 @@ static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config * return -EINVAL; } - if (shim_nrf_comp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { - return -EINVAL; - } + nrf->ext_ref = (nrfx_analog_input_t)shim->extrefsel; + nrf->input = (nrfx_analog_input_t)shim->psel; nrf->main_mode = NRF_COMP_MAIN_MODE_SE; @@ -519,10 +348,6 @@ static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config * } #endif - if (shim_nrf_comp_psel_to_nrf(shim->psel, &nrf->input)) { - return -EINVAL; - } - nrf->interrupt_priority = 0; return 0; } @@ -532,9 +357,8 @@ static int shim_nrf_comp_diff_config_to_nrf(const struct comp_nrf_comp_diff_conf { nrf->reference = NRF_COMP_REF_AREF; - if (shim_nrf_comp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { - return -EINVAL; - } + nrf->ext_ref = (nrfx_analog_input_t)shim->extrefsel; + nrf->input = (nrfx_analog_input_t)shim->psel; nrf->main_mode = NRF_COMP_MAIN_MODE_DIFF; nrf->threshold.th_down = 0; @@ -566,10 +390,6 @@ static int shim_nrf_comp_diff_config_to_nrf(const struct comp_nrf_comp_diff_conf } #endif - if (shim_nrf_comp_psel_to_nrf(shim->psel, &nrf->input)) { - return -EINVAL; - } - nrf->interrupt_priority = 0; return 0; } diff --git a/drivers/comparator/comparator_nrf_lpcomp.c b/drivers/comparator/comparator_nrf_lpcomp.c index 6faba2b8669..36b4c440f4b 100644 --- a/drivers/comparator/comparator_nrf_lpcomp.c +++ b/drivers/comparator/comparator_nrf_lpcomp.c @@ -9,7 +9,6 @@ #include #include #include -#include "comparator_nrf_common.h" #include @@ -37,22 +36,15 @@ struct shim_nrf_lpcomp_data { void *user_data; }; -#if (NRF_LPCOMP_HAS_AIN_AS_PIN) -BUILD_ASSERT(NRF_COMP_AIN0 == 0); -BUILD_ASSERT(NRF_COMP_AIN7 == 7); -#else -BUILD_ASSERT((NRF_COMP_AIN0 == NRF_LPCOMP_INPUT_0) && - (NRF_COMP_AIN1 == NRF_LPCOMP_INPUT_1) && - (NRF_COMP_AIN2 == NRF_LPCOMP_INPUT_2) && - (NRF_COMP_AIN3 == NRF_LPCOMP_INPUT_3) && - (NRF_COMP_AIN4 == NRF_LPCOMP_INPUT_4) && - (NRF_COMP_AIN5 == NRF_LPCOMP_INPUT_5) && - (NRF_COMP_AIN6 == NRF_LPCOMP_INPUT_6) && - (NRF_COMP_AIN7 == NRF_LPCOMP_INPUT_7) && - (NRF_COMP_AIN0 == NRF_LPCOMP_EXT_REF_REF0) && - (NRF_COMP_AIN1 == NRF_LPCOMP_EXT_REF_REF1), - "Definitions from nrf-comp.h do not match those from HAL"); -#endif +BUILD_ASSERT((NRF_COMP_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0) && + (NRF_COMP_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1) && + (NRF_COMP_AIN2 == NRFX_ANALOG_EXTERNAL_AIN2) && + (NRF_COMP_AIN3 == NRFX_ANALOG_EXTERNAL_AIN3) && + (NRF_COMP_AIN4 == NRFX_ANALOG_EXTERNAL_AIN4) && + (NRF_COMP_AIN5 == NRFX_ANALOG_EXTERNAL_AIN5) && + (NRF_COMP_AIN6 == NRFX_ANALOG_EXTERNAL_AIN6) && + (NRF_COMP_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7), + "Definitions from nrf-comp.h do not match those from nrfx_analog_common.h"); #if (LPCOMP_REFSEL_RESOLUTION == 8) BUILD_ASSERT((SHIM_NRF_LPCOMP_DT_INST_REFSEL(0) < COMP_NRF_LPCOMP_REFSEL_VDD_1_16) || @@ -133,94 +125,6 @@ static int shim_nrf_lpcomp_pm_callback(const struct device *dev, enum pm_device_ return 0; } -#if (NRF_LPCOMP_HAS_AIN_AS_PIN) -static int shim_nrf_lpcomp_psel_to_nrf(uint8_t shim, - nrf_lpcomp_input_t *nrf) -{ - if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { - return -EINVAL; - } - - *nrf = shim_nrf_comp_ain_map[shim]; - return 0; -} -#else -static int shim_nrf_lpcomp_psel_to_nrf(uint8_t shim, - nrf_lpcomp_input_t *nrf) -{ - switch (shim) { - case NRF_COMP_AIN0: - *nrf = NRF_LPCOMP_INPUT_0; - break; - - case NRF_COMP_AIN1: - *nrf = NRF_LPCOMP_INPUT_1; - break; - - case NRF_COMP_AIN2: - *nrf = NRF_LPCOMP_INPUT_2; - break; - - case NRF_COMP_AIN3: - *nrf = NRF_LPCOMP_INPUT_3; - break; - - case NRF_COMP_AIN4: - *nrf = NRF_LPCOMP_INPUT_4; - break; - - case NRF_COMP_AIN5: - *nrf = NRF_LPCOMP_INPUT_5; - break; - - case NRF_COMP_AIN6: - *nrf = NRF_LPCOMP_INPUT_6; - break; - - case NRF_COMP_AIN7: - *nrf = NRF_LPCOMP_INPUT_7; - break; - - default: - return -EINVAL; - } - - return 0; -} -#endif - -#if (NRF_LPCOMP_HAS_AIN_AS_PIN) -static int shim_nrf_lpcomp_extrefsel_to_nrf(uint8_t shim, - nrf_lpcomp_ext_ref_t *nrf) -{ - if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { - return -EINVAL; - } - - *nrf = shim_nrf_comp_ain_map[shim]; - return 0; -} -#else -static int shim_nrf_lpcomp_extrefsel_to_nrf(uint8_t shim, - nrf_lpcomp_ext_ref_t *nrf) -{ - switch (shim) { - case NRF_COMP_AIN0: - *nrf = NRF_LPCOMP_EXT_REF_REF0; - break; - - case NRF_COMP_AIN1: - *nrf = NRF_LPCOMP_EXT_REF_REF1; - break; - - default: - return -EINVAL; - } - - return 0; -} -#endif - static int shim_nrf_lpcomp_refsel_to_nrf(enum comp_nrf_lpcomp_refsel shim, nrf_lpcomp_ref_t *nrf) { @@ -305,9 +209,8 @@ static int shim_nrf_lpcomp_config_to_nrf(const struct comp_nrf_lpcomp_config *sh return -EINVAL; } - if (shim_nrf_lpcomp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) { - return -EINVAL; - } + nrf->ext_ref = (nrfx_analog_input_t)shim->extrefsel; + nrf->input = (nrfx_analog_input_t)shim->psel; #if NRF_LPCOMP_HAS_HYST if (shim->enable_hyst) { @@ -321,10 +224,6 @@ static int shim_nrf_lpcomp_config_to_nrf(const struct comp_nrf_lpcomp_config *sh } #endif - if (shim_nrf_lpcomp_psel_to_nrf(shim->psel, &nrf->input)) { - return -EINVAL; - } - return 0; } diff --git a/include/zephyr/dt-bindings/comparator/nrf-comp.h b/include/zephyr/dt-bindings/comparator/nrf-comp.h index 1a5407554a1..13314bc963c 100644 --- a/include/zephyr/dt-bindings/comparator/nrf-comp.h +++ b/include/zephyr/dt-bindings/comparator/nrf-comp.h @@ -15,7 +15,9 @@ #define NRF_COMP_AIN5 5 /** AIN5 external input */ #define NRF_COMP_AIN6 6 /** AIN6 external input */ #define NRF_COMP_AIN7 7 /** AIN7 external input */ -#define NRF_COMP_AIN_VDD_DIV2 8 /** VDD / 2 */ -#define NRF_COMP_AIN_VDDH_DIV5 9 /** VDDH / 5 */ + +#define NRF_COMP_AIN_VDD_SHIM_OFFSET 128 +#define NRF_COMP_AIN_VDD_DIV2 (NRF_COMP_AIN_VDD_SHIM_OFFSET + 1) +#define NRF_COMP_AIN_VDDH_DIV5 (NRF_COMP_AIN_VDD_SHIM_OFFSET + 4) #endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_COMP_H_ */