mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 18:54:14 +01:00
gpio pins numbering
This commit is contained in:
parent
6d2e6eb15a
commit
a814ea337f
3 changed files with 16 additions and 14 deletions
|
@ -15,7 +15,7 @@ import esphome.codegen as cg
|
|||
import esphome.config_validation as cv
|
||||
from esphome.core import coroutine_with_priority
|
||||
from esphome.components.esp32 import add_idf_component, add_idf_sdkconfig_option
|
||||
from esphome import automation
|
||||
from esphome import pins, automation
|
||||
|
||||
CODEOWNERS = ["@oarcher"]
|
||||
DEPENDENCIES = ["esp32"]
|
||||
|
@ -47,11 +47,11 @@ CONFIG_SCHEMA = cv.All(
|
|||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(ModemComponent),
|
||||
cv.Required(CONF_TX_PIN): cv.positive_int,
|
||||
cv.Required(CONF_RX_PIN): cv.positive_int,
|
||||
cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_schema,
|
||||
cv.Required(CONF_RX_PIN): pins.internal_gpio_output_pin_schema,
|
||||
cv.Required(CONF_MODEL): cv.string,
|
||||
cv.Required(CONF_APN): cv.string,
|
||||
cv.Optional(CONF_DTR_PIN): cv.positive_int,
|
||||
cv.Optional(CONF_DTR_PIN): pins.internal_gpio_output_pin_schema,
|
||||
cv.Optional(CONF_PIN_CODE): cv.string_strict,
|
||||
cv.Optional(CONF_USERNAME): cv.string,
|
||||
cv.Optional(CONF_PASSWORD): cv.string,
|
||||
|
@ -134,10 +134,11 @@ async def to_code(config):
|
|||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
cg.add(var.set_apn(config[CONF_APN]))
|
||||
|
||||
gpio_num_t = cg.global_ns.enum("gpio_num_t")
|
||||
tx_pin = await cg.gpio_pin_expression(config[CONF_TX_PIN])
|
||||
cg.add(var.set_tx_pin(tx_pin))
|
||||
|
||||
cg.add(var.set_rx_pin(getattr(gpio_num_t, f"GPIO_NUM_{config[CONF_RX_PIN]}")))
|
||||
cg.add(var.set_tx_pin(getattr(gpio_num_t, f"GPIO_NUM_{config[CONF_TX_PIN]}")))
|
||||
rx_pin = await cg.gpio_pin_expression(config[CONF_RX_PIN])
|
||||
cg.add(var.set_rx_pin(rx_pin))
|
||||
|
||||
for conf in config.get(CONF_ON_NOT_RESPONDING, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
|
|
|
@ -111,8 +111,8 @@ void ModemComponent::reset_() {
|
|||
esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
|
||||
this->dte_config_ = dte_config;
|
||||
|
||||
this->dte_config_.uart_config.tx_io_num = this->tx_pin_;
|
||||
this->dte_config_.uart_config.rx_io_num = this->rx_pin_;
|
||||
this->dte_config_.uart_config.tx_io_num = this->tx_pin_->get_pin();
|
||||
this->dte_config_.uart_config.rx_io_num = this->rx_pin_->get_pin();
|
||||
// this->dte_config_.uart_config.rts_io_num = static_cast<gpio_num_t>( CONFIG_EXAMPLE_MODEM_UART_RTS_PIN);
|
||||
// this->dte_config_.uart_config.cts_io_num = static_cast<gpio_num_t>( CONFIG_EXAMPLE_MODEM_UART_CTS_PIN);
|
||||
this->dte_config_.uart_config.rx_buffer_size = CONFIG_MODEM_UART_RX_BUFFER_SIZE;
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
#include <memory>
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/components/network/util.h"
|
||||
#include "esphome/core/gpio.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/components/network/util.h"
|
||||
|
||||
#ifdef USE_ESP_IDF
|
||||
|
||||
|
@ -53,8 +54,8 @@ class ModemComponent : public Component {
|
|||
network::IPAddresses get_ip_addresses();
|
||||
std::string get_use_address() const;
|
||||
void set_use_address(const std::string &use_address);
|
||||
void set_rx_pin(gpio_num_t rx_pin) { this->rx_pin_ = rx_pin; }
|
||||
void set_tx_pin(gpio_num_t tx_pin) { this->tx_pin_ = tx_pin; }
|
||||
void set_rx_pin(InternalGPIOPin *rx_pin) { this->rx_pin_ = rx_pin; }
|
||||
void set_tx_pin(InternalGPIOPin *tx_pin) { this->tx_pin_ = tx_pin; }
|
||||
void set_username(const std::string &username) { this->username_ = username; }
|
||||
void set_password(const std::string &password) { this->password_ = password; }
|
||||
void set_pin_code(const std::string &pin_code) { this->pin_code_ = pin_code; }
|
||||
|
@ -74,8 +75,8 @@ class ModemComponent : public Component {
|
|||
|
||||
protected:
|
||||
void reset_(); // (re)create dte and dce
|
||||
gpio_num_t rx_pin_ = gpio_num_t::GPIO_NUM_NC;
|
||||
gpio_num_t tx_pin_ = gpio_num_t::GPIO_NUM_NC;
|
||||
InternalGPIOPin *tx_pin_;
|
||||
InternalGPIOPin *rx_pin_;
|
||||
std::string pin_code_;
|
||||
std::string username_;
|
||||
std::string password_;
|
||||
|
|
Loading…
Reference in a new issue