xref: /btstack/src/btstack_hid.c (revision 3cbedd4337c5f865d4c28535558ba1f75f168a17)
1*3cbedd43SMatthias Ringwald /*
2*3cbedd43SMatthias Ringwald  * Copyright (C) 2021 BlueKitchen GmbH
3*3cbedd43SMatthias Ringwald  *
4*3cbedd43SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5*3cbedd43SMatthias Ringwald  * modification, are permitted provided that the following conditions
6*3cbedd43SMatthias Ringwald  * are met:
7*3cbedd43SMatthias Ringwald  *
8*3cbedd43SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9*3cbedd43SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10*3cbedd43SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11*3cbedd43SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12*3cbedd43SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13*3cbedd43SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14*3cbedd43SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15*3cbedd43SMatthias Ringwald  *    from this software without specific prior written permission.
16*3cbedd43SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17*3cbedd43SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18*3cbedd43SMatthias Ringwald  *    monetary gain.
19*3cbedd43SMatthias Ringwald  *
20*3cbedd43SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21*3cbedd43SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*3cbedd43SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*3cbedd43SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24*3cbedd43SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*3cbedd43SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*3cbedd43SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27*3cbedd43SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*3cbedd43SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*3cbedd43SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30*3cbedd43SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*3cbedd43SMatthias Ringwald  * SUCH DAMAGE.
32*3cbedd43SMatthias Ringwald  *
33*3cbedd43SMatthias Ringwald  * Please inquire about commercial licensing options at
34*3cbedd43SMatthias Ringwald  * [email protected]
35*3cbedd43SMatthias Ringwald  *
36*3cbedd43SMatthias Ringwald  */
37*3cbedd43SMatthias Ringwald 
38*3cbedd43SMatthias Ringwald #include "btstack_hid.h"
39*3cbedd43SMatthias Ringwald 
40*3cbedd43SMatthias Ringwald 
41*3cbedd43SMatthias Ringwald // from USB HID Specification 1.1, Appendix B.1
42*3cbedd43SMatthias Ringwald const uint8_t hid_descriptor_boot_mode[] = {
43*3cbedd43SMatthias Ringwald     // Keyboard
44*3cbedd43SMatthias Ringwald 
45*3cbedd43SMatthias Ringwald     0x05, 0x01,                    // Usage Page (Generic Desktop)
46*3cbedd43SMatthias Ringwald     0x09, 0x06,                    // Usage (Keyboard)
47*3cbedd43SMatthias Ringwald     0xa1, 0x01,                    // Collection (Application)
48*3cbedd43SMatthias Ringwald 
49*3cbedd43SMatthias Ringwald     0x85,  0x01,                   // Report ID 1
50*3cbedd43SMatthias Ringwald 
51*3cbedd43SMatthias Ringwald     // Modifier byte
52*3cbedd43SMatthias Ringwald 
53*3cbedd43SMatthias Ringwald     0x75, 0x01,                    //   Report Size (1)
54*3cbedd43SMatthias Ringwald     0x95, 0x08,                    //   Report Count (8)
55*3cbedd43SMatthias Ringwald     0x05, 0x07,                    //   Usage Page (Key codes)
56*3cbedd43SMatthias Ringwald     0x19, 0xe0,                    //   Usage Minimum (Keyboard LeftControl)
57*3cbedd43SMatthias Ringwald     0x29, 0xe7,                    //   Usage Maxium (Keyboard Right GUI)
58*3cbedd43SMatthias Ringwald     0x15, 0x00,                    //   Logical Minimum (0)
59*3cbedd43SMatthias Ringwald     0x25, 0x01,                    //   Logical Maximum (1)
60*3cbedd43SMatthias Ringwald     0x81, 0x02,                    //   Input (Data, Variable, Absolute)
61*3cbedd43SMatthias Ringwald 
62*3cbedd43SMatthias Ringwald     // Reserved byte
63*3cbedd43SMatthias Ringwald 
64*3cbedd43SMatthias Ringwald     0x75, 0x01,                    //   Report Size (1)
65*3cbedd43SMatthias Ringwald     0x95, 0x08,                    //   Report Count (8)
66*3cbedd43SMatthias Ringwald     0x81, 0x03,                    //   Input (Constant, Variable, Absolute)
67*3cbedd43SMatthias Ringwald 
68*3cbedd43SMatthias Ringwald     // LED report + padding
69*3cbedd43SMatthias Ringwald 
70*3cbedd43SMatthias Ringwald     0x95, 0x05,                    //   Report Count (5)
71*3cbedd43SMatthias Ringwald     0x75, 0x01,                    //   Report Size (1)
72*3cbedd43SMatthias Ringwald     0x05, 0x08,                    //   Usage Page (LEDs)
73*3cbedd43SMatthias Ringwald     0x19, 0x01,                    //   Usage Minimum (Num Lock)
74*3cbedd43SMatthias Ringwald     0x29, 0x05,                    //   Usage Maxium (Kana)
75*3cbedd43SMatthias Ringwald     0x91, 0x02,                    //   Output (Data, Variable, Absolute)
76*3cbedd43SMatthias Ringwald 
77*3cbedd43SMatthias Ringwald     0x95, 0x01,                    //   Report Count (1)
78*3cbedd43SMatthias Ringwald     0x75, 0x03,                    //   Report Size (3)
79*3cbedd43SMatthias Ringwald     0x91, 0x03,                    //   Output (Constant, Variable, Absolute)
80*3cbedd43SMatthias Ringwald 
81*3cbedd43SMatthias Ringwald     // Keycodes
82*3cbedd43SMatthias Ringwald 
83*3cbedd43SMatthias Ringwald     0x95, 0x06,                    //   Report Count (6)
84*3cbedd43SMatthias Ringwald     0x75, 0x08,                    //   Report Size (8)
85*3cbedd43SMatthias Ringwald     0x15, 0x00,                    //   Logical Minimum (0)
86*3cbedd43SMatthias Ringwald     0x25, 0xff,                    //   Logical Maximum (1)
87*3cbedd43SMatthias Ringwald     0x05, 0x07,                    //   Usage Page (Key codes)
88*3cbedd43SMatthias Ringwald     0x19, 0x00,                    //   Usage Minimum (Reserved (no event indicated))
89*3cbedd43SMatthias Ringwald     0x29, 0xff,                    //   Usage Maxium (Reserved)
90*3cbedd43SMatthias Ringwald     0x81, 0x00,                    //   Input (Data, Array)
91*3cbedd43SMatthias Ringwald 
92*3cbedd43SMatthias Ringwald     0xc0,                          // End collection
93*3cbedd43SMatthias Ringwald 
94*3cbedd43SMatthias Ringwald     // Mouse
95*3cbedd43SMatthias Ringwald     0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
96*3cbedd43SMatthias Ringwald     0x09, 0x02,                    // USAGE (Mouse)
97*3cbedd43SMatthias Ringwald     0xa1, 0x01,                    // COLLECTION (Application)
98*3cbedd43SMatthias Ringwald 
99*3cbedd43SMatthias Ringwald     0x85,  0x01,                    // Report ID 1
100*3cbedd43SMatthias Ringwald 
101*3cbedd43SMatthias Ringwald     0x09, 0x01,                    //   USAGE (Pointer)
102*3cbedd43SMatthias Ringwald 
103*3cbedd43SMatthias Ringwald     0xa1, 0x00,                    //   COLLECTION (Physical)
104*3cbedd43SMatthias Ringwald 
105*3cbedd43SMatthias Ringwald #if 1
106*3cbedd43SMatthias Ringwald     0x05, 0x09,                    //     USAGE_PAGE (Button)
107*3cbedd43SMatthias Ringwald     0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
108*3cbedd43SMatthias Ringwald     0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
109*3cbedd43SMatthias Ringwald     0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
110*3cbedd43SMatthias Ringwald     0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
111*3cbedd43SMatthias Ringwald     0x95, 0x03,                    //     REPORT_COUNT (3)
112*3cbedd43SMatthias Ringwald     0x75, 0x01,                    //     REPORT_SIZE (1)
113*3cbedd43SMatthias Ringwald     0x81, 0x02,                    //     INPUT (Data,Var,Abs)
114*3cbedd43SMatthias Ringwald     0x95, 0x01,                    //     REPORT_COUNT (1)
115*3cbedd43SMatthias Ringwald     0x75, 0x05,                    //     REPORT_SIZE (5)
116*3cbedd43SMatthias Ringwald     0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
117*3cbedd43SMatthias Ringwald #endif
118*3cbedd43SMatthias Ringwald 
119*3cbedd43SMatthias Ringwald #if 1
120*3cbedd43SMatthias Ringwald     0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
121*3cbedd43SMatthias Ringwald     0x09, 0x30,                    //     USAGE (X)
122*3cbedd43SMatthias Ringwald     0x09, 0x31,                    //     USAGE (Y)
123*3cbedd43SMatthias Ringwald     0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
124*3cbedd43SMatthias Ringwald     0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
125*3cbedd43SMatthias Ringwald     0x75, 0x08,                    //     REPORT_SIZE (8)
126*3cbedd43SMatthias Ringwald     0x95, 0x02,                    //     REPORT_COUNT (2)
127*3cbedd43SMatthias Ringwald     0x81, 0x06,                    //     INPUT (Data,Var,Rel)
128*3cbedd43SMatthias Ringwald #endif
129*3cbedd43SMatthias Ringwald 
130*3cbedd43SMatthias Ringwald     0xc0,                          //   END_COLLECTION
131*3cbedd43SMatthias Ringwald     0xc0                           // END_COLLECTION
132*3cbedd43SMatthias Ringwald };
133*3cbedd43SMatthias Ringwald 
134*3cbedd43SMatthias Ringwald const uint8_t * hid_get_boot_descriptor_data(void){
135*3cbedd43SMatthias Ringwald     return &hid_descriptor_boot_mode[0];
136*3cbedd43SMatthias Ringwald }
137*3cbedd43SMatthias Ringwald 
138*3cbedd43SMatthias Ringwald uint16_t hid_get_boot_descriptor_len(void){
139*3cbedd43SMatthias Ringwald     return sizeof(hid_descriptor_boot_mode);
140*3cbedd43SMatthias Ringwald }
141*3cbedd43SMatthias Ringwald 
142