From 85c8be89dea8f7a00e8efb06d38e2b32f3459935 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Apr 2020 16:20:34 -0400 Subject: [PATCH] Initial work. --- .gitignore | 1 + .gitmodules | 3 +++ CMakeLists.txt | 40 +++++++++++++++++++++++++++++++++ src/main.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/zmk_lib.h | 7 ++++++ zephyr-rust | 1 + 6 files changed, 112 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 src/main.c create mode 100644 src/zmk_lib.h create mode 160000 zephyr-rust diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..567609b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..c41b2432 --- /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 00000000..58277409 --- /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 00000000..e487325a --- /dev/null +++ b/src/main.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#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 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 00000000..0b7706ed --- /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 index 00000000..78b433aa --- /dev/null +++ b/zephyr-rust @@ -0,0 +1 @@ +Subproject commit 78b433aa9e0255a719fb0c3c9ac303f3924c1348