Skip to content

Commit 3fccf08

Browse files
committed
more testing
1 parent b9f5114 commit 3fccf08

File tree

4 files changed

+74
-29
lines changed

4 files changed

+74
-29
lines changed

adapter_ninafw-machine.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build ninafw
1+
//go:build ninafw_machine_init
22

33
package bluetooth
44

@@ -7,9 +7,7 @@ import (
77
)
88

99
func init() {
10-
NINA_SCK = machine.NINA_SCK
11-
NINA_SDO = machine.NINA_SDO
12-
NINA_SDI = machine.NINA_SDI
10+
NINA_UART = machine.UART1
1311
NINA_CS = machine.NINA_CS
1412
NINA_ACK = machine.NINA_ACK
1513
NINA_GPIO0 = machine.NINA_GPIO0

adapter_ninafw.go

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import (
1212
const maxConnections = 1
1313

1414
var (
15-
// NINA-W102 Pins
16-
NINA_SCK machine.Pin
17-
NINA_SDO machine.Pin
18-
NINA_SDI machine.Pin
15+
NINA_UART *machine.UART
1916

2017
NINA_CS machine.Pin
2118
NINA_ACK machine.Pin
@@ -28,9 +25,9 @@ var (
2825
NINA_RTS machine.Pin
2926

3027
// NINA-W102 settings
31-
NINA_BAUDRATE = 115200
32-
NINA_RESET_INVERTED = true
33-
NINA_SOFT_FLOWCONTROL = false
28+
NINA_BAUDRATE uint32
29+
NINA_RESET_INVERTED bool
30+
NINA_SOFT_FLOWCONTROL bool
3431
)
3532

3633
// Adapter represents the UART connection to the NINA fw.
@@ -62,34 +59,51 @@ var DefaultAdapter = &Adapter{
6259
// Bluetooth-related calls (unless otherwise indicated).
6360
func (a *Adapter) Enable() error {
6461
// reset the NINA in BLE mode
65-
machine.NINA_CS.Configure(machine.PinConfig{Mode: machine.PinOutput})
66-
machine.NINA_RESETN.Configure(machine.PinConfig{Mode: machine.PinOutput})
67-
machine.NINA_CS.Low()
62+
NINA_CS.Configure(machine.PinConfig{Mode: machine.PinOutput})
63+
NINA_RESETN.Configure(machine.PinConfig{Mode: machine.PinOutput})
64+
NINA_CS.Low()
6865

69-
if machine.NINA_RESET_INVERTED {
66+
if _debug {
67+
println("tx:", NINA_TX, "rx:", NINA_RX, "baudrate:", NINA_BAUDRATE, "cts:", NINA_CTS, "rts:", NINA_RTS)
68+
}
69+
70+
// serial port for nina chip
71+
uart := NINA_UART
72+
if err := uart.Configure(machine.UARTConfig{
73+
TX: NINA_TX,
74+
RX: NINA_RX,
75+
BaudRate: NINA_BAUDRATE,
76+
CTS: NINA_CTS,
77+
RTS: NINA_RTS,
78+
}); err != nil {
79+
println("error configuring UART:", err.Error())
80+
return err
81+
}
82+
83+
if NINA_RESET_INVERTED {
7084
resetNINAInverted()
7185
} else {
7286
resetNINA()
7387
}
7488

75-
// serial port for nina chip
76-
uart := machine.UART1
77-
uart.Configure(machine.UARTConfig{
78-
TX: machine.NINA_TX,
79-
RX: machine.NINA_RX,
80-
BaudRate: machine.NINA_BAUDRATE,
81-
CTS: machine.NINA_CTS,
82-
RTS: machine.NINA_RTS,
83-
})
84-
8589
a.hci, a.att = newBLEStack(uart)
8690

91+
if _debug {
92+
println("starting hci")
93+
}
8794
a.hci.start()
8895

96+
if _debug {
97+
println("reseting hci")
98+
}
8999
if err := a.hci.reset(); err != nil {
90100
return err
91101
}
92102

103+
if _debug {
104+
println("hci reset successfully")
105+
}
106+
93107
time.Sleep(150 * time.Millisecond)
94108

95109
if err := a.hci.setEventMask(0x3FFFFFFFFFFFFFFF); err != nil {
@@ -144,16 +158,19 @@ func makeNINAAddress(mac MAC) [6]uint8 {
144158
}
145159

146160
func resetNINA() {
147-
machine.NINA_RESETN.High()
161+
NINA_RESETN.High()
148162
time.Sleep(100 * time.Millisecond)
149-
machine.NINA_RESETN.Low()
163+
NINA_RESETN.Low()
150164
time.Sleep(1000 * time.Millisecond)
151165
}
152166

153167
func resetNINAInverted() {
154-
machine.NINA_RESETN.Low()
168+
if _debug {
169+
println("resetNINAInverted")
170+
}
171+
NINA_RESETN.Low()
155172
time.Sleep(100 * time.Millisecond)
156-
machine.NINA_RESETN.High()
173+
NINA_RESETN.High()
157174
time.Sleep(1000 * time.Millisecond)
158175
}
159176

examples/scanner/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package main
22

33
import (
4+
"time"
5+
46
"tinygo.org/x/bluetooth"
57
)
68

79
var adapter = bluetooth.DefaultAdapter
810

911
func main() {
12+
13+
time.Sleep(2 * time.Second)
1014
// Enable BLE interface.
1115
must("enable BLE stack", adapter.Enable())
1216

examples/scanner/ninafw_custom.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build ninafw && !ninafw_machine_init
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/bluetooth"
9+
)
10+
11+
func init() {
12+
bluetooth.NINA_UART = machine.DefaultUART
13+
bluetooth.NINA_CS = machine.D13
14+
bluetooth.NINA_ACK = machine.D11
15+
bluetooth.NINA_GPIO0 = machine.D10
16+
bluetooth.NINA_RESETN = machine.D12
17+
bluetooth.NINA_BAUDRATE = 115200 // machine.NINA_BAUDRATE
18+
bluetooth.NINA_RESET_INVERTED = true // machine.NINA_RESET_INVERTED
19+
bluetooth.NINA_SOFT_FLOWCONTROL = true // machine.NINA_SOFT_FLOWCONTROL
20+
21+
bluetooth.NINA_TX = machine.UART_TX_PIN
22+
bluetooth.NINA_RX = machine.UART_RX_PIN
23+
24+
bluetooth.NINA_CTS = bluetooth.NINA_ACK
25+
bluetooth.NINA_RTS = bluetooth.NINA_GPIO0
26+
}

0 commit comments

Comments
 (0)