diff --git a/src/machine/machine_nrf52840.go b/src/machine/machine_nrf52840.go index c30933ba4..c858355fd 100644 --- a/src/machine/machine_nrf52840.go +++ b/src/machine/machine_nrf52840.go @@ -110,3 +110,7 @@ func eraseBlockSize() int64 { } const spiMaxBufferSize = 0xffff // from the datasheet: TXD.MAXCNT and RXD.MAXCNT + +// ADC instance for the VDDH input pin. This pin is typically connected to USB +// input voltage (~5V) or directly to a battery. +var ADC_VDDH = ADC{adcVDDHPin} diff --git a/src/machine/machine_nrf52xxx.go b/src/machine/machine_nrf52xxx.go index 15e7a577c..6fa267e7b 100644 --- a/src/machine/machine_nrf52xxx.go +++ b/src/machine/machine_nrf52xxx.go @@ -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 }