nrf: add ReadTemperature method

Similar to the rp2040, the nrf has an on-board temperature sensor.

The main reason why I added this function was to show how this new API
is more general and can be used on multiple chips.
Этот коммит содержится в:
Ayke van Laethem 2022-09-18 23:13:15 +02:00 коммит произвёл Ron Evans
родитель 70b3ece6ec
коммит a68f7e4ce3

Просмотреть файл

@ -372,3 +372,14 @@ func GetRNG() (ret uint32, err error) {
return ret, nil return ret, nil
} }
// ReadTemperature reads the silicon die temperature of the chip. The return
// value is in milli-celsius.
func ReadTemperature() int32 {
nrf.TEMP.TASKS_START.Set(1)
for nrf.TEMP.EVENTS_DATARDY.Get() == 0 {
}
temp := int32(nrf.TEMP.TEMP.Get()) * 250 // the returned value is in units of 0.25°C
nrf.TEMP.EVENTS_DATARDY.Set(0)
return temp
}