Skip to content

Commit 2d7b664

Browse files
committed
[nrf fromlist] drivers comparator: nordic: Align drivers to changed analog input types
External analog input types changed from `string` to `int`. Upstream PR #: 95106 Signed-off-by: Jakub Zymelka <[email protected]>
1 parent 7f15ee9 commit 2d7b664

File tree

4 files changed

+108
-175
lines changed

4 files changed

+108
-175
lines changed

drivers/comparator/comparator_nrf_comp.c

Lines changed: 63 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#define SHIM_NRF_COMP_DT_INST_REFSEL_IS_AREF(inst) \
2020
DT_INST_ENUM_HAS_VALUE(inst, refsel, aref)
2121

22-
#define SHIM_NRF_COMP_DT_INST_EXTREFSEL(inst) \
23-
_CONCAT(COMP_NRF_COMP_EXTREFSEL_, DT_INST_STRING_TOKEN(inst, extrefsel))
22+
#define SHIM_NRF_COMP_DT_INST_EXTREFSEL(inst) DT_INST_PROP(inst, extrefsel)
2423

2524
#define SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(inst) \
2625
DT_INST_ENUM_HAS_VALUE(inst, main_mode, se)
@@ -43,8 +42,7 @@
4342
#define SHIM_NRF_COMP_DT_INST_ISOURCE(inst) \
4443
_CONCAT(COMP_NRF_COMP_ISOURCE_, DT_INST_STRING_TOKEN(inst, isource))
4544

46-
#define SHIM_NRF_COMP_DT_INST_PSEL(inst) \
47-
_CONCAT(COMP_NRF_COMP_PSEL_, DT_INST_STRING_TOKEN(inst, psel))
45+
#define SHIM_NRF_COMP_DT_INST_PSEL(inst) DT_INST_PROP(inst, psel)
4846

4947
#if defined(COMP_HYST_HYST_Hyst40mV)
5048
#define NRF_COMP_HYST_ENABLED NRF_COMP_HYST_40MV
@@ -73,35 +71,50 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_DOWN(0) < 64);
7371
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_TH_UP(0) < 64);
7472
#endif
7573

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));
74+
#if (NRF_COMP_HAS_AIN_AS_PIN)
75+
BUILD_ASSERT(NRF_COMP_AIN0 == 0);
76+
BUILD_ASSERT(NRF_COMP_AIN7 == 7);
8177
#else
82-
#ifndef COMP_PSEL_PSEL_AnalogInput4
83-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN4);
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) &&
8484
#endif
85-
86-
#ifndef COMP_PSEL_PSEL_AnalogInput5
87-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN5);
85+
#if defined(COMP_PSEL_PSEL_AnalogInput5)
86+
(NRF_COMP_AIN5 == NRF_COMP_INPUT_5) &&
8887
#endif
89-
90-
#ifndef COMP_PSEL_PSEL_AnalogInput6
91-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN6);
88+
#if defined(COMP_PSEL_PSEL_AnalogInput6)
89+
(NRF_COMP_AIN6 == NRF_COMP_INPUT_6) &&
9290
#endif
93-
94-
#ifndef COMP_PSEL_PSEL_AnalogInput7
95-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_AIN7);
91+
#if defined(COMP_PSEL_PSEL_AnalogInput7)
92+
(NRF_COMP_AIN7 == NRF_COMP_INPUT_7) &&
9693
#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) &&
97100
#endif
98-
99-
#ifndef COMP_PSEL_PSEL_VddDiv2
100-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_VDD_DIV2);
101+
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5)
102+
(NRF_COMP_AIN5 == NRF_COMP_EXT_REF_5) &&
101103
#endif
102-
103-
#ifndef COMP_PSEL_PSEL_VddhDiv5
104-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_PSEL(0) != COMP_NRF_COMP_PSEL_VDDH_DIV5);
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) &&
109+
#endif
110+
#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) &&
115+
#endif
116+
1,
117+
"Definitions from nrf-comp.h do not match those from HAL");
105118
#endif
106119

107120
#ifndef COMP_MODE_SP_Normal
@@ -122,24 +135,6 @@ BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_ISOURCE(0) != COMP_NRF_COMP_ISOURCE_10UA);
122135
#endif
123136
#endif
124137

125-
#if SHIM_NRF_COMP_DT_INST_REFSEL_IS_AREF(0)
126-
#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference4
127-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN4);
128-
#endif
129-
130-
#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference5
131-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN5);
132-
#endif
133-
134-
#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference6
135-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN6);
136-
#endif
137-
138-
#ifndef COMP_EXTREFSEL_EXTREFSEL_AnalogReference7
139-
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_EXTREFSEL(0) != COMP_NRF_COMP_EXTREFSEL_AIN7);
140-
#endif
141-
#endif
142-
143138
#if SHIM_NRF_COMP_DT_INST_MAIN_MODE_IS_SE(0)
144139
#ifndef COMP_REFSEL_REFSEL_Int1V8
145140
BUILD_ASSERT(SHIM_NRF_COMP_DT_INST_REFSEL(0) != COMP_NRF_COMP_REFSEL_INT_1V8);
@@ -246,69 +241,69 @@ static int shim_nrf_comp_pm_callback(const struct device *dev, enum pm_device_ac
246241
}
247242

248243
#if (NRF_COMP_HAS_AIN_AS_PIN)
249-
static int shim_nrf_comp_psel_to_nrf(enum comp_nrf_comp_psel shim,
244+
static int shim_nrf_comp_psel_to_nrf(uint8_t shim,
250245
nrf_comp_input_t *nrf)
251246
{
252247
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
253248
return -EINVAL;
254249
}
255250

256-
*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
251+
*nrf = shim_nrf_comp_ain_map[shim];
257252
return 0;
258253
}
259254
#else
260-
static int shim_nrf_comp_psel_to_nrf(enum comp_nrf_comp_psel shim,
255+
static int shim_nrf_comp_psel_to_nrf(uint8_t shim,
261256
nrf_comp_input_t *nrf)
262257
{
263258
switch (shim) {
264-
case COMP_NRF_COMP_PSEL_AIN0:
259+
case NRF_COMP_AIN0:
265260
*nrf = NRF_COMP_INPUT_0;
266261
break;
267262

268-
case COMP_NRF_COMP_PSEL_AIN1:
263+
case NRF_COMP_AIN1:
269264
*nrf = NRF_COMP_INPUT_1;
270265
break;
271266

272-
case COMP_NRF_COMP_PSEL_AIN2:
267+
case NRF_COMP_AIN2:
273268
*nrf = NRF_COMP_INPUT_2;
274269
break;
275270

276-
case COMP_NRF_COMP_PSEL_AIN3:
271+
case NRF_COMP_AIN3:
277272
*nrf = NRF_COMP_INPUT_3;
278273
break;
279274

280275
#if defined(COMP_PSEL_PSEL_AnalogInput4)
281-
case COMP_NRF_COMP_PSEL_AIN4:
276+
case NRF_COMP_AIN4:
282277
*nrf = NRF_COMP_INPUT_4;
283278
break;
284279
#endif
285280

286281
#if defined(COMP_PSEL_PSEL_AnalogInput5)
287-
case COMP_NRF_COMP_PSEL_AIN5:
282+
case NRF_COMP_AIN5:
288283
*nrf = NRF_COMP_INPUT_5;
289284
break;
290285
#endif
291286

292287
#if defined(COMP_PSEL_PSEL_AnalogInput6)
293-
case COMP_NRF_COMP_PSEL_AIN6:
288+
case NRF_COMP_AIN6:
294289
*nrf = NRF_COMP_INPUT_6;
295290
break;
296291
#endif
297292

298293
#if defined(COMP_PSEL_PSEL_AnalogInput7)
299-
case COMP_NRF_COMP_PSEL_AIN7:
294+
case NRF_COMP_AIN7:
300295
*nrf = NRF_COMP_INPUT_7;
301296
break;
302297
#endif
303298

304299
#if defined(COMP_PSEL_PSEL_VddDiv2)
305-
case COMP_NRF_COMP_PSEL_VDD_DIV2:
300+
case NRF_COMP_AIN_VDD_DIV2:
306301
*nrf = NRF_COMP_VDD_DIV2;
307302
break;
308303
#endif
309304

310305
#if defined(COMP_PSEL_PSEL_VddhDiv5)
311-
case COMP_NRF_COMP_PSEL_VDDH_DIV5:
306+
case NRF_COMP_AIN_VDDH_DIV5:
312307
*nrf = NRF_COMP_VDDH_DIV5;
313308
break;
314309
#endif
@@ -382,57 +377,57 @@ static int shim_nrf_comp_isource_to_nrf(enum comp_nrf_comp_isource shim,
382377
#endif
383378

384379
#if (NRF_COMP_HAS_AIN_AS_PIN)
385-
static int shim_nrf_comp_extrefsel_to_nrf(enum comp_nrf_comp_extrefsel shim,
380+
static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim,
386381
nrf_comp_ext_ref_t *nrf)
387382
{
388383
if (shim >= ARRAY_SIZE(shim_nrf_comp_ain_map)) {
389384
return -EINVAL;
390385
}
391386

392-
*nrf = shim_nrf_comp_ain_map[(uint32_t)shim];
387+
*nrf = shim_nrf_comp_ain_map[shim];
393388
return 0;
394389
}
395390
#else
396-
static int shim_nrf_comp_extrefsel_to_nrf(enum comp_nrf_comp_extrefsel shim,
391+
static int shim_nrf_comp_extrefsel_to_nrf(uint8_t shim,
397392
nrf_comp_ext_ref_t *nrf)
398393
{
399394
switch (shim) {
400-
case COMP_NRF_COMP_EXTREFSEL_AIN0:
395+
case NRF_COMP_AIN0:
401396
*nrf = NRF_COMP_EXT_REF_0;
402397
break;
403398

404-
case COMP_NRF_COMP_EXTREFSEL_AIN1:
399+
case NRF_COMP_AIN1:
405400
*nrf = NRF_COMP_EXT_REF_1;
406401
break;
407402

408-
case COMP_NRF_COMP_EXTREFSEL_AIN2:
403+
case NRF_COMP_AIN2:
409404
*nrf = NRF_COMP_EXT_REF_2;
410405
break;
411406

412-
case COMP_NRF_COMP_EXTREFSEL_AIN3:
407+
case NRF_COMP_AIN3:
413408
*nrf = NRF_COMP_EXT_REF_3;
414409
break;
415410

416411
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference4)
417-
case COMP_NRF_COMP_EXTREFSEL_AIN4:
412+
case NRF_COMP_AIN4:
418413
*nrf = NRF_COMP_EXT_REF_4;
419414
break;
420415
#endif
421416

422417
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference5)
423-
case COMP_NRF_COMP_EXTREFSEL_AIN5:
418+
case NRF_COMP_AIN5:
424419
*nrf = NRF_COMP_EXT_REF_5;
425420
break;
426421
#endif
427422

428423
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference6)
429-
case COMP_NRF_COMP_EXTREFSEL_AIN6:
424+
case NRF_COMP_AIN6:
430425
*nrf = NRF_COMP_EXT_REF_6;
431426
break;
432427
#endif
433428

434429
#if defined(COMP_EXTREFSEL_EXTREFSEL_AnalogReference7)
435-
case COMP_NRF_COMP_EXTREFSEL_AIN7:
430+
case NRF_COMP_AIN7:
436431
*nrf = NRF_COMP_EXT_REF_7;
437432
break;
438433
#endif

0 commit comments

Comments
 (0)