Browse Source

Some refactoring to prep for BLE support.

xmkb
Pete Johanson 5 years ago
parent
commit
04fe57d3a3
  1. 1
      CMakeLists.txt
  2. 17
      src/endpoints.c
  3. 5
      src/endpoints.h
  4. 11
      src/handlers.c
  5. 8
      src/handlers.h
  6. 3
      src/keymap.h
  7. 11
      src/keys.h
  8. 6
      src/usb_hid.h

1
CMakeLists.txt

@ -13,6 +13,7 @@ target_include_directories(app PRIVATE include)
target_sources(app PRIVATE src/kscan.c) target_sources(app PRIVATE src/kscan.c)
target_sources(app PRIVATE src/keymap.c) target_sources(app PRIVATE src/keymap.c)
target_sources(app PRIVATE src/usb_hid.c) target_sources(app PRIVATE src/usb_hid.c)
target_sources(app PRIVATE src/endpoints.c)
target_sources(app PRIVATE src/main.c) target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE src/handlers.c) target_sources(app PRIVATE src/handlers.c)

17
src/endpoints.c

@ -0,0 +1,17 @@
#include "endpoints.h"
#include "usb_hid.h"
int zmk_endpoints_send_key_event(struct zmk_key_event key_event)
{
if (key_event.pressed)
{
zmk_usb_hid_press_key(key_event.key);
}
else
{
zmk_usb_hid_release_key(key_event.key);
}
return 0;
}

5
src/endpoints.h

@ -0,0 +1,5 @@
#pragma once
#include "keys.h"
int zmk_endpoints_send_key_event(struct zmk_key_event key_event);

11
src/handlers.c

@ -1,7 +1,7 @@
#include "handlers.h" #include "handlers.h"
#include "usb_hid.h" #include "endpoints.h"
__attribute__((weak)) bool zmk_handle_key_user(struct zmk_key_event *key_event) __attribute__((weak)) bool zmk_handle_key_user(struct zmk_key_event *key_event)
{ {
@ -15,12 +15,5 @@ void zmk_handle_key(struct zmk_key_event key_event)
return; return;
} }
if (key_event.pressed) zmk_endpoints_send_key_event(key_event);
{
zmk_usb_hid_press_key(key_event.key);
}
else
{
zmk_usb_hid_release_key(key_event.key);
}
}; };

8
src/handlers.h

@ -1,12 +1,8 @@
#pragma once #pragma once
#include "keymap.h"
#include <dt-bindings/zmk/keys.h> #include <dt-bindings/zmk/keys.h>
struct zmk_key_event #include "keymap.h"
{ #include "keys.h"
zmk_key key;
bool pressed;
};
void zmk_handle_key(struct zmk_key_event key_event); void zmk_handle_key(struct zmk_key_event key_event);

3
src/keymap.h

@ -6,12 +6,11 @@
#include "dt-bindings/zmk/keys.h" #include "dt-bindings/zmk/keys.h"
#include "zmk.h" #include "zmk.h"
#include "keys.h"
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap) #define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap)
#define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers) #define ZMK_KEYMAP_LAYERS_LEN DT_PROP_LEN(ZMK_KEYMAP_NODE, layers)
typedef u64_t zmk_key;
bool zmk_keymap_layer_activate(u8_t layer); bool zmk_keymap_layer_activate(u8_t layer);
bool zmk_keymap_layer_deactivate(u8_t layer); bool zmk_keymap_layer_deactivate(u8_t layer);

11
src/keys.h

@ -0,0 +1,11 @@
#pragma once
#include <zephyr.h>
typedef u64_t zmk_key;
struct zmk_key_event
{
zmk_key key;
bool pressed;
};

6
src/usb_hid.h

@ -4,11 +4,13 @@
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/class/usb_hid.h> #include <usb/class/usb_hid.h>
#include "keys.h"
int zmk_usb_hid_init(); int zmk_usb_hid_init();
// TODO: Modifiers! // TODO: Modifiers!
int zmk_usb_hid_press_key(enum hid_kbd_code code); int zmk_usb_hid_press_key(zmk_key key);
int zmk_usb_hid_release_key(enum hid_kbd_code code); int zmk_usb_hid_release_key(zmk_key key);
#endif #endif

Loading…
Cancel
Save