diff --git a/CMakeLists.txt b/CMakeLists.txt index 9667067c..b6e66ba5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,5 +8,6 @@ project(zmk) # Add your source file to the "app" target. This must come after # find_package(Zephyr) which defines the target. +target_sources(app PRIVATE src/kscan.c) target_sources(app PRIVATE src/main.c) diff --git a/src/kscan.c b/src/kscan.c new file mode 100644 index 00000000..244bedcf --- /dev/null +++ b/src/kscan.c @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include + +static void zmk_kscan_callback(struct device *dev, u32_t row, u32_t column, bool pressed) { + printk("Row: %d, col: %d, pressed: %s\n", row, column, (pressed ? "true" : "false")); + // TODO: Push this to a message box, and then trigger a work item! +} + +int zmk_kscan_init(char* name) { + struct device *dev = device_get_binding(name); + if (dev == NULL) { + printk("NO DEVICE!\n"); + return -EINVAL; + } + + return 0; + + kscan_config(dev, zmk_kscan_callback); + + kscan_enable_callback(dev); +} diff --git a/src/kscan.h b/src/kscan.h new file mode 100644 index 00000000..18f08a6a --- /dev/null +++ b/src/kscan.h @@ -0,0 +1,2 @@ + +int zmk_kscan_init(char *name); diff --git a/src/main.c b/src/main.c index 6640e479..4cfe052c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,33 +1,18 @@ /* - * Copyright (c) 2016 Intel Corporation + * Copyright (c) 2020 Peter Johanson * - * SPDX-License-Identifier: Apache-2.0 + * SPDX-License-Identifier: MIT */ #include #include #include -#include -#include - - -void zmk_kscan_callback(struct device *dev, u32_t row, u32_t column, bool pressed) { - printk("Row: %d, col: %d, pressed: %s\n", row, column, (pressed ? "true" : "false")); -} +#include "kscan.h" void main(void) { - struct device *dev; printk("Welcome to ZMK!\n"); - dev = device_get_binding(CONFIG_KSCAN_MATRIX_DEV_NAME); - if (dev == NULL) { - printk("NO DEVICE!\n"); - return; - } - - kscan_config(dev, zmk_kscan_callback); - - kscan_enable_callback(dev); + zmk_kscan_init(CONFIG_KSCAN_MATRIX_DEV_NAME); }