annotate Scan/MD1/scan_loop.c @ 420:23a1868b4ac2

Adding dynamic USB power support - Each scan module now has a current change callback which passes the available current as a parameter - No longer attempts to use the max 500 mA immediately, starts with 100 mA then goes to 500 mA after enumeration - If enumeration fails due to bMaxPower of 500 mA, then attempt again at 100 mA (might also be possible to go even lower to 20 mA in certain cases) - Now working with the Apple Ipad (no over-power messages) - Fixed Wake-up behaviour on Apple Ipad (and likely other iOS devices) - More effecient set_feature/clear_feature handling (device handler) - Initial power handling via Interconnect (still needs work to get it more dynamic)
author Jacob Alexander <haata@kiibohd.com>
date Sun, 21 Feb 2016 19:56:52 -0800
parents 83cb0d4b57e3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
1 /* Copyright (C) 2014-2016 by Jacob Alexander
186
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
2 *
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
4 * of this software and associated documentation files (the "Software"), to deal
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
5 * in the Software without restriction, including without limitation the rights
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
7 * copies of the Software, and to permit persons to whom the Software is
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
8 * furnished to do so, subject to the following conditions:
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
9 *
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
10 * The above copyright notice and this permission notice shall be included in
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
11 * all copies or substantial portions of the Software.
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
12 *
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
19 * THE SOFTWARE.
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
20 */
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
21
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
22 // ----- Includes -----
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
23
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
24 // Compiler Includes
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
25 #include <Lib/ScanLib.h>
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
26
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
27 // Project Includes
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
28 #include <cli.h>
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
29 #include <led.h>
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
30 #include <print.h>
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
31 #include <matrix_scan.h>
256
98d1981f4dd3 Small typos
Jacob Alexander <haata@kiibohd.com>
parents: 239
diff changeset
32 #include <macro.h>
186
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
33
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
34 // Local Includes
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
35 #include "scan_loop.h"
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
36
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
37
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
39 // ----- Function Declarations -----
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
40
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
41 // CLI Functions
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
42 void cliFunc_echo( char* args );
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
43
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
44
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
45
186
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
46 // ----- Variables -----
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
47
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
48 // Scan Module command dictionary
239
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
49 CLIDict_Entry( echo, "Example command, echos the arguments." );
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
50
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
51 CLIDict_Def( scanCLIDict, "Scan Module Commands" ) = {
2a4c99da1276 HUGE AVR RAM optimization (~28%).
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
52 CLIDict_Item( echo ),
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
53 { 0, 0, 0 } // Null entry for dictionary end
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
54 };
186
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
55
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
56 // Number of scans since the last USB send
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
57 uint16_t Scan_scanCount = 0;
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
58
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
59
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
60
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
61 // ----- Functions -----
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
62
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
63 // Setup
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
64 inline void Scan_setup()
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
65 {
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
66 // Register Scan CLI dictionary
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
67 CLI_registerDictionary( scanCLIDict, scanCLIDictName );
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
68
186
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
69 // Setup GPIO pins for matrix scanning
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
70 Matrix_setup();
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
71
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
72 // Reset scan count
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
73 Scan_scanCount = 0;
186
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
74 }
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
75
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
76
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
77 // Main Detection Loop
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
78 inline uint8_t Scan_loop()
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
79 {
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
80 Matrix_scan( Scan_scanCount++ );
186
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
81
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
82 return 0;
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
83 }
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
84
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
85
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86 // Signal from Macro Module that all keys have been processed (that it knows about)
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
87 inline void Scan_finishedWithMacro( uint8_t sentKeys )
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
88 {
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
89 }
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
90
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
91
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
92 // Signal from Output Module that all keys have been processed (that it knows about)
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
93 inline void Scan_finishedWithOutput( uint8_t sentKeys )
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
94 {
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
95 // Reset scan loop indicator (resets each key debounce state)
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
96 // TODO should this occur after USB send or Macro processing?
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
97 Scan_scanCount = 0;
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
98 }
50702debf278 Initial MatrixARM implementation
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
99
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
100
363
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
101
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
102 // ----- Capabilities -----
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
103
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
104 // Custom capability examples
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
105 // Refer to kll.h in Macros/PartialMap for state and stateType information
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
106 void CustomAction_action1_capability( uint8_t state, uint8_t stateType, uint8_t *args )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
107 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
108 // Display capability name
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
109 // XXX This is required for debug cli to give you a list of capabilities
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
110 if ( stateType == 0xFF && state == 0xFF )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
111 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
112 print("CustomAction_action1_capability()");
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
113 return;
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
114 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
115
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
116 // Prints Action1 info message to the debug cli
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
117 info_print("Action1");
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
118 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
119
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
120 uint8_t CustomAction_blockHold_storage = 0;
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
121 void CustomAction_blockHold_capability( uint8_t state, uint8_t stateType, uint8_t *args )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
122 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
123 // Display capability name
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
124 if ( stateType == 0xFF && state == 0xFF )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
125 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
126 print("CustomAction_blockHold_capability(usbCode)");
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
127 return;
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
128 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
129
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
130 // Retrieve 8-bit argument
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
131 uint8_t key = args[0];
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
132
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
133 // We only care about normal keys
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
134 if ( stateType == 0x00 )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
135 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
136 // Block given key if we're in the "Press" or "Hold" state
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
137 if ( ( state == 0x01 || state == 0x02 )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
138 && CustomAction_blockHold_storage == 0 )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
139 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
140 CustomAction_blockHold_storage = key;
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
141 info_msg("Blocking Key: ");
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
142 printHex( key );
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
143 print( NL );
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
144 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
145 // Release if in the "Off" or "Release" state and we're blocking
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
146 else if ( ( state == 0x00 || state == 0x03 )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
147 && key == CustomAction_blockHold_storage )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
148 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
149 info_msg("Unblocking Key: ");
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
150 printHex( CustomAction_blockHold_storage );
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
151 print( NL );
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
152 CustomAction_blockHold_storage = 0;
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
153 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
154 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
155 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
156
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
157 void CustomAction_blockKey_capability( uint8_t state, uint8_t stateType, uint8_t *args )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
158 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
159 // Display capability name
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
160 if ( stateType == 0xFF && state == 0xFF )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
161 {
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
162 print("CustomAction_blockKey_capability(usbCode)");
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
163 return;
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
164 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
165
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
166 // Retrieve 8-bit argument
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
167 uint8_t key = args[0];
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
168
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
169 // If key is not blocked, process
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
170 if ( key != CustomAction_blockHold_storage )
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
171 {
373
83cb0d4b57e3 Updating convenience build scripts to build Left and Right sides
Jacob Alexander <haata@kiibohd.com>
parents: 363
diff changeset
172 extern void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args );
363
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
173 Output_usbCodeSend_capability( state, stateType, &key );
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
174 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
175 }
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
176
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
177
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
178 // Signal from the Output Module that the available current has changed
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
179 // current - mA
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
180 void Scan_currentChange( unsigned int current )
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
181 {
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
182 // Indicate to all submodules current change
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
183 Matrix_currentChange( current );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
184 }
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
185
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 373
diff changeset
186
363
28ea37f4075b Adding examples of custom action/capabilties
Jacob Alexander <haata@kiibohd.com>
parents: 256
diff changeset
187
187
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
188 // ----- CLI Command Functions -----
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
189
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
190 // XXX Just an example command showing how to parse arguments (more complex than generally needed)
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
191 void cliFunc_echo( char* args )
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
192 {
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
193 char* curArgs;
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
194 char* arg1Ptr;
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
195 char* arg2Ptr = args;
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
196
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
197 // Parse args until a \0 is found
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
198 while ( 1 )
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
199 {
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
200 print( NL ); // No \r\n by default after the command is entered
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
201
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
202 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
203 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
204
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
205 // Stop processing args if no more are found
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
206 if ( *arg1Ptr == '\0' )
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
207 break;
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
208
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
209 // Print out the arg
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
210 dPrint( arg1Ptr );
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
211 }
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
212 }
b250056298df Matrix scanning for ARM now functional.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
213