@@ -56,60 +56,49 @@ typedef struct {
56
56
uint32_t task_stack_size ; //!< repl task stack size
57
57
uint32_t task_priority ; //!< repl task priority
58
58
const char * prompt ; //!< prompt (NULL represents default: "esp> ")
59
- union {
60
- struct {
61
- int channel ; //!< UART channel
62
- uint32_t baud_rate ; //!< Comunication baud rate
63
- int tx_gpio ; //!< GPIO number for TX path, -1 means using the default
64
- int rx_gpio ; //!< GPIO number for RX path, -1 means using the default
65
- } uart ; //!< UART specific configuration
66
- } device ; //!< device configuration
67
59
} esp_console_repl_config_t ;
68
60
69
- #ifdef CONFIG_ESP_CONSOLE_UART_NUM
70
- #define CONSOLE_DEFAULT_UART_CHANNEL CONFIG_ESP_CONSOLE_UART_NUM
71
- #else
72
- #define CONSOLE_DEFAULT_UART_CHANNEL 0
73
- #endif
74
-
75
- #ifdef CONFIG_ESP_CONSOLE_UART_BAUDRATE
76
- #define CONSOLE_DEFAULT_UART_BAUDRATE CONFIG_ESP_CONSOLE_UART_BAUDRATE
77
- #else
78
- #define CONSOLE_DEFAULT_UART_BAUDRATE 115200
79
- #endif
80
-
81
- #ifdef CONFIG_ESP_CONSOLE_UART_TX_GPIO
82
- #define CONSOLE_DEFAULT_UART_TX_GPIO CONFIG_ESP_CONSOLE_UART_TX_GPIO
83
- #else
84
- #define CONSOLE_DEFAULT_UART_TX_GPIO 1
85
- #endif
86
-
87
- #ifdef CONFIG_ESP_CONSOLE_UART_RX_GPIO
88
- #define CONSOLE_DEFAULT_UART_RX_GPIO CONFIG_ESP_CONSOLE_UART_RX_GPIO
89
- #else
90
- #define CONSOLE_DEFAULT_UART_RX_GPIO 3
91
- #endif
92
-
93
61
/**
94
62
* @brief Default console repl configuration value
95
63
*
96
64
*/
97
- #define ESP_CONSOLE_REPL_CONFIG_DEFAULT () \
98
- { \
99
- .max_history_len = 32, \
100
- .history_save_path = NULL, \
101
- .task_stack_size = 4096, \
102
- .task_priority = 2, \
103
- .prompt = NULL, \
104
- .device = { \
105
- .uart = { \
106
- .channel = CONSOLE_DEFAULT_UART_CHANNEL, \
107
- .baud_rate = CONSOLE_DEFAULT_UART_BAUDRATE, \
108
- .tx_gpio = CONSOLE_DEFAULT_UART_TX_GPIO, \
109
- .rx_gpio = CONSOLE_DEFAULT_UART_RX_GPIO, \
110
- } \
111
- } \
112
- }
65
+ #define ESP_CONSOLE_REPL_CONFIG_DEFAULT () \
66
+ { \
67
+ .max_history_len = 32, \
68
+ .history_save_path = NULL, \
69
+ .task_stack_size = 4096, \
70
+ .task_priority = 2, \
71
+ .prompt = NULL, \
72
+ }
73
+
74
+ /**
75
+ * @brief Parameters for console device: UART
76
+ *
77
+ */
78
+ typedef struct {
79
+ int channel ; //!< UART channel number (count from zero)
80
+ int baud_rate ; //!< Comunication baud rate
81
+ int tx_gpio_num ; //!< GPIO number for TX path, -1 means using default one
82
+ int rx_gpio_num ; //!< GPIO number for RX path, -1 means using default one
83
+ } esp_console_dev_uart_config_t ;
84
+
85
+ #ifdef CONFIG_ESP_CONSOLE_UART_CUSTOM
86
+ #define ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT () \
87
+ { \
88
+ .channel = CONFIG_ESP_CONSOLE_UART_NUM, \
89
+ .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE, \
90
+ .tx_gpio_num = CONFIG_ESP_CONSOLE_UART_TX_GPIO, \
91
+ .rx_gpio_num = CONFIG_ESP_CONSOLE_UART_RX_GPIO, \
92
+ }
93
+ #else
94
+ #define ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT () \
95
+ { \
96
+ .channel = CONFIG_ESP_CONSOLE_UART_NUM, \
97
+ .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE, \
98
+ .tx_gpio_num = -1, \
99
+ .rx_gpio_num = -1, \
100
+ }
101
+ #endif
113
102
114
103
/**
115
104
* @brief initialize console module
@@ -270,10 +259,34 @@ esp_err_t esp_console_register_help_command(void);
270
259
/******************************************************************************
271
260
* Console REPL
272
261
******************************************************************************/
262
+
273
263
/**
274
- * @brief Initialize console REPL environment
264
+ * @brief Type defined for console REPL
275
265
*
276
- * @param config REPL configuration
266
+ */
267
+ typedef struct esp_console_repl_s esp_console_repl_t ;
268
+
269
+ /**
270
+ * @brief Console REPL base structure
271
+ *
272
+ */
273
+ struct esp_console_repl_s {
274
+ /**
275
+ * @brief Delete console REPL environment
276
+ * @param[in] repl REPL handle returned from esp_console_new_repl_xxx
277
+ * @return
278
+ * - ESP_OK on success
279
+ * - ESP_FAIL on errors
280
+ */
281
+ esp_err_t (* del )(esp_console_repl_t * repl );
282
+ };
283
+
284
+ /**
285
+ * @brief Establish a console REPL environment over UART driver
286
+ *
287
+ * @param[in] dev_config UART device configuration
288
+ * @param[in] repl_config REPL configuration
289
+ * @param[out] ret_repl return REPL handle after initialization succeed, return NULL otherwise
277
290
*
278
291
* @note This is a all-in-one function to establish the environment needed for REPL, includes:
279
292
* - Install the UART driver on the console UART (8n1, 115200, REF_TICK clock source)
@@ -289,27 +302,17 @@ esp_err_t esp_console_register_help_command(void);
289
302
* - ESP_OK on success
290
303
* - ESP_FAIL Parameter error
291
304
*/
292
- esp_err_t esp_console_repl_init (const esp_console_repl_config_t * config );
305
+ 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 );
293
306
294
307
/**
295
- * @brief Start REPL task
296
- *
308
+ * @brief Start REPL environment
309
+ * @param[in] repl REPL handle returned from esp_console_new_repl_xxx
310
+ * @note Once the REPL got started, it won't be stopped until user call repl->del(repl) to destory the REPL environment.
297
311
* @return
298
312
* - ESP_OK on success
299
313
* - ESP_ERR_INVALID_STATE, if repl has started already
300
314
*/
301
- esp_err_t esp_console_repl_start (void );
302
-
303
- /**
304
- * @brief Register a 'quit' command
305
- *
306
- * Default 'quit' command will destory resources and exit REPL environment.
307
- *
308
- * @return
309
- * - ESP_OK on success
310
- * - others on failed
311
- */
312
- esp_err_t esp_console_register_quit_command (void );
315
+ esp_err_t esp_console_start_repl (esp_console_repl_t * repl );
313
316
314
317
#ifdef __cplusplus
315
318
}
0 commit comments