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

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