Skip to content

Commit

Permalink
wip hybrid bootkb
Browse files Browse the repository at this point in the history
  • Loading branch information
tlyu committed Nov 30, 2023
1 parent 619c4d2 commit 5dac1e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 128 deletions.
98 changes: 13 additions & 85 deletions src/kaleidoscope/driver/hid/base/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,6 @@ class NoBootKeyboard {
void onUSBReset() {}
};

class NoNKROKeyboard {
public:
NoNKROKeyboard() {}
void begin() {}

void sendReport() {}

void press(uint8_t code) {}
void release(uint8_t code) {}
void releaseAll() {}

bool isModifierActive(Key key) {
return false;
}
bool wasModifierActive(Key key) {
return false;
}
bool isAnyModifierActive() {
return false;
}
bool wasAnyModifierActive() {
return false;
}
bool isKeyPressed(uint8_t code) {
return false;
}

uint8_t getLeds() {
return 0;
}
};

class NoConsumerControl {
public:
NoConsumerControl() {}
Expand All @@ -125,7 +93,6 @@ class NoSystemControl {

struct KeyboardProps {
typedef NoBootKeyboard BootKeyboard;
typedef NoNKROKeyboard NKROKeyboard;
typedef NoConsumerControl ConsumerControl;
typedef NoSystemControl SystemControl;
};
Expand All @@ -134,7 +101,6 @@ template<typename _Props>
class Keyboard {
private:
typename _Props::BootKeyboard boot_keyboard_;
typename _Props::NKROKeyboard nkro_keyboard_;
typename _Props::ConsumerControl consumer_control_;
typename _Props::SystemControl system_control_;

Expand All @@ -143,24 +109,19 @@ class Keyboard {

void setup() __attribute__((noinline)) {
boot_keyboard_.begin();
nkro_keyboard_.begin();
consumer_control_.begin();
system_control_.begin();
}

void sendReport() __attribute__((noinline)) {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
boot_keyboard_.sendReport();
return;
boot_keyboard_.sendReport();
if (boot_keyboard_.getProtocol() != HID_BOOT_PROTOCOL) {
consumer_control_.sendReport();
}
nkro_keyboard_.sendReport();
consumer_control_.sendReport();
}
void releaseAllKeys() __attribute__((noinline)) {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
boot_keyboard_.releaseAll();
} else {
nkro_keyboard_.releaseAll();
boot_keyboard_.releaseAll();
if (boot_keyboard_.getProtocol() != HID_BOOT_PROTOCOL) {
consumer_control_.releaseAll();
}
}
Expand Down Expand Up @@ -204,21 +165,11 @@ class Keyboard {
// pressRawKey takes a Key object and calles KeyboardioHID's ".press" method
// with its keycode. It does no processing of any flags or modifiers on the key
void pressRawKey(Key pressed_key) {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
boot_keyboard_.press(pressed_key.getKeyCode());
return;
}

nkro_keyboard_.press(pressed_key.getKeyCode());
boot_keyboard_.press(pressed_key.getKeyCode());
}

void releaseRawKey(Key released_key) {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
boot_keyboard_.release(released_key.getKeyCode());
return;
}

nkro_keyboard_.release(released_key.getKeyCode());
boot_keyboard_.release(released_key.getKeyCode());
}

void releaseKey(Key released_key) {
Expand All @@ -227,50 +178,27 @@ class Keyboard {
}

bool isKeyPressed(Key key) {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
return boot_keyboard_.isKeyPressed(key.getKeyCode());
}
return nkro_keyboard_.isKeyPressed(key.getKeyCode());
return boot_keyboard_.isKeyPressed(key.getKeyCode());
}

bool isModifierKeyActive(Key modifier_key) {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
return boot_keyboard_.isModifierActive(modifier_key.getKeyCode());
}

return nkro_keyboard_.isModifierActive(modifier_key.getKeyCode());
return boot_keyboard_.isModifierActive(modifier_key.getKeyCode());
}

bool wasModifierKeyActive(Key modifier_key) {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
return boot_keyboard_.wasModifierActive(modifier_key.getKeyCode());
}

return nkro_keyboard_.wasModifierActive(modifier_key.getKeyCode());
return boot_keyboard_.wasModifierActive(modifier_key.getKeyCode());
}

bool isAnyModifierKeyActive() {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
return boot_keyboard_.isAnyModifierActive();
}

return nkro_keyboard_.isAnyModifierActive();
return boot_keyboard_.isAnyModifierActive();
}

bool wasAnyModifierKeyActive() {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
return boot_keyboard_.wasAnyModifierActive();
}

return nkro_keyboard_.wasAnyModifierActive();
return boot_keyboard_.wasAnyModifierActive();
}

uint8_t getKeyboardLEDs() {
if (boot_keyboard_.getProtocol() == HID_BOOT_PROTOCOL) {
return boot_keyboard_.getLeds();
}

return nkro_keyboard_.getLeds();
return boot_keyboard_.getLeds();
}

uint8_t getProtocol() {
Expand Down
43 changes: 0 additions & 43 deletions src/kaleidoscope/driver/hid/keyboardio/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,48 +96,6 @@ class BootKeyboardWrapper {
}
};

class NKROKeyboardWrapper {
public:
NKROKeyboardWrapper() {}
void begin() {
Keyboard.begin();
}

void sendReport() {
Keyboard.sendReport();
}

void press(uint8_t code) {
Keyboard.press(code);
}
void release(uint8_t code) {
Keyboard.release(code);
}
void releaseAll() {
Keyboard.releaseAll();
}

bool isKeyPressed(uint8_t code) {
return Keyboard.isKeyPressed(code);
}
bool isModifierActive(uint8_t code) {
return Keyboard.isModifierActive(code);
}
bool wasModifierActive(uint8_t code) {
return Keyboard.wasModifierActive(code);
}
bool isAnyModifierActive() {
return Keyboard.isAnyModifierActive();
}
bool wasAnyModifierActive() {
return Keyboard.wasAnyModifierActive();
}

uint8_t getLeds() {
return Keyboard.getLEDs();
}
};

class ConsumerControlWrapper {
public:
ConsumerControlWrapper() {}
Expand Down Expand Up @@ -177,7 +135,6 @@ class SystemControlWrapper {

struct KeyboardProps : public base::KeyboardProps {
typedef BootKeyboardWrapper BootKeyboard;
typedef NKROKeyboardWrapper NKROKeyboard;
typedef ConsumerControlWrapper ConsumerControl;
typedef SystemControlWrapper SystemControl;
};
Expand Down

0 comments on commit 5dac1e0

Please sign in to comment.