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.h 2.2KB

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