/* * SPDX-License-Identifier: AGPL-3.0-only * Copyright (c) Camden Dixie O'Brien */ #include "console.h" #include "esp_console.h" #include "esp_log.h" #include "esp_system.h" #define TAG "Console" static esp_console_repl_t *repl; static int reboot_command_func(int argc, char **argv) { (void)argc; (void)argv; (void)esp_restart(); return 0; } void console_init(void) { esp_err_t error; error = esp_console_register_help_command(); if (error != ESP_OK) ESP_LOGE(TAG, "Error registering help command: %04x", error); esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); repl_config.prompt = ">"; esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); error = esp_console_new_repl_uart(&uart_config, &repl_config, &repl); if (error != ESP_OK) { ESP_LOGE(TAG, "Error initializing console REPL: %04x", error); return; } error = esp_console_start_repl(repl); if (error != ESP_OK) ESP_LOGE(TAG, "Error starting console REPL: %04x", error); console_register( "reboot", "Reboot the system", "reboot", reboot_command_func); } void console_register( const char *name, const char *help, const char *hint, CommandFunc func) { const esp_console_cmd_t command = { .command = name, .help = help, .hint = hint, .func = func, }; const esp_err_t error = esp_console_cmd_register(&command); if (error != ESP_OK) ESP_LOGE(TAG, "Error registering command %s: %04x", name, error); }