M5Unit-RF433 0.2.0 git rev:ed9ef39
Loading...
Searching...
No Matches
rmt_item_types.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_RF433_RMT_ITEM_TYPES_HPP
11#define M5_UNIT_RF433_RMT_ITEM_TYPES_HPP
12
13#include <M5UnitComponent.hpp>
14#if defined(ESP_PLATFORM)
15#include <soc/soc_caps.h>
16#endif
17
18namespace m5 {
19namespace unit {
20namespace rf433 {
21
23constexpr m5::unit::gpio::m5_rmt_item_t rmt_item_one{{800, 1, 200, 0}}; // 1
24constexpr m5::unit::gpio::m5_rmt_item_t rmt_item_zero{{200, 1, 800, 0}}; // 0
25constexpr m5::unit::gpio::m5_rmt_item_t rmt_sof_0{{4868, 1, 2469, 0}}; // Frame start 0
26constexpr m5::unit::gpio::m5_rmt_item_t rmt_sof_1{{1647, 1, 315, 0}}; // Frame start 1
27constexpr m5::unit::gpio::m5_rmt_item_t rmt_preamble{{500, 1, 500, 0}}; // preamble
29
30using container_type = std::vector<uint8_t>;
31using item_container_type = std::vector<gpio::m5_rmt_item_t>;
33
35constexpr uint8_t ProtocolOverhead = 4;
36
45#if defined(M5_UNIT_UNIFIED_USING_RMT_V2)
46constexpr uint8_t RmtRxMemBlocks = 2;
47#elif defined(SOC_RMT_SUPPORT_RX_PINGPONG) && SOC_RMT_SUPPORT_RX_PINGPONG
48constexpr uint8_t RmtRxMemBlocks = 1;
49#elif defined(SOC_RMT_RX_CANDIDATES_PER_GROUP)
50// RX channels are the last SOC_RMT_RX_CANDIDATES_PER_GROUP ones and their blocks must stay within the group
51constexpr uint8_t RmtRxMemBlocks = (SOC_RMT_RX_CANDIDATES_PER_GROUP < 6) ? SOC_RMT_RX_CANDIDATES_PER_GROUP : 6;
52#else
53constexpr uint8_t RmtRxMemBlocks = 6; // Host (native) build: same as ESP32
54#endif
55
69#if defined(M5_UNIT_UNIFIED_USING_RMT_V2)
70constexpr uint16_t RmtRxMaxItems = 4096; // RMT v2: ping-pong/DMA handles large frames
71#elif defined(SOC_RMT_MEM_WORDS_PER_CHANNEL)
72constexpr uint16_t RmtRxMaxItems =
73 RmtRxMemBlocks * SOC_RMT_MEM_WORDS_PER_CHANNEL; // ESP32: 384, ESP32-S2: 256, ESP32-S3 / ESP32-C3: 48
74#else
75constexpr uint16_t RmtRxMaxItems = RmtRxMemBlocks * 64; // Host (native) build: same as ESP32
76#endif
77
94constexpr uint8_t MaxPayloadSize =
95#if defined(M5_UNIT_UNIFIED_USING_RMT_V2)
96 255;
97#elif defined(SOC_RMT_SUPPORT_RX_PINGPONG) && SOC_RMT_SUPPORT_RX_PINGPONG
98 // ESP32-S3 / ESP32-C3 use mem_blocks=1 with threshold ISR wrapping;
99 // theoretical limit depends on ISR throughput, use ESP32 equivalent
100 43;
101#else
102 static_cast<uint8_t>((RmtRxMaxItems - 1 /*SOF*/) / 8 - ProtocolOverhead);
103#endif
104
110constexpr uint32_t calculateRingBufferSize(const uint32_t payload_size)
111{
112 // Frame: SOF(1 item) + (overhead + payload) * 8 Manchester items per byte
113 return (1 /*SOF*/ + (ProtocolOverhead + payload_size) * 8) * sizeof(m5::unit::gpio::m5_rmt_item_t) +
114 2 /*length prefix*/;
115}
116
124item_container_type encodeManchester(const uint8_t* data, const uint32_t len, const bool MSB = true);
125
135uint16_t decodeManchester(uint8_t* buf, const uint16_t buf_size, const m5::unit::gpio::m5_rmt_item_t* data,
136 const uint32_t num, const bool MSB = true);
137
138} // namespace rf433
139} // namespace unit
140} // namespace m5
141#endif
Top level namespace of M5Stack.
Unit-related namespace.
uint8_t communication_identifier_t
Communication identifier (0-255)
Definition rmt_item_types.hpp:32
constexpr uint8_t MaxPayloadSize
Theoretical maximum payload size in bytes for the current platform.
Definition rmt_item_types.hpp:94
constexpr uint32_t calculateRingBufferSize(const uint32_t payload_size)
Calculate the minimum ring buffer size required to receive the given payload size.
Definition rmt_item_types.hpp:110
std::vector< uint8_t > container_type
Container.
Definition rmt_item_types.hpp:30
constexpr uint8_t RmtRxMemBlocks
RMT memory blocks used by the RX channel per platform.
Definition rmt_item_types.hpp:53
constexpr uint16_t RmtRxMaxItems
Maximum RMT items receivable in a single frame per platform.
Definition rmt_item_types.hpp:75
constexpr uint8_t ProtocolOverhead
Protocol overhead in bytes: CRC8(1) + ID(1) + Count(1) + Length(1) = 4.
Definition rmt_item_types.hpp:35
std::vector< gpio::m5_rmt_item_t > item_container_type
Item container.
Definition rmt_item_types.hpp:31