Add .gitignore file and refactor llcc68 component
- Added a comprehensive .gitignore file to exclude unnecessary files and directories for various platforms and tools. - Removed the llcc68.cpp source file as part of the refactoring process. - Updated llcc68.hpp to replace the `init_exti` function declaration with inline interrupt configuration logic. - Changed `EXTI_PIN` to `EXTI_PINS` for clarity and consistency. - Refactored the handling of CAD parameters and improved type safety by using `enum class` for `CAD_EXIT_MODE` and `CAD_SYMB`.
This commit is contained in:
124
inc/llcc68.hpp
124
inc/llcc68.hpp
@ -121,8 +121,6 @@ namespace details {
|
||||
extern uint32_t __tcxo_delay__;
|
||||
}
|
||||
|
||||
void init_exti();
|
||||
|
||||
constexpr auto delay_ms = app::utils::delay_ms;
|
||||
|
||||
/*!
|
||||
@ -174,7 +172,7 @@ write_register(const uint16_t addr, std::span<const uint8_t> data) {
|
||||
return spi::write_register(addr, data);
|
||||
}
|
||||
|
||||
Result<Unit, error_t> inline write_buffer(std::span<const uint8_t> data, const uint8_t offset = 0x00) {
|
||||
Result<Unit, error_t> inline write_buffer(std::span<const uint8_t> data, const uint8_t offset = DEFAULT_TX_BUFFER_ADDRESS) {
|
||||
return spi::write_buffer(offset, data);
|
||||
}
|
||||
|
||||
@ -447,8 +445,7 @@ set_dio2_as_rf_switch(const bool en) {
|
||||
* \brief set packet type and do the calibration
|
||||
*/
|
||||
inline Result<Unit, error_t> config_packet_type(const parameters_t ¶ms) {
|
||||
auto res = set_buffer_base_address();
|
||||
APP_RADIO_RETURN_ERR(res);
|
||||
Result<Unit, error_t> res;
|
||||
constexpr auto mod = RADIOLIB_SX126X_PACKET_TYPE_LORA;
|
||||
uint8_t data[7];
|
||||
data[0] = mod;
|
||||
@ -584,13 +581,21 @@ inline Result<Unit, error_t> rx(const uint32_t timeout = RADIOLIB_SX126X_RX_TIME
|
||||
return spi::write_stream(RADIOLIB_SX126X_CMD_SET_RX, data);
|
||||
}
|
||||
|
||||
enum CAD_EXIT_MODE : uint8_t {
|
||||
enum class CAD_EXIT_MODE : uint8_t {
|
||||
CAD_ONLY = 0x00,
|
||||
CAD_RX = 0x01,
|
||||
};
|
||||
|
||||
enum class CAD_SYMB : uint8_t {
|
||||
CAD_ON_1_SYMB = 0x00,
|
||||
CAD_ON_2_SYMB = 0x01,
|
||||
CAD_ON_4_SYMB = 0x02,
|
||||
CAD_ON_8_SYMB = 0x03,
|
||||
CAD_ON_16_SYMB = 0x04,
|
||||
};
|
||||
|
||||
struct cad_params_t {
|
||||
uint8_t symbol_num;
|
||||
CAD_SYMB symbol_num;
|
||||
uint8_t det_peak;
|
||||
uint8_t det_min;
|
||||
CAD_EXIT_MODE exit_mode;
|
||||
@ -603,42 +608,30 @@ struct cad_params_t {
|
||||
uint32_t timeout;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Calculate default CAD parameters for a given spreading factor
|
||||
* \param sf Spreading factor
|
||||
* \param params CAD parameters
|
||||
* \note will mutate `params.symbol_num`, `params.det_peak`, and `params.det_min`
|
||||
* \return true if the sf is valid and the parameters are set, false otherwise
|
||||
*/
|
||||
inline bool calculate_default_cad_params(const uint8_t sf, cad_params_t ¶ms) {
|
||||
// Parameters `cadDetPeak` and `cadDetMin` define the sensitivity of the LoRa
|
||||
// modem when trying to correlate to actual LoRa preamble symbols. These
|
||||
// two settings depend on the LoRa spreading factor and Bandwidth, but
|
||||
// also depend on the number of symbols used to validate or not the detection.
|
||||
//
|
||||
// Choosing the right value is not easy and the values selected must be
|
||||
// carefully tested to ensure a good detection at sensitivity level, and
|
||||
// also to limit the number of false detections. Application note AN1200.48
|
||||
// provides guidance for the selection of these parameters.
|
||||
constexpr std::tuple<uint8_t, uint8_t> sf_det_peak_map[6] = {
|
||||
{7, 22},
|
||||
{8, 22},
|
||||
{9, 24},
|
||||
{10, 25},
|
||||
{11, 26},
|
||||
{12, 30}};
|
||||
|
||||
// default CAD parameters are shown in Semtech AN1200.48, page 41.
|
||||
const std::tuple<uint8_t, uint8_t> det_peak_map[6] = {{7, 22}, {8, 22}, {9, 24}, {10, 25}, {11, 26}, {12, 30}};
|
||||
std::optional<uint8_t> det_peak;
|
||||
for (const auto &[r_sf, r_det_peak] : det_peak_map) {
|
||||
// Parameters `cadDetPeak` and `cadDetMin` define the sensitivity of the LoRa
|
||||
// modem when trying to correlate to actual LoRa preamble symbols. These
|
||||
// two settings depend on the LoRa spreading factor and Bandwidth, but
|
||||
// also depend on the number of symbols used to validate or not the detection.
|
||||
//
|
||||
// Choosing the right value is not easy and the values selected must be
|
||||
// carefully tested to ensure a good detection at sensitivity level, and
|
||||
// also to limit the number of false detections. Application note AN1200.48
|
||||
// provides guidance for the selection of these parameters.
|
||||
constexpr inline std::optional<uint8_t> get_det_peak(const uint8_t sf) {
|
||||
for (const auto &[r_sf, r_det_peak] : sf_det_peak_map) {
|
||||
if (r_sf == sf) {
|
||||
det_peak = r_det_peak;
|
||||
break;
|
||||
return r_det_peak;
|
||||
}
|
||||
}
|
||||
if (not det_peak) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// CAD parameters aren't available for SF-6. Just to be safe.
|
||||
params.symbol_num = RADIOLIB_SX126X_CAD_ON_2_SYMB;
|
||||
params.det_peak = det_peak.value();
|
||||
params.det_min = RADIOLIB_SX126X_CAD_PARAM_DET_MIN;
|
||||
return true;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -647,10 +640,10 @@ inline bool calculate_default_cad_params(const uint8_t sf, cad_params_t ¶ms)
|
||||
inline Result<Unit, error_t>
|
||||
set_cad_params(const cad_params_t ¶ms) {
|
||||
uint8_t data[7];
|
||||
data[0] = params.symbol_num;
|
||||
data[0] = static_cast<uint8_t>(params.symbol_num);
|
||||
data[1] = params.det_peak;
|
||||
data[2] = params.det_min;
|
||||
data[3] = params.exit_mode;
|
||||
data[3] = static_cast<uint8_t>(params.exit_mode);
|
||||
data[4] = static_cast<uint8_t>((params.timeout >> 16) & 0xFF);
|
||||
data[5] = static_cast<uint8_t>((params.timeout >> 8) & 0xFF);
|
||||
data[6] = static_cast<uint8_t>(params.timeout & 0xFF);
|
||||
@ -950,7 +943,8 @@ struct read_result_t {
|
||||
* \brief user should call this function after reading data (since it will override the internal buffer)
|
||||
*/
|
||||
static Result<Unit, error_t> post_procedure() {
|
||||
auto res = set_buffer_base_address();
|
||||
Result<Unit, error_t> res;
|
||||
res = set_buffer_base_address();
|
||||
APP_RADIO_RETURN_ERR(res);
|
||||
res = clear_irq_status();
|
||||
APP_RADIO_RETURN_ERR(res);
|
||||
@ -991,8 +985,10 @@ read_data_internal() {
|
||||
* is incremented starting from the previous position.
|
||||
*/
|
||||
const auto [sz, ptr] = std::move(*tuple_);
|
||||
ESP_LOGD(TAG, "sz=%d, ptr=0x%02x", sz, ptr);
|
||||
auto res = hal::spi::read_buffer(ptr - sz, sz);
|
||||
// the rx pointer would become 0x80 at first, so we need to adapt that behavior
|
||||
const auto r_ptr = ptr - sz < DEFAULT_RX_BUFFER_ADDRESS ? ptr : ptr - sz;
|
||||
|
||||
auto res = hal::spi::read_buffer(r_ptr, sz);
|
||||
APP_RADIO_RETURN_ERR(res);
|
||||
return read_result_t{irq, *res};
|
||||
}
|
||||
@ -1024,22 +1020,10 @@ inline Result<Unit, error_t>
|
||||
kick_inf_rx() {
|
||||
Result<Unit, error_t> res;
|
||||
res = standby();
|
||||
|
||||
// res = set_packet_type(PacketType::LORA);
|
||||
// APP_RADIO_RETURN_ERR_CTX(res, "failed to set packet type");
|
||||
|
||||
res = set_frequency(DEFAULT_FREQUENCY, false);
|
||||
APP_RADIO_RETURN_ERR_CTX(res, "failed to set frequency");
|
||||
|
||||
APP_RADIO_RETURN_ERR_CTX(res, "failed to standby");
|
||||
res = set_buffer_base_address();
|
||||
APP_RADIO_RETURN_ERR_CTX(res, "failed to set buffer base address");
|
||||
|
||||
res = set_modulation_params(DEFAULT_SF, DEFAULT_BW, DEFAULT_CR, DEFAULT_LDR_OPTIMIZE);
|
||||
APP_RADIO_RETURN_ERR_CTX(res, "failed to set modulation params");
|
||||
|
||||
res = set_packet_params(DEFAULT_PREAMBLE_LEN, 0xff, DEFAULT_CRC_TYPE, DEFAULT_HEADER_TYPE);
|
||||
APP_RADIO_RETURN_ERR_CTX(res, "failed to set packet params");
|
||||
|
||||
constexpr auto irq_mask = RADIOLIB_SX126X_IRQ_RX_DEFAULT;
|
||||
constexpr auto irq_params = irq_params_t{
|
||||
irq_mask,
|
||||
@ -1047,6 +1031,7 @@ kick_inf_rx() {
|
||||
DIO2_PIN == NC_PIN ? RADIOLIB_SX126X_IRQ_NONE : irq_mask,
|
||||
DIO3_PIN == NC_PIN ? RADIOLIB_SX126X_IRQ_NONE : irq_mask,
|
||||
};
|
||||
|
||||
res = set_dio_irq_params(irq_params);
|
||||
APP_RADIO_RETURN_ERR_CTX(res, "failed to set dio irq params");
|
||||
res = clear_irq_status();
|
||||
@ -1148,7 +1133,7 @@ async_transmit(const uint8_t *data, const size_t len,
|
||||
};
|
||||
res = set_dio_irq_params(irq_params);
|
||||
APP_RADIO_RETURN_ERR_CTX(res, "failed to set dio irq params");
|
||||
clear_irq_status();
|
||||
clear_irq_status(irq_mask);
|
||||
APP_RADIO_RETURN_ERR_CTX(res, "failed to clear irq status");
|
||||
|
||||
res = tx();
|
||||
@ -1172,11 +1157,30 @@ async_transmit(const std::span<const uint8_t> data,
|
||||
}
|
||||
|
||||
|
||||
static constexpr auto init_pins = [] {
|
||||
static constexpr auto init_pins = [](void (*isr)(void *), void *arg) {
|
||||
if (RST_PIN != GPIO_NUM_NC) {
|
||||
gpio::set_mode(RST_PIN, gpio::Mode::OUTPUT);
|
||||
}
|
||||
init_exti();
|
||||
uint64_t pin_bit_mask = 0;
|
||||
for (const auto pin : EXTI_PINS) {
|
||||
pin_bit_mask |= (1ULL << pin);
|
||||
}
|
||||
gpio_config_t io_conf = {
|
||||
.pin_bit_mask = pin_bit_mask,
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_POSEDGE,
|
||||
};
|
||||
// https://github.com/espressif/esp-idf/blob/v5.3.2/examples/peripherals/gpio/generic_gpio/main/gpio_example_main.c
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
gpio_install_isr_service(ESP_INTR_FLAG_IRAM);
|
||||
for (const auto pin : EXTI_PINS) {
|
||||
if (pin == NC_PIN) {
|
||||
continue;
|
||||
}
|
||||
gpio_isr_handler_add(pin, isr, arg);
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr auto begin = [](const parameters_t ¶ms) -> Result<Unit, error_t> {
|
||||
|
||||
Reference in New Issue
Block a user