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