1- /*
2- * Licensed to the Apache Software Foundation (ASF) under one
3- * or more contributor license agreements. See the NOTICE file
4- * distributed with this work for additional information
5- * regarding copyright ownership. The ASF licenses this file
6- * to you under the Apache License, Version 2.0 (the
7- * "License"); you may not use this file except in compliance
8- * with the License. You may obtain a copy of the License at
9- *
10- * http://www.apache.org/licenses/LICENSE-2.0
11- *
12- * Unless required by applicable law or agreed to in writing,
13- * software distributed under the License is distributed on an
14- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15- * KIND, either express or implied. See the License for the
16- * specific language governing permissions and limitations
17- * under the License.
18- */
19-
201#include <assert.h>
212#include <stdio.h>
223#include <string.h>
@@ -32,138 +13,31 @@ static const char *firmware_rev = "2.0";
3213static const char * software_rev = "4.8" ;
3314
3415static const uint8_t hidReportMap [] = {
35- 0x05 , 0x01 , // Usage Page (Generic Desktop)
36- 0x09 , 0x02 , // Usage (Mouse)
37- 0xA1 , 0x01 , // Collection (Application)
38- 0x85 , 0x01 , // Report Id (1)
39- 0x09 , 0x01 , // Usage (Pointer)
40- 0xA1 , 0x00 , // Collection (Physical)
41- 0x05 , 0x09 , // Usage Page (Buttons)
42- 0x19 , 0x01 , // Usage Minimum (01) - Button 1
43- 0x29 , 0x03 , // Usage Maximum (03) - Button 3
44- 0x15 , 0x00 , // Logical Minimum (0)
45- 0x25 , 0x01 , // Logical Maximum (1)
46- 0x75 , 0x01 , // Report Size (1)
47- 0x95 , 0x03 , // Report Count (3)
48- 0x81 , 0x02 , // Input (Data, Variable, Absolute) - Button states
49- 0x75 , 0x05 , // Report Size (5)
50- 0x95 , 0x01 , // Report Count (1)
51- 0x81 , 0x01 , // Input (Constant) - Padding or Reserved bits
52- 0x05 , 0x01 , // Usage Page (Generic Desktop)
53- 0x09 , 0x30 , // Usage (X)
54- 0x09 , 0x31 , // Usage (Y)
55- 0x09 , 0x38 , // Usage (Wheel)
56- 0x15 , 0x81 , // Logical Minimum (-127)
57- 0x25 , 0x7F , // Logical Maximum (127)
58- 0x75 , 0x08 , // Report Size (8)
59- 0x95 , 0x03 , // Report Count (3)
60- 0x81 , 0x06 , // Input (Data, Variable, Relative) - X & Y coordinate
61- 0xC0 , // End Collection
62- 0xC0 , // End Collection
63-
64- 0x05 , 0x01 , // Usage Pg (Generic Desktop)
65- 0x09 , 0x06 , // Usage (Keyboard)
66- 0xA1 , 0x01 , // Collection: (Application)
67- 0x85 , 0x02 , // Report Id (2)
68- //
69- 0x05 , 0x07 , // Usage Pg (Key Codes)
70- 0x19 , 0xE0 , // Usage Min (224)
71- 0x29 , 0xE7 , // Usage Max (231)
72- 0x15 , 0x00 , // Log Min (0)
73- 0x25 , 0x01 , // Log Max (1)
74- //
75- // Modifier byte
76- 0x75 , 0x01 , // Report Size (1)
77- 0x95 , 0x08 , // Report Count (8)
78- 0x81 , 0x02 , // Input: (Data, Variable, Absolute)
79- //
80- // Reserved byte
81- 0x95 , 0x01 , // Report Count (1)
82- 0x75 , 0x08 , // Report Size (8)
83- 0x81 , 0x01 , // Input: (Constant)
84- //
85- // LED report
86- 0x95 , 0x05 , // Report Count (5)
87- 0x75 , 0x01 , // Report Size (1)
88- 0x05 , 0x08 , // Usage Pg (LEDs)
89- 0x19 , 0x01 , // Usage Min (1)
90- 0x29 , 0x05 , // Usage Max (5)
91- 0x91 , 0x02 , // Output: (Data, Variable, Absolute)
92- //
93- // LED report padding
94- 0x95 , 0x01 , // Report Count (1)
95- 0x75 , 0x03 , // Report Size (3)
96- 0x91 , 0x01 , // Output: (Constant)
97- //
98- // Key arrays (6 bytes)
99- 0x95 , 0x06 , // Report Count (6)
100- 0x75 , 0x08 , // Report Size (8)
101- 0x15 , 0x00 , // Log Min (0)
102- 0x25 , 0x65 , // Log Max (101)
103- 0x05 , 0x07 , // Usage Pg (Key Codes)
104- 0x19 , 0x00 , // Usage Min (0)
105- 0x29 , 0x65 , // Usage Max (101)
106- 0x81 , 0x00 , // Input: (Data, Array)
107- //
108- 0xC0 , // End Collection
109- //
110- 0x05 , 0x0C , // Usage Pg (Consumer Devices)
111- 0x09 , 0x01 , // Usage (Consumer Control)
112- 0xA1 , 0x01 , // Collection (Application)
113- 0x85 , 0x03 , // Report Id (3)
114- 0x09 , 0x02 , // Usage (Numeric Key Pad)
115- 0xA1 , 0x02 , // Collection (Logical)
116- 0x05 , 0x09 , // Usage Pg (Button)
117- 0x19 , 0x01 , // Usage Min (Button 1)
118- 0x29 , 0x0A , // Usage Max (Button 10)
119- 0x15 , 0x01 , // Logical Min (1)
120- 0x25 , 0x0A , // Logical Max (10)
121- 0x75 , 0x04 , // Report Size (4)
122- 0x95 , 0x01 , // Report Count (1)
123- 0x81 , 0x00 , // Input (Data, Ary, Abs)
124- 0xC0 , // End Collection
125- 0x05 , 0x0C , // Usage Pg (Consumer Devices)
126- 0x09 , 0x86 , // Usage (Channel)
127- 0x15 , 0xFF , // Logical Min (-1)
128- 0x25 , 0x01 , // Logical Max (1)
129- 0x75 , 0x02 , // Report Size (2)
130- 0x95 , 0x01 , // Report Count (1)
131- 0x81 , 0x46 , // Input (Data, Var, Rel, Null)
132- 0x09 , 0xE9 , // Usage (Volume Up)
133- 0x09 , 0xEA , // Usage (Volume Down)
134- 0x15 , 0x00 , // Logical Min (0)
135- 0x75 , 0x01 , // Report Size (1)
136- 0x95 , 0x02 , // Report Count (2)
137- 0x81 , 0x02 , // Input (Data, Var, Abs)
138- 0x09 , 0xE2 , // Usage (Mute)
139- 0x09 , 0x30 , // Usage (Power)
140- 0x09 , 0x83 , // Usage (Recall Last)
141- 0x09 , 0x81 , // Usage (Assign Selection)
142- 0x09 , 0xB0 , // Usage (Play)
143- 0x09 , 0xB1 , // Usage (Pause)
144- 0x09 , 0xB2 , // Usage (Record)
145- 0x09 , 0xB3 , // Usage (Fast Forward)
146- 0x09 , 0xB4 , // Usage (Rewind)
147- 0x09 , 0xB5 , // Usage (Scan Next)
148- 0x09 , 0xB6 , // Usage (Scan Prev)
149- 0x09 , 0xB7 , // Usage (Stop)
150- 0x15 , 0x01 , // Logical Min (1)
151- 0x25 , 0x0C , // Logical Max (12)
152- 0x75 , 0x04 , // Report Size (4)
153- 0x95 , 0x01 , // Report Count (1)
154- 0x81 , 0x00 , // Input (Data, Ary, Abs)
155- 0x09 , 0x80 , // Usage (Selection)
156- 0xA1 , 0x02 , // Collection (Logical)
157- 0x05 , 0x09 , // Usage Pg (Button)
158- 0x19 , 0x01 , // Usage Min (Button 1)
159- 0x29 , 0x03 , // Usage Max (Button 3)
160- 0x15 , 0x01 , // Logical Min (1)
161- 0x25 , 0x03 , // Logical Max (3)
162- 0x75 , 0x02 , // Report Size (2)
163- 0x81 , 0x00 , // Input (Data, Ary, Abs)
164- 0xC0 , // End Collection
165- 0x81 , 0x03 , // Input (Const, Var, Abs)
166- 0xC0 , // End Collectionq
16+ 0x05 , 0x0C , // Usage Page (Consumer)
17+ 0x09 , 0x01 , // Usage (Consumer Control)
18+ 0xA1 , 0x01 , // Collection (Application)
19+ 0x15 , 0x00 , // Logical Minimum (0)
20+ 0x25 , 0x01 , // Logical Maximum (1)
21+ 0x09 , 0xE9 , // Usage (Volume Increment)
22+ 0x09 , 0xEA , // Usage (Volume Decrement)
23+ 0x75 , 0x01 , // Report Size (1)
24+ 0x95 , 0x02 , // Report Count (2)
25+ 0x81 , 0x02 , // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
26+ 0x09 , 0xE2 , // Usage (Mute)
27+ 0x09 , 0x00 , // Usage (Unassigned)
28+ 0x81 , 0x06 , // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position)
29+ 0x09 , 0x00 , // Usage (Unassigned)
30+ 0x95 , 0x04 , // Report Count (4)
31+ 0x81 , 0x02 , // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
32+ 0x26 , 0xFF , 0x00 , // Logical Maximum (255)
33+ 0x09 , 0x00 , // Usage (Unassigned)
34+ 0x75 , 0x08 , // Report Size (8)
35+ 0x95 , 0x03 , // Report Count (3)
36+ 0x81 , 0x02 , // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
37+ 0x09 , 0x00 , // Usage (Unassigned)
38+ 0x95 , 0x04 , // Report Count (4)
39+ 0x91 , 0x02 , // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
40+ 0xC0 , // End Collection
16741};
16842
16943static const uint8_t hidInfo [HID_INFORMATION_LEN ] = {
@@ -173,16 +47,11 @@ static const uint8_t hidInfo[HID_INFORMATION_LEN] = {
17347};
17448
17549static const uint8_t reportReferenceChar [2 ] = {
176- 0x01 , //report-id des reports vom report deskriptor
50+ 0x00 , //report-id des reports vom report deskriptor
17751 0x01 //input: 0x01, output: 0x02, feature: 0x03
17852};
17953
180- static const uint8_t reportData [2 ] = {
181- 0x12 ,
182- 0xEF
183- };
184-
185- uint16_t hrs_hrm_handle ;
54+ uint16_t report_data_handle ;
18655
18756static int
18857gatt_svr_chr_access_heart_rate (uint16_t conn_handle , uint16_t attr_handle ,
@@ -201,28 +70,6 @@ report_descriptor_callback(uint16_t conn_handle, uint16_t attr_handle,
20170 struct ble_gatt_access_ctxt * ctxt , void * arg );
20271
20372static const struct ble_gatt_svc_def gatt_svr_svcs [] = {
204- {
205- /* Service: Heart-rate */
206- .type = BLE_GATT_SVC_TYPE_PRIMARY ,
207- .uuid = BLE_UUID16_DECLARE (GATT_HRS_UUID ),
208- .characteristics = (struct ble_gatt_chr_def [])
209- { {
210- /* Characteristic: Heart-rate measurement */
211- .uuid = BLE_UUID16_DECLARE (GATT_HRS_MEASUREMENT_UUID ),
212- .access_cb = gatt_svr_chr_access_heart_rate ,
213- .val_handle = & hrs_hrm_handle ,
214- .flags = BLE_GATT_CHR_F_NOTIFY ,
215- }, {
216- /* Characteristic: Body sensor location */
217- .uuid = BLE_UUID16_DECLARE (GATT_HRS_BODY_SENSOR_LOC_UUID ),
218- .access_cb = gatt_svr_chr_access_heart_rate ,
219- .flags = BLE_GATT_CHR_F_READ ,
220- }, {
221- 0 , /* No more characteristics in this service */
222- },
223- }
224- },
225-
22673 {
22774 /* Service: Device Information */
22875 .type = BLE_GATT_SVC_TYPE_PRIMARY ,
@@ -294,7 +141,7 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
294141 /* Characteristic: Report Input, Pro Report Collection wird ein Reportmerkmal benötigt */
295142 .uuid = BLE_UUID16_DECLARE (GATT_HID_REPORT_UUID ),
296143 .access_cb = gatt_svr_chr_hid ,
297- // .val_handle = &hrs_hrm_handle ,
144+ .val_handle = & report_data_handle ,
298145 .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY ,
299146 .descriptors = (struct ble_gatt_dsc_def []){
300147 //client configuration descriptor soll nicht manuell hinzugefügt werden, da dieser mittels dem flag notify automatisch hinzugefügt wird
@@ -371,27 +218,6 @@ static int gatt_svr_chr_hid(uint16_t conn_handle, uint16_t attr_handle,
371218 return BLE_ATT_ERR_UNLIKELY ;
372219}
373220
374- static int
375- gatt_svr_chr_access_heart_rate (uint16_t conn_handle , uint16_t attr_handle ,
376- struct ble_gatt_access_ctxt * ctxt , void * arg )
377- {
378- /* Sensor location, set to "Chest" */
379- static uint8_t body_sens_loc = 0x01 ;
380- uint16_t uuid ;
381- int rc ;
382-
383- uuid = ble_uuid_u16 (ctxt -> chr -> uuid );
384-
385- if (uuid == GATT_HRS_BODY_SENSOR_LOC_UUID ) {
386- rc = os_mbuf_append (ctxt -> om , & body_sens_loc , sizeof (body_sens_loc ));
387-
388- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES ;
389- }
390-
391- assert (0 );
392- return BLE_ATT_ERR_UNLIKELY ;
393- }
394-
395221static int
396222gatt_svr_chr_access_device_info (uint16_t conn_handle , uint16_t attr_handle ,
397223 struct ble_gatt_access_ctxt * ctxt , void * arg )
0 commit comments