Skip to content

Commit

Permalink
Tweaks to fix after squish
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Oct 16, 2023
1 parent 26cba92 commit 1e4faab
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 77 deletions.
4 changes: 2 additions & 2 deletions app/src/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <dt-bindings/zmk/modifiers.h>

static struct zmk_hid_keyboard_report keyboard_report = {
.report_id = HID_REPORT_ID_KEYBOARD, .body = {.modifiers = 0, ._reserved = 0, .keys = {0}}};
.report_id = ZMK_REPORT_ID_KEYBOARD, .body = {.modifiers = 0, ._reserved = 0, .keys = {0}}};

static struct zmk_hid_consumer_report consumer_report = {.report_id = HID_REPORT_ID_CONSUMER,
static struct zmk_hid_consumer_report consumer_report = {.report_id = ZMK_REPORT_ID_CONSUMER,
.body = {.keys = {0}}};

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
Expand Down
2 changes: 1 addition & 1 deletion app/src/hog.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static struct hids_report input = {
};

static struct hids_report led_indicators = {
.id = HID_REPORT_ID_LEDS,
.id = ZMK_REPORT_ID_LEDS,
.type = HIDS_OUTPUT,
};

Expand Down
150 changes: 76 additions & 74 deletions app/src/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ static void in_ready_cb(const struct device *dev) { k_sem_give(&hid_sem); }
#define HID_REPORT_TYPE_OUTPUT 0x200
#define HID_REPORT_TYPE_FEATURE 0x300

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
static int set_report_cb(const struct device *dev, struct usb_setup_packet *setup, int32_t *len,
uint8_t **data) {
if (((setup->wValue & HID_GET_REPORT_TYPE_MASK) != HID_REPORT_TYPE_FEATURE) |
((setup->wValue & HID_GET_REPORT_TYPE_MASK) != HID_REPORT_TYPE_OUTPUT)) {
if (!(((setup->wValue & HID_GET_REPORT_TYPE_MASK) == HID_REPORT_TYPE_FEATURE) ||
((setup->wValue & HID_GET_REPORT_TYPE_MASK) == HID_REPORT_TYPE_OUTPUT))) {
LOG_ERR("Unsupported report type %d requested",
(setup->wValue & HID_GET_REPORT_TYPE_MASK) >> 8);
return -ENOTSUP;
}
switch (setup->wValue & HID_GET_REPORT_ID_MASK) {
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
case ZMK_REPORT_ID_FEATURE_PTP_SELECTIVE:
if (*len != sizeof(struct zmk_hid_ptp_feature_selective_report)) {
LOG_ERR("LED set report is malformed: length=%d", *len);
Expand All @@ -53,7 +53,8 @@ static int set_report_cb(const struct device *dev, struct usb_setup_packet *setu
zmk_hid_ptp_set_feature_selective_report(report->selective_reporting);
}
break;
case HID_REPORT_ID_LEDS:
#endif
case ZMK_REPORT_ID_LEDS:
if (*len != sizeof(struct zmk_hid_led_report)) {
LOG_ERR("LED set report is malformed: length=%d", *len);
return -EINVAL;
Expand All @@ -63,93 +64,94 @@ static int set_report_cb(const struct device *dev, struct usb_setup_packet *setu
.transport = ZMK_TRANSPORT_USB,
};
zmk_hid_indicators_process_report(&report->body, endpoint);
break;
default:
LOG_ERR("Invalid report ID %d requested", setup->wValue & HID_GET_REPORT_ID_MASK);
return -EINVAL;
}

return 0;
break;
default:
LOG_ERR("Invalid report ID %d requested", setup->wValue & HID_GET_REPORT_ID_MASK);
return -EINVAL;
}

static int get_report_cb(const struct device *dev, struct usb_setup_packet *setup, int32_t *len,
uint8_t **data) {
if ((setup->wValue & HID_GET_REPORT_TYPE_MASK) != HID_REPORT_TYPE_FEATURE) {
LOG_ERR("Unsupported report type %d requested",
(setup->wValue & HID_GET_REPORT_TYPE_MASK) >> 8);
return -ENOTSUP;
}

switch (setup->wValue & HID_GET_REPORT_ID_MASK) {
case ZMK_REPORT_ID_FEATURE_PTP_SELECTIVE:
return 0;
}
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
static int get_report_cb(const struct device *dev, struct usb_setup_packet *setup, int32_t *len,
uint8_t **data) {
if ((setup->wValue & HID_GET_REPORT_TYPE_MASK) != HID_REPORT_TYPE_FEATURE) {
LOG_ERR("Unsupported report type %d requested",
(setup->wValue & HID_GET_REPORT_TYPE_MASK) >> 8);
return -ENOTSUP;
}

*data = (uint8_t *)zmk_hid_ptp_get_feature_selective_report();
LOG_DBG("Selective report get %d", 0);
*len = sizeof(struct zmk_hid_ptp_feature_selective_report);
break;
case ZMK_REPORT_ID_FEATURE_PTPHQA:
switch (setup->wValue & HID_GET_REPORT_ID_MASK) {
case ZMK_REPORT_ID_FEATURE_PTP_SELECTIVE:

*data = (uint8_t *)zmk_hid_ptp_get_feature_certification_report();
LOG_DBG("certification report get %d", 0);
*len = sizeof(struct zmk_hid_ptp_feature_certification_report);
*data = (uint8_t *)zmk_hid_ptp_get_feature_selective_report();
LOG_DBG("Selective report get %d", 0);
*len = sizeof(struct zmk_hid_ptp_feature_selective_report);
break;
case ZMK_REPORT_ID_FEATURE_PTPHQA:

break;
case ZMK_REPORT_ID_FEATURE_PTP_CAPABILITIES:
*data = (uint8_t *)zmk_hid_ptp_get_feature_certification_report();
LOG_DBG("certification report get %d", 0);
*len = sizeof(struct zmk_hid_ptp_feature_certification_report);

*data = (uint8_t *)zmk_hid_ptp_get_feature_capabilities_report();
LOG_DBG("capabilities report get %d", 0);
*len = sizeof(struct zmk_hid_ptp_feature_capabilities_report);
break;
case ZMK_REPORT_ID_FEATURE_PTP_CAPABILITIES:

break;
default:
LOG_ERR("Invalid report ID %d requested", setup->wValue & HID_GET_REPORT_ID_MASK);
return -EINVAL;
}
*data = (uint8_t *)zmk_hid_ptp_get_feature_capabilities_report();
LOG_DBG("capabilities report get %d", 0);
*len = sizeof(struct zmk_hid_ptp_feature_capabilities_report);

return 0;
break;
default:
LOG_ERR("Invalid report ID %d requested", setup->wValue & HID_GET_REPORT_ID_MASK);
return -EINVAL;
}

return 0;
}
#endif

static const struct hid_ops ops = {
.int_in_ready = in_ready_cb,
static const struct hid_ops ops = {
.int_in_ready = in_ready_cb,
.set_report = set_report_cb,
#if IS_ENABLED(CONFIG_ZMK_TRACKPAD)
.set_report = set_report_cb,
.get_report = get_report_cb,
.get_report = get_report_cb,
#endif
};

int zmk_usb_hid_send_report(const uint8_t *report, size_t len) {
switch (zmk_usb_get_status()) {
case USB_DC_SUSPEND:
return usb_wakeup_request();
case USB_DC_ERROR:
case USB_DC_RESET:
case USB_DC_DISCONNECTED:
case USB_DC_UNKNOWN:
return -ENODEV;
default:
k_sem_take(&hid_sem, K_MSEC(30));
int err = hid_int_ep_write(hid_dev, report, len, NULL);

if (err) {
k_sem_give(&hid_sem);
}

return err;
};

int zmk_usb_hid_send_report(const uint8_t *report, size_t len) {
switch (zmk_usb_get_status()) {
case USB_DC_SUSPEND:
return usb_wakeup_request();
case USB_DC_ERROR:
case USB_DC_RESET:
case USB_DC_DISCONNECTED:
case USB_DC_UNKNOWN:
return -ENODEV;
default:
k_sem_take(&hid_sem, K_MSEC(30));
int err = hid_int_ep_write(hid_dev, report, len, NULL);

if (err) {
k_sem_give(&hid_sem);
}

return err;
}
}

static int zmk_usb_hid_init(const struct device *_arg) {
hid_dev = device_get_binding("HID_0");
if (hid_dev == NULL) {
LOG_ERR("Unable to locate HID device");
return -EINVAL;
}
static int zmk_usb_hid_init(const struct device *_arg) {
hid_dev = device_get_binding("HID_0");
if (hid_dev == NULL) {
LOG_ERR("Unable to locate HID device");
return -EINVAL;
}

usb_hid_register_device(hid_dev, zmk_hid_report_desc, sizeof(zmk_hid_report_desc), &ops);
usb_hid_init(hid_dev);
usb_hid_register_device(hid_dev, zmk_hid_report_desc, sizeof(zmk_hid_report_desc), &ops);
usb_hid_init(hid_dev);

return 0;
}
return 0;
}

SYS_INIT(zmk_usb_hid_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
SYS_INIT(zmk_usb_hid_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

0 comments on commit 1e4faab

Please sign in to comment.