*
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
# usb_plus_plus
|
||||
Slowly writing custom USB device stack implementation in C++
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* usb_configuration.h
|
||||
*
|
||||
* Created on: 10 ôåâð. 2017 ã.
|
||||
* Author: l-pro
|
||||
*/
|
||||
|
||||
#ifndef USB_CONFIGURATION_H_
|
||||
#define USB_CONFIGURATION_H_
|
||||
|
||||
|
||||
namespace UsbPlusPlus {
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* USB_CONFIGURATION_H_ */
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* usb_descriptors.h
|
||||
*
|
||||
* Created on: 9 ôåâð. 2017 ã.
|
||||
* Author: l-pro
|
||||
*/
|
||||
|
||||
#ifndef USB_DESCRIPTORS_H_
|
||||
#define USB_DESCRIPTORS_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace UsbPlusPlus {
|
||||
|
||||
namespace BcdUSB {
|
||||
static constexpr uint16_t Usb1_0 = 0x0100;
|
||||
static constexpr uint16_t Usb1_1 = 0x0110;
|
||||
static constexpr uint16_t Usb2_0 = 0x0200;
|
||||
}
|
||||
|
||||
namespace DeviceClass {
|
||||
static constexpr uint8_t InterfaceDefined = 0x00;
|
||||
static constexpr uint8_t Vendor = 0xFF;
|
||||
}
|
||||
|
||||
enum class DescriptorType : uint8_t {
|
||||
device = 1,
|
||||
configuration = 2,
|
||||
string = 3,
|
||||
interface = 4,
|
||||
endpoint = 5,
|
||||
deviceQualifier = 6,
|
||||
otherSpeedConfiguration = 7,
|
||||
interfacePower = 8,
|
||||
otg = 9,
|
||||
debug = 10,
|
||||
interfaceAssociation = 11
|
||||
};
|
||||
|
||||
namespace ConfigurationAttributes {
|
||||
static constexpr uint8_t None = 0;
|
||||
static constexpr uint8_t RemoteWakeup = (1 << 5);
|
||||
static constexpr uint8_t SelfPowered = (1 << 6);
|
||||
static constexpr uint8_t Reserved = 1 << 7; //Set to 1
|
||||
}
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
class Descriptor {
|
||||
public:
|
||||
constexpr Descriptor(uint8_t bLength, DescriptorType bDescriptionType):bLength(bLength),bDescriptionType(bDescriptionType){}
|
||||
uint8_t bLength; //Size of Descriptor in Bytes
|
||||
DescriptorType bDescriptionType;
|
||||
};
|
||||
|
||||
class DeviceDescriptor : public Descriptor {
|
||||
public:
|
||||
DeviceDescriptor():Descriptor(sizeof(DeviceDescriptor), DescriptorType::device){}
|
||||
uint16_t bcdUSB; //Binary coded decimal with a format of 0xJJMN, e.g. 0x0200
|
||||
uint8_t bDeviceClass;
|
||||
uint8_t bDeviceSubClass;
|
||||
uint8_t bDeviceProtocol;
|
||||
uint8_t bMaxPacketSize0; //Maximum packet size for endpoint 0
|
||||
uint16_t idVendor;
|
||||
uint16_t idProduct;
|
||||
uint16_t bcdDevice; //Device Release Number
|
||||
uint8_t iManufacturer;
|
||||
uint8_t iProduct;
|
||||
uint8_t iSerialNumber;
|
||||
uint8_t bNumConfigurations;
|
||||
};
|
||||
|
||||
class ConfigurationDescriptor : public Descriptor {
|
||||
public:
|
||||
ConfigurationDescriptor():Descriptor(sizeof(ConfigurationDescriptor), DescriptorType::configuration){}
|
||||
uint16_t wTotalLength;
|
||||
uint8_t bNumInterfaces;
|
||||
uint8_t bConfigurationValue;
|
||||
uint8_t iConfiguration;
|
||||
uint8_t bmAttributes;
|
||||
uint8_t bMaxPower;
|
||||
|
||||
static constexpr uint8_t makeMaxPower(uint16_t ma){
|
||||
return ma >> 1;
|
||||
}
|
||||
};
|
||||
|
||||
class InterfaceDescriptor : public Descriptor {
|
||||
public:
|
||||
InterfaceDescriptor():Descriptor(sizeof(InterfaceDescriptor), DescriptorType::interface){}
|
||||
uint8_t bInterfaceNumber;
|
||||
uint8_t bAlternateSetting;
|
||||
uint8_t bNumEndpoints;
|
||||
uint8_t bInterfaceClass;
|
||||
uint8_t bInterfaceSubClass;
|
||||
uint8_t bInterfaceProtocol;
|
||||
uint8_t iInterface;
|
||||
};
|
||||
|
||||
namespace EndpointAttributes {
|
||||
namespace TransferType{
|
||||
static constexpr uint8_t Control = 0;
|
||||
static constexpr uint8_t Isochronous = 1;
|
||||
static constexpr uint8_t Bulk = 2;
|
||||
static constexpr uint8_t Interrupt = 3;
|
||||
}
|
||||
//Only for Isochronous endpoint
|
||||
namespace IsoSynchronisationType{
|
||||
static constexpr uint8_t NoSynchonisation = 0 << 2;
|
||||
static constexpr uint8_t Asynchronous = 1 << 2;
|
||||
static constexpr uint8_t Adaptive = 2 << 2;
|
||||
static constexpr uint8_t Synchronous = 3 << 2;
|
||||
}
|
||||
//Only for Isochronous endpoint
|
||||
namespace IsoUsageType{
|
||||
static constexpr uint8_t DataEndpoint = 0 << 4;
|
||||
static constexpr uint8_t FeedbackEndpoint = 1 << 4;
|
||||
static constexpr uint8_t ExplicitFeedbackDataEndpoint = 2 << 4;
|
||||
static constexpr uint8_t Reserved = 3 << 4;
|
||||
}
|
||||
}
|
||||
|
||||
class EndpointDescriptor : public Descriptor {
|
||||
public:
|
||||
EndpointDescriptor():Descriptor(sizeof(EndpointDescriptor), DescriptorType::endpoint){}
|
||||
uint8_t bEndpointAddress;
|
||||
uint8_t bmAttributes; //see EndpointAttributes
|
||||
uint16_t wMaxPacketSize;
|
||||
uint8_t bInterval;
|
||||
};
|
||||
|
||||
class DeviceQualifierDescriptor : public Descriptor{
|
||||
public:
|
||||
DeviceQualifierDescriptor():Descriptor(sizeof(DeviceQualifierDescriptor), DescriptorType::deviceQualifier){}
|
||||
uint16_t bcdUSB;
|
||||
uint8_t bDeviceClass;
|
||||
uint8_t bDeviceSubClass;
|
||||
uint8_t bDeviceProtocol;
|
||||
uint8_t bMaxPacketSize0;
|
||||
uint8_t bNumConfigurations;
|
||||
uint8_t bReserved;
|
||||
};
|
||||
|
||||
class InterfaceAssociationDescriptor : public Descriptor{
|
||||
public:
|
||||
InterfaceAssociationDescriptor():Descriptor(sizeof(InterfaceAssociationDescriptor), DescriptorType::interfaceAssociation){}
|
||||
uint8_t bFirstInterface;
|
||||
uint8_t bInterfaceCount;
|
||||
uint8_t bFunctionClass;
|
||||
uint8_t bFunctionSubClass;
|
||||
uint8_t bFunctionProtocol;
|
||||
uint8_t iFunction;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
static_assert(sizeof(InterfaceAssociationDescriptor) == 8, "Invalid size");
|
||||
static_assert(sizeof(DeviceQualifierDescriptor) == 10, "Invalid size");
|
||||
static_assert(sizeof(EndpointDescriptor) == 7, "Invalid size");
|
||||
static_assert(sizeof(InterfaceDescriptor) == 9, "Invalid size");
|
||||
static_assert(sizeof(ConfigurationDescriptor) == 9, "Invalid size");
|
||||
static_assert(sizeof(DeviceDescriptor) == 18, "Invalid size");
|
||||
static_assert(sizeof(Descriptor) == 2, "Invalid size");
|
||||
|
||||
}//UsbPlusPlus
|
||||
#endif /* USB_DESCRIPTORS_H_ */
|
||||
Reference in New Issue
Block a user