M5Unit-INFRARED 0.2.0 git rev:76ad9e1
Loading...
Searching...
No Matches
raw_codec.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_INFRARED_IR_RAW_CODEC_HPP
11#define M5_UNIT_INFRARED_IR_RAW_CODEC_HPP
12
13#include "ir_codec.hpp"
14#include "ir_rmt_items.hpp"
15
16namespace m5 {
17namespace unit {
18namespace ir {
19
26class RawCodec : public IRCodec {
27public:
32 explicit RawCodec(uint32_t carrier_hz = 38000) : IRCodec(CodecType::Raw), _carrier_hz(carrier_hz)
33 {
34 }
35
37 item_container_type encode(uint16_t, uint16_t, bool) override
38 {
39 return {};
40 }
41
49 bool decode(const gpio::m5_rmt_item_t* items, uint32_t num, DecodeResult& result) override
50 {
51 if (!items || num == 0) {
52 return false;
53 }
54 result.protocol = CodecType::Raw;
55 result.address = 0;
56 result.command = 0;
57 result.bits = static_cast<uint8_t>(num > 255 ? 255 : num);
58 result.repeat = false;
59 result.toggle = false;
60 return true;
61 }
62
67 uint32_t carrierFrequencyHz() const override
68 {
69 return _carrier_hz;
70 }
71
79 item_container_type encodeRaw(const uint16_t* mark_space_us, uint32_t count)
80 {
82 items.reserve(count / 2 + 1);
83 for (uint32_t i = 0; i + 1 < count; i += 2) {
84 items.push_back(makeItem(mark_space_us[i], mark_space_us[i + 1]));
85 }
86 if (count & 1) {
87 items.push_back(makeTerminator(mark_space_us[count - 1]));
88 }
89 return items;
90 }
91
92private:
93 uint32_t _carrier_hz;
94};
95
96} // namespace ir
97} // namespace unit
98} // namespace m5
99#endif
Abstract base class for IR protocol encoding/decoding.
Definition ir_codec.hpp:62
Raw mark/space pass-through codec.
Definition raw_codec.hpp:26
bool decode(const gpio::m5_rmt_item_t *items, uint32_t num, DecodeResult &result) override
decode() stores raw item count in bits and tags protocol as Raw
Definition raw_codec.hpp:49
item_container_type encodeRaw(const uint16_t *mark_space_us, uint32_t count)
Encode raw mark/space pairs into RMT items.
Definition raw_codec.hpp:79
item_container_type encode(uint16_t, uint16_t, bool) override
encode() is not meaningful for Raw; returns empty
Definition raw_codec.hpp:37
uint32_t carrierFrequencyHz() const override
Carrier frequency configured at construction.
Definition raw_codec.hpp:67
RawCodec(uint32_t carrier_hz=38000)
Constructor.
Definition raw_codec.hpp:32
IR protocol codec base class and types.
std::vector< m5::unit::gpio::m5_rmt_item_t > item_container_type
RMT item container.
Definition ir_codec.hpp:54
CodecType
Identifies the IR protocol codec implementation.
Definition ir_codec.hpp:27
@ Raw
Raw mark/space (no protocol)
RMT item helper functions for IR protocols.
gpio::m5_rmt_item_t makeItem(uint16_t mark_us, uint16_t space_us)
Create an RMT item representing a mark (carrier burst) followed by a space (silence)
Definition ir_rmt_items.hpp:25
gpio::m5_rmt_item_t makeTerminator(uint16_t mark_us)
Create a terminator RMT item (mark only, no space)
Definition ir_rmt_items.hpp:40
Top level namespace of M5Stack.
Unit-related namespace.
Result of decoding a received IR frame.
Definition ir_codec.hpp:44
uint8_t bits
Total bit count (NEC=32, SIRC=12/15/20, RC5=14, RC6=21)
Definition ir_codec.hpp:49
uint16_t command
Command code.
Definition ir_codec.hpp:47
uint16_t address
Device address.
Definition ir_codec.hpp:46
CodecType protocol
Detected protocol.
Definition ir_codec.hpp:45
bool toggle
Toggle bit (RC5/RC6 only)
Definition ir_codec.hpp:51
bool repeat
True if repeat frame (NEC repeat code / re-sent frame)
Definition ir_codec.hpp:50