Added Keyboard LED report masks (KEYBOARD_LED_*) to the HID class driver and demos.
[pub/USBasp.git] / Demos / Device / LowLevel / Keyboard / Keyboard.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
11 Based on code by Dean Camera (dean [at] fourwalledcubicle [dot] com)
12
13 Permission to use, copy, modify, distribute, and sell this
14 software and its documentation for any purpose is hereby granted
15 without fee, provided that the above copyright notice appear in
16 all copies and that both that the copyright notice and this
17 permission notice and warranty disclaimer appear in supporting
18 documentation, and that the name of the author not be used in
19 advertising or publicity pertaining to distribution of the
20 software without specific, written prior permission.
21
22 The author disclaim all warranties with regard to this
23 software, including all implied warranties of merchantability
24 and fitness. In no event shall the author be liable for any
25 special, indirect or consequential damages or any damages
26 whatsoever resulting from loss of use, data or profits, whether
27 in an action of contract, negligence or other tortious action,
28 arising out of or in connection with the use or performance of
29 this software.
30 */
31
32 /** \file
33 *
34 * Header file for Keyboard.c.
35 */
36
37 #ifndef _KEYBOARD_H_
38 #define _KEYBOARD_H_
39
40 /* Includes: */
41 #include <avr/io.h>
42 #include <avr/wdt.h>
43 #include <avr/power.h>
44 #include <stdbool.h>
45 #include <string.h>
46
47 #include "Descriptors.h"
48
49 #include <LUFA/Version.h>
50 #include <LUFA/Drivers/USB/USB.h>
51 #include <LUFA/Drivers/Board/Joystick.h>
52 #include <LUFA/Drivers/Board/Buttons.h>
53 #include <LUFA/Drivers/Board/LEDs.h>
54
55 /* Macros: */
56 /** Idle period indicating that reports should be sent only when the inputs have changed */
57 #define HID_IDLE_CHANGESONLY 0
58
59 /** HID Class specific request to get the next HID report from the device. */
60 #define REQ_GetReport 0x01
61
62 /** HID Class specific request to get the idle timeout period of the device. */
63 #define REQ_GetIdle 0x02
64
65 /** HID Class specific request to send the next HID report to the device. */
66 #define REQ_SetReport 0x09
67
68 /** HID Class specific request to set the idle timeout period of the device. */
69 #define REQ_SetIdle 0x0A
70
71 /** HID Class specific request to get the current HID protocol in use, either report or boot. */
72 #define REQ_GetProtocol 0x03
73
74 /** HID Class specific request to set the current HID protocol in use, either report or boot. */
75 #define REQ_SetProtocol 0x0B
76
77 /** Constant for a keyboard report modifier byte, indicating that the keyboard's left control key is currently pressed. */
78 #define KEYBOARD_MODIFER_LEFTCTRL (1 << 0)
79
80 /** Constant for a keyboard report modifier byte, indicating that the keyboard's left shift key is currently pressed. */
81 #define KEYBOARD_MODIFER_LEFTSHIFT (1 << 1)
82
83 /** Constant for a keyboard report modifier byte, indicating that the keyboard's left alt key is currently pressed. */
84 #define KEYBOARD_MODIFER_LEFTALT (1 << 2)
85
86 /** Constant for a keyboard report modifier byte, indicating that the keyboard's left GUI key is currently pressed. */
87 #define KEYBOARD_MODIFER_LEFTGUI (1 << 3)
88
89 /** Constant for a keyboard report modifier byte, indicating that the keyboard's right control key is currently pressed. */
90 #define KEYBOARD_MODIFER_RIGHTCTRL (1 << 4)
91
92 /** Constant for a keyboard report modifier byte, indicating that the keyboard's right shift key is currently pressed. */
93 #define KEYBOARD_MODIFER_RIGHTSHIFT (1 << 5)
94
95 /** Constant for a keyboard report modifier byte, indicating that the keyboard's right alt key is currently pressed. */
96 #define KEYBOARD_MODIFER_RIGHTALT (1 << 6)
97
98 /** Constant for a keyboard report modifier byte, indicating that the keyboard's right GUI key is currently pressed. */
99 #define KEYBOARD_MODIFER_RIGHTGUI (1 << 7)
100
101 /** Constant for a keyboard output report LED byte, indicating that the host's NUM LOCK mode is currently set. */
102 #define KEYBOARD_LED_NUMLOCK (1 << 0)
103
104 /** Constant for a keyboard output report LED byte, indicating that the host's CAPS LOCK mode is currently set. */
105 #define KEYBOARD_LED_CAPSLOCK (1 << 1)
106
107 /** Constant for a keyboard output report LED byte, indicating that the host's SCROLL LOCK mode is currently set. */
108 #define KEYBOARD_LED_SCROLLLOCK (1 << 2)
109
110 /** Constant for a keyboard output report LED byte, indicating that the host's KATANA mode is currently set. */
111 #define KEYBOARD_LED_KATANA (1 << 3)
112
113 /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
114 #define LEDMASK_USB_NOTREADY LEDS_LED1
115
116 /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */
117 #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3)
118
119 /** LED mask for the library LED driver, to indicate that the USB interface is ready. */
120 #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4)
121
122 /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
123 #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
124
125 /* Type Defines: */
126 /** Type define for the keyboard HID report structure, for creating and sending HID reports to the host PC.
127 * This mirrors the layout described to the host in the HID report descriptor, in Descriptors.c.
128 */
129 typedef struct
130 {
131 uint8_t Modifier; /**< Modifier mask byte, containing a mask of modifier keys set (such as shift or CTRL) */
132 uint8_t Reserved; /**< Reserved, always set as 0x00 */
133 uint8_t KeyCode[6]; /**< Array of up to six simultaneous key codes of pressed keys */
134 } USB_KeyboardReport_Data_t;
135
136 /* Function Prototypes: */
137 void SetupHardware(void);
138 void HID_Task(void);
139
140 void EVENT_USB_Device_Connect(void);
141 void EVENT_USB_Device_Disconnect(void);
142 void EVENT_USB_Device_ConfigurationChanged(void);
143 void EVENT_USB_Device_UnhandledControlRequest(void);
144 void EVENT_USB_Device_StartOfFrame(void);
145
146 void CreateKeyboardReport(USB_KeyboardReport_Data_t* ReportData);
147 void ProcessLEDReport(uint8_t LEDReport);
148 void SendNextReport(void);
149 void ReceiveNextReport(void);
150
151 #endif