Initial commit
This commit is contained in:
49
.github/workflows/build.yml
vendored
Normal file
49
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-22.04, macos-12, macos-14, windows-2022]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: example-application
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.11
|
||||
|
||||
- name: Setup Zephyr project
|
||||
uses: zephyrproject-rtos/action-zephyr-setup@v1
|
||||
with:
|
||||
app-path: example-application
|
||||
toolchains: arm-zephyr-eabi
|
||||
|
||||
- name: Build firmware
|
||||
working-directory: example-application
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ runner.os }}" = "Windows" ]; then
|
||||
EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out"
|
||||
fi
|
||||
west twister -T app -v --inline-logs --integration $EXTRA_TWISTER_FLAGS
|
||||
|
||||
- name: Twister Tests
|
||||
working-directory: example-application
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ runner.os }}" = "Windows" ]; then
|
||||
EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out"
|
||||
fi
|
||||
west twister -T tests -v --inline-logs --integration $EXTRA_TWISTER_FLAGS
|
61
.github/workflows/docs.yml
vendored
Normal file
61
.github/workflows/docs.yml
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2024, Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
name: Documentation
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
DOXYGEN_VERSION: 1.9.6
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
wget --no-verbose "https://github.com/doxygen/doxygen/releases/download/Release_${DOXYGEN_VERSION//./_}/doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz"
|
||||
tar xf doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz
|
||||
echo "${PWD}/doxygen-${DOXYGEN_VERSION}/bin" >> $GITHUB_PATH
|
||||
pip install -r doc/requirements.txt
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cd doc
|
||||
doxygen
|
||||
|
||||
SPHINXOPTS="-W" make html
|
||||
|
||||
mkdir deploy
|
||||
mv _build_doxygen/html deploy/doxygen
|
||||
mv _build_sphinx/html/* deploy
|
||||
|
||||
- name: Setup pages
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: actions/configure-pages@v4
|
||||
|
||||
- name: Upload pages artifact
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: doc/deploy
|
||||
|
||||
- name: Upload artifacts
|
||||
if: github.event_name == 'pull_request'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
path: doc/deploy
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-22.04
|
||||
needs: build
|
||||
if: github.event_name != 'pull_request'
|
||||
permissions:
|
||||
pages: write
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: actions/deploy-pages@v4
|
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# editors
|
||||
.vscode
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# python
|
||||
.venv
|
||||
|
||||
# build
|
||||
/build*
|
||||
/twister-out*
|
||||
|
||||
__pycache__/
|
||||
|
||||
# docs
|
||||
/doc/_build*
|
15
CMakeLists.txt
Normal file
15
CMakeLists.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# 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).
|
||||
|
||||
|
||||
# This is needed so that custom driver classes using system calls are taken into
|
||||
# account
|
||||
zephyr_syscall_include_directories(include)
|
||||
|
||||
zephyr_include_directories(include)
|
||||
|
||||
add_subdirectory(drivers)
|
||||
add_subdirectory(lib)
|
9
Kconfig
Normal file
9
Kconfig
Normal file
@ -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"
|
201
LICENSE
Normal file
201
LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
130
README.md
Normal file
130
README.md
Normal file
@ -0,0 +1,130 @@
|
||||
# Zephyr Example Application
|
||||
|
||||
<a href="https://zephyrproject-rtos.github.io/example-application">
|
||||
<img alt="Documentation" src="https://img.shields.io/badge/documentation-3D578C?logo=sphinx&logoColor=white">
|
||||
</a>
|
||||
<a href="https://zephyrproject-rtos.github.io/example-application/doxygen">
|
||||
<img alt="API Documentation" src="https://img.shields.io/badge/API-documentation-3D578C?logo=c&logoColor=white">
|
||||
</a>
|
||||
|
||||
This repository contains a Zephyr example application. The main purpose of this
|
||||
repository is to serve as a reference on how to structure Zephyr-based
|
||||
applications. Some of the features demonstrated in this example are:
|
||||
|
||||
- Basic [Zephyr application][app_dev] skeleton
|
||||
- [Zephyr workspace applications][workspace_app]
|
||||
- [Zephyr modules][modules]
|
||||
- [West T2 topology][west_t2]
|
||||
- [Custom boards][board_porting]
|
||||
- Custom [devicetree bindings][bindings]
|
||||
- Out-of-tree [drivers][drivers]
|
||||
- Out-of-tree libraries
|
||||
- Example CI configuration (using Github Actions)
|
||||
- Custom [west extension][west_ext]
|
||||
- Doxygen and Sphinx documentation boilerplate
|
||||
|
||||
This repository is versioned together with the [Zephyr main tree][zephyr]. This
|
||||
means that every time that Zephyr is tagged, this repository is tagged as well
|
||||
with the same version number, and the [manifest](west.yml) entry for `zephyr`
|
||||
will point to the corresponding Zephyr tag. For example, the `example-application`
|
||||
v2.6.0 will point to Zephyr v2.6.0. Note that the `main` branch always
|
||||
points to the development branch of Zephyr, also `main`.
|
||||
|
||||
[app_dev]: https://docs.zephyrproject.org/latest/develop/application/index.html
|
||||
[workspace_app]: https://docs.zephyrproject.org/latest/develop/application/index.html#zephyr-workspace-app
|
||||
[modules]: https://docs.zephyrproject.org/latest/develop/modules.html
|
||||
[west_t2]: https://docs.zephyrproject.org/latest/develop/west/workspaces.html#west-t2
|
||||
[board_porting]: https://docs.zephyrproject.org/latest/guides/porting/board_porting.html
|
||||
[bindings]: https://docs.zephyrproject.org/latest/guides/dts/bindings.html
|
||||
[drivers]: https://docs.zephyrproject.org/latest/reference/drivers/index.html
|
||||
[zephyr]: https://github.com/zephyrproject-rtos/zephyr
|
||||
[west_ext]: https://docs.zephyrproject.org/latest/develop/west/extensions.html
|
||||
|
||||
## Getting Started
|
||||
|
||||
Before getting started, make sure you have a proper Zephyr development
|
||||
environment. Follow the official
|
||||
[Zephyr Getting Started Guide](https://docs.zephyrproject.org/latest/getting_started/index.html).
|
||||
|
||||
### Initialization
|
||||
|
||||
The first step is to initialize the workspace folder (``my-workspace``) where
|
||||
the ``example-application`` and all Zephyr modules will be cloned. Run the following
|
||||
command:
|
||||
|
||||
```shell
|
||||
# initialize my-workspace for the example-application (main branch)
|
||||
west init -m https://github.com/zephyrproject-rtos/example-application --mr main my-workspace
|
||||
# update Zephyr modules
|
||||
cd my-workspace
|
||||
west update
|
||||
```
|
||||
|
||||
### Building and running
|
||||
|
||||
To build the application, run the following command:
|
||||
|
||||
```shell
|
||||
cd example-application
|
||||
west build -b $BOARD app
|
||||
```
|
||||
|
||||
where `$BOARD` is the target board.
|
||||
|
||||
You can use the `custom_plank` board found in this
|
||||
repository. Note that Zephyr sample boards may be used if an
|
||||
appropriate overlay is provided (see `app/boards`).
|
||||
|
||||
A sample debug configuration is also provided. To apply it, run the following
|
||||
command:
|
||||
|
||||
```shell
|
||||
west build -b $BOARD app -- -DOVERLAY_CONFIG=debug.conf
|
||||
```
|
||||
|
||||
Once you have built the application, run the following command to flash it:
|
||||
|
||||
```shell
|
||||
west flash
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
To execute Twister integration tests, run the following command:
|
||||
|
||||
```shell
|
||||
west twister -T tests --integration
|
||||
```
|
||||
|
||||
### Documentation
|
||||
|
||||
A minimal documentation setup is provided for Doxygen and Sphinx. To build the
|
||||
documentation first change to the ``doc`` folder:
|
||||
|
||||
```shell
|
||||
cd doc
|
||||
```
|
||||
|
||||
Before continueing, check if you have Doxygen installed. It is recommended to
|
||||
use the same Doxygen version used in [CI](.github/workflows/docs.yml). To
|
||||
install Sphinx, make sure you have a Python installation in place and run:
|
||||
|
||||
```shell
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
API documentation (Doxygen) can be built using the following command:
|
||||
|
||||
```shell
|
||||
doxygen
|
||||
```
|
||||
|
||||
The output will be stored in the ``_build_doxygen`` folder. Similarly, the
|
||||
Sphinx documentation (HTML) can be built using the following command:
|
||||
|
||||
```shell
|
||||
make html
|
||||
```
|
||||
|
||||
The output will be stored in the ``_build_sphinx`` folder. You may check for
|
||||
other output formats other than HTML by running ``make help``.
|
12
app/CMakeLists.txt
Normal file
12
app/CMakeLists.txt
Normal 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
15
app/Kconfig
Normal 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
5
app/VERSION
Normal file
@ -0,0 +1,5 @@
|
||||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 0
|
||||
PATCHLEVEL = 0
|
||||
VERSION_TWEAK = 0
|
||||
EXTRAVERSION =
|
27
app/boards/nucleo_f302r8.overlay
Normal file
27
app/boards/nucleo_f302r8.overlay
Normal 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
12
app/debug.conf
Normal 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
7
app/prj.conf
Normal 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
16
app/sample.yaml
Normal 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
80
app/src/main.c
Normal 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;
|
||||
}
|
||||
|
8
boards/vendor/custom_plank/Kconfig
vendored
Normal file
8
boards/vendor/custom_plank/Kconfig
vendored
Normal file
@ -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
|
5
boards/vendor/custom_plank/Kconfig.custom_plank
vendored
Normal file
5
boards/vendor/custom_plank/Kconfig.custom_plank
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config BOARD_CUSTOM_PLANK
|
||||
select SOC_NRF52840_QIAA
|
6
boards/vendor/custom_plank/README.md
vendored
Normal file
6
boards/vendor/custom_plank/README.md
vendored
Normal file
@ -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`.
|
12
boards/vendor/custom_plank/board.cmake
vendored
Normal file
12
boards/vendor/custom_plank/board.cmake
vendored
Normal file
@ -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)
|
8
boards/vendor/custom_plank/board.yml
vendored
Normal file
8
boards/vendor/custom_plank/board.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
board:
|
||||
name: custom_plank
|
||||
vendor: vendor
|
||||
socs:
|
||||
- name: nrf52840
|
26
boards/vendor/custom_plank/custom_plank-pinctrl.dtsi
vendored
Normal file
26
boards/vendor/custom_plank/custom_plank-pinctrl.dtsi
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&pinctrl {
|
||||
uart0_default: uart0_default {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(UART_TX, 0, 6)>,
|
||||
<NRF_PSEL(UART_RX, 0, 8)>,
|
||||
<NRF_PSEL(UART_RTS, 0, 5)>,
|
||||
<NRF_PSEL(UART_CTS, 0, 7)>;
|
||||
};
|
||||
};
|
||||
|
||||
uart0_sleep: uart0_sleep {
|
||||
group1 {
|
||||
psels = <NRF_PSEL(UART_TX, 0, 6)>,
|
||||
<NRF_PSEL(UART_RX, 0, 8)>,
|
||||
<NRF_PSEL(UART_RTS, 0, 5)>,
|
||||
<NRF_PSEL(UART_CTS, 0, 7)>;
|
||||
low-power-enable;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
52
boards/vendor/custom_plank/custom_plank.dts
vendored
Normal file
52
boards/vendor/custom_plank/custom_plank.dts
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/dts-v1/;
|
||||
#include <nordic/nrf52840_qiaa.dtsi>
|
||||
#include "custom_plank-pinctrl.dtsi"
|
||||
|
||||
/ {
|
||||
model = "Custom Plank Board";
|
||||
compatible = "vendor,custom-plank";
|
||||
|
||||
chosen {
|
||||
zephyr,console = &uart0;
|
||||
zephyr,sram = &sram0;
|
||||
zephyr,flash = &flash0;
|
||||
};
|
||||
|
||||
example_sensor: example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
blink_led: blink-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
|
||||
blink-period-ms = <1000>;
|
||||
};
|
||||
};
|
||||
|
||||
&uicr {
|
||||
gpio-as-nreset;
|
||||
};
|
||||
|
||||
&gpiote {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&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";
|
||||
};
|
16
boards/vendor/custom_plank/custom_plank.yaml
vendored
Normal file
16
boards/vendor/custom_plank/custom_plank.yaml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
identifier: custom_plank
|
||||
name: Custom-Plank
|
||||
vendor: vendor
|
||||
type: mcu
|
||||
arch: arm
|
||||
ram: 256
|
||||
flash: 1024
|
||||
toolchain:
|
||||
- zephyr
|
||||
- gnuarmemb
|
||||
- xtools
|
||||
supported:
|
||||
- gpio
|
15
boards/vendor/custom_plank/custom_plank_defconfig
vendored
Normal file
15
boards/vendor/custom_plank/custom_plank_defconfig
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
CONFIG_ARM_MPU=y
|
||||
CONFIG_HW_STACK_PROTECTION=y
|
||||
|
||||
# Enable UART console on all configurations for convenience. This is usually
|
||||
# done at board level upstream so that all samples output printed messages to
|
||||
# the configured #zephyr,console. In production boards, this may be enabled at
|
||||
# application level or in a debug configuration overlay.
|
||||
CONFIG_SERIAL=y
|
||||
CONFIG_CONSOLE=y
|
||||
CONFIG_UART_CONSOLE=y
|
||||
|
||||
CONFIG_PINCTRL=y
|
2735
doc/Doxyfile
Normal file
2735
doc/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
20
doc/Makefile
Normal file
20
doc/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?=
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SOURCEDIR = .
|
||||
BUILDDIR = _build_sphinx
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
.PHONY: help Makefile
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
17
doc/_doxygen/groups.dox
Normal file
17
doc/_doxygen/groups.dox
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @defgroup drivers Custom driver classes
|
||||
* @{
|
||||
*
|
||||
* @brief Custom driver classes
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup lib Custom libraries
|
||||
* @{
|
||||
*
|
||||
* @brief Custom libraries
|
||||
*
|
||||
* @}
|
||||
*/
|
5
doc/_doxygen/main.md
Normal file
5
doc/_doxygen/main.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Introduction
|
||||
|
||||
This is the Doxygen documentation for [example-application].
|
||||
|
||||
[example-application]: https://github.com/zephyrproject-rtos/example-application
|
40
doc/conf.py
Normal file
40
doc/conf.py
Normal file
@ -0,0 +1,40 @@
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# For the full list of built-in configuration values, see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
||||
|
||||
project = 'Example Application'
|
||||
copyright = '2024, The Zephyr Community'
|
||||
author = 'The Zephyr Community'
|
||||
release = '1.0.0'
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
|
||||
extensions = ['sphinx.ext.intersphinx', 'breathe']
|
||||
|
||||
templates_path = ['_templates']
|
||||
exclude_patterns = ['_build_sphinx', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
||||
|
||||
html_theme = 'alabaster'
|
||||
|
||||
# -- Options for Intersphinx -------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html
|
||||
|
||||
intersphinx_mapping = {'zephyr': ('https://docs.zephyrproject.org/latest/', None)}
|
||||
|
||||
## -- Options for Breathe ----------------------------------------------------
|
||||
# https://breathe.readthedocs.io/en/latest/index.html
|
||||
#
|
||||
# WARNING: please, check breathe maintainership status before using this
|
||||
# extension in production!
|
||||
|
||||
breathe_projects = {'example-application': '_build_doxygen/xml'}
|
||||
breathe_default_project = 'example-application'
|
||||
breathe_default_members = ('members', )
|
14
doc/drivers/blink.rst
Normal file
14
doc/drivers/blink.rst
Normal file
@ -0,0 +1,14 @@
|
||||
Blink
|
||||
=====
|
||||
|
||||
.. doxygengroup:: drivers_blink
|
||||
|
||||
Driver operations
|
||||
-----------------
|
||||
|
||||
.. doxygengroup:: drivers_blink_ops
|
||||
|
||||
Public API
|
||||
----------
|
||||
|
||||
.. doxygengroup:: drivers_blink_api
|
9
doc/drivers/index.rst
Normal file
9
doc/drivers/index.rst
Normal file
@ -0,0 +1,9 @@
|
||||
Drivers
|
||||
=======
|
||||
|
||||
.. doxygengroup:: drivers
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
blink
|
18
doc/index.rst
Normal file
18
doc/index.rst
Normal file
@ -0,0 +1,18 @@
|
||||
Welcome to Example Application's documentation!
|
||||
===============================================
|
||||
|
||||
This is a simple Sphinx documentation setup for ``example-application``.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents
|
||||
|
||||
drivers/index
|
||||
lib/index
|
||||
zephyr
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`search`
|
11
doc/lib/custom.rst
Normal file
11
doc/lib/custom.rst
Normal file
@ -0,0 +1,11 @@
|
||||
Custom
|
||||
======
|
||||
|
||||
.. doxygengroup:: lib_custom
|
||||
:desc-only:
|
||||
|
||||
Public API
|
||||
----------
|
||||
|
||||
.. doxygengroup:: lib_custom
|
||||
:content-only:
|
9
doc/lib/index.rst
Normal file
9
doc/lib/index.rst
Normal file
@ -0,0 +1,9 @@
|
||||
Libraries
|
||||
=========
|
||||
|
||||
.. doxygengroup:: lib
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
custom
|
35
doc/make.bat
Normal file
35
doc/make.bat
Normal file
@ -0,0 +1,35 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set SOURCEDIR=.
|
||||
set BUILDDIR=_build_sphinx
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.https://www.sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
|
||||
:end
|
||||
popd
|
2
doc/requirements.txt
Normal file
2
doc/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Sphinx
|
||||
breathe
|
5
doc/zephyr.rst
Normal file
5
doc/zephyr.rst
Normal file
@ -0,0 +1,5 @@
|
||||
Zephyr
|
||||
======
|
||||
|
||||
You can reference Zephyr documentation items, like
|
||||
:external+zephyr:ref:`getting_started` or :external+zephyr:c:func:`k_sleep`.
|
8
drivers/CMakeLists.txt
Normal file
8
drivers/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Out-of-tree drivers for custom classes
|
||||
add_subdirectory_ifdef(CONFIG_BLINK blink)
|
||||
|
||||
# Out-of-tree drivers for existing driver classes
|
||||
add_subdirectory_ifdef(CONFIG_SENSOR sensor)
|
7
drivers/Kconfig
Normal file
7
drivers/Kconfig
Normal file
@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menu "Drivers"
|
||||
rsource "blink/Kconfig"
|
||||
rsource "sensor/Kconfig"
|
||||
endmenu
|
5
drivers/blink/CMakeLists.txt
Normal file
5
drivers/blink/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
zephyr_library_sources_ifdef(CONFIG_BLINK_GPIO_LED gpio_led.c)
|
23
drivers/blink/Kconfig
Normal file
23
drivers/blink/Kconfig
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menuconfig BLINK
|
||||
bool "Blink device drivers"
|
||||
help
|
||||
This option enables the blink custom driver class.
|
||||
|
||||
if BLINK
|
||||
|
||||
config BLINK_INIT_PRIORITY
|
||||
int "Blink device drivers init priority"
|
||||
default KERNEL_INIT_PRIORITY_DEVICE
|
||||
help
|
||||
Blink device drivers init priority.
|
||||
|
||||
module = BLINK
|
||||
module-str = blink
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
rsource "Kconfig.gpio_led"
|
||||
|
||||
endif # BLINK
|
11
drivers/blink/Kconfig.gpio_led
Normal file
11
drivers/blink/Kconfig.gpio_led
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config BLINK_GPIO_LED
|
||||
bool "GPIO-controlled LED blink driver"
|
||||
default y
|
||||
depends on DT_HAS_BLINK_GPIO_LED_ENABLED
|
||||
select GPIO
|
||||
help
|
||||
Enable this option to use the GPIO-controlled LED blink driver. This
|
||||
demonstrates how to implement a driver for a custom driver class.
|
101
drivers/blink/gpio_led.c
Normal file
101
drivers/blink/gpio_led.c
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT blink_gpio_led
|
||||
|
||||
#include <zephyr/device.h>
|
||||
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include <app/drivers/blink.h>
|
||||
|
||||
LOG_MODULE_REGISTER(blink_gpio_led, CONFIG_BLINK_LOG_LEVEL);
|
||||
|
||||
struct blink_gpio_led_data {
|
||||
struct k_timer timer;
|
||||
};
|
||||
|
||||
struct blink_gpio_led_config {
|
||||
struct gpio_dt_spec led;
|
||||
unsigned int period_ms;
|
||||
};
|
||||
|
||||
static void blink_gpio_led_on_timer_expire(struct k_timer *timer)
|
||||
{
|
||||
const struct device *dev = k_timer_user_data_get(timer);
|
||||
const struct blink_gpio_led_config *config = dev->config;
|
||||
int ret;
|
||||
|
||||
ret = gpio_pin_toggle_dt(&config->led);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not toggle LED GPIO (%d)", ret);
|
||||
}
|
||||
}
|
||||
|
||||
static int blink_gpio_led_set_period_ms(const struct device *dev,
|
||||
unsigned int period_ms)
|
||||
{
|
||||
const struct blink_gpio_led_config *config = dev->config;
|
||||
struct blink_gpio_led_data *data = dev->data;
|
||||
|
||||
if (period_ms == 0) {
|
||||
k_timer_stop(&data->timer);
|
||||
return gpio_pin_set_dt(&config->led, 0);
|
||||
}
|
||||
|
||||
k_timer_start(&data->timer, K_MSEC(period_ms), K_MSEC(period_ms));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct blink_driver_api blink_gpio_led_api = {
|
||||
.set_period_ms = &blink_gpio_led_set_period_ms,
|
||||
};
|
||||
|
||||
static int blink_gpio_led_init(const struct device *dev)
|
||||
{
|
||||
const struct blink_gpio_led_config *config = dev->config;
|
||||
struct blink_gpio_led_data *data = dev->data;
|
||||
int ret;
|
||||
|
||||
if (!gpio_is_ready_dt(&config->led)) {
|
||||
LOG_ERR("LED GPIO not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = gpio_pin_configure_dt(&config->led, GPIO_OUTPUT_INACTIVE);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not configure LED GPIO (%d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
k_timer_init(&data->timer, blink_gpio_led_on_timer_expire, NULL);
|
||||
k_timer_user_data_set(&data->timer, (void *)dev);
|
||||
|
||||
if (config->period_ms > 0) {
|
||||
k_timer_start(&data->timer, K_MSEC(config->period_ms),
|
||||
K_MSEC(config->period_ms));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BLINK_GPIO_LED_DEFINE(inst) \
|
||||
static struct blink_gpio_led_data data##inst; \
|
||||
\
|
||||
static const struct blink_gpio_led_config config##inst = { \
|
||||
.led = GPIO_DT_SPEC_INST_GET(inst, led_gpios), \
|
||||
.period_ms = DT_INST_PROP_OR(inst, blink_period_ms, 0U), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, blink_gpio_led_init, NULL, &data##inst, \
|
||||
&config##inst, POST_KERNEL, \
|
||||
CONFIG_BLINK_INIT_PRIORITY, \
|
||||
&blink_gpio_led_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(BLINK_GPIO_LED_DEFINE)
|
4
drivers/sensor/CMakeLists.txt
Normal file
4
drivers/sensor/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
add_subdirectory_ifdef(CONFIG_EXAMPLE_SENSOR example_sensor)
|
6
drivers/sensor/Kconfig
Normal file
6
drivers/sensor/Kconfig
Normal file
@ -0,0 +1,6 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if SENSOR
|
||||
rsource "example_sensor/Kconfig"
|
||||
endif # SENSOR
|
5
drivers/sensor/example_sensor/CMakeLists.txt
Normal file
5
drivers/sensor/example_sensor/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
zephyr_library_sources(example_sensor.c)
|
10
drivers/sensor/example_sensor/Kconfig
Normal file
10
drivers/sensor/example_sensor/Kconfig
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config EXAMPLE_SENSOR
|
||||
bool "Example sensor"
|
||||
default y
|
||||
depends on DT_HAS_ZEPHYR_EXAMPLE_SENSOR_ENABLED
|
||||
select GPIO
|
||||
help
|
||||
Enable example sensor
|
86
drivers/sensor/example_sensor/example_sensor.c
Normal file
86
drivers/sensor/example_sensor/example_sensor.c
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zephyr_example_sensor
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(example_sensor, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
struct example_sensor_data {
|
||||
int state;
|
||||
};
|
||||
|
||||
struct example_sensor_config {
|
||||
struct gpio_dt_spec input;
|
||||
};
|
||||
|
||||
static int example_sensor_sample_fetch(const struct device *dev,
|
||||
enum sensor_channel chan)
|
||||
{
|
||||
const struct example_sensor_config *config = dev->config;
|
||||
struct example_sensor_data *data = dev->data;
|
||||
|
||||
data->state = gpio_pin_get_dt(&config->input);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int example_sensor_channel_get(const struct device *dev,
|
||||
enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct example_sensor_data *data = dev->data;
|
||||
|
||||
if (chan != SENSOR_CHAN_PROX) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
val->val1 = data->state;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct sensor_driver_api example_sensor_api = {
|
||||
.sample_fetch = &example_sensor_sample_fetch,
|
||||
.channel_get = &example_sensor_channel_get,
|
||||
};
|
||||
|
||||
static int example_sensor_init(const struct device *dev)
|
||||
{
|
||||
const struct example_sensor_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 EXAMPLE_SENSOR_INIT(i) \
|
||||
static struct example_sensor_data example_sensor_data_##i; \
|
||||
\
|
||||
static const struct example_sensor_config example_sensor_config_##i = {\
|
||||
.input = GPIO_DT_SPEC_INST_GET(i, input_gpios), \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(i, example_sensor_init, NULL, \
|
||||
&example_sensor_data_##i, \
|
||||
&example_sensor_config_##i, POST_KERNEL, \
|
||||
CONFIG_SENSOR_INIT_PRIORITY, &example_sensor_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(EXAMPLE_SENSOR_INIT)
|
28
dts/bindings/blink/blink-gpio-leds.yaml
Normal file
28
dts/bindings/blink/blink-gpio-leds.yaml
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
A generic binding for a GPIO-controlled blinking LED. Note that this binding
|
||||
has no vendor prefix, as it does not target a specific device or vendor.
|
||||
|
||||
Example definition in devicetree:
|
||||
|
||||
blink-gpio-led {
|
||||
compatible = "blink-gpio-led";
|
||||
led-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
|
||||
blink-period-ms = <1000>;
|
||||
};
|
||||
|
||||
compatible: "blink-gpio-led"
|
||||
|
||||
include: base.yaml
|
||||
|
||||
properties:
|
||||
led-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: GPIO-controlled LED.
|
||||
|
||||
blink-period-ms:
|
||||
type: int
|
||||
description: Initial blinking period in milliseconds.
|
23
dts/bindings/sensor/zephyr,example-sensor.yaml
Normal file
23
dts/bindings/sensor/zephyr,example-sensor.yaml
Normal file
@ -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:
|
||||
|
||||
example-sensor {
|
||||
compatible = "zephyr,example-sensor";
|
||||
input-gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
|
||||
};
|
||||
|
||||
compatible: "zephyr,example-sensor"
|
||||
|
||||
include: base.yaml
|
||||
|
||||
properties:
|
||||
input-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
description: Input GPIO to be sensed.
|
113
include/app/drivers/blink.h
Normal file
113
include/app/drivers/blink.h
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef APP_DRIVERS_BLINK_H_
|
||||
#define APP_DRIVERS_BLINK_H_
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/toolchain.h>
|
||||
|
||||
/**
|
||||
* @defgroup drivers_blink Blink drivers
|
||||
* @ingroup drivers
|
||||
* @{
|
||||
*
|
||||
* @brief A custom driver class to blink LEDs
|
||||
*
|
||||
* This driver class is provided as an example of how to create custom driver
|
||||
* classes. It provides an interface to blink an LED at a configurable rate.
|
||||
* Implementations could include simple GPIO-controlled LEDs, addressable LEDs,
|
||||
* etc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup drivers_blink_ops Blink driver operations
|
||||
* @{
|
||||
*
|
||||
* @brief Operations of the blink driver class.
|
||||
*
|
||||
* Each driver class tipically provides a set of operations that need to be
|
||||
* implemented by each driver. These are used to implement the public API. If
|
||||
* support for system calls is needed, the operations structure must be tagged
|
||||
* with `__subsystem` and follow the `${class}_driver_api` naming scheme.
|
||||
*/
|
||||
|
||||
/** @brief Blink driver class operations */
|
||||
__subsystem struct blink_driver_api {
|
||||
/**
|
||||
* @brief Configure the LED blink period.
|
||||
*
|
||||
* @param dev Blink device instance.
|
||||
* @param period_ms Period of the LED blink in milliseconds, 0 to
|
||||
* disable blinking.
|
||||
*
|
||||
* @retval 0 if successful.
|
||||
* @retval -EINVAL if @p period_ms can not be set.
|
||||
* @retval -errno Other negative errno code on failure.
|
||||
*/
|
||||
int (*set_period_ms)(const struct device *dev, unsigned int period_ms);
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup drivers_blink_api Blink driver API
|
||||
* @{
|
||||
*
|
||||
* @brief Public API provided by the blink driver class.
|
||||
*
|
||||
* The public API is the interface that is used by applications to interact with
|
||||
* devices that implement the blink driver class. If support for system calls is
|
||||
* needed, functions accessing device fields need to be tagged with `__syscall`
|
||||
* and provide an implementation that follows the `z_impl_${function_name}`
|
||||
* naming scheme.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure the LED blink period.
|
||||
*
|
||||
*
|
||||
* @param dev Blink device instance.
|
||||
* @param period_ms Period of the LED blink in milliseconds.
|
||||
*
|
||||
* @retval 0 if successful.
|
||||
* @retval -EINVAL if @p period_ms can not be set.
|
||||
* @retval -errno Other negative errno code on failure.
|
||||
*/
|
||||
__syscall int blink_set_period_ms(const struct device *dev,
|
||||
unsigned int period_ms);
|
||||
|
||||
static inline int z_impl_blink_set_period_ms(const struct device *dev,
|
||||
unsigned int period_ms)
|
||||
{
|
||||
const struct blink_driver_api *api =
|
||||
(const struct blink_driver_api *)dev->api;
|
||||
|
||||
return api->set_period_ms(dev, period_ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turn LED blinking off.
|
||||
*
|
||||
* This is a convenience function to turn off the LED blinking. It also shows
|
||||
* how to create convenience functions that re-use other driver functions, or
|
||||
* driver operations, to provide a higher-level API.
|
||||
*
|
||||
* @param dev Blink device instance.
|
||||
*
|
||||
* @return See blink_set_period_ms().
|
||||
*/
|
||||
static inline int blink_off(const struct device *dev)
|
||||
{
|
||||
return blink_set_period_ms(dev, 0);
|
||||
}
|
||||
|
||||
#include <syscalls/blink.h>
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* APP_DRIVERS_BLINK_H_ */
|
37
include/app/lib/custom.h
Normal file
37
include/app/lib/custom.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef APP_LIB_CUSTOM_H_
|
||||
#define APP_LIB_CUSTOM_H_
|
||||
|
||||
/**
|
||||
* @defgroup lib_custom Custom library
|
||||
* @ingroup lib
|
||||
* @{
|
||||
*
|
||||
* @brief An example of a custom out-of-tree library.
|
||||
*
|
||||
* This library illustrates how create custom out-of-tree libraries. Splitting
|
||||
* code in libraries enables code reuse and modularity, also easing testing.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return @p val 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 val Value to return if non-zero
|
||||
*
|
||||
* @retval val if @p val is non-zero
|
||||
* @retval CONFIG_CUSTOM_GET_VALUE_DEFAULT if @p val is zero
|
||||
*/
|
||||
int custom_get_value(int val);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* APP_LIB_CUSTOM_H_ */
|
3
lib/CMakeLists.txt
Normal file
3
lib/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
add_subdirectory_ifdef(CONFIG_CUSTOM custom)
|
8
lib/Kconfig
Normal file
8
lib/Kconfig
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021 Legrand North America, LLC.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menu "Custom libraries"
|
||||
|
||||
rsource "custom/Kconfig"
|
||||
|
||||
endmenu
|
5
lib/custom/CMakeLists.txt
Normal file
5
lib/custom/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# Copyright (c) 2021, Legrand North America, LLC.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
zephyr_library_sources(custom.c)
|
19
lib/custom/Kconfig
Normal file
19
lib/custom/Kconfig
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2021, Legrand North America, LLC.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config CUSTOM
|
||||
bool "Support for custom library"
|
||||
help
|
||||
This option enables the 'custom' library
|
||||
|
||||
config CUSTOM_GET_VALUE_DEFAULT
|
||||
int "custom_get_value() default return value"
|
||||
depends on CUSTOM
|
||||
default 0
|
||||
help
|
||||
This option primarily exists as an example of a library Kconfig
|
||||
setting.
|
||||
|
||||
This option specifies the value for custom_get_value() to return
|
||||
when the input parameter is zero. (Otherwise the function returns the
|
||||
input parameter value.)
|
12
lib/custom/custom.c
Normal file
12
lib/custom/custom.c
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Legrand North America, LLC.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <app/lib/custom.h>
|
||||
|
||||
int custom_get_value(int val)
|
||||
{
|
||||
return (val != 0) ? val : CONFIG_CUSTOM_GET_VALUE_DEFAULT;
|
||||
}
|
49
scripts/example_west_command.py
Normal file
49
scripts/example_west_command.py
Normal file
@ -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)
|
6
scripts/west-commands.yml
Normal file
6
scripts/west-commands.yml
Normal file
@ -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
|
8
tests/lib/custom/CMakeLists.txt
Normal file
8
tests/lib/custom/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# 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(app_lib_custom_test)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
2
tests/lib/custom/prj.conf
Normal file
2
tests/lib/custom/prj.conf
Normal file
@ -0,0 +1,2 @@
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_CUSTOM=y
|
42
tests/lib/custom/src/main.c
Normal file
42
tests/lib/custom/src/main.c
Normal file
@ -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 <limits.h>
|
||||
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
#include <app/lib/custom.h>
|
||||
|
||||
ZTEST(custom_lib, test_get_value)
|
||||
{
|
||||
/* Verify standard behavior */
|
||||
zassert_equal(custom_get_value(INT_MIN), INT_MIN,
|
||||
"get_value failed input of INT_MIN");
|
||||
zassert_equal(custom_get_value(INT_MIN + 1), INT_MIN + 1,
|
||||
"get_value failed input of INT_MIN + 1");
|
||||
zassert_equal(custom_get_value(-1), -1,
|
||||
"get_value failed input of -1");
|
||||
zassert_equal(custom_get_value(1), 1,
|
||||
"get_value failed input of 1");
|
||||
zassert_equal(custom_get_value(INT_MAX - 1), INT_MAX - 1,
|
||||
"get_value failed input of INT_MAX - 1");
|
||||
zassert_equal(custom_get_value(INT_MAX), INT_MAX,
|
||||
"get_value failed input of INT_MAX");
|
||||
|
||||
/* Verify override behavior */
|
||||
zassert_equal(custom_get_value(0),
|
||||
CONFIG_CUSTOM_GET_VALUE_DEFAULT,
|
||||
"get_value failed input of 0");
|
||||
}
|
||||
|
||||
ZTEST_SUITE(custom_lib, NULL, NULL, NULL, NULL, NULL);
|
9
tests/lib/custom/testcase.yaml
Normal file
9
tests/lib/custom/testcase.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
common:
|
||||
tags: extensibility
|
||||
integration_platforms:
|
||||
- custom_plank
|
||||
- qemu_cortex_m0
|
||||
tests:
|
||||
lib.custom: {}
|
||||
lib.custom.non_default:
|
||||
extra_args: CONFIG_CUSTOM_GET_VALUE_DEFAULT=6
|
22
west.yml
Normal file
22
west.yml
Normal file
@ -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)
|
20
zephyr/module.yml
Normal file
20
zephyr/module.yml
Normal file
@ -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
|
||||
# `<board_root>/boards` for additional boards. The `.` is the root of this
|
||||
# repository.
|
||||
board_root: .
|
||||
# Zephyr will use the `<dts_root>/dts` for additional dts files and
|
||||
# `<dts_root>/dts/bindings` for additional dts binding files. The `.` is
|
||||
# the root of this repository.
|
||||
dts_root: .
|
Reference in New Issue
Block a user