esp-nimble-cpp 2.0.2
Loading...
Searching...
No Matches
NimBLEHIDDevice.h
1/*
2 * Copyright 2020-2024 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 "nimconfig.h"
22#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) && defined(CONFIG_BT_NIMBLE_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;
43
48 public:
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);
60 NimBLECharacteristic* getInputReport(uint8_t reportId);
61 NimBLECharacteristic* getOutputReport(uint8_t reportId);
62 NimBLECharacteristic* getFeatureReport(uint8_t reportId);
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* locateReportCharacteristicById(uint8_t reportId, uint8_t& reportType);
86};
87
88#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
89#endif // NIMBLE_CPP_HIDDEVICE_H_
The model of a BLE Characteristic.
Definition NimBLECharacteristic.h:40
A model of a BLE Human Interface Device.
Definition NimBLEHIDDevice.h:47
NimBLECharacteristic * getProtocolMode()
Get the HID protocol mode characteristic.
Definition NimBLEHIDDevice.cpp:300
NimBLECharacteristic * getHidInfo()
Get the HID information characteristic.
Definition NimBLEHIDDevice.cpp:332
NimBLEService * getHidService()
Get the HID service.
Definition NimBLEHIDDevice.cpp:348
NimBLECharacteristic * getBatteryLevel()
Get the battery level characteristic.
Definition NimBLEHIDDevice.cpp:308
bool setManufacturer(const std::string &name)
Get the manufacturer characteristic (this characteristic is optional).
Definition NimBLEHIDDevice.cpp:98
void startServices()
Start the HID device services. This function called when all the services have been created.
Definition NimBLEHIDDevice.cpp:87
NimBLEService * getDeviceInfoService()
Get the manufacturer characteristic.
Definition NimBLEHIDDevice.cpp:340
NimBLECharacteristic * getBootInput()
Get a keyboard boot input report characteristic.
Definition NimBLEHIDDevice.cpp:264
void setPnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version)
Sets the Plug n Play characteristic value.
Definition NimBLEHIDDevice.cpp:118
void setBatteryLevel(uint8_t level, bool notify=false)
Set the battery level characteristic value.
Definition NimBLEHIDDevice.cpp:145
NimBLECharacteristic * getHidControl()
Get the HID control point characteristic.
Definition NimBLEHIDDevice.cpp:292
NimBLECharacteristic * getPnp()
Get the PnP characteristic.
Definition NimBLEHIDDevice.cpp:324
void setReportMap(uint8_t *map, uint16_t)
Set the report map data formatting information.
Definition NimBLEHIDDevice.cpp:79
NimBLECharacteristic * getFeatureReport(uint8_t reportId)
Get the feature report characteristic.
Definition NimBLEHIDDevice.cpp:238
NimBLECharacteristic * getOutputReport(uint8_t reportId)
Get the output report characteristic.
Definition NimBLEHIDDevice.cpp:209
NimBLECharacteristic * getBootOutput()
Create a keyboard boot output report characteristic.
Definition NimBLEHIDDevice.cpp:278
NimBLEService * getBatteryService()
Get the battery service.
Definition NimBLEHIDDevice.cpp:356
void setHidInfo(uint8_t country, uint8_t flags)
Sets the HID Information characteristic value.
Definition NimBLEHIDDevice.cpp:135
NimBLECharacteristic * getInputReport(uint8_t reportId)
Get the input report characteristic.
Definition NimBLEHIDDevice.cpp:181
NimBLECharacteristic * getReportMap()
Get the report map characteristic.
Definition NimBLEHIDDevice.cpp:316
The model of a BLE server.
Definition NimBLEServer.h:60
The model of a BLE service.
Definition NimBLEService.h:34