Skip to content

Commit 472f8ae

Browse files
committed
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. Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
1 parent 68ffb9a commit 472f8ae

File tree

4 files changed

+31
-363
lines changed

4 files changed

+31
-363
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: 16 additions & 196 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

@@ -71,51 +70,22 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64);
7170
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64);
7271
#endif
7372

74-
#if (NRF_COMP_HAS_AIN_AS_PIN)
75-
BUILD_ASSERT(NRF_COMP_AIN0 == 0);
76-
BUILD_ASSERT(NRF_COMP_AIN7 == 7);
77-
#else
78-
BUILD_ASSERT((NRF_COMP_AIN0 == NRF_COMP_INPUT_0) &&
79-
(NRF_COMP_AIN1 == NRF_COMP_INPUT_1) &&
80-
(NRF_COMP_AIN2 == NRF_COMP_INPUT_2) &&
81-
(NRF_COMP_AIN3 == NRF_COMP_INPUT_3) &&
82-
#if defined(COMP_PSEL_PSEL_AnalogInput4)
83-
(NRF_COMP_AIN4 == NRF_COMP_INPUT_4) &&
84-
#endif
85-
#if defined(COMP_PSEL_PSEL_AnalogInput5)
86-
(NRF_COMP_AIN5 == NRF_COMP_INPUT_5) &&
87-
#endif
88-
#if defined(COMP_PSEL_PSEL_AnalogInput6)
89-
(NRF_COMP_AIN6 == NRF_COMP_INPUT_6) &&
90-
#endif
91-
#if defined(COMP_PSEL_PSEL_AnalogInput7)
92-
(NRF_COMP_AIN7 == NRF_COMP_INPUT_7) &&
93-
#endif
94-
(NRF_COMP_AIN0 == NRF_COMP_EXT_REF_0) &&
95-
(NRF_COMP_AIN1 == NRF_COMP_EXT_REF_1) &&
96-
(NRF_COMP_AIN2 == NRF_COMP_EXT_REF_2) &&
97-
(NRF_COMP_AIN3 == NRF_COMP_EXT_REF_3) &&
98-
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4)
99-
(NRF_COMP_AIN4 == NRF_COMP_EXT_REF_4) &&
100-
#endif
101-
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5)
102-
(NRF_COMP_AIN5 == NRF_COMP_EXT_REF_5) &&
103-
#endif
104-
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6)
105-
(NRF_COMP_AIN6 == NRF_COMP_EXT_REF_6) &&
106-
#endif
107-
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7)
108-
(NRF_COMP_AIN7 == NRF_COMP_EXT_REF_7) &&
73+
BUILD_ASSERT((NRF_COMP_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0) &&
74+
(NRF_COMP_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1) &&
75+
(NRF_COMP_AIN2 == NRFX_ANALOG_EXTERNAL_AIN2) &&
76+
(NRF_COMP_AIN3 == NRFX_ANALOG_EXTERNAL_AIN3) &&
77+
(NRF_COMP_AIN4 == NRFX_ANALOG_EXTERNAL_AIN4) &&
78+
(NRF_COMP_AIN5 == NRFX_ANALOG_EXTERNAL_AIN5) &&
79+
(NRF_COMP_AIN6 == NRFX_ANALOG_EXTERNAL_AIN6) &&
80+
(NRF_COMP_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7) &&
81+
#if defined(COMP_PSEL_PSEL_VddhDiv5)
82+
(NRF_COMP_AIN_VDDH_DIV5 == NRFX_ANALOG_INTERNAL_VDDHDIV5) &&
10983
#endif
11084
#if defined(COMP_PSEL_PSEL_VddDiv2)
111-
(NRF_COMP_VDD_DIV2 == NRF_COMP_VDD_DIV2) &&
112-
#endif
113-
#if defined(COMP_PSEL_PSEL_VddhDiv5)
114-
(NRF_COMP_VDDH_DIV5 == NRF_COMP_VDDH_DIV5) &&
85+
(NRF_COMP_AIN_VDD_DIV2 == NRFX_ANALOG_INTERNAL_VDDDIV2) &&
11586
#endif
11687
1,
117-
"Definitions from nrf-comp.h do not match those from HAL");
118-
#endif
88+
"Definitions from nrf-comp.h do not match those from nrfx_analog_common.h");
11989

12090
#ifndef COMP_MODE_SP_Normal
12191
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
240210
return 0;
241211
}
242212

