Keyboard firmwares for Atmel AVR and Cortex-M
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.

config_vusb.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. Copyright 2011 Jun Wako <[email protected]>
  3. This program 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 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef CONFIG_H
  15. #define CONFIG_H
  16. #define VENDOR_ID 0xFEED
  17. #define PRODUCT_ID 0x2233
  18. // TODO: share these strings with usbconfig.h
  19. // Edit usbconfig.h to change these.
  20. #define MANUFACTURER t.m.k.
  21. #define PRODUCT PS/2 keyboard converter
  22. #define DESCRIPTION convert PS/2 keyboard to USB
  23. /* matrix size */
  24. #define MATRIX_ROWS 32 // keycode bit: 3-0
  25. #define MATRIX_COLS 8 // keycode bit: 6-4
  26. /* key combination for command */
  27. #define IS_COMMAND() ( \
  28. keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \
  29. keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \
  30. )
  31. /* mouse keys */
  32. #ifdef MOUSEKEY_ENABLE
  33. # define MOUSEKEY_DELAY_TIME 255
  34. #endif
  35. /* PS/2 lines */
  36. #define PS2_CLOCK_PORT PORTD
  37. #define PS2_CLOCK_PIN PIND
  38. #define PS2_CLOCK_DDR DDRD
  39. #define PS2_CLOCK_BIT 4
  40. #define PS2_DATA_PORT PORTD
  41. #define PS2_DATA_PIN PIND
  42. #define PS2_DATA_DDR DDRD
  43. #define PS2_DATA_BIT 0
  44. // Synchronous USART is used to receive data from keyboard.
  45. // Use RXD pin for PS/2 DATA line and XCK for PS/2 CLOCK.
  46. // NOTE: This is recomended strongly if you use V-USB library.
  47. #define PS2_USE_USART
  48. // External or Pin Change Interrupt is used to receive data from keyboard.
  49. // Use INT1 or PCINTxx for PS/2 CLOCK line. see below.
  50. //#define PS2_USE_INT
  51. #ifdef PS2_USE_USART
  52. // synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge
  53. // set DDR of CLOCK as input to be slave
  54. #define PS2_USART_INIT() do { \
  55. PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); \
  56. PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); \
  57. UCSR0C = ((1 << UMSEL00) | \
  58. (3 << UPM00) | \
  59. (0 << USBS0) | \
  60. (3 << UCSZ00) | \
  61. (0 << UCPOL0)); \
  62. UCSR0A = 0; \
  63. UBRR0H = 0; \
  64. UBRR0L = 0; \
  65. } while (0)
  66. #define PS2_USART_RX_INT_ON() do { \
  67. UCSR0B = ((1 << RXCIE0) | \
  68. (1 << RXEN0)); \
  69. } while (0)
  70. #define PS2_USART_RX_POLL_ON() do { \
  71. UCSR0B = (1 << RXEN0); \
  72. } while (0)
  73. #define PS2_USART_OFF() do { \
  74. UCSR0C = 0; \
  75. UCSR0B &= ~((1 << RXEN0) | \
  76. (1 << TXEN0)); \
  77. } while (0)
  78. #define PS2_USART_RX_READY (UCSR0A & (1<<RXC0))
  79. #define PS2_USART_RX_DATA UDR0
  80. #define PS2_USART_ERROR (UCSR0A & ((1<<FE0) | (1<<DOR0) | (1<<UPE0)))
  81. #define PS2_USART_RX_VECT USART_RX_vect
  82. #endif
  83. #ifdef PS2_USE_INT
  84. /* INT1
  85. #define PS2_INT_INIT() do { \
  86. EICRA |= ((1<<ISC11) | \
  87. (0<<ISC10)); \
  88. } while (0)
  89. #define PS2_INT_ON() do { \
  90. EIMSK |= (1<<INT1); \
  91. } while (0)
  92. #define PS2_INT_OFF() do { \
  93. EIMSK &= ~(1<<INT1); \
  94. } while (0)
  95. #define PS2_INT_VECT INT1_vect
  96. */
  97. /* PCINT20 */
  98. #define PS2_INT_INIT() do { \
  99. PCICR |= (1<<PCIE2); \
  100. } while (0)
  101. #define PS2_INT_ON() do { \
  102. PCMSK2 |= (1<<PCINT20); \
  103. } while (0)
  104. #define PS2_INT_OFF() do { \
  105. PCMSK2 &= ~(1<<PCINT20); \
  106. PCICR &= ~(1<<PCIE2); \
  107. } while (0)
  108. #define PS2_INT_VECT PCINT2_vect
  109. #endif
  110. #endif