1
0
mirror of https://github.com/NevermindZZT/letter-shell.git synced 2025-01-21 10:02:54 +08:00
letter-shell/demo/esp-idf/shell_port.c
Letter 1624e4835c 新增 支持在程序中调用接口直接运行命令
新增 支持在程序中调用接口直接运行命令
修复 直接运行未导出命令时,参数错误时的错误处理
2020-07-14 22:15:03 +08:00

67 lines
1.2 KiB
C

/**
* @file shell_port.c
* @author Letter (NevermindZZT@gmail.com)
* @brief
* @version 0.1
* @date 2019-02-22
*
* @copyright (c) 2019 Letter
*
*/
#include "shell.h"
#include "freertos/FreeRTOS.h"
#include "driver/uart.h"
#define SHELL_UART UART_NUM_0
Shell shell;
char shellBuffer[512];
/**
* @brief 用户shell写
*
* @param data 数据
*/
void userShellWrite(char data)
{
uart_write_bytes(SHELL_UART, (const char *)&data, 1);
}
/**
* @brief 用户shell读
*
* @param data 数据
* @return char 状态
*/
signed char userShellRead(char *data)
{
return (uart_read_bytes(SHELL_UART, (uint8_t *)data, 1, portMAX_DELAY) == 1)
? 0 : -1;
}
/**
* @brief 用户shell初始化
*
*/
void userShellInit(void)
{
uart_config_t uartConfig = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
uart_param_config(SHELL_UART, &uartConfig);
uart_driver_install(SHELL_UART, 256 * 2, 0, 0, NULL, 0);
shell.write = userShellWrite;
shell.read = userShellRead;
shellInit(&shell, shellBuffer, 512);
}