1 | /*
|
---|
2 | * Copyright (c) 2011 Vojtech Horky
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup usbvirthid
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | *
|
---|
34 | */
|
---|
35 | #include "../virthid.h"
|
---|
36 | #include <errno.h>
|
---|
37 | #include <usb/debug.h>
|
---|
38 | #include <usb/hid/hid.h>
|
---|
39 | #include <usb/hid/usages/core.h>
|
---|
40 |
|
---|
41 | #include "../report.h"
|
---|
42 |
|
---|
43 | uint8_t report_descriptor[] = {
|
---|
44 | STD_USAGE_PAGE(USB_HIDUT_PAGE_GENERIC_DESKTOP),
|
---|
45 | USAGE1(USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD),
|
---|
46 | START_COLLECTION(COLLECTION_APPLICATION),
|
---|
47 | STD_USAGE_PAGE(USB_HIDUT_PAGE_KEYBOARD),
|
---|
48 | USAGE_MINIMUM1(224),
|
---|
49 | USAGE_MAXIMUM1(231),
|
---|
50 | LOGICAL_MINIMUM1(0),
|
---|
51 | LOGICAL_MAXIMUM1(1),
|
---|
52 | REPORT_SIZE1(1),
|
---|
53 | REPORT_COUNT1(8),
|
---|
54 | /* Modifiers */
|
---|
55 | INPUT(IOF_DATA | IOF_VARIABLE | IOF_ABSOLUTE),
|
---|
56 | REPORT_COUNT1(1),
|
---|
57 | REPORT_SIZE1(8),
|
---|
58 | /* Reserved */
|
---|
59 | INPUT(IOF_CONSTANT),
|
---|
60 | REPORT_COUNT1(5),
|
---|
61 | REPORT_SIZE1(1),
|
---|
62 | STD_USAGE_PAGE(USB_HIDUT_PAGE_LED),
|
---|
63 | USAGE_MINIMUM1(1),
|
---|
64 | USAGE_MAXIMUM1(5),
|
---|
65 | /* LED states */
|
---|
66 | OUTPUT(IOF_DATA | IOF_VARIABLE | IOF_ABSOLUTE),
|
---|
67 | REPORT_COUNT1(1),
|
---|
68 | REPORT_SIZE1(3),
|
---|
69 | /* LED states padding */
|
---|
70 | OUTPUT(IOF_CONSTANT),
|
---|
71 | REPORT_COUNT1(6),
|
---|
72 | REPORT_SIZE1(8),
|
---|
73 | LOGICAL_MINIMUM1(0),
|
---|
74 | LOGICAL_MAXIMUM1(101),
|
---|
75 | STD_USAGE_PAGE(USB_HIDUT_PAGE_KEYBOARD),
|
---|
76 | USAGE_MINIMUM1(0),
|
---|
77 | USAGE_MAXIMUM1(101),
|
---|
78 | /* Key array */
|
---|
79 | INPUT(IOF_DATA | IOF_ARRAY),
|
---|
80 | END_COLLECTION()
|
---|
81 | };
|
---|
82 |
|
---|
83 | #define INPUT_SIZE 8
|
---|
84 |
|
---|
85 | static uint8_t in_data[] = {
|
---|
86 | 0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
87 | 0, 0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, // Caps Lock
|
---|
88 | 0, 0, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, // Num Lock
|
---|
89 | 0, 0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, // Caps Lock
|
---|
90 | 1 << 2, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
91 | 1 << 2, 0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
92 | 1 << 2, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
93 | 0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
94 | };
|
---|
95 | static vuhid_interface_life_t boot_life = {
|
---|
96 | .data_in = in_data,
|
---|
97 | .data_in_count = sizeof(in_data)/INPUT_SIZE,
|
---|
98 | .data_in_pos_change_delay = 500,
|
---|
99 | .msg_born = "Boot keyboard comes to life...",
|
---|
100 | .msg_die = "Boot keyboard died."
|
---|
101 | };
|
---|
102 |
|
---|
103 | static int on_data_out(vuhid_interface_t *iface,
|
---|
104 | const void *buffer, size_t buffer_size)
|
---|
105 | {
|
---|
106 | if (buffer_size == 0) {
|
---|
107 | return EEMPTY;
|
---|
108 | }
|
---|
109 | uint8_t leds = ((uint8_t *) buffer)[0];
|
---|
110 | #define _GET_LED(index, signature) \
|
---|
111 | (((leds) & (1 << index)) ? (signature) : '-')
|
---|
112 | usb_log_info("%s: LEDs = %c%c%c%c%c\n",
|
---|
113 | iface->name,
|
---|
114 | _GET_LED(0, '0'), _GET_LED(1, 'A'), _GET_LED(2, 's'),
|
---|
115 | _GET_LED(3, 'c'), _GET_LED(4, 'k'));
|
---|
116 | #undef _GET_LED
|
---|
117 | return EOK;
|
---|
118 | }
|
---|
119 |
|
---|
120 | vuhid_interface_t vuhid_interface_bootkbd = {
|
---|
121 | .id = "boot",
|
---|
122 | .name = "boot keyboard",
|
---|
123 | .usb_subclass = USB_HID_SUBCLASS_BOOT,
|
---|
124 | .usb_protocol = USB_HID_PROTOCOL_KEYBOARD,
|
---|
125 |
|
---|
126 | .report_descriptor = report_descriptor,
|
---|
127 | .report_descriptor_size = sizeof(report_descriptor),
|
---|
128 |
|
---|
129 | .in_data_size = INPUT_SIZE,
|
---|
130 | .on_data_in = interface_live_on_data_in,
|
---|
131 |
|
---|
132 | .out_data_size = 1,
|
---|
133 | .on_data_out = on_data_out,
|
---|
134 |
|
---|
135 | .live = interface_life_live,
|
---|
136 |
|
---|
137 | .interface_data = &boot_life,
|
---|
138 | .vuhid_data = NULL
|
---|
139 | };
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * @}
|
---|
143 | */
|
---|