Initial work.
This commit is contained in:
commit
85c8be89de
6 changed files with 112 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build/
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "zephyr-rust"]
|
||||
path = zephyr-rust
|
||||
url = https://github.com/tylerwhall/zephyr-rust.git
|
40
CMakeLists.txt
Normal file
40
CMakeLists.txt
Normal file
|
@ -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)
|
||||
|
60
src/main.c
Normal file
60
src/main.c
Normal file
|
@ -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);
|
||||
// }
|
||||
}
|
7
src/zmk_lib.h
Normal file
7
src/zmk_lib.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef ZMK_LIB_H
|
||||
#define ZMK_LIB_H
|
||||
|
||||
void zmk_run(void);
|
||||
|
||||
#endif
|
||||
|
1
zephyr-rust
Submodule
1
zephyr-rust
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 78b433aa9e0255a719fb0c3c9ac303f3924c1348
|
Loading…
Add table
Reference in a new issue