Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
name: macos-14
runs-on: macos-14
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Go
uses: actions/setup-go@v6
with:
go-version: '1.23.12'
- name: Checkout
uses: actions/checkout@v6
go-version-file: 'go.mod'
- name: Run unit tests
run: go test
- name: "Run macOS smoke tests"
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ smoketest-tinygo:
@md5sum test.hex
$(TINYGO) build -o test.uf2 -size=short -target=badger2040-w ./examples/advertisement
@md5sum test.hex
$(TINYGO) build -o test.bin -size=short -target=xiao-esp32c3 ./examples/advertisement
@md5sum test.bin
$(TINYGO) build -o test.bin -size=short -target=xiao-esp32c3 ./examples/discover
@md5sum test.bin

smoketest-linux:
# Test on Linux.
Expand Down
71 changes: 71 additions & 0 deletions adapter_espradio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//go:build espradio

package bluetooth

import (
"runtime"

"tinygo.org/x/espradio"
)

const maxConnections = 1

// Adapter represents the BLE adapter on the ESP32 via espradio VHCI transport.
type Adapter struct {
hciAdapter
}

// DefaultAdapter is the default adapter on the current system.
//
// Make sure to call Enable() before using it to initialize the adapter.
var DefaultAdapter = &Adapter{
hciAdapter: hciAdapter{
isDefault: true,
connectHandler: func(device Device, connected bool) {
return
},
connectedDevices: make([]Device, 0, maxConnections),
},
}

// Enable configures the BLE stack. It must be called before any
// Bluetooth-related calls (unless otherwise indicated).
// For WiFi+BLE co-existence, call espradio.Enable() first.
func (a *Adapter) Enable() error {
if err := espradio.BLEInit(); err != nil {
return err
}

transport := &hciVHCI{}

a.hci, a.att = newBLEStack(transport)

a.enable()

return nil
}

// hciVHCI wraps espradio's BLE VHCI transport to implement the
// unexported hciTransport interface.
type hciVHCI struct {
t espradio.VHCITransport
}

func (h *hciVHCI) startRead() { runtime.Gosched() }
func (h *hciVHCI) endRead() {}

func (h *hciVHCI) Buffered() int {
return h.t.Buffered()
}

func (h *hciVHCI) ReadByte() (byte, error) {
return h.t.ReadByte()
}

func (h *hciVHCI) Read(buf []byte) (int, error) {
return h.t.Read(buf)
}

func (h *hciVHCI) Write(buf []byte) (int, error) {
return h.t.Write(buf)
}
2 changes: 1 addition & 1 deletion adapter_hci.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build hci || ninafw || cyw43439
//go:build hci || ninafw || cyw43439 || espradio

package bluetooth

Expand Down
2 changes: 1 addition & 1 deletion att_hci.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build hci || ninafw || cyw43439
//go:build hci || ninafw || cyw43439 || espradio

package bluetooth

Expand Down
5 changes: 5 additions & 0 deletions examples/scanner/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package main

import (
"time"

"tinygo.org/x/bluetooth"
)

var adapter = bluetooth.DefaultAdapter

