Refactor for better organization
This commit is contained in:
parent
495cd00658
commit
4e672eafd4
4 changed files with 36 additions and 19 deletions
|
@ -8,5 +8,6 @@ project(zmk)
|
||||||
|
|
||||||
# Add your source file to the "app" target. This must come after
|
# Add your source file to the "app" target. This must come after
|
||||||
# find_package(Zephyr) which defines the target.
|
# find_package(Zephyr) which defines the target.
|
||||||
|
target_sources(app PRIVATE src/kscan.c)
|
||||||
target_sources(app PRIVATE src/main.c)
|
target_sources(app PRIVATE src/main.c)
|
||||||
|
|
||||||
|
|
29
src/kscan.c
Normal file
29
src/kscan.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr.h>
|
||||||
|
#include <device.h>
|
||||||
|
#include <devicetree.h>
|
||||||
|
#include <drivers/kscan.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
2
src/kscan.h
Normal file
2
src/kscan.h
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
int zmk_kscan_init(char *name);
|
23
src/main.c
23
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 <zephyr.h>
|
#include <zephyr.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <devicetree.h>
|
#include <devicetree.h>
|
||||||
#include <drivers/gpio.h>
|
|
||||||
#include <drivers/kscan.h>
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
void main(void)
|
||||||
{
|
{
|
||||||
struct device *dev;
|
|
||||||
printk("Welcome to ZMK!\n");
|
printk("Welcome to ZMK!\n");
|
||||||
|
|
||||||
dev = device_get_binding(CONFIG_KSCAN_MATRIX_DEV_NAME);
|
zmk_kscan_init(CONFIG_KSCAN_MATRIX_DEV_NAME);
|
||||||
if (dev == NULL) {
|
|
||||||
printk("NO DEVICE!\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
kscan_config(dev, zmk_kscan_callback);
|
|
||||||
|
|
||||||
kscan_enable_callback(dev);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue