Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ESP32Console/Commands/GPIOCommands.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "./GPIOCommands.h"
#include "Arduino.h"
#include <string>
#include <stdexcept>

static int _pinmode(int argc, char **argv)
{
Expand Down
2 changes: 2 additions & 0 deletions src/ESP32Console/Commands/NetworkCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ static void ipconfig_wlan()
printf("IP: %s\n", WiFi.localIP().toString().c_str());
printf("Subnet Mask: %s (/%d)\n", WiFi.subnetMask().toString().c_str(), WiFi.subnetCIDR());
printf("Gateway: %s\n", WiFi.gatewayIP().toString().c_str());
#if !defined(ESP_ARDUINO_VERSION_MAJOR) || ESP_ARDUINO_VERSION_MAJOR < 3
printf("IPv6: %s\n", WiFi.localIPv6().toString().c_str());
#endif

printf("\n");
printf("Hostname: %s\n", WiFi.getHostname());
Expand Down
17 changes: 16 additions & 1 deletion src/ESP32Console/Commands/SystemCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
#include <esp_partition.h>
#include <esp_ota_ops.h>
#include <esp_system.h>
#if __has_include(<esp_chip_info.h>)
#include <esp_chip_info.h>
#endif
#if __has_include(<core_version.h>)
#include <core_version.h>
#endif
#include <getopt.h>

// For XSTR macros
// For XTSTR macros (Xtensa-specific)
#if __has_include(<xtensa/xtruntime.h>)
#include <xtensa/xtruntime.h>
#else
// Provide a fallback stringification macro for non-Xtensa architectures (e.g. RISC-V)
#ifndef XTSTR
#define _XTSTR(x) #x
#define XTSTR(x) _XTSTR(x)
#endif
#endif

static String mac2String(uint64_t mac)
{
Expand Down Expand Up @@ -84,7 +97,9 @@ static int sysInfo(int argc, char **argv)
esp_chip_info(&info);

printf("ESP32Console version: %s\n", ESP32CONSOLE_VERSION);
#if defined(ARDUINO_ESP32_GIT_DESC)
printf("Arduino Core version: %s (%x)\n", XTSTR(ARDUINO_ESP32_GIT_DESC), ARDUINO_ESP32_GIT_VER);
#endif
printf("ESP-IDF Version: %s\n", ESP.getSdkVersion());

printf("\n");
Expand Down
17 changes: 16 additions & 1 deletion src/ESP32Console/Console.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include "./Console.h"
#include "soc/soc_caps.h"
#include "esp_err.h"
#include "esp_idf_version.h"
#include "ESP32Console/Commands/CoreCommands.h"
#include "ESP32Console/Commands/SystemCommands.h"
#include "ESP32Console/Commands/NetworkCommands.h"
#include "ESP32Console/Commands/VFSCommands.h"
#include "ESP32Console/Commands/GPIOCommands.h"
#include "driver/uart.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#include "driver/uart_vfs.h"
#else
#include "esp_vfs_dev.h"
#endif
#include "linenoise/linenoise.h"
#include "ESP32Console/Helpers/PWDHelpers.h"
#include "ESP32Console/Helpers/InputParser.h"
Expand Down Expand Up @@ -86,7 +91,7 @@ namespace ESP32Console
registerCoreCommands();
}

void Console::begin(int baud, int rxPin, int txPin, uint8_t channel)
void Console::begin(int baud, int rxPin, int txPin, uart_port_t channel)
{
log_d("Initialize console");

Expand All @@ -111,9 +116,15 @@ namespace ESP32Console
setvbuf(stdin, NULL, _IONBF, 0);

/* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uart_vfs_dev_port_set_rx_line_endings(channel, ESP_LINE_ENDINGS_CR);
/* Move the caret to the beginning of the next line on '\n' */
uart_vfs_dev_port_set_tx_line_endings(channel, ESP_LINE_ENDINGS_CRLF);
#else
esp_vfs_dev_uart_port_set_rx_line_endings(channel, ESP_LINE_ENDINGS_CR);
/* Move the caret to the beginning of the next line on '\n' */
esp_vfs_dev_uart_port_set_tx_line_endings(channel, ESP_LINE_ENDINGS_CRLF);
#endif

/* Configure UART. Note that REF_TICK is used so that the baud rate remains
* correct while APB frequency is changing in light sleep mode.
Expand Down Expand Up @@ -145,7 +156,11 @@ namespace ESP32Console
ESP_ERROR_CHECK(uart_driver_install(channel, 256, 0, 0, NULL, 0));

/* Tell VFS to use UART driver */
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
uart_vfs_dev_use_driver(channel);
#else
esp_vfs_dev_uart_use_driver(channel);
#endif

esp_console_config_t console_config = {
.max_cmdline_length = max_cmdline_len_,
Expand Down
20 changes: 17 additions & 3 deletions src/ESP32Console/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "./ConsoleCommandBase.h"
#include "freertos/task.h"
#include "linenoise/linenoise.h"
#include "driver/uart.h"

namespace ESP32Console
{
Expand All @@ -25,7 +26,7 @@ namespace ESP32Console
const size_t max_cmdline_len_;
const size_t max_cmdline_args_;

uint8_t uart_channel_;
uart_port_t uart_channel_;

TaskHandle_t task_;

Expand Down Expand Up @@ -142,9 +143,22 @@ namespace ESP32Console
* @param baud The baud rate with which the console should work. Recommended: 115200
* @param rxPin The pin to use for RX
* @param txPin The pin to use for TX
* @param channel The number of the UART to use
* @param channel The UART port to use
*/
void begin(int baud, int rxPin = -1, int txPin = -1, uint8_t channel = 0);
void begin(int baud, int rxPin = -1, int txPin = -1, uart_port_t channel = UART_NUM_0);

/**
* @brief Starts the console. Overload for backward compatibility with uint8_t channel argument.
*
* @param baud The baud rate with which the console should work. Recommended: 115200
* @param rxPin The pin to use for RX
* @param txPin The pin to use for TX
* @param channel The number of the UART to use (cast to uart_port_t)
*/
void begin(int baud, int rxPin, int txPin, uint8_t channel)
{
begin(baud, rxPin, txPin, static_cast<uart_port_t>(channel));
}

void end();
};
Expand Down