]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Scan/UARTConnect/connect_scan.h
Code cleanup
[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    = 0, // Comm check
31         IdRequest     = 1, // Slave initialization (request id from master)
32         IdEnumeration = 2, // Slave initialization (begin enumeration from master)
33         IdReport      = 3, // Slave initialization complete, report id to master
34         ScanCode      = 4, // ScanCode event status change
35         Animation     = 5, // Master trigger animation event (same command is sent back to master when ready)
36 } Command;
37
38 // UART Rx/Tx Status
39 typedef enum UARTStatus {
40         UARTStatus_Wait    = 0, // Waiting  Rx: for SYN  Tx: for current command copy to finish
41         UARTStatus_SYN     = 1, // Rx: SYN Received, waiting for SOH
42         UARTStatus_SOH     = 2, // Rx: SOH Received, waiting for Command
43         UARTStatus_Command = 3, // Rx: Command Received, waiting for data
44         UARTStatus_Ready   = 4, // Tx: Ready to receive commands
45 } UARTStatus;
46
47
48
49 // ----- Structs -----
50
51 // UART Connect Commands
52
53 // Cable Check Command
54 // Called on each UART every few seconds to make sure there is a connection
55 // Also used to make sure there aren't any serious problems with the cable with data corruption
56 // This command must pass before sending any other commands on the particular UART
57 // Each argument is always 0xD2 (11010010)
58 typedef struct CableCheckCommand {
59         Command command;
60         uint8_t numArgs;
61         uint8_t firstArg[0];
62 } CableCheckCommand;
63
64 // Id Request Command
65 // Issued by the slave device (non-master) whenever it is powered up
66 // Do not issue any commands until given an Id
67 // (Except for Cable Check and IdRequestCommand)
68 typedef struct IdRequestCommand {
69         Command command;
70 } IdRequestCommand;
71
72 // Id Enumeration Command
73 // Issued by the master whenever an Id Request is received
74 // XXX Future work may include an "external capabilities" list in this command
75 typedef struct IdEnumerationCommand {
76         Command command;
77         uint8_t id;
78 } IdEnumerationCommand;
79
80 // Id Report Command
81 // Issued by each slave to the master when assigned an Id
82 // XXX Future work will include an "external capabilities" list in this command
83 typedef struct IdReportCommand {
84         Command command;
85         uint8_t id;
86 } IdReportCommand;
87
88 // Scan Code Command
89 // Sent from the slave to the master whenever there is a scan code state change
90 typedef struct ScanCodeCommand {
91         Command command;
92         uint8_t id;
93         uint8_t numScanCodes;
94         TriggerGuide firstScanCode[0];
95 } ScanCodeCommand;
96
97 // Animation Command
98 // Initiated by the master whenever an animation id should modify it's state
99 // Then after the leaf slave node receives the command, send it back to the master
100 // On the way back, each device can begin the animation adjustment
101 //
102 // The master->leaf command should indicate to each device that it should finish sending the
103 // current slave->master data and wait for the leaf->master command
104 // This allows for a tighter synchronization of animation events
105 typedef struct AnimationCommand {
106         Command command;
107         uint8_t animationId;
108         uint8_t numParams;
109         uint8_t firstParam[0];
110 } AnimationCommand;
111
112
113
114 // ----- Functions -----
115
116 void Connect_setup( uint8_t master );
117 void Connect_scan();
118