8000 Merge pull request #9161 from dhalbert/fix-nordic-analogin · jepler/circuitpython@25dd72d · GitHub
[go: up one dir, main page]

Skip to content

Commit 25dd72d

Browse files
authored
Merge pull request adafruit#9161 from dhalbert/fix-nordic-analogin
nrf: fix regression in AnalogIn, fix problem with reuse as digital pin
2 parents 0ef433b + 6d9f1ad commit 25dd72d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ports/nrf/common-hal/analogio/AnalogIn.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
127127
// I think I'd like to declare `value` as volatile, but that causes type errors.
128128
asm volatile ("" : : : "memory");
129129

130+
// Disconnect ADC from pin.
131+
nrf_saadc_channel_input_set(NRF_SAADC, CHANNEL_NO, NRF_SAADC_INPUT_DISABLED, NRF_SAADC_INPUT_DISABLED);
132+
133+
// value is signed and might be (slightly) < 0, even on single-ended conversions, so force to 0.
134+
if (value < 0) {
135+
value = 0;
136+
}
137+
130138
// Stretch 14-bit ADC reading to 16-bit range
131139
return (value << 2) | (value >> 12);
132140
}

0 commit comments

Comments
 (0)
0