From 03a9df38e963bb68a313ea60befa97a538f33538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Thu, 8 May 2025 09:57:18 +0200 Subject: [PATCH] drivers: comparator: comparator_nrf: Add analog pins for nRF54L20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added set of analog pins for nRF54L20 COMP and LPCOMP. Moved the array of analong pins for both comparator variants to avoid code duplication. Signed-off-by: MichaƂ Stasiak --- drivers/comparator/comparator_nrf_common.h | 44 ++++++++++++++++++++++ drivers/comparator/comparator_nrf_comp.c | 25 +----------- drivers/comparator/comparator_nrf_lpcomp.c | 33 +++------------- 3 files changed, 50 insertions(+), 52 deletions(-) create mode 100644 drivers/comparator/comparator_nrf_common.h diff --git a/drivers/comparator/comparator_nrf_common.h b/drivers/comparator/comparator_nrf_common.h new file mode 100644 index 00000000000..c45e6676e2d --- /dev/null +++ b/drivers/comparator/comparator_nrf_common.h @@ -0,0 +1,44 @@ +/* + * 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(CONFIG_SOC_COMPATIBLE_NRF54LX) + 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), +#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 33bea15778f..b60aef17987 100644 --- a/drivers/comparator/comparator_nrf_comp.c +++ b/drivers/comparator/comparator_nrf_comp.c @@ -9,6 +9,7 @@ #include #include #include +#include "comparator_nrf_common.h" #define DT_DRV_COMPAT nordic_nrf_comp @@ -67,30 +68,6 @@ struct shim_nrf_comp_data { void *user_data; }; -#if (NRF_COMP_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), -#endif -}; -#endif - #if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(0) BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64); BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64); diff --git a/drivers/comparator/comparator_nrf_lpcomp.c b/drivers/comparator/comparator_nrf_lpcomp.c index 5b3ff0d4a46..a3de2b8069c 100644 --- a/drivers/comparator/comparator_nrf_lpcomp.c +++ b/drivers/comparator/comparator_nrf_lpcomp.c @@ -9,6 +9,7 @@ #include #include #include +#include "comparator_nrf_common.h" #include @@ -38,30 +39,6 @@ struct shim_nrf_lpcomp_data { void *user_data; }; -#if (NRF_LPCOMP_HAS_AIN_AS_PIN) -static const uint32_t shim_nrf_lpcomp_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), -#endif -}; -#endif - #if (NRF_LPCOMP_HAS_AIN_AS_PIN) BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN0 == 0); BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN7 == 7); @@ -152,11 +129,11 @@ static int shim_nrf_lpcomp_pm_callback(const struct device *dev, enum pm_device_ static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim, nrf_lpcomp_input_t *nrf) { - if (shim >= ARRAY_SIZE(shim_nrf_lpcomp_ain_map)) { + if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { return -EINVAL; } - *nrf = shim_nrf_lpcomp_ain_map[(uint32_t)shim]; + *nrf = shim_nrf_comp_ain_map[(uint32_t)shim]; return 0; } #else @@ -208,11 +185,11 @@ static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim, static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim, nrf_lpcomp_ext_ref_t *nrf) { - if (shim >= ARRAY_SIZE(shim_nrf_lpcomp_ain_map)) { + if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) { return -EINVAL; } - *nrf = shim_nrf_lpcomp_ain_map[shim]; + *nrf = shim_nrf_comp_ain_map[shim]; return 0; } #else