We now use a 32-bit structure to describe each key, and an `uhk_key_t` type that wraps all the supported things into a union. But this is not the only change: to be able to move the Fn/Mod keys anywhere, instead of hardcoding their location, they are now proper layer keys. To make it easier to handle turning a layer off, key releases can be handled explicitly, too. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
91 lines
2.2 KiB
C
91 lines
2.2 KiB
C
#ifndef KEYBOARD_LAYOUT_H_
|
|
#define KEYBOARD_LAYOUT_H_
|
|
|
|
#include <stdint.h>
|
|
#include "lufa/HIDClassCommon.h"
|
|
#include "usb_composite_device.h"
|
|
|
|
/**
|
|
* Keyboard layout is a 2D array of scan codes.
|
|
*
|
|
* First dimension is the Key ID of a given key. Key IDs are the indices of the
|
|
* of the active keys of the key_matrix_t structure. In case of left half, an
|
|
* offset of 35 is added.
|
|
*
|
|
* For each Key ID, there are 4 different possible scan codes:
|
|
* - default, when no modifiers are pressed
|
|
* - mod layer
|
|
* - fn layer
|
|
* - mod+fn layer
|
|
*
|
|
*/
|
|
|
|
#define KEY_STATE_COUNT (5*7)
|
|
|
|
#define LAYOUT_KEY_COUNT 70
|
|
#define LAYOUT_MOD_COUNT 4
|
|
|
|
#define LAYOUT_LEFT_OFFSET KEY_STATE_COUNT
|
|
|
|
typedef enum {
|
|
UHK_KEY_SIMPLE,
|
|
UHK_KEY_MOUSE,
|
|
UHK_KEY_LAYER,
|
|
UHK_KEY_LAYER_TOGGLE,
|
|
UHK_KEY_KEYMAP,
|
|
UHK_KEY_MACRO,
|
|
UHK_KEY_LPRESSMOD,
|
|
UHK_KEY_LPRESSLAYER,
|
|
} uhk_key_type_t;
|
|
|
|
typedef union {
|
|
struct {
|
|
uint8_t type;
|
|
union {
|
|
struct {
|
|
uint8_t __unused_bits;
|
|
uint8_t mods;
|
|
uint8_t key;
|
|
} __attribute__ ((packed)) simple;
|
|
struct {
|
|
uint8_t __unused_bits;
|
|
uint8_t scrollActions; // bitfield
|
|
uint8_t moveActions; // bitfield
|
|
} __attribute__ ((packed)) mouse;
|
|
struct {
|
|
uint16_t __unused_bits;
|
|
uint8_t target;
|
|
} __attribute__ ((packed)) layer;
|
|
struct {
|
|
uint16_t __unused_bits;
|
|
uint8_t target;
|
|
} __attribute__ ((packed)) keymap;
|
|
struct {
|
|
uint8_t __unused_bits;
|
|
uint16_t index;
|
|
} __attribute__ ((packed)) macro;
|
|
struct {
|
|
uint8_t longPressMod; // single mod, or bitfield?
|
|
uint8_t mods; // for the alternate action
|
|
uint8_t key;
|
|
} __attribute__ ((packed)) longpressMod;
|
|
struct {
|
|
uint8_t longPressLayer;
|
|
uint8_t mods;
|
|
uint8_t key;
|
|
} __attribute__ ((packed)) longpressLayer;
|
|
};
|
|
} __attribute__ ((packed));
|
|
uint32_t raw;
|
|
} __attribute__ ((packed)) uhk_key_t;
|
|
|
|
#define Key_NoKey {.raw = 0}
|
|
#define KEYBOARD_LAYOUT(name) const uhk_key_t name[LAYOUT_KEY_COUNT][LAYOUT_MOD_COUNT]
|
|
|
|
#define LAYER_MOD 1
|
|
#define LAYER_FN 2
|
|
|
|
void fillKeyboardReport(usb_keyboard_report_t *report, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates, KEYBOARD_LAYOUT(layout));
|
|
|
|
#endif
|