Fixes MaxPayloadSize calculation, Doxygen comments and C-style casts

This commit is contained in:
GOB
2026-04-07 15:07:18 +09:00
parent 0c785ba0a5
commit 58a268be55
6 changed files with 41 additions and 12 deletions
+2 -2
View File
@@ -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
+27
View File
@@ -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;
+4 -4
View File
@@ -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<uint8_t>((RmtRxMaxItems - 1 /*SOF*/) / 8 - ProtocolOverhead);
#endif
/*!
+4 -3
View File
@@ -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<const uint8_t*>(rmt_items.data()),
rmt_items.size() * sizeof(m5_rmt_item_t), wait) == m5::hal::error::error_t::OK);
}
if (ret) {
clear();
+2 -2
View File
@@ -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
+2 -1
View File
@@ -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<m5::unit::gpio::m5_rmt_item_t*>(buff + 2 /* len */);
// Decode via codec (handles SOF scan, Manchester decode, CRC validation)