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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (C) 2014-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. // Local Includes
  34. #include "scan_loop.h"
  35. // ----- Function Declarations -----
  36. // ----- Variables -----
  37. // Number of scans since the last USB send
  38. uint16_t Scan_scanCount = 0;
  39. // ----- Functions -----
  40. // Setup
  41. inline void Scan_setup()
  42. {
  43. // Setup UART Connect, if Output_Available, this is the master node
  44. Connect_setup( Output_Available );
  45. // Setup GPIO pins for matrix scanning
  46. Matrix_setup();
  47. // Setup ISSI chip to control the leds
  48. LED_setup();
  49. // Reset scan count
  50. Scan_scanCount = 0;
  51. }
  52. // Main Detection Loop
  53. inline uint8_t Scan_loop()
  54. {
  55. // Scan Matrix
  56. Matrix_scan( Scan_scanCount++ );
  57. // Process any interconnect commands
  58. Connect_scan();
  59. // Process any LED events
  60. LED_scan();
  61. return 0;
  62. }
  63. // Signal from Macro Module that all keys have been processed (that it knows about)
  64. inline void Scan_finishedWithMacro( uint8_t sentKeys )
  65. {
  66. }
  67. // Signal from Output Module that all keys have been processed (that it knows about)
  68. inline void Scan_finishedWithOutput( uint8_t sentKeys )
  69. {
  70. // Reset scan loop indicator (resets each key debounce state)
  71. // TODO should this occur after USB send or Macro processing?
  72. Scan_scanCount = 0;
  73. }
  74. // Signal from the Output Module that the available current has changed
  75. // current - mA
  76. void Scan_currentChange( unsigned int current )
  77. {
  78. // Indicate to all submodules current change
  79. Connect_currentChange( current );
  80. Matrix_currentChange( current );
  81. LED_currentChange( current );
  82. }