Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
krikun98 committed May 2, 2021
1 parent 0fe48ce commit bd108c5
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 167 deletions.
20 changes: 9 additions & 11 deletions app/include/zmk/events/mouse_state_changed.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@
#include <zephyr.h>
#include <zmk/event_manager.h>


struct zmk_mouse_state_changed {
uint32_t x;
uint32_t y;
bool state;
int64_t timestamp;
uint32_t x;
uint32_t y;
bool state;
int64_t timestamp;
};

ZMK_EVENT_DECLARE(zmk_mouse_state_changed);

static inline struct zmk_mouse_state_changed_event *
zmk_mouse_state_changed_from_encoded(uint32_t encoded, bool pressed,
int64_t timestamp) {
zmk_mouse_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) {

uint32_t x = (encoded & 0xFFFF0000) >> 16;
uint32_t y = encoded & 0x0000FFFF;
uint32_t x = (encoded & 0xFFFF0000) >> 16;
uint32_t y = encoded & 0x0000FFFF;

return new_zmk_mouse_state_changed((struct zmk_mouse_state_changed){
.x = x, .y = y, .state = pressed, .timestamp = timestamp});
return new_zmk_mouse_state_changed(
(struct zmk_mouse_state_changed){.x = x, .y = y, .state = pressed, .timestamp = timestamp});
}
178 changes: 69 additions & 109 deletions app/include/zmk/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,159 +22,119 @@

