]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Scan/UARTConnect/connect_scan.h
bb50610dfdb2b79ca753907502e78a171c136366
[kiibohd-controller.git] / Scan / UARTConnect / connect_scan.h
1 /* Copyright (C) 2014-2015 by Jacob Alexander
2  *
3  * This file is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This file is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 #pragma once
18
19 // ----- Includes -----
20
21 // Project Includes
22 #include <kll.h>
23
24
25
26 // ----- Enums -----
27
28 // Functions
29 typedef enum Command {
30         CableCheck,       // Comm check
31
32         IdRequest,        // Slave initialization (request id from master)
33         IdEnumeration,    // Slave initialization (begin enumeration from master)
34         IdReport,         // Slave initialization complete, report id to master
35
36         ScanCode,         // ScanCode event status change
37         Animation,        // Master trigger animation event (same command is sent back to master when ready)
38
39         RemoteCapability, // Activate a capability on the given node
40         RemoteOutput,     // Remote debug output from a given node
41         RemoteInput,      // Remote command to send to a given node's debug cli
42
43         Command_TOP,      // Enum bounds
44         Command_SYN = 0x16, // Reserved for error handling
45 } Command;
46
47 // UART Rx/Tx Status
48 typedef enum UARTStatus {
49         UARTStatus_Wait    = 0, // Waiting  Rx: for SYN  Tx: for current command copy to finish
50         UARTStatus_SYN     = 1, // Rx: SYN Received, waiting for SOH
51         UARTStatus_SOH     = 2, // Rx: SOH Received, waiting for Command
52         UARTStatus_Command = 3, // Rx: Command Received, waiting for data
53         UARTStatus_Ready   = 4, // Tx: Ready to send commands
54 } UARTStatus;
55
56
57
58 // ----- Structs -----
59
60 // UART Connect Commands
61
62 // Cable Check Command
63 // Called on each UART every few seconds to make sure there is a connection
64 // Also used to make sure there aren't any serious problems with the cable with data corruption
65 // This command must pass before sending any other commands on the particular UART
66 // Each argument is always 0xD2 (11010010)
67 typedef struct CableCheckCommand {
68         Command command;
69         uint8_t numArgs;
70         uint8_t firstArg[0];
71 } CableCheckCommand;
72
73 // Id Request Command
74 // Issued by the slave device (non-master) whenever it is powered up
75 // Do not issue any commands until given an Id
76 // (Except for Cable Check and IdRequestCommand)
77 typedef struct IdRequestCommand {
78         Command command;
79 } IdRequestCommand;
80
81 // Id Enumeration Command
82 // Issued by the master whenever an Id Request is received
83 typedef struct IdEnumerationCommand {
84         Command command;
85         uint8_t id;
86 } IdEnumerationCommand;
87
88 // Id Report Command
89 // Issued by each slave to the master when assigned an Id
90 typedef struct IdReportCommand {
91         Command command;
92         uint8_t id;
93 } IdReportCommand;
94
95 // Scan Code Command
96 // Sent from the slave to the master whenever there is a scan code state change
97 typedef struct ScanCodeCommand {
98         Command command;
99         uint8_t id;
100         uint8_t numScanCodes;
101         TriggerGuide firstScanCode[0];
102 } ScanCodeCommand;
103
104 // Animation Command
105 // Initiated by the master whenever an animation id should modify it's state
106 // Then after the leaf slave node receives the command, send it back to the master
107 // On the way back, each device can begin the animation adjustment
108 //
109 // The master->leaf command should indicate to each device that it should finish sending the
110 // current slave->master data and wait for the leaf->master command
111 // This allows for a tighter synchronization of animation events
112 typedef struct AnimationCommand {
113         Command command;
114         uint8_t animationId;
115         uint8_t numParams;
116         uint8_t firstParam[0];
117 } AnimationCommand;
118
119 // Remote Capability Command
120 // Initiated by the master to trigger a capability on a given node
121 // RemoteOutput is enabled while capability is activated
122 typedef struct RemoteCapabilityCommand {
123         Command command;
124         uint8_t id;
125         Capability capability;
126         uint8_t numArgs;
127         uint8_t firstArg[0];
128 } RemoteCapabilityCommand;
129
130 // Remote Output Command
131 // Sends debug output to the master node
132 // Uses print command redirection to generate each command message
133 typedef struct RemoteOutputCommand {
134         Command command;
135         uint8_t id;
136         uint8_t length;
137         uint8_t firstChar[0];
138 } RemoteOutputCommand;
139
140 // Remote Input Command
141 // Sends debug input to given node (usually from master)
142 // Uses debug cli to execute command and sends all output using Remote Output Command
143 typedef struct RemoteInputCommand {
144         Command command;
145         uint8_t id;
146         uint8_t length;
147         uint8_t firstChar[0];
148 } RemoteInputCommand;
149
150
151
152 // ----- Variables -----
153
154 extern uint8_t Connect_id;
155 extern uint8_t Connect_master; // Set if master
156
157
158
159 // ----- Functions -----
160
161 void Connect_setup( uint8_t master );
162 void Connect_scan();
163
164 void Connect_send_ScanCode( uint8_t id, TriggerGuide *scanCodeStateList, uint8_t numScanCodes );
165