Merge pull request #238 from petejohanson/core/usb-without-hid-refactor
Expose USB status without having USB HID output.
This commit is contained in:
commit
222515f091
5 changed files with 23 additions and 12 deletions
|
@ -54,7 +54,7 @@ target_sources_ifdef(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL app PRIVATE src/split/
|
|||
target_sources_ifdef(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL app PRIVATE src/split/bluetooth/central.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_KSCAN_MOCK_DRIVER app PRIVATE src/kscan_mock.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER app PRIVATE src/kscan_composite.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_USB app PRIVATE src/usb_hid.c)
|
||||
target_sources_ifdef(CONFIG_USB app PRIVATE src/usb.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c)
|
||||
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c)
|
||||
target_sources(app PRIVATE src/endpoints.c)
|
||||
|
|
|
@ -21,12 +21,16 @@ menuconfig ZMK_USB
|
|||
select USB_DEVICE_STACK
|
||||
select USB_DEVICE_HID
|
||||
|
||||
if ZMK_USB
|
||||
if USB
|
||||
|
||||
config ZMK_USB_INIT_PRIORITY
|
||||
int "Init Priority"
|
||||
default 50
|
||||
|
||||
endif
|
||||
|
||||
if ZMK_USB
|
||||
|
||||
config USB_NUMOF_EP_WRITE_RETRIES
|
||||
default 10
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
#include <zmk/keys.h>
|
||||
#include <zmk/hid.h>
|
||||
|
||||
int zmk_usb_hid_init();
|
||||
|
||||
enum usb_dc_status_code zmk_usb_hid_get_status();
|
||||
enum usb_dc_status_code zmk_usb_get_status();
|
||||
|
||||
#ifdef CONFIG_ZMK_USB
|
||||
int zmk_usb_hid_send_report(u8_t *report, size_t len);
|
||||
#endif /* CONFIG_ZMK_USB */
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <zmk/endpoints.h>
|
||||
#include <zmk/hid.h>
|
||||
#include <zmk/usb_hid.h>
|
||||
#include <zmk/usb.h>
|
||||
#include <zmk/hog.h>
|
||||
|
||||
#include <logging/log.h>
|
||||
|
|
|
@ -18,6 +18,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
|
||||
static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN;
|
||||
|
||||
#ifdef CONFIG_ZMK_USB
|
||||
|
||||
static struct device *hid_dev;
|
||||
|
||||
static K_SEM_DEFINE(hid_sem, 1, 1);
|
||||
|
@ -28,8 +30,6 @@ static const struct hid_ops ops = {
|
|||
.int_in_ready = in_ready_cb,
|
||||
};
|
||||
|
||||
enum usb_dc_status_code zmk_usb_hid_get_status() { return usb_status; }
|
||||
|
||||
int zmk_usb_hid_send_report(const u8_t *report, size_t len) {
|
||||
switch (usb_status) {
|
||||
case USB_DC_SUSPEND:
|
||||
|
@ -51,11 +51,16 @@ int zmk_usb_hid_send_report(const u8_t *report, size_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
void usb_hid_status_cb(enum usb_dc_status_code status, const u8_t *params) { usb_status = status; };
|
||||
#endif /* CONFIG_ZMK_USB */
|
||||
|
||||
static int zmk_usb_hid_init(struct device *_arg) {
|
||||
enum usb_dc_status_code zmk_usb_get_status() { return usb_status; }
|
||||
|
||||
void usb_status_cb(enum usb_dc_status_code status, const u8_t *params) { usb_status = status; };
|
||||
|
||||
static int zmk_usb_init(struct device *_arg) {
|
||||
int usb_enable_ret;
|
||||
|
||||
#ifdef CONFIG_ZMK_USB
|
||||
hid_dev = device_get_binding("HID_0");
|
||||
if (hid_dev == NULL) {
|
||||
LOG_ERR("Unable to locate HID device");
|
||||
|
@ -66,7 +71,9 @@ static int zmk_usb_hid_init(struct device *_arg) {
|
|||
|
||||
usb_hid_init(hid_dev);
|
||||
|
||||
usb_enable_ret = usb_enable(usb_hid_status_cb);
|
||||
#endif /* CONFIG_ZMK_USB */
|
||||
|
||||
usb_enable_ret = usb_enable(usb_status_cb);
|
||||
|
||||
if (usb_enable_ret != 0) {
|
||||
LOG_ERR("Unable to enable USB");
|
||||
|
@ -76,4 +83,4 @@ static int zmk_usb_hid_init(struct device *_arg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(zmk_usb_hid_init, APPLICATION, CONFIG_ZMK_USB_INIT_PRIORITY);
|
||||
SYS_INIT(zmk_usb_init, APPLICATION, CONFIG_ZMK_USB_INIT_PRIORITY);
|
Loading…
Reference in a new issue