VENDOR/HostDevice.h
Go to the documentation of this file.
1 /****
2  * VENDOR/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 #include <bitset>
25 
26 namespace USB::VENDOR
27 {
31 class HostDevice : public HostInterface
32 {
33 public:
37  struct Config {
41  };
42 
46  struct Transfer {
49  xfer_result_t result;
50  uint32_t xferred_bytes;
51  };
52 
53  using HostInterface::HostInterface;
54 
55  void end() override
56  {
57  ep_mask.reset();
58  }
59 
65  virtual bool setConfig(uint8_t itf_num) = 0;
66 
70  virtual bool transferComplete(const Transfer& txfr) = 0;
71 
72  bool ownsEndpoint(uint8_t ep_addr);
73 
74 protected:
81  bool openEndpoint(const tusb_desc_endpoint_t& ep_desc);
82 
83 private:
84  std::bitset<32> ep_mask{};
85 };
86 
94 
100 
105 void onMount(MountCallback callback);
106 
111 void onUnmount(UnmountCallback callback);
112 
113 } // namespace USB::VENDOR
uint16_t vid
Vendor ID.
Definition: VENDOR/HostDevice.h:38
uint8_t dev_addr
Definition: VENDOR/HostDevice.h:47
DescriptorList list
Interface descriptor list.
Definition: VENDOR/HostDevice.h:40
Structure passed to &#39;transferComplete&#39; method.
Definition: VENDOR/HostDevice.h:46
virtual bool transferComplete(const Transfer &txfr)=0
Called when a non-control USB transfer has completed.
Buffer containing list of descriptors.
Definition: Descriptors.h:78
xfer_result_t result
Definition: VENDOR/HostDevice.h:49
bool openEndpoint(const tusb_desc_endpoint_t &ep_desc)
Implementations should call this method during initialisation.
void onMount(MountCallback callback)
Application should call this method to receive device connection notifications.
Definition: Delegate.h:20
bool ownsEndpoint(uint8_t ep_addr)
virtual bool setConfig(uint8_t itf_num)=0
Set active configuration.
uint16_t pid
Product ID.
Definition: VENDOR/HostDevice.h:39
Common base class to support Host USB access.
Definition: HostInterface.h:29
Base class to use for custom devices.
Definition: VENDOR/HostDevice.h:31
void end() override
Called when device is disconnected. Override as required.
Definition: VENDOR/HostDevice.h:55
uint8_t ep_addr
Definition: VENDOR/HostDevice.h:48
Device configuration received during mount procedure.
Definition: VENDOR/HostDevice.h:37
void onUnmount(UnmountCallback callback)
Application should call this method to receive device disconnection notifications.
Definition: Libraries/USB/src/USB/VENDOR/Device.h:25
uint32_t xferred_bytes
Definition: VENDOR/HostDevice.h:50