M5Unit-INFRARED 0.2.0 git rev:76ad9e1
Loading...
Searching...
No Matches
nec_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_NEC_CODEC_HPP
11#define M5_UNIT_INFRARED_IR_NEC_CODEC_HPP
12
13#include "ir_codec.hpp"
14
15namespace m5 {
16namespace unit {
17namespace ir {
18
39class NecCodec : public IRCodec {
40public:
43 {
44 }
45
47 item_container_type encode(uint16_t address, uint16_t command, bool repeat) override;
49 bool decode(const gpio::m5_rmt_item_t* items, uint32_t num, DecodeResult& result) override;
50
52 uint32_t carrierFrequencyHz() const override
53 {
54 return 38000;
55 }
56
62 item_container_type encodeRaw(uint32_t data);
63
69
70private:
71 // Timing constants in microseconds (RMT tick = 1 us)
72 static constexpr uint16_t LEADER_MARK{9000};
73 static constexpr uint16_t LEADER_SPACE{4500};
74 static constexpr uint16_t BIT_MARK{560};
75 static constexpr uint16_t ONE_SPACE{1690};
76 static constexpr uint16_t ZERO_SPACE{560};
77 static constexpr uint16_t REPEAT_SPACE{2250};
78 static constexpr uint16_t TOLERANCE{200};
79};
80
81} // namespace ir
82} // namespace unit
83} // namespace m5
84#endif
Abstract base class for IR protocol encoding/decoding.
Definition ir_codec.hpp:62
NEC / Extended NEC IR protocol encoder/decoder.
Definition nec_codec.hpp:39
bool decode(const gpio::m5_rmt_item_t *items, uint32_t num, DecodeResult &result) override
Decode a NEC full frame or repeat frame.
Definition nec_codec.cpp:70
item_container_type encodeRepeat()
Encode NEC repeat code.
Definition nec_codec.cpp:58
item_container_type encode(uint16_t address, uint16_t command, bool repeat) override
Encode a standard or extended NEC frame, or the 2-item repeat frame when repeat is true.
Definition nec_codec.cpp:17
NecCodec()
Constructor.
Definition nec_codec.hpp:42
item_container_type encodeRaw(uint32_t data)
Encode with explicit 32-bit raw data.
Definition nec_codec.cpp:41
uint32_t carrierFrequencyHz() const override
Carrier frequency for NEC (38 kHz)
Definition nec_codec.hpp:52
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
@ NEC
NEC / Extended NEC.
Top level namespace of M5Stack.
Unit-related namespace.
Result of decoding a received IR frame.
Definition ir_codec.hpp:44