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.

usb_keyboard_debug.h 2.6KB

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