]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Debug/cli/cli.h
Code cleanup
[kiibohd-controller.git] / Debug / cli / cli.h
1 /* Copyright (C) 2014-2015 by Jacob Alexander
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  */
21
22 #pragma once
23
24 // ----- Includes -----
25
26 // Compiler Includes
27 #include <Lib/MainLib.h>
28
29 // Project Includes
30 #include <output_com.h>
31
32
33 // ----- Defines -----
34
35 #define CLILineBufferMaxSize 100
36 #define CLIMaxDictionaries   10
37 #define CLIEntryTabAlign     13
38 #define CLIMaxHistorySize    10
39
40
41 // ----- Macros -----
42
43 // AVR CLI Dictionary definitions (has to deal with the annoying PROGMEM
44 // Only using PROGMEM with descriptions (all the string comparison tools need to be re-written otherwise)
45 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
46 #define CLIDict_Def(name,description) \
47         const PROGMEM char name##Name[] = description; \
48         const CLIDictItem name[]
49
50 #define CLIDict_Item(name) \
51         { #name, name##CLIDict_DescEntry, (const void (*)(char*))cliFunc_##name }
52
53 #define CLIDict_Entry(name,description) \
54         const PROGMEM char name##CLIDict_DescEntry[] = description;
55
56 // ARM is easy :P
57 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
58 #define CLIDict_Def(name,description) \
59         const char name##Name[] = description; \
60         const CLIDictItem name[]
61
62 #define CLIDict_Item(name) \
63         { #name, name##CLIDict_DescEntry, (const void (*)(char*))cliFunc_##name }
64
65 #define CLIDict_Entry(name,description) \
66         const char name##CLIDict_DescEntry[] = description;
67 #endif
68
69 #define RING_PREV(i) CLI_wrap(i - 1, 0, CLIMaxHistorySize - 1)
70 #define RING_NEXT(i) CLI_wrap(i + 1, 0, CLIMaxHistorySize - 1)
71
72
73 // ----- Structs -----
74
75 // Each item has a name, description, and function pointer with an argument for arguments
76 typedef struct CLIDictItem {
77         const char*  name;
78         const char*  description;
79         const void (*function)(char*);
80 } CLIDictItem;
81
82
83
84 // ----- Variables -----
85
86 char    CLILineBuffer[CLILineBufferMaxSize+1]; // +1 for an additional NULL
87 uint8_t CLILineBufferCurrent;
88
89 // Main command dictionary
90 CLIDictItem *CLIDict     [CLIMaxDictionaries];
91 char*        CLIDictNames[CLIMaxDictionaries];
92 uint8_t      CLIDictionariesUsed;
93
94 // History
95 char CLIHistoryBuffer[CLIMaxHistorySize][CLILineBufferMaxSize];
96 uint8_t CLIHistoryHead;
97 uint8_t CLIHistoryTail;
98 int8_t CLIHistoryCurrent;
99
100 // Debug
101 uint8_t CLILEDState;
102 uint8_t CLIHexDebugMode;
103
104
105
106 // ----- Functions and Corresponding Function Aliases -----
107
108 void CLI_init();
109 void CLI_process();
110 void CLI_registerDictionary( const CLIDictItem *cmdDict, const char* dictName );
111 void CLI_argumentIsolation( char* string, char** first, char** second );
112
113 int CLI_wrap( int x, int low, int high );
114 void CLI_commandLookup();
115 void CLI_tabCompletion();
116 void CLI_saveHistory( char *buff );
117 void CLI_retreiveHistory( int index );
118
119 // CLI Command Functions
120 void cliFunc_arch    ( char* args );
121 void cliFunc_chip    ( char* args );
122 void cliFunc_clear   ( char* args );
123 void cliFunc_cliDebug( char* args );
124 void cliFunc_device  ( char* args );
125 void cliFunc_help    ( char* args );
126 void cliFunc_led     ( char* args );
127 void cliFunc_reload  ( char* args );
128 void cliFunc_reset   ( char* args );
129 void cliFunc_restart ( char* args );
130 void cliFunc_version ( char* args );
131