From 7756f2f4b7b1561fbe40d6c06184e28a7660dea4 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sat, 18 Feb 2017 06:09:28 -0800 Subject: [PATCH] Begin work on keyboard device driver --- USBHost.h | 21 +++++++++++++++ k66_usbhost.ino | 1 + keyboard.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 keyboard.cpp diff --git a/USBHost.h b/USBHost.h index 3f32ecd..1d0f201 100644 --- a/USBHost.h +++ b/USBHost.h @@ -258,6 +258,27 @@ protected: uint8_t portstate[7]; }; +class KeyboardController : public USBDriver { +public: + KeyboardController(); + int available(); + int read(); + uint8_t getKey(); + uint8_t getModifiers(); + uint8_t getOemKey(); + void attachPress(void (*keyPressed)()); + void attachRelease(void (*keyReleased)()); +protected: + virtual bool claim(Device_t *device, int type, const uint8_t *descriptors); + virtual void disconnect(); + static void callback(const Transfer_t *transfer); + void new_data(const Transfer_t *transfer); +private: + void (*keyPressedFunction)(); + void (*keyReleasedFunction)(); + Pipe_t *datapipe; + uint8_t report[8]; +}; #endif diff --git a/k66_usbhost.ino b/k66_usbhost.ino index e76b3ad..bbe85e5 100644 --- a/k66_usbhost.ino +++ b/k66_usbhost.ino @@ -27,6 +27,7 @@ USBHost myusb; USBHub hub1; USBHub hub2; USBHub hub3; +KeyboardController keyboard; void setup() { diff --git a/keyboard.cpp b/keyboard.cpp new file mode 100644 index 0000000..eaf2bde --- /dev/null +++ b/keyboard.cpp @@ -0,0 +1,71 @@ +/* USB EHCI Host for Teensy 3.6 + * Copyright 2017 Paul Stoffregen (paul@pjrc.com) + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include "USBHost.h" + + +KeyboardController::KeyboardController() +{ + // TODO: free Device_t, Pipe_t & Transfer_t we will need + driver_ready_for_device(this); +} + +bool KeyboardController::claim(Device_t *dev, int type, const uint8_t *descriptors) +{ + Serial.print("KeyboardController claim this="); + Serial.println((uint32_t)this, HEX); + + // only claim at interface level + if (type != 1) return false; + + return false; + + uint32_t endpoint=1; + datapipe = new_Pipe(dev, 3, endpoint, 1, 8, 64); + queue_Data_Transfer(datapipe, report, 8, this); + return true; +} + +void KeyboardController::callback(const Transfer_t *transfer) +{ + Serial.println("KeyboardController Callback (static)"); + if (transfer->driver) { + ((KeyboardController *)(transfer->driver))->new_data(transfer); + } +} + +void KeyboardController::new_data(const Transfer_t *transfer) +{ + Serial.println("KeyboardController Callback (member)"); + // TODO: parse the new data + queue_Data_Transfer(datapipe, report, 8, this); +} + +void KeyboardController::disconnect() +{ + // TODO: free resources +} + + +