Some refactoring to prep for BLE support.

This commit is contained in:
Pete Johanson 2020-05-12 14:15:33 -04:00
parent be53560b77
commit 04fe57d3a3
8 changed files with 43 additions and 19 deletions

View file

@ -13,6 +13,7 @@ target_include_directories(app PRIVATE include)
target_sources(app PRIVATE src/kscan.c)
target_sources(app PRIVATE src/keymap.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/handlers.c)

17
src/endpoints.c Normal file
View file

@ -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 Normal file
View file

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

View file

@ -1,7 +1,7 @@
#include "handlers.h"
#include "usb_hid.h"
#include "endpoints.h"
__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;
}
if (key_event.pressed)
{
zmk_usb_hid_press_key(key_event.key);
}
else
{
zmk_usb_hid_release_key(key_event.key);
}
zmk_endpoints_send_key_event(key_event);
};

View file

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

View file

@ -6,12 +6,11 @@
#include "dt-bindings/zmk/keys.h"
#include "zmk.h"
#include "keys.h"
#define ZMK_KEYMAP_NODE DT_CHOSEN(zmk_keymap)
#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_deactivate(u8_t layer);

11
src/keys.h Normal file
View file

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

View file

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