@@ -12,10 +12,7 @@ import (
1212const maxConnections = 1
1313
1414var (
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
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).
6360func (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
146160func 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
153167func 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
0 commit comments