243-
#if (NRF_COMP_HAS_AIN_AS_PIN)
244-
static int shim_nrf_comp_psel_to_nrf(uint8_t shim,
245-
nrf_comp_input_t *nrf)
246-
{
247-
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
248-
return -EINVAL;
249-
}
250-
251-
*nrf = shim_nrf_comp_ain_map[shim];
252-
return 0;
253-
}
254-
#else
255-
static int shim_nrf_comp_psel_to_nrf(uint8_t shim,
256-
nrf_comp_input_t *nrf)
257-
{
258-
switch (shim) {
259-
case NRF_COMP_AIN0:
260-
*nrf = NRF_COMP_INPUT_0;
261-
break;
262-
263-
case NRF_COMP_AIN1:
264-
*nrf = NRF_COMP_INPUT_1;
265-
break;
266-
267-
case NRF_COMP_AIN2:
268-
*nrf = NRF_COMP_INPUT_2;
269-
break;
270-
271-
case NRF_COMP_AIN3:
272-
*nrf = NRF_COMP_INPUT_3;
273-
break;
274-
275-
#if defined(COMP_PSEL_PSEL_AnalogInput4)
276-
case NRF_COMP_AIN4:
277-
*nrf = NRF_COMP_INPUT_4;
278-
break;
279-
#endif
280-
281-
#if defined(COMP_PSEL_PSEL_AnalogInput5)
282-
case NRF_COMP_AIN5:
283-
*nrf = NRF_COMP_INPUT_5;
284-
break;
285-
#endif
286-
287-
#if defined(COMP_PSEL_PSEL_AnalogInput6)
288-
case NRF_COMP_AIN6:
289-
*nrf = NRF_COMP_INPUT_6;
290-
break;
291-
#endif
292-
293-
#if defined(COMP_PSEL_PSEL_AnalogInput7)
294-
case NRF_COMP_AIN7:
295-
*nrf = NRF_COMP_INPUT_7;
296-
break;
297-
#endif
298-
299-
#if defined(COMP_PSEL_PSEL_VddDiv2)
300-
case NRF_COMP_AIN_VDD_DIV2:
301-
*nrf = NRF_COMP_VDD_DIV2;
302-
break;
303-
#endif
304-
305-
#if defined(COMP_PSEL_PSEL_VddhDiv5)
306-
case NRF_COMP_AIN_VDDH_DIV5:
307-
*nrf = NRF_COMP_VDDH_DIV5;
308-
break;
309-
#endif
310-
311-
default:
312-
return -EINVAL;
313-
}
314-
315-
return 0;
316-
}
317-
#endif
318-
319213
static int shim_nrf_comp_sp_mode_to_nrf(enum comp_nrf_comp_sp_mode shim,
320214
nrf_comp_sp_mode_t *nrf)
321215
{
@@ -376,70 +270,6 @@ static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim,
376270
}
377271
#endif
378272

379-
#if (NRF_COMP_HAS_AIN_AS_PIN)
380-
static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim,
381-
nrf_comp_ext_ref_t *nrf)
382-
{
383-
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
384-
return -EINVAL;
385-
}
386-
387-
*nrf = shim_nrf_comp_ain_map[shim];
388-
return 0;
389-
}
390-
#else
391-
static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim,
392-
nrf_comp_ext_ref_t *nrf)
393-
{
394-
switch (shim) {
395-
case NRF_COMP_AIN0:
396-
*nrf = NRF_COMP_EXT_REF_0;
397-
break;
398-
399-
case NRF_COMP_AIN1:
400-
*nrf = NRF_COMP_EXT_REF_1;
401-
break;
402-
403-
case NRF_COMP_AIN2:
404-
*nrf = NRF_COMP_EXT_REF_2;
405-
break;
406-
407-
case NRF_COMP_AIN3:
408-
*nrf = NRF_COMP_EXT_REF_3;
409-
break;
410-
411-
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4)
412-
case NRF_COMP_AIN4:
413-
*nrf = NRF_COMP_EXT_REF_4;
414-
break;
415-
#endif
416-
417-
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5)
418-
case NRF_COMP_AIN5:
419-
*nrf = NRF_COMP_EXT_REF_5;
420-
break;
421-
#endif
422-
423-
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6)
424-
case NRF_COMP_AIN6:
425-
*nrf = NRF_COMP_EXT_REF_6;
426-
break;
427-
#endif
428-
429-
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7)
430-
case NRF_COMP_AIN7:
431-
*nrf = NRF_COMP_EXT_REF_7;
432-
break;
433-
#endif
434-
435-
default:
436-
return -EINVAL;
437-
}
438-
439-
return 0;
440-
}
441-
#endif
442-
443273
static int shim_nrf_comp_refsel_to_nrf(enum comp_nrf_comp_refsel shim,
444274
nrf_comp_ref_t *nrf)
445275
{
@@ -490,9 +320,8 @@ static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config *
490320
return -EINVAL;
491321
}
492322

493-
if (shim_nrf_comp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) {
494-
return -EINVAL;
495-
}
323+
nrf->ext_ref = (nrfx_analog_input_t)shim->extrefsel;
324+
nrf->input = (nrfx_analog_input_t)shim->psel;
496325

497326
nrf->main_mode = NRF_COMP_MAIN_MODE_SE;
498327

@@ -519,10 +348,6 @@ static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config *
519348
}
520349
#endif
521350

522-
if (shim_nrf_comp_psel_to_nrf(shim->psel, &nrf->input)) {
523-
return -EINVAL;
524-
}
525-
526351
nrf->interrupt_priority = 0;
527352
return 0;
528353
}
@@ -532,9 +357,8 @@ static int shim_nrf_comp_diff_config_to_nrf(const struct comp_nrf_comp_diff_conf
532357
{
533358
nrf->reference = NRF_COMP_REF_AREF;
534359

535-
if (shim_nrf_comp_extrefsel_to_nrf(shim->extrefsel, &nrf->ext_ref)) {
536-
return -EINVAL;
537-
}
360+
nrf->ext_ref = (nrfx_analog_input_t)shim->extrefsel;
361+
nrf->input = (nrfx_analog_input_t)shim->psel;
538362

539363
nrf->main_mode = NRF_COMP_MAIN_MODE_DIFF;
540364
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
566390
}
567391
#endif
568392

569-
if (shim_nrf_comp_psel_to_nrf(shim->psel, &nrf->input)) {
570-
return -EINVAL;
571-
}
572-
573393
nrf->interrupt_priority = 0;
574394
return 0;
575395
}

0 commit comments

Comments
 (0)