From 58a268be550a2102fe1072cfa2cb23d8ee0a0204 Mon Sep 17 00:00:00 2001 From: GOB Date: Tue, 7 Apr 2026 15:07:18 +0900 Subject: [PATCH] Fixes MaxPayloadSize calculation, Doxygen comments and C-style casts --- src/M5UnitUnifiedRF433.hpp | 4 ++-- src/unit/codec/m5_codec.hpp | 27 +++++++++++++++++++++++++++ src/unit/rmt_item_types.hpp | 8 ++++---- src/unit/unit_SYN115.cpp | 7 ++++--- src/unit/unit_SYN115.hpp | 4 ++-- src/unit/unit_SYN531R.cpp | 3 ++- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/M5UnitUnifiedRF433.hpp b/src/M5UnitUnifiedRF433.hpp index a24cace..809a8c1 100644 --- a/src/M5UnitUnifiedRF433.hpp +++ b/src/M5UnitUnifiedRF433.hpp @@ -28,8 +28,8 @@ namespace m5 { */ namespace unit { -using UnitRF433T = UnitSYN115; -using UnitRF433R = UnitSYN531R; +using UnitRF433T = UnitSYN115; //!< @brief Alias for UnitSYN115 (RF433 transmitter, SKU:U114) +using UnitRF433R = UnitSYN531R; //!< @brief Alias for UnitSYN531R (RF433 receiver, SKU:U113) } // namespace unit } // namespace m5 diff --git a/src/unit/codec/m5_codec.hpp b/src/unit/codec/m5_codec.hpp index 7a8f071..8196aa0 100644 --- a/src/unit/codec/m5_codec.hpp +++ b/src/unit/codec/m5_codec.hpp @@ -32,11 +32,30 @@ public: { } + /*! + @brief Encode payload into RMT items with M5 protocol framing + @param payload Pointer to the payload data + @param payload_len Length of the payload in bytes + @return Encoded RMT items including preamble, SOF, protocol fields, and Manchester-encoded data + */ item_container_type encode(const uint8_t* payload, uint32_t payload_len) override; + /*! + @brief Decode RMT items into payload data + @param items Pointer to the received RMT items (after SOF detection) + @param num Number of RMT items + @param work_buf Working buffer for decoded bytes + @param work_buf_size Size of the working buffer + @param[out] result Decoded result containing payload pointer and metadata + @return True if decoding and CRC8 verification succeeded + */ bool decode(const gpio::m5_rmt_item_t* items, uint32_t num, uint8_t* work_buf, uint16_t work_buf_size, DecodeResult& result) override; + /*! + @brief Get protocol overhead in bytes + @return 4 (CRC8 + ID + Count + Length) + */ uint8_t overhead() const override { // CRC8(1) + ID(1) + Count(1) + Length(1) = 4 @@ -45,10 +64,18 @@ public: ///@name Communication identifier (M5Codec specific) ///@{ + /*! + @brief Get the communication identifier + @return Current communication identifier (0-255) + */ inline communication_identifier_t communicationIdentifier() const { return _comm_id; } + /*! + @brief Set the communication identifier + @param id Communication identifier (0-255) for filtering received frames + */ inline void setCommunicationIdentifier(communication_identifier_t id) { _comm_id = id; diff --git a/src/unit/rmt_item_types.hpp b/src/unit/rmt_item_types.hpp index d35f21b..1807bad 100644 --- a/src/unit/rmt_item_types.hpp +++ b/src/unit/rmt_item_types.hpp @@ -57,8 +57,8 @@ constexpr uint16_t RmtRxMaxItems = 6 * 64; //!< ESP32: 8ch x 64 items, use 6 = This is the theoretical limit based on RMT hardware memory. In practice, AGC noise from the SYN531R receiver consumes RMT items, reducing the usable capacity. Theoretical values: - - ESP32: 40 bytes (practical safe limit ~23 bytes) - - ESP32-S3: 40 bytes (1 mem_block + threshold ISR wrapping; practical safe limit ~23 bytes) + - ESP32: 43 bytes (practical safe limit ~23 bytes) + - ESP32-S3: 43 bytes (1 mem_block + threshold ISR wrapping; practical safe limit ~23 bytes) - ESP-IDF 5.x (RMT v2): 255 bytes @warning When communicating between RMT v1 (ESP-IDF 4.x) and RMT v2 (ESP-IDF 5.x) devices, the payload size must not exceed the receiver's limit. A v2 transmitter can send up to 255 bytes, @@ -72,9 +72,9 @@ constexpr uint8_t MaxPayloadSize = #elif defined(CONFIG_IDF_TARGET_ESP32S3) // ESP32-S3 uses mem_blocks=1 with threshold ISR wrapping; // theoretical limit depends on ISR throughput, use ESP32 equivalent - 40; + 43; #else - (uint8_t)((RmtRxMaxItems - 1 /*SOF*/) / 8 - ProtocolOverhead); + static_cast((RmtRxMaxItems - 1 /*SOF*/) / 8 - ProtocolOverhead); #endif /*! diff --git a/src/unit/unit_SYN115.cpp b/src/unit/unit_SYN115.cpp index f502f22..3cdd6c6 100644 --- a/src/unit/unit_SYN115.cpp +++ b/src/unit/unit_SYN115.cpp @@ -73,6 +73,7 @@ bool UnitSYN115::begin() void UnitSYN115::update(const bool force) { + (void)force; if (!_payload.empty() && _cfg.send_in_update) { if (!send(_cfg.burst_transmission_count)) { M5_LIB_LOGD("Failed to send"); @@ -105,13 +106,13 @@ bool UnitSYN115::send(const uint8_t burst_transmission_count) auto rmt_items = _codec->encode(_payload.data(), _payload_size); auto wait = estimate_tx_timeout_ticks(rmt_items); - uint8_t count = burst_transmission_count ? burst_transmission_count : 1; + uint8_t count = burst_transmission_count ? burst_transmission_count : _cfg.burst_transmission_count; bool ret{true}; // Burst transmission while (ret && count--) { - ret &= (writeWithTransaction((const uint8_t*)rmt_items.data(), rmt_items.size() * sizeof(m5_rmt_item_t), - wait) == m5::hal::error::error_t::OK); + ret &= (writeWithTransaction(reinterpret_cast(rmt_items.data()), + rmt_items.size() * sizeof(m5_rmt_item_t), wait) == m5::hal::error::error_t::OK); } if (ret) { clear(); diff --git a/src/unit/unit_SYN115.hpp b/src/unit/unit_SYN115.hpp index 74767c9..08b5d0b 100644 --- a/src/unit/unit_SYN115.hpp +++ b/src/unit/unit_SYN115.hpp @@ -82,11 +82,11 @@ public: /*! @brief Send force if exists payload - @param burst_transmission_count Count of burst transmission + @param burst_transmission_count Count of burst transmission (0 = use config_t::burst_transmission_count) @return True if successful @note The payload will be empty if successful */ - bool send(const uint8_t burst_transmission_count = 4); + bool send(const uint8_t burst_transmission_count = 0); /*! @brief Clear inner buffer diff --git a/src/unit/unit_SYN531R.cpp b/src/unit/unit_SYN531R.cpp index 097e359..8e1a09f 100644 --- a/src/unit/unit_SYN531R.cpp +++ b/src/unit/unit_SYN531R.cpp @@ -135,7 +135,8 @@ bool UnitSYN531R::read_data() } // buff is 4-byte aligned (heap_caps_aligned_alloc), buff+2 is 2-byte aligned. - // m5_rmt_item_t requires only 2-byte alignment (uint16_t fields), so this is safe. + // rmt_item32_t is naturally 4-byte aligned, but ESP32 (Xtensa) and ESP32-C6 (RISC-V) + // both handle unaligned access transparently, so buff+2 is safe in practice. auto* items = reinterpret_cast(buff + 2 /* len */); // Decode via codec (handles SOF scan, Manchester decode, CRC validation)