Enabled Raw HID
This commit is contained in:
parent
da7d74ead6
commit
34dca71b28
4 changed files with 36 additions and 90 deletions
|
|
@ -19,8 +19,6 @@ const int pinButton = 2;
|
|||
void setup() {
|
||||
pinMode(pinLed, OUTPUT);
|
||||
pinMode(pinButton, INPUT_PULLUP);
|
||||
Serial.begin(0);//TODO
|
||||
//Keyboard.begin();
|
||||
// No begin function needed for RawHID
|
||||
}
|
||||
|
||||
|
|
@ -28,29 +26,12 @@ void loop() {
|
|||
if (!digitalRead(pinButton)) {
|
||||
digitalWrite(pinLed, HIGH);
|
||||
|
||||
// Direct without library. Always send RAWHID_RX_SIZE bytes!
|
||||
uint8_t buff[RAWHID_TX_SIZE] = {0};
|
||||
|
||||
// With library
|
||||
memset(&buff, 42, sizeof(buff));
|
||||
RawHID.write(buff, sizeof(buff));
|
||||
|
||||
// Write a single byte, will fill the rest with zeros
|
||||
RawHID.write(0xCD);
|
||||
|
||||
// Huge buffer with library, will fill the rest with zeros
|
||||
// Create buffer and send it
|
||||
uint8_t megabuff[100];
|
||||
for (int i = 0; i < sizeof(megabuff); i++)
|
||||
megabuff[i] = i;
|
||||
RawHID.write(megabuff, sizeof(megabuff));
|
||||
|
||||
// You can use print too, but better do not use a linefeed.
|
||||
// A linefeed will send the \r and \n in a separate report.
|
||||
RawHID.println("Hello World");
|
||||
|
||||
// Compare print to write:
|
||||
RawHID.write("Hello World\r\n");
|
||||
|
||||
// Simple debounce
|
||||
delay(300);
|
||||
digitalWrite(pinLed, LOW);
|
||||
|
|
@ -73,53 +54,3 @@ void loop() {
|
|||
digitalWrite(pinLed, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Expected output:
|
||||
|
||||
// manual with unintialized buff
|
||||
recv 15 bytes:
|
||||
01 55 C1 FF 01 01 01 00 00 01 00 00 01 00 20
|
||||
|
||||
// filled buff
|
||||
recv 15 bytes:
|
||||
2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A
|
||||
|
||||
// single byte filled with zero
|
||||
recv 15 bytes:
|
||||
CD 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
|
||||
// huge buffer filled with zero at the end
|
||||
recv 15 bytes:
|
||||
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E
|
||||
|
||||
recv 15 bytes:
|
||||
0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D
|
||||
|
||||
recv 15 bytes:
|
||||
1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C
|
||||
|
||||
recv 15 bytes:
|
||||
2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B
|
||||
|
||||
recv 15 bytes:
|
||||
3C 3D 3E 3F 00 00 00 00 00 00 00 00 00 00 00
|
||||
|
||||
// print
|
||||
recv 15 bytes:
|
||||
48 65 6C 6C 6F 20 57 6F 72 6C 64 00 00 00 00
|
||||
|
||||
//\r
|
||||
recv 15 bytes:
|
||||
0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
|
||||
//\n
|
||||
recv 15 bytes:
|
||||
0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
|
||||
//write
|
||||
recv 15 bytes:
|
||||
48 65 6C 6C 6F 20 57 6F 72 6C 64 0D 0A 00 00
|
||||
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ THE SOFTWARE.
|
|||
#include "SingleReport/SingleGamepad.h"
|
||||
#include "MultiReport/Gamepad.h"
|
||||
#include "MultiReport/System.h"
|
||||
//#include "RawHID.h"
|
||||
#include "SingleReport/RawHID.h"
|
||||
|
||||
// Include Teensy HID afterwards to overwrite key definitions if used
|
||||
#ifdef USE_TEENSY_KEYBOARD
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ RawHID_::RawHID_(void) : PluggableUSBModule(1, 1, epType), protocol(HID_REPORT_P
|
|||
int RawHID_::getInterface(uint8_t* interfaceCount)
|
||||
{
|
||||
// TODO add a 2nd OUT endpoint to get more speed???
|
||||
// Maybe as optional device
|
||||
// Maybe as optional device FastRawHID with different USAGE PAGE
|
||||
*interfaceCount += 1; // uses 1
|
||||
HIDDescriptor hidInterface = {
|
||||
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
|
||||
|
|
@ -115,7 +115,38 @@ bool RawHID_::setup(USBSetup& setup)
|
|||
}
|
||||
if (request == HID_SET_REPORT)
|
||||
{
|
||||
// TODO
|
||||
// Get the data length information and the corresponding bytes
|
||||
int length = setup.wLength;
|
||||
|
||||
// Ensure that there IS some data
|
||||
if(length > 0)
|
||||
{
|
||||
void* data = malloc(length);
|
||||
if(data){
|
||||
auto recvLength = length;
|
||||
//TODO loop can be improved maybe? Or does the compiler do this already?
|
||||
while(recvLength > USB_EP_SIZE){
|
||||
USB_RecvControl((uint8_t*)data + (length - recvLength), USB_EP_SIZE);
|
||||
recvLength -= USB_EP_SIZE;
|
||||
}
|
||||
USB_RecvControl((uint8_t*)data + (length - recvLength), recvLength);
|
||||
|
||||
// Only overwrite the buffer if its empty.
|
||||
// This avoids corrupted data while reading.
|
||||
if(!dataLength){
|
||||
// Save new data
|
||||
dataLength = length;
|
||||
dataHead = (uint8_t*) data;
|
||||
dataTail = (uint8_t*)(data) + length;
|
||||
|
||||
// Clear the passed in pointer to not free the data
|
||||
data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Release data if the pointer still exists
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -120,8 +120,7 @@ public:
|
|||
}
|
||||
|
||||
virtual size_t write(uint8_t *buffer, size_t size){
|
||||
// TODO this only sends the report ID in the first packat
|
||||
// TODO this will split the data into USB_EP_SIZE packets
|
||||
// TODO this will split the data into proper USB_EP_SIZE packets already
|
||||
SendReport(buffer, size);
|
||||
return size;
|
||||
|
||||
|
|
@ -152,21 +151,6 @@ protected:
|
|||
uint8_t protocol;
|
||||
uint8_t idle;
|
||||
|
||||
|
||||
virtual void setReportData(void* &data, int len){
|
||||
// Only overwrite the buffer if its empty.
|
||||
// This avoids corrupted data while reading.
|
||||
if(!dataLength){
|
||||
// Save new data
|
||||
dataLength = len;
|
||||
dataHead = (uint8_t*) data;
|
||||
dataTail = (uint8_t*)(data) + len;
|
||||
|
||||
// Clear the passed in pointer to not free the data
|
||||
data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Buffer pointers to hold the received data
|
||||
int dataLength;
|
||||
uint8_t* dataHead;
|
||||
|
|
|
|||
Loading…
Reference in a new issue