usb: add ds client api

This commit is contained in:
Michael Scire 2021-02-07 16:29:38 -08:00
parent 621520c30b
commit 13b17a5848
21 changed files with 1993 additions and 0 deletions

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/usb/usb_limits.hpp>
#include <stratosphere/usb/usb_types.hpp>
#include <stratosphere/usb/usb_device_types.hpp>
#include <stratosphere/usb/usb_device.hpp>

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/usb/usb_limits.hpp>
#include <stratosphere/usb/usb_types.hpp>
#include <stratosphere/usb/usb_device_types.hpp>
#define AMS_USB_I_DS_ENDPOINT_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, PostBufferAsync, (sf::Out<u32> out_urb_id, u64 address, u32 size), (out_urb_id, address, size)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, Cancel, (), ()) \
AMS_SF_METHOD_INFO(C, H, 2, Result, GetCompletionEvent, (sf::OutCopyHandle out), (out)) \
AMS_SF_METHOD_INFO(C, H, 3, Result, GetUrbReport, (sf::Out<usb::UrbReport> out), (out)) \
AMS_SF_METHOD_INFO(C, H, 4, Result, Stall, (), ()) \
AMS_SF_METHOD_INFO(C, H, 5, Result, SetZlt, (bool zlt), (zlt))
/* TODO: Deprecated interface? */
AMS_SF_DEFINE_INTERFACE(ams::usb::ds, IDsEndpoint, AMS_USB_I_DS_ENDPOINT_INTERFACE_INFO)

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/usb/usb_limits.hpp>
#include <stratosphere/usb/usb_types.hpp>
#include <stratosphere/usb/usb_device_types.hpp>
#include <stratosphere/usb/ds/usb_i_ds_endpoint.hpp>
#define AMS_USB_I_DS_INTERFACE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, RegisterEndpoint, (u8 endpoint_address, sf::Out<sf::SharedPointer<usb::ds::IDsEndpoint>> out), (endpoint_address, out)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, GetSetupEvent, (sf::OutCopyHandle out), (out)) \
AMS_SF_METHOD_INFO(C, H, 2, Result, GetSetupPacket, (const sf::OutBuffer &out), (out)) \
AMS_SF_METHOD_INFO(C, H, 3, Result, CtrlInAsync, (sf::Out<u32> out_urb_id, u64 address, u32 size), (out_urb_id, address, size)) \
AMS_SF_METHOD_INFO(C, H, 4, Result, CtrlOutAsync, (sf::Out<u32> out_urb_id, u64 address, u32 size), (out_urb_id, address, size)) \
AMS_SF_METHOD_INFO(C, H, 5, Result, GetCtrlInCompletionEvent, (sf::OutCopyHandle out), (out)) \
AMS_SF_METHOD_INFO(C, H, 6, Result, GetCtrlInUrbReport, (sf::Out<usb::UrbReport> out), (out)) \
AMS_SF_METHOD_INFO(C, H, 7, Result, GetCtrlOutCompletionEvent, (sf::OutCopyHandle out), (out)) \
AMS_SF_METHOD_INFO(C, H, 8, Result, GetCtrlOutUrbReport, (sf::Out<usb::UrbReport> out), (out)) \
AMS_SF_METHOD_INFO(C, H, 9, Result, CtrlStall, (), ()) \
AMS_SF_METHOD_INFO(C, H, 10, Result, AppendConfigurationData, (u8 bInterfaceNumber, usb::UsbDeviceSpeed device_speed, const sf::InBuffer &data), (bInterfaceNumber, device_speed, data)) \
AMS_SF_METHOD_INFO(C, H, 65000, Result, Enable, (), ()) \
AMS_SF_METHOD_INFO(C, H, 65001, Result, Disable, (), ())
/* TODO: Deprecated interface? */
AMS_SF_DEFINE_INTERFACE(ams::usb::ds, IDsInterface, AMS_USB_I_DS_INTERFACE_INTERFACE_INFO)

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/usb/usb_limits.hpp>
#include <stratosphere/usb/usb_types.hpp>
#include <stratosphere/usb/usb_device_types.hpp>
#include <stratosphere/usb/ds/usb_i_ds_interface.hpp>
#define AMS_USB_I_DS_SERVICE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, Bind, (usb::ComplexId complex_id, sf::CopyHandle process_h), (complex_id, process_h)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, RegisterInterface, (sf::Out<sf::SharedPointer<usb::ds::IDsInterface>> out, u8 bInterfaceNumber), (out, bInterfaceNumber)) \
AMS_SF_METHOD_INFO(C, H, 2, Result, GetStateChangeEvent, (sf::OutCopyHandle out), (out)) \
AMS_SF_METHOD_INFO(C, H, 3, Result, GetState, (sf::Out<usb::UsbState> out), (out)) \
AMS_SF_METHOD_INFO(C, H, 4, Result, ClearDeviceData, (), ()) \
AMS_SF_METHOD_INFO(C, H, 5, Result, AddUsbStringDescriptor, (sf::Out<u8> out, const sf::InBuffer &desc), (out, desc)) \
AMS_SF_METHOD_INFO(C, H, 6, Result, DeleteUsbStringDescriptor, (u8 index), (index)) \
AMS_SF_METHOD_INFO(C, H, 7, Result, SetUsbDeviceDescriptor, (const sf::InBuffer &desc, usb::UsbDeviceSpeed speed), (desc, speed)) \
AMS_SF_METHOD_INFO(C, H, 8, Result, SetBinaryObjectStore, (const sf::InBuffer &bos), (bos)) \
AMS_SF_METHOD_INFO(C, H, 9, Result, Enable, (), ()) \
AMS_SF_METHOD_INFO(C, H, 10, Result, Disable, (), ())
/* TODO: Deprecated interface? */
AMS_SF_DEFINE_INTERFACE(ams::usb::ds, IDsService, AMS_USB_I_DS_SERVICE_INTERFACE_INFO)
#define AMS_USB_I_DS_ROOT_SERVICE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, GetService, (sf::Out<sf::SharedPointer<usb::ds::IDsService>> out), (out))
AMS_SF_DEFINE_INTERFACE(ams::usb::ds, IDsRootService, AMS_USB_I_DS_ROOT_SERVICE_INTERFACE_INFO)

