Fixed tab/space and added comments

This commit is contained in:
Hakan Lindestaf 2016-03-21 11:54:30 -07:00
parent c1c955c225
commit 83a52b5063
3 changed files with 44 additions and 41 deletions

View file

@ -7,6 +7,7 @@
#include <SPI.h> #include <SPI.h>
#endif #endif
// Override HIDComposite to be able to select which interface we want to hook into
class HIDSelector : public HIDComposite class HIDSelector : public HIDComposite
{ {
public: public:
@ -17,6 +18,7 @@ protected:
bool SelectInterface(uint8_t iface, uint8_t proto); bool SelectInterface(uint8_t iface, uint8_t proto);
}; };
// Return true for the interface we want to hook into
bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto) bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto)
{ {
if(proto != 0) if(proto != 0)
@ -25,6 +27,7 @@ bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto)
return false; return false;
} }
// Will be called for all HID data received from the USB interface
void HIDSelector::ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) { void HIDSelector::ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) {
#if 1 #if 1
if (len && buf) { if (len && buf) {

View file

@ -227,15 +227,15 @@ uint8_t HIDComposite::Init(uint8_t parent, uint8_t port, bool lowspeed) {
if(rcode) if(rcode)
goto FailSetConfDescr; goto FailSetConfDescr;
USBTRACE2("NumIface:", bNumIface); USBTRACE2("NumIface:", bNumIface);
for(uint8_t i = 0; i < bNumIface; i++) { for(uint8_t i = 0; i < bNumIface; i++) {
if(hidInterfaces[i].epIndex[epInterruptInIndex] == 0) if(hidInterfaces[i].epIndex[epInterruptInIndex] == 0)
continue; continue;
USBTRACE2("SetIdle:", hidInterfaces[i].bmInterface); USBTRACE2("SetIdle:", hidInterfaces[i].bmInterface);
rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0); rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0);
if(rcode && rcode != hrSTALL) if(rcode && rcode != hrSTALL)
goto FailSetIdle; goto FailSetIdle;
@ -314,29 +314,29 @@ void HIDComposite::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint
} }
if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
index = epInterruptInIndex; index = epInterruptInIndex;
else else
index = epInterruptOutIndex; index = epInterruptOutIndex;
if(!SelectInterface(iface, proto)) if(!SelectInterface(iface, proto))
index = 0; index = 0;
if(index) { if(index) {
// Fill in the endpoint info structure // Fill in the endpoint info structure
epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F);
epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize;
epInfo[bNumEP].bmSndToggle = 0; epInfo[bNumEP].bmSndToggle = 0;
epInfo[bNumEP].bmRcvToggle = 0; epInfo[bNumEP].bmRcvToggle = 0;
epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT; epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT;
// Fill in the endpoint index list // Fill in the endpoint index list
piface->epIndex[index] = bNumEP; //(pep->bEndpointAddress & 0x0F); piface->epIndex[index] = bNumEP; //(pep->bEndpointAddress & 0x0F);
if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
pollInterval = pep->bInterval; pollInterval = pep->bInterval;
bNumEP++; bNumEP++;
} }
} }
uint8_t HIDComposite::Release() { uint8_t HIDComposite::Release() {
@ -368,8 +368,8 @@ uint8_t HIDComposite::Poll() {
for(uint8_t i = 0; i < bNumIface; i++) { for(uint8_t i = 0; i < bNumIface; i++) {
uint8_t index = hidInterfaces[i].epIndex[epInterruptInIndex]; uint8_t index = hidInterfaces[i].epIndex[epInterruptInIndex];
if (index == 0) if (index == 0)
continue; continue;
uint16_t read = (uint16_t)epInfo[index].maxPktSize; uint16_t read = (uint16_t)epInfo[index].maxPktSize;
@ -383,29 +383,29 @@ uint8_t HIDComposite::Poll() {
continue; continue;
} }
if(read == 0) if(read == 0)
continue; continue;
if(read > constBuffLen) if(read > constBuffLen)
read = constBuffLen; read = constBuffLen;
#if 0 #if 0
Notify(PSTR("\r\nBuf: "), 0x80); Notify(PSTR("\r\nBuf: "), 0x80);
for(uint8_t i = 0; i < read; i++) { for(uint8_t i = 0; i < read; i++) {
D_PrintHex<uint8_t > (buf[i], 0x80); D_PrintHex<uint8_t > (buf[i], 0x80);
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
} }
Notify(PSTR("\r\n"), 0x80); Notify(PSTR("\r\n"), 0x80);
#endif #endif
ParseHIDData(this, epInfo[index].epAddr, bHasReportId, (uint8_t)read, buf); ParseHIDData(this, epInfo[index].epAddr, bHasReportId, (uint8_t)read, buf);
HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0)); HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0));
if(prs) if(prs)
prs->Parse(this, bHasReportId, (uint8_t)read, buf); prs->Parse(this, bHasReportId, (uint8_t)read, buf);
} }
} }
return rcode; return rcode;

View file

@ -101,8 +101,8 @@ public:
// Send report - do not mix with SetReport()! // Send report - do not mix with SetReport()!
uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr); uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr);
// Returns true if we should listen on an interface, false if not // Returns true if we should listen on an interface, false if not
virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0; virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0;
}; };
#endif // __HIDCOMPOSITE_H__ #endif // __HIDCOMPOSITE_H__