Move keyboard event handling into action.c
Since keyboard_layout.[ch] has gained more features, and handles more than just filling out the keyboard report, move it to action.[ch] instead. I see no sane way to separate the keyboard and mouse report filling, unless we want to loop over key states twice, hence them being in the same file. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This commit is contained in:
+96
-30
@@ -1,39 +1,105 @@
|
||||
#ifndef __ACTION_H__
|
||||
#define __ACTION_H__
|
||||
#ifndef __UHK_ACTION_H_
|
||||
#define __UHK_ACTION_H_
|
||||
|
||||
// Macros:
|
||||
#include <stdint.h>
|
||||
#include "lufa/HIDClassCommon.h"
|
||||
#include "usb_composite_device.h"
|
||||
|
||||
// The value of action ID can be any valid HID_KEYBOARD_SC_* scancode constants of LUFA.
|
||||
// Hence, ACTION_ID_* values must not conflict with any of the HID_KEYBOARD_SC_* constants.
|
||||
#define ACTION_ID_NONE 0xFF
|
||||
#define ACTION_ID_SWITCH_LAYER 0xFE
|
||||
#define ACTION_ID_MOUSE 0xFD
|
||||
#define ACTION_ID_SWITCH_KEYMAP 0xFC
|
||||
#define ACTION_ID_PLAY_MACRO 0xFB
|
||||
#include "module.h"
|
||||
|
||||
#define ACTION_ARG_NONE 0
|
||||
// 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 ACTION_ARG_SWITCH_LAYER_MOD 0
|
||||
#define ACTION_ARG_SWITCH_LAYER_FN 1
|
||||
#define ACTION_ARG_SWITCH_LAYER_MOUSE 2
|
||||
#define KEY_STATE_COUNT (5*7)
|
||||
|
||||
#define ACTION_ARG_MOUSE_MOVE_UP 0
|
||||
#define ACTION_ARG_MOUSE_MOVE_DOWN 1
|
||||
#define ACTION_ARG_MOUSE_MOVE_LEFT 3
|
||||
#define ACTION_ARG_MOUSE_MOVE_RIGHT 4
|
||||
#define ACTION_ARG_MOUSE_CLICK_LEFT 5
|
||||
#define ACTION_ARG_MOUSE_CLICK_MIDDLE 6
|
||||
#define ACTION_ARG_MOUSE_CLICK_RIGHT 7
|
||||
#define ACTION_ARG_MOUSE_WHEEL_UP 8
|
||||
#define ACTION_ARG_MOUSE_WHEEL_DOWN 9
|
||||
#define ACTION_ARG_MOUSE_WHEEL_LEFT 10
|
||||
#define ACTION_ARG_MOUSE_WHEEL_RIGHT 11
|
||||
typedef enum {
|
||||
UHK_KEY_NONE,
|
||||
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;
|
||||
|
||||
// Typedefs:
|
||||
enum {
|
||||
UHK_MOUSE_BUTTON_LEFT = (1 << 0),
|
||||
UHK_MOUSE_BUTTON_RIGHT = (1 << 1),
|
||||
UHK_MOUSE_BUTTON_MIDDLE = (1 << 2),
|
||||
UHK_MOUSE_BUTTON_4 = (1 << 3),
|
||||
UHK_MOUSE_BUTTON_5 = (1 << 4),
|
||||
UHK_MOUSE_BUTTON_6 = (1 << 5),
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t id;
|
||||
uint8_t arg;
|
||||
} action_t;
|
||||
enum {
|
||||
UHK_MOUSE_MOVE_UP = (1 << 0),
|
||||
UHK_MOUSE_MOVE_DOWN = (1 << 1),
|
||||
UHK_MOUSE_MOVE_LEFT = (1 << 2),
|
||||
UHK_MOUSE_MOVE_RIGHT = (1 << 3),
|
||||
|
||||
UHK_MOUSE_ACCELERATE = (1 << 4),
|
||||
UHK_MOUSE_DECELERATE = (1 << 5),
|
||||
};
|
||||
|
||||
enum {
|
||||
UHK_MOUSE_SCROLL_UP = (1 << 0),
|
||||
UHK_MOUSE_SCROLL_DOWN = (1 << 1),
|
||||
UHK_MOUSE_SCROLL_LEFT = (1 << 2),
|
||||
UHK_MOUSE_SCROLL_RIGHT = (1 << 3),
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
union {
|
||||
struct {
|
||||
uint8_t __unused_bits;
|
||||
uint8_t mods;
|
||||
uint8_t key;
|
||||
} __attribute__ ((packed)) simple;
|
||||
struct {
|
||||
uint8_t buttonActions; // bitfield
|
||||
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)) uhk_key_t;
|
||||
|
||||
extern uint8_t prevKeyStates[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||
extern uhk_key_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE];
|
||||
|
||||
void HandleKeyboardEvents(usb_keyboard_report_t *keyboardReport, usb_mouse_report_t *mouseReport, const uint8_t *leftKeyStates, const uint8_t *rightKeyStates);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user