From 059070e1469159a1634c82872abce4b678a1b1e4 Mon Sep 17 00:00:00 2001 From: crosstyan Date: Thu, 7 Aug 2025 16:00:31 +0800 Subject: [PATCH] refactor: update Instant usage and adjust regulator configuration --- inc/llcc68.hpp | 26 ++++++++++++++------------ src/hal_spi.cpp | 4 ++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/inc/llcc68.hpp b/inc/llcc68.hpp index d6e4642..ef15ab2 100644 --- a/inc/llcc68.hpp +++ b/inc/llcc68.hpp @@ -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 -using Instant = app::utils::Instant; +using Instant = app::utils::Instant; template using Result = app::utils::Result; @@ -93,7 +93,7 @@ using millisecond = std::chrono::duration; /** * \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{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 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), }; } diff --git a/src/hal_spi.cpp b/src/hal_spi.cpp index d89a5c8..5121f7c 100644 --- a/src/hal_spi.cpp +++ b/src/hal_spi.cpp @@ -10,7 +10,7 @@ #include "hal_gpio.hpp" #include "hal_spi.hpp" #include "utils/app_utils.hpp" -#include "utils/app_instant.hpp" +#include "utils/app_clock_instant.hpp" // https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32h2/api-reference/peripherals/spi_master.html // https://github.com/espressif/esp-idf/blob/v5.3.2/examples/peripherals/spi_master/lcd/main/spi_master_example_main.c namespace app::driver::hal::spi { @@ -123,7 +123,7 @@ inline bool wait_for_not_busy(const size_t timeout_ms) { app::utils::delay_ms(timeout_ms); return true; } else { - const auto io_inst = app::utils::Instant<>{}; + const auto io_inst = app::utils::Instant{}; while (hal::gpio::digital_read(BUSY_PIN) == hal::gpio::HIGH) { if (io_inst.elapsed_ms() > timeout_ms) { return false;