HID/HostDevice.h
Go to the documentation of this file.
1 /****
2  * HID/HostDevice.h
3  *
4  * Copyright 2023 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming USB Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include "../HostInterface.h"
23 #include <debug_progmem.h>
24 
25 namespace USB::HID
26 {
27 struct Report : public DescriptorList {
28  unsigned parse(tuh_hid_report_info_t report_info_arr[], unsigned arr_count) const;
29 };
30 
31 class HostDevice : public HostInterface
32 {
33 public:
35 
36  using HostInterface::HostInterface;
37 
39  {
40  return tuh_hid_receive_report(inst.dev_addr, inst.idx);
41  }
42 
43  void onReport(ReportReceived callback)
44  {
45  reportReceivedCallback = callback;
46  }
47 
48  void reportReceived(const Report& report)
49  {
50  if(reportReceivedCallback) {
51  reportReceivedCallback(report);
52  }
53  }
54 
55 private:
56  ReportReceived reportReceivedCallback;
57 };
58 
66 
72 
77 void onMount(MountCallback callback);
78 
83 void onUnmount(UnmountCallback callback);
84 
85 } // namespace USB::HID
void onMount(MountCallback callback)
Application should call this method to receive device connection notifications.
Buffer containing list of descriptors.
Definition: Descriptors.h:78
Definition: HID/HostDevice.h:31
Definition: HID/HostDevice.h:27
void reportReceived(const Report &report)
Definition: HID/HostDevice.h:48
void onUnmount(UnmountCallback callback)
Application should call this method to receive device disconnection notifications.
Definition: Libraries/USB/src/USB/HID/Device.h:24
Common base class to support Host USB access.
Definition: HostInterface.h:29
bool requestReport()
Definition: HID/HostDevice.h:38
void onReport(ReportReceived callback)
Definition: HID/HostDevice.h:43
unsigned parse(tuh_hid_report_info_t report_info_arr[], unsigned arr_count) const