View file

@ -0,0 +1,145 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/os_system_event.hpp>
#include <stratosphere/sf/sf_lmem_utility.hpp>
#include <stratosphere/usb/usb_limits.hpp>
#include <stratosphere/usb/usb_device_types.hpp>
#include <stratosphere/usb/ds/usb_i_ds_service.hpp>
namespace ams::usb {
class DsInterface;
class DsEndpoint;
class DsClient {
friend class DsInterface;
friend class DsEndpoint;
private:
/* NOTE: Nintendo uses a UnitHeap here on newer firmware versions. */
/* For now, we'll use an ExpHeap and do it the old way. */
sf::ExpHeapAllocator m_allocator{};
u8 m_heap_buffer[32_KB];
lmem::HeapHandle m_heap_handle{};
sf::SharedPointer<ds::IDsRootService> m_root_service{};
sf::SharedPointer<ds::IDsService> m_ds_service{};
bool m_is_initialized{false};
std::atomic<int> m_reference_count{0};
os::SystemEventType m_state_change_event{};
DsInterface *m_interfaces[DsLimitMaxInterfacesPerConfigurationCount]{};
bool m_is_enabled{false};
public:
DsClient() = default;
~DsClient() { /* ... */ }
public:
Result Initialize(ComplexId complex_id);
Result Finalize();
bool IsInitialized();
Result EnableDevice();
Result DisableDevice();
os::SystemEventType *GetStateChangeEvent();
Result GetState(UsbState *out);
Result ClearDeviceData();
Result AddUsbStringDescriptor(u8 *out_index, UsbStringDescriptor *desc);
Result DeleteUsbStringDescriptor(u8 index);
Result SetUsbDeviceDescriptor(UsbDeviceDescriptor *desc, UsbDeviceSpeed speed);
Result SetBinaryObjectStore(u8 *data, int size);
private:
Result AddInterface(DsInterface *intf, sf::SharedPointer<ds::IDsInterface> *out_srv, uint8_t bInterfaceNumber);
Result DeleteInterface(uint8_t bInterfaceNumber);
};
class DsInterface {
friend class DsEndpoint;
private:
DsClient *m_client;
sf::SharedPointer<ds::IDsInterface> m_interface;
bool m_is_initialized;
std::atomic<int> m_reference_count;
os::SystemEventType m_setup_event;
os::SystemEventType m_ctrl_in_completion_event;
os::SystemEventType m_ctrl_out_completion_event;
UrbReport m_report;
u8 m_interface_num;
DsEndpoint *m_endpoints[UsbLimitMaxEndpointsCount];
public:
DsInterface() : m_client(nullptr), m_is_initialized(false), m_reference_count(0) { /* ... */ }
~DsInterface() { /* ... */ }
public:
Result Initialize(DsClient *client, u8 bInterfaceNumber);
Result Finalize();
Result AppendConfigurationData(UsbDeviceSpeed speed, void *data, u32 size);
bool IsInitialized();
os::SystemEventType *GetSetupEvent();
Result GetSetupPacket(UsbCtrlRequest *out);
Result Enable();
Result Disable();
Result CtrlRead(u32 *out_transferred, void *dst, u32 size);
Result CtrlWrite(u32 *out_transferred, void *dst, u32 size);
Result CtrlDone();
Result CtrlStall();
private:
Result AddEndpoint(DsEndpoint *ep, u8 bEndpointAddress, sf::SharedPointer<ds::IDsEndpoint> *out);
Result DeleteEndpoint(u8 bEndpointAddress);
Result CtrlIn(u32 *out_transferred, void *dst, u32 size);
Result CtrlOut(u32 *out_transferred, void *dst, u32 size);
};
class DsEndpoint {
private:
bool m_is_initialized;
bool m_is_new_format;
std::atomic<int> m_reference_count;
DsInterface *m_interface;
sf::SharedPointer<ds::IDsEndpoint> m_endpoint;
u8 m_address;
os::SystemEventType m_completion_event;
os::SystemEventType m_unknown_event;
public:
DsEndpoint() : m_is_initialized(false), m_is_new_format(false), m_reference_count(0) { /* ... */ }
public:
Result Initialize(DsInterface *interface, u8 bEndpointAddress);
Result Finalize();
bool IsInitialized();
Result PostBuffer(u32 *out_transferred, void *buf, u32 size);
Result PostBufferAsync(u32 *out_urb_id, void *buf, u32 size);
os::SystemEventType *GetCompletionEvent();
Result GetUrbReport(UrbReport *out);
Result Cancel();
Result SetZeroLengthTransfer(bool zlt);
};
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/usb/usb_limits.hpp>
#include <stratosphere/usb/usb_types.hpp>
namespace ams::usb {
constexpr inline u8 InterfaceNumberAuto = DsLimitMaxInterfacesPerConfigurationCount;
constexpr inline u8 EndpointAddressAutoIn = UsbEndpointAddressMask_DirDevicetoHost;
constexpr inline u8 EndpointAddressAutoOut = UsbEndpointAddressMask_DirHostToDevice;
enum UrbStatus {
UrbStatus_Invalid = 0,
UrbStatus_Pending = 1,
UrbStatus_Running = 2,
UrbStatus_Finished = 3,
UrbStatus_Cancelled = 4,
UrbStatus_Failed = 5,
};
struct UrbReport {
struct Report {
u32 id;
u32 requested_size;
u32 transferred_size;
UrbStatus status;
} reports[DsLimitRingSize];
u32 count;
};
enum DsString {
DsString_Max = 0x20,
};
struct DsVidPidBcd {
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
char manufacturer[DsString_Max];
char product[DsString_Max];
char serial_number[DsString_Max];
};
}

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/dd/dd_device_address_space_common.hpp>
namespace ams::usb {
constexpr inline int HwLimitDmaBufferAlignmentSize = dd::DeviceAddressSpaceMemoryRegionAlignment;
constexpr inline int HwLimitDataCacheLineSize = 0x40;
constexpr inline int HwLimitMaxPortCount = 0x4;
constexpr inline int UsbLimitMaxEndpointsCount = 0x20;
constexpr inline int UsbLimitMaxEndpointPairCount = 0x10;
constexpr inline int DsLimitMaxConfigurationsPerDeviceCount = 1;
constexpr inline int DsLimitMaxInterfacesPerConfigurationCount = 4;
constexpr inline int DsLimitMaxNameSize = 0x40;
constexpr inline int DsLimitRingSize = 8;
}

View file

@ -0,0 +1,214 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/usb/usb_limits.hpp>
namespace ams::usb {
constexpr ALWAYS_INLINE bool IsDmaAligned(u64 address) {
return util::IsAligned(address, static_cast<u64>(HwLimitDmaBufferAlignmentSize));
}
enum ComplexId {
ComplexId_Tegra21x = 2,
};
enum UsbDescriptorType {
UsbDescriptorType_Device = 1,
UsbDescriptorType_Config = 2,
UsbDescriptorType_String = 3,
UsbDescriptorType_Interface = 4,
UsbDescriptorType_Endpoint = 5,
UsbDescriptorType_DeviceQualifier = 6,
UsbDescriptorType_OtherSpeedConfig = 7,
UsbDescriptorType_InterfacePower = 8,
UsbDescriptorType_Otg = 9,
UsbDescriptorType_Debug = 10,
UsbDescriptorType_InterfaceAssociation = 11,
UsbDescriptorType_Bos = 15,
UsbDescriptorType_DeviceCapability = 16,
UsbDescriptorType_Hid = 33,
UsbDescriptorType_Report = 34,
UsbDescriptorType_Physical = 35,
UsbDescriptorType_Hub = 41,
UsbDescriptorType_EndpointCompanion = 48,
UsbDescriptorType_IsocEndpointCompanion = 49,
};
struct UsbDescriptorHeader {
uint8_t bLength;
uint8_t bDescriptorType;
} PACKED;
struct UsbInterfaceDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
} PACKED;
struct UsbEndpointDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
} PACKED;
struct UsbDeviceDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
} PACKED;
struct UsbConfigDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
} PACKED;
struct UsbEndpointCompanionDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bMaxBurst;
uint8_t bmAttributes;
uint16_t wBytesPerInterval;
} PACKED;
struct UsbStringDescriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wData[DsLimitMaxNameSize];
} PACKED;
struct UsbCtrlRequest {
uint8_t bmRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} PACKED;
enum UsbState {
UsbState_Detached = 0,
UsbState_Attached = 1,
UsbState_Powered = 2,
UsbState_Default = 3,
UsbState_Address = 4,
UsbState_Configured = 5,
UsbState_Suspended = 6,
};
enum UsbDescriptorSize {
UsbDescriptorSize_Interface = sizeof(UsbInterfaceDescriptor),
UsbDescriptorSize_Endpoint = sizeof(UsbEndpointDescriptor),
UsbDescriptorSize_Device = sizeof(UsbDeviceDescriptor),
UsbDescriptorSize_Config = sizeof(UsbConfigDescriptor),
UsbDescriptorSize_EndpointCompanion = sizeof(UsbEndpointCompanionDescriptor),
};
enum UsbDeviceSpeed {
UsbDeviceSpeed_Invalid = 0,
UsbDeviceSpeed_Low = 1,
UsbDeviceSpeed_Full = 2,
UsbDeviceSpeed_High = 3,
UsbDeviceSpeed_Super = 4,
UsbDeviceSpeed_SuperPlus = 5,
};
enum UsbEndpointAddressMask {
UsbEndpointAddressMask_EndpointNumber = (0xF << 0),
UsbEndpointAddressMask_Dir = (0x1 << 7),
UsbEndpointAddressMask_DirHostToDevice = (0x0 << 7),
UsbEndpointAddressMask_DirDevicetoHost = (0x1 << 7),
};
enum UsbEndpointDirection {
UsbEndpointDirection_Invalid = 0,
UsbEndpointDirection_ToDevice = 1,
UsbEndpointDirection_ToHost = 2,
UsbEndpointDirection_Control = 3,
};
constexpr inline u8 UsbGetEndpointNumber(const UsbEndpointDescriptor *desc) {
return desc->bEndpointAddress & UsbEndpointAddressMask_EndpointNumber;
}
constexpr inline bool UsbEndpointIsHostToDevice(const UsbEndpointDescriptor *desc) {
return (desc->bEndpointAddress & UsbEndpointAddressMask_Dir) == UsbEndpointAddressMask_DirHostToDevice;
}
constexpr inline bool UsbEndpointIsDeviceToHost(const UsbEndpointDescriptor *desc) {
return (desc->bEndpointAddress & UsbEndpointAddressMask_Dir) == UsbEndpointAddressMask_DirDevicetoHost;
}
constexpr inline u8 UsbGetEndpointAddress(u8 number, UsbEndpointDirection dir) {
u8 val = static_cast<u8>(number & UsbEndpointAddressMask_EndpointNumber);
if (dir == UsbEndpointDirection_ToHost) {
val |= UsbEndpointAddressMask_DirDevicetoHost;
} else {
val |= UsbEndpointAddressMask_DirHostToDevice;
}
return val;
}
constexpr inline UsbEndpointDirection GetUsbEndpointDirection(const UsbEndpointDescriptor *desc) {
if (UsbEndpointIsDeviceToHost(desc)) {
return UsbEndpointDirection_ToHost;
} else {
return UsbEndpointDirection_ToDevice;
}
}
constexpr inline bool UsbEndpointIsValid(const UsbEndpointDescriptor *desc) {
return desc != nullptr && desc->bLength >= UsbDescriptorSize_Endpoint && desc->bEndpointAddress != 0;
}
constexpr inline void UsbMarkEndpointInvalid(UsbEndpointDescriptor *desc) {
desc->bLength = 0;
desc->bEndpointAddress = 0;
}
}