Skip to content

Commit

Permalink
Added Boot Keyboard support
Browse files Browse the repository at this point in the history
If enabled the keyboard will not work in the OS again. This still needs to be fixed.
Experimental!
  • Loading branch information
NicoHood committed Sep 19, 2015
1 parent 78c763e commit 0e29749
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/HID-Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THE SOFTWARE.
#endif

#define HID_KEYBOARD_LEDS_ENABLED
//#define USE_BOOT_KEYBOARD_PROTOCOL

//#define LAYOUT_US_ENGLISH
//#define LAYOUT_CANADIAN_FRENCH
Expand Down Expand Up @@ -72,6 +73,8 @@ THE SOFTWARE.
#define LAYOUT_US_ENGLISH
#endif

#define HID_REPORTID_NONE 0

#ifndef HID_REPORTID_MOUSE
#define HID_REPORTID_MOUSE 1
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/ImprovedKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ void Keyboard_::sendReport(HID_KeyboardReport_Data_t* keys)
{
// Call the inherited function.
// This wrapper still saves us some bytes
#if defined(USE_BOOT_KEYBOARD_PROTOCOL)
HID.SendReport(HID_REPORTID_NONE, keys,sizeof(HID_KeyboardReport_Data_t));
#else
SendReport(keys,sizeof(HID_KeyboardReport_Data_t));
#endif
}

#if defined(HID_KEYBOARD_LEDS_ENABLED)
Expand Down
23 changes: 18 additions & 5 deletions src/PluggableHID/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "PluggableUSB.h"
#include "HID.h"
#include "HIDDevice.h"
#include "HID-Project.h" // Only used for the BootKeyboard setting

#if defined(USBCON)

Expand Down Expand Up @@ -58,7 +59,11 @@ int HID_GetInterface(u8* interfaceNum)
interfaceNum[0] += 1; // uses 1
_hidInterface =
{
#if defined(USE_BOOT_KEYBOARD_PROTOCOL)
D_INTERFACE(HID_INTERFACE,1,3,1,1),
#else
D_INTERFACE(HID_INTERFACE,1,3,0,0),
#endif
D_HIDREPORT(sizeof_hidReportDescriptor),
D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,USB_EP_SIZE,0x01)
};
Expand Down Expand Up @@ -97,7 +102,10 @@ void HID_::AppendDescriptor(HIDDevice *device)

void HID_::SendReport(u8 id, const void* data, int len)
{
USB_Send(HID_TX, &id, 1);
// Only send report ID if it exists
if(id){
USB_Send(HID_TX, &id, 1);
}
USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
}

Expand Down Expand Up @@ -143,17 +151,22 @@ bool HID_::HID_Setup(USBSetup& setup, u8 i)
HIDDevice *current = rootDevice;
while(current != NULL)
{
// TODO implementation for non reportID HID devices
// This would could make rawHID work. reportID 0 could be used as indicator
// Search HIDDevice for report ID
if(current->reportID == ID)
{
// Get the data length information and the corresponding bytes
uint8_t length = setup.wLength;
uint8_t data[length];
USB_RecvControl(data, length);

// Skip report ID data
current->setReportData(data+1, length-1);
// Skip report ID data, if any
if(ID){
current->setReportData(data+1, length-1);
}
// TODO test this case
else{
current->setReportData(data, length);
}

// Dont search any further
break;
Expand Down
4 changes: 4 additions & 0 deletions src/TeensyKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ void usb_keyboard_class::set_media(uint8_t c)

void usb_keyboard_class::send_now(void)
{
#if defined(USE_BOOT_KEYBOARD_PROTOCOL)
HID.SendReport(HID_REPORTID_NONE, keyboard_report_data,sizeof(keyboard_report_data));
#else
SendReport(keyboard_report_data,sizeof(keyboard_report_data));
#endif
}


Expand Down

0 comments on commit 0e29749

Please sign in to comment.