diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index ae7339e00d7..8d8c6a01ad3 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -40,7 +40,7 @@ static const uint32_t saadc_psels[NRF_SAADC_AIN13 + 1] = { [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_COMPATIBLE_NRF54LX) +#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), @@ -54,6 +54,20 @@ static const uint32_t saadc_psels[NRF_SAADC_DVDD + 1] = { [NRF_SAADC_AVDD] = NRF_SAADC_INPUT_AVDD, [NRF_SAADC_DVDD] = NRF_SAADC_INPUT_DVDD, }; +#elif defined(CONFIG_SOC_COMPATIBLE_NRF54LX) +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, +}; #endif #else 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 diff --git a/tests/boards/nrf/comp/Kconfig b/tests/boards/nrf/comp/Kconfig new file mode 100644 index 00000000000..63b969a1bf3 --- /dev/null +++ b/tests/boards/nrf/comp/Kconfig @@ -0,0 +1,20 @@ +# Copyright (c) 2025 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config TEST_COMP_SE_PSEL_AIN_INDEX + int "Index of analog input for SE psel." + default 5 + +config TEST_COMP_SE_EXTREFSEL_AIN_INDEX + int "Index of analog input for SE extrefsel." + default 1 + +config TEST_COMP_DIFF_PSEL_AIN_INDEX + int "Index of analog input for DIFF psel." + default 4 + +config TEST_COMP_DIFF_EXTREFSEL_AIN_INDEX + int "Index of analog input for DIFF extrefsel." + default 5 + +source "Kconfig.zephyr" diff --git a/tests/boards/nrf/comp/src/test.c b/tests/boards/nrf/comp/src/test.c index 01493d06811..2195f0e1ea9 100644 --- a/tests/boards/nrf/comp/src/test.c +++ b/tests/boards/nrf/comp/src/test.c @@ -13,22 +13,30 @@ 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) struct comp_nrf_comp_se_config comp_se_config = { - .psel = COMP_NRF_COMP_PSEL_AIN5, + .psel = TEST_COMP_SE_PSEL_AIN, .sp_mode = COMP_NRF_COMP_SP_MODE_HIGH, .isource = COMP_NRF_COMP_ISOURCE_DISABLED, .refsel = COMP_NRF_COMP_REFSEL_AREF, - .extrefsel = COMP_NRF_COMP_EXTREFSEL_AIN1, + .extrefsel = TEST_COMP_SE_EXTREFSEL_AIN, .th_up = 32, .th_down = 32, }; struct comp_nrf_comp_diff_config comp_diff_config = { - .psel = COMP_NRF_COMP_PSEL_AIN4, + .psel = TEST_COMP_DIFF_PSEL_AIN, .sp_mode = COMP_NRF_COMP_SP_MODE_LOW, .isource = COMP_NRF_COMP_ISOURCE_DISABLED, - .extrefsel = COMP_NRF_COMP_EXTREFSEL_AIN5, + .extrefsel = TEST_COMP_DIFF_EXTREFSEL_AIN, .enable_hyst = true, };