Skip to content

Commit

Permalink
ninafw: add support for Arduino Nano IoT 33
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Jan 5, 2024
1 parent 190c4be commit f0b813b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
22 changes: 3 additions & 19 deletions adapter_ninafw.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Adapter struct {
isDefault bool
scanning bool

reset func()
connectHandler func(device Address, connected bool)

connectedDevices []*Device
Expand All @@ -31,7 +30,6 @@ type Adapter struct {
// Make sure to call Enable() before using it to initialize the adapter.
var DefaultAdapter = &Adapter{
isDefault: true,
reset: resetNINAInverted,
connectHandler: func(device Address, connected bool) {
return
},
Expand All @@ -45,14 +43,14 @@ func (a *Adapter) Enable() error {
machine.NINA_CS.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.NINA_RESETN.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.NINA_CS.Low()
a.reset()
resetNINA()

// serial port for nina chip
uart := machine.UART1
uart := machine.UART_NINA
uart.Configure(machine.UARTConfig{
TX: machine.NINA_TX,
RX: machine.NINA_RX,
BaudRate: 115200,
BaudRate: ninaBaudrate,
CTS: machine.NINA_CTS,
RTS: machine.NINA_RTS,
})
Expand Down Expand Up @@ -118,20 +116,6 @@ func makeNINAAddress(mac MAC) [6]uint8 {
}
}

func resetNINA() {
machine.NINA_RESETN.High()
time.Sleep(100 * time.Millisecond)
machine.NINA_RESETN.Low()
time.Sleep(1000 * time.Millisecond)
}

func resetNINAInverted() {
machine.NINA_RESETN.Low()
time.Sleep(100 * time.Millisecond)
machine.NINA_RESETN.High()
time.Sleep(1000 * time.Millisecond)
}

func (a *Adapter) startNotifications() {
if a.notificationsStarted {
return
Expand Down
15 changes: 15 additions & 0 deletions ninafw_reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build ninafw && !ninafw_reset_inverse

package bluetooth

import (
"machine"
"time"
)

func resetNINA() {
machine.NINA_RESETN.High()
time.Sleep(100 * time.Millisecond)
machine.NINA_RESETN.Low()
time.Sleep(1000 * time.Millisecond)
}
15 changes: 15 additions & 0 deletions ninafw_reset_inverse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build ninafw && ninafw_reset_inverse

package bluetooth

import (
"machine"
"time"
)

func resetNINA() {
machine.NINA_RESETN.Low()
time.Sleep(100 * time.Millisecond)
machine.NINA_RESETN.High()
time.Sleep(1000 * time.Millisecond)
}
5 changes: 5 additions & 0 deletions ninafw_uart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build ninafw && !ninafw_uart_slow

package bluetooth

const ninaBaudrate = 912600
5 changes: 5 additions & 0 deletions ninafw_uart_slow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build ninafw && ninafw_uart_slow

package bluetooth

const ninaBaudrate = 115200

0 comments on commit f0b813b

Please sign in to comment.