diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..cd680b74d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,69 @@ +name: SemVer Release & Build + +on: + pull_request: + types: [opened, synchronize, closed] + branches: main + +jobs: + version: + outputs: + next: ${{steps.semver.outputs.next}} + nextStrict: ${{steps.semver.outputs.nextStrict}} + + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Get Next Version + id: semver + uses: ietf-tools/semver-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: main + + build: + runs-on: ubuntu-22.04 + container: ghcr.io/zephyrproject-rtos/ci:v0.26.2 + env: + CMAKE_PREFIX_PATH: /opt/toolchains + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + path: example-application + + - name: Initialize + working-directory: example-application + run: | + west init -l . + west update + + - name: Build firmware + working-directory: example-application + run: | + west twister -T app -v --inline-logs --integration + + - name: Twister Tests + working-directory: example-application + run: | + west twister -T tests --integration + + release: + runs-on: ubuntu-latest + needs: [version,build] + steps: + - name: Create Release + uses: ncipollo/release-action@v1.12.0 + with: + allowUpdates: true + draft: false + makeLatest: true + generateReleaseNotes: true + name: ${{ needs.version.outputs.next }} + body: Changelog Contents + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "README.md,LICENSE,app/build/zephyr/${{ github.repository }}-${{ needs.version.outputs.nextStrict }}.uf2" + commit: ${{ github.sha }} + tag: ${{ needs.version.outputs.next }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..014d594a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# editors +.vscode +*.swp +*~ + +# python +.venv + +# build +/build* +/twister-out* + +__pycache__/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..b8b7f59a3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 +# +# This CMake file is picked by the Zephyr build system because it is defined +# as the module CMake entry point (see zephyr/module.yml). + +zephyr_include_directories(include) + +add_subdirectory(drivers) +add_subdirectory(lib) diff --git a/Kconfig b/Kconfig new file mode 100644 index 000000000..3bd03f246 --- /dev/null +++ b/Kconfig @@ -0,0 +1,9 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 +# +# This Kconfig file is picked by the Zephyr build system because it is defined +# as the module Kconfig entry point (see zephyr/module.yml). You can browse +# module options by going to Zephyr -> Modules in Kconfig. + +rsource "drivers/Kconfig" +rsource "lib/Kconfig" diff --git a/README.md b/README.md index ccad12ef2..dae3052db 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# example-application -Example out-of-tree application that is also a module +# Zephyr Template App + +Template app with SemVer and Release workflows for GitHub Actions along with the Zephyr build action \ No newline at end of file diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt new file mode 100644 index 000000000..a59bf06b5 --- /dev/null +++ b/app/CMakeLists.txt @@ -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) diff --git a/app/Kconfig b/app/Kconfig new file mode 100644 index 000000000..140eaafb5 --- /dev/null +++ b/app/Kconfig @@ -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" diff --git a/app/VERSION b/app/VERSION new file mode 100644 index 000000000..16a13732e --- /dev/null +++ b/app/VERSION @@ -0,0 +1,5 @@ +VERSION_MAJOR = 1 +VERSION_MINOR = 0 +PATCHLEVEL = 0 +VERSION_TWEAK = 0 +EXTRAVERSION = diff --git a/app/boards/nucleo_f302r8.overlay b/app/boards/nucleo_f302r8.overlay new file mode 100644 index 000000000..c79248095 --- /dev/null +++ b/app/boards/nucleo_f302r8.overlay @@ -0,0 +1,21 @@ +/* + * 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. + */ + +/ { + examplesensor0: examplesensor_0 { + compatible = "zephyr,examplesensor"; + input-gpios = <&gpioc 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + }; +}; + +&gpioc { + status = "okay"; +}; diff --git a/app/debug.conf b/app/debug.conf new file mode 100644 index 000000000..885971fc3 --- /dev/null +++ b/app/debug.conf @@ -0,0 +1,19 @@ +# 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 + +# console +CONFIG_CONSOLE=y + +# UART console +CONFIG_SERIAL=y +CONFIG_UART_CONSOLE=y + +# logging +CONFIG_LOG=y +CONFIG_APP_LOG_LEVEL_DBG=y diff --git a/app/prj.conf b/app/prj.conf new file mode 100644 index 000000000..e7a3bfa9c --- /dev/null +++ b/app/prj.conf @@ -0,0 +1,6 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 +# +# This file contains selected Kconfig options for the application. + +CONFIG_SENSOR=y diff --git a/app/sample.yaml b/app/sample.yaml new file mode 100644 index 000000000..582bb8fe5 --- /dev/null +++ b/app/sample.yaml @@ -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 diff --git a/app/src/main.c b/app/src/main.c new file mode 100644 index 000000000..0bf9b67a9 --- /dev/null +++ b/app/src/main.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL); + +int main(void) +{ + int ret; + const struct device *sensor; + + printk("Zephyr Example Application %s\n", APP_VERSION_STRING); + + sensor = DEVICE_DT_GET(DT_NODELABEL(examplesensor0)); + if (!device_is_ready(sensor)) { + LOG_ERR("Sensor not ready"); + return 0; + } + + while (1) { + struct sensor_value val; + + 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; + } + + printk("Sensor value: %d\n", val.val1); + + k_sleep(K_MSEC(1000)); + } + + return 0; +} + diff --git a/boards/arm/custom_plank/Kconfig b/boards/arm/custom_plank/Kconfig new file mode 100644 index 000000000..8cd0b5520 --- /dev/null +++ b/boards/arm/custom_plank/Kconfig @@ -0,0 +1,8 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_ENABLE_DCDC + bool "Enable DCDC mode" + select SOC_DCDC_NRF52X + default y + depends on BOARD_CUSTOM_PLANK diff --git a/boards/arm/custom_plank/Kconfig.board b/boards/arm/custom_plank/Kconfig.board new file mode 100644 index 000000000..51cdc50a4 --- /dev/null +++ b/boards/arm/custom_plank/Kconfig.board @@ -0,0 +1,6 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_CUSTOM_PLANK + bool "Custom Plank Board" + depends on SOC_NRF52840_QIAA diff --git a/boards/arm/custom_plank/Kconfig.defconfig b/boards/arm/custom_plank/Kconfig.defconfig new file mode 100644 index 000000000..114f0ee8d --- /dev/null +++ b/boards/arm/custom_plank/Kconfig.defconfig @@ -0,0 +1,9 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_CUSTOM_PLANK + +config BOARD + default "custom_plank" + +endif # BOARD_CUSTOM_PLANK diff --git a/boards/arm/custom_plank/README.md b/boards/arm/custom_plank/README.md new file mode 100644 index 000000000..f4b868be7 --- /dev/null +++ b/boards/arm/custom_plank/README.md @@ -0,0 +1,6 @@ +# Custom Plank Board + +`custom_plank` board is used to demonstrate how to create custom boards. It is +in fact a simplified version of the nRF52840-DK board, so the +`example-application` can be run on that development kit when using +`custom_plank`. diff --git a/boards/arm/custom_plank/board.cmake b/boards/arm/custom_plank/board.cmake new file mode 100644 index 000000000..5c6b5319f --- /dev/null +++ b/boards/arm/custom_plank/board.cmake @@ -0,0 +1,12 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +board_runner_args(jlink "--device=nrf52" "--speed=4000") +board_runner_args(pyocd "--target=nrf52840" "--frequency=4000000") + +set(OPENOCD_NRF5_SUBFAMILY "nrf52") + +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) +include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/boards/arm/custom_plank/custom_plank-pinctrl.dtsi b/boards/arm/custom_plank/custom_plank-pinctrl.dtsi new file mode 100644 index 000000000..4da31cb0e --- /dev/null +++ b/boards/arm/custom_plank/custom_plank-pinctrl.dtsi @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +&pinctrl { + uart0_default: uart0_default { + group1 { + psels = , + , + , + ; + }; + }; + + uart0_sleep: uart0_sleep { + group1 { + psels = , + , + , + ; + low-power-enable; + }; + }; + +}; diff --git a/boards/arm/custom_plank/custom_plank.dts b/boards/arm/custom_plank/custom_plank.dts new file mode 100644 index 000000000..dee804d6a --- /dev/null +++ b/boards/arm/custom_plank/custom_plank.dts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include "custom_plank-pinctrl.dtsi" + +/ { + model = "Custom Plank Board"; + compatible = "vendor,custom-plank"; + + chosen { + zephyr,console = &uart0; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + }; + + examplesensor0: examplesensor_0 { + compatible = "zephyr,examplesensor"; + input-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + }; +}; + +&gpio0 { + status = "okay"; +}; + +&uart0 { + compatible = "nordic,nrf-uarte"; + status = "okay"; + + current-speed = <115200>; + pinctrl-0 = <&uart0_default>; + pinctrl-1 = <&uart0_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/boards/arm/custom_plank/custom_plank.yaml b/boards/arm/custom_plank/custom_plank.yaml new file mode 100644 index 000000000..071ba3d08 --- /dev/null +++ b/boards/arm/custom_plank/custom_plank.yaml @@ -0,0 +1,15 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +identifier: custom_plank +name: Custom-Plank +type: mcu +arch: arm +ram: 256 +flash: 1024 +toolchain: + - zephyr + - gnuarmemb + - xtools +supported: + - gpio diff --git a/boards/arm/custom_plank/custom_plank_defconfig b/boards/arm/custom_plank/custom_plank_defconfig new file mode 100644 index 000000000..4a5558aa9 --- /dev/null +++ b/boards/arm/custom_plank/custom_plank_defconfig @@ -0,0 +1,14 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF52X=y +CONFIG_SOC_NRF52840_QIAA=y +CONFIG_BOARD_CUSTOM_PLANK=y + +CONFIG_ARM_MPU=y +CONFIG_HW_STACK_PROTECTION=y + +CONFIG_GPIO=y +CONFIG_GPIO_AS_PINRESET=y + +CONFIG_PINCTRL=y diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt new file mode 100644 index 000000000..183462eb2 --- /dev/null +++ b/drivers/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory_ifdef(CONFIG_SENSOR sensor) diff --git a/drivers/Kconfig b/drivers/Kconfig new file mode 100644 index 000000000..550329c2f --- /dev/null +++ b/drivers/Kconfig @@ -0,0 +1,6 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +menu "Drivers" +rsource "sensor/Kconfig" +endmenu diff --git a/drivers/sensor/CMakeLists.txt b/drivers/sensor/CMakeLists.txt new file mode 100644 index 000000000..fbb6b450d --- /dev/null +++ b/drivers/sensor/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory_ifdef(CONFIG_EXAMPLESENSOR examplesensor) diff --git a/drivers/sensor/Kconfig b/drivers/sensor/Kconfig new file mode 100644 index 000000000..23c196630 --- /dev/null +++ b/drivers/sensor/Kconfig @@ -0,0 +1,6 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SENSOR +rsource "examplesensor/Kconfig" +endif # SENSOR diff --git a/drivers/sensor/examplesensor/CMakeLists.txt b/drivers/sensor/examplesensor/CMakeLists.txt new file mode 100644 index 000000000..ff3266eba --- /dev/null +++ b/drivers/sensor/examplesensor/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_sources(examplesensor.c) diff --git a/drivers/sensor/examplesensor/Kconfig b/drivers/sensor/examplesensor/Kconfig new file mode 100644 index 000000000..a8ab99ad6 --- /dev/null +++ b/drivers/sensor/examplesensor/Kconfig @@ -0,0 +1,10 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +config EXAMPLESENSOR + bool "Example sensor" + default y + depends on DT_HAS_ZEPHYR_EXAMPLESENSOR_ENABLED + select GPIO + help + Enable example sensor diff --git a/drivers/sensor/examplesensor/examplesensor.c b/drivers/sensor/examplesensor/examplesensor.c new file mode 100644 index 000000000..0e35e200a --- /dev/null +++ b/drivers/sensor/examplesensor/examplesensor.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT zephyr_examplesensor + +#include +#include +#include + +#include +LOG_MODULE_REGISTER(examplesensor, CONFIG_SENSOR_LOG_LEVEL); + +struct examplesensor_data { + int state; +}; + +struct examplesensor_config { + struct gpio_dt_spec input; +}; + +static int examplesensor_sample_fetch(const struct device *dev, + enum sensor_channel chan) +{ + const struct examplesensor_config *config = dev->config; + struct examplesensor_data *data = dev->data; + + data->state = gpio_pin_get_dt(&config->input); + + return 0; +} + +static int examplesensor_channel_get(const struct device *dev, + enum sensor_channel chan, + struct sensor_value *val) +{ + struct examplesensor_data *data = dev->data; + + if (chan != SENSOR_CHAN_PROX) { + return -ENOTSUP; + } + + val->val1 = data->state; + + return 0; +} + +static const struct sensor_driver_api examplesensor_api = { + .sample_fetch = &examplesensor_sample_fetch, + .channel_get = &examplesensor_channel_get, +}; + +static int examplesensor_init(const struct device *dev) +{ + const struct examplesensor_config *config = dev->config; + + int ret; + + if (!device_is_ready(config->input.port)) { + LOG_ERR("Input GPIO not ready"); + return -ENODEV; + } + + ret = gpio_pin_configure_dt(&config->input, GPIO_INPUT); + if (ret < 0) { + LOG_ERR("Could not configure input GPIO (%d)", ret); + return ret; + } + + return 0; +} + +#define EXAMPLESENSOR_INIT(i) \ + static struct examplesensor_data examplesensor_data_##i; \ + \ + static const struct examplesensor_config examplesensor_config_##i = { \ + .input = GPIO_DT_SPEC_INST_GET(i, input_gpios), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(i, examplesensor_init, NULL, \ + &examplesensor_data_##i, \ + &examplesensor_config_##i, POST_KERNEL, \ + CONFIG_SENSOR_INIT_PRIORITY, &examplesensor_api); + +DT_INST_FOREACH_STATUS_OKAY(EXAMPLESENSOR_INIT) diff --git a/dts/bindings/sensor/zephyr,examplesensor.yaml b/dts/bindings/sensor/zephyr,examplesensor.yaml new file mode 100644 index 000000000..41f9d9e37 --- /dev/null +++ b/dts/bindings/sensor/zephyr,examplesensor.yaml @@ -0,0 +1,23 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +description: | + An example sensor that reads the GPIO level defined in input-gpios. The + purpose of this sensor is to demonstrate how to create out-of-tree drivers. + + Example definition in devicetree: + + examplesensor { + compatible = "zephyr,examplesensor"; + input-gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + }; + +compatible: "zephyr,examplesensor" + +include: base.yaml + +properties: + input-gpios: + type: phandle-array + required: true + description: Input GPIO to be sensed. diff --git a/include/custom_lib/custom_lib.h b/include/custom_lib/custom_lib.h new file mode 100644 index 000000000..9d285d010 --- /dev/null +++ b/include/custom_lib/custom_lib.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021, Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef EXAMPLE_APPLICATION_INCLUDE_CUSTOM_LIB_CUSTOM_LIB_H_ +#define EXAMPLE_APPLICATION_INCLUDE_CUSTOM_LIB_CUSTOM_LIB_H_ + +/** + * @brief Return parameter if non-zero, or Kconfig-controlled default + * + * Function returns the provided value if non-zero, or a Kconfig-controlled + * default value if the parameter is zero. This trivial function is + * provided in order to have a library interface example that is trivial + * to test. + * + * @param return_value_if_nonzero Value to return if non-zero + * @returns return_value_if_nonzero when the parameter is non-zero + * @returns CONFIG_CUSTOM_LIB_GET_VALUE_DEFAULT if parameter is zero + */ +int custom_lib_get_value(int return_value_if_nonzero); + +#endif /* EXAMPLE_APPLICATION_INCLUDE_CUSTOM_LIB_CUSTOM_LIB_H_ */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 000000000..d24bef004 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory_ifdef(CONFIG_CUSTOM_LIB custom_lib) diff --git a/lib/Kconfig b/lib/Kconfig new file mode 100644 index 000000000..5fd3678d0 --- /dev/null +++ b/lib/Kconfig @@ -0,0 +1,8 @@ +# Copyright (c) 2021 Legrand North America, LLC. +# SPDX-License-Identifier: Apache-2.0 + +menu "Libraries" + +rsource "custom_lib/Kconfig" + +endmenu diff --git a/lib/custom_lib/CMakeLists.txt b/lib/custom_lib/CMakeLists.txt new file mode 100644 index 000000000..d683936de --- /dev/null +++ b/lib/custom_lib/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright (c) 2021, Legrand North America, LLC. +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_sources(custom_lib.c) diff --git a/lib/custom_lib/Kconfig b/lib/custom_lib/Kconfig new file mode 100644 index 000000000..14cc9eb0d --- /dev/null +++ b/lib/custom_lib/Kconfig @@ -0,0 +1,19 @@ +# Copyright (c) 2021, Legrand North America, LLC. +# SPDX-License-Identifier: Apache-2.0 + +config CUSTOM_LIB + bool "custom_lib Support" + help + This option enables the custom_lib library + +config CUSTOM_LIB_GET_VALUE_DEFAULT + int "custom_lib_get_value() default return value" + depends on CUSTOM_LIB + default 0 + help + This option primarily exists as an example of a library Kconfig + setting. + + This option specifies the value for custom_lib_get_value() + to return when the input parameter is zero. (Otherwise + the function returns the input parameter value.) diff --git a/lib/custom_lib/custom_lib.c b/lib/custom_lib/custom_lib.c new file mode 100644 index 000000000..6711cc4e5 --- /dev/null +++ b/lib/custom_lib/custom_lib.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2021, Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +int custom_lib_get_value(int return_value_if_nonzero) +{ + return (return_value_if_nonzero != 0) ? return_value_if_nonzero + : CONFIG_CUSTOM_LIB_GET_VALUE_DEFAULT; +} diff --git a/scripts/example_west_command.py b/scripts/example_west_command.py new file mode 100644 index 000000000..7f68d7f4e --- /dev/null +++ b/scripts/example_west_command.py @@ -0,0 +1,49 @@ +# Copyright (c) 2019 Foundries.io +# Copyright (c) 2022 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +'''example_west_command.py + +Example of a west extension in the example-application repository.''' + +from west.commands import WestCommand # your extension must subclass this +from west import log # use this for user output + +class ExampleWestCommand(WestCommand): + + def __init__(self): + super().__init__( + 'example-west-command', # gets stored as self.name + 'an example west extension command', # self.help + # self.description: + '''\ +A multi-line description of example-west-command. + +You can split this up into multiple paragraphs and they'll get +reflowed for you. You can also pass +formatter_class=argparse.RawDescriptionHelpFormatter when calling +parser_adder.add_parser() below if you want to keep your line +endings.''') + + def do_add_parser(self, parser_adder): + # This is a bit of boilerplate, which allows you full control over the + # type of argparse handling you want. The "parser_adder" argument is + # the return value of an argparse.ArgumentParser.add_subparsers() call. + parser = parser_adder.add_parser(self.name, + help=self.help, + description=self.description) + + # Add some example options using the standard argparse module API. + parser.add_argument('-o', '--optional', help='an optional argument') + parser.add_argument('required', help='a required argument') + + return parser # gets stored as self.parser + + def do_run(self, args, unknown_args): + # This gets called when the user runs the command, e.g.: + # + # $ west my-command-name -o FOO BAR + # --optional is FOO + # required is BAR + log.inf('--optional is', args.optional) + log.inf('required is', args.required) diff --git a/scripts/west-commands.yml b/scripts/west-commands.yml new file mode 100644 index 000000000..e32692a90 --- /dev/null +++ b/scripts/west-commands.yml @@ -0,0 +1,6 @@ +west-commands: + - file: scripts/example_west_command.py + commands: + - name: example-west-command + class: ExampleWestCommand + help: an example west extension command diff --git a/tests/lib/custom_lib/CMakeLists.txt b/tests/lib/custom_lib/CMakeLists.txt new file mode 100644 index 000000000..054149097 --- /dev/null +++ b/tests/lib/custom_lib/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2021, Legrand North America, LLC. +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(custom_lib) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/lib/custom_lib/prj.conf b/tests/lib/custom_lib/prj.conf new file mode 100644 index 000000000..b0d275aa4 --- /dev/null +++ b/tests/lib/custom_lib/prj.conf @@ -0,0 +1,3 @@ +CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y +CONFIG_CUSTOM_LIB=y diff --git a/tests/lib/custom_lib/src/main.c b/tests/lib/custom_lib/src/main.c new file mode 100644 index 000000000..e3a4695dd --- /dev/null +++ b/tests/lib/custom_lib/src/main.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Legrand North America, LLC. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * @file test custom_lib library + * + * This suite verifies that the methods provided with the custom_lib + * library works correctly. + */ + +#include + +#include + +#include + +ZTEST(custom_lib, test_get_value) +{ + /* Verify standard behavior */ + zassert_equal(custom_lib_get_value(INT_MIN), INT_MIN, + "get_value failed input of INT_MIN"); + zassert_equal(custom_lib_get_value(INT_MIN + 1), INT_MIN + 1, + "get_value failed input of INT_MIN + 1"); + zassert_equal(custom_lib_get_value(-1), -1, + "get_value failed input of -1"); + zassert_equal(custom_lib_get_value(1), 1, + "get_value failed input of 1"); + zassert_equal(custom_lib_get_value(INT_MAX - 1), INT_MAX - 1, + "get_value failed input of INT_MAX - 1"); + zassert_equal(custom_lib_get_value(INT_MAX), INT_MAX, + "get_value failed input of INT_MAX"); + + /* Verify override behavior */ + zassert_equal(custom_lib_get_value(0), + CONFIG_CUSTOM_LIB_GET_VALUE_DEFAULT, + "get_value failed input of 0"); +} + +ZTEST_SUITE(custom_lib, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/lib/custom_lib/testcase.yaml b/tests/lib/custom_lib/testcase.yaml new file mode 100644 index 000000000..9055f6795 --- /dev/null +++ b/tests/lib/custom_lib/testcase.yaml @@ -0,0 +1,9 @@ +common: + tags: extensibility + integration_platforms: + - custom_plank + - qemu_cortex_m0 +tests: + lib.custom_lib: {} + lib.custom_lib.non_default: + extra_args: CONFIG_CUSTOM_LIB_GET_VALUE_DEFAULT=6 diff --git a/west.yml b/west.yml new file mode 100644 index 000000000..6bb551cbd --- /dev/null +++ b/west.yml @@ -0,0 +1,22 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +manifest: + self: + west-commands: scripts/west-commands.yml + + remotes: + - name: zephyrproject-rtos + url-base: https://github.com/zephyrproject-rtos + + projects: + - name: zephyr + remote: zephyrproject-rtos + revision: main + import: + # By using name-allowlist we can clone only the modules that are + # strictly needed by the application. + name-allowlist: + - cmsis # required by the ARM port + - hal_nordic # required by the custom_plank board (Nordic based) + - hal_stm32 # required by the nucleo_f302r8 board (STM32 based) diff --git a/zephyr/module.yml b/zephyr/module.yml new file mode 100644 index 000000000..047032a91 --- /dev/null +++ b/zephyr/module.yml @@ -0,0 +1,20 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +build: + # Path to the Kconfig file that will be sourced into Zephyr Kconfig tree under + # Zephyr > Modules > example-application. Path is relative from root of this + # repository. + kconfig: Kconfig + # Path to the folder that contains the CMakeLists.txt file to be included by + # Zephyr build system. The `.` is the root of this repository. + cmake: . + settings: + # Additional roots for boards and DTS files. Zephyr will use the + # `/boards` for additional boards. The `.` is the root of this + # repository. + board_root: . + # Zephyr will use the `/dts` for additional dts files and + # `/dts/bindings` for additional dts binding files. The `.` is + # the root of this repository. + dts_root: .