]> git.donarmstrong.com Git - kiibohd-controller.git/blob - USB/pjrc/usb_com.c
Adding soft entry bootloader via key sequence.
[kiibohd-controller.git] / USB / pjrc / usb_com.c
1 /* Copyright (C) 2011 by Jacob Alexander
2  * 
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  * 
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  * 
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  */
21
22 // ----- Includes -----
23
24 // Compiler Includes
25 #include <util/delay.h>
26
27 // AVR Includes
28
29 // Project Includes
30 #include "usb_keyboard_debug.h"
31
32 // Local Includes
33 #include "usb_com.h"
34
35
36
37 // ----- Variables -----
38
39 // which modifier keys are currently pressed
40 // 1=left ctrl,    2=left shift,   4=left alt,    8=left gui
41 // 16=right ctrl, 32=right shift, 64=right alt, 128=right gui
42          uint8_t USBKeys_Modifiers = 0;
43
44 // which keys are currently pressed, up to 6 keys may be down at once
45          uint8_t USBKeys_Array[USB_MAX_KEY_SEND] = {0,0,0,0,0,0};
46
47 // The number of keys sent to the usb in the array
48          uint8_t USBKeys_Sent;
49
50 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
51 volatile uint8_t USBKeys_LEDs = 0;
52
53
54
55 // ----- Functions -----
56
57 // USB Module Setup
58 inline void usb_setup(void)
59 {
60         // Initialize the USB, and then wait for the host to set configuration.
61         // If the Teensy is powered without a PC connected to the USB port,
62         // this will wait forever.
63         usb_init();
64         while ( !usb_configured() ) /* wait */ ;
65
66         // Wait an extra second for the PC's operating system to load drivers
67         // and do whatever it does to actually be ready for input
68         _delay_ms(1000);
69 }
70
71
72 // USB Data Send
73 inline void usb_send(void)
74 {
75                 // TODO undo potentially old keys
76                 for ( uint8_t c = USBKeys_Sent; c < USBKeys_MaxSize; c++ )
77                         USBKeys_Array[c] = 0;
78
79                 // Send keypresses
80                 usb_keyboard_send();
81
82                 // Clear modifiers and keys
83                 USBKeys_Modifiers = 0;
84                 USBKeys_Sent      = 0;
85 }
86