From 52bfc9dd84592f834c13ce9af4a1dd7fc90d7fef Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 1 May 2020 14:58:00 -0400 Subject: [PATCH] Lots of clean up, basic kscan working, remove zephyr-rust. --- .gitmodules | 3 -- CMakeLists.txt | 7 +-- boards/arm/planck/planck_rev6.dts | 37 +++++++------- .../petejohanson_handwire/Kconfig.defconfig | 0 .../petejohanson_handwire/Kconfig.shield | 6 +++ .../petejohanson_handwire.overlay | 12 +++++ prj.conf | 4 +- src/lib.rs | 11 ---- src/main.c | 51 +++---------------- src/zmk_lib.h | 7 --- zephyr-rust | 1 - 11 files changed, 46 insertions(+), 93 deletions(-) delete mode 100644 .gitmodules create mode 100644 boards/shields/petejohanson_handwire/Kconfig.defconfig create mode 100644 boards/shields/petejohanson_handwire/Kconfig.shield create mode 100644 boards/shields/petejohanson_handwire/petejohanson_handwire.overlay delete mode 100644 src/lib.rs delete mode 100644 src/zmk_lib.h delete mode 160000 zephyr-rust diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index c41b2432..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "zephyr-rust"] - path = zephyr-rust - url = https://github.com/tylerwhall/zephyr-rust.git diff --git a/CMakeLists.txt b/CMakeLists.txt index baeedcc4..9667067c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,9 @@ # Find Zephyr. This also loads Zephyr's build system. cmake_minimum_required(VERSION 3.13.1) -list(APPEND BOARD_ROOT .) +list(APPEND BOARD_ROOT ${CMAKE_SOURCE_DIR}) -get_filename_component(ZEPHYR_RUST ${CMAKE_CURRENT_SOURCE_DIR}/zephyr-rust ABSOLUTE) -list(APPEND ZEPHYR_EXTRA_MODULES ${ZEPHYR_RUST}) - -include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) find_package(Zephyr) - project(zmk) # Add your source file to the "app" target. This must come after diff --git a/boards/arm/planck/planck_rev6.dts b/boards/arm/planck/planck_rev6.dts index a3e14f7f..58de7a44 100644 --- a/boards/arm/planck/planck_rev6.dts +++ b/boards/arm/planck/planck_rev6.dts @@ -16,7 +16,6 @@ zephyr,shell-uart = &usart1; zephyr,sram = &sram0; zephyr,flash = &flash0; - zmk,matrix = &matrix0; }; leds { @@ -55,25 +54,23 @@ }; }; - matrix0: kscan_matrix { - rows { - gpio-map = <0 0 &gpioa 10 0>, - <1 0 &gpioa 9 0>, - <2 0 &gpioa 8 0>, - <3 0 &gpiob 15 0>, - <4 0 &gpioc 13 0>, - <5 0 &gpioc 14 0>, - <6 0 &gpioc 15 0>, - <7 0 &gpioa 2 0>; - }; - columns { - gpio-map = <0 0 &gpiob 11 0>, - <1 0 &gpiob 10 0>, - <2 0 &gpiob 2 0>, - <3 0 &gpiob 1 0>, - <4 0 &gpioa 7 0>, - <5 0 &gpiob 0 0>; - }; + kscan { + compatible = "gpio-kscan"; + label = "Keyscan Matrix"; + row-gpios = <&gpioa 10 GPIO_ACTIVE_HIGH>, + <&gpioa 9 GPIO_ACTIVE_HIGH>, + <&gpioa 8 GPIO_ACTIVE_HIGH>, + <&gpiob 15 GPIO_ACTIVE_HIGH>, + <&gpioc 13 GPIO_ACTIVE_HIGH>, + <&gpioc 14 GPIO_ACTIVE_HIGH>, + <&gpioc 15 GPIO_ACTIVE_HIGH>, + <&gpioa 2 GPIO_ACTIVE_HIGH>; + col-gpios = <&gpiob 11 GPIO_ACTIVE_HIGH>, + <&gpiob 10 GPIO_ACTIVE_HIGH>, + <&gpiob 2 GPIO_ACTIVE_HIGH>, + <&gpiob 1 GPIO_ACTIVE_HIGH>, + <&gpioa 7 GPIO_ACTIVE_HIGH>, + <&gpiob 0 GPIO_ACTIVE_HIGH>; }; gpio_keys { diff --git a/boards/shields/petejohanson_handwire/Kconfig.defconfig b/boards/shields/petejohanson_handwire/Kconfig.defconfig new file mode 100644 index 00000000..e69de29b diff --git a/boards/shields/petejohanson_handwire/Kconfig.shield b/boards/shields/petejohanson_handwire/Kconfig.shield new file mode 100644 index 00000000..7e8ad482 --- /dev/null +++ b/boards/shields/petejohanson_handwire/Kconfig.shield @@ -0,0 +1,6 @@ +# Copyright (c) 2019 Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +config SHIELD_PETEJOHANSON_HANDWIRE + def_bool $(shields_list_contains,petejohanson_handwire) + diff --git a/boards/shields/petejohanson_handwire/petejohanson_handwire.overlay b/boards/shields/petejohanson_handwire/petejohanson_handwire.overlay new file mode 100644 index 00000000..678070ef --- /dev/null +++ b/boards/shields/petejohanson_handwire/petejohanson_handwire.overlay @@ -0,0 +1,12 @@ + +/ { + kscan { + compatible = "gpio-kscan"; + label = "Handwired GPIO KSCAN matrix"; + + row-gpios = <&arduino_header 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>, + <&arduino_header 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + col-gpios = <&arduino_header 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>, + <&arduino_header 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + }; +}; diff --git a/prj.conf b/prj.conf index 382a34a0..5c21d2c1 100644 --- a/prj.conf +++ b/prj.conf @@ -1,4 +1,4 @@ -CONFIG_RUST=y -CONFIG_RUST_ALLOC_POOL=y +# CONFIG_RUST=y +# CONFIG_RUST_ALLOC_POOL=y CONFIG_KSCAN=y CONFIG_KSCAN_GPIO=y diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 75ada985..00000000 --- a/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[no_mangle] -pub extern "C" fn zmk_run() { -} - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/src/main.c b/src/main.c index 21f481a0..6640e479 100644 --- a/src/main.c +++ b/src/main.c @@ -10,59 +10,24 @@ #include #include -#include "zmk_lib.h" -/* 1000 msec = 1 sec */ -#define SLEEP_TIME_MS 1000 - -/* The devicetree node identifier for the "led0" alias. */ -/* -#define LED0_NODE DT_ALIAS(led0) - -#if DT_HAS_NODE(LED0_NODE) -#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios) -#define PIN DT_GPIO_PIN(LED0_NODE, gpios) -#if DT_PHA_HAS_CELL(LED0_NODE, gpios, flags) -#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios) -#endif -#else -*/ -/* A build error here means your board isn't set up to blink an LED. */ -/* -#error "Unsupported board: led0 devicetree alias is not defined" -#define LED0 "" -#define PIN 0 -#endif - -#ifndef FLAGS -#define FLAGS 0 -#endif - -*/ +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")); +} void main(void) { - /* struct device *dev; - bool led_is_on = true; - int ret; + printk("Welcome to ZMK!\n"); - dev = device_get_binding(LED0); + dev = device_get_binding(CONFIG_KSCAN_MATRIX_DEV_NAME); if (dev == NULL) { + printk("NO DEVICE!\n"); return; } - ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS); - if (ret < 0) { - return; - } - */ + kscan_config(dev, zmk_kscan_callback); - zmk_run(); - // while (1) { - // gpio_pin_set(dev, PIN, (int)led_is_on); - // led_is_on = !led_is_on; - // k_msleep(SLEEP_TIME_MS); - // } + kscan_enable_callback(dev); } diff --git a/src/zmk_lib.h b/src/zmk_lib.h deleted file mode 100644 index 0b7706ed..00000000 --- a/src/zmk_lib.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef ZMK_LIB_H -#define ZMK_LIB_H - -void zmk_run(void); - -#endif - diff --git a/zephyr-rust b/zephyr-rust deleted file mode 160000 index 78b433aa..00000000 --- a/zephyr-rust +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 78b433aa9e0255a719fb0c3c9ac303f3924c1348