source: mainline/uspace/app/vuhid/hids/bootkbd.c

Last change on this file was 904b1bc, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix remaining ccheck issues.

  • Property mode set to 100644
File size: 4.2 KB
Line 
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
43uint8_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
48 STD_USAGE_PAGE(USB_HIDUT_PAGE_KEYBOARD),
49 USAGE_MINIMUM1(224),
50 USAGE_MAXIMUM1(231),
51 LOGICAL_MINIMUM1(0),
52 LOGICAL_MAXIMUM1(1),
53 REPORT_SIZE1(1),
54 REPORT_COUNT1(8),
55 /* Modifiers */
56 INPUT(IOF_DATA | IOF_VARIABLE | IOF_ABSOLUTE),
57 REPORT_COUNT1(1),
58 REPORT_SIZE1(8),
59 /* Reserved */
60 INPUT(IOF_CONSTANT),
61 REPORT_COUNT1(5),
62 REPORT_SIZE1(1),
63 STD_USAGE_PAGE(USB_HIDUT_PAGE_LED),
64 USAGE_MINIMUM1(1),
65 USAGE_MAXIMUM1(5),
66 /* LED states */
67 OUTPUT(IOF_DATA | IOF_VARIABLE | IOF_ABSOLUTE),
68 REPORT_COUNT1(1),
69 REPORT_SIZE1(3),
70 /* LED states padding */
71 OUTPUT(IOF_CONSTANT),
72 REPORT_COUNT1(6),
73 REPORT_SIZE1(8),
74 LOGICAL_MINIMUM1(0),
75 LOGICAL_MAXIMUM1(101),
76 STD_USAGE_PAGE(USB_HIDUT_PAGE_KEYBOARD),
77 USAGE_MINIMUM1(0),
78 USAGE_MAXIMUM1(101),
79 /* Key array */
80 INPUT(IOF_DATA | IOF_ARRAY),
81
82 END_COLLECTION()
83};
84
85#define INPUT_SIZE 8
86
87static uint8_t in_data[] = {
88 0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89 0, 0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, // Caps Lock
90 0, 0, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, // Num Lock
91 0, 0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, // Caps Lock
92 1 << 2, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 1 << 2, 0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00,
94 1 << 2, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
96};
97static vuhid_interface_life_t boot_life = {
98 .data_in = in_data,
99 .data_in_count = sizeof(in_data) / INPUT_SIZE,
100 .data_in_pos_change_delay = 500,
101 .msg_born = "Boot keyboard comes to life...",
102 .msg_die = "Boot keyboard died."
103};
104
105static errno_t on_data_out(vuhid_interface_t *iface,
106 const void *buffer, size_t buffer_size)
107{
108 if (buffer_size == 0) {
109 return EEMPTY;
110 }
111 uint8_t leds = ((uint8_t *) buffer)[0];
112#define _GET_LED(index, signature) \
113 (((leds) & (1 << index)) ? (signature) : '-')
114 usb_log_info("%s: LEDs = %c%c%c%c%c",
115 iface->name,
116 _GET_LED(0, '0'), _GET_LED(1, 'A'), _GET_LED(2, 's'),
117 _GET_LED(3, 'c'), _GET_LED(4, 'k'));
118#undef _GET_LED
119 return EOK;
120}
121
122vuhid_interface_t vuhid_interface_bootkbd = {
123 .id = "boot",
124 .name = "boot keyboard",
125 .usb_subclass = USB_HID_SUBCLASS_BOOT,
126 .usb_protocol = USB_HID_PROTOCOL_KEYBOARD,
127
128 .report_descriptor = report_descriptor,
129 .report_descriptor_size = sizeof(report_descriptor),
130
131 .in_data_size = INPUT_SIZE,
132 .on_data_in = interface_live_on_data_in,
133
134 .out_data_size = 1,
135 .on_data_out = on_data_out,
136
137 .live = interface_life_live,
138
139 .interface_data = &boot_life,
140 .vuhid_data = NULL
141};
142
143/**
144 * @}
145 */
Note: See TracBrowser for help on using the repository browser.