Skip to content

Commit f633013

Browse files
committed
drivers: comparator: nordic: Replace analog pin mapping method
Replace the analog pin mapping method with the generic one from the (LP)COMP driver. Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
1 parent d4d4f5a commit f633013

File tree

3 files changed

+20
-71
lines changed

3 files changed

+20
-71
lines changed

drivers/comparator/comparator_nrf_common.h

Lines changed: 0 additions & 53 deletions
This file was deleted.

drivers/comparator/comparator_nrf_comp.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
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"
1312

1413
#define DT_DRV_COMPAT nordic_nrf_comp
1514

@@ -74,10 +73,10 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64);
7473
#endif
7574

7675
#if NRF_COMP_HAS_AIN_AS_PIN
77-
BUILD_ASSERT((COMP_NRF_COMP_PSEL_AIN0 == 0));
78-
BUILD_ASSERT((COMP_NRF_COMP_PSEL_AIN7 == 7));
79-
BUILD_ASSERT((COMP_NRF_COMP_EXTREFSEL_AIN0 == 0));
80-
BUILD_ASSERT((COMP_NRF_COMP_EXTREFSEL_AIN7 == 7));
76+
BUILD_ASSERT((COMP_NRF_COMP_PSEL_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0));
77+
BUILD_ASSERT((COMP_NRF_COMP_PSEL_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7));
78+
BUILD_ASSERT((COMP_NRF_COMP_EXTREFSEL_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0));
79+
BUILD_ASSERT((COMP_NRF_COMP_EXTREFSEL_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7));
8180
#else
8281
#ifndef COMP_PSEL_PSEL_AnalogInput4
8382
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN4);
@@ -249,11 +248,12 @@ static int shim_nrf_comp_pm_callback(const struct device *dev, enum pm_device_ac
249248
static int shim_nrf_comp_psel_to_nrf(enum comp_nrf_comp_psel shim,
250249
nrf_comp_input_t *nrf)
251250
{
252-
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
251+
nrfx_error_t err = nrfx_comp_input_convert(shim, nrf);
252+
253+
if (err != NRFX_SUCCESS) {
253254
return -EINVAL;
254255
}
255256

256-
*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
257257
return 0;
258258
}
259259
#else
@@ -385,11 +385,12 @@ static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim,
385385
static int shim_nrf_comp_extrefsel_to_nrf(enum comp_nrf_comp_extrefsel shim,
386386
nrf_comp_ext_ref_t *nrf)
387387
{
388-
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
388+
nrfx_error_t err = nrfx_comp_input_convert(shim, nrf);
389+
390+
if (err != NRFX_SUCCESS) {
389391
return -EINVAL;
390392
}
391393

392-
*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
393394
return 0;
394395
}
395396
#else

drivers/comparator/comparator_nrf_lpcomp.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
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"
1312

1413
#include <string.h>
1514

@@ -40,10 +39,10 @@ struct shim_nrf_lpcomp_data {
4039
};
4140

4241
#if (NRF_LPCOMP_HAS_AIN_AS_PIN)
43-
BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN0 == 0);
44-
BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN7 == 7);
45-
BUILD_ASSERT(COMP_NRF_LPCOMP_EXTREFSEL_AIN0 == 0);
46-
BUILD_ASSERT(COMP_NRF_LPCOMP_EXTREFSEL_AIN1 == 1);
42+
BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0);
43+
BUILD_ASSERT(COMP_NRF_LPCOMP_PSEL_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7);
44+
BUILD_ASSERT(COMP_NRF_LPCOMP_EXTREFSEL_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0);
45+
BUILD_ASSERT(COMP_NRF_LPCOMP_EXTREFSEL_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1);
4746
#endif
4847

4948
#if (LPCOMP_REFSEL_RESOLUTION == 8)
@@ -129,11 +128,12 @@ static int shim_nrf_lpcomp_pm_callback(const struct device *dev, enum pm_device_
129128
static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim,
130129
nrf_lpcomp_input_t *nrf)
131130
{
132-
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
131+
nrfx_error_t err = nrfx_lpcomp_input_convert(shim, nrf);
132+
133+
if (err != NRFX_SUCCESS) {
133134
return -EINVAL;
134135
}
135136

136-
*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
137137
return 0;
138138
}
139139
#else
@@ -185,11 +185,12 @@ static int shim_nrf_lpcomp_psel_to_nrf(enum comp_nrf_lpcomp_psel shim,
185185
static int shim_nrf_lpcomp_extrefsel_to_nrf(enum comp_nrf_lpcomp_extrefsel shim,
186186
nrf_lpcomp_ext_ref_t *nrf)
187187
{
188-
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
188+
nrfx_error_t err = nrfx_lpcomp_input_convert(shim, nrf);
189+
190+
if (err != NRFX_SUCCESS) {
189191
return -EINVAL;
190192
}
191193

192-
*nrf = shim_nrf_comp_ain_map[shim];
193194
return 0;
194195
}
195196
#else

0 commit comments

Comments
 (0)