Skip to content

Commit 37a9092

Browse files
mstasiaknordicrlubos
authored andcommitted
[nrf fromtree] drivers: comparator: comparator_nrf: Add analog pins for nRF54L20
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 <[email protected]> (cherry picked from commit 03a9df3)
1 parent 32a19b0 commit 37a9092

File tree

3 files changed

+50
-52
lines changed

3 files changed

+50
-52
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_
7+
#define ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_
8+
9+
#include <nrfx.h>
10+
11+
#if (NRF_COMP_HAS_AIN_AS_PIN || NRF_LPCOMP_HAS_AIN_AS_PIN)
12+
static const uint32_t shim_nrf_comp_ain_map[] = {
13+
#if defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280)
14+
NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1),
15+
NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1),
16+
NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1),
17+
NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1),
18+
NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1),
19+
NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1),
20+
NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1),
21+
NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
22+
#elif defined(CONFIG_SOC_NRF54L05) || defined(CONFIG_SOC_NRF54L10) || defined(CONFIG_SOC_NRF54L15)
23+
NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1),
24+
NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1),
25+
NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1),
26+
NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
27+
NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1),
28+
NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1),
29+
NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1),
30+
NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1),
31+
#elif defined(CONFIG_SOC_COMPATIBLE_NRF54LX)
32+
NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1),
33+
NRF_PIN_PORT_TO_PIN_NUMBER(31U, 1),
34+
NRF_PIN_PORT_TO_PIN_NUMBER(30U, 1),
35+
NRF_PIN_PORT_TO_PIN_NUMBER(29U, 1),
36+
NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1),
37+
NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1),
38+
NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1),
39+
NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1),
40+
#endif
41+
};
42+
#endif
43+
44+
#endif /* ZEPHYR_DRIVERS_COMPARATOR_NRF_COMMON_H_ */

drivers/comparator/comparator_nrf_comp.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/drivers/comparator/nrf_comp.h>
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/pm/device.h>
12+
#include "comparator_nrf_common.h"
1213

1314
#define DT_DRV_COMPAT nordic_nrf_comp
1415

@@ -67,30 +68,6 @@ struct shim_nrf_comp_data {
6768
void *user_data;
6869
};
6970

70-
#if (NRF_COMP_HAS_AIN_AS_PIN)
71-
static const uint32_t shim_nrf_comp_ain_map[] = {
72-
#if defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280)
73-
NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1),
74-
NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1),
75-
NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1),
76-
NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1),
77-
NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1),
78-
NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1),
79-
NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1),
80-
NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
81-
#elif defined(CONFIG_SOC_NRF54L05) || defined(CONFIG_SOC_NRF54L10) || defined(CONFIG_SOC_NRF54L15)
82-
NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1),
83-
NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1),
84-
NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1),
85-
NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
86-
NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1),
87-
NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1),
88-
NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1),
89-
NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1),
90-
#endif
91-
};
92-
#endif
93-
9471
#if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(0)
9572
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64);
9673
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64);

drivers/comparator/comparator_nrf_lpcomp.c

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/drivers/comparator/nrf_lpcomp.h>
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/pm/device.h>
12+
#include "comparator_nrf_common.h"
1213

1314
#include <string.h>
1415

@@ -38,30 +39,6 @@ struct shim_nrf_lpcomp_data {
3839
void *user_data;
3940
};
4041

41-
#if (NRF_LPCOMP_HAS_AIN_AS_PIN)
42-
static const uint32_t shim_nrf_lpcomp_ain_map[] = {
43-
#if defined(CONFIG_SOC_NRF54H20) || defined(CONFIG_SOC_NRF9280)
44-
NRF_PIN_PORT_TO_PIN_NUMBER(0U, 1),
45-
NRF_PIN_PORT_TO_PIN_NUMBER(1U, 1),
46-
NRF_PIN_PORT_TO_PIN_NUMBER(2U, 1),
47-
NRF_PIN_PORT_TO_PIN_NUMBER(3U, 1),
48-
NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1),
49-
NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1),
50-
NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1),
51-
NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
52-
#elif defined(CONFIG_SOC_NRF54L05) || defined(CONFIG_SOC_NRF54L10) || defined(CONFIG_SOC_NRF54L15)
53-
NRF_PIN_PORT_TO_PIN_NUMBER(4U, 1),
54-
NRF_PIN_PORT_TO_PIN_NUMBER(5U, 1),
55-
NRF_PIN_PORT_TO_PIN_NUMBER(6U, 1),
56-
NRF_PIN_PORT_TO_PIN_NUMBER(7U, 1),
57-
NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1),
58-
NRF_PIN_PORT_TO_PIN_NUMBER(12U, 1),
59-
NRF_PIN_PORT_TO_PIN_NUMBER(13U, 1),
60-
NRF_PIN_PORT_TO_PIN_NUMBER(14U, 1),
61-
#endif
62-
};
63-
#endif
64-
6542
#if (NRF_LPCOMP_HAS_AIN_AS_PIN)
6643
BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN0 == 0);
6744
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_
152129
static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim,
153130
nrf_lpcomp_input_t *nrf)
154131
{
155-
if (shim >= ARRAY_SIZE(shim_nrf_lpcomp_ain_map)) {
132+
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
156133
return -EINVAL;
157134
}
158135

159-
*nrf = shim_nrf_lpcomp_ain_map[(uint32_t)shim];
136+
*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
160137
return 0;
161138
}
162139
#else
@@ -208,11 +185,11 @@ static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim,
208185
static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim,
209186
nrf_lpcomp_ext_ref_t *nrf)
210187
{
211-
if (shim >= ARRAY_SIZE(shim_nrf_lpcomp_ain_map)) {
188+
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
212189
return -EINVAL;
213190
}
214191

215-
*nrf = shim_nrf_lpcomp_ain_map[shim];
192+
*nrf = shim_nrf_comp_ain_map[shim];
216193
return 0;
217194
}
218195
#else

0 commit comments

Comments
 (0)