]> git.donarmstrong.com Git - kiibohd-controller.git/blob - usb_keyboard.h
Initial Commit
[kiibohd-controller.git] / usb_keyboard.h
1 #ifndef usb_serial_h__
2 #define usb_serial_h__
3
4 #include <stdint.h>
5
6 void usb_init(void);                    // initialize everything
7 uint8_t usb_configured(void);           // is the USB port configured
8
9 int8_t usb_keyboard_press(uint8_t key, uint8_t modifier);
10 int8_t usb_keyboard_send(void);
11 extern uint8_t keyboard_modifier_keys;
12 extern uint8_t keyboard_keys[6];
13 extern volatile uint8_t keyboard_leds;
14
15 // This file does not include the HID debug functions, so these empty
16 // macros replace them with nothing, so users can compile code that
17 // has calls to these functions.
18 #define usb_debug_putchar(c)
19 #define usb_debug_flush_output()
20
21
22 #define KEY_CTRL        0x01
23 #define KEY_SHIFT       0x02
24 #define KEY_ALT         0x04
25 #define KEY_GUI         0x08
26 #define KEY_LEFT_CTRL   0x01
27 #define KEY_LEFT_SHIFT  0x02
28 #define KEY_LEFT_ALT    0x04
29 #define KEY_LEFT_GUI    0x08
30 #define KEY_RIGHT_CTRL  0x10
31 #define KEY_RIGHT_SHIFT 0x20
32 #define KEY_RIGHT_ALT   0x40
33 #define KEY_RIGHT_GUI   0x80
34
35 #define KEY_A           4
36 #define KEY_B           5
37 #define KEY_C           6
38 #define KEY_D           7
39 #define KEY_E           8
40 #define KEY_F           9
41 #define KEY_G           10
42 #define KEY_H           11
43 #define KEY_I           12
44 #define KEY_J           13
45 #define KEY_K           14
46 #define KEY_L           15
47 #define KEY_M           16
48 #define KEY_N           17
49 #define KEY_O           18
50 #define KEY_P           19
51 #define KEY_Q           20
52 #define KEY_R           21
53 #define KEY_S           22
54 #define KEY_T           23
55 #define KEY_U           24
56 #define KEY_V           25
57 #define KEY_W           26
58 #define KEY_X           27
59 #define KEY_Y           28
60 #define KEY_Z           29
61 #define KEY_1           30
62 #define KEY_2           31
63 #define KEY_3           32
64 #define KEY_4           33
65 #define KEY_5           34
66 #define KEY_6           35
67 #define KEY_7           36
68 #define KEY_8           37
69 #define KEY_9           38
70 #define KEY_0           39
71 #define KEY_ENTER       40      
72 #define KEY_ESC         41
73 #define KEY_BACKSPACE   42      
74 #define KEY_TAB         43
75 #define KEY_SPACE       44      
76 #define KEY_MINUS       45
77 #define KEY_EQUAL       46
78 #define KEY_LEFT_BRACE  47
79 #define KEY_RIGHT_BRACE 48
80 #define KEY_BACKSLASH   49
81 #define KEY_NUMBER      50
82 #define KEY_SEMICOLON   51
83 #define KEY_QUOTE       52
84 #define KEY_TILDE       53
85 #define KEY_COMMA       54
86 #define KEY_PERIOD      55
87 #define KEY_SLASH       56
88 #define KEY_CAPS_LOCK   57
89 #define KEY_F1          58
90 #define KEY_F2          59
91 #define KEY_F3          60
92 #define KEY_F4          61
93 #define KEY_F5          62
94 #define KEY_F6          63
95 #define KEY_F7          64
96 #define KEY_F8          65
97 #define KEY_F9          66
98 #define KEY_F10         67
99 #define KEY_F11         68
100 #define KEY_F12         69
101 #define KEY_PRINTSCREEN 70              
102 #define KEY_SCROLL_LOCK 71              
103 #define KEY_PAUSE       72
104 #define KEY_INSERT      73      
105 #define KEY_HOME        74
106 #define KEY_PAGE_UP     75
107 #define KEY_DELETE      76
108 #define KEY_END         77
109 #define KEY_PAGE_DOWN   78      
110 #define KEY_RIGHT       79
111 #define KEY_LEFT        80
112 #define KEY_DOWN        81
113 #define KEY_UP          82
114 #define KEY_NUM_LOCK    83
115 #define KEYPAD_SLASH    84      
116 #define KEYPAD_ASTERIX  85      
117 #define KEYPAD_MINUS    86      
118 #define KEYPAD_PLUS     87      
119 #define KEYPAD_ENTER    88      
120 #define KEYPAD_1        89
121 #define KEYPAD_2        90
122 #define KEYPAD_3        91      
123 #define KEYPAD_4        92      
124 #define KEYPAD_5        93      
125 #define KEYPAD_6        94      
126 #define KEYPAD_7        95      
127 #define KEYPAD_8        96      
128 #define KEYPAD_9        97      
129 #define KEYPAD_0        98              
130 #define KEYPAD_PERIOD   99              
131
132
133
134
135 // Everything below this point is only intended for usb_serial.c
136 #ifdef USB_SERIAL_PRIVATE_INCLUDE
137 #include <avr/io.h>
138 #include <avr/pgmspace.h>
139 #include <avr/interrupt.h>
140
141 #define EP_TYPE_CONTROL                 0x00
142 #define EP_TYPE_BULK_IN                 0x81
143 #define EP_TYPE_BULK_OUT                0x80
144 #define EP_TYPE_INTERRUPT_IN            0xC1
145 #define EP_TYPE_INTERRUPT_OUT           0xC0
146 #define EP_TYPE_ISOCHRONOUS_IN          0x41
147 #define EP_TYPE_ISOCHRONOUS_OUT         0x40
148
149 #define EP_SINGLE_BUFFER                0x02
150 #define EP_DOUBLE_BUFFER                0x06
151
152 #define EP_SIZE(s)      ((s) == 64 ? 0x30 :     \
153                         ((s) == 32 ? 0x20 :     \
154                         ((s) == 16 ? 0x10 :     \
155                                      0x00)))
156
157 #define MAX_ENDPOINT            4
158
159 #define LSB(n) (n & 255)
160 #define MSB(n) ((n >> 8) & 255)
161
162 #if defined(__AVR_AT90USB162__)
163 #define HW_CONFIG() 
164 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
165 #define USB_CONFIG() (USBCON = (1<<USBE))
166 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
167 #elif defined(__AVR_ATmega32U4__)
168 #define HW_CONFIG() (UHWCON = 0x01)
169 #define PLL_CONFIG() (PLLCSR = 0x12)
170 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
171 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
172 #elif defined(__AVR_AT90USB646__)
173 #define HW_CONFIG() (UHWCON = 0x81)
174 #define PLL_CONFIG() (PLLCSR = 0x1A)
175 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
176 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
177 #elif defined(__AVR_AT90USB1286__)
178 #define HW_CONFIG() (UHWCON = 0x81)
179 #define PLL_CONFIG() (PLLCSR = 0x16)
180 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
181 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
182 #endif
183
184 // standard control endpoint request types
185 #define GET_STATUS                      0
186 #define CLEAR_FEATURE                   1
187 #define SET_FEATURE                     3
188 #define SET_ADDRESS                     5
189 #define GET_DESCRIPTOR                  6
190 #define GET_CONFIGURATION               8
191 #define SET_CONFIGURATION               9
192 #define GET_INTERFACE                   10
193 #define SET_INTERFACE                   11
194 // HID (human interface device)
195 #define HID_GET_REPORT                  1
196 #define HID_GET_IDLE                    2
197 #define HID_GET_PROTOCOL                3
198 #define HID_SET_REPORT                  9
199 #define HID_SET_IDLE                    10
200 #define HID_SET_PROTOCOL                11
201 // CDC (communication class device)
202 #define CDC_SET_LINE_CODING             0x20
203 #define CDC_GET_LINE_CODING             0x21
204 #define CDC_SET_CONTROL_LINE_STATE      0x22
205 #endif
206 #endif