libtransistor
A userland library for the Nintendo Switch
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
usb_ds.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include<libtransistor/cpp/types.hpp>
11 
12 #include<memory>
13 
14 namespace trn {
15 namespace service {
16 namespace usb {
17 namespace ds {
18 
19 enum class State : uint32_t {
20  INITIAL = USB_DS_STATE_INITIAL,
21  INIT_STARTING = USB_DS_STATE_INIT_STARTING,
22  INIT2 = USB_DS_STATE_INIT2,
23  INIT3 = USB_DS_STATE_INIT3,
24  INITIALIZED = USB_DS_STATE_INITIALIZED,
25 };
26 
27 class Interface;
28 class Endpoint;
29 
30 class DS {
31  public:
32  static Result<DS> Initialize(uint32_t complex_id, usb_device_data_t *device_data);
33  DS(const DS& other);
34  DS(DS&& other);
35  ~DS();
36 
37  Result<KEvent> GetStateChangeEvent();
38  Result<State> GetState();
39  Result<std::shared_ptr<Interface>> GetInterface(usb_interface_descriptor_t &descriptor, const char *name);
40 
41  private:
42  DS(uint32_t complex_id, usb_device_data_t *device_data); // use DS::Initialize
43  uint32_t complex_id;
44  usb_device_data_t *device_data;
45 };
46 
47 class Interface {
48  public:
50 
51  Result<std::nullopt_t> Enable();
52  Result<std::nullopt_t> Disable();
53  Result<std::shared_ptr<Endpoint>> GetEndpoint(usb_endpoint_descriptor_t &descriptor);
54  Result<std::shared_ptr<Endpoint>> GetCtrlInEndpoint();
55  Result<std::shared_ptr<Endpoint>> GetCtrlOutEndpoint();
56  Result<std::nullopt_t> StallCtrl();
57 
58  ~Interface();
59  private:
60  usb_ds_interface_t intf;
61 };
62 
63 class Endpoint {
64  public:
65  Endpoint(KEvent &&completion_event);
66 
67  // returns urb_id
68  virtual Result<uint32_t> PostBufferAsync(void *buffer, size_t size) = 0;
69  virtual Result<usb_ds_report_t> GetReportData() = 0;
70  virtual Result<std::nullopt_t> Stall() = 0;
71 
72  KEvent completion_event;
73 
74  virtual ~Endpoint() = 0;
75 };
76 
77 }
78 }
79 }
80 }
Definition: usb_ds.hpp:47
Definition: types.hpp:126
Definition: usb.h:122
Definition: interface.h:20
USB Services.
USB definitions (C++ header)
Definition: usb_ds.hpp:63
Definition: usb_ds.hpp:30