-
Couldn't load subscription status.
- Fork 173
ninafw: allow custom config #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //go:build ninafw && ninafw_featherwing_init | ||
|
|
||
| package bluetooth | ||
|
|
||
| import ( | ||
| "machine" | ||
| ) | ||
|
|
||
| func init() { | ||
| AdapterConfig = NINAConfig{ | ||
| UART: machine.DefaultUART, | ||
| CS: machine.D13, | ||
| ACK: machine.D11, | ||
| GPIO0: machine.D10, | ||
| RESETN: machine.D12, | ||
| CTS: machine.D11, // same as ACK | ||
| RTS: machine.D10, // same as GPIO0 | ||
| BaudRate: 115200, | ||
| ResetInverted: true, | ||
| SoftFlowControl: true, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //go:build ninafw && ninafw_machine_init | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about name |
||
|
|
||
| package bluetooth | ||
|
|
||
| import ( | ||
| "machine" | ||
| ) | ||
|
|
||
| func init() { | ||
| AdapterConfig = NINAConfig{ | ||
| UART: machine.UART_NINA, | ||
| CS: machine.NINA_CS, | ||
| ACK: machine.NINA_ACK, | ||
| GPIO0: machine.NINA_GPIO0, | ||
| RESETN: machine.NINA_RESETN, | ||
| CTS: machine.NINA_CTS, | ||
| RTS: machine.NINA_RTS, | ||
| BaudRate: machine.NINA_BAUDRATE, | ||
| ResetInverted: machine.NINA_RESET_INVERTED, | ||
| SoftFlowControl: machine.NINA_SOFT_FLOWCONTROL, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,29 @@ import ( | |
|
|
||
| const maxConnections = 1 | ||
|
|
||
| // NINAConfig encapsulates the hardware options for the NINA firmware | ||
| type NINAConfig struct { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest name this |
||
| UART *machine.UART | ||
|
|
||
| CS machine.Pin | ||
| ACK machine.Pin | ||
| GPIO0 machine.Pin | ||
| RESETN machine.Pin | ||
|
|
||
| TX machine.Pin | ||
| RX machine.Pin | ||
| CTS machine.Pin | ||
| RTS machine.Pin | ||
|
|
||
| BaudRate uint32 | ||
| ResetInverted bool | ||
| SoftFlowControl bool | ||
| } | ||
|
|
||
| // AdapterConfig is used to set the hardware options for the NINA adapter prior | ||
| // to calling DefaultAdapter.Enable() | ||
| var AdapterConfig NINAConfig | ||
|
|
||
| // Adapter represents the UART connection to the NINA fw. | ||
| type Adapter struct { | ||
| hci *hci | ||
|
|
@@ -40,37 +63,37 @@ var DefaultAdapter = &Adapter{ | |
| // Bluetooth-related calls (unless otherwise indicated). | ||
| func (a *Adapter) Enable() error { | ||
| // reset the NINA in BLE mode | ||
| machine.NINA_CS.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
| machine.NINA_CS.Low() | ||
| AdapterConfig.CS.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
| AdapterConfig.CS.Low() | ||
|
|
||
| if machine.NINA_RESET_INVERTED { | ||
| if AdapterConfig.ResetInverted { | ||
| resetNINAInverted() | ||
| } else { | ||
| resetNINA() | ||
| } | ||
|
|
||
| // serial port for nina chip | ||
| uart := machine.UART_NINA | ||
| uart := AdapterConfig.UART | ||
| cfg := machine.UARTConfig{ | ||
| TX: machine.NINA_TX, | ||
| RX: machine.NINA_RX, | ||
| BaudRate: machine.NINA_BAUDRATE, | ||
| TX: AdapterConfig.TX, | ||
| RX: AdapterConfig.RX, | ||
| BaudRate: AdapterConfig.BaudRate, | ||
| } | ||
| if !machine.NINA_SOFT_FLOWCONTROL { | ||
| cfg.CTS = machine.NINA_CTS | ||
| cfg.RTS = machine.NINA_RTS | ||
| if !AdapterConfig.SoftFlowControl { | ||
| cfg.CTS = AdapterConfig.CTS | ||
| cfg.RTS = AdapterConfig.RTS | ||
| } | ||
|
|
||
| uart.Configure(cfg) | ||
|
|
||
| a.hci, a.att = newBLEStack(uart) | ||
| if machine.NINA_SOFT_FLOWCONTROL { | ||
| a.hci.softRTS = machine.NINA_RTS | ||
| if AdapterConfig.SoftFlowControl { | ||
| a.hci.softRTS = AdapterConfig.RTS | ||
| a.hci.softRTS.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
| a.hci.softRTS.High() | ||
|
|
||
| a.hci.softCTS = machine.NINA_CTS | ||
| machine.NINA_CTS.Configure(machine.PinConfig{Mode: machine.PinInput}) | ||
| a.hci.softCTS = AdapterConfig.CTS | ||
| AdapterConfig.CTS.Configure(machine.PinConfig{Mode: machine.PinInput}) | ||
| } | ||
|
|
||
| a.hci.start() | ||
|
|
@@ -133,20 +156,20 @@ func makeNINAAddress(mac MAC) [6]uint8 { | |
| } | ||
|
|
||
| func resetNINA() { | ||
| machine.NINA_RESETN.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
| AdapterConfig.RESETN.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
|
|
||
| machine.NINA_RESETN.High() | ||
| AdapterConfig.RESETN.High() | ||
| time.Sleep(100 * time.Millisecond) | ||
| machine.NINA_RESETN.Low() | ||
| AdapterConfig.RESETN.Low() | ||
| time.Sleep(1000 * time.Millisecond) | ||
| } | ||
|
|
||
| func resetNINAInverted() { | ||
| machine.NINA_RESETN.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
| AdapterConfig.RESETN.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
|
|
||
| machine.NINA_RESETN.Low() | ||
| AdapterConfig.RESETN.Low() | ||
| time.Sleep(100 * time.Millisecond) | ||
| machine.NINA_RESETN.High() | ||
| AdapterConfig.RESETN.High() | ||
| time.Sleep(1000 * time.Millisecond) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
ninafw_featherwing_initcan just befeatherwing.