From 4c0df2892d55628b9029d05f5f7b16af939d23b1 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 13 Apr 2022 18:02:17 +0200 Subject: [PATCH] nrf: fix CGo errors after TinyGo update For details, see: https://github.com/tinygo-org/tinygo/pull/2774 --- adapter_sd.go | 8 ++++++++ gattc_sd.go | 4 ++-- gatts_sd.go | 1 + uuid_sd.go | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/adapter_sd.go b/adapter_sd.go index 338af8e..e3c40ec 100644 --- a/adapter_sd.go +++ b/adapter_sd.go @@ -10,6 +10,14 @@ import ( "unsafe" ) +// #include "ble.h" +// #ifdef NRF51 +// #include "nrf_soc.h" +// #else +// #include "nrf_nvic.h" +// #endif +import "C" + var ( ErrNotDefaultAdapter = errors.New("bluetooth: not the default adapter") ) diff --git a/gattc_sd.go b/gattc_sd.go index 197b339..a237a8d 100644 --- a/gattc_sd.go +++ b/gattc_sd.go @@ -134,7 +134,7 @@ func (d *Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) { // Store the discovered service. svc := DeviceService{ - uuid: suuid, + uuid: shortUUID(suuid), connectionHandle: d.connectionHandle, startHandle: startHandle, endHandle: endHandle, @@ -276,7 +276,7 @@ func (s *DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacter permissions |= CharacteristicIndicatePermission } - dc := DeviceCharacteristic{uuid: discoveringCharacteristic.uuid} + dc := DeviceCharacteristic{uuid: shortUUID(discoveringCharacteristic.uuid)} dc.permissions = permissions dc.valueHandle = foundCharacteristicHandle diff --git a/gatts_sd.go b/gatts_sd.go index 796fb24..6255c1f 100644 --- a/gatts_sd.go +++ b/gatts_sd.go @@ -8,6 +8,7 @@ package bluetooth #define SVCALL_AS_NORMAL_FUNCTION #include "ble_gap.h" +#include "ble_gatts.h" */ import "C" diff --git a/uuid_sd.go b/uuid_sd.go index abe93ad..9b68a2b 100644 --- a/uuid_sd.go +++ b/uuid_sd.go @@ -39,7 +39,7 @@ func (s shortUUID) UUID() UUID { // IsIn checks the passed in slice of short UUIDs to see if this uuid is in it. func (s shortUUID) IsIn(uuids []C.ble_uuid_t) bool { for _, u := range uuids { - if u == s { + if shortUUID(u) == s { return true } }