mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
using reset pi as GPIOPin entity
This commit is contained in:
parent
1edeadbbf4
commit
bfe6187e14
3 changed files with 13 additions and 11 deletions
|
@ -48,7 +48,7 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
{
|
||||
cv.GenerateID(): cv.declare_id(ModemComponent),
|
||||
cv.Required(CONF_TYPE): cv.enum(MODEM_TYPES, upper=True),
|
||||
cv.Required(CONF_RESET_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Required(CONF_RESET_PIN): pins.internal_gpio_output_pin_schema,
|
||||
cv.Optional(CONF_POWER_PIN): pins.internal_gpio_output_pin_schema,
|
||||
cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Required(CONF_RX_PIN): pins.internal_gpio_output_pin_number,
|
||||
|
@ -71,7 +71,10 @@ async def to_code(config):
|
|||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
cg.add(var.set_type(config[CONF_TYPE]))
|
||||
cg.add(var.set_reset_pin(config[CONF_RESET_PIN]))
|
||||
# cg.add(var.set_reset_pin(config[CONF_RESET_PIN]))
|
||||
if reset_pin := config.get(CONF_RESET_PIN, None):
|
||||
pin = await cg.gpio_pin_expression(reset_pin)
|
||||
cg.add(var.set_reset_pin(pin))
|
||||
if power_pin := config.get(CONF_POWER_PIN, None):
|
||||
pin = await cg.gpio_pin_expression(power_pin)
|
||||
cg.add(var.set_power_pin(pin))
|
||||
|
|
|
@ -93,6 +93,7 @@ void ModemComponent::setup() {
|
|||
if (this->power_pin_) {
|
||||
this->power_pin_->setup();
|
||||
this->power_pin_->digital_write(false);
|
||||
this->reset_pin_->setup();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +138,7 @@ void ModemComponent::dump_config() {
|
|||
ESP_LOGCONFIG(TAG, "Modem:");
|
||||
ESP_LOGCONFIG(TAG, " Power Pin: %d", this->power_pin_->get_pin());
|
||||
ESP_LOGCONFIG(TAG, " Type: %d", this->type_);
|
||||
ESP_LOGCONFIG(TAG, " Reset Pin: %d", this->reset_pin_);
|
||||
ESP_LOGCONFIG(TAG, " Reset Pin: %d", this->reset_pin_->get_pin());
|
||||
ESP_LOGCONFIG(TAG, " APN: %s", this->apn_.c_str());
|
||||
ESP_LOGCONFIG(TAG, " TX Pin: %d", this->tx_pin_);
|
||||
ESP_LOGCONFIG(TAG, " RX Pin: %d", this->rx_pin_);
|
||||
|
@ -162,12 +163,10 @@ void ModemComponent::dump_connect_params() {
|
|||
}
|
||||
|
||||
void ModemComponent::esp_modem_hard_reset() {
|
||||
gpio_set_direction(gpio_num_t(this->reset_pin_), GPIO_MODE_OUTPUT);
|
||||
// gpio_pullup_en(reset_pin_);
|
||||
gpio_set_level(gpio_num_t(this->reset_pin_), 0);
|
||||
this->reset_pin_->digital_write(false);
|
||||
ESP_LOGD(TAG, "reset_pin_ 0");
|
||||
vTaskDelay(pdMS_TO_TICKS(50)); // NOLINT
|
||||
gpio_set_level(gpio_num_t(this->reset_pin_), 1);
|
||||
vTaskDelay(pdMS_TO_TICKS(110)); // NOLINT
|
||||
this->reset_pin_->digital_write(true);
|
||||
ESP_LOGD(TAG, "reset_pin_ 1");
|
||||
time_hard_reset_modem = millis();
|
||||
}
|
||||
|
@ -259,7 +258,7 @@ void ModemComponent::start_connect_() {
|
|||
bool ModemComponent::is_connected() { return this->state_ == ModemComponentState::CONNECTED; }
|
||||
void ModemComponent::set_power_pin(InternalGPIOPin *power_pin) { this->power_pin_ = power_pin; }
|
||||
void ModemComponent::set_type(ModemType type) { this->type_ = type; }
|
||||
void ModemComponent::set_reset_pin(int reset_pin) { this->reset_pin_ = reset_pin; }
|
||||
void ModemComponent::set_reset_pin(InternalGPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
|
||||
void ModemComponent::set_apn(const std::string &apn) { this->apn_ = apn; }
|
||||
void ModemComponent::set_tx_pin(int tx_pin) { this->tx_pin_ = tx_pin; }
|
||||
void ModemComponent::set_rx_pin(int rx_pin) { this->rx_pin_ = rx_pin; }
|
||||
|
|
|
@ -42,7 +42,7 @@ class ModemComponent : public Component {
|
|||
bool is_connected();
|
||||
void set_power_pin(InternalGPIOPin *power_pin);
|
||||
void set_type(ModemType type);
|
||||
void set_reset_pin(int reset_pin);
|
||||
void set_reset_pin(InternalGPIOPin *reset_pin);
|
||||
void set_apn(const std::string &apn);
|
||||
void set_tx_pin(int tx_pin);
|
||||
void set_rx_pin(int rx_pin);
|
||||
|
@ -68,7 +68,7 @@ class ModemComponent : public Component {
|
|||
std::shared_ptr<esp_modem::DTE> dte{nullptr};
|
||||
std::unique_ptr<esp_modem::DCE> dce{nullptr};
|
||||
ModemType type_{MODEM_TYPE_UNKNOWN};
|
||||
int reset_pin_{-1};
|
||||
InternalGPIOPin *reset_pin_{nullptr};
|
||||
InternalGPIOPin *power_pin_{nullptr};
|
||||
int tx_pin_{-1};
|
||||
int rx_pin_{-1};
|
||||
|
|
Loading…
Reference in a new issue