From cf8fbd80f47a544bd9504feea13586cff1cb546e Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Tue, 7 Jul 2020 06:25:04 -0400 Subject: [PATCH] testing USB host --- teensy/teensy-usb.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ teensy/teensy-usb.h | 21 +++++++++++++++++++++ teensy/teensy.ino | 23 +++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 teensy/teensy-usb.cpp create mode 100644 teensy/teensy-usb.h diff --git a/teensy/teensy-usb.cpp b/teensy/teensy-usb.cpp new file mode 100644 index 0000000..28e370e --- /dev/null +++ b/teensy/teensy-usb.cpp @@ -0,0 +1,40 @@ +#include +#include +#include "teensy-usb.h" + +USBHost myusb; +USBHub hub1(myusb); +USBHub hub2(myusb); +USBHub hub3(myusb); +KeyboardController keyboard1(myusb); +KeyboardController keyboard2(myusb); + +TeensyUSB::TeensyUSB() +{ +} + +TeensyUSB::~TeensyUSB() +{ +} + +void TeensyUSB::init() +{ + myusb.begin(); +} + +void TeensyUSB::attachKeypress(keyboardCallback cb) +{ + keyboard1.attachPress(cb); + keyboard2.attachPress(cb); +} + +void TeensyUSB::attachKeyrelease(keyboardCallback cb) +{ + keyboard1.attachRelease(cb); + keyboard2.attachRelease(cb); +} + +void TeensyUSB::maintain() +{ + myusb.Task(); +} diff --git a/teensy/teensy-usb.h b/teensy/teensy-usb.h new file mode 100644 index 0000000..2789f4a --- /dev/null +++ b/teensy/teensy-usb.h @@ -0,0 +1,21 @@ +#ifndef __TEENSY_USB +#define __TEENSY_USB + +#include +#include + +typedef void (*keyboardCallback)(int unicode); + +class TeensyUSB { + public: + TeensyUSB(); + ~TeensyUSB(); + + void init(); + void attachKeypress(keyboardCallback cb); + void attachKeyrelease(keyboardCallback cb); + + void maintain(); +}; + +#endif diff --git a/teensy/teensy.ino b/teensy/teensy.ino index 00b3447..f803c96 100644 --- a/teensy/teensy.ino +++ b/teensy/teensy.ino @@ -10,6 +10,7 @@ #include "teensy-speaker.h" #include "teensy-paddles.h" #include "teensy-filemanager.h" +#include "teensy-usb.h" #include "appleui.h" #include "teensy-prefs.h" #include "teensy-println.h" @@ -35,6 +36,22 @@ BIOS bios; static time_t getTeensy3Time() { return Teensy3Clock.get(); } +TeensyUSB usb; + +void onKeypress(int unicode) +{ + Serial.print("onKeypress:"); + Serial.println(unicode); + // vmkeyboard->keyDepressed(keypad.key[i].kchar); +} + +void onKeyrelease(int unicode) +{ + Serial.print("onKeyrelease: "); + Serial.println(unicode); + // vmkeyboard->keyReleased(keypad.key[i].kchar); +} + void setup() { Serial.begin(230400); @@ -104,6 +121,11 @@ void setup() println(" cpu"); g_cpu = new Cpu(); + println(" usb"); + usb.init(); + usb.attachKeypress(onKeypress); + usb.attachKeyrelease(onKeyrelease); + Serial.print("Free RAM: "); println(FreeRamEstimate()); @@ -277,6 +299,7 @@ void loop() } g_keyboard->maintainKeyboard(); + usb.maintain(); //debugLCDState = !debugLCDState; //digitalWrite(57, debugLCDState);