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

View File

@ -10,7 +10,7 @@
#include "hal_gpio.hpp" #include "hal_gpio.hpp"
#include "hal_spi.hpp" #include "hal_spi.hpp"
#include "utils/app_utils.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://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 // 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 { 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); app::utils::delay_ms(timeout_ms);
return true; return true;
} else { } 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) { while (hal::gpio::digital_read(BUSY_PIN) == hal::gpio::HIGH) {
if (io_inst.elapsed_ms() > timeout_ms) { if (io_inst.elapsed_ms() > timeout_ms) {
return false; return false;