-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new NFC shell sample that demonstrates how to use shell over NFC T4T ISO-DEP transport. NCSDK-22428 Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
- Loading branch information
Showing
5 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Copyright (c) 2023 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(NONE) | ||
|
||
# NORDIC SDK APP START | ||
target_sources(app PRIVATE src/main.c) | ||
# NORDIC SDK APP END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
.. _nfc_shell: | ||
|
||
NFC: Shell | ||
########## | ||
|
||
.. contents:: | ||
:local: | ||
:depth: 2 | ||
|
||
This sample demonstrates the NFC transport feature for a shell interface. | ||
It runs the shell interface with the NFC T4T ISO-DEP transport layer. | ||
It uses the :ref:`shell_nfc_readme` library. | ||
|
||
Requirements | ||
************ | ||
|
||
The sample supports the following development kits: | ||
|
||
.. table-from-sample-yaml:: | ||
|
||
.. include:: /includes/tfm.txt | ||
|
||
The sample also requires the polling device with support for raw ISO-DEP (ISO14443-4A) protocol. | ||
The polling device must follow data exchange mechanism described in the :ref:`shell_nfc_readme` library. | ||
|
||
Overview | ||
******** | ||
|
||
This sample presents one of possible ways to run shell through the NFC T4T transport layer. | ||
This is not a common use case for NFC as an NFC tag is a passive device. | ||
However, this feature can be useful, for example, for devices provisioning on the production line. | ||
This sample runs a shell over the NFC transport and implements two shell commands that control **LED 2**. | ||
|
||
You can use the following commands: | ||
|
||
* The ``led on`` command lits **LED 2**. | ||
* The ``led off`` command dims **LED 2**. | ||
|
||
User interface | ||
************** | ||
|
||
LED 1: | ||
Blinks, toggling on/off every second, when the main loop is running. | ||
|
||
LED 2: | ||
Lits or dims when user issues the shell commands that control the LED. | ||
|
||
Building and running | ||
******************** | ||
|
||
.. |sample path| replace:: :file:`samples/nfc/shell` | ||
|
||
.. include:: /includes/build_and_run.txt | ||
|
||
.. note:: | ||
|nfc_nfct_driver_note| | ||
|
||
Testing | ||
======= | ||
|
||
After programming the sample to your development kit, complete the following steps to test it: | ||
|
||
1. |connect_terminal_ANSI| | ||
#. Reset your development kit. | ||
#. Observe that the sample starts. | ||
#. Touch the NFC antenna with the polling device. | ||
#. Observe that the shell prompt appears on the terminal. | ||
#. Keep the NFC antenna in the polling device field range. | ||
#. Issue the ``led on`` command through the terminal. | ||
#. Observe that the **LED 2** lits. | ||
#. Issue the ``led off`` command through the terminal. | ||
#. Observe that the **LED 2** dims. | ||
#. You can play with other build-in shell commands. | ||
|
||
Dependencies | ||
************ | ||
|
||
This sample uses the following |NCS| libraries: | ||
|
||
* :ref:`shell_nfc_readme` | ||
|
||
It uses the following Zephyr libraries: | ||
|
||
* ``include/zephyr/kernel.h`` | ||
* ``zephyr/shell/shell.h`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (c) 2023 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
CONFIG_DK_LIBRARY=y | ||
|
||
CONFIG_SHELL=y | ||
CONFIG_SHELL_NFC=y | ||
|
||
# Disable serial backend and use UART for logger purpose. | ||
CONFIG_SHELL_BACKEND_SERIAL=n | ||
|
||
CONFIG_NFC_T4T_NRFXLIB=y | ||
|
||
CONFIG_LOG=y | ||
CONFIG_LOG_MODE_DEFERRED=y | ||
CONFIG_LOG_PRINTK=y | ||
|
||
CONFIG_ASSERT=y | ||
CONFIG_ASSERT_NO_COND_INFO=y | ||
CONFIG_ASSERT_NO_MSG_INFO=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
sample: | ||
description: NFC Shell sample | ||
name: NFC Shell | ||
tests: | ||
sample.nfc.shell: | ||
build_only: true | ||
integration_platforms: | ||
- nrf52840dk_nrf52840 | ||
- nrf52dk_nrf52832 | ||
- nrf5340dk_nrf5340_cpuapp | ||
- nrf5340dk_nrf5340_cpuapp_ns | ||
platform_allow: > | ||
nrf52840dk_nrf52840 | ||
nrf52dk_nrf52832 | ||
nrf5340dk_nrf5340_cpuapp | ||
nrf5340dk_nrf5340_cpuapp_ns | ||
tags: ci_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2023 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/shell/shell.h> | ||
|
||
#include <dk_buttons_and_leds.h> | ||
|
||
#define RUN_STATUS_LED DK_LED1 | ||
#define SHELL_LED DK_LED2 | ||
|
||
#define STATUS_LED_INTERVAL K_MSEC(1000) | ||
|
||
void main(void) | ||
{ | ||
uint32_t blink_status = 0; | ||
int err; | ||
|
||
printk("Starting NFC shell example\n"); | ||
|
||
err = dk_leds_init(); | ||
if (err) { | ||
printk("LEDs init failed (err %d)\n", err); | ||
return; | ||
} | ||
|
||
for (;;) { | ||
dk_set_led(RUN_STATUS_LED, (++blink_status) % 2); | ||
k_sleep(STATUS_LED_INTERVAL); | ||
} | ||
} | ||
|
||
static int led_on_handler(const struct shell *shell, size_t argc, char **argv) | ||
{ | ||
int err = dk_set_led_on(SHELL_LED); | ||
|
||
if (err) { | ||
shell_error(shell, "Failed to turn on the LED, (err: %d)", err); | ||
return err; | ||
} | ||
|
||
shell_print(shell, "The LED is on"); | ||
|
||
return 0; | ||
} | ||
|
||
static int led_off_handler(const struct shell *shell, size_t argc, char **argv) | ||
{ | ||
int err = dk_set_led_off(SHELL_LED); | ||
|
||
if (err) { | ||
shell_error(shell, "Failed to turn off the LED, (err: %d)", err); | ||
return err; | ||
} | ||
|
||
shell_print(shell, "The LED is off"); | ||
|
||
return 0; | ||
} | ||
|
||
SHELL_STATIC_SUBCMD_SET_CREATE( | ||
led_subcmd, | ||
SHELL_CMD(on, NULL, "Turn on DK LED", led_on_handler), | ||
SHELL_CMD(off, NULL, "Turn off DK LED", led_off_handler), | ||
SHELL_SUBCMD_SET_END | ||
); | ||
|
||
SHELL_CMD_REGISTER(led, &led_subcmd, "Control DK LED", NULL); |