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.6KB

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