diff --git a/components/console/esp_console.h b/components/console/esp_console.h index 66349d2f8..1409bfe5b 100644 --- a/components/console/esp_console.h +++ b/components/console/esp_console.h @@ -18,6 +18,7 @@ extern "C" { #endif #include +#include "sdkconfig.h" #include "esp_err.h" // Forward declaration. Definition in linenoise/linenoise.h. @@ -55,19 +56,59 @@ typedef struct { uint32_t task_stack_size; //!< repl task stack size uint32_t task_priority; //!< repl task priority const char *prompt; //!< prompt (NULL represents default: "esp> ") + union { + struct { + int channel; //!< UART channel + uint32_t baud_rate; //!< Comunication baud rate + int tx_gpio; //!< GPIO number for TX path, -1 means using the default + int rx_gpio; //!< GPIO number for RX path, -1 means using the default + } uart; //!< UART specific configuration + } device; //!< device configuration } esp_console_repl_config_t; +#ifdef CONFIG_ESP_CONSOLE_UART_NUM +#define CONSOLE_DEFAULT_UART_CHANNEL CONFIG_ESP_CONSOLE_UART_NUM +#else +#define CONSOLE_DEFAULT_UART_CHANNEL 0 +#endif + +#ifdef CONFIG_ESP_CONSOLE_UART_BAUDRATE +#define CONSOLE_DEFAULT_UART_BAUDRATE CONFIG_ESP_CONSOLE_UART_BAUDRATE +#else +#define CONSOLE_DEFAULT_UART_BAUDRATE 115200 +#endif + +#ifdef CONFIG_ESP_CONSOLE_UART_TX_GPIO +#define CONSOLE_DEFAULT_UART_TX_GPIO CONFIG_ESP_CONSOLE_UART_TX_GPIO +#else +#define CONSOLE_DEFAULT_UART_TX_GPIO 1 +#endif + +#ifdef CONFIG_ESP_CONSOLE_UART_RX_GPIO +#define CONSOLE_DEFAULT_UART_RX_GPIO CONFIG_ESP_CONSOLE_UART_RX_GPIO +#else +#define CONSOLE_DEFAULT_UART_RX_GPIO 3 +#endif + /** * @brief Default console repl configuration value * */ -#define ESP_CONSOLE_REPL_CONFIG_DEFAULT() \ - { \ - .max_history_len = 32, \ - .history_save_path = NULL, \ - .task_stack_size = 4096, \ - .task_priority = 2, \ - .prompt = NULL, \ +#define ESP_CONSOLE_REPL_CONFIG_DEFAULT() \ + { \ + .max_history_len = 32, \ + .history_save_path = NULL, \ + .task_stack_size = 4096, \ + .task_priority = 2, \ + .prompt = NULL, \ + .device = { \ + .uart = { \ + .channel = CONSOLE_DEFAULT_UART_CHANNEL, \ + .baud_rate = CONSOLE_DEFAULT_UART_BAUDRATE, \ + .tx_gpio = CONSOLE_DEFAULT_UART_TX_GPIO, \ + .rx_gpio = CONSOLE_DEFAULT_UART_RX_GPIO, \ + } \ + } \ } /** @@ -232,6 +273,8 @@ esp_err_t esp_console_register_help_command(void); /** * @brief Initialize console REPL environment * + * @param config REPL configuration + * * @note This is a all-in-one function to establish the environment needed for REPL, includes: * - Install the UART driver on the console UART (8n1, 115200, REF_TICK clock source) * - Configures the stdin/stdout to go through the UART driver diff --git a/components/console/esp_console_repl.c b/components/console/esp_console_repl.c index 6addf5d64..39e8d2d14 100644 --- a/components/console/esp_console_repl.c +++ b/components/console/esp_console_repl.c @@ -48,6 +48,12 @@ static char s_prompt[CONSOLE_PROMPT_LEN_MAX]; */ static const char *s_history_save_path = NULL; +/** + * @brief default uart channel number + * + */ +static int s_uart_channel = -1; + /** * @brief REPL task handle * @@ -122,21 +128,23 @@ esp_err_t esp_console_repl_init(const esp_console_repl_config_t *config) * correct while APB frequency is changing in light sleep mode. */ const uart_config_t uart_config = { - .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE, + .baud_rate = config->device.uart.baud_rate, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .source_clk = UART_SCLK_REF_TICK, }; /* Install UART driver for interrupt-driven reads and writes */ - ret = uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0); + ret = uart_driver_install(config->device.uart.channel, 256, 0, 0, NULL, 0); if (ret != ESP_OK) { goto _exit; } - uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config); + s_uart_channel = config->device.uart.channel; + uart_param_config(s_uart_channel, &uart_config); + uart_set_pin(s_uart_channel, config->device.uart.tx_gpio, config->device.uart.rx_gpio, -1, -1); /* Tell VFS to use UART driver */ - esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM); + esp_vfs_dev_uart_use_driver(s_uart_channel); /* Initialize the console */ esp_console_config_t console_config = ESP_CONSOLE_CONFIG_DEFAULT(); @@ -220,8 +228,9 @@ esp_err_t esp_console_repl_init(const esp_console_repl_config_t *config) _console_del: esp_console_deinit(); - esp_vfs_dev_uart_use_nonblocking(CONFIG_ESP_CONSOLE_UART_NUM); - uart_driver_delete(CONFIG_ESP_CONSOLE_UART_NUM); + esp_vfs_dev_uart_use_nonblocking(s_uart_channel); + uart_driver_delete(s_uart_channel); + s_uart_channel = -1; s_repl_state = CONSOLE_REPL_STATE_DEINIT; _exit: return ret; @@ -240,8 +249,9 @@ esp_err_t esp_console_repl_deinit(void) s_repl_state = CONSOLE_REPL_STATE_DEINIT; esp_console_deinit(); - esp_vfs_dev_uart_use_nonblocking(CONFIG_ESP_CONSOLE_UART_NUM); - uart_driver_delete(CONFIG_ESP_CONSOLE_UART_NUM); + esp_vfs_dev_uart_use_nonblocking(s_uart_channel); + uart_driver_delete(s_uart_channel); + s_uart_channel = -1; s_repl_task_hdl = NULL; s_history_save_path = NULL; _exit: diff --git a/components/esp_eth/src/esp_eth.c b/components/esp_eth/src/esp_eth.c index 64025c4bd..17ab9a7e6 100644 --- a/components/esp_eth/src/esp_eth.c +++ b/components/esp_eth/src/esp_eth.c @@ -288,8 +288,8 @@ esp_err_t esp_eth_update_input_path( { esp_err_t ret = ESP_OK; esp_eth_driver_t *eth_driver = (esp_eth_driver_t *)hdl; - eth_driver->priv = priv; ETH_CHECK(eth_driver, "ethernet driver handle can't be null", err, ESP_ERR_INVALID_ARG); + eth_driver->priv = priv; eth_driver->stack_input = stack_input; return ESP_OK; err: diff --git a/examples/peripherals/i2c/i2c_tools/README.md b/examples/peripherals/i2c/i2c_tools/README.md index e79a95f79..24eaa35e2 100644 --- a/examples/peripherals/i2c/i2c_tools/README.md +++ b/examples/peripherals/i2c/i2c_tools/README.md @@ -159,7 +159,7 @@ esp32> i2cget -c 0x5b -r 0x00 -l 1 0x10 ``` -* `-c` option to specify the address of I2C device (acquired from `i2cetect` command). +* `-c` option to specify the address of I2C device (acquired from `i2cdetect` command). * `-r` option to specify the register address you want to inspect. * `-l` option to specify the length of the content. * Here the returned value 0x10 means that the sensor is just in the boot mode and is ready to go into application mode. For more information about CCS811 you should consult the [official website](http://ams.com/ccs811).