Create Zephyr workspace app
Build / Build app and tests (ubuntu-22.04) (push) Failing after 1m22s
Documentation / Build (1.14.0) (push) Failing after 22s
Documentation / Build (1.9.6) (push) Failing after 12s
Documentation / Deploy (push) Has been skipped
Build / Build app and tests (macos-14) (push) Has been cancelled
Build / Build app and tests (windows-2022) (push) Has been cancelled
Build / Build app and tests (ubuntu-22.04) (push) Failing after 1m22s
Documentation / Build (1.14.0) (push) Failing after 22s
Documentation / Build (1.9.6) (push) Failing after 12s
Documentation / Deploy (push) Has been skipped
Build / Build app and tests (macos-14) (push) Has been cancelled
Build / Build app and tests (windows-2022) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Zephyr Example Application
|
||||
#
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(app LANGUAGES C)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
||||
|
||||
# The code below locates the git index file for this repository and adds it as a dependency for
|
||||
# the application VERSION file so that if the repo has a new commit added, even if no files in
|
||||
# the build have changed, the application version file will be regenerated with the new git commit
|
||||
find_package(Git QUIET)
|
||||
if(GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse --absolute-git-dir
|
||||
WORKING_DIRECTORY .
|
||||
OUTPUT_VARIABLE application_git_dir
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_VARIABLE stderr
|
||||
RESULT_VARIABLE return_code
|
||||
)
|
||||
# If there is an error e.g. it is not a git repo, we just silently ignore it and continue
|
||||
# without a dependency, this will be the case with freestanding applications.
|
||||
if(NOT return_code)
|
||||
if(NOT "${stderr}" STREQUAL "")
|
||||
message(WARNING "Application build version git rev-parse warned: ${stderr}")
|
||||
endif()
|
||||
|
||||
set_property(TARGET app_version_h PROPERTY APP_VERSION_DEPENDS ${application_git_dir}/index)
|
||||
endif()
|
||||
endif()
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# This file is the application Kconfig entry point. All application Kconfig
|
||||
# options can be defined here or included via other application Kconfig files.
|
||||
# You can browse these options using the west targets menuconfig (terminal) or
|
||||
# guiconfig (GUI).
|
||||
|
||||
menu "Zephyr"
|
||||
source "Kconfig.zephyr"
|
||||
endmenu
|
||||
|
||||
module = APP
|
||||
module-str = APP
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
@@ -0,0 +1,5 @@
|
||||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 0
|
||||
PATCHLEVEL = 0
|
||||
VERSION_TWEAK = 0
|
||||
EXTRAVERSION =
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* This devicetree overlay file will be automatically picked by the Zephyr
|
||||
* build system when building the sample for the nucleo_f302r8 board. It shows
|
||||
* how the example-application can be built on sample boards already provided
|
||||
* by Zephyr.
|
||||
*/
|
||||
|
||||
/ {
|
||||
example_sensor: example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpioc 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
blink_led: blink-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpiob 13 GPIO_ACTIVE_HIGH>;
|
||||
blink-period-ms = <1000>;
|
||||
};
|
||||
};
|
||||
|
||||
&gpioc {
|
||||
status = "okay";
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# This is a Kconfig fragment which can be used to enable debug-related options
|
||||
# in the application. See the README for more details.
|
||||
|
||||
# compiler
|
||||
CONFIG_DEBUG_OPTIMIZATIONS=y
|
||||
|
||||
# logging
|
||||
CONFIG_LOG=y
|
||||
CONFIG_APP_LOG_LEVEL_DBG=y
|
||||
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# This file contains selected Kconfig options for the application.
|
||||
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_BLINK=y
|
||||
@@ -0,0 +1,16 @@
|
||||
# This file is provided so that the application can be compiled using Twister,
|
||||
# the Zephyr testing tool. In this file, multiple combinations can be specified,
|
||||
# so that you can easily test all of them locally or in CI.
|
||||
sample:
|
||||
description: Example application
|
||||
name: example-application
|
||||
common:
|
||||
build_only: true
|
||||
integration_platforms:
|
||||
- custom_plank
|
||||
- nucleo_f302r8
|
||||
tests:
|
||||
app.default: {}
|
||||
app.debug:
|
||||
extra_overlay_confs:
|
||||
- debug.conf
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include <app/drivers/blink.h>
|
||||
|
||||
#include <app_version.h>
|
||||
|
||||
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
||||
|
||||
#define BLINK_PERIOD_MS_STEP 100U
|
||||
#define BLINK_PERIOD_MS_MAX 1000U
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ret;
|
||||
unsigned int period_ms = BLINK_PERIOD_MS_MAX;
|
||||
const struct device *sensor, *blink;
|
||||
struct sensor_value last_val = { 0 }, val;
|
||||
|
||||
printk("Zephyr Example Application %s\n", APP_VERSION_STRING);
|
||||
|
||||
sensor = DEVICE_DT_GET(DT_NODELABEL(example_sensor));
|
||||
if (!device_is_ready(sensor)) {
|
||||
LOG_ERR("Sensor not ready");
|
||||
return 0;
|
||||
}
|
||||
|
||||
blink = DEVICE_DT_GET(DT_NODELABEL(blink_led));
|
||||
if (!device_is_ready(blink)) {
|
||||
LOG_ERR("Blink LED not ready");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = blink_off(blink);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not turn off LED (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printk("Use the sensor to change LED blinking period\n");
|
||||
|
||||
while (1) {
|
||||
ret = sensor_sample_fetch(sensor);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not fetch sample (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = sensor_channel_get(sensor, SENSOR_CHAN_PROX, &val);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not get sample (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((last_val.val1 == 0) && (val.val1 == 1)) {
|
||||
if (period_ms == 0U) {
|
||||
period_ms = BLINK_PERIOD_MS_MAX;
|
||||
} else {
|
||||
period_ms -= BLINK_PERIOD_MS_STEP;
|
||||
}
|
||||
|
||||
printk("Proximity detected, setting LED period to %u ms\n",
|
||||
period_ms);
|
||||
blink_set_period_ms(blink, period_ms);
|
||||
}
|
||||
|
||||
last_val = val;
|
||||
|
||||
k_sleep(K_MSEC(100));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user