BLE_DCF_TYQ_CH592F/common/letter-shell/shell_port.c

76 lines
1.2 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @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 "bsp_uart.h"
#include "log.h"
#include "stdbool.h"
#include "shell_port.h"
Shell shell;
char shellBuffer[SHELL_BUF_LENGTH];
void Uart_Log_Write(char *buffer, short len);
// 定义log对象
Log uartLog = {
.write = Uart_Log_Write,
.active = LOG_ENABLE,
.level = LOG_ALL
};
/**
* @brief 用户shell写
*
* @param data 数据
* @param len 数据长度
*
* @return unsigned short 写入实际长度
*/
signed short userShellWrite(char *data, unsigned short len)
{
BSP_Uart1_Send_Data(data, len);
return len;
}
// 实现log写buffer函数
void Uart_Log_Write(char *buffer, short len)
{
if (uartLog.shell)
{
//
// log工具可以结合letter shell的尾行模式实现log和shell共用一个终端但不影响shell交互体验
shellWriteEndLine(uartLog.shell, buffer, len);
}
// UART1_SendString((uint8_t *)buffer, len);
}
/**
* @brief 用户shell初始化
*
*/
void SHELL_Init(void)
{
shell.write = userShellWrite;
shellInit(&shell, shellBuffer, SHELL_BUF_LENGTH);
logRegister(&uartLog, &shell);
}