Browse Source

Use SYS_INIT for BLE and USB init.

xmkb
Pete Johanson 4 years ago
parent
commit
7c5fb7adb5
  1. 14
      app/Kconfig
  2. 1
      app/include/zmk/endpoints.h
  3. 9
      app/src/ble.c
  4. 28
      app/src/endpoints.c
  5. 5
      app/src/hog.c
  6. 5
      app/src/main.c
  7. 7
      app/src/usb_hid.c

14
app/Kconfig

@ -15,12 +15,20 @@ config ZMK_KSCAN_EVENT_QUEUE_SIZE
menu "HID Output Types" menu "HID Output Types"
config ZMK_USB menuconfig ZMK_USB
bool "USB" bool "USB"
select USB select USB
select USB_DEVICE_STACK select USB_DEVICE_STACK
select USB_DEVICE_HID select USB_DEVICE_HID
if ZMK_USB
config ZMK_USB_INIT_PRIORITY
int "Init Priority"
default 50
endif
menuconfig ZMK_BLE menuconfig ZMK_BLE
bool "BLE (HID over GATT)" bool "BLE (HID over GATT)"
select BT select BT
@ -32,6 +40,10 @@ menuconfig ZMK_BLE
if ZMK_BLE if ZMK_BLE
config ZMK_BLE_INIT_PRIORITY
int "Init Priority"
default 50
# HID GATT notifications sent this way are *not* picked up by Linux, and possibly others. # HID GATT notifications sent this way are *not* picked up by Linux, and possibly others.
config BT_GATT_NOTIFY_MULTIPLE config BT_GATT_NOTIFY_MULTIPLE
default n default n

1
app/include/zmk/endpoints.h

@ -3,5 +3,4 @@
#include <zmk/keys.h> #include <zmk/keys.h>
#include <zmk/hid.h> #include <zmk/hid.h>
int zmk_endpoints_init();
int zmk_endpoints_send_report(u8_t usage_report); int zmk_endpoints_send_report(u8_t usage_report);

9
app/src/ble.c

@ -1,4 +1,7 @@
#include <device.h>
#include <init.h>
#include <math.h> #include <math.h>
#include <settings/settings.h> #include <settings/settings.h>
@ -139,7 +142,7 @@ static void zmk_ble_ready(int err)
} }
} }
int zmk_ble_init() static int zmk_ble_init(struct device *_arg)
{ {
if (IS_ENABLED(CONFIG_SETTINGS)) if (IS_ENABLED(CONFIG_SETTINGS))
{ {
@ -191,3 +194,7 @@ bool zmk_ble_handle_key_user(struct zmk_key_event *key_event)
return false; return false;
} }
SYS_INIT(zmk_ble_init,
APPLICATION,
CONFIG_ZMK_BLE_INIT_PRIORITY);

28
app/src/endpoints.c

@ -8,34 +8,6 @@
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
int zmk_endpoints_init()
{
int err;
LOG_DBG("");
#ifdef CONFIG_ZMK_USB
err = zmk_usb_hid_init();
if (err)
{
LOG_ERR("USB HID Init Failed\n");
return err;
}
#endif /* CONFIG_ZMK_USB */
#ifdef CONFIG_ZMK_BLE
err = zmk_hog_init();
if (err)
{
LOG_ERR("HOG Init Failed\n");
return err;
}
#endif /* CONFIG_ZMK_BLE */
return 0;
}
int zmk_endpoints_send_report(u8_t usage_page) int zmk_endpoints_send_report(u8_t usage_page)
{ {
int err; int err;

5
app/src/hog.c

@ -7,11 +7,6 @@
#include <zmk/hog.h> #include <zmk/hog.h>
#include <zmk/hid.h> #include <zmk/hid.h>
int zmk_hog_init()
{
return zmk_ble_init();
}
enum enum
{ {
HIDS_REMOTE_WAKE = BIT(0), HIDS_REMOTE_WAKE = BIT(0),

5
app/src/main.c

@ -27,11 +27,6 @@ void main(void)
return; return;
} }
if (zmk_endpoints_init())
{
printk("ENDPOINT INIT FAILED\n");
return;
}
#ifdef CONFIG_SETTINGS #ifdef CONFIG_SETTINGS
settings_load(); settings_load();

7
app/src/usb_hid.c

@ -1,5 +1,6 @@
#include <device.h> #include <device.h>
#include <init.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/class/usb_hid.h> #include <usb/class/usb_hid.h>
@ -29,7 +30,7 @@ void usb_hid_status_cb(enum usb_dc_status_code status, const u8_t *params)
usb_status = status; usb_status = status;
}; };
int zmk_usb_hid_init() static int zmk_usb_hid_init(struct device *_arg)
{ {
int usb_enable_ret; int usb_enable_ret;
@ -56,3 +57,7 @@ int zmk_usb_hid_init()
return 0; return 0;
} }
SYS_INIT(zmk_usb_hid_init,
APPLICATION,
CONFIG_ZMK_USB_INIT_PRIORITY);

Loading…
Cancel
Save