refactor: update Instant usage and adjust regulator configuration

This commit is contained in:
2025-08-07 16:00:31 +08:00
parent 7637906efe
commit 059070e146
2 changed files with 16 additions and 14 deletions

View File

@ -14,9 +14,10 @@
#include "hal_gpio.hpp"
#include "app_const_llcc68.hpp"
#include "radiolib_definitions.hpp"
#include "utils/app_clock.hpp"
#include "utils/app_utils.hpp"
#include "utils/app_result.hpp"
#include "utils/app_instant.hpp"
#include "utils/app_clock_instant.hpp"
#include "llcc68_definitions.hpp"
#include "hal_spi.hpp"
#include "hal_error.hpp"
@ -81,8 +82,7 @@ namespace app::driver::llcc68 {
constexpr auto TAG = "lora";
using namespace app::driver::hal;
template <typename T = int64_t>
using Instant = app::utils::Instant<T>;
using Instant = app::utils::Instant;
template <typename T, typename E>
using Result = app::utils::Result<T, E>;
@ -93,7 +93,7 @@ using millisecond = std::chrono::duration<size_t, std::milli>;
/**
* \brief Whether to use only LDO regulator (true) or DC-DC regulator (false)
*/
constexpr bool USE_REGULATOR_LDO = false;
constexpr bool USE_REGULATOR_LDO = true;
/*!
\brief Whether the module has an XTAL (true) or TCXO (false)
@ -110,8 +110,12 @@ using ue_t = spi::ue_t;
*/
struct transmit_state_t {
bool is_transmitting = false;
Instant<> start{};
uint16_t expected_duration_ms{};
Instant::time_point expected_end_timestamp{};
void mut_reset() {
is_transmitting = false;
expected_end_timestamp = Instant::time_point::min();
}
};
/**
@ -142,8 +146,8 @@ reset() {
delay_ms(250);
gpio::digital_write(RST_PIN, true);
delay_ms(1'000);
const auto instant = Instant<>{};
constexpr auto INTERVAL = std::chrono::duration<uint16_t, std::milli>{spi::DEFAULT_TIMEOUT_MS};
const auto instant = Instant{};
constexpr auto INTERVAL = Instant::milliseconds{spi::DEFAULT_TIMEOUT_MS};
decltype(standby()) res = ue_t{error_t{error::FAILED}};
while (not res && instant.elapsed() < INTERVAL) {
res = standby();
@ -1165,11 +1169,9 @@ async_transmit(const std::span<const uint8_t> data,
packet_params.hdr_type) *
TIMEOUT_FACTOR;
const uint16_t timeout_ms = timeout_us / 1000;
auto instant = Instant<>{};
return transmit_state_t{
.is_transmitting = true,
.start = std::move(instant),
.expected_duration_ms = timeout_ms,
.is_transmitting = true,
.expected_end_timestamp = app::utils::clock_t::now() + Instant::milliseconds(timeout_ms),
};
}