M5Unit-INFRARED 0.2.0 git rev:76ad9e1
Loading...
Searching...
No Matches
ir_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_CODEC_HPP
11#define M5_UNIT_INFRARED_IR_CODEC_HPP
12
13#include <M5UnitComponent.hpp>
14#include <cstdint>
15#include <vector>
16
17namespace m5 {
18namespace unit {
19namespace ir {
20
27enum class CodecType : uint8_t {
28 NEC = 0,
29 SIRC,
30 RC5,
31 RC6,
32 Panasonic,
34 Raw,
35 // Reserved for future protocols (Samsung, LG, JVC, Sharp, AEHA, etc.)
36 Unknown = 254,
37 Custom = 255,
38};
39
45 CodecType protocol{CodecType::Unknown};
46 uint16_t address{};
47 uint16_t command{};
48 uint64_t raw{};
49 uint8_t bits{};
50 bool repeat{};
51 bool toggle{};
52};
53
54using item_container_type = std::vector<m5::unit::gpio::m5_rmt_item_t>;
55
62class IRCodec {
63public:
64 explicit IRCodec(CodecType t) : _type(t)
65 {
66 }
67 virtual ~IRCodec() = default;
68
74 {
75 return _type;
76 }
77
80
87 virtual item_container_type encode(uint16_t address, uint16_t command, bool repeat = false) = 0;
88
93 virtual uint32_t carrierFrequencyHz() const = 0;
94
99 virtual float carrierDuty() const
100 {
101 return 0.33f;
102 }
103
109 virtual uint8_t minFrames() const
110 {
111 return 1;
112 }
113
119 virtual uint16_t frameGapUs() const
120 {
121 return 0;
122 }
124
127
134 virtual bool decode(const m5::unit::gpio::m5_rmt_item_t* items, uint32_t num, DecodeResult& result) = 0;
136
137private:
138 CodecType _type;
139};
140
141} // namespace ir
142} // namespace unit
143} // namespace m5
144#endif
Abstract base class for IR protocol encoding/decoding.
Definition ir_codec.hpp:62
virtual float carrierDuty() const
Carrier duty cycle (0.0 - 1.0)
Definition ir_codec.hpp:99
virtual uint8_t minFrames() const
Number of frames that should be transmitted per keypress for this protocol.
Definition ir_codec.hpp:109
virtual item_container_type encode(uint16_t address, uint16_t command, bool repeat=false)=0
Encode IR command into RMT items.
virtual bool decode(const m5::unit::gpio::m5_rmt_item_t *items, uint32_t num, DecodeResult &result)=0
Try to decode RMT items into an IR command.
virtual uint32_t carrierFrequencyHz() const =0
Carrier frequency for this protocol in Hz.
virtual uint16_t frameGapUs() const
Inter-frame gap (microseconds) when transmitting multiple frames in one burst.
Definition ir_codec.hpp:119
CodecType type() const
Get codec type for safe downcasting.
Definition ir_codec.hpp:73
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
@ SIRC
Sony SIRC (12/15/20-bit)
@ Mitsubishi
Mitsubishi (16-bit, no leader, sent twice)
@ Panasonic
Panasonic / Kaseikyo (48-bit, customer code + data)
@ RC5
Philips RC5 / RC5X.
@ Raw
Raw mark/space (no protocol)
@ NEC
NEC / Extended NEC.
@ Unknown
Unknown protocol.
@ Custom
User-defined custom protocol.
@ RC6
Philips RC6 Mode 0.
Top level namespace of M5Stack.
Unit-related namespace.
Result of decoding a received IR frame.
Definition ir_codec.hpp:44
uint64_t raw
Raw encoded value (protocol-specific, up to 64 bits)
Definition ir_codec.hpp:48
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