-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
56 lines (41 loc) · 1.16 KB
/
main.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
#include "STM32X.h"
#include "Core.h"
#include "USB.h"
#include "Cmd.h"
// Test 1 expects an argument
static void Test1Function(Cmd_Line_t * line, Cmd_ArgValue_t * args)
{
Cmd_Printf(line, Cmd_Reply_Info, "Test 1: Value is %d\r\n", args[0].number);
}
static const Cmd_Arg_t gTest1Args[] = {
CMD_ARGUMENT(Cmd_Arg_Number, "input")
};
static const Cmd_Node_t gTest1Node = CMD_AFUNCTION("test-1", Test1Function, gTest1Args);
// Test 2 expects no arguments.
static void Test2Function(Cmd_Line_t * line, Cmd_ArgValue_t * args)
{
Cmd_Printf(line, Cmd_Reply_Info, "Test 2.\r\n");
}
static const Cmd_Node_t gTest2Node = CMD_FUNCTION("test-2", Test2Function);
// The menu contains both items
static const Cmd_Node_t * gRootItems[] = {
&gTest1Node,
&gTest2Node
};
static const Cmd_Node_t gRootMenu = CMD_MENU("root", gRootItems);
int main(void)
{
CORE_Init();
USB_Init();
uint8_t heap[256];
Cmd_Line_t line;
Cmd_Init(&line, &gRootMenu, USB_Write, heap, sizeof(heap));
line.cfg.echo = true;
while(1)
{
uint8_t bfr[64];
uint32_t count = USB_Read(bfr, sizeof(bfr));
Cmd_Parse(&line, bfr, count);
CORE_Idle();
}
}