2019-10-31 18:00:42 +00:00
|
|
|
#pragma once
|
2019-11-13 11:16:13 +00:00
|
|
|
#include "Result.h"
|
2019-10-31 18:00:42 +00:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
class IUSBEndpoint
|
|
|
|
{
|
|
|
|
public:
|
2019-11-22 00:47:16 +00:00
|
|
|
enum Direction : uint8_t
|
2019-10-31 18:00:42 +00:00
|
|
|
{
|
|
|
|
USB_ENDPOINT_IN = 0x80,
|
|
|
|
USB_ENDPOINT_OUT = 0x00,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EndpointDescriptor
|
|
|
|
{
|
|
|
|
uint8_t bLength;
|
|
|
|
uint8_t bDescriptorType;
|
|
|
|
uint8_t bEndpointAddress;
|
|
|
|
uint8_t bmAttributes;
|
|
|
|
uint16_t wMaxPacketSize;
|
|
|
|
uint8_t bInterval;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~IUSBEndpoint() = default;
|
|
|
|
|
2019-11-12 17:56:22 +00:00
|
|
|
//Open and close the endpoint. if maxPacketSize is not set, it uses wMaxPacketSize from the descriptor.
|
2019-11-13 11:16:13 +00:00
|
|
|
virtual Result Open(int maxPacketSize = 0) = 0;
|
2019-10-31 18:00:42 +00:00
|
|
|
virtual void Close() = 0;
|
|
|
|
|
|
|
|
//This will read from the inBuffer pointer for the specified size and write it to the endpoint.
|
2019-11-13 11:16:13 +00:00
|
|
|
virtual Result Write(const void *inBuffer, size_t bufferSize) = 0;
|
2019-10-31 18:00:42 +00:00
|
|
|
|
|
|
|
//This will read from the endpoint and put the data in the outBuffer pointer for the specified size.
|
2019-11-13 11:16:13 +00:00
|
|
|
virtual Result Read(void *outBuffer, size_t bufferSize) = 0;
|
2019-10-31 18:00:42 +00:00
|
|
|
|
|
|
|
//Get endpoint's direction. (IN or OUT)
|
|
|
|
virtual IUSBEndpoint::Direction GetDirection() = 0;
|
|
|
|
//Get the endpoint descriptor
|
|
|
|
virtual EndpointDescriptor *GetDescriptor() = 0;
|
|
|
|
};
|