From 3112fe1b27ebed36ab57095810c0a188704c699b Mon Sep 17 00:00:00 2001 From: soypat Date: Mon, 12 Jun 2023 00:09:27 -0300 Subject: [PATCH] add latest barebone additions --- .gitignore | 1 + examples/barebones/barebones.go | 18 ++++++++---------- sx127x/barebones.go | 3 +++ sx127x/sx127x.go | 3 ++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 1e58d2f..000ccc7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ # Test binary, built with `go test -c` *.test +local # Output of the go coverage tool, specifically when used with LiteIDE *.out diff --git a/examples/barebones/barebones.go b/examples/barebones/barebones.go index a782442..d405d6d 100644 --- a/examples/barebones/barebones.go +++ b/examples/barebones/barebones.go @@ -9,13 +9,11 @@ import ( ) const ( - pinCS0 = machine.GPIO27 - pinCS1 = machine.GPIO28 - pinRST0 = machine.GPIO29 - pinRST1 = machine.GPIO29 - pinMOSI = machine.GPIO3 - pinMISO = machine.GPIO4 - pinSCK = machine.GPIO6 + pinSCK = machine.GPIO18 + pinMOSI = machine.GPIO19 + pinMISO = machine.GPIO16 + pinCS0 = machine.GPIO8 + pinRST0 = machine.GPIO9 pinDIO0 = machine.GPIO7 ) @@ -69,11 +67,11 @@ func setup() { panic(err.Error()) } pinCS0.Configure(machine.PinConfig{Mode: machine.PinOutput}) - pinCS1.Configure(machine.PinConfig{Mode: machine.PinOutput}) pinRST0.Configure(machine.PinConfig{Mode: machine.PinOutput}) - pinRST1.Configure(machine.PinConfig{Mode: machine.PinOutput}) - dev0 = &sx127x.DeviceLoRaBare{DL: *sx127x.NewLoRa(bus, pinCS0.Set, pinRST0.Set)} pinDIO0.Configure(machine.PinConfig{Mode: machine.PinInputPulldown}) + + dev0 = &sx127x.DeviceLoRaBare{DL: *sx127x.NewLoRa(bus, pinCS0.Set, pinRST0.Set)} + // dev1 = sx127x.NewLoRa(bus, pinCS1.Set, pinRST1.Set) cfg = sx127x.DefaultConfig(lora.Freq433_0M) diff --git a/sx127x/barebones.go b/sx127x/barebones.go index 2ff5398..714a5d3 100644 --- a/sx127x/barebones.go +++ b/sx127x/barebones.go @@ -12,6 +12,9 @@ type DeviceLoRaBare struct { } func (d *DeviceLoRaBare) Configure(c lora.Config) (err error) { + // Taken from both: + // pico-lorawan/src/lorawan.c + // pico-lorawan/lib/LoRaMac-node/src/radio/sx1276/sx1276.c d.DL.Reset() // Seems to take just under ~6ms. Wait 20ms. err = d.DL.rxFSKChainCalibration(20 * time.Millisecond) diff --git a/sx127x/sx127x.go b/sx127x/sx127x.go index 08530ef..61eee98 100644 --- a/sx127x/sx127x.go +++ b/sx127x/sx127x.go @@ -245,6 +245,7 @@ func (d *DeviceLoRa) Reset() { time.Sleep(1 * time.Millisecond) d.rst(true) time.Sleep(6 * time.Millisecond) + d.csEnable(false) } // IsConnected reads the version register and checks if it matches the expected value. @@ -947,7 +948,7 @@ func (d *DeviceLoRa) setHopPeriod(val uint8) error { return d.Write8(regHOP_PERI func (d *DeviceLoRa) writeMasked8(addr uint8, mask, value byte) error { if value != 0 && value&^mask != 0 { - println("value", value, "mask", mask) + println("addr", addr, "value", value, "mask", mask) panic("misuse of writeMasked8") // Bug in this package if hit. } existing, err := d.read8(addr)