USB Host support stub. Doesn't work.

This commit is contained in:
Thomas Göttgens
2023-08-24 15:21:09 +02:00
parent f95b90364a
commit 15790fff73
13 changed files with 151 additions and 11 deletions

72
src/input/kbUsbBase.cpp Normal file
View File

@@ -0,0 +1,72 @@
#include "kbUsbBase.h"
#include "configuration.h"
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3
KbUsbBase::KbUsbBase(const char *name) : concurrency::OSThread(name)
{
this->_originName = name;
}
int32_t KbUsbBase::runOnce()
{
if (firstTime) {
// This is the first time the OSThread library has called this function, so init the USB HID routines
begin();
firstTime = 0;
} else {
task();
}
return 100;
}
void KbUsbBase::onKeyboardKey(uint8_t ascii, uint8_t keycode, uint8_t modifier)
{
if (ascii != 0) {
LOG_DEBUG("Key 0x%x Code 0x%x Mod 0x%x pressed\n", ascii, keycode, modifier);
// reset shift now that we have a keypress
InputEvent e;
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE;
e.source = this->_originName;
switch (ascii) {
case 0x1b: // ESC
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL;
break;
case 0x08: // Back
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK;
e.kbchar = ascii;
break;
case 0xb5: // Up
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP;
break;
case 0xb6: // Down
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN;
break;
case 0xb4: // Left
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT;
e.kbchar = ascii;
break;
case 0xb7: // Right
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT;
e.kbchar = ascii;
break;
case 0x0d: // Enter
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT;
break;
case 0x00: // nopress
e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE;
break;
default: // all other keys
e.inputEvent = ANYKEY;
e.kbchar = ascii;
break;
}
if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) {
this->notifyObservers(&e);
}
}
}
#endif

21
src/input/kbUsbBase.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include "InputBroker.h"
#include "concurrency/OSThread.h"
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3
#include "EspUsbHost.h"
class KbUsbBase : public Observable<const InputEvent *>, public concurrency::OSThread, public EspUsbHost
{
public:
explicit KbUsbBase(const char *name);
protected:
virtual int32_t runOnce() override;
private:
void onKeyboardKey(uint8_t ascii, uint8_t keycode, uint8_t modifier);
const char *_originName;
bool firstTime = 1;
};
#endif

15
src/input/kbUsbImpl.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include "KbUsbImpl.h"
#include "InputBroker.h"
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3
KbUsbImpl *kbUsbImpl;
KbUsbImpl::KbUsbImpl() : KbUsbBase("usbKB") {}
void KbUsbImpl::init()
{
inputBroker->registerSource(this);
}
#endif // INPUTBROKER_MATRIX_TYPE

19
src/input/kbUsbImpl.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include "kbUsbBase.h"
#include "main.h"
/**
* @brief The idea behind this class to have static methods for the event handlers.
* Check attachInterrupt() at RotaryEncoderInteruptBase.cpp
* Technically you can have as many rotary encoders hardver attached
* to your device as you wish, but you always need to have separate event
* handlers, thus you need to have a RotaryEncoderInterrupt implementation.
*/
class KbUsbImpl : public KbUsbBase
{
public:
KbUsbImpl();
void init();
};
extern KbUsbImpl *kbUsbImpl;