HostInterface.h
Go to the documentation of this file.
1 /****
2  * HostInterface.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 "Descriptors.h"
23 
24 namespace USB
25 {
30 {
31 public:
35  struct Instance {
36  uint8_t dev_addr{255};
37  uint8_t idx{255};
38  const char* name;
39 
40  bool operator==(const Instance& other) const
41  {
42  return dev_addr == other.dev_addr && idx == other.idx;
43  }
44  };
45 
49  void begin(const Instance& inst)
50  {
51  this->inst = inst;
52  }
53 
57  virtual void end()
58  {
59  inst.dev_addr = 255;
60  inst.idx = 255;
61  }
62 
63  const char* getName() const
64  {
65  return inst.name;
66  }
67 
68  uint8_t getAddress() const
69  {
70  return inst.dev_addr;
71  }
72 
73  bool operator==(const HostInterface& other) const
74  {
75  return inst == other.inst;
76  }
77 
78  bool operator==(const Instance& other) const
79  {
80  return inst == other;
81  }
82 
83 protected:
85 };
86 
87 } // namespace USB
Common base class to support Host USB access.
Definition: HostInterface.h:30
Instance inst
Definition: HostInterface.h:84
void begin(const Instance &inst)
Descendant classes should override this method to peform initialisation.
Definition: HostInterface.h:49
virtual void end()
Called when device is disconnected. Override as required.
Definition: HostInterface.h:57
bool operator==(const HostInterface &other) const
Definition: HostInterface.h:73
uint8_t getAddress() const
Definition: HostInterface.h:68
bool operator==(const Instance &other) const
Definition: HostInterface.h:78
const char * getName() const
Definition: HostInterface.h:63
Definition: Libraries/USB/src/USB/CDC/Device.h:26
Identifies a TinyUSB host interface.
Definition: HostInterface.h:35
uint8_t dev_addr
Device address (from 1)
Definition: HostInterface.h:36
bool operator==(const Instance &other) const
Definition: HostInterface.h:40
const char * name
Optional name for this interface instance.
Definition: HostInterface.h:38
uint8_t idx
Index or instance value specific to class.
Definition: HostInterface.h:37