Kiibohd Controller
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

main.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright (C) 2011 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. #include <avr/io.h>
  22. #include <avr/pgmspace.h>
  23. #include <avr/interrupt.h>
  24. #include <util/delay.h>
  25. #include "usb_keyboard.h"
  26. #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
  27. #define PRE_DRIVE_SLEEP
  28. #define POST_DRIVE_SLEEP
  29. #define DRIVE_reg_1 PORTB
  30. #define DRIVE_reg_2 PORTB
  31. #define DRIVE_reg_3 PORTB
  32. #define DRIVE_reg_4 PORTC
  33. #define DRIVE_reg_5 PORTE
  34. #define DRIVE_reg_6 PORTE
  35. #define DRIVE_reg_7 PORTF
  36. #define DRIVE_reg_8 PORTF
  37. #define DRIVE_reg_9 PORTF
  38. #define DRIVE_reg_10 <blank>
  39. #define DRIVE_reg_11 <blank>
  40. #define DRIVE_reg_12 <blank>
  41. #define DRIVE_pin_1 0
  42. #define DRIVE_pin_2 1
  43. #define DRIVE_pin_3 2
  44. #define DRIVE_pin_4 7
  45. #define DRIVE_pin_5 6
  46. #define DRIVE_pin_6 7
  47. #define DRIVE_pin_7 0
  48. #define DRIVE_pin_8 4
  49. #define DRIVE_pin_9 5
  50. #define DRIVE_pin_10 <blank>
  51. #define DRIVE_pin_11 <blank>
  52. #define DRIVE_pin_12 <blank>
  53. #define DETECT_group_1 0
  54. #define DETECT_group_2 0
  55. #define DETECT_group_3 0
  56. #define DETECT_group_4 0
  57. #define DETECT_group_5 0
  58. #define DETECT_group_6 0
  59. #define DETECT_group_7 0
  60. #define DETECT_group_8 0
  61. #define DETECT_group_9 0
  62. #define DETECT_group_10 <blank>
  63. #define DETECT_group_11 <blank>
  64. #define DETECT_group_12 <blank>
  65. // Change number of ORDs if number of lines differ
  66. #define DD_LOOP \
  67. for ( int c = 0;; c++ ) { \
  68. switch ( c ) { \
  69. DD_CASE_ORD(1) \
  70. DD_CASE_ORD(2) \
  71. DD_CASE_ORD(3) \
  72. DD_CASE_ORD(4) \
  73. DD_CASE_ORD(5) \
  74. DD_CASE_ORD(6) \
  75. DD_CASE_ORD(7) \
  76. DD_CASE_ORD(8) \
  77. DD_CASE_END(9,c) \
  78. } \
  79. }
  80. #define DRIVE_DETECT(reg,pin,group) \
  81. reg |= (1 << pin);\
  82. detection(group);\
  83. reg &= (0 << pin);
  84. #define DD_CASE(number) \
  85. case number:\
  86. DRIVE_DETECT(DRIVE_reg##_##number, DRIVE_pin##_##number, DETECT_group##_##number)
  87. #define DD_CASE_ORD(number) \
  88. DD_CASE(number) \
  89. break;
  90. #define DD_CASE_END(number,var) \
  91. DD_CASE(number) \
  92. default: \
  93. var = -1; \
  94. break;
  95. int main(void)
  96. {
  97. // set for 16 MHz clock
  98. CPU_PRESCALE( 0 );
  99. // Configuring Pins
  100. // TODO
  101. // Initialize the USB, and then wait for the host to set configuration.
  102. // If the Teensy is powered without a PC connected to the USB port,
  103. // this will wait forever.
  104. usb_init();
  105. while ( !usb_configured() ) /* wait */ ;
  106. // Wait an extra second for the PC's operating system to load drivers
  107. // and do whatever it does to actually be ready for input
  108. _delay_ms(1000);
  109. // Main Detection Loop
  110. DD_LOOP
  111. // usb_keyboard_press(KEY_B, KEY_SHIFT);
  112. return 0;
  113. }