Initial commit

This commit is contained in:
2024-04-21 14:41:37 -06:00
commit 145348809e
65 changed files with 4395 additions and 0 deletions

12
app/CMakeLists.txt Normal file
View File

@ -0,0 +1,12 @@
#-------------------------------------------------------------------------------
# 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)

15
app/Kconfig Normal file
View File

@ -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"

5
app/VERSION Normal file
View File

@ -0,0 +1,5 @@
VERSION_MAJOR = 1
VERSION_MINOR = 0
PATCHLEVEL = 0
VERSION_TWEAK = 0
EXTRAVERSION =

View File

@ -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";
};

12
app/debug.conf Normal file
View File

@ -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

7
app/prj.conf Normal file
View File

@ -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

16
app/sample.yaml Normal file
View File

@ -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

80
app/src/main.c Normal file
View File

@ -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;
}