Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hid::Keyboardio: Make it possible to switch the default protocol via Props #772

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions doc/plugin/OneShot.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ plugin:
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-OneShot.h>
#include <kaleidoscope/hid.h>

// somewhere in the keymap...
OSM(LeftControl), OSL(_FN)
Expand Down Expand Up @@ -108,8 +107,8 @@ modifiers and one-shot layer keys. It has the following methods:
### `.isModifierActive(key)`

> Returns if the modifier `key` has a one-shot state active. Use this together
> with `hid::isModifierKeyActive` to catch cases where a one-shot modifier is
> active, but not registered yet.
> with `Kaleidoscope.hid().keyboard().isModifierKeyActive` to catch cases where
> a one-shot modifier is active, but not registered yet.

### `.cancel([with_stickies])`

Expand Down
5 changes: 2 additions & 3 deletions doc/plugin/Syster.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ will handle the symbol actions:
#include <Kaleidoscope-HostOS.h>
#include <Kaleidoscope-Syster.h>
#include <Kaleidoscope-Unicode.h>
#include <kaleidoscope/hid.h>

void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *symbol) {
switch (action) {
Expand All @@ -29,9 +28,9 @@ void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *sym
break;
case kaleidoscope::plugin::Syster::EndAction:
handleKeyswitchEvent (Key_Backspace, UnknownKeyswitchLocation, IS_PRESSED | INJECTED);
kaleidoscope::hid::sendKeyboardReport ();
Kaleidoscope.hid().keyboard().sendReport();
handleKeyswitchEvent (Key_Backspace, UnknownKeyswitchLocation, WAS_PRESSED | INJECTED);
kaleidoscope::hid::sendKeyboardReport ();
Kaleidoscope.hid().keyboard().sendReport();
break;
case kaleidoscope::plugin::Syster::SymbolAction:
Kaleidoscope.serialPort().print ("systerAction: symbol=");
Expand Down
5 changes: 2 additions & 3 deletions examples/Keystrokes/Syster/Syster.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <Kaleidoscope-HostOS.h>
#include <Kaleidoscope-Syster.h>
#include <Kaleidoscope-Unicode.h>
#include <kaleidoscope/hid.h>

// *INDENT-OFF*
KEYMAPS(
Expand Down Expand Up @@ -51,9 +50,9 @@ void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *sym
break;
case kaleidoscope::plugin::Syster::EndAction:
handleKeyswitchEvent(Key_Backspace, UnknownKeyswitchLocation, IS_PRESSED | INJECTED);
kaleidoscope::hid::sendKeyboardReport();
Kaleidoscope.hid().keyboard().sendReport();
handleKeyswitchEvent(Key_Backspace, UnknownKeyswitchLocation, WAS_PRESSED | INJECTED);
kaleidoscope::hid::sendKeyboardReport();
Kaleidoscope.hid().keyboard().sendReport();
break;
case kaleidoscope::plugin::Syster::SymbolAction:
Kaleidoscope.serialPort().print("systerAction: symbol=");
Expand Down
1 change: 0 additions & 1 deletion src/Kaleidoscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ static constexpr DEPRECATED(LED_COUNT) uint8_t LED_COUNT = kaleidoscope_internal

#include "kaleidoscope/KeyAddr.h"
#include "kaleidoscope/key_events.h"
#include "kaleidoscope/hid.h"
#include "kaleidoscope/layers.h"
#include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h"
#include "kaleidoscope/macro_map.h"
Expand Down
9 changes: 2 additions & 7 deletions src/kaleidoscope/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include "kaleidoscope/Runtime.h"
#include "kaleidoscope/hid.h"
#include "kaleidoscope/layers.h"
#include "kaleidoscope/keyswitch_state.h"

Expand Down Expand Up @@ -43,10 +42,6 @@ Runtime_::setup(void) {

device().setup();

kaleidoscope::hid::initializeKeyboard();
kaleidoscope::hid::initializeConsumerControl();
kaleidoscope::hid::initializeSystemControl();

// Update the keymap cache, so we start with a non-empty state.
Layer.updateActiveLayers();
for (auto key_addr : KeyAddr::all()) {
Expand All @@ -64,8 +59,8 @@ Runtime_::loop(void) {

kaleidoscope::Hooks::beforeReportingState();

kaleidoscope::hid::sendKeyboardReport();
kaleidoscope::hid::releaseAllKeys();
device().hid().keyboard().sendReport();
device().hid().keyboard().releaseAllKeys();

kaleidoscope::Hooks::afterEachCycle();
}
Expand Down
4 changes: 4 additions & 0 deletions src/kaleidoscope/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class Runtime_ {
return device().storage();
}

auto hid() -> decltype(device().hid()) & {
return device().hid();
}

void rebootBootloader() {
device().rebootBootloader();
}
Expand Down
15 changes: 14 additions & 1 deletion src/kaleidoscope/device/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "kaleidoscope_internal/deprecations.h"
#include "kaleidoscope/macro_helpers.h"

#include "kaleidoscope/driver/hid/Keyboardio.h"
#include "kaleidoscope/driver/keyscanner/None.h"
#include "kaleidoscope/driver/led/None.h"
#include "kaleidoscope/driver/mcu/None.h"
Expand Down Expand Up @@ -52,6 +53,8 @@ namespace kaleidoscope {
namespace device {

struct BaseProps {
typedef kaleidoscope::driver::hid::KeyboardioProps HIDProps;
typedef kaleidoscope::driver::hid::Keyboardio<HIDProps> HID;
typedef kaleidoscope::driver::keyscanner::BaseProps KeyScannerProps;
typedef kaleidoscope::driver::keyscanner::None KeyScanner;
typedef kaleidoscope::driver::led::BaseProps LEDDriverProps;
Expand All @@ -77,6 +80,8 @@ class Base {

typedef _DeviceProps Props;

typedef typename _DeviceProps::HIDProps HIDProps;
typedef typename _DeviceProps::HID HID;
typedef typename _DeviceProps::KeyScanner KeyScanner;
typedef typename _DeviceProps::KeyScannerProps KeyScannerProps;
typedef typename _DeviceProps::KeyScannerProps::KeyAddr KeyAddr;
Expand All @@ -101,6 +106,13 @@ class Base {
return matrix_columns * matrix_rows;
}

/**
* Returns the HID driver used by the keyboard.
*/
HID &hid() {
return hid_;
}

/**
* Returns the storage driver used by the keyboard.
*/
Expand Down Expand Up @@ -474,6 +486,7 @@ class Base {
void setup() {
bootloader_.setup();
mcu_.setup();
hid_.setup();
storage_.setup();
key_scanner_.setup();
led_driver_.setup();
Expand Down Expand Up @@ -507,6 +520,7 @@ class Base {
/** @} */

protected:
HID hid_;
KeyScanner key_scanner_;
LEDDriver led_driver_;
MCU mcu_;
Expand Down Expand Up @@ -534,4 +548,3 @@ class Base {
#define EXPORT_DEVICE(DEVICE) \
typedef DEVICE##Props DeviceProps;
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD

5 changes: 2 additions & 3 deletions src/kaleidoscope/device/dygma/Raise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <KeyboardioHID.h>
#include <Wire.h>

#include "kaleidoscope/hid.h"
#include "kaleidoscope/util/crc16.h"
#include "kaleidoscope/driver/color/GammaCorrection.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
Expand Down Expand Up @@ -418,8 +417,8 @@ void RaiseKeyScanner::setup() {
void RaiseKeyScanner::reset() {
leftHandState.all = 0;
rightHandState.all = 0;
kaleidoscope::hid::releaseAllKeys();
kaleidoscope::hid::sendKeyboardReport();
Kaleidoscope.hid().keyboard().releaseAllKeys();
Kaleidoscope.hid().keyboard().sendReport();
}

/********* Hardware plugin *********/
Expand Down
1 change: 0 additions & 1 deletion src/kaleidoscope/device/dygma/Raise.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#ifdef ARDUINO_SAMD_RAISE
#include <Arduino.h>

#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
#include "kaleidoscope/device/dygma/raise/Hand.h"

#define CRGB(r,g,b) (cRGB){b, g, r}
Expand Down
3 changes: 2 additions & 1 deletion src/kaleidoscope/device/ez/ErgoDox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#ifdef ARDUINO_AVR_ERGODOX

#include "kaleidoscope/Runtime.h"
#include <KeyboardioHID.h>
#include <avr/wdt.h>
#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h"
#include "kaleidoscope/key_events.h"
Expand Down Expand Up @@ -78,6 +77,8 @@ void ErgoDox::setup(void) {
ICR1 = cycles;
TCCR1B = _BV(WGM13) | _BV(CS10);
TIMSK1 = _BV(TOIE1);

hid_.setup();
}

ISR(TIMER1_OVF_vect) {
Expand Down
2 changes: 0 additions & 2 deletions src/kaleidoscope/device/ez/ErgoDox.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

#include <Arduino.h>

#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"

struct cRGB {
uint8_t r, g, b;
};
Expand Down
2 changes: 1 addition & 1 deletion src/kaleidoscope/device/keyboardio/Model01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ uint8_t Model01KeyScanner::previousPressedKeyswitchCount() {
/********* Hardware plugin *********/

void Model01::setup() {
KeyScanner::setup();
Model01Hands::setup();
kaleidoscope::device::Base<Model01Props>::setup();

TWBR = 12; // This is 400mhz, which is the fastest we can drive the ATTiny
}
Expand Down
3 changes: 1 addition & 2 deletions src/kaleidoscope/device/keyboardio/Model01.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ struct cRGB {

#include "kaleidoscope/driver/keyscanner/Base.h"
#include "kaleidoscope/driver/led/Base.h"
#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
#include "kaleidoscope/driver/bootloader/avr/Caterina.h"

#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
Expand Down Expand Up @@ -126,7 +125,7 @@ struct Model01Props : public kaleidoscope::device::ATmega32U4KeyboardProps {

class Model01 : public kaleidoscope::device::ATmega32U4Keyboard<Model01Props> {
public:
static void setup();
void setup();

static void enableHardwareTestMode();
};
Expand Down
68 changes: 68 additions & 0 deletions src/kaleidoscope/driver/hid/Base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// -*- mode: c++ -*-
/* Kaleidoscope - Firmware for computer input devices
* Copyright (C) 2013-2019 Keyboard.io, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include <Arduino.h>
#include "kaleidoscope/key_defs.h"

#include "base/Keyboard.h"
#include "base/Mouse.h"
#include "base/AbsoluteMouse.h"

namespace kaleidoscope {
namespace driver {
namespace hid {

struct BaseProps {
typedef base::KeyboardProps KeyboardProps;
typedef base::Keyboard<KeyboardProps> Keyboard;
typedef base::MouseProps MouseProps;
typedef base::Mouse<MouseProps> Mouse;
typedef base::AbsoluteMouseProps AbsoluteMouseProps;
typedef base::AbsoluteMouse<AbsoluteMouseProps> AbsoluteMouse;
};

template <typename _Props>
class Base {
private:
typename _Props::Keyboard keyboard_;
typename _Props::Mouse mouse_;
typename _Props::AbsoluteMouse absolute_mouse_;

public:
Base() {}

void setup() {
keyboard().setup();
}

auto keyboard() -> decltype(keyboard_) & {
return keyboard_;
}

auto mouse() -> decltype(mouse_) & {
return mouse_;
}

auto absoluteMouse() -> decltype(absolute_mouse_) & {
return absolute_mouse_;
}
};

}
}
}
53 changes: 53 additions & 0 deletions src/kaleidoscope/driver/hid/Keyboardio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// -*- mode: c++ -*-
/* Kaleidoscope - Firmware for computer input devices
* Copyright (C) 2013-2019 Keyboard.io, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include <Arduino.h>
#include <KeyboardioHID.h>
#include "kaleidoscope/key_defs.h"

#include "kaleidoscope/driver/hid/Base.h"

#include "keyboardio/Keyboard.h"
#include "keyboardio/Mouse.h"
#include "keyboardio/AbsoluteMouse.h"

namespace kaleidoscope {
namespace driver {
namespace hid {

struct KeyboardioProps: public BaseProps {
typedef keyboardio::KeyboardProps KeyboardProps;
typedef keyboardio::Keyboard<KeyboardProps> Keyboard;
typedef keyboardio::MouseProps MouseProps;
typedef keyboardio::Mouse<MouseProps> Mouse;
typedef keyboardio::AbsoluteMouseProps AbsoluteMouseProps;
typedef keyboardio::AbsoluteMouse<AbsoluteMouseProps> AbsoluteMouse;
};

template <typename _Props>
class Keyboardio: public Base<_Props> {
public:
void setup() {
Base<_Props>::keyboard().setDefaultProtocol(_Props::KeyboardProps::default_protocol);
Base<_Props>::setup();
}
};

}
}
}
Loading