1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00:00

esp32 remote: make RMT memory blocks configureable (#1002)

This commit is contained in:
puuu
2020-05-01 10:59:51 +09:00
committed by GitHub
parent af66753c1b
commit d49ee47018
8 changed files with 63 additions and 28 deletions

View File

@@ -6,14 +6,24 @@ namespace remote_base {
static const char *TAG = "remote_base";
RemoteComponentBase::RemoteComponentBase(GPIOPin *pin) : pin_(pin) {
#ifdef ARDUINO_ARCH_ESP32
RemoteRMTChannel::RemoteRMTChannel(uint8_t mem_block_num) : mem_block_num_(mem_block_num) {
static rmt_channel_t next_rmt_channel = RMT_CHANNEL_0;
this->channel_ = next_rmt_channel;
next_rmt_channel = rmt_channel_t(int(next_rmt_channel) + 1);
#endif
next_rmt_channel = rmt_channel_t(int(next_rmt_channel) + mem_block_num);
}
void RemoteRMTChannel::config_rmt(rmt_config_t &rmt) {
if (rmt_channel_t(int(this->channel_) + this->mem_block_num_) > RMT_CHANNEL_7) {
this->mem_block_num_ = int(RMT_CHANNEL_7) - int(this->channel_) + 1;
ESP_LOGW(TAG, "Not enough RMT memory blocks avaiable, reduced to %i blocks.", this->mem_block_num_);
}
rmt.channel = this->channel_;
rmt.clk_div = this->clock_divider_;
rmt.mem_block_num = this->mem_block_num_;
}
#endif
void RemoteReceiverBinarySensorBase::dump_config() { LOG_BINARY_SENSOR("", "Remote Receiver Binary Sensor", this); }
void RemoteTransmitterBase::send_(uint32_t send_times, uint32_t send_wait) {

View File

@@ -146,15 +146,21 @@ template<typename T> class RemoteProtocol {
class RemoteComponentBase {
public:
explicit RemoteComponentBase(GPIOPin *pin);
#ifdef ARDUINO_ARCH_ESP32
void set_channel(rmt_channel_t channel) { this->channel_ = channel; }
void set_clock_divider(uint8_t clock_divider) { this->clock_divider_ = clock_divider; }
#endif
explicit RemoteComponentBase(GPIOPin *pin) : pin_(pin){};
protected:
GPIOPin *pin_;
};
#ifdef ARDUINO_ARCH_ESP32
class RemoteRMTChannel {
public:
explicit RemoteRMTChannel(uint8_t mem_block_num = 1);
void config_rmt(rmt_config_t &rmt);
void set_clock_divider(uint8_t clock_divider) { this->clock_divider_ = clock_divider; }
protected:
uint32_t from_microseconds(uint32_t us) {
const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
return us * ticks_per_ten_us / 10;
@@ -163,15 +169,12 @@ class RemoteComponentBase {
const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
return (ticks * 10) / ticks_per_ten_us;
}
#endif
GPIOPin *pin_;
#ifdef ARDUINO_ARCH_ESP32
RemoteComponentBase *remote_base_;
rmt_channel_t channel_{RMT_CHANNEL_0};
uint8_t mem_block_num_;
uint8_t clock_divider_{80};
esp_err_t error_code_{ESP_OK};
#endif
};
#endif
class RemoteTransmitterBase : public RemoteComponentBase {
public: