diff --git a/src/ESP32Console/Commands/GPIOCommands.cpp b/src/ESP32Console/Commands/GPIOCommands.cpp index 4a335be..ef048e5 100644 --- a/src/ESP32Console/Commands/GPIOCommands.cpp +++ b/src/ESP32Console/Commands/GPIOCommands.cpp @@ -1,5 +1,7 @@ #include "./GPIOCommands.h" #include "Arduino.h" +#include +#include static int _pinmode(int argc, char **argv) { diff --git a/src/ESP32Console/Commands/NetworkCommands.cpp b/src/ESP32Console/Commands/NetworkCommands.cpp index fdb5c7b..60e4eee 100644 --- a/src/ESP32Console/Commands/NetworkCommands.cpp +++ b/src/ESP32Console/Commands/NetworkCommands.cpp @@ -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()); diff --git a/src/ESP32Console/Commands/SystemCommands.cpp b/src/ESP32Console/Commands/SystemCommands.cpp index ec619cf..153868e 100644 --- a/src/ESP32Console/Commands/SystemCommands.cpp +++ b/src/ESP32Console/Commands/SystemCommands.cpp @@ -4,11 +4,24 @@ #include #include #include +#if __has_include() +#include +#endif +#if __has_include() #include +#endif #include -// For XSTR macros +// For XTSTR macros (Xtensa-specific) +#if __has_include() #include +#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) { @@ -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"); diff --git a/src/ESP32Console/Console.cpp b/src/ESP32Console/Console.cpp index 558e10a..e7df91b 100644 --- a/src/ESP32Console/Console.cpp +++ b/src/ESP32Console/Console.cpp @@ -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" @@ -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"); @@ -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. @@ -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_, diff --git a/src/ESP32Console/Console.h b/src/ESP32Console/Console.h index 6d3ff3a..49b915c 100644 --- a/src/ESP32Console/Console.h +++ b/src/ESP32Console/Console.h @@ -9,6 +9,7 @@ #include "./ConsoleCommandBase.h" #include "freertos/task.h" #include "linenoise/linenoise.h" +#include "driver/uart.h" namespace ESP32Console { @@ -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_; @@ -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(channel)); + } void end(); };