Fix consumer keys w/ refactored behaviors.

This commit is contained in:
Pete Johanson
2020-06-22 11:06:01 -04:00
parent 8027be106e
commit 55cf9db564
20 changed files with 193 additions and 238 deletions

View File

@@ -25,7 +25,7 @@ extern "C" {
typedef int (*behavior_position_callback_t)(struct device *dev, u32_t position);
typedef int (*behavior_keymap_binding_callback_t)(struct device *dev, u32_t position, u32_t param1, u32_t param2);
typedef int (*behavior_keycode_callback_t)(struct device *dev, u32_t keycode);
typedef int (*behavior_keycode_callback_t)(struct device *dev, u8_t usage_page, u32_t keycode);
typedef int (*behavior_modifiers_callback_t)(struct device *dev, zmk_mod_flags modifiers);
__subsystem struct behavior_driver_api {
@@ -135,14 +135,15 @@ static inline int z_impl_behavior_keymap_binding_released(struct device *dev, u3
/**
* @brief Handle the keycode being pressed
* @param dev Pointer to the device structure for the driver instance.
* @param usage_page The usage page for the keycode.
* @param keycode The keycode that is being pressed.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
__syscall int behavior_keycode_pressed(struct device *dev, u32_t keycode);
__syscall int behavior_keycode_pressed(struct device *dev, u8_t usage_page, u32_t keycode);
static inline int z_impl_behavior_keycode_pressed(struct device *dev, u32_t keycode)
static inline int z_impl_behavior_keycode_pressed(struct device *dev, u8_t usage_page, u32_t keycode)
{
const struct behavior_driver_api *api =
(const struct behavior_driver_api *)dev->driver_api;
@@ -151,21 +152,22 @@ static inline int z_impl_behavior_keycode_pressed(struct device *dev, u32_t keyc
return -ENOTSUP;
}
return api->keycode_pressed(dev, keycode);
return api->keycode_pressed(dev, usage_page, keycode);
}
/**
* @brief Handle the keycode being released
* @param dev Pointer to the device structure for the driver instance.
* @param usage_page The usage page for the keycode.
* @param keycode The keycode that is being pressed.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
__syscall int behavior_keycode_released(struct device *dev, u32_t keycode);
__syscall int behavior_keycode_released(struct device *dev, u8_t usage_page, u32_t keycode);
static inline int z_impl_behavior_keycode_released(struct device *dev, u32_t keycode)
static inline int z_impl_behavior_keycode_released(struct device *dev, u8_t usage_page, u32_t keycode)
{
const struct behavior_driver_api *api =
(const struct behavior_driver_api *)dev->driver_api;
@@ -174,7 +176,7 @@ static inline int z_impl_behavior_keycode_released(struct device *dev, u32_t key
return -ENOTSUP;
}
return api->keycode_released(dev, keycode);
return api->keycode_released(dev, usage_page, keycode);
}

View File

@@ -1,6 +1,9 @@
#pragma once
#define USAGE_KEYPAD 0x07
#define USAGE_CONSUMER 0x0C
#define A 0x04
#define B 0x05
#define C 0x06
@@ -104,14 +107,14 @@
/* The following are select consumer page usages */
#define MNXT 0x100
#define MPRV 0x101
#define MSTP 0x102
#define MJCT 0x103
#define MPLY 0x104
#define MMUT 0x105
#define MVLU 0x106
#define MVLD 0x107
#define M_NEXT 0xB5
#define M_PREV 0xB6
#define M_STOP 0xB7
#define M_EJCT 0xB8
#define M_PLAY 0xCD
#define M_MUTE 0xE2
#define M_VOLU 0xE9
#define M_VOLD 0xEA
#define MOD_LCTL (1 << 0x00)
#define MOD_LSFT (1 << 0x01)

View File

@@ -4,5 +4,4 @@
#include <zmk/hid.h>
int zmk_endpoints_init();
int zmk_endpoints_send_report(enum zmk_hid_report_changes changes);
int zmk_endpoints_send_key_event(struct zmk_key_event key_event);
int zmk_endpoints_send_report(u8_t usage_report);

View File

@@ -4,8 +4,8 @@
int zmk_events_position_pressed(u32_t position);
int zmk_events_position_released(u32_t position);
int zmk_events_keycode_pressed(u32_t keycode);
int zmk_events_keycode_released(u32_t keycode);
int zmk_events_keycode_pressed(u8_t usage_page, u32_t keycode);
int zmk_events_keycode_released(u8_t usage_page, u32_t keycode);
int zmk_events_modifiers_pressed(zmk_mod_flags modifiers);
int zmk_events_modifiers_released(zmk_mod_flags modifiers);
int zmk_events_consumer_key_pressed(u32_t usage);

View File

@@ -108,40 +108,21 @@ static const u8_t zmk_hid_report_desc[] = {
0x00,
/* LOGICAL_MAXIMUM (1) */
HID_GI_LOGICAL_MAX(1),
0x01,
/* USAGE (Scan Next Track) */
HID_LI_USAGE,
0xB5,
/* USAGE (Scan Previous Track) */
HID_LI_USAGE,
0xB6,
/* USAGE (Stop) */
HID_LI_USAGE,
0xB7,
/* USAGE (Eject) */
HID_LI_USAGE,
0xB8,
/* USAGE (Media Play/Pause) */
HID_LI_USAGE,
0xCD,
/* USAGE (Mute) */
HID_LI_USAGE,
0xE2,
/* USAGE (Volume Increment) */
HID_LI_USAGE,
0xE9,
/* USAGE (Volume Decrement) */
HID_LI_USAGE,
0xEA,
0xFF,
HID_LI_USAGE_MIN(1),
0x00,
/* USAGE_MAXIMUM (Keyboard Application) */
HID_LI_USAGE_MAX(1),
0xFF,
/* INPUT (Data,Ary,Abs) */
/* REPORT_SIZE (1) */
/* REPORT_SIZE (8) */
HID_GI_REPORT_SIZE,
0x01,
0x08,
/* REPORT_COUNT (8) */
HID_GI_REPORT_COUNT,
0x08,
0x06,
HID_MI_INPUT,
0x02,
0x00,
/* END COLLECTION */
HID_MI_COLLECTION_END,
};
@@ -167,7 +148,7 @@ struct zmk_hid_keypad_report
struct zmk_hid_consumer_report_body
{
u8_t keys;
u8_t keys[6];
} __packed;
struct zmk_hid_consumer_report
@@ -176,19 +157,15 @@ struct zmk_hid_consumer_report
struct zmk_hid_consumer_report_body body;
} __packed;
enum zmk_hid_report_changes
{
None = 0x00,
Keypad = (0x01 << 0x00),
Consumer = (0x01 << 0x01)
};
int zmk_hid_register_mod(zmk_mod modifier);
int zmk_hid_unregister_mod(zmk_mod modifier);
int zmk_hid_register_mods(zmk_mod_flags modifiers);
int zmk_hid_unregister_mods(zmk_mod_flags modifiers);
enum zmk_hid_report_changes zmk_hid_press_key(zmk_key key);
enum zmk_hid_report_changes zmk_hid_release_key(zmk_key key);
int zmk_hid_keypad_press(zmk_key key);
int zmk_hid_keypad_release(zmk_key key);
int zmk_hid_consumer_press(zmk_key key);
int zmk_hid_consumer_release(zmk_key key);
struct zmk_hid_keypad_report *zmk_hid_get_keypad_report();
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report();

View File

@@ -1,6 +1,6 @@
#pragma once
bool zmk_keymap_layer_activate(u8_t layer);
bool zmk_keymap_layer_deactivate(u8_t layer);
int zmk_keymap_layer_activate(u8_t layer);
int zmk_keymap_layer_deactivate(u8_t layer);
int zmk_keymap_position_state_changed(u32_t position, bool pressed);