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.

scan_loop.c 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Copyright (C) 2015-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. // ----- Includes -----
  22. // Compiler Includes
  23. #include <Lib/ScanLib.h>
  24. // Project Includes
  25. #include <cli.h>
  26. #include <connect_scan.h>
  27. #include <led.h>
  28. #include <led_scan.h>
  29. #include <print.h>
  30. #include <matrix_scan.h>
  31. #include <macro.h>
  32. #include <output_com.h>
  33. #include <port_scan.h>
  34. #include <pixel.h>
  35. // Local Includes
  36. #include "scan_loop.h"
  37. // ----- Function Declarations -----
  38. // ----- Variables -----
  39. // Number of scans since the last USB send
  40. uint16_t Scan_scanCount = 0;
  41. // ----- Functions -----
  42. // Setup
  43. inline void Scan_setup()
  44. {
  45. // Setup Port Swap module
  46. Port_setup();
  47. // Setup UART Connect, if Output_Available, this is the master node
  48. Connect_setup( Output_Available );
  49. // Setup GPIO pins for matrix scanning
  50. Matrix_setup();
  51. // Setup ISSI chip to control the leds
  52. LED_setup();
  53. // Setup Pixel Map
  54. Pixel_setup();
  55. // Reset scan count
  56. Scan_scanCount = 0;
  57. }
  58. // Main Detection Loop
  59. inline uint8_t Scan_loop()
  60. {
  61. // Port Swap detection
  62. Port_scan();
  63. // Scan Matrix
  64. //Matrix_scan( Scan_scanCount++ );
  65. // Process any interconnect commands
  66. Connect_scan();
  67. // Prepare any LED events
  68. Pixel_process();
  69. // Process any LED events
  70. LED_scan();
  71. return 0;
  72. }
  73. // Signal from Macro Module that all keys have been processed (that it knows about)
  74. inline void Scan_finishedWithMacro( uint8_t sentKeys )
  75. {
  76. }
  77. // Signal from Output Module that all keys have been processed (that it knows about)
  78. inline void Scan_finishedWithOutput( uint8_t sentKeys )
  79. {
  80. // Reset scan loop indicator (resets each key debounce state)
  81. // TODO should this occur after USB send or Macro processing?
  82. Scan_scanCount = 0;
  83. }
  84. // Signal from the Output Module that the available current has changed
  85. // current - mA
  86. void Scan_currentChange( unsigned int current )
  87. {
  88. // Indicate to all submodules current change
  89. Connect_currentChange( current );
  90. Port_currentChange( current );
  91. Matrix_currentChange( current );
  92. LED_currentChange( current );
  93. }