1 /* Copyright (C) 2014 by Jacob Alexander
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
25 // ----- Includes -----
28 #include <Lib/MainLib.h>
31 #include <output_com.h>
34 // ----- Defines -----
36 #define CLILineBufferMaxSize 100
37 #define CLIMaxDictionaries 5
38 #define CLIEntryTabAlign 13
44 // AVR CLI Dictionary definitions (has to deal with the annoying PROGMEM
45 // Only using PROGMEM with descriptions (all the string comparison tools need to be re-written otherwise)
46 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
47 #define CLIDict_Def(name,description) \
48 const PROGMEM char name##Name[] = description; \
49 const CLIDictItem name[]
51 #define CLIDict_Item(name) \
52 { #name, name##CLIDict_DescEntry, (const void (*)(char*))cliFunc_##name }
54 #define CLIDict_Entry(name,description) \
55 const PROGMEM char name##CLIDict_DescEntry[] = description;
58 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
59 #define CLIDict_Def(name,description) \
60 const char name##Name[] = description; \
61 const CLIDictItem name[]
63 #define CLIDict_Item(name) \
64 { #name, name##CLIDict_DescEntry, (const void (*)(char*))cliFunc_##name }
66 #define CLIDict_Entry(name,description) \
67 const char name##CLIDict_DescEntry[] = description;
72 // ----- Structs -----
74 // Each item has a name, description, and function pointer with an argument for arguments
75 typedef struct CLIDictItem {
77 const char* description;
78 const void (*function)(char*);
83 // ----- Variables -----
85 char CLILineBuffer[CLILineBufferMaxSize+1]; // +1 for an additional NULL
86 uint8_t CLILineBufferCurrent;
88 // Main command dictionary
89 CLIDictItem *CLIDict [CLIMaxDictionaries];
90 char* CLIDictNames[CLIMaxDictionaries];
91 uint8_t CLIDictionariesUsed;
94 uint8_t CLIHexDebugMode;
98 // ----- Functions and Corresponding Function Aliases -----
102 void CLI_registerDictionary( const CLIDictItem *cmdDict, const char* dictName );
103 void CLI_argumentIsolation( char* string, char** first, char** second );
105 void CLI_commandLookup();
106 void CLI_tabCompletion();
108 // CLI Command Functions
109 void cliFunc_arch ( char* args );
110 void cliFunc_chip ( char* args );
111 void cliFunc_cliDebug( char* args );
112 void cliFunc_device ( char* args );
113 void cliFunc_help ( char* args );
114 void cliFunc_led ( char* args );
115 void cliFunc_reload ( char* args );
116 void cliFunc_reset ( char* args );
117 void cliFunc_restart ( char* args );
118 void cliFunc_version ( char* args );