Skip to content

Commit

Permalink
Configure keyboard matrix from info.json (qmk#10817)
Browse files Browse the repository at this point in the history
* Make parameters from info.json available to the build system

* move all clueboard settings to info.json

* code formatting

* make flake8 happy

* make flake8 happy

* make qmk lint happy

* Add support for specifying led indicators in json

* move led indicators to the clueboard info.json

* Apply suggestions from code review

Co-authored-by: Erovia <Erovia@users.noreply.github.com>

* add missing docstring

Co-authored-by: Erovia <Erovia@users.noreply.github.com>
  • Loading branch information
skullydazed and Erovia authored Dec 30, 2020
1 parent f231f24 commit 47b9b11
Show file tree
Hide file tree
Showing 79 changed files with 4,787 additions and 3,897 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ endef
%:
# Check if we have the CMP tool installed
cmp $(ROOT_DIR)/Makefile $(ROOT_DIR)/Makefile >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi;
# Ensure that bin/qmk works. This will be a failing check after the next develop merge
if ! bin/qmk hello 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; fi
# Ensure that bin/qmk works.
if ! bin/qmk hello 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; exit 1; fi
# Check if the submodules are dirty, and display a warning if they are
ifndef SKIP_GIT
if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 50 --init lib/chibios; fi
Expand Down
33 changes: 31 additions & 2 deletions build_keyboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ ifneq ("$(wildcard $(KEYBOARD_PATH_1)/rules.mk)","")
include $(KEYBOARD_PATH_1)/rules.mk
endif


MAIN_KEYMAP_PATH_1 := $(KEYBOARD_PATH_1)/keymaps/$(KEYMAP)
MAIN_KEYMAP_PATH_2 := $(KEYBOARD_PATH_2)/keymaps/$(KEYMAP)
MAIN_KEYMAP_PATH_3 := $(KEYBOARD_PATH_3)/keymaps/$(KEYMAP)
MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP)
MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP)

# Pull in rules from info.json
INFO_RULES_MK = $(shell bin/qmk generate-rules-mk --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/rules.mk)
include $(INFO_RULES_MK)

# Check for keymap.json first, so we can regenerate keymap.c
include build_json.mk

Expand Down Expand Up @@ -290,6 +293,32 @@ ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
CONFIG_H += $(KEYMAP_PATH)/config.h
endif

# Pull in stuff from info.json
INFO_JSON_FILES :=
ifneq ("$(wildcard $(KEYBOARD_PATH_1)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_1)/info.json
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_2)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_2)/info.json
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_3)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_3)/info.json
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_4)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_4)/info.json
endif
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/info.json)","")
INFO_JSON_FILES += $(KEYBOARD_PATH_5)/info.json
endif

CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h

$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES)
bin/qmk generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h

$(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES)
bin/qmk generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h

# project specific files
SRC += $(KEYBOARD_SRC) \
$(KEYMAP_C) \
Expand Down Expand Up @@ -364,7 +393,7 @@ all:
echo "skipped" >&2
endif

build: elf cpfirmware
build: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h elf cpfirmware
check-size: build
objs-size: build

