nrf: add ADC_VDDH which is an ADC pin for VDDH

VDDH is typically connected to USB (~5V) or directly to a battery.
Measuring the voltage on VDDH is a way to measure the current battery
voltage, which in turn can be useful to determine how much power is left
in the battery.

I've special cased the nrf52840 in a somewhat unusual way, maybe there
is a better way, feel free to comment!
This commit is contained in:
Ayke van Laethem
2025-11-30 11:14:57 +01:00
committed by Ron Evans
parent b1083d78c7
commit 887ac286ff
2 changed files with 12 additions and 0 deletions
+8
View File
@@ -12,6 +12,8 @@ func CPUFrequency() uint32 {
return 64000000
}
var adcVDDHPin = Pin(254) // special pin number for VDDH on the nrf52840
// InitADC initializes the registers needed for ADC.
func InitADC() {
// Enable ADC.
@@ -136,6 +138,12 @@ func (a *ADC) Get() uint16 {
adcPin = nrf.SAADC_CH_PSELP_PSELP_AnalogInput6
case 31:
adcPin = nrf.SAADC_CH_PSELP_PSELP_AnalogInput7
case adcVDDHPin:
if Device == "nrf52840" {
adcPin = 0x0D // VDDHDIV5 on the nrf52840
} else {
return 0
}
default:
return 0
}