Some refactoring to prep for BLE support.
This commit is contained in:
parent
be53560b77
commit
04fe57d3a3
8 changed files with 43 additions and 19 deletions
|
@ -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
Normal file
17
src/endpoints.c
Normal 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
5
src/endpoints.h
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "keys.h"
|
||||||
|
|
||||||
|
int zmk_endpoints_send_key_event(struct zmk_key_event key_event);
|
|
@ -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);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
Normal file
11
src/keys.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <zephyr.h>
|
||||||
|
|
||||||
|
typedef u64_t zmk_key;
|
||||||
|
|
||||||
|
struct zmk_key_event
|
||||||
|
{
|
||||||
|
zmk_key key;
|
||||||
|
bool pressed;
|
||||||
|
};
|
|
@ -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…
Reference in a new issue