using reset_pin from config

This commit is contained in:
Chelios 2024-10-02 10:27:37 +03:00
parent d8905417ba
commit d662f7995a
3 changed files with 25 additions and 22 deletions

View file

@ -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")

View file

@ -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 {

View file

@ -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<ManualIP> manual_ip_{};