SkyLok/chip_test_example/lr1121_malnus_api.md
2026-05-29 09:30:44 +02:00

2.3 KiB
Raw Blame History

lr1121_malnus.hpp — API reference

#include "lr1121_malnus.hpp"   // namespace lr1121

Setup

lr1121::Config cfg;            // all fields have sensible defaults
cfg.freq_hz  = lr1121::FREQ_433;   // FREQ_433 / FREQ_868 / FREQ_2400
cfg.sf       = 7;              // spreading factor 612
cfg.bw       = 0x04;           // 0x03=62.5 kHz  0x04=125 kHz  0x05=250 kHz
cfg.cr       = 0x01;           // 0x01=4/5  0x02=4/6  0x03=4/7  0x04=4/8
cfg.tx_dbm   = 10;
cfg.pa_sel   = lr1121::PA_LP;  // PA_LP (014 dBm)  PA_HP (022 dBm)

lr1121::Radio radio;
if (!radio.begin(cfg))
    fprintf(stderr, "init failed: %s\n", lr1121::Radio::errorString(radio.lastError()));

TX / RX

bool ok = radio.send(data, len);              // blocks until TX_DONE or error
// returns: true=ok  false=error (check lastError)

lr1121::RxInfo info;

// one-shot: arm, wait timeout_ms, chip returns to standby
int n = radio.receive(buf, sizeof(buf), 1000, &info);

// continuous: arm once, chip stays in RX between packets
radio.startListening();
for (;;) {
    int n = radio.receive(buf, sizeof(buf), 0, &info); // 0 = wait forever per call
    if (n > 0) { /* handle */ }
}
radio.stopListening();   // returns chip to standby

// receive() returns: n>=0 bytes  -1=timeout/error  -2=crc error
// info.rssi_dbm  info.snr_db  info.signal_rssi_dbm

Runtime tuning (call between packets, chip stays in standby)

radio.setFrequency(lr1121::FREQ_868);
radio.setTxPower(20, lr1121::PA_HP);
radio.setModulation(9, 0x04, 0x01);   // sf, bw, cr

Diagnostics

lr1121::ChipVersion v = radio.chipVersion();  // v.hw  v.type  v.fw_hi  v.fw_lo
float vbat            = radio.vbatVolts();
uint16_t errs         = radio.chipErrors();   // chip-side error flags
lr1121::Error e       = radio.lastError();
const char *msg       = lr1121::Radio::errorString(e);

Errors

Ok NotReady SpiOpen SpiIo GpioOpen BusyTimeout BadChip TxTimeout TxLbd RxTimeout RxCrc

Other

radio.softResetSettings();          // re-apply Config without hard reset
radio.reboot(false);                // reboot chip (true = stay in bootloader)
radio.end();                        // close SPI + GPIO fds
const lr1121::Config &c = radio.config();   // current live config