working on USB keyboard support; fix pin assignments

This commit is contained in:
Jorj Bauer 2020-07-08 09:44:33 -04:00
parent bfa402104d
commit fe44c2135c
3 changed files with 45 additions and 7 deletions

View File

@ -38,3 +38,15 @@ void TeensyUSB::maintain()
{ {
myusb.Task(); myusb.Task();
} }
uint8_t TeensyUSB::getModifiers()
{
// FIXME: specifically keyboard1? guess the callbacks need a kb #
return keyboard1.getModifiers();
}
uint8_t TeensyUSB::getOemKey()
{
// same FIXME as getModifiers
return keyboard1.getOemKey();
}

View File

@ -15,6 +15,9 @@ class TeensyUSB {
void attachKeypress(keyboardCallback cb); void attachKeypress(keyboardCallback cb);
void attachKeyrelease(keyboardCallback cb); void attachKeyrelease(keyboardCallback cb);
uint8_t getModifiers();
uint8_t getOemKey();
void maintain(); void maintain();
}; };

View File

@ -20,8 +20,8 @@
#endif #endif
#define RESETPIN 39 #define RESETPIN 39
#define BATTERYPIN 32 #define BATTERYPIN 38
#define SPEAKERPIN A17 // aka digital 41 #define SPEAKERPIN A16 // aka digital 40
#include "globals.h" #include "globals.h"
#include "teensy-crash.h" #include "teensy-crash.h"
@ -42,6 +42,14 @@ void onKeypress(int unicode)
{ {
Serial.print("onKeypress:"); Serial.print("onKeypress:");
Serial.println(unicode); Serial.println(unicode);
uint8_t modifiers = usb.getModifiers();
Serial.print("Modifiers: ");
Serial.println(modifiers, HEX);
if (unicode == 0) {
unicode = usb.getOemKey();
Serial.print("oemKey: ");
Serial.println(unicode);
}
// vmkeyboard->keyDepressed(keypad.key[i].kchar); // vmkeyboard->keyDepressed(keypad.key[i].kchar);
} }
@ -49,6 +57,14 @@ void onKeyrelease(int unicode)
{ {
Serial.print("onKeyrelease: "); Serial.print("onKeyrelease: ");
Serial.println(unicode); Serial.println(unicode);
uint8_t modifiers = usb.getModifiers();
Serial.print("Modifiers: ");
Serial.println(modifiers, HEX);
if (unicode == 0) {
unicode = usb.getOemKey();
Serial.print("oemKey: ");
Serial.println(unicode);
}
// vmkeyboard->keyReleased(keypad.key[i].kchar); // vmkeyboard->keyReleased(keypad.key[i].kchar);
} }
@ -306,6 +322,9 @@ void loop()
doDebugging(); doDebugging();
// FIXME: this is sometimes *VERY* slow.
uint32_t startDisp = millis();
uint32_t cpuBefore = g_cpu->cycles;
g_ui->blit(); g_ui->blit();
g_vm->vmdisplay->lockDisplay(); g_vm->vmdisplay->lockDisplay();
if (g_vm->vmdisplay->needsRedraw()) { // necessary for the VM to redraw if (g_vm->vmdisplay->needsRedraw()) { // necessary for the VM to redraw
@ -317,6 +336,14 @@ void loop()
} }
g_display->blit(); // Blit the whole thing, including UI area g_display->blit(); // Blit the whole thing, including UI area
g_vm->vmdisplay->unlockDisplay(); g_vm->vmdisplay->unlockDisplay();
uint32_t dispTime = millis() - startDisp;
uint32_t cpuAfter = g_cpu->cycles;
if (dispTime > 30) {
Serial.print("Slow blit: ");
Serial.print(dispTime);
Serial.print(" cpu ran: ");
Serial.println(cpuAfter - cpuBefore);
}
static unsigned long nextBattCheck = millis() + 30;// debugging static unsigned long nextBattCheck = millis() + 30;// debugging
static int batteryLevel = 0; // static for debugging code! When done static int batteryLevel = 0; // static for debugging code! When done
@ -329,11 +356,7 @@ void loop()
// This is a bit disruptive - but the external 3.3v will drop along with the battery level, so we should use the more stable (I hope) internal 1.7v. // This is a bit disruptive - but the external 3.3v will drop along with the battery level, so we should use the more stable (I hope) internal 1.7v.
// The alternative is to build a more stable buck/boost regulator for reference... // The alternative is to build a more stable buck/boost regulator for reference...
println("FIXME: analogReference for Teensy 4.0 => batteryLevel");
/*
analogReference(INTERNAL);
batteryLevel = analogRead(BATTERYPIN); batteryLevel = analogRead(BATTERYPIN);
analogReference(EXTERNAL);*/
/* LiIon charge to a max of 4.2v; and we should not let them discharge below about 3.5v. /* LiIon charge to a max of 4.2v; and we should not let them discharge below about 3.5v.
* With a resistor voltage divider of Z1=39k, Z2=10k we're looking at roughly 20.4% of * With a resistor voltage divider of Z1=39k, Z2=10k we're looking at roughly 20.4% of
@ -349,7 +372,7 @@ void loop()
* 3.46v = 144 - 146 * 3.46v = 144 - 146
* 4.21v = 172 * 4.21v = 172
*/ */
#if 0 #if 1
Serial.print("battery: "); Serial.print("battery: ");
println(batteryLevel); println(batteryLevel);
#endif #endif