2018-11-20 11:40:26 -05:00
|
|
|
/* Common functions for protocol examples, to configure stdin and stdout.
|
|
|
|
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "protocol_examples_common.h"
|
|
|
|
#include "esp_err.h"
|
2023-11-24 01:56:08 -05:00
|
|
|
#include "driver/uart_vfs.h"
|
2018-11-20 11:40:26 -05:00
|
|
|
#include "driver/uart.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
esp_err_t example_configure_stdin_stdout(void)
|
2018-11-20 11:40:26 -05:00
|
|
|
{
|
2022-07-03 03:24:39 -04:00
|
|
|
static bool configured = false;
|
|
|
|
if (configured) {
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
2018-11-20 11:40:26 -05:00
|
|
|
// Initialize VFS & UART so we can use std::cout/cin
|
|
|
|
setvbuf(stdin, NULL, _IONBF, 0);
|
|
|
|
/* Install UART driver for interrupt-driven reads and writes */
|
2019-04-30 06:51:55 -04:00
|
|
|
ESP_ERROR_CHECK( uart_driver_install( (uart_port_t)CONFIG_ESP_CONSOLE_UART_NUM,
|
2018-11-20 11:40:26 -05:00
|
|
|
256, 0, 0, NULL, 0) );
|
|
|
|
/* Tell VFS to use UART driver */
|
2023-11-24 01:56:08 -05:00
|
|
|
uart_vfs_dev_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
|
|
|
|
uart_vfs_dev_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
|
2018-11-20 11:40:26 -05:00
|
|
|
/* Move the caret to the beginning of the next line on '\n' */
|
2023-11-24 01:56:08 -05:00
|
|
|
uart_vfs_dev_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
|
2022-07-03 03:24:39 -04:00
|
|
|
configured = true;
|
2018-11-20 11:40:26 -05:00
|
|
|
return ESP_OK;
|
|
|
|
}
|