mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
[PUSB] callbacks are now pure virtual methods
This change allows the compiler to handle callbacks resolution. Callbacks now must be implemented on the class that extends PUSBListNode and this is forced by compiler by means of pure virtual methods. Also the calls to HID.interface() and HID.endpoint() can now be simplified to interface() and endpoint() respectively since the methods are no more static.
This commit is contained in:
parent
2ac2a27173
commit
0dfa815ce4
@ -28,9 +28,6 @@
|
|||||||
class PUSBListNode {
|
class PUSBListNode {
|
||||||
public:
|
public:
|
||||||
PUSBListNode() { }
|
PUSBListNode() { }
|
||||||
bool (*setup)(USBSetup& setup, uint8_t i);
|
|
||||||
int (*getInterface)(uint8_t* interfaceNum);
|
|
||||||
int (*getDescriptor)(int8_t t);
|
|
||||||
int8_t numEndpoints;
|
int8_t numEndpoints;
|
||||||
int8_t numInterfaces;
|
int8_t numInterfaces;
|
||||||
uint8_t *endpointType;
|
uint8_t *endpointType;
|
||||||
@ -39,6 +36,10 @@ public:
|
|||||||
inline int8_t endpoint() const { return pluggedEndpoint; }
|
inline int8_t endpoint() const { return pluggedEndpoint; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool setup(USBSetup& setup, uint8_t i) = 0;
|
||||||
|
virtual int getInterface(uint8_t* interfaceNum) = 0;
|
||||||
|
virtual int getDescriptor(int8_t t) = 0;
|
||||||
|
|
||||||
uint8_t pluggedInterface;
|
uint8_t pluggedInterface;
|
||||||
int8_t pluggedEndpoint;
|
int8_t pluggedEndpoint;
|
||||||
|
|
||||||
|
@ -41,19 +41,19 @@ uint8_t HID_::epType[] = { EP_TYPE_INTERRUPT_IN };
|
|||||||
uint8_t HID_::protocol = 1;
|
uint8_t HID_::protocol = 1;
|
||||||
uint8_t HID_::idle = 1;
|
uint8_t HID_::idle = 1;
|
||||||
|
|
||||||
int HID_::GetInterface(uint8_t* interfaceNum)
|
int HID_::getInterface(uint8_t* interfaceNum)
|
||||||
{
|
{
|
||||||
interfaceNum[0] += 1; // uses 1
|
interfaceNum[0] += 1; // uses 1
|
||||||
hidInterface =
|
hidInterface =
|
||||||
{
|
{
|
||||||
D_INTERFACE(HID.interface(), 1, 3, 0, 0),
|
D_INTERFACE(interface(), 1, 3, 0, 0),
|
||||||
D_HIDREPORT(sizeof_hidReportDescriptor),
|
D_HIDREPORT(sizeof_hidReportDescriptor),
|
||||||
D_ENDPOINT(USB_ENDPOINT_IN(HID.endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
|
D_ENDPOINT(USB_ENDPOINT_IN(endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
|
||||||
};
|
};
|
||||||
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
|
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
|
||||||
}
|
}
|
||||||
|
|
||||||
int HID_::GetDescriptor(int8_t t)
|
int HID_::getDescriptor(int8_t t)
|
||||||
{
|
{
|
||||||
if (HID_REPORT_DESCRIPTOR_TYPE == t) {
|
if (HID_REPORT_DESCRIPTOR_TYPE == t) {
|
||||||
HIDDescriptorListNode* current = rootNode;
|
HIDDescriptorListNode* current = rootNode;
|
||||||
@ -85,13 +85,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node)
|
|||||||
|
|
||||||
void HID_::SendReport(uint8_t id, const void* data, int len)
|
void HID_::SendReport(uint8_t id, const void* data, int len)
|
||||||
{
|
{
|
||||||
USB_Send(HID.endpoint(), &id, 1);
|
USB_Send(endpoint(), &id, 1);
|
||||||
USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len);
|
USB_Send(endpoint() | TRANSFER_RELEASE,data,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HID_::Setup(USBSetup& setup, uint8_t i)
|
bool HID_::setup(USBSetup& setup, uint8_t i)
|
||||||
{
|
{
|
||||||
if (HID.interface() != i) {
|
if (interface() != i) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
uint8_t r = setup.bRequest;
|
uint8_t r = setup.bRequest;
|
||||||
@ -130,9 +130,6 @@ bool HID_::Setup(USBSetup& setup, uint8_t i)
|
|||||||
|
|
||||||
HID_::HID_(void)
|
HID_::HID_(void)
|
||||||
{
|
{
|
||||||
setup = HID_::Setup;
|
|
||||||
getInterface = HID_::GetInterface;
|
|
||||||
getDescriptor = HID_::GetDescriptor;
|
|
||||||
numEndpoints = 1;
|
numEndpoints = 1;
|
||||||
numInterfaces = 1;
|
numInterfaces = 1;
|
||||||
endpointType = epType;
|
endpointType = epType;
|
||||||
|
@ -80,11 +80,13 @@ public:
|
|||||||
void SendReport(uint8_t id, const void* data, int len);
|
void SendReport(uint8_t id, const void* data, int len);
|
||||||
void AppendDescriptor(HIDDescriptorListNode* node);
|
void AppendDescriptor(HIDDescriptorListNode* node);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
static int GetInterface(uint8_t* interfaceNum);
|
// Implementation of the PUSBListNode
|
||||||
static int GetDescriptor(int8_t t);
|
int getInterface(uint8_t* interfaceNum);
|
||||||
static bool Setup(USBSetup& setup, uint8_t i);
|
int getDescriptor(int8_t t);
|
||||||
|
bool setup(USBSetup& setup, uint8_t i);
|
||||||
|
|
||||||
|
private:
|
||||||
static HIDDescriptor hidInterface;
|
static HIDDescriptor hidInterface;
|
||||||
|
|
||||||
static HIDDescriptorListNode* rootNode;
|
static HIDDescriptorListNode* rootNode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user