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
@@ -73,36 +72,22 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64);
7372BUILD_ASSERT (SHIM_NRF_COMP_DT_INST_TH_UP (0 ) < 64 );
7473#endif
7574
76- #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 ));
81- #else
82- #ifndef COMP_PSEL_PSEL_AnalogInput4
83- BUILD_ASSERT (SHIM_NRF_COMP_DT_INST_PSEL (0 ) != COMP_NRF_COMP_PSEL_AIN4 );
84- #endif
85-
86- #ifndef COMP_PSEL_PSEL_AnalogInput5
87- BUILD_ASSERT (SHIM_NRF_COMP_DT_INST_PSEL (0 ) != COMP_NRF_COMP_PSEL_AIN5 );
88- #endif
89-
90- #ifndef COMP_PSEL_PSEL_AnalogInput6
91- BUILD_ASSERT (SHIM_NRF_COMP_DT_INST_PSEL (0 ) != COMP_NRF_COMP_PSEL_AIN6 );
92- #endif
93-
94- #ifndef COMP_PSEL_PSEL_AnalogInput7
95- BUILD_ASSERT (SHIM_NRF_COMP_DT_INST_PSEL (0 ) != COMP_NRF_COMP_PSEL_AIN7 );
96- #endif
97- #endif
98-
99- #ifndef COMP_PSEL_PSEL_VddDiv2
100- BUILD_ASSERT (SHIM_NRF_COMP_DT_INST_PSEL (0 ) != COMP_NRF_COMP_PSEL_VDD_DIV2 );
75+ BUILD_ASSERT ((NRF_COMP_AIN0 == NRFX_ANALOG_EXTERNAL_AIN0 ) &&
76+ (NRF_COMP_AIN1 == NRFX_ANALOG_EXTERNAL_AIN1 ) &&
77+ (NRF_COMP_AIN2 == NRFX_ANALOG_EXTERNAL_AIN2 ) &&
78+ (NRF_COMP_AIN3 == NRFX_ANALOG_EXTERNAL_AIN3 ) &&
79+ (NRF_COMP_AIN4 == NRFX_ANALOG_EXTERNAL_AIN4 ) &&
80+ (NRF_COMP_AIN5 == NRFX_ANALOG_EXTERNAL_AIN5 ) &&
81+ (NRF_COMP_AIN6 == NRFX_ANALOG_EXTERNAL_AIN6 ) &&
82+ (NRF_COMP_AIN7 == NRFX_ANALOG_EXTERNAL_AIN7 ) &&
83+ #if defined(COMP_PSEL_PSEL_VddhDiv5 )
84+ (NRF_COMP_VDDHDIV5 == NRFX_ANALOG_INTERNAL_VDDHDIV5 ) &&
10185#endif
102-
103- #ifndef COMP_PSEL_PSEL_VddhDiv5
104- BUILD_ASSERT (SHIM_NRF_COMP_DT_INST_PSEL (0 ) != COMP_NRF_COMP_PSEL_VDDH_DIV5 );
86+ #if defined(COMP_PSEL_PSEL_VddDiv2 )
87+ (NRF_COMP_VDDDIV2 == NRFX_ANALOG_INTERNAL_VDDDIV2 ) &&
10588#endif
89+ 1 ,
90+ "Definitions from nrf-comp.h do not match those from nrfx_analog_common.h" );
10691
10792#ifndef COMP_MODE_SP_Normal
10893BUILD_ASSERT (SHIM_NRF_COMP_DT_INST_SP_MODE (0 ) != COMP_NRF_COMP_SP_MODE_NORMAL );
@@ -245,82 +230,6 @@ static int shim_nrf_comp_pm_callback(const struct device *dev, enum pm_device_ac
245230 return 0 ;
246231}
247232
248- #if (NRF_COMP_HAS_AIN_AS_PIN )
249- static int shim_nrf_comp_psel_to_nrf (enum comp_nrf_comp_psel shim ,
250- nrf_comp_input_t * nrf )
251- {
252- if (shim >= ARRAY_SIZE (shim_nrf_comp_ain_map )) {
253- return - EINVAL ;
254- }
255-
256- * nrf = shim_nrf_comp_ain_map [(uint32_t )shim ];
257- return 0 ;
258- }
259- #else
260- static int shim_nrf_comp_psel_to_nrf (enum comp_nrf_comp_psel shim ,
261- nrf_comp_input_t * nrf )
262- {
263- switch (shim ) {
264- case COMP_NRF_COMP_PSEL_AIN0 :
265- * nrf = NRF_COMP_INPUT_0 ;
266- break ;
267-
268- case COMP_NRF_COMP_PSEL_AIN1 :
269- * nrf = NRF_COMP_INPUT_1 ;
270- break ;
271-
272- case COMP_NRF_COMP_PSEL_AIN2 :
273- * nrf = NRF_COMP_INPUT_2 ;
274- break ;
275-
276- case COMP_NRF_COMP_PSEL_AIN3 :
277- * nrf = NRF_COMP_INPUT_3 ;
278- break ;
279-
280- #if defined(COMP_PSEL_PSEL_AnalogInput4 )
281- case COMP_NRF_COMP_PSEL_AIN4 :
282- * nrf = NRF_COMP_INPUT_4 ;
283- break ;
284- #endif
285-
286- #if defined(COMP_PSEL_PSEL_AnalogInput5 )
287- case COMP_NRF_COMP_PSEL_AIN5 :
288- * nrf = NRF_COMP_INPUT_5 ;
289- break ;
290- #endif
291-
292- #if defined(COMP_PSEL_PSEL_AnalogInput6 )
293- case COMP_NRF_COMP_PSEL_AIN6 :
294- * nrf = NRF_COMP_INPUT_6 ;
295- break ;
296- #endif
297-
298- #if defined(COMP_PSEL_PSEL_AnalogInput7 )
299- case COMP_NRF_COMP_PSEL_AIN7 :
300- * nrf = NRF_COMP_INPUT_7 ;
301- break ;
302- #endif
303-
304- #if defined(COMP_PSEL_PSEL_VddDiv2 )
305- case COMP_NRF_COMP_PSEL_VDD_DIV2 :
306- * nrf = NRF_COMP_VDD_DIV2 ;
307- break ;
308- #endif
309-
310- #if defined(COMP_PSEL_PSEL_VddhDiv5 )
311- case COMP_NRF_COMP_PSEL_VDDH_DIV5 :
312- * nrf = NRF_COMP_VDDH_DIV5 ;
313- break ;
314- #endif
315-
316- default :
317- return - EINVAL ;
318- }
319-
320- return 0 ;
321- }
322- #endif
323-
324233static int shim_nrf_comp_sp_mode_to_nrf (enum comp_nrf_comp_sp_mode shim ,
325234 nrf_comp_sp_mode_t * nrf )
326235{
@@ -381,70 +290,6 @@ static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim,
381290}
382291#endif
383292
384- #if (NRF_COMP_HAS_AIN_AS_PIN )
385- static int shim_nrf_comp_extrefsel_to_nrf (enum comp_nrf_comp_extrefsel shim ,
386- nrf_comp_ext_ref_t * nrf )
387- {
388- if (shim >= ARRAY_SIZE (shim_nrf_comp_ain_map )) {
389- return - EINVAL ;
390- }
391-
392- * nrf = shim_nrf_comp_ain_map [(uint32_t )shim ];
393- return 0 ;
394- }
395- #else
396- static int shim_nrf_comp_extrefsel_to_nrf (enum comp_nrf_comp_extrefsel shim ,
397- nrf_comp_ext_ref_t * nrf )
398- {
399- switch (shim ) {
400- case COMP_NRF_COMP_EXTREFSEL_AIN0 :
401- * nrf = NRF_COMP_EXT_REF_0 ;
402- break ;
403-
404- case COMP_NRF_COMP_EXTREFSEL_AIN1 :
405- * nrf = NRF_COMP_EXT_REF_1 ;
406- break ;
407-
408- case COMP_NRF_COMP_EXTREFSEL_AIN2 :
409- * nrf = NRF_COMP_EXT_REF_2 ;
410- break ;
411-
412- case COMP_NRF_COMP_EXTREFSEL_AIN3 :
413- * nrf = NRF_COMP_EXT_REF_3 ;
414- break ;
415-
416- #if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4 )
417- case COMP_NRF_COMP_EXTREFSEL_AIN4 :
418- * nrf = NRF_COMP_EXT_REF_4 ;
419- break ;
420- #endif
421-
422- #if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5 )
423- case COMP_NRF_COMP_EXTREFSEL_AIN5 :
424- * nrf = NRF_COMP_EXT_REF_5 ;
425- break ;
426- #endif
427-
428- #if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6 )
429- case COMP_NRF_COMP_EXTREFSEL_AIN6 :
430- * nrf = NRF_COMP_EXT_REF_6 ;
431- break ;
432- #endif
433-
434- #if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7 )
435- case COMP_NRF_COMP_EXTREFSEL_AIN7 :
436- * nrf = NRF_COMP_EXT_REF_7 ;
437- break ;
438- #endif
439-
440- default :
441- return - EINVAL ;
442- }
443-
444- return 0 ;
445- }
446- #endif
447-
448293static int shim_nrf_comp_refsel_to_nrf (enum comp_nrf_comp_refsel shim ,
449294 nrf_comp_ref_t * nrf )
450295{
@@ -495,9 +340,8 @@ static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config *
495340 return - EINVAL ;
496341 }
497342
498- if (shim_nrf_comp_extrefsel_to_nrf (shim -> extrefsel , & nrf -> ext_ref )) {
499- return - EINVAL ;
500- }
343+ nrf -> ext_ref = (nrfx_analog_input_t )shim -> extrefsel ;
344+ nrf -> input = (nrfx_analog_input_t )shim -> psel ;
501345
502346 nrf -> main_mode = NRF_COMP_MAIN_MODE_SE ;
503347
@@ -524,10 +368,6 @@ static int shim_nrf_comp_se_config_to_nrf(const struct comp_nrf_comp_se_config *
524368 }
525369#endif
526370
527- if (shim_nrf_comp_psel_to_nrf (shim -> psel , & nrf -> input )) {
528- return - EINVAL ;
529- }
530-
531371 nrf -> interrupt_priority = 0 ;
532372 return 0 ;
533373}
@@ -537,9 +377,8 @@ static int shim_nrf_comp_diff_config_to_nrf(const struct comp_nrf_comp_diff_conf
537377{
538378 nrf -> reference = NRF_COMP_REF_AREF ;
539379
540- if (shim_nrf_comp_extrefsel_to_nrf (shim -> extrefsel , & nrf -> ext_ref )) {
541- return - EINVAL ;
542- }
380+ nrf -> ext_ref = (nrfx_analog_input_t )shim -> extrefsel ;
381+ nrf -> input = (nrfx_analog_input_t )shim -> psel ;
543382
544383 nrf -> main_mode = NRF_COMP_MAIN_MODE_DIFF ;
545384 nrf -> threshold .th_down = 0 ;
@@ -571,10 +410,6 @@ static int shim_nrf_comp_diff_config_to_nrf(const struct comp_nrf_comp_diff_conf
571410 }
572411#endif
573412
574- if (shim_nrf_comp_psel_to_nrf (shim -> psel , & nrf -> input )) {
575- return - EINVAL ;
576- }
577-
578413 nrf -> interrupt_priority = 0 ;
579414 return 0 ;
580415}
0 commit comments