mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 03:24:00 +00:00
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:
committed by
Ron Evans
parent
b1083d78c7
commit
887ac286ff
@@ -110,3 +110,7 @@ func eraseBlockSize() int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const spiMaxBufferSize = 0xffff // from the datasheet: TXD.MAXCNT and RXD.MAXCNT
|
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}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ func CPUFrequency() uint32 {
|
|||||||
return 64000000
|
return 64000000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var adcVDDHPin = Pin(254) // special pin number for VDDH on the nrf52840
|
||||||
|
|
||||||
// InitADC initializes the registers needed for ADC.
|
// InitADC initializes the registers needed for ADC.
|
||||||
func InitADC() {
|
func InitADC() {
|
||||||
// Enable ADC.
|
// Enable ADC.
|
||||||
@@ -136,6 +138,12 @@ func (a *ADC) Get() uint16 {
|
|||||||
adcPin = nrf.SAADC_CH_PSELP_PSELP_AnalogInput6
|
adcPin = nrf.SAADC_CH_PSELP_PSELP_AnalogInput6
|
||||||
case 31:
|
case 31:
|
||||||
adcPin = nrf.SAADC_CH_PSELP_PSELP_AnalogInput7
|
adcPin = nrf.SAADC_CH_PSELP_PSELP_AnalogInput7
|
||||||
|
case adcVDDHPin:
|
||||||
|
if Device == "nrf52840" {
|
||||||
|
adcPin = 0x0D // VDDHDIV5 on the nrf52840
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user