-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
USB Host support stub. Doesn't work.
- Loading branch information
Showing
13 changed files
with
151 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ extends = esp32_base | |
|
||
monitor_speed = 115200 | ||
|
||
lib_deps = ${esp32_base.lib_deps} | ||
tanakamasayuki/EspUsbHost@^1.0.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters