Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

connect_scan.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #pragma once
  17. // ----- Includes -----
  18. // Project Includes
  19. #include <kll.h>
  20. // ----- Enums -----
  21. // Functions
  22. typedef enum Command {
  23. CableCheck, // Comm check
  24. IdRequest, // Slave initialization (request id from master)
  25. IdEnumeration, // Slave initialization (begin enumeration from master)
  26. IdReport, // Slave initialization complete, report id to master
  27. ScanCode, // ScanCode event status change
  28. Animation, // Master trigger animation event (same command is sent back to master when ready)
  29. RemoteCapability, // Activate a capability on the given node
  30. RemoteOutput, // Remote debug output from a given node
  31. RemoteInput, // Remote command to send to a given node's debug cli
  32. Command_TOP, // Enum bounds
  33. Command_SYN = 0x16, // Reserved for error handling
  34. } Command;
  35. // UART Rx/Tx Status
  36. typedef enum UARTStatus {
  37. UARTStatus_Wait = 0, // Waiting Rx: for SYN Tx: for current command copy to finish
  38. UARTStatus_SYN = 1, // Rx: SYN Received, waiting for SOH
  39. UARTStatus_SOH = 2, // Rx: SOH Received, waiting for Command
  40. UARTStatus_Command = 3, // Rx: Command Received, waiting for data
  41. UARTStatus_Ready = 4, // Tx: Ready to send commands
  42. } UARTStatus;
  43. // ----- Structs -----
  44. // UART Connect Commands
  45. // Cable Check Command
  46. // Called on each UART every few seconds to make sure there is a connection
  47. // Also used to make sure there aren't any serious problems with the cable with data corruption
  48. // This command must pass before sending any other commands on the particular UART
  49. // Each argument is always 0xD2 (11010010)
  50. typedef struct CableCheckCommand {
  51. Command command;
  52. uint8_t numArgs;
  53. uint8_t firstArg[0];
  54. } CableCheckCommand;
  55. // Id Request Command
  56. // Issued by the slave device (non-master) whenever it is powered up
  57. // Do not issue any commands until given an Id
  58. // (Except for Cable Check and IdRequestCommand)
  59. typedef struct IdRequestCommand {
  60. Command command;
  61. } IdRequestCommand;
  62. // Id Enumeration Command
  63. // Issued by the master whenever an Id Request is received
  64. typedef struct IdEnumerationCommand {
  65. Command command;
  66. uint8_t id;
  67. } IdEnumerationCommand;
  68. // Id Report Command
  69. // Issued by each slave to the master when assigned an Id
  70. typedef struct IdReportCommand {
  71. Command command;
  72. uint8_t id;
  73. } IdReportCommand;
  74. // Scan Code Command
  75. // Sent from the slave to the master whenever there is a scan code state change
  76. typedef struct ScanCodeCommand {
  77. Command command;
  78. uint8_t id;
  79. uint8_t numScanCodes;
  80. TriggerGuide firstScanCode[0];
  81. } ScanCodeCommand;
  82. // Animation Command
  83. // Initiated by the master whenever an animation id should modify it's state
  84. // Then after the leaf slave node receives the command, send it back to the master
  85. // On the way back, each device can begin the animation adjustment
  86. //
  87. // The master->leaf command should indicate to each device that it should finish sending the
  88. // current slave->master data and wait for the leaf->master command
  89. // This allows for a tighter synchronization of animation events
  90. typedef struct AnimationCommand {
  91. Command command;
  92. uint8_t animationId;
  93. uint8_t numParams;
  94. uint8_t firstParam[0];
  95. } AnimationCommand;
  96. // Remote Capability Command
  97. // Initiated by the master to trigger a capability on a given node
  98. // RemoteOutput is enabled while capability is activated
  99. // Set id to 255 if command should be sent in all directions
  100. typedef struct RemoteCapabilityCommand {
  101. Command command;
  102. uint8_t id;
  103. uint8_t capabilityIndex;
  104. uint8_t state;
  105. uint8_t stateType;
  106. uint8_t numArgs; // # of bytes, args may be larger than 1 byte
  107. uint8_t firstArg[0];
  108. } RemoteCapabilityCommand;
  109. // Remote Output Command
  110. // Sends debug output to the master node
  111. // Uses print command redirection to generate each command message
  112. typedef struct RemoteOutputCommand {
  113. Command command;
  114. uint8_t id;
  115. uint8_t length;
  116. uint8_t firstChar[0];
  117. } RemoteOutputCommand;
  118. // Remote Input Command
  119. // Sends debug input to given node (usually from master)
  120. // Uses debug cli to execute command and sends all output using Remote Output Command
  121. typedef struct RemoteInputCommand {
  122. Command command;
  123. uint8_t id;
  124. uint8_t length;
  125. uint8_t firstChar[0];
  126. } RemoteInputCommand;
  127. // ----- Variables -----
  128. extern uint8_t Connect_id;
  129. extern uint8_t Connect_master; // Set if master
  130. // ----- Functions -----
  131. void Connect_setup( uint8_t master );
  132. void Connect_scan();
  133. void Connect_send_ScanCode( uint8_t id, TriggerGuide *scanCodeStateList, uint8_t numScanCodes );
  134. void Connect_send_RemoteCapability( uint8_t id, uint8_t capabilityIndex, uint8_t state, uint8_t stateType, uint8_t numArgs, uint8_t *args );