static const uint8_t zmk_hid_report_desc[] = {
/* USAGE_PAGE (Generic Desktop) */
HID_GI_USAGE_PAGE,
HID_USAGE_GD,
HID_GI_USAGE_PAGE, HID_USAGE_GD,
/* USAGE (Keyboard) */
HID_LI_USAGE,
HID_USAGE_GD_KEYBOARD,
HID_LI_USAGE, HID_USAGE_GD_KEYBOARD,
/* COLLECTION (Application) */
HID_MI_COLLECTION,
COLLECTION_APPLICATION,
HID_MI_COLLECTION, COLLECTION_APPLICATION,
/* REPORT ID (1) */
HID_GI_REPORT_ID,
0x01,
HID_GI_REPORT_ID, 0x01,
/* USAGE_PAGE (Keyboard/Keypad) */
HID_GI_USAGE_PAGE,
HID_USAGE_KEY,
HID_GI_USAGE_PAGE, HID_USAGE_KEY,
/* USAGE_MINIMUM (Keyboard LeftControl) */
HID_LI_USAGE_MIN(1),
HID_USAGE_KEY_KEYBOARD_LEFTCONTROL,
HID_LI_USAGE_MIN(1), HID_USAGE_KEY_KEYBOARD_LEFTCONTROL,
/* USAGE_MAXIMUM (Keyboard Right GUI) */
HID_LI_USAGE_MAX(1),
HID_USAGE_KEY_KEYBOARD_RIGHT_GUI,
HID_LI_USAGE_MAX(1), HID_USAGE_KEY_KEYBOARD_RIGHT_GUI,
/* LOGICAL_MINIMUM (0) */
HID_GI_LOGICAL_MIN(1),
0x00,
HID_GI_LOGICAL_MIN(1), 0x00,
/* LOGICAL_MAXIMUM (1) */
HID_GI_LOGICAL_MAX(1),
0x01,
HID_GI_LOGICAL_MAX(1), 0x01,

/* REPORT_SIZE (1) */
HID_GI_REPORT_SIZE,
0x01,
HID_GI_REPORT_SIZE, 0x01,
/* REPORT_COUNT (8) */
HID_GI_REPORT_COUNT,
0x08,
HID_GI_REPORT_COUNT, 0x08,
/* INPUT (Data,Var,Abs) */
HID_MI_INPUT,
0x02,
HID_MI_INPUT, 0x02,

/* USAGE_PAGE (Keyboard/Keypad) */
HID_GI_USAGE_PAGE,
HID_USAGE_KEY,
HID_GI_USAGE_PAGE, HID_USAGE_KEY,
/* REPORT_SIZE (8) */
HID_GI_REPORT_SIZE,
0x08,
HID_GI_REPORT_SIZE, 0x08,
/* REPORT_COUNT (1) */
HID_GI_REPORT_COUNT,
0x01,
HID_GI_REPORT_COUNT, 0x01,
/* INPUT (Cnst,Var,Abs) */
HID_MI_INPUT,
0x03,
HID_MI_INPUT, 0x03,

/* USAGE_PAGE (Keyboard/Keypad) */
HID_GI_USAGE_PAGE,
HID_USAGE_KEY,
HID_GI_USAGE_PAGE, HID_USAGE_KEY,
/* LOGICAL_MINIMUM (0) */
HID_GI_LOGICAL_MIN(1),
0x00,
HID_GI_LOGICAL_MIN(1), 0x00,
/* LOGICAL_MAXIMUM (0xFF) */
HID_GI_LOGICAL_MAX(1),
0xFF,
HID_GI_LOGICAL_MAX(1), 0xFF,
/* USAGE_MINIMUM (Reserved) */
HID_LI_USAGE_MIN(1),
0x00,
HID_LI_USAGE_MIN(1), 0x00,
/* USAGE_MAXIMUM (Keyboard Application) */
HID_LI_USAGE_MAX(1),
0xFF,
HID_LI_USAGE_MAX(1), 0xFF,
/* REPORT_SIZE (1) */
HID_GI_REPORT_SIZE,
0x08,
HID_GI_REPORT_SIZE, 0x08,
/* REPORT_COUNT (ZMK_HID_KEYBOARD_NKRO_SIZE) */
HID_GI_REPORT_COUNT,
ZMK_HID_KEYBOARD_NKRO_SIZE,
HID_GI_REPORT_COUNT, ZMK_HID_KEYBOARD_NKRO_SIZE,
/* INPUT (Data,Ary,Abs) */
HID_MI_INPUT,
0x00,
HID_MI_INPUT, 0x00,

/* END_COLLECTION */
HID_MI_COLLECTION_END,
/* USAGE_PAGE (Consumer) */
HID_GI_USAGE_PAGE,
HID_USAGE_CONSUMER,
HID_GI_USAGE_PAGE, HID_USAGE_CONSUMER,
/* USAGE (Consumer Control) */
HID_LI_USAGE,
HID_USAGE_CONSUMER_CONSUMER_CONTROL,
HID_LI_USAGE, HID_USAGE_CONSUMER_CONSUMER_CONTROL,
/* Consumer Page */
HID_MI_COLLECTION,
COLLECTION_APPLICATION,
HID_MI_COLLECTION, COLLECTION_APPLICATION,
/* REPORT ID (1) */
HID_GI_REPORT_ID,
0x02,
HID_GI_REPORT_ID, 0x02,
/* USAGE_PAGE (Consumer) */
HID_GI_USAGE_PAGE,
HID_USAGE_CONSUMER,
HID_GI_USAGE_PAGE, HID_USAGE_CONSUMER,
/* LOGICAL_MINIMUM (0) */
HID_GI_LOGICAL_MIN(1),
0x00,
HID_GI_LOGICAL_MIN(1), 0x00,
/* LOGICAL_MAXIMUM (0xFFFF) */
HID_GI_LOGICAL_MAX(2),
0xFF,
0xFF,
HID_LI_USAGE_MIN(1),
0x00,
HID_GI_LOGICAL_MAX(2), 0xFF, 0xFF, HID_LI_USAGE_MIN(1), 0x00,
/* USAGE_MAXIMUM (0xFFFF) */
HID_LI_USAGE_MAX(2),
0xFF,
0xFF,
HID_LI_USAGE_MAX(2), 0xFF, 0xFF,
/* INPUT (Data,Ary,Abs) */
/* REPORT_SIZE (16) */
HID_GI_REPORT_SIZE,
0x10,
HID_GI_REPORT_SIZE, 0x10,
/* REPORT_COUNT (ZMK_HID_CONSUMER_NKRO_SIZE) */
HID_GI_REPORT_COUNT,
ZMK_HID_CONSUMER_NKRO_SIZE,
HID_MI_INPUT,
0x00,
HID_GI_REPORT_COUNT, ZMK_HID_CONSUMER_NKRO_SIZE, HID_MI_INPUT, 0x00,
/* END COLLECTION */
HID_MI_COLLECTION_END,

0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x09, 0x02, /* Usage (Mouse) */
0xA1, 0x01, /* Collection (Application) */
0x85, 0x04, /* Report ID (4) */
0x09, 0x01, /* Usage (Pointer) */
0xA1, 0x00, /* Collection (Physical) */
0x05, 0x09, /* Usage Page (Button) */
0x19, 0x01, /* Usage Minimum (0x01) */
0x29, 0x10, /* Usage Maximum (0x10) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x95, 0x10, /* Report Count (16) */
0x75, 0x01, /* Report Size (1) */
0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,...) */
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x16, 0x01, 0x80, /* Logical Minimum (-32767) */
0x26, 0xFF, 0x7F, /* Logical Maximum (32767) */
0x75, 0x10, /* Report Size (8) */
0x95, 0x02, /* Report Count (2) */
0x09, 0x30, /* Usage (X) */
0x09, 0x31, /* Usage (Y) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0x15, 0x81, /* Logical Minimum (-127) */
0x25, 0x7F, /* Logical Maximum (127) */
0x75, 0x08, /* Report Count (8) */
0x95, 0x01, /* Report Size (1) */
0x09, 0x38, /* Usage (Wheel) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x09, 0x02, /* Usage (Mouse) */
0xA1, 0x01, /* Collection (Application) */
0x85, 0x04, /* Report ID (4) */
0x09, 0x01, /* Usage (Pointer) */
0xA1, 0x00, /* Collection (Physical) */
0x05, 0x09, /* Usage Page (Button) */
0x19, 0x01, /* Usage Minimum (0x01) */
0x29, 0x10, /* Usage Maximum (0x10) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x95, 0x10, /* Report Count (16) */
0x75, 0x01, /* Report Size (1) */
0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,...) */
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
0x16, 0x01, 0x80, /* Logical Minimum (-32767) */
0x26, 0xFF, 0x7F, /* Logical Maximum (32767) */
0x75, 0x10, /* Report Size (8) */
0x95, 0x02, /* Report Count (2) */
0x09, 0x30, /* Usage (X) */
0x09, 0x31, /* Usage (Y) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0x15, 0x81, /* Logical Minimum (-127) */
0x25, 0x7F, /* Logical Maximum (127) */
0x75, 0x08, /* Report Count (8) */
0x95, 0x01, /* Report Size (1) */
0x09, 0x38, /* Usage (Wheel) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0x05, 0x0C, /* Usage Page (Consumer) */ // Horizontal wheel
0x0A, 0x38, 0x02, /* Usage (AC Pan) */
0x15, 0x81, /* Logical Minimum (-127) */
0x25, 0x7f, /* Logical Maximum (127) */
0x95, 0x01, /* Report Count (1) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0xC0, /* End Collection */
0xC0, /* End Collection */
0x0A, 0x38, 0x02, /* Usage (AC Pan) */
0x15, 0x81, /* Logical Minimum (-127) */
0x25, 0x7f, /* Logical Maximum (127) */
0x95, 0x01, /* Report Count (1) */
0x81, 0x06, /* Input (Data,Var,Rel,No Wrap,Linear,...) */
0xC0, /* End Collection */
0xC0, /* End Collection */
};

