10#if defined(USE_BK72XX) && !defined(CLANG_TIDY)
13#include <ArduinoPrivate.h>
27static constexpr uint32_t IRDA_CTRL_REG = 0x00802400;
28static constexpr uint32_t IRDA_INT_REG = 0x00802408;
29static constexpr uint32_t IRDA_RX_FIFO_REG = 0x0080240C;
31static constexpr uint32_t IRDA_END_INT = 1u << 0;
32static constexpr uint32_t IRDA_REPEAT_INT = 1u << 2;
33static constexpr uint32_t IRDA_FIFO_WREN_INT = 1u << 3;
34static constexpr uint32_t IRDA_PARITY_ERR_INT = 1u << 4;
35static constexpr uint32_t IRDA_STOP_ERR_INT = 1u << 5;
37static constexpr uint32_t IRDA_FRAME_ERROR_INTS = IRDA_PARITY_ERR_INT | IRDA_STOP_ERR_INT;
38static constexpr uint32_t IRDA_ERROR_INTS = IRDA_FIFO_WREN_INT | IRDA_FRAME_ERROR_INTS;
42static constexpr size_t NEC_FRAME_DURATIONS = 2 + 64 + 1;
45static inline void saturating_increment(
volatile uint8_t &
value) {
46 if (
value != UINT8_MAX)
51static BekenIrdaComponent *s_irda =
nullptr;
57 REG_WRITE(IRDA_INT_REG,
status);
59 if (
status & IRDA_END_INT) {
60 const uint32_t code = REG_READ(IRDA_RX_FIFO_REG);
61 const uint8_t command = code >> 16;
62 const uint8_t inverse = code >> 24;
64 if ((
status & IRDA_FRAME_ERROR_INTS) == 0 && (command ^ inverse) == 0xFF) {
75 status &= ~IRDA_ERROR_INTS;
80 }
else if ((status & IRDA_REPEAT_INT) && (
status & IRDA_FRAME_ERROR_INTS) == 0 && this->
repeats_valid_) {
83 if (status & IRDA_ERROR_INTS)
91 std::array<int32_t, NEC_FRAME_DURATIONS> frame;
95 for (
uint32_t mask = 1; mask != 0; mask <<= 1) {
114 intc_service_register(IRQ_IRDA, PRI_IRQ_IRDA,
irda_isr);
118 if (REG_READ(IRDA_CTRL_REG) == 0) {
119 this->
mark_failed(LOG_STR(
"IRDA controller did not initialize"));
148 ESP_LOGD(TAG,
"%u decode errors", errors);
151 ESP_LOGW(TAG,
"%u codes dropped, the loop did not keep up", dropped);
153 if (!have_code && !have_repeat) {
164 ESP_LOGCONFIG(TAG,
"Beken IRDA receiver (NEC):");
165 LOG_PIN(
" Pin: ", this->
pin_);
void intc_service_change_handler(unsigned char int_num, void(*isr)())
void mark_failed()
Mark this component as failed.
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
void disable_loop()
Disable this component's loop.
Helper class to disable interrupts.
void dispatch_full_(uint32_t code)
void dump_config() override
volatile bool repeats_valid_
Repeats belong to the last frame the ISR read, so they are dropped after a rejected one.
volatile bool repeat_ready_
volatile uint8_t error_count_
volatile uint8_t dropped_count_
volatile uint32_t last_code_
static constexpr int32_t HEADER_HIGH_US
static constexpr int32_t REPEAT_HEADER_LOW_US
static constexpr int32_t BIT_ZERO_LOW_US
static constexpr int32_t BIT_HIGH_US
static constexpr int32_t HEADER_LOW_US
static constexpr int32_t BIT_ONE_LOW_US
void call_listeners_dumpers_()
ESPHOME_LOG_TAG(TAG, "beken_irda")