esp-nimble-cpp 2.3.2
Loading...
Searching...
No Matches
NimBLEHIDDevice.h
1/*
2 * Copyright 2020-2025 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLE_CPP_HIDDEVICE_H_
19#define NIMBLE_CPP_HIDDEVICE_H_
20
21#include "syscfg/syscfg.h"
22#if CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
23
24# include <stdint.h>
25# include <string>
26
27# define GENERIC_HID 0x03C0
28# define HID_KEYBOARD 0x03C1
29# define HID_MOUSE 0x03C2
30# define HID_JOYSTICK 0x03C3
31# define HID_GAMEPAD 0x03C4
32# define HID_TABLET 0x03C5
33# define HID_CARD_READER 0x03C6
34# define HID_DIGITAL_PEN 0x03C7
35# define HID_BARCODE 0x03C8
36
37# define PNPVersionField(MajorVersion, MinorVersion, PatchVersion) \
38 ((MajorVersion << 16) & 0xFF00) | ((MinorVersion << 8) & 0x00F0) | (PatchVersion & 0x000F)
39
40class NimBLEServer;
41class NimBLEService;
42class NimBLECharacteristic;
43
47class NimBLEHIDDevice {
48 public:
49 NimBLEHIDDevice(NimBLEServer* server);
50
51 void setReportMap(uint8_t* map, uint16_t);
52 void startServices();
53 bool setManufacturer(const std::string& name);
54 void setPnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version);
55 void setHidInfo(uint8_t country, uint8_t flags);
56 void setBatteryLevel(uint8_t level, bool notify = false);
57 NimBLECharacteristic* getBatteryLevel();
58 NimBLECharacteristic* getReportMap();
59 NimBLECharacteristic* getHidControl();
60 NimBLECharacteristic* getInputReport(uint8_t reportId);
61 NimBLECharacteristic* getOutputReport(uint8_t reportId);
62 NimBLECharacteristic* getFeatureReport(uint8_t reportId);
63 NimBLECharacteristic* getProtocolMode();
64 NimBLECharacteristic* getBootInput();
65 NimBLECharacteristic* getBootOutput();
66 NimBLECharacteristic* getPnp();
67 NimBLECharacteristic* getHidInfo();
68 NimBLEService* getDeviceInfoService();
69 NimBLEService* getHidService();
70 NimBLEService* getBatteryService();
71
72 private:
73 NimBLEService* m_deviceInfoSvc{nullptr}; // 0x180a
74 NimBLEService* m_hidSvc{nullptr}; // 0x1812
75 NimBLEService* m_batterySvc{nullptr}; // 0x180f
76
77 NimBLECharacteristic* m_manufacturerChr{nullptr}; // 0x2a29
78 NimBLECharacteristic* m_pnpChr{nullptr}; // 0x2a50
79 NimBLECharacteristic* m_hidInfoChr{nullptr}; // 0x2a4a
80 NimBLECharacteristic* m_reportMapChr{nullptr}; // 0x2a4b
81 NimBLECharacteristic* m_hidControlChr{nullptr}; // 0x2a4c
82 NimBLECharacteristic* m_protocolModeChr{nullptr}; // 0x2a4e
83 NimBLECharacteristic* m_batteryLevelChr{nullptr}; // 0x2a19
84
85 NimBLECharacteristic* locateReportCharacteristicByIdAndType(uint8_t reportId, uint8_t reportType);
86};
87
88#endif // CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
89#endif // NIMBLE_CPP_HIDDEVICE_H_