mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-09-01 22:38:19 +00:00
97 lines
2.1 KiB
C++
97 lines
2.1 KiB
C++
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* LR2021 hardware hooks for LoRaRadioBase.
|
|
*/
|
|
|
|
#include "LR2021Radio.h"
|
|
#include <zephyr/kernel.h>
|
|
|
|
/* LR20xx driver extension API */
|
|
extern "C" {
|
|
#include "lr20xx_lora.h"
|
|
}
|
|
|
|
#include <zephyr/logging/log.h>
|
|
LOG_MODULE_REGISTER(lr2021_radio, CONFIG_ZEPHCORE_LORA_LOG_LEVEL);
|
|
|
|
namespace mesh {
|
|
|
|
K_THREAD_STACK_DEFINE(lr20xx_tx_wait_stack, TX_WAIT_THREAD_STACK_SIZE);
|
|
|
|
LR2021Radio::LR2021Radio(const struct device *lora_dev, MainBoard &board,
|
|
NodePrefs *prefs)
|
|
: LoRaRadioBase(lora_dev, board, prefs)
|
|
{
|
|
}
|
|
|
|
void LR2021Radio::begin()
|
|
{
|
|
startTxThread(lr20xx_tx_wait_stack,
|
|
K_THREAD_STACK_SIZEOF(lr20xx_tx_wait_stack));
|
|
LoRaRadioBase::begin();
|
|
}
|
|
|
|
/* ── Hardware primitives ──────────────────────────────────────────────── */
|
|
|
|
bool LR2021Radio::hwConfigure(const struct lora_modem_config &cfg)
|
|
{
|
|
int ret = lora_config(_dev, const_cast<struct lora_modem_config *>(&cfg));
|
|
if (ret < 0) {
|
|
LOG_ERR("lora_config failed: %d", ret);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void LR2021Radio::hwCancelReceive()
|
|
{
|
|
lora_recv_async(_dev, NULL, NULL);
|
|
}
|
|
|
|
int LR2021Radio::hwSendAsync(uint8_t *buf, uint32_t len,
|
|
struct k_poll_signal *sig)
|
|
{
|
|
return lora_send_async(_dev, buf, len, sig);
|
|
}
|
|
|
|
int16_t LR2021Radio::hwGetCurrentRSSI()
|
|
{
|
|
return lr20xx_get_rssi_inst(_dev);
|
|
}
|
|
|
|
bool LR2021Radio::hwIsReceiving()
|
|
{
|
|
/* MUST be non-destructive: never clear IRQ bits from this path.
|
|
* Foreign-preamble release is hardware-driven (chip-internal release
|
|
* on HEADER_ERROR / sync timeout). The driver's lr20xx_is_receiving()
|
|
* reads via get_status() without clearing. */
|
|
return lr20xx_is_receiving(_dev);
|
|
}
|
|
|
|
void LR2021Radio::hwSetRxBoost(bool enable)
|
|
{
|
|
lr20xx_set_rx_boost(_dev, enable);
|
|
}
|
|
|
|
void LR2021Radio::hwResetAGC()
|
|
{
|
|
lr20xx_reset_agc(_dev);
|
|
}
|
|
|
|
int LR2021Radio::hwCadProbe(int8_t level)
|
|
{
|
|
return lr20xx_cad_probe(_dev, level);
|
|
}
|
|
|
|
void LR2021Radio::hwCadSetPeakOffset(int8_t offset)
|
|
{
|
|
lr20xx_cad_set_peak_offset(_dev, offset);
|
|
}
|
|
|
|
uint8_t LR2021Radio::hwCadBasePeak()
|
|
{
|
|
return lr20xx_cad_base_peak(_dev);
|
|
}
|
|
|
|
} /* namespace mesh */
|