usb_usb: Add multiple keyboard support

it supports four keyboards and two cascaded hubs
This commit is contained in:
tmk 2016-06-21 13:49:06 +09:00
parent 60b88f155e
commit 148c6a5175
7 changed files with 238 additions and 191 deletions

View file

@ -28,6 +28,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define XSTR(s) #s
#ifdef __cplusplus
extern "C" {
#endif
uint8_t bitpop(uint8_t bits);
uint8_t bitpop16(uint16_t bits);
uint8_t bitpop32(uint32_t bits);
@ -40,4 +44,8 @@ uint8_t bitrev(uint8_t bits);
uint16_t bitrev16(uint16_t bits);
uint32_t bitrev32(uint32_t bits);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -4,30 +4,14 @@
#include "debug.h"
report_keyboard_t usb_hid_keyboard_report;
uint16_t usb_hid_time_stamp;
void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
bool is_error = false;
report_keyboard_t *report = (report_keyboard_t *)buf;
::memcpy(&report, buf, sizeof(report_keyboard_t));
time_stamp = millis();
dprintf("keyboard input: %02X %02X", report->mods, report->reserved);
dprintf("input %d: %02X %02X", hid->GetAddress(), report.mods, report.reserved);
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
if (IS_ERROR(report->keys[i])) {
is_error = true;
}
dprintf(" %02X", report->keys[i]);
dprintf(" %02X", report.keys[i]);
}
dprint("\r\n");
// ignore error and not send report to computer
if (is_error) {
dprint("Error usage! \r\n");
return;
}
::memcpy(&usb_hid_keyboard_report, buf, sizeof(report_keyboard_t));
usb_hid_time_stamp = millis();
}

View file

@ -2,11 +2,14 @@
#define PARSER_H
#include "hid.h"
#include "report.h"
class KBDReportParser : public HIDReportParser
{
public:
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
report_keyboard_t report;
uint16_t time_stamp;
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};
#endif