diff options
author | Pete Johanson <peter@peterjohanson.com> | 2020-04-21 16:20:34 -0400 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2020-04-21 16:20:34 -0400 |
commit | 85c8be89dea8f7a00e8efb06d38e2b32f3459935 (patch) | |
tree | b87dcac5eeba3f67fd2db7e43712043d82b9a607 |
Initial work.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | CMakeLists.txt | 40 | ||||
-rw-r--r-- | src/main.c | 60 | ||||
-rw-r--r-- | src/zmk_lib.h | 7 | ||||
m--------- | zephyr-rust | 0 |
6 files changed, 111 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c41b243 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "zephyr-rust"] + path = zephyr-rust + url = https://github.com/tylerwhall/zephyr-rust.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5827740 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,40 @@ +# Find Zephyr. This also loads Zephyr's build system. +cmake_minimum_required(VERSION 3.13.1) +find_package(Zephyr) + +get_filename_component(ZEPHYR_RUST ${CMAKE_CURRENT_SOURCE_DIR}/zephyr-rust ABSOLUTE) +list(APPEND ZEPHYR_EXTRA_MODULES ${ZEPHYR_RUST}) + +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/main.c) + +include(ExternalProject) + +# Add rust_example as a CMake target +ExternalProject_Add( + zmk_crate + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND cargo build --target thumbv7m-none-eabi COMMAND cargo build --release --target thumbv7m-none-eabi + BINARY_DIR "${CMAKE_SOURCE_DIR}/zmk" + INSTALL_COMMAND "" + BUILD_BYPRODUCTS "${CMAKE_SOURCE_DIR}/zmk/target/thumbv7m-none-eabi/release/libzmk.a" + LOG_BUILD ON) + +# Create a wrapper CMake library that our app can link with +add_library(zmk_lib STATIC IMPORTED GLOBAL) +add_dependencies( + zmk_lib + zmk_crate + ) + +set_target_properties(zmk_lib PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/zmk/target/thumbv7m-none-eabi/release/libzmk.a) +# target_link_libraries(zmk_lib +# debug "${CMAKE_SOURCE_DIR}/target/debug/zmk.a" +# optimized "${CMAKE_SOURCE_DIR}/target/release/zmk.a") + +target_link_libraries(app PUBLIC zmk_lib) + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..e487325 --- /dev/null +++ b/src/main.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include <zephyr.h> +#include <device.h> +#include <devicetree.h> +#include <drivers/gpio.h> + +#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 main(void) +{ + struct device *dev; + bool led_is_on = true; + int ret; + + dev = device_get_binding(LED0); + if (dev == NULL) { + return; + } + + ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS); + if (ret < 0) { + return; + } + + zmk_run(); + // while (1) { + // gpio_pin_set(dev, PIN, (int)led_is_on); + // led_is_on = !led_is_on; + // k_msleep(SLEEP_TIME_MS); + // } +} diff --git a/src/zmk_lib.h b/src/zmk_lib.h new file mode 100644 index 0000000..0b7706e --- /dev/null +++ b/src/zmk_lib.h @@ -0,0 +1,7 @@ +#ifndef ZMK_LIB_H +#define ZMK_LIB_H + +void zmk_run(void); + +#endif + diff --git a/zephyr-rust b/zephyr-rust new file mode 160000 +Subproject 78b433aa9e0255a719fb0c3c9ac303f3924c134 |