mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2026-04-28 03:08:08 +00:00
Refactor IR decoder and encoder for improved pulse filtering and ISR handling. Removed unused filtered sub-buffer, updated pulse filter methods, and added support for buffered ISR storage in the encoder. Enhanced documentation for clarity on DMA TX backend and ISR modes.
This commit is contained in:
31
IR_Encoder.h
31
IR_Encoder.h
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "IR_config.h"
|
||||
#include "IrTxBsrrWave.h"
|
||||
#include "IrTxGateTypes.h"
|
||||
|
||||
// TODO: Отложенная передача после завершения приема
|
||||
|
||||
@ -14,6 +14,7 @@ struct IR_SendResult {
|
||||
};
|
||||
|
||||
class IR_DecoderRaw;
|
||||
class IrTxIsrBufferedStorageBase;
|
||||
class IR_Encoder : public IR_FOX
|
||||
{
|
||||
friend IR_DecoderRaw;
|
||||
@ -24,6 +25,10 @@ public:
|
||||
static HardwareTimer* IR_Timer;
|
||||
|
||||
using IR_TxGateRun = IrTxGateRun;
|
||||
enum class TxIsrMode : uint8_t {
|
||||
Legacy = 0,
|
||||
Buffered = 1
|
||||
};
|
||||
|
||||
using ExternalTxBusyFn = bool (*)(void *ctx);
|
||||
using ExternalTxStartFn = bool (*)(void *ctx, IR_Encoder *enc, const uint8_t *packet, uint8_t len);
|
||||
@ -69,10 +74,19 @@ public:
|
||||
/**
|
||||
* Режим внутреннего TX без DMA: false — BSRR + кольцо (buildGateRuns + scaleGateRunsToPhysical);
|
||||
* true — FSM «налету» + скважность несущей как у буферного пути (подшаги multiply/2 на шаг FSM).
|
||||
* Выставить до begin/rawSend (глобально на все IR_Encoder). Игнорируется при externalTxStartFn.
|
||||
* По умолчанию включён legacy=true для обратной совместимости. Вызов меняет default и обновляет
|
||||
* все зарегистрированные encoder-объекты. Buffered ISR реально используется только если у encoder
|
||||
* привязан storage через attachBufferedIsrStorage()/enableBufferedIsr().
|
||||
* Выставить до begin/rawSend. Игнорируется при externalTxStartFn.
|
||||
*/
|
||||
static void setTxIsrLegacyMode(bool legacy);
|
||||
static bool txIsrLegacyMode();
|
||||
void attachBufferedIsrStorage(IrTxIsrBufferedStorageBase& storage);
|
||||
void detachBufferedIsrStorage();
|
||||
bool hasBufferedIsrStorage() const;
|
||||
void enableBufferedIsr(IrTxIsrBufferedStorageBase& storage);
|
||||
void disableBufferedIsr();
|
||||
TxIsrMode txIsrMode() const;
|
||||
|
||||
/** Optional: register external TX backend (e.g. DMA driver). */
|
||||
static void setExternalTxBackend(ExternalTxStartFn startFn, ExternalTxBusyFn busyFn, void *ctx);
|
||||
@ -175,14 +189,7 @@ private:
|
||||
static bool txEmitTick(TxFsmState &st, const uint8_t *sendBufferLocal, bool &gateOut);
|
||||
void loadTxFsmFromMembers(TxFsmState &st) const;
|
||||
void storeTxFsmToMembers(const TxFsmState &st);
|
||||
|
||||
IrTxBsrrWave txBsrrWave_{};
|
||||
IR_TxGateRun txGateRuns_[irproto::kIsrTxMaxGateRuns]{};
|
||||
uint32_t txBsrrWords_[irproto::kIsrTxBsrrWordCount]{};
|
||||
uint16_t txBsrrReadIdx_ = 0;
|
||||
uint16_t txBsrrHalfLen_ = 0;
|
||||
uint32_t txBsrrTotalTicks_ = 0;
|
||||
uint32_t txBsrrTicksSent_ = 0;
|
||||
bool shouldUseBufferedIsr() const;
|
||||
|
||||
/** Снимок на старт TX (буферный и legacy путь). */
|
||||
uint16_t txPowerSnap_ = 1;
|
||||
@ -194,6 +201,10 @@ private:
|
||||
uint16_t legacySlotInPeriod_ = 0;
|
||||
|
||||
volatile uint16_t powerNumerator_ = 1;
|
||||
IrTxIsrBufferedStorageBase* txBufferedCtx_ = nullptr;
|
||||
IrTxIsrBufferedStorageBase* txActiveBufferedCtx_ = nullptr;
|
||||
TxIsrMode txIsrMode_ = TxIsrMode::Legacy;
|
||||
bool txUseBufferedIsr_ = false;
|
||||
|
||||
IR_DecoderRaw *decPair = nullptr;
|
||||
IR_DecoderRaw *singleBlindDecoder = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user