From 3b63f9d5e58d891596a5e6f079a4c2f23ef79df9 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sun, 12 Nov 2023 23:36:13 +0000 Subject: [PATCH] zephyr/blink: copy in example to show how to build --- zephyr/.gitignore | 1 + zephyr/blink/CMakeLists.txt | 5 +++++ zephyr/blink/README.txt | 3 +++ zephyr/blink/prj.conf | 1 + zephyr/blink/src/main.c | 44 +++++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 zephyr/.gitignore create mode 100644 zephyr/blink/CMakeLists.txt create mode 100644 zephyr/blink/README.txt create mode 100644 zephyr/blink/prj.conf create mode 100644 zephyr/blink/src/main.c diff --git a/zephyr/.gitignore b/zephyr/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/zephyr/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/zephyr/blink/CMakeLists.txt b/zephyr/blink/CMakeLists.txt new file mode 100644 index 0000000..be8ebaa --- /dev/null +++ b/zephyr/blink/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(blink) +target_sources(app PRIVATE src/main.c) diff --git a/zephyr/blink/README.txt b/zephyr/blink/README.txt new file mode 100644 index 0000000..423dd23 --- /dev/null +++ b/zephyr/blink/README.txt @@ -0,0 +1,3 @@ +Example application to show building: +cmake -B build -G Ninja -D BOARD=your_board +ninja -C build diff --git a/zephyr/blink/prj.conf b/zephyr/blink/prj.conf new file mode 100644 index 0000000..91c3c15 --- /dev/null +++ b/zephyr/blink/prj.conf @@ -0,0 +1 @@ +CONFIG_GPIO=y diff --git a/zephyr/blink/src/main.c b/zephyr/blink/src/main.c new file mode 100644 index 0000000..a6d0954 --- /dev/null +++ b/zephyr/blink/src/main.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* 1000 msec = 1 sec */ +#define SLEEP_TIME_MS 1000 + +/* The devicetree node identifier for the "led0" alias. */ +#define LED0_NODE DT_ALIAS(led0) + +/* + * A build error on this line means your board is unsupported. + * See the sample documentation for information on how to fix this. + */ +static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); + +int main(void) +{ + int ret; + + if (!gpio_is_ready_dt(&led)) { + return 0; + } + + ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); + if (ret < 0) { + return 0; + } + + while (1) { + ret = gpio_pin_toggle_dt(&led); + if (ret < 0) { + return 0; + } + k_msleep(SLEEP_TIME_MS); + } + return 0; +} +