nrf52: use low-frequency crystal oscillator when available

I couldn't measure a difference in my setup, apparently my multimeter is
not able to handle the high-to-low current transition when entering
sleep mode. But it _should_ reduce current consumption a little bit.
This commit is contained in:
Ayke van Laethem 2020-08-01 18:39:34 +02:00
parent d2228b9e79
commit de824e1884
No known key found for this signature in database
GPG key ID: E97FF5335DFDFDED

View file

@ -16,23 +16,30 @@ void assertHandler(void);
*/
import "C"
import "unsafe"
import (
"machine"
"unsafe"
)
//export assertHandler
func assertHandler() {
println("SoftDevice assert")
}
var clockConfig C.nrf_clock_lf_cfg_t = C.nrf_clock_lf_cfg_t{
source: C.NRF_CLOCK_LF_SRC_RC,
rc_ctiv: 16,
rc_temp_ctiv: 2,
accuracy: C.NRF_CLOCK_LF_ACCURACY_500_PPM,
var clockConfigXtal C.nrf_clock_lf_cfg_t = C.nrf_clock_lf_cfg_t{
source: C.NRF_CLOCK_LF_SRC_XTAL,
rc_ctiv: 0,
rc_temp_ctiv: 0,
accuracy: C.NRF_CLOCK_LF_ACCURACY_250_PPM,
}
func (a *Adapter) enable() error {
// Enable the SoftDevice.
errCode := C.sd_softdevice_enable(&clockConfig, C.nrf_fault_handler_t(C.assertHandler))
var clockConfig *C.nrf_clock_lf_cfg_t
if machine.HasLowFrequencyCrystal {
clockConfig = &clockConfigXtal
}
errCode := C.sd_softdevice_enable(clockConfig, C.nrf_fault_handler_t(C.assertHandler))
if errCode != 0 {
return Error(errCode)
}