Move all firmware files to subdirectory

This commit is contained in:
2023-05-21 15:06:44 +01:00
parent 3d8ec33cd3
commit 8c957d043a
46 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
idf_component_register(
SRCS "console.c"
INCLUDE_DIRS "."
REQUIRES console system_utils
)

View File

@@ -0,0 +1,64 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) Camden Dixie O'Brien
*/
#include "console.h"
#include "system_utils.h"
#include "esp_console.h"
#include "esp_log.h"
#define TAG "Console"
static esp_console_repl_t *repl;
static int reboot_command_func(int argc, char **argv)
{
(void)argc;
(void)argv;
reboot();
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);
}

View File

@@ -0,0 +1,25 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) Camden Dixie O'Brien
*/
#ifndef CONSOLE_H
#define CONSOLE_H
typedef int (*CommandFunc)(int argc, char **argv);
/**
* Initialize and start the console.
*/
void console_init(void);
/**
* Register a console command.
*
* The name, help and hint should all be null-terminated strings. Hint
* should list possible arguments.
*/
void console_register(
const char *name, const char *help, const char *hint, CommandFunc func);
#endif