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:
34  using ReportReceived = Delegate<void(const Report& report)>;
35 
36  using HostInterface::HostInterface;
37 
38  bool requestReport()
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 
65 using MountCallback = Delegate<HostDevice*(const HostInterface::Instance& inst, const Report& report)>;
66 
71 using UnmountCallback = Delegate<void(HostDevice& dev)>;
72 
77 void onMount(MountCallback callback);
78 
83 void onUnmount(UnmountCallback callback);
84 
85 } // namespace USB::HID
Delegate< void(const Report &report)> ReportReceived
Definition: HID/HostDevice.h:51
Identifies a TinyUSB host interface.
Definition: HostInterface.h:69
void onMount(MountCallback callback)
Application should call this method to receive device connection notifications.
Definition: HID/HostDevice.h:48
Instance inst
Definition: HostInterface.h:118
Definition: HID/HostDevice.h:44
void reportReceived(const Report &report)
Definition: HID/HostDevice.h:65
unsigned parse(tuh_hid_report_info_t report_info_arr[], unsigned arr_count) const
bool requestReport()
Definition: HID/HostDevice.h:55
uint8_t idx
Index or instance value specific to class.
Definition: HostInterface.h:88
uint8_t dev_addr
Device address (from 1)
Definition: HostInterface.h:87
void onUnmount(UnmountCallback callback)
Application should call this method to receive device disconnection notifications.
void onReport(ReportReceived callback)
Definition: HID/HostDevice.h:60
Definition: Delegate.h:20
Definition: Libraries/USB/src/USB/HID/Device.h:24