sx126x: pre-define all errors to avoid heap allocations

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2023-01-15 12:22:24 +01:00
parent 2174b039a5
commit 10458f377f
+7 -7
View File
@@ -14,9 +14,11 @@ import (
)
var (
errWaitWhileBusyTimeout = errors.New("WaitBusy Timeout")
errWaitWhileBusyTimeout = errors.New("WaitWhileBusy Timeout")
errLowPowerTxNotSupported = errors.New("RFSWITCH_TX_LP not supported")
errRadioNotFound = errors.New("LoRa radio not found")
errUnexpectedRxRadioEvent = errors.New("Unexpected Radio Event during RX")
errUnexpectedTxRadioEvent = errors.New("Unexpected Radio Event during TX")
)
const (
@@ -50,12 +52,10 @@ type Device struct {
// New creates a new SX126x connection.
func New(spi drivers.SPI) *Device {
c := make(chan lora.RadioEvent, 10)
d := Device{
return &Device{
spi: spi,
radioEventChan: c,
radioEventChan: make(chan lora.RadioEvent, 10),
}
return &d
}
const (
@@ -618,7 +618,7 @@ func (d *Device) Tx(pkt []uint8, timeoutMs uint32) error {
msg := <-d.GetRadioEventChan()
if msg.EventType != lora.RadioEventTxDone {
return errors.New("Unexpected Radio Event while TX")
return errUnexpectedTxRadioEvent
}
return nil
}
@@ -650,7 +650,7 @@ func (d *Device) Rx(timeoutMs uint32) ([]uint8, error) {
if msg.EventType == lora.RadioEventTimeout {
return nil, nil
} else if msg.EventType != lora.RadioEventRxDone {
return nil, errors.New("Unexpected Radio Event while RX")
return nil, errUnexpectedRxRadioEvent
}
pLen, pStart := d.GetRxBufferStatus()