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.6KB

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