[PUSB] Fixed checks on return values
This commit is contained in:
parent
10512b3f9b
commit
bad9b58ce3
|
@ -29,19 +29,23 @@ PluggableUSB_ PluggableUSB;
|
||||||
|
|
||||||
int PluggableUSB_::getInterface(uint8_t* interfaceNum)
|
int PluggableUSB_::getInterface(uint8_t* interfaceNum)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int sent = 0;
|
||||||
PUSBListNode* node;
|
PUSBListNode* node;
|
||||||
for (node = rootNode; node; node = node->next) {
|
for (node = rootNode; node; node = node->next) {
|
||||||
ret = node->getInterface(interfaceNum);
|
int res = node->getInterface(interfaceNum);
|
||||||
|
if (res == -1)
|
||||||
|
return -1;
|
||||||
|
sent += res;
|
||||||
}
|
}
|
||||||
return ret;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PluggableUSB_::getDescriptor(int8_t t)
|
int PluggableUSB_::getDescriptor(int8_t type)
|
||||||
{
|
{
|
||||||
PUSBListNode* node;
|
PUSBListNode* node;
|
||||||
for (node = rootNode; node; node = node->next) {
|
for (node = rootNode; node; node = node->next) {
|
||||||
int ret = node->getDescriptor(t);
|
int ret = node->getDescriptor(type);
|
||||||
|
// ret!=0 -> request has been processed
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,19 +35,23 @@ int HID_::getInterface(uint8_t* interfaceNum)
|
||||||
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 type)
|
||||||
{
|
{
|
||||||
if (HID_REPORT_DESCRIPTOR_TYPE == t) {
|
if (HID_REPORT_DESCRIPTOR_TYPE == type) {
|
||||||
HIDDescriptorListNode* current = rootNode;
|
HIDDescriptorListNode* current = rootNode;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
while(current != NULL) {
|
while (current != NULL) {
|
||||||
total += USB_SendControl(TRANSFER_PGM,current->data,current->length);
|
int res = USB_SendControl(TRANSFER_PGM, current->data, current->length);
|
||||||
|
if (res == -1)
|
||||||
|
return -1;
|
||||||
|
total += res;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignored
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
|
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
|
||||||
|
@ -71,9 +75,9 @@ void HID_::SendReport(uint8_t id, const void* data, int len)
|
||||||
USB_Send(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 interfaceNum)
|
||||||
{
|
{
|
||||||
if (interface() != i) {
|
if (interface() != interfaceNum) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
uint8_t r = setup.bRequest;
|
uint8_t r = setup.bRequest;
|
||||||
|
|
|
@ -83,8 +83,8 @@ public:
|
||||||
protected:
|
protected:
|
||||||
// Implementation of the PUSBListNode
|
// Implementation of the PUSBListNode
|
||||||
int getInterface(uint8_t* interfaceNum);
|
int getInterface(uint8_t* interfaceNum);
|
||||||
int getDescriptor(int8_t t);
|
int getDescriptor(int8_t type);
|
||||||
bool setup(USBSetup& setup, uint8_t i);
|
bool setup(USBSetup& setup, uint8_t interfaceNum);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HIDDescriptor hidInterface;
|
HIDDescriptor hidInterface;
|
||||||
|
|
Loading…
Reference in New Issue