Skip to content

Commit

Permalink
nrf52: use low-frequency crystal oscillator when available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aykevl committed Aug 1, 2020
1 parent d2228b9 commit de824e1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions adapter_nrf528xx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit de824e1

Please sign in to comment.