18
18
#include < lib/shell/Engine.h>
19
19
#include < lib/shell/streamer.h>
20
20
21
- #include " driver/uart.h"
22
21
#include " esp_console.h"
23
22
#include " esp_vfs_dev.h"
24
23
#include " linenoise/linenoise.h"
25
24
#include < fcntl.h>
26
25
#include < lib/core/CHIPError.h>
27
26
#include < stdio.h>
28
27
#include < string.h>
28
+ #if CONFIG_ESP_CONSOLE_UART_DEFAULT
29
+ #include " driver/uart.h"
30
+ #endif
31
+ #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
32
+ #include " driver/usb_serial_jtag.h"
33
+ #include " esp_vfs_usb_serial_jtag.h"
34
+ #endif
29
35
30
36
namespace chip {
31
37
namespace Shell {
@@ -49,6 +55,7 @@ int streamer_esp32_init(streamer_t * streamer)
49
55
fflush (stdout);
50
56
fsync (fileno (stdout));
51
57
setvbuf (stdin, NULL , _IONBF, 0 );
58
+ #if CONFIG_ESP_CONSOLE_UART_DEFAULT
52
59
esp_vfs_dev_uart_port_set_rx_line_endings (CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
53
60
esp_vfs_dev_uart_port_set_tx_line_endings (CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
54
61
if (!uart_is_driver_installed (CONFIG_ESP_CONSOLE_UART_NUM))
@@ -70,6 +77,23 @@ int streamer_esp32_init(streamer_t * streamer)
70
77
};
71
78
ESP_ERROR_CHECK (uart_param_config (CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
72
79
esp_vfs_dev_uart_use_driver (0 );
80
+ #endif // CONFIG_ESP_CONSOLE_UART_DEFAULT
81
+
82
+ #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
83
+ esp_vfs_dev_usb_serial_jtag_set_rx_line_endings (ESP_LINE_ENDINGS_CR);
84
+ esp_vfs_dev_usb_serial_jtag_set_tx_line_endings (ESP_LINE_ENDINGS_CRLF);
85
+
86
+ fcntl (fileno (stdout), F_SETFL, O_NONBLOCK);
87
+ fcntl (fileno (stdin), F_SETFL, O_NONBLOCK);
88
+
89
+ usb_serial_jtag_driver_config_t usb_serial_jtag_config = {
90
+ .tx_buffer_size = 256 ,
91
+ .rx_buffer_size = 256 ,
92
+ };
93
+ usb_serial_jtag_driver_install (&usb_serial_jtag_config);
94
+ esp_vfs_usb_serial_jtag_use_driver ();
95
+ esp_vfs_dev_uart_register ();
96
+ #endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
73
97
esp_console_config_t console_config = {
74
98
.max_cmdline_length = 256 ,
75
99
.max_cmdline_args = 32 ,
@@ -97,7 +121,12 @@ ssize_t streamer_esp32_read(streamer_t * streamer, char * buf, size_t len)
97
121
98
122
ssize_t streamer_esp32_write (streamer_t * streamer, const char * buf, size_t len)
99
123
{
124
+ #if CONFIG_ESP_CONSOLE_UART_DEFAULT
100
125
return uart_write_bytes (CONFIG_ESP_CONSOLE_UART_NUM, buf, len);
126
+ #endif
127
+ #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
128
+ return usb_serial_jtag_write_bytes (buf, len, 0 );
129
+ #endif
101
130
}
102
131
103
132
static streamer_t streamer_stdio = {
0 commit comments