diff --git a/esphome/components/modem/__init__.py b/esphome/components/modem/__init__.py index e63715ff48..6ee1911eff 100644 --- a/esphome/components/modem/__init__.py +++ b/esphome/components/modem/__init__.py @@ -26,6 +26,7 @@ CONF_APN = "apn" CONF_UART_EVENT_TASK_STACK_SIZE = "uart_event_task_stack_size" CONF_UART_EVENT_TASK_PRIORITY = "uart_event_task_priority" CONF_UART_EVENT_QUEUE_SIZE = "uart_event_queue_size" +CONF_POWER_PIN = "power_pin" ModemType = modem_ns.enum("ModemType") MODEM_TYPES = { @@ -71,9 +72,9 @@ 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_schema, - cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_schema, - cv.Required(CONF_RX_PIN): pins.internal_gpio_input_pin_schema, + cv.Required(CONF_RESET_PIN): pins.internal_gpio_output_pin_number, + cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_number, + cv.Required(CONF_RX_PIN): pins.internal_gpio_output_pin_number, cv.Optional(CONF_APN, default="internet"): cv.string, cv.Optional(CONF_UART_EVENT_TASK_STACK_SIZE, default=2048): cv.positive_not_null_int, cv.Optional(CONF_UART_EVENT_TASK_PRIORITY, default=5): cv.positive_not_null_int, @@ -91,19 +92,17 @@ async def to_code(config): 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_tx_pin(config[CONF_TX_PIN])) + # cg.add(var.set_rx_pin(config[CONF_RX_PIN])) + # cg.add(var.set_apn(config[CONF_APN])) + # cg.add(var.set_tx_buffer_size(config[CONF_TX_BUFFER_SIZE])) + # cg.add(var.set_rx_buffer_size(config[CONF_RX_BUFFER_SIZE])) + # cg.add(var.set_uart_event_task_stack_size(config[CONF_UART_EVENT_TASK_STACK_SIZE])) + # cg.add(var.set_uart_event_task_priority(config[CONF_UART_EVENT_TASK_PRIORITY])) + # cg.add(var.set_uart_event_queue_size([CONF_UART_EVENT_QUEUE_SIZE])) + # cg.add(var.set_use_address(config[CONF_USE_ADDRESS])) cg.add(var.set_reset_pin(config[CONF_RESET_PIN])) - cg.add(var.set_tx_pin(config[CONF_TX_PIN])) - cg.add(var.set_rx_pin(config[CONF_RX_PIN])) - cg.add(var.set_apn(config[CONF_APN])) - cg.add(var.set_tx_buffer_size(config[CONF_TX_BUFFER_SIZE])) - cg.add(var.set_rx_buffer_size(config[CONF_RX_BUFFER_SIZE])) - cg.add(var.set_uart_event_task_stack_size(config[CONF_UART_EVENT_TASK_STACK_SIZE])) - cg.add(var.set_uart_event_task_priority(config[CONF_UART_EVENT_TASK_PRIORITY])) - cg.add(var.set_uart_event_queue_size([CONF_UART_EVENT_QUEUE_SIZE])) - cg.add(var.set_use_address(config[CONF_USE_ADDRESS])) - - # if CONF_POWER_PIN in config: - # cg.add(var.set_power_pin(config[CONF_POWER_PIN])) cg.add_define("USE_MODEM") diff --git a/esphome/components/modem/modem_component.cpp b/esphome/components/modem/modem_component.cpp index e053c61229..3f9ff0a664 100644 --- a/esphome/components/modem/modem_component.cpp +++ b/esphome/components/modem/modem_component.cpp @@ -67,15 +67,15 @@ void print_netif_flags(esp_netif_flags_t flags) { } #include "driver/gpio.h" -void esp_modem_hard_reset() +void ModemComponent::esp_modem_hard_reset() { - gpio_set_direction(GPIO_NUM_23, GPIO_MODE_OUTPUT); - //gpio_pullup_en(GPIO_NUM_23); - gpio_set_level(GPIO_NUM_23, 0); - ESP_LOGD(TAG, "GPIO_NUM_23 0"); + 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); + ESP_LOGD(TAG, "reset_pin_ 0"); vTaskDelay(50); - gpio_set_level(GPIO_NUM_23, 1); - ESP_LOGD(TAG, "GPIO_NUM_23 1"); + gpio_set_level(gpio_num_t(this->reset_pin_), 1); + ESP_LOGD(TAG, "reset_pin_ 1"); vTaskDelay(2000); time_hard_reset_modem = millis(); } @@ -366,6 +366,7 @@ bool ModemComponent::is_connected() { return this->state_ == ModemComponentState void ModemComponent::set_power_pin(int 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; } std::string ModemComponent::get_use_address() const { diff --git a/esphome/components/modem/modem_component.h b/esphome/components/modem/modem_component.h index 456c62c0c4..84d342ae80 100644 --- a/esphome/components/modem/modem_component.h +++ b/esphome/components/modem/modem_component.h @@ -46,6 +46,7 @@ class ModemComponent : public Component { void set_power_pin(int power_pin); void set_type(ModemType type); + void set_reset_pin(int reset_pin); //void set_clk_mode(emac_rmii_clock_mode_t clk_mode, emac_rmii_clock_gpio_t clk_gpio); //void set_manual_ip(const ManualIP &manual_ip); @@ -59,9 +60,11 @@ class ModemComponent : public Component { static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); void start_connect_(); + void esp_modem_hard_reset(); std::string use_address_; int power_pin_{-1}; + int reset_pin_{-1}; ModemType type_{MODEM_TYPE_UNKNOWN}; optional manual_ip_{};