mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-17 05:13:23 +00:00
sx126x: pre-define all errors to avoid heap allocations
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
+7
-7
@@ -14,9 +14,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errWaitWhileBusyTimeout = errors.New("WaitBusy Timeout")
|
errWaitWhileBusyTimeout = errors.New("WaitWhileBusy Timeout")
|
||||||
errLowPowerTxNotSupported = errors.New("RFSWITCH_TX_LP not supported")
|
errLowPowerTxNotSupported = errors.New("RFSWITCH_TX_LP not supported")
|
||||||
errRadioNotFound = errors.New("LoRa radio not found")
|
errRadioNotFound = errors.New("LoRa radio not found")
|
||||||
|
errUnexpectedRxRadioEvent = errors.New("Unexpected Radio Event during RX")
|
||||||
|
errUnexpectedTxRadioEvent = errors.New("Unexpected Radio Event during TX")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -50,12 +52,10 @@ type Device struct {
|
|||||||
|
|
||||||
// New creates a new SX126x connection.
|
// New creates a new SX126x connection.
|
||||||
func New(spi drivers.SPI) *Device {
|
func New(spi drivers.SPI) *Device {
|
||||||
c := make(chan lora.RadioEvent, 10)
|
return &Device{
|
||||||
d := Device{
|
|
||||||
spi: spi,
|
spi: spi,
|
||||||
radioEventChan: c,
|
radioEventChan: make(chan lora.RadioEvent, 10),
|
||||||
}
|
}
|
||||||
return &d
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -618,7 +618,7 @@ func (d *Device) Tx(pkt []uint8, timeoutMs uint32) error {
|
|||||||
|
|
||||||
msg := <-d.GetRadioEventChan()
|
msg := <-d.GetRadioEventChan()
|
||||||
if msg.EventType != lora.RadioEventTxDone {
|
if msg.EventType != lora.RadioEventTxDone {
|
||||||
return errors.New("Unexpected Radio Event while TX")
|
return errUnexpectedTxRadioEvent
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -650,7 +650,7 @@ func (d *Device) Rx(timeoutMs uint32) ([]uint8, error) {
|
|||||||
if msg.EventType == lora.RadioEventTimeout {
|
if msg.EventType == lora.RadioEventTimeout {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
} else if msg.EventType != lora.RadioEventRxDone {
|
} else if msg.EventType != lora.RadioEventRxDone {
|
||||||
return nil, errors.New("Unexpected Radio Event while RX")
|
return nil, errUnexpectedRxRadioEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
pLen, pStart := d.GetRxBufferStatus()
|
pLen, pStart := d.GetRxBufferStatus()
|
||||||
|
|||||||
Reference in New Issue
Block a user