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