forked from NevermindZZT/letter-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_port.c
91 lines (76 loc) · 1.47 KB
/
shell_port.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @file shell_port.c
* @author EtcFly ([email protected])
* @brief Portable interface for letter shell
* @version 1.0.0
* @date 2020-01-10
*
* @Copyright (c) 2019 Letter
*
*/
#include "stm32f1xx_hal.h"
#include "shell.h"
extern UART_HandleTypeDef huart2;
static SHELL_TypeDef *pDefault_shell;
static SHELL_TypeDef default_shell;
/**
* @brief shell底层写字节函数
*
* @param ch 待发送字节
* @return None
*/
static void shell_write_byte(char ch)
{
HAL_UART_Transmit(&huart2, (void *)&ch, 1, 1000);
}
/**
* @brief shell底层读字节函数
*
* @param ch 待读取字节指针
* @return
* -1: fail 0: success
*/
static signed char shell_read_byte(char *ch)
{
if (HAL_UART_Receive(&huart2, (void *)ch, 1, 50) != HAL_OK)
return -1;
return 0;
}
/**
* @brief shell组件初始化
*
* @param None
* @return
* -1: fail 0: success
*/
void shell_initAll(void)
{
default_shell.write = shell_write_byte;
default_shell.read = shell_read_byte;
pDefault_shell = &default_shell;
shellInit(pDefault_shell);
}
/**
* @brief 设置默认使用的shell
*
* @param shell 待设置的默认shell指针
* @return None
*/
void set_defaultShell(SHELL_TypeDef *shell)
{
if (NULL == shell)
{
return ;
}
pDefault_shell = (SHELL_TypeDef *)shell;
}
/**
* @brief 获取默认使用的shell指针
*
* @param None
* @return 默认使用的shell指针
*/
SHELL_TypeDef *get_default_shell(void)
{
return (void *)pDefault_shell;
}