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