3#include <driver/rmt_rx.h>
4#include <driver/rmt_tx.h>
5#include <freertos/FreeRTOS.h>
6#include <freertos/queue.h>
7#include <freertos/task.h>
11#include "../TransceiverConfig.h"
12#include "pulse/Codec.h"
13#include "pulse/RingBuffer.h"
14#include "pulse/RxDriver.h"
15#include "pulse/TxDriver.h"
16#include "pulse/TxDriverCommon.h"
17#include "pulse/TxProtocol.h"
18#include "pulse/Vector.h"
39 if (!_codec->
begin()) {
75 void sendPreamble()
override {
76 if (is_frame_closed) {
81 is_frame_closed =
false;
98 for (
size_t i = 0,
j = 0;
i + 1 < output.
size();
i += 2, ++
j) {
99 _itemsBuffer[
j].duration0 = output[
i].pulseUs;
100 _itemsBuffer[
j].level0 = output[
i].level ? 1 : 0;
101 _itemsBuffer[
j].duration1 = output[
i + 1].pulseUs;
102 _itemsBuffer[
j].level1 = output[
i + 1].level ? 1 : 0;
104 if (_txChannel && _txEncoder) {
113 _itemsBuffer.
clear();
118 if (is_frame_closed)
return;
132 for (
size_t i = 0,
j = 0;
i + 1 < output.
size();
i += 2, ++
j) {
133 _itemsBuffer[
j].duration0 = output[
i].pulseUs;
134 _itemsBuffer[
j].level0 = output[
i].level ? 1 : 0;
135 _itemsBuffer[
j].duration1 = output[
i + 1].pulseUs;
136 _itemsBuffer[
j].level1 = output[
i + 1].level ? 1 : 0;
138 if (_txChannel && _txEncoder) {
146 is_frame_closed =
true;
149 bool isFrameClosed()
const override {
return is_frame_closed; }
152 Codec* _codec =
nullptr;
161 bool is_frame_closed =
true;
191 if (!protocol.begin(&codec, pin)) {
198 TxProtocolESP32 protocol;
200 void sendPreamble() { protocol.sendPreamble(); }
202 void sendData(
const uint8_t* data, uint8_t len) {
203 protocol.sendData(data, len, _bitPeriod);
206 void sendEnd() { protocol.sendEnd(_useChecksum,
true); }
Abstract base class for IR protocol encoding and decoding.
virtual size_t encode(uint8_t byte, Vector< OutputEdge > &output)
Fill output vector with protocol-specific OutputSpec(s) for a byte.
virtual bool begin(uint32_t bitFrequencyHz)
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
Preamble & getPreamble()
Get the preamble detector associated with this codec.
static void error(const char *format,...)
Log an error message with formatting.
virtual int getEdges(pulsewire::Vector< pulsewire::OutputEdge > &output) const =0
Returns the expected preamble edges for this protocol.
Provides common logic for transmitting signals using various framing modes.
ESP32-specific TxDriver implementation that uses TxProtocolESP32 for transmission.
TxDriverESP32(Codec &codec, uint8_t pin, uint32_t carrierHz=CARRIER_HZ, uint32_t freqHz=DEFAULT_BIT_FREQ_HZ, uint8_t duty=33, bool useChecksum=false)
ESP32-specific TxProtocol implementation using RMT for precise timing and DMA support.
Abstract base class for defining transmission protocols.
Small, header-only vector replacement for non-STL environments.
void resize(size_t n)
Resize vector to n elements.
void clear()
Remove all elements.
void push_back(const T &value)
Add element to end of vector.
T * data()
Pointer to underlying data.
size_t size() const
Number of elements in vector.
Specifies a single IR signal segment for protocol-agnostic transmission.