Skip to content

Commit ea011a8

Browse files
author
noseglasses
authored
Merge branch 'master' into pr_host_keymap
2 parents 7198b5f + 9158661 commit ea011a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+4407
-213
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This stub makefile for a Kaleidoscope example pulls in all the targets
2+
# required to build the example
3+
4+
UNAME_S := $(shell uname -s)
5+
6+
ifeq ($(UNAME_S),Darwin)
7+
SKETCHBOOK_DIR ?= $(HOME)/Documents/Arduino
8+
PACKAGE_DIR ?= $(HOME)/Library/Arduino15
9+
else
10+
SKETCHBOOK_DIR ?= $(HOME)/Arduino
11+
PACKAGE_DIR ?= $(HOME)/.arduino15
12+
endif
13+
14+
15+
ARDUINO_INSTALLED_ENV=$(shell ls -dt $(PACKAGE_DIR)/packages/keyboardio/hardware/avr 2>/dev/null |head -n 1)
16+
MANUALLY_INSTALLED_ENV=$(shell ls -dt $(SKETCHBOOK_DIR)/hardware/keyboardio/avr 2>/dev/null |head -n 1)
17+
18+
19+
20+
ifneq ("$(wildcard $(ARDUINO_INSTALLED_ENV)/boards.txt)","")
21+
22+
ifneq ("$(wildcard $(MANUALLY_INSTALLED_ENV)/boards.txt)","")
23+
24+
$(info ***************************************************************************)
25+
$(info It appears that you have installed two copies of Kaleidoscope. One copy was)
26+
$(info installed using Arduino's "Board Manager", while the other was installed by)
27+
$(info hand, probably using "git".)
28+
$(info )
29+
$(info This will likely cause some trouble as you try to build keyboard firmware)
30+
$(info using Kaleidoscope. You may want to remove either: )
31+
$(info )
32+
$(info $(PACKAGE_DIR)/packages/keyboardio/ which was installed using Arduino)
33+
$(info )
34+
$(info or)
35+
$(info )
36+
$(info $(SKETCHBOOK_DIR)/hardware/keyboardio/ which was installed by hand.)
37+
$(info )
38+
$(info ***************************************************************************)
39+
$(info )
40+
41+
endif
42+
43+
BOARD_HARDWARE_PATH = $(ARDUINO_INSTALLED_ENV)
44+
KALEIDOSCOPE_PLUGIN_MAKEFILE_DIR ?= build-tools/makefiles/
45+
KALEIDOSCOPE_BUILDER_DIR ?= $(ARDUINO_INSTALLED_ENV)/libraries/Kaleidoscope/bin/
46+
47+
48+
49+
endif
50+
51+
52+
BOARD_HARDWARE_PATH ?= $(SKETCHBOOK_DIR)/hardware
53+
KALEIDOSCOPE_PLUGIN_MAKEFILE_DIR ?= keyboardio/avr/build-tools/makefiles/
54+
55+
include $(BOARD_HARDWARE_PATH)/$(KALEIDOSCOPE_PLUGIN_MAKEFILE_DIR)/rules.mk
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/* -*- mode: c++ -*-
2+
* Basic -- A very basic Kaleidoscope example
3+
* Copyright (C) 2018 Keyboard.io, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under
6+
* the terms of the GNU General Public License as published by the Free Software
7+
* Foundation, version 3.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12+
* details.
13+
*
14+
* You should have received a copy of the GNU General Public License along with
15+
* this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "Kaleidoscope.h"
19+
20+
21+
// This example demonstrates how a plugin can gather information about
22+
// the keymap at compile time, e.g. to adapt its behavior, safe resources, ...
23+
24+
/* *INDENT-OFF* */
25+
KEYMAPS(
26+
[0] = KEYMAP_STACKED
27+
(
28+
Key_NoKey, Key_1, Key_1, Key_1, Key_4, Key_5, Key_NoKey,
29+
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
30+
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
31+
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
32+
33+
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
34+
Key_NoKey,
35+
36+
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
37+
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
38+
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
39+
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
40+
41+
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
42+
Key_NoKey
43+
),
44+
)
45+
/* *INDENT-ON* */
46+
47+
using namespace kaleidoscope::sketch_exploration;
48+
49+
class BPlugin : public kaleidoscope::Plugin {};
50+
class CPlugin : public kaleidoscope::Plugin {};
51+
52+
// A simple plugin that defines just one hook.
53+
//
54+
class APlugin : public kaleidoscope::Plugin {
55+
56+
public:
57+
APlugin() : has_key_1_{false} {}
58+
59+
template<typename _Sketch>
60+
kaleidoscope::EventHandlerResult exploreSketch() {
61+
62+
// Static keymap exploration
63+
64+
typedef typename _Sketch::StaticKeymap K;
65+
66+
// Important: Always make sure to call _Sketch::StaticKeymap's methods
67+
// in a constexpr context. This is done by
68+
// passing their value to a constexpr temporary variable.
69+
70+
constexpr uint8_t n_key_1 = K::collect(NumKeysEqual{Key_1});
71+
static_assert(n_key_1 == 3, "Error determining key count");
72+
73+
constexpr bool has_key_1 = K::collect(HasKey{Key_1});
74+
static_assert(has_key_1, "Error querying key existence");
75+
has_key_1_ = has_key_1; // Assign the temporary that was computed
76+
// at compile time.
77+
78+
constexpr Key max_key = K::collect(MaxKeyRaw{});
79+
static_assert(max_key.getRaw() > 0, "");
80+
81+
static_assert(K::getKey(0 /*layer*/, KeyAddr{2, 3}) == Key_D,
82+
"Key lookup failed");
83+
84+
constexpr auto n_layers = K::nLayers();
85+
constexpr auto layer_size = K::layerSize();
86+
87+
// Plugin exploration
88+
//
89+
// Use macros ENTRY_TYPE, ENRTY_IS_LAST, PLUGIN_POSITION,
90+
// PLUGIN_IS_REGISTERED and NUM_OCCURRENCES to retreive information
91+
// about the plugins that are registered in the sketch.
92+
93+
typedef typename _Sketch::Plugins P;
94+
95+
static_assert(std::is_same<ENTRY_TYPE(P, 0), APlugin>::value, "");
96+
static_assert(std::is_same<ENTRY_TYPE(P, 1), BPlugin>::value, "");
97+
98+
static_assert(P::size == 3, "");
99+
100+
static_assert(!ENRTY_IS_LAST(P, 0), "");
101+
static_assert(!ENRTY_IS_LAST(P, 1), "");
102+
static_assert(ENRTY_IS_LAST(P, 2), "");
103+
104+
static_assert(PLUGIN_POSITION(P, APlugin) == 0, "");
105+
static_assert(PLUGIN_POSITION(P, BPlugin) == 1, "");
106+
static_assert(PLUGIN_POSITION(P, CPlugin) == -1, "");
107+
108+
static_assert(PLUGIN_IS_REGISTERED(P, APlugin) == true, "");
109+
static_assert(PLUGIN_IS_REGISTERED(P, BPlugin) == true, "");
110+
static_assert(PLUGIN_IS_REGISTERED(P, CPlugin) == false, "");
111+
112+
static_assert(NUM_OCCURRENCES(P, APlugin) == 2, "");
113+
static_assert(NUM_OCCURRENCES(P, BPlugin) == 1, "");
114+
static_assert(NUM_OCCURRENCES(P, CPlugin) == 0, "");
115+
116+
return kaleidoscope::EventHandlerResult::OK;
117+
}
118+
119+
private:
120+
121+
bool has_key_1_;
122+
};
123+
124+
APlugin a_plugin1, a_plugin2;
125+
BPlugin b_plugin;
126+
127+
KALEIDOSCOPE_INIT_PLUGINS(
128+
a_plugin1,
129+
b_plugin,
130+
a_plugin2
131+
)
132+
133+
void setup() {
134+
Kaleidoscope.setup();
135+
}
136+
137+
void loop() {
138+
Kaleidoscope.loop();
139+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* -*- mode: c++ -*-
2+
* kaleidoscope::device::dygma::Raise -- Kaleidoscope device plugin for Dygma Raise
3+
* Copyright (C) 2017-2019 Keyboard.io, Inc
4+
* Copyright (C) 2017-2019 Dygma Lab S.L.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it under
7+
* the terms of the GNU General Public License as published by the Free Software
8+
* Foundation, version 3.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13+
* details.
14+
*
15+
* You should have received a copy of the GNU General Public License along with
16+
* this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
#include "kaleidoscope/device/dygma/Raise.h"

src/kaleidoscope/Kaleidoscope.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Kaleidoscope_::setup(void) {
3636
// properly.
3737
device().serialPort().begin(9600);
3838

39+
kaleidoscope::sketch_exploration::pluginsExploreSketch();
3940
kaleidoscope::Hooks::onSetup();
4041

4142
device().setup();

src/kaleidoscope/Kaleidoscope.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void setup();
3636
#include <math.h>
3737
#include <stdint.h>
3838

39-
#include KALEIDOSCOPE_HARDWARE_H
39+
#include "kaleidoscope/device/device.h"
4040
#include "kaleidoscope/device/key_indexes.h"
4141
#include "kaleidoscope_internal/device.h"
4242
#include "kaleidoscope_internal/deprecations.h"
@@ -87,6 +87,7 @@ static constexpr DEPRECATED(LED_COUNT) uint8_t LED_COUNT = kaleidoscope_internal
8787
#include "kaleidoscope/key_events.h"
8888
#include "kaleidoscope/hid.h"
8989
#include "kaleidoscope/layers.h"
90+
#include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h"
9091
#include "kaleidoscope/macro_map.h"
9192
#include "kaleidoscope_internal/event_dispatch.h"
9293
#include "kaleidoscope_internal/LEDModeManager.h"

src/kaleidoscope/KeyAddr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616

1717
#pragma once
1818

19-
#include KALEIDOSCOPE_HARDWARE_H
19+
#include "kaleidoscope/device/device.h"
2020

2121
typedef kaleidoscope::Device::KeyAddr KeyAddr;

src/kaleidoscope/device/ATMega32U4Keyboard.h

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)