6#if defined(USE_BK72XX) && !defined(CLANG_TIDY)
10#include <ArduinoPrivate.h>
19static const char *
const TAG =
"remote_transmitter";
21#ifdef REMOTE_TRANSMITTER_BK_PWM
29static constexpr uint32_t REG_PWM_BASE = 0x00802B00UL;
30static constexpr uint32_t REG_PWM_GROUP_STRIDE = 0x40;
31static constexpr uint32_t REG_PWM_T_REGS[2] = {0x04, 0x14};
32static constexpr uint32_t PWM_INT_STATUS_MASK = 3UL << 30;
33static constexpr uint8_t ENVELOPE_TIMER = BKTIMER1;
47static constexpr PwmPinChannel PWM_PIN_CHANNELS[] = {
68static int8_t pwm_channel_for_pin(uint8_t pin) {
69 for (
const auto &entry : PWM_PIN_CHANNELS) {
78 const int8_t channel = pwm_channel_for_pin(this->
pin_->
get_pin());
80 ESP_LOGE(TAG,
"Pin %u is not PWM-capable", this->
pin_->
get_pin());
90 param.init_level = idle_t1 ? 1 : 0;
91 if (pwm_init_param(¶m) != 0 || pwm_start(channel) != 0) {
92 ESP_LOGE(TAG,
"PWM init failed on pin %u", this->
pin_->
get_pin());
102 "Remote Transmitter:\n"
103 " Carrier Duty: %u%%\n"
106 LOG_PIN(
" Pin: ", this->
pin_);
116 const uint32_t group_base = REG_PWM_BASE + REG_PWM_GROUP_STRIDE * group;
117 auto *t_regs = (
volatile uint32_t *) (group_base + REG_PWM_T_REGS[post]);
118 auto *ctrl = (
volatile uint32_t *) group_base;
119 const uint32_t init_level_bit = 1UL << (8 * post + 6);
120 const uint32_t cfg_updata_bit = 1UL << (8 * post + 7);
121 t_regs[0] = t1_counts;
126 cfg &= ~(PWM_INT_STATUS_MASK | init_level_bit | cfg_updata_bit);
128 cfg |= init_level_bit;
130 *ctrl = cfg | cfg_updata_bit;
140 if (carrier_frequency > 0) {
162 timer_param_t param{};
163 param.channel = ENVELOPE_TIMER;
165 param.period = duration_us;
166 param.t_Int_Handler = envelope_timer_isr;
167 sddev_control((
char *) TIMER_DEV_NAME, CMD_TIMER_INIT_PARAM_US, ¶m);
171 UINT32 channel = ENVELOPE_TIMER;
172 sddev_control((
char *) TIMER_DEV_NAME, CMD_TIMER_UNIT_DISABLE, &channel);
void mark_failed()
Mark this component as failed.
void disable_loop()
Disable this component's loop.
virtual uint8_t get_pin() const =0
virtual bool is_inverted() const =0
bool envelope_ready_() const
void write_envelope_level_(bool mark)
static void advance_active_isr()
void stop_envelope_timer_()
void prepare_carrier_(uint32_t carrier_frequency)
void write_pwm_t1_(uint32_t t1_counts)
void digital_write(bool value)
void arm_one_shot_(uint32_t duration_us)
uint8_t carrier_duty_percent_
void dump_config() override