mirror of
https://github.com/esphome/esphome.git
synced 2025-09-25 22:52:20 +01:00
esp32 remote: make RMT memory blocks configureable (#1002)
This commit is contained in:
@@ -3,7 +3,8 @@ import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import remote_base
|
||||
from esphome.const import CONF_BUFFER_SIZE, CONF_DUMP, CONF_FILTER, CONF_ID, CONF_IDLE, \
|
||||
CONF_PIN, CONF_TOLERANCE
|
||||
CONF_PIN, CONF_TOLERANCE, CONF_MEMORY_BLOCKS
|
||||
from esphome.core import CORE
|
||||
|
||||
AUTO_LOAD = ['remote_base']
|
||||
remote_receiver_ns = cg.esphome_ns.namespace('remote_receiver')
|
||||
@@ -21,12 +22,16 @@ CONFIG_SCHEMA = remote_base.validate_triggers(cv.Schema({
|
||||
cv.SplitDefault(CONF_BUFFER_SIZE, esp32='10000b', esp8266='1000b'): cv.validate_bytes,
|
||||
cv.Optional(CONF_FILTER, default='50us'): cv.positive_time_period_microseconds,
|
||||
cv.Optional(CONF_IDLE, default='10ms'): cv.positive_time_period_microseconds,
|
||||
cv.Optional(CONF_MEMORY_BLOCKS, default=3): cv.Range(min=1, max=8),
|
||||
}).extend(cv.COMPONENT_SCHEMA))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
pin = yield cg.gpio_pin_expression(config[CONF_PIN])
|
||||
var = cg.new_Pvariable(config[CONF_ID], pin)
|
||||
if CORE.is_esp32:
|
||||
var = cg.new_Pvariable(config[CONF_ID], pin, config[CONF_MEMORY_BLOCKS])
|
||||
else:
|
||||
var = cg.new_Pvariable(config[CONF_ID], pin)
|
||||
|
||||
yield remote_base.build_dumpers(config[CONF_DUMP])
|
||||
yield remote_base.build_triggers(config)
|
||||
|
@@ -25,9 +25,20 @@ struct RemoteReceiverComponentStore {
|
||||
};
|
||||
#endif
|
||||
|
||||
class RemoteReceiverComponent : public remote_base::RemoteReceiverBase, public Component {
|
||||
class RemoteReceiverComponent : public remote_base::RemoteReceiverBase,
|
||||
public Component
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
,
|
||||
public remote_base::RemoteRMTChannel
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
RemoteReceiverComponent(GPIOPin *pin, uint8_t mem_block_num = 1)
|
||||
: RemoteReceiverBase(pin), remote_base::RemoteRMTChannel(mem_block_num) {}
|
||||
#else
|
||||
RemoteReceiverComponent(GPIOPin *pin) : RemoteReceiverBase(pin) {}
|
||||
#endif
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
void loop() override;
|
||||
@@ -40,11 +51,10 @@ class RemoteReceiverComponent : public remote_base::RemoteReceiverBase, public C
|
||||
protected:
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
void decode_rmt_(rmt_item32_t *item, size_t len);
|
||||
RingbufHandle_t ringbuf_;
|
||||
esp_err_t error_code_{ESP_OK};
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
RingbufHandle_t ringbuf_;
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
RemoteReceiverComponentStore store_;
|
||||
HighFrequencyLoopRequester high_freq_;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <driver/rmt.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace remote_receiver {
|
||||
@@ -11,10 +12,8 @@ static const char *TAG = "remote_receiver.esp32";
|
||||
void RemoteReceiverComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Remote Receiver...");
|
||||
rmt_config_t rmt{};
|
||||
rmt.channel = this->channel_;
|
||||
this->config_rmt(rmt);
|
||||
rmt.gpio_num = gpio_num_t(this->pin_->get_pin());
|
||||
rmt.clk_div = this->clock_divider_;
|
||||
rmt.mem_block_num = 1;
|
||||
rmt.rmt_mode = RMT_MODE_RX;
|
||||
if (this->filter_us_ == 0) {
|
||||
rmt.rx_config.filter_en = false;
|
||||
@@ -58,6 +57,7 @@ void RemoteReceiverComponent::dump_config() {
|
||||
"invert the signal using 'inverted: True' in the pin schema!");
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " Channel: %d", this->channel_);
|
||||
ESP_LOGCONFIG(TAG, " RMT memory blocks: %d", this->mem_block_num_);
|
||||
ESP_LOGCONFIG(TAG, " Clock divider: %u", this->clock_divider_);
|
||||
ESP_LOGCONFIG(TAG, " Tolerance: %u%%", this->tolerance_);
|
||||
ESP_LOGCONFIG(TAG, " Filter out pulses shorter than: %u us", this->filter_us_);
|
||||
|
Reference in New Issue
Block a user