M5Unit-INFRARED 0.2.0 git rev:76ad9e1
Loading...
Searching...
No Matches
m5::unit::ir::NecCodec Class Reference

NEC / Extended NEC IR protocol encoder/decoder. More...

#include <nec_codec.hpp>

Inheritance diagram for m5::unit::ir::NecCodec:
m5::unit::ir::IRCodec

Public Member Functions

 NecCodec ()
 Constructor.
 
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.
 
bool decode (const gpio::m5_rmt_item_t *items, uint32_t num, DecodeResult &result) override
 Decode a NEC full frame or repeat frame.
 
uint32_t carrierFrequencyHz () const override
 Carrier frequency for NEC (38 kHz)
 
item_container_type encodeRaw (uint32_t data)
 Encode with explicit 32-bit raw data.
 
item_container_type encodeRepeat ()
 Encode NEC repeat code.
 
- Public Member Functions inherited from m5::unit::ir::IRCodec
 IRCodec (CodecType t)
 
CodecType type () const
 Get codec type for safe downcasting.
 
virtual float carrierDuty () const
 Carrier duty cycle (0.0 - 1.0)
 
virtual uint8_t minFrames () const
 Number of frames that should be transmitted per keypress for this protocol.
 
virtual uint16_t frameGapUs () const
 Inter-frame gap (microseconds) when transmitting multiple frames in one burst.
 
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.
 

Detailed Description

NEC / Extended NEC IR protocol encoder/decoder.

  • Carrier: 38 kHz, duty 1/3
  • Modulation: Pulse Distance (mark duration constant, space varies)
  • Bit order: LSB first
  • Standard NEC: 8-bit address + inverted + 8-bit command + inverted = 32 bits
  • Extended NEC: 16-bit address (no inversion) + 8-bit command + inverted = 32 bits
  • Repeat code: 9ms mark + 2.25ms space + 560us mark
Timing
Element Mark (us) Space (us)
Leader 9000 4500
Bit "1" 560 1690
Bit "0" 560 560
Repeat 9000 2250
Stop 560 -

Member Function Documentation

◆ carrierFrequencyHz()

uint32_t m5::unit::ir::NecCodec::carrierFrequencyHz ( ) const
inlineoverridevirtual

Carrier frequency for NEC (38 kHz)

Implements m5::unit::ir::IRCodec.

◆ encode()

item_container_type m5::unit::ir::NecCodec::encode ( uint16_t address,
uint16_t command,
bool repeat )
overridevirtual

Encode a standard or extended NEC frame, or the 2-item repeat frame when repeat is true.

Implements m5::unit::ir::IRCodec.

◆ encodeRaw()

item_container_type m5::unit::ir::NecCodec::encodeRaw ( uint32_t data)

Encode with explicit 32-bit raw data.

Parameters
data32-bit NEC frame (address + ~address + command + ~command)
Returns
RMT items

◆ encodeRepeat()

item_container_type m5::unit::ir::NecCodec::encodeRepeat ( )

Encode NEC repeat code.

Returns
RMT items for repeat frame