6#if defined(USE_BK72XX) && !defined(CLANG_TIDY)
10#include <ArduinoPrivate.h>
22static const char *
const TAG =
"remote_transmitter";
24#ifdef REMOTE_TRANSMITTER_BK_PWM
32static constexpr uint32_t REG_PWM_BASE = 0x00802B00UL;
33static constexpr uint32_t REG_PWM_GROUP_STRIDE = 0x40;
34static constexpr uint32_t REG_PWM_T_REGS[2] = {0x04, 0x14};
35static constexpr uint32_t PWM_INT_STATUS_MASK = 3UL << 30;
36static constexpr uint8_t ENVELOPE_TIMER = BKTIMER1;
50static constexpr PwmPinChannel PWM_PIN_CHANNELS[] = {
71static int8_t pwm_channel_for_pin(uint8_t pin) {
72 for (
const auto &entry : PWM_PIN_CHANNELS) {
81 const int8_t channel = pwm_channel_for_pin(this->
pin_->
get_pin());
83 ESP_LOGE(TAG,
"Pin %u is not PWM-capable", this->
pin_->
get_pin());
93 param.init_level = idle_t1 ? 1 : 0;
94 if (pwm_init_param(¶m) != 0 || pwm_start(channel) != 0) {
95 ESP_LOGE(TAG,
"PWM init failed on pin %u", this->
pin_->
get_pin());
105 "Remote Transmitter:\n"
106 " Carrier Duty: %u%%\n"
109 LOG_PIN(
" Pin: ", this->
pin_);
119 const uint32_t group_base = REG_PWM_BASE + REG_PWM_GROUP_STRIDE * group;
120 auto *t_regs = (
volatile uint32_t *) (group_base + REG_PWM_T_REGS[post]);
121 auto *ctrl = (
volatile uint32_t *) group_base;
122 const uint32_t init_level_bit = 1UL << (8 * post + 6);
123 const uint32_t cfg_updata_bit = 1UL << (8 * post + 7);
124 t_regs[0] = t1_counts;
129 cfg &= ~(PWM_INT_STATUS_MASK | init_level_bit | cfg_updata_bit);
131 cfg |= init_level_bit;
133 *ctrl = cfg | cfg_updata_bit;
143 if (carrier_frequency > 0) {
165 timer_param_t param{};
166 param.channel = ENVELOPE_TIMER;
168 param.period = duration_us;
169 param.t_Int_Handler = envelope_timer_isr;
170 sddev_control((
char *) TIMER_DEV_NAME, CMD_TIMER_INIT_PARAM_US, ¶m);
174 UINT32 channel = ENVELOPE_TIMER;
175 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