// TITLE: USB HID device class driver
#include "usbdhid.h"
#include <usb.h>
namespace usb{
bool tHIDDevice::SendReport(uint8_t *data, unsigned len) {
int32_t i32Retcode = USBEndpointDataPut(USB_BASE,USB_EP_1,data,len);
if (!i32Retcode) {
i32Retcode = USBEndpointDataSend(USB_BASE,USB_EP_1,USB_TRANS_IN);
}
return i32Retcode==0;
}
// This function is called by the USB device stack whenever a request for a
// non-standard descriptor is received.
bool tHIDDevice::cbGetDescriptor(const tRequest&rq) {
switch (rq.wValueH) {
// This is a request for a HID report or physical descriptor.
case 0x22: {
// Find the index to the descriptor that is being queried.
const uint8_t*data=desc.hidrep;
unsigned size=desc.hid[7]|desc.hid[8]<<8;
rq.limitLength(size);
// Send the data via endpoint 0.
SendDataEP0(data,size);
}return true;
// This is a request for the HID descriptor (as found in the
// configuration descriptor following the relevant interface).
case 0x21: {
// How big is the HID descriptor?
const uint8_t*data=desc.hid;
unsigned size=*data;
rq.limitLength(size);
SendDataEP0(data,size);
}return true;
}
return tDevice::cbGetDescriptor(rq);
}
bool tHIDDevice::cbRequestHandler(const tRequest&rq) {
switch (rq.wRequest()) {
case 0x06A1: return cbGetDescriptor(rq);
}
return false;
}
}
Vorgefundene Kodierung: UTF-8 | 0
|