// struct zmk_hid_boot_report
Expand Down
6 changes: 3 additions & 3 deletions app/src/behaviors/behavior_mouse_key_press.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static const struct behavior_driver_api behavior_mouse_key_press_driver_api = {
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};

#define KP_INST(n) \
DEVICE_AND_API_INIT(behavior_mouse_key_press_##n, DT_INST_LABEL(n), behavior_mouse_key_press_init, NULL, \
NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&behavior_mouse_key_press_driver_api);
DEVICE_AND_API_INIT( \
behavior_mouse_key_press_##n, DT_INST_LABEL(n), behavior_mouse_key_press_init, NULL, NULL, \
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_mouse_key_press_driver_api);

DT_INST_FOREACH_STATUS_OKAY(KP_INST)
9 changes: 4 additions & 5 deletions app/src/behaviors/behavior_mouse_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

static int behavior_mouse_move_init(const struct device *dev) { return 0; };


static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
int res = ZMK_EVENT_RAISE(zmk_mouse_state_changed_from_encoded(binding->param1, true,
event.timestamp));
int res = ZMK_EVENT_RAISE(
zmk_mouse_state_changed_from_encoded(binding->param1, true, event.timestamp));
return res;
}

static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);

return ZMK_EVENT_RAISE(zmk_mouse_state_changed_from_encoded(binding->param1, false,
event.timestamp));
return ZMK_EVENT_RAISE(
zmk_mouse_state_changed_from_encoded(binding->param1, false, event.timestamp));
}

static const struct behavior_driver_api behavior_mouse_move_driver_api = {
Expand Down
5 changes: 2 additions & 3 deletions app/src/behaviors/behavior_mouse_wheel.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
static const struct behavior_driver_api behavior_mouse_wheel_driver_api = {
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};


#define KP_INST(n) \
DEVICE_AND_API_INIT(behavior_mouse_wheel_##n, DT_INST_LABEL(n), behavior_mouse_wheel_init, NULL, \
NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
DEVICE_AND_API_INIT(behavior_mouse_wheel_##n, DT_INST_LABEL(n), behavior_mouse_wheel_init, \
NULL, NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&behavior_mouse_wheel_driver_api);

DT_INST_FOREACH_STATUS_OKAY(KP_INST)
4 changes: 2 additions & 2 deletions app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int zmk_endpoints_send_mouse_report() {

switch (current_endpoint) {
#if IS_ENABLED(CONFIG_ZMK_USB)
case ZMK_ENDPOINT_USB: {
case ZMK_ENDPOINT_USB: {
int err = zmk_usb_hid_send_report((uint8_t *)mouse_report, sizeof(*mouse_report));
if (err) {
LOG_ERR("FAILED TO SEND OVER USB: %d", err);
Expand All @@ -160,7 +160,7 @@ int zmk_endpoints_send_mouse_report() {
#endif /* IS_ENABLED(CONFIG_ZMK_USB) */

#if IS_ENABLED(CONFIG_ZMK_BLE)
case ZMK_ENDPOINT_BLE: {
case ZMK_ENDPOINT_BLE: {
int err = zmk_hog_send_mouse_report(&mouse_report->body);
if (err) {
LOG_ERR("FAILED TO SEND OVER HOG: %d", err);
Expand Down
Loading

0 comments on commit bd108c5

Please sign in to comment.