prototooth/adapter_nrf528xx.go
Ayke van Laethem bb8767730c nrf: add support for S113 SoftDevice
This SoftDevice is used by default on the BBC micro:bit v2 so it's a
good idea to add support here.

Unfortunately this SoftDevice does not support scanning and connecting
to other devices. This means that I unfortunately had to duplicate the
event handler. I managed to refactor most other code to avoid
duplicating much more. (This is when macros would have been useful in
Go...)
2021-04-15 15:37:36 +02:00

57 lines
1.2 KiB
Go

// +build softdevice,s113v7 softdevice,s132v6 softdevice,s140v6 softdevice,s140v7
package bluetooth
// This file defines the SoftDevice adapter for all nrf52-series chips.
/*
// Define SoftDevice functions as regular function declarations (not inline
// static functions).
#define SVCALL_AS_NORMAL_FUNCTION
#include "nrf_sdm.h"
#include "nrf_nvic.h"
#include "ble.h"
#include "ble_gap.h"
void assertHandler(void);
*/
import "C"
import (
"machine"
"unsafe"
)
//export assertHandler
func assertHandler() {
println("SoftDevice assert")
}
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,
}
//go:extern __app_ram_base
var appRAMBase [0]uint32
func (a *Adapter) enable() error {
// Enable the SoftDevice.
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)
}
// Enable the BLE stack.
appRAMBase := uint32(uintptr(unsafe.Pointer(&appRAMBase)))
errCode = C.sd_ble_enable(&appRAMBase)
return makeError(errCode)
}