20 #include "UsbHumanInterfaceDevice.h" 21 #include "modules/drivers/common/hid/HidReport.h" 22 #include "modules/system/usb/UsbConstants.h" 23 #include "modules/system/usb/UsbDevice.h" 24 #include "pedigree/kernel/Log.h" 25 #include "pedigree/kernel/processor/types.h" 26 #include "pedigree/kernel/utilities/PointerGuard.h" 27 #include "pedigree/kernel/utilities/Vector.h" 28 #include "pedigree/kernel/utilities/utility.h" 30 UsbHumanInterfaceDevice::UsbHumanInterfaceDevice(
UsbDevice *pDev)
35 UsbHumanInterfaceDevice::~UsbHumanInterfaceDevice()
43 for (
size_t i = 0; i <
m_pInterface->otherDescriptorList.count(); i++)
46 if (pDescriptor->nType == 0x21)
54 ERROR(
"USB: HID: No HID descriptor");
61 UsbRequestType::Class | UsbRequestRecipient::Interface,
62 UsbRequest::GetInterface, 0, 0);
65 uint16_t nReportDescriptorSize = pHidDescriptor->nDescriptorLength;
66 uint8_t *pReportDescriptor =
static_cast<uint8_t *
>(
getDescriptor(
67 0x22, 0, nReportDescriptorSize, UsbRequestRecipient::Interface));
72 m_pReport->parseDescriptor(pReportDescriptor, nReportDescriptorSize);
75 for (
size_t i = 0; i <
m_pInterface->endpointList.count(); i++)
78 if (pEndpoint->nTransferType == Endpoint::Interrupt && pEndpoint->bIn)
80 m_pInEndpoint = pEndpoint;
88 ERROR(
"USB: HID: No Interrupt IN endpoint");
94 m_pInReportBuffer =
new uint8_t[m_pInEndpoint->nMaxPacketSize];
95 m_pOldInReportBuffer =
new uint8_t[m_pInEndpoint->nMaxPacketSize];
96 ByteSet(m_pInReportBuffer, 0, m_pInEndpoint->nMaxPacketSize);
97 ByteSet(m_pOldInReportBuffer, 0, m_pInEndpoint->nMaxPacketSize);
101 m_pInEndpoint, reinterpret_cast<uintptr_t>(m_pInReportBuffer),
102 m_pInEndpoint->nMaxPacketSize, callback,
103 reinterpret_cast<uintptr_t>(
this));
108 void UsbHumanInterfaceDevice::callback(uintptr_t pParam, ssize_t ret)
112 pHid->inputHandler();
115 void UsbHumanInterfaceDevice::inputHandler()
122 m_pReport->feedInput(
123 m_pInReportBuffer, m_pOldInReportBuffer, m_pInEndpoint->nMaxPacketSize);
virtual void initialiseDriver()
Implemented by the driver class, initialises driver-specific stuff.
virtual void addInterruptInHandler(UsbEndpoint endpointInfo, uintptr_t pBuffer, uint16_t nBytes, void(*pCallback)(uintptr_t, ssize_t), uintptr_t pParam=0)
Adds a new handler for an interrupt IN transaction.
bool controlRequest(uint8_t nRequestType, uint8_t nRequest, uint16_t nValue, uint16_t nIndex, uint16_t nLength=0, uintptr_t pBuffer=0)
Performs an USB control request.
UsbState m_UsbState
The current state of the device.
DeviceDescriptor * getDescriptor()
Returns the device descriptor of the device.
Interface * m_pInterface
Interface in use.