Expand Down
157 changes: 136 additions & 21 deletions docs/reference_info_json.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,20 @@ The `info.json` file is a JSON formatted dictionary with the following keys avai
* Width of the board in Key Units
* `height`
* Height of the board in Key Units
* `debounce`
* How many milliseconds (ms) to wait for debounce to happen. (Default: 5)
* `diode_direction`
* The direction diodes face. See [`DIRECT_PINS` in the hardware configuration](https://docs.qmk.fm/#/config_options?id=hardware-options) for more details.
* `layout_aliases`
* A dictionary containing layout aliases. The key is the alias and the value is a layout in `layouts` it maps to.
* `layouts`
* Physical Layout representations. See the next section for more detail.
* Physical Layout representations. See the [Layout Format](#layout_format) section for more detail.
* `matrix_pins`
* Configure the pins corresponding to columns and rows, or direct pins. See [Matrix Pins](#matrix_pins) for more detail.
* `rgblight`
* Configure the [RGB Lighting feature](feature_rgblight.md). See the [RGB Lighting](#rgb_lighting) section for more detail.
* `usb`
* Configure USB VID, PID, and other parameters. See [USB](#USB) for more detail.

### Layout Format

Expand Down Expand Up @@ -49,25 +61,128 @@ All key positions and rotations are specified in relation to the top-left corner
* The width of the key, in Key Units. Ignored if `ks` is provided. Default: `1`
* `h`
* The height of the key, in Key Units. Ignored if `ks` is provided. Default: `1`
* `r`
* How many degrees clockwise to rotate the key.
* `rx`
* The absolute position of the point to rotate the key around in the horizontal axis. Default: `x`
* `ry`
* The absolute position of the point to rotate the key around in the vertical axis. Default: `y`
* `ks`
* Key Shape: define a polygon by providing a list of points, in Key Units.
* **Important**: These are relative to the top-left of the key, not absolute.
* Example ISO Enter: `[ [0,0], [1.5,0], [1.5,2], [0.25,2], [0.25,1], [0,1], [0,0] ]`
* `label`
* What to name this position in the matrix.
* This should usually be the same name as what is silkscreened on the PCB at this location.

## How is the Metadata Exposed?

This metadata is primarily used in two ways:

* To allow web-based configurators to dynamically generate UI
* To support the new `make keyboard:keymap:qmk` target, which bundles this metadata up with the firmware to allow QMK Toolbox to be smarter.

Configurator authors can see the [QMK Compiler](https://docs.api.qmk.fm/using-the-api) docs for more information on using the JSON API.
* This should usually correspond to the keycode for the first layer of the default keymap.
* `matrix`
* A 2 item list describing the row and column location for this key.

### Matrix Pins

Currently QMK supports connecting switches either directly to GPIO pins or via a switch matrix. At this time you can not combine these, they are mutually exclusive.

#### Switch Matrix

Most keyboards use a switch matrix to connect keyswitches to the MCU. You can define your pin columns and rows to configure your switch matrix. When defining switch matrices you should also define your `diode_direction`.

Example:

```json
{
"diode_direction": "COL2ROW",
"matrix_pins": {
"cols": ["F4", "E6", "B1", "D2"],
"rows": ["B0", "D3", "D5", "D4", "D6"]
}
}
```

#### Direct Pins

Direct pins are when you connect one side of the switch to GND and the other side to a GPIO pin on your MCU. No diode is required, but there is a 1:1 mapping between switches and pins.

When specifying direct pins you need to arrange them in nested arrays. The outer array consists of rows, while the inner array is a text string corresponding to a pin. You can use `null` to indicate an empty spot in the matrix.

Example:

```json
{
"matrix_pins": {
"direct": [
["A10", "A9"],
["A0", "B8"],
[null, "B11"],
["B9", "A8"],
["A7", "B1"],
[null, "B2"]
]
}
```

### RGB Lighting

This section controls the legacy WS2812 support in QMK. This should not be confused with the RGB Matrix feature, which can be used to control both WS2812 and ISSI RGB LEDs.

The following items can be set. Not every value is required.

* `led_count`
* The number of LEDs in your strip
* `pin`
* The GPIO pin that your LED strip is connected to
* `animations`
* A dictionary that lists enabled and disabled animations. See [RGB Light Animations](#rgb_light_animations) below.
* `sleep`
* Set to `true` to enable lighting during host sleep
* `split`
* Set to `true` to enable synchronization functionality between split halves
* `split_count`
* For split keyboards, the number of LEDs on each side
* `max_brightness`
* (0-255) What the maxmimum brightness (value) level is
* `hue_steps`
* How many steps of adjustment to have for hue
* `saturation_steps`
* How many steps of adjustment to have for saturation
* `brightness_steps`
* How many steps of adjustment to have for brightness (value)

Example:

```json
{
"rgblight": {
"led_count": 4,
"pin": "F6",
"hue_steps": 10,
"saturation_steps": 17,
"brightness_steps": 17,
"animations": {
"all": true
}
}
}
```

#### RGB Light Animations

The following animations can be enabled:

| Key | Description |
|-----|-------------|
| `all` | Enable all additional animation modes. |
| `alternating` | Enable alternating animation mode. |
| `breathing` | Enable breathing animation mode. |
| `christmas` | Enable christmas animation mode. |
| `knight` | Enable knight animation mode. |
| `rainbow_mood` | Enable rainbow mood animation mode. |
| `rainbow_swirl` | Enable rainbow swirl animation mode. |
| `rgb_test` | Enable RGB test animation mode. |
| `snake` | Enable snake animation mode. |
| `static_gradient` | Enable static gradient mode. |
| `twinkle` | Enable twinkle animation mode. |

### USB

Every USB keyboard needs to have its USB parmaters defined. At a minimum you need to set vid, pid, and device version.

Example:

```json
{
"usb": {
"vid": "0xC1ED",
"pid": "0x23B0",
"device_ver": "0x0001"
}
}
```
33 changes: 0 additions & 33 deletions keyboards/clueboard/17/17.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,4 @@

#include "quantum.h"


/* Cluepad matrix layout
* .-------------------.
* |NLCK| /| *| -|
* |-------------------|
* | 7| 8| 9| |
* |--------------| |
* | 4| 5| 6| +|
* |-------------------|
* | 1| 2| 3| |
* |--------------| |
* | 0| .| Ent|
* '-------------------'
*/
// The first section contains all of the arguments
// The second converts the arguments into a two-dimensional array
#define LAYOUT_numpad_5x4( \
k00, k01, k02, k03, \
k10, k11, k12, \
k20, k21, k22, k13, \
k30, k31, k32, \
k40, k42, k33 \
) { \
{ k00, k01, k02, k03 }, \
{ k10, k11, k12, k13 }, \
{ k20, k21, k22, KC_NO }, \
{ k30, k31, k32, k33 }, \
{ k40, KC_NO, k42, KC_NO } \
}

#define LAYOUT LAYOUT_numpad_5x4
#define KEYMAP LAYOUT_numpad_5x4

#endif
69 changes: 0 additions & 69 deletions keyboards/clueboard/17/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,76 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "config_common.h"

/* USB Device descriptor parameter */
#define VENDOR_ID 0xC1ED
#define PRODUCT_ID 0x2312
#define DEVICE_VER 0x0001
#define MANUFACTURER Clueboard
#define PRODUCT Cluepad with RGB Underlighting
#define DESCRIPTION QMK keyboard firmware for Cluepad

/* key matrix size */
#define MATRIX_ROWS 5
#define MATRIX_COLS 4

// ROWS: Top to bottom, COLS: Left to right
/* Row pin configuration
* row: 0 1 2 3 4
* pin:
*/
#define MATRIX_ROW_PINS { B0, D3, D5, D4, D6 }
/* Column pin configuration
* col: 0 1 2 3
* pin: F4 E6 B1 D2
*/
#define MATRIX_COL_PINS { F4, E6, B1, D2 }
#define UNUSED_PINS

/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW

/* define if matrix has ghost */
//#define MATRIX_HAS_GHOST

/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5

/* Number of backlighting levels */
#define BACKLIGHT_LEVELS 3

/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE

/* Underlight configuration
*/
#define RGB_DI_PIN F6
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 4 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
#define RGBLIGHT_VAL_STEP 17

/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/

/* disable debug print */
//#define NO_DEBUG

/* Debug forcibly enabled */
#define ALWAYS_DEBUG

/* disable print */
//#define NO_PRINT

/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION

#endif
Loading

0 comments on commit 47b9b11

Please sign in to comment.