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.

usb_keyboard_debug.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef usb_serial_h__
  2. #define usb_serial_h__
  3. #include <stdint.h>
  4. void usb_init(void); // initialize everything
  5. uint8_t usb_configured(void); // is the USB port configured
  6. int8_t usb_keyboard_press(uint8_t key, uint8_t modifier);
  7. int8_t usb_keyboard_send(void);
  8. extern uint8_t keyboard_modifier_keys;
  9. extern uint8_t keyboard_keys[6];
  10. extern volatile uint8_t keyboard_leds;
  11. int8_t usb_debug_putchar(uint8_t c); // transmit a character
  12. void usb_debug_flush_output(void); // immediately transmit any buffered output
  13. #define USB_DEBUG_HID
  14. // Everything below this point is only intended for usb_serial.c
  15. #ifdef USB_SERIAL_PRIVATE_INCLUDE
  16. #include <avr/io.h>
  17. #include <avr/pgmspace.h>
  18. #include <avr/interrupt.h>
  19. #define EP_TYPE_CONTROL 0x00
  20. #define EP_TYPE_BULK_IN 0x81
  21. #define EP_TYPE_BULK_OUT 0x80
  22. #define EP_TYPE_INTERRUPT_IN 0xC1
  23. #define EP_TYPE_INTERRUPT_OUT 0xC0
  24. #define EP_TYPE_ISOCHRONOUS_IN 0x41
  25. #define EP_TYPE_ISOCHRONOUS_OUT 0x40
  26. #define EP_SINGLE_BUFFER 0x02
  27. #define EP_DOUBLE_BUFFER 0x06
  28. #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
  29. ((s) == 32 ? 0x20 : \
  30. ((s) == 16 ? 0x10 : \
  31. 0x00)))
  32. #define MAX_ENDPOINT 4
  33. #define LSB(n) (n & 255)
  34. #define MSB(n) ((n >> 8) & 255)
  35. #if defined(__AVR_AT90USB162__)
  36. #define HW_CONFIG()
  37. #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
  38. #define USB_CONFIG() (USBCON = (1<<USBE))
  39. #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
  40. #elif defined(__AVR_ATmega32U4__)
  41. #define HW_CONFIG() (UHWCON = 0x01)
  42. #define PLL_CONFIG() (PLLCSR = 0x12)
  43. #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
  44. #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
  45. #elif defined(__AVR_AT90USB646__)
  46. #define HW_CONFIG() (UHWCON = 0x81)
  47. #define PLL_CONFIG() (PLLCSR = 0x1A)
  48. #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
  49. #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
  50. #elif defined(__AVR_AT90USB1286__)
  51. #define HW_CONFIG() (UHWCON = 0x81)
  52. #define PLL_CONFIG() (PLLCSR = 0x16)
  53. #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
  54. #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
  55. #endif
  56. // standard control endpoint request types
  57. #define GET_STATUS 0
  58. #define CLEAR_FEATURE 1
  59. #define SET_FEATURE 3
  60. #define SET_ADDRESS 5
  61. #define GET_DESCRIPTOR 6
  62. #define GET_CONFIGURATION 8
  63. #define SET_CONFIGURATION 9
  64. #define GET_INTERFACE 10
  65. #define SET_INTERFACE 11
  66. // HID (human interface device)
  67. #define HID_GET_REPORT 1
  68. #define HID_GET_IDLE 2
  69. #define HID_GET_PROTOCOL 3
  70. #define HID_SET_REPORT 9
  71. #define HID_SET_IDLE 10
  72. #define HID_SET_PROTOCOL 11
  73. // CDC (communication class device)
  74. #define CDC_SET_LINE_CODING 0x20
  75. #define CDC_GET_LINE_CODING 0x21
  76. #define CDC_SET_CONTROL_LINE_STATE 0x22
  77. #endif
  78. #endif