func main() {
time.Sleep(time.Second) // wait for the system to initialize
println("Starting BLE")

// Enable BLE interface.
must("enable BLE stack", adapter.Enable())

Expand Down
2 changes: 1 addition & 1 deletion gap_hci.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build hci || ninafw || cyw43439
//go:build hci || ninafw || cyw43439 || espradio

package bluetooth

Expand Down
2 changes: 1 addition & 1 deletion gattc_hci.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build hci || ninafw || cyw43439
//go:build hci || ninafw || cyw43439 || espradio

package bluetooth

Expand Down
2 changes: 1 addition & 1 deletion gatts_hci.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build hci || ninafw || cyw43439
//go:build hci || ninafw || cyw43439 || espradio

package bluetooth

Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module tinygo.org/x/bluetooth

go 1.23.8
go 1.24.4

require (
github.com/go-ole/go-ole v1.2.6
Expand All @@ -9,18 +9,19 @@ require (
github.com/soypat/cyw43439 v0.1.0
github.com/tinygo-org/cbgo v0.0.4
golang.org/x/crypto v0.12.0
tinygo.org/x/drivers v0.35.0
golang.org/x/sys v0.11.0
tinygo.org/x/drivers v0.35.1-0.20260604174950-1d695a231aef
tinygo.org/x/espradio v0.1.1-0.20260730102224-eccd37c7e46e
tinygo.org/x/tinyfont v0.6.0
tinygo.org/x/tinyterm v0.5.0
)

require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/soypat/lneto v0.1.0 // indirect
github.com/soypat/lneto v0.2.1 // indirect
github.com/soypat/seqs v0.0.0-20250124201400-0d65bc7c1710 // indirect
github.com/tinygo-org/pio v0.3.0 // indirect
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/soypat/cyw43439 v0.1.0 h1:3Nyqg2LSndhCYgCr2VXuL2nn73vyaJXAnD02veMoLvA=
github.com/soypat/cyw43439 v0.1.0/go.mod h1:R2uSILRwSPmcmmKy5Z0FtK4ypgiPf5YqK+F+IKmXqxc=
github.com/soypat/lneto v0.1.0 h1:VAHCJ33hvC3wDqhM0Vm7w0k6vwNsOCAsQ8XTrXJpS7I=
github.com/soypat/lneto v0.1.0/go.mod h1:g/8Lk+hIsMZydyWDJjK2YfsCuG6jA5mWCO6U+4S7w1U=
github.com/soypat/lneto v0.2.1 h1:o07lXylFCkRs4djA9PYrIf0oW+tMLjxO2/JbHv2XoK0=
github.com/soypat/lneto v0.2.1/go.mod h1:Be5PjwoYukvHFiUXxpYi8+ppH2F/gw/vjGBvFdv+Ti8=
github.com/soypat/seqs v0.0.0-20250124201400-0d65bc7c1710 h1:Y9fBuiR/urFY/m76+SAZTxk2xAOS2n85f+H1CugajeA=
github.com/soypat/seqs v0.0.0-20250124201400-0d65bc7c1710/go.mod h1:oCVCNGCHMKoBj97Zp9znLbQ1nHxpkmOY9X+UAGzOxc8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -45,8 +45,10 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
tinygo.org/x/drivers v0.35.0 h1:cTK36tsI/S4Mg3hCPH0MBjV/ta7XKQ+wpvch4mVqgsE=
tinygo.org/x/drivers v0.35.0/go.mod h1:DQgKyHkB4G6IEOKVTAjApbKnWGwESN91EVJO+nMOE9Y=
tinygo.org/x/drivers v0.35.1-0.20260604174950-1d695a231aef h1:nG/qd6hSQonHse2l8DYUrCuJSiCfcFD9n8YMze8sVo0=
tinygo.org/x/drivers v0.35.1-0.20260604174950-1d695a231aef/go.mod h1:DQgKyHkB4G6IEOKVTAjApbKnWGwESN91EVJO+nMOE9Y=
tinygo.org/x/espradio v0.1.1-0.20260730102224-eccd37c7e46e h1:m5UUMZzkBAf6rDtoD9d8lzv6YJdXNGctE62clvhOgc8=
tinygo.org/x/espradio v0.1.1-0.20260730102224-eccd37c7e46e/go.mod h1:1l1bd9M8w8iXQ5eFfOlyPpZT+0l+DutBLxSYIHPj2mI=
tinygo.org/x/tinyfont v0.6.0 h1:GibXDSFz6xrWnEDkDRo6vsbOyRw0MVj/eza3zNHMSHs=
tinygo.org/x/tinyfont v0.6.0/go.mod h1:onflMSkpWl7r7j4MIqhPEVV39pn7yL4N3MOePl3G+G8=
tinygo.org/x/tinyterm v0.5.0 h1:HusDSiTM290KzYM4+2X+ZfNM6Ll1yu13LpvIszlQE9M=
Expand Down
2 changes: 1 addition & 1 deletion hci.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ninafw || hci || cyw43439
//go:build ninafw || hci || cyw43439 || espradio

package bluetooth

Expand Down
2 changes: 1 addition & 1 deletion l2cap_hci.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ninafw || hci || cyw43439
//go:build ninafw || hci || cyw43439 || espradio

package bluetooth

Expand Down
2 changes: 1 addition & 1 deletion uuid_hci.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build hci || ninafw || cyw43439
//go:build hci || ninafw || cyw43439 || espradio

package bluetooth

Expand Down
Loading