From 978805056833963e898b42735e0f6aa87b79134e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Tue, 15 Mar 2016 01:17:33 +0100 Subject: [PATCH] Lay the foundation for actions, layers, modules, and slots. --- right/action.h | 39 +++++++++++++++++++++++++++++++++++++++ right/build/kds/.project | 20 ++++++++++++++++++++ right/layer.h | 13 +++++++++++++ right/module.h | 39 +++++++++++++++++++++++++++++++++++++++ right/slot.h | 27 +++++++++++++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 right/action.h create mode 100644 right/layer.h create mode 100644 right/module.h create mode 100644 right/slot.h diff --git a/right/action.h b/right/action.h new file mode 100644 index 0000000..934bfdc --- /dev/null +++ b/right/action.h @@ -0,0 +1,39 @@ +#ifndef __ACTION_H__ +#define __ACTION_H__ + +// Macros: + + // 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 + + #define ACTION_ARG_NONE 0 + + #define ACTION_ARG_SWITCH_LAYER_MOD 0 + #define ACTION_ARG_SWITCH_LAYER_FN 1 + #define ACTION_ARG_SWITCH_LAYER_MOUSE 2 + + #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 + +// Typedefs: + + typedef struct { + uint8_t id; + uint8_t arg; + } action_t; + +#endif diff --git a/right/build/kds/.project b/right/build/kds/.project index 1dde0fa..20b113e 100644 --- a/right/build/kds/.project +++ b/right/build/kds/.project @@ -190,11 +190,21 @@ 1 $%7BPARENT-3-PROJECT_LOC%7D/lib/KSDK_2.0_FRDM-K22F/middleware/usb_1.0.0/osa/usb_osa_bm.h + + sources/action.h + 1 + PARENT-2-PROJECT_LOC/action.h + sources/i2c.h 1 PARENT-3-PROJECT_LOC/include/i2c.h + + sources/layer.h + 1 + PARENT-2-PROJECT_LOC/layer.h + sources/main.c 1 @@ -205,6 +215,16 @@ 1 PARENT-2-PROJECT_LOC/main.h + + sources/module.h + 1 + PARENT-2-PROJECT_LOC/module.h + + + sources/slot.h + 1 + PARENT-2-PROJECT_LOC/slot.h + sources/usb_api.h 1 diff --git a/right/layer.h b/right/layer.h new file mode 100644 index 0000000..34b9099 --- /dev/null +++ b/right/layer.h @@ -0,0 +1,13 @@ +#ifndef __LAYER_H__ +#define __LAYER_H__ + +// Macros: + + #define LAYER_ID_BASE 0 + #define LAYER_ID_MOD 1 + #define LAYER_ID_FN 2 + #define LAYER_ID_MOUSE 3 + + #define LAYER_COUNT 4 + +#endif diff --git a/right/module.h b/right/module.h new file mode 100644 index 0000000..29fe09f --- /dev/null +++ b/right/module.h @@ -0,0 +1,39 @@ +#ifndef __MODULE_H__ +#define __MODULE_H__ + +// Includes: + + #include "action.h" + #include "layer.h" + #include "slot.h" + +// Macros: + + #define MODULE_ID_LEFT_KEYBOARD_HALF 0 + #define MODULE_ID_KEY_CLUSTER_LEFT 1 + #define MODULE_ID_TRACKBALL_RIGHT 2 + #define MODULE_ID_TRACKPOINT_RIGHT 3 + #define MODULE_ID_TOUCHPAD 4 + + #define MODULE_REQUEST_GET_PROTOCOL_VERSION 0 + #define MODULE_REQUEST_GET_MODULE_ID 1 + #define MODULE_REQUEST_GET_FEATURES 2 + #define MODULE_REQUEST_GET_STATE 3 + + #define MAX_KEY_COUNT_PER_MODULE 64 + +// Typedefs: + + typedef struct { + uint8_t moduleId; + uint8_t pointerCount; + uint8_t keyCount; + uint8_t keyStates[MAX_KEY_COUNT_PER_MODULE]; + key_action_t keyActions[LAYER_COUNT][MAX_KEY_COUNT_PER_MODULE]; + } module_t; + +// Variables: + + extern module_t AttachedModules[SLOT_COUNT]; + +#endif diff --git a/right/slot.h b/right/slot.h new file mode 100644 index 0000000..b7fa96f --- /dev/null +++ b/right/slot.h @@ -0,0 +1,27 @@ +#ifndef __SLOT_H__ +#define __SLOT_H__ + +// Slots provide a way to avoid I2C address collision of modules as only a single module can +// allocate a given slot. + +// Macros: + + #define SLOT_ID_RIGHT_KEYBOARD_HALF 0 + #define SLOT_ID_LEFT_KEYBOARD_HALF 1 + #define SLOT_ID_LEFT_MODULE 2 + #define SLOT_ID_RIGHT_MODULE 3 + #define SLOT_ID_BOTH_SIDED_MODULE 4 + + // The 7-bit I2C addresses below 0x08 are reserved. + #define SLOT_I2C_ADDRESS_LEFT_KEYBOARD_HALF 0x08 + #define SLOT_I2C_ADDRESS_LEFT_MODULE 0x09 + #define SLOT_I2C_ADDRESS_RIGHT_MODULE 0x0A + #define SLOT_I2C_ADDRESS_BOTH_SIDED_MODULE 0x0B + #define SLOT_I2C_ADDRESS_LEFT_KEYBOARD_HALF 0x0C + + #define SLOT_I2C_ADDRESS_MIN 0x08 + #define SLOT_I2C_ADDRESS_MAX 0x0C + + #define SLOT_COUNT 5 + +#endif