Skip to content

Commit 03986a4

Browse files
nordic-krchnordicjm
authored andcommitted
[nrf fromlist] drivers: adc: nrfx_saadc: Add validation of channel configuration
On nrf54h20 there are additional analog pins (AIN8+). When differential mode is used they must not be mixed with AIN0-AIN7. Add build time validation which detects if configuration is invalid. Upstream PR #: 87405 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent fb81ddb commit 03986a4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

drivers/adc/adc_nrfx_saadc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,29 @@ static DEVICE_API(adc, adc_nrfx_driver_api) = {
719719
#endif
720720
};
721721

722+
#ifdef NRF_SAADC_AIN8
723+
/* AIN8-AIN14 inputs are on 3v3 GPIO port and they cannot be mixed with other
724+
* analog inputs (from 1v8 ports) in differential mode.
725+
*/
726+
#define CH_IS_3V3(val) (val >= NRF_SAADC_AIN8)
727+
728+
#define CH_IS_DIFF(node) DT_PROP(node, zephyr_differential)
729+
730+
#define CH_MIX_3V3_1V8_CHECK(node) \
731+
(!CH_IS_DIFF(node) || \
732+
!(CH_IS_3V3(DT_PROP_OR(node, zephyr_input_positive, 0)) ^ \
733+
CH_IS_3V3(DT_PROP_OR(node, zephyr_input_negative, 0))))
734+
#else
735+
#define CH_MIX_3V3_1V8_CHECK(node) true
736+
#endif
737+
738+
#define VALIDATE_CHANNEL_CONFIG(node) \
739+
BUILD_ASSERT(CH_MIX_3V3_1V8_CHECK(node) == true, \
740+
"1v8 inputs cannot be mixed with 3v3 inputs");
741+
742+
/* Validate configuration of all channels. */
743+
#define VALIDATE_CHANNELS_CONFIG(inst) DT_FOREACH_CHILD(DT_DRV_INST(inst), VALIDATE_CHANNEL_CONFIG)
744+
722745
/*
723746
* There is only one instance on supported SoCs, so inst is guaranteed
724747
* to be 0 if any instance is okay. (We use adc_0 above, so the driver
@@ -731,6 +754,7 @@ static DEVICE_API(adc, adc_nrfx_driver_api) = {
731754
#define SAADC_INIT(inst) \
732755
BUILD_ASSERT((inst) == 0, \
733756
"multiple instances not supported"); \
757+
VALIDATE_CHANNELS_CONFIG(inst) \
734758
PM_DEVICE_DT_INST_DEFINE(0, saadc_pm_hook, 1); \
735759
DEVICE_DT_INST_DEFINE(0, \
736760
init_saadc, \

0 commit comments

Comments
 (0)