diff --git a/components/console/esp_console.h b/components/console/esp_console.h index cd7bf8155e..cfc75a2f6c 100644 --- a/components/console/esp_console.h +++ b/components/console/esp_console.h @@ -65,6 +65,7 @@ typedef struct { .max_cmdline_length = 0, \ } +#if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM /** * @brief Parameters for console device: UART * @@ -76,7 +77,7 @@ typedef struct { int rx_gpio_num; //!< GPIO number for RX path, -1 means using default one } esp_console_dev_uart_config_t; -#ifdef CONFIG_ESP_CONSOLE_UART_CUSTOM +#if CONFIG_ESP_CONSOLE_UART_CUSTOM #define ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT() \ { \ .channel = CONFIG_ESP_CONSOLE_UART_NUM, \ @@ -92,8 +93,10 @@ typedef struct { .tx_gpio_num = -1, \ .rx_gpio_num = -1, \ } -#endif +#endif // CONFIG_ESP_CONSOLE_UART_CUSTOM +#endif // CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM +#if CONFIG_ESP_CONSOLE_USB_CDC || (defined __DOXYGEN__ && SOC_USB_OTG_SUPPORTED) /** * @brief Parameters for console device: USB CDC * @@ -104,11 +107,10 @@ typedef struct { } esp_console_dev_usb_cdc_config_t; -#define ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT() \ -{ \ -} +#define ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT() {} +#endif // CONFIG_ESP_CONSOLE_USB_CDC || (defined __DOXYGEN__ && SOC_USB_OTG_SUPPORTED) -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED) /** * @brief Parameters for console device: USB-SERIAL-JTAG * @@ -120,8 +122,7 @@ typedef struct { } esp_console_dev_usb_serial_jtag_config_t; #define ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT() {} - -#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED) /** * @brief initialize console module @@ -304,6 +305,7 @@ struct esp_console_repl_s { esp_err_t (*del)(esp_console_repl_t *repl); }; +#if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM /** * @brief Establish a console REPL environment over UART driver * @@ -326,7 +328,9 @@ struct esp_console_repl_s { * - ESP_FAIL Parameter error */ esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl); +#endif // CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM +#if CONFIG_ESP_CONSOLE_USB_CDC || (defined __DOXYGEN__ && SOC_USB_OTG_SUPPORTED) /** * @brief Establish a console REPL environment over USB CDC * @@ -347,8 +351,9 @@ esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_con * - ESP_FAIL Parameter error */ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl); +#endif // CONFIG_ESP_CONSOLE_USB_CDC || (defined __DOXYGEN__ && SOC_USB_OTG_SUPPORTED) -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED) /** * @brief Establish a console REPL (Read-eval-print loop) environment over USB-SERIAL-JTAG * @@ -369,7 +374,7 @@ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *d * - ESP_FAIL Parameter error */ esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_jtag_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl); -#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED) /** * @brief Start REPL environment diff --git a/components/console/esp_console_repl.c b/components/console/esp_console_repl.c index f656cee91f..7cee440e5f 100644 --- a/components/console/esp_console_repl.c +++ b/components/console/esp_console_repl.c @@ -47,8 +47,12 @@ typedef struct { } esp_console_repl_universal_t; static void esp_console_repl_task(void *args); +#if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM static esp_err_t esp_console_repl_uart_delete(esp_console_repl_t *repl); +#endif // CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM +#if CONFIG_ESP_CONSOLE_USB_CDC static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl); +#endif // CONFIG_ESP_CONSOLE_USB_CDC #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl); #endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG @@ -56,6 +60,7 @@ static esp_err_t esp_console_common_init(size_t max_cmdline_length, esp_console_ static esp_err_t esp_console_setup_prompt(const char *prompt, esp_console_repl_com_t *repl_com); static esp_err_t esp_console_setup_history(const char *history_path, uint32_t max_history_len, esp_console_repl_com_t *repl_com); +#if CONFIG_ESP_CONSOLE_USB_CDC esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl) { esp_err_t ret = ESP_OK; @@ -119,6 +124,7 @@ _exit: } return ret; } +#endif // CONFIG_ESP_CONSOLE_USB_CDC #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_jtag_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl) @@ -200,6 +206,7 @@ _exit: } #endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl) { esp_err_t ret = ESP_OK; @@ -300,6 +307,7 @@ _exit: } return ret; } +#endif // CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM esp_err_t esp_console_start_repl(esp_console_repl_t *repl) { @@ -404,6 +412,7 @@ _exit: return ret; } +#if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM static esp_err_t esp_console_repl_uart_delete(esp_console_repl_t *repl) { esp_err_t ret = ESP_OK; @@ -423,7 +432,9 @@ static esp_err_t esp_console_repl_uart_delete(esp_console_repl_t *repl) _exit: return ret; } +#endif // CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM +#if CONFIG_ESP_CONSOLE_USB_CDC static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl) { esp_err_t ret = ESP_OK; @@ -441,6 +452,7 @@ static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl) _exit: return ret; } +#endif // CONFIG_ESP_CONSOLE_USB_CDC #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl) diff --git a/examples/system/console/advanced/main/console_example_main.c b/examples/system/console/advanced/main/console_example_main.c index 67618495d5..c7a5a3241b 100644 --- a/examples/system/console/advanced/main/console_example_main.c +++ b/examples/system/console/advanced/main/console_example_main.c @@ -27,6 +27,10 @@ #error This example is incompatible with USB CDC console. Please try "console_usb" example instead. #endif // CONFIG_ESP_CONSOLE_USB_CDC +#ifdef CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#error This example is incompatible with USB serial JTAG console. +#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG + static const char* TAG = "example"; #define PROMPT_STR CONFIG_IDF_TARGET diff --git a/examples/wifi/ftm/main/ftm_main.c b/examples/wifi/ftm/main/ftm_main.c index 1647fa40b4..e666c345b2 100644 --- a/examples/wifi/ftm/main/ftm_main.c +++ b/examples/wifi/ftm/main/ftm_main.c @@ -618,10 +618,24 @@ void app_main(void) esp_console_repl_t *repl = NULL; esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); - esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); + repl_config.prompt = "ftm>"; - // init console REPL environment + +#if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) || defined(CONFIG_ESP_CONSOLE_UART_CUSTOM) + esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl)); + +#elif defined(CONFIG_ESP_CONSOLE_USB_CDC) + esp_console_dev_usb_cdc_config_t hw_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT(); + ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&hw_config, &repl_config, &repl)); + +#elif defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) + esp_console_dev_usb_serial_jtag_config_t hw_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT(); + ESP_ERROR_CHECK(esp_console_new_repl_usb_serial_jtag(&hw_config, &repl_config, &repl)); +#else +#error Unsupported console type +#endif + /* Register commands */ register_system(); register_wifi();