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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Copyright (C) 2015-2016 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. // Compiler Includes
  19. #include <stdint.h>
  20. // ----- Enums -----
  21. typedef enum FrameState {
  22. FrameState_Ready, // Buffers have been updated and are ready to send
  23. FrameState_Sending, // Buffers are currently being sent, do not change
  24. FrameState_Update, // Buffers need to be updated to latest frame
  25. } FrameState;
  26. // Pixel Change Storage
  27. // - Store only the change of the pixel
  28. // - Change is a value (size of the pixel)
  29. // - Contiguous sets of pixel changes can be stored for maximized packing (with the same width)
  30. // - Each value has a corresponding operator
  31. // * Add
  32. // * Subtract
  33. // * Left shift
  34. // * Right shift
  35. // * Set
  36. // * Add no-rollover
  37. // * Subtract no-rollover
  38. typedef enum PixelChange {
  39. PixelChange_Set = 0, // =
  40. PixelChange_Add, // +
  41. PixelChange_Subtract, // -
  42. PixelChange_NoRoll_Add, // +:
  43. PixelChange_NoRoll_Subtract, // -:
  44. PixelChange_LeftShift, // <<
  45. PixelChange_RightShift, // >>
  46. } PixelChange;
  47. // Animation modifiers
  48. typedef enum AnimationModifier {
  49. AnimationModifier_None = 0x00,
  50. AnimationModifier_Fallthrough = 0x01, // Process lower animation first
  51. } AnimationModifier;
  52. // ----- Structs -----
  53. // Element of array of buffers pointers
  54. typedef struct PixelBuf {
  55. uint8_t size; // Number of elements
  56. uint8_t width; // Width of each element
  57. uint16_t offset; // Subtraction offset from absolute channel
  58. void *data; // Pointer to start of buffer
  59. } PixelBuf;
  60. #define PixelBufElem(len,width,offset,ptr) { len, width, offset, (void*)ptr }
  61. #define PixelBuf8(pixbuf, ch) ( ((uint8_t*) (pixbuf->data))[ ch - pixbuf->offset ] )
  62. #define PixelBuf16(pixbuf, ch) ( ((uint16_t*)(pixbuf->data))[ ch - pixbuf->offset ] )
  63. // Individual Pixel element
  64. #define Pixel_MaxChannelPerPixel 3 // TODO Generate
  65. typedef struct PixelElement {
  66. uint8_t width; // Number of bits in a channel
  67. uint8_t channels; // Number of channels
  68. // Hardware indices for each channel
  69. uint16_t indices[Pixel_MaxChannelPerPixel];
  70. } PixelElement;
  71. #define Pixel_RGBChannel(r,g,b) { 8, 3, { r, g, b } }
  72. // TODO generate macro based on max channels
  73. //#define Pixel_8bitChannel(c) { 8, 1, { c } }
  74. typedef struct PixelMod {
  75. uint16_t pixel; // Pixel index
  76. PixelChange change; // Change to apply to pixel
  77. uint8_t contiguousPixels; // # of contiguous pixels to apply same changes too
  78. uint8_t data[0]; // Data size depends on PixelElement definition
  79. } PixelMod;
  80. // Animation stack element
  81. typedef struct AnimationElement {
  82. uint16_t index; // Animation id
  83. uint16_t pos; // Current frame
  84. uint8_t loops; // # of loops to run animation, 0 indicates infinite
  85. uint8_t divider; // # of times to repeat each frame
  86. AnimationModifier modifier; // Modifier applied to the entire animation
  87. } AnimationElement;
  88. // Animation stack
  89. #define Pixel_AnimationStackSize 16
  90. typedef struct AnimationStack {
  91. uint16_t size;
  92. AnimationElement stack[Pixel_AnimationStackSize];
  93. } AnimationStack;
  94. // ----- Variables -----
  95. extern FrameState Pixel_FrameState;
  96. // ----- Functions -----
  97. void Pixel_process();
  98. void Pixel_setup();