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.

output_com.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* Copyright (C) 2013-2016 by Jacob Alexander
  2. *
  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:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  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
  19. * THE SOFTWARE.
  20. */
  21. #pragma once
  22. // ----- Includes -----
  23. // Compiler Includes
  24. #include <stdint.h>
  25. // Local Includes
  26. #include <buildvars.h> // Defines USB Parameters, partially generated by CMake
  27. // ----- Defines -----
  28. // Max size of key buffer needed for NKRO
  29. // Boot mode uses only the first 6 bytes
  30. #define USB_NKRO_BITFIELD_SIZE_KEYS 27
  31. #define USB_BOOT_MAX_KEYS 6
  32. // ----- Enumerations -----
  33. // USB NKRO state transitions (indicates which Report ID's need refreshing)
  34. // Boot mode just checks if any keys were changed (as everything is sent every time)
  35. typedef enum USBKeyChangeState {
  36. USBKeyChangeState_None = 0x00,
  37. USBKeyChangeState_Modifiers = 0x01,
  38. USBKeyChangeState_MainKeys = 0x02,
  39. USBKeyChangeState_SecondaryKeys = 0x04,
  40. USBKeyChangeState_TertiaryKeys = 0x08,
  41. USBKeyChangeState_QuartiaryKeys = 0x10,
  42. USBKeyChangeState_System = 0x20,
  43. USBKeyChangeState_Consumer = 0x40,
  44. USBKeyChangeState_All = 0x7F,
  45. } USBKeyChangeState;
  46. // Allows for selective USB descriptor pushes
  47. // However, in most cases everything is updated for each packet push
  48. typedef enum USBMouseChangeState {
  49. USBMouseChangeState_None = 0x00,
  50. USBMouseChangeState_Buttons = 0x01,
  51. USBMouseChangeState_Relative = 0x02,
  52. USBMouseChangeState_All = 0x03,
  53. } USBMouseChangeState;
  54. // ----- Variables -----
  55. // Variables used to communciate to the output module
  56. // XXX Even if the output module is not USB, this is internally understood keymapping scheme
  57. extern uint8_t USBKeys_Modifiers;
  58. extern uint8_t USBKeys_Keys[USB_NKRO_BITFIELD_SIZE_KEYS];
  59. extern uint8_t USBKeys_Sent;
  60. extern volatile uint8_t USBKeys_LEDs;
  61. extern uint8_t USBKeys_SysCtrl; // 1KRO container for System Control HID table
  62. extern uint16_t USBKeys_ConsCtrl; // 1KRO container for Consumer Control HID table
  63. extern volatile uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode
  64. extern volatile uint16_t USBMouse_Buttons; // Bitmask for mouse buttons
  65. extern volatile uint16_t USBMouse_Relative_x;
  66. extern volatile uint16_t USBMouse_Relative_y;
  67. // Keeps track of the idle timeout refresh (used on Mac OSX)
  68. extern uint8_t USBKeys_Idle_Config;
  69. extern uint32_t USBKeys_Idle_Expiry;
  70. extern uint8_t USBKeys_Idle_Count; // AVR only
  71. extern USBKeyChangeState USBKeys_Changed;
  72. extern USBMouseChangeState USBMouse_Changed;
  73. extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working
  74. extern uint8_t Output_DebugMode; // 0 - Debug disabled, 1 - Debug enabled
  75. extern uint16_t Output_ExtCurrent_Available; // mA - Set by outside module if not using USB (i.e. Interconnect)
  76. extern volatile uint32_t USBInit_TimeStart; // Timetamp when usb_init was triggered
  77. extern volatile uint32_t USBInit_TimeEnd; // Timetamp since last call to the Configuration endpoint
  78. extern volatile uint16_t USBInit_Ticks; // Number of times the end time has been updated
  79. // ----- Functions -----
  80. void Output_setup();
  81. void Output_send();
  82. void Output_flushBuffers();
  83. void Output_firmwareReload();
  84. void Output_softReset();
  85. // Relies on USB serial module
  86. unsigned int Output_availablechar();
  87. // Returns the total mA available (total, if used in a chain, each device will have to use a slice of it)
  88. unsigned int Output_current_available();
  89. void Output_update_external_current( unsigned int current );
  90. void Output_update_usb_current( unsigned int current );
  91. int Output_getchar();
  92. int Output_putchar( char c );
  93. int Output_putstr( char* str );