From aba9e7080fd9c758ff3bfe30980c483850571da8 Mon Sep 17 00:00:00 2001 From: Marcin Jelinski Date: Mon, 17 Nov 2025 14:42:30 +0100 Subject: [PATCH] samples: esb: add sample showing PRX concurrent operation with BLE This sample showcases how to use the ESB protocol concurrently with Bluetooth. It runs the ESB radio in PRX (receiver) mode while simultaneously enabling the BLE LBS (LED Button Service). Ref: NCSDK-35772 Signed-off-by: Marcin Jelinski --- .../releases/release-notes-changelog.rst | 11 +- samples/esb/esb_prx/README.rst | 2 + samples/esb/esb_prx_ble/CMakeLists.txt | 15 + samples/esb/esb_prx_ble/Kconfig | 15 + samples/esb/esb_prx_ble/Kconfig.sysbuild | 4 + samples/esb/esb_prx_ble/README.rst | 132 ++++++ .../boards/nrf54h20dk_nrf54h20_cpurad.overlay | 64 +++ .../boards/nrf54l15dk_nrf54l05_cpuapp.conf | 8 + .../boards/nrf54l15dk_nrf54l10_cpuapp.conf | 8 + .../boards/nrf54l15dk_nrf54l15_cpuapp.conf | 8 + .../boards/nrf54lm20dk_nrf54lm20a_cpuapp.conf | 8 + .../boards/nrf54lv10dk_nrf54lv10a_cpuapp.conf | 8 + samples/esb/esb_prx_ble/prj.conf | 32 ++ samples/esb/esb_prx_ble/sample.yaml | 38 ++ samples/esb/esb_prx_ble/src/main.c | 378 ++++++++++++++++++ samples/esb/esb_ptx/README.rst | 2 + 16 files changed, 729 insertions(+), 4 deletions(-) create mode 100644 samples/esb/esb_prx_ble/CMakeLists.txt create mode 100644 samples/esb/esb_prx_ble/Kconfig create mode 100644 samples/esb/esb_prx_ble/Kconfig.sysbuild create mode 100644 samples/esb/esb_prx_ble/README.rst create mode 100644 samples/esb/esb_prx_ble/boards/nrf54h20dk_nrf54h20_cpurad.overlay create mode 100644 samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l05_cpuapp.conf create mode 100644 samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l10_cpuapp.conf create mode 100644 samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l15_cpuapp.conf create mode 100644 samples/esb/esb_prx_ble/boards/nrf54lm20dk_nrf54lm20a_cpuapp.conf create mode 100644 samples/esb/esb_prx_ble/boards/nrf54lv10dk_nrf54lv10a_cpuapp.conf create mode 100644 samples/esb/esb_prx_ble/prj.conf create mode 100644 samples/esb/esb_prx_ble/sample.yaml create mode 100644 samples/esb/esb_prx_ble/src/main.c diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 39ddbe7676f..51da0455055 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -206,11 +206,14 @@ DECT NR+ Enhanced ShockBurst (ESB) ------------------------- -* Added the :ref:`esb_monitor_mode` feature. -* Added experimental support for the nRF54LV10A SoC in the following samples: +* Added: + + * Experimental support for the nRF54LV10A SoC in the following samples: - * :ref:`esb_prx` - * :ref:`esb_ptx` + * :ref:`esb_prx` + * :ref:`esb_ptx` + * The :ref:`esb_monitor_mode` feature. + * The :ref:`esb_prx_ble` sample that demonstrates how to use the ESB protocol in receiver mode concurrently with the Bluetooth LE LBS service. Gazell ------ diff --git a/samples/esb/esb_prx/README.rst b/samples/esb/esb_prx/README.rst index 384fd0fdc08..5875b741ff9 100644 --- a/samples/esb/esb_prx/README.rst +++ b/samples/esb/esb_prx/README.rst @@ -57,6 +57,8 @@ FEM support .. include:: /includes/sample_fem_support.txt +.. _esb_prx_testing: + Testing ======= diff --git a/samples/esb/esb_prx_ble/CMakeLists.txt b/samples/esb/esb_prx_ble/CMakeLists.txt new file mode 100644 index 00000000000..b41dcb01e15 --- /dev/null +++ b/samples/esb/esb_prx_ble/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# Copyright (c) 2025 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(esb_prx_ble) + +# NORDIC SDK APP START +target_sources(app PRIVATE + src/main.c +) +# NORDIC SDK APP END diff --git a/samples/esb/esb_prx_ble/Kconfig b/samples/esb/esb_prx_ble/Kconfig new file mode 100644 index 00000000000..c09afd7fee6 --- /dev/null +++ b/samples/esb/esb_prx_ble/Kconfig @@ -0,0 +1,15 @@ +# +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +source "Kconfig.zephyr" + +menu "Enhanced ShockBurst: Receiver BLE" + +module = ESB_PRX_BLE +module-str = "ESB_PRX_BLE" +source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config" + +endmenu diff --git a/samples/esb/esb_prx_ble/Kconfig.sysbuild b/samples/esb/esb_prx_ble/Kconfig.sysbuild new file mode 100644 index 00000000000..858e9d89462 --- /dev/null +++ b/samples/esb/esb_prx_ble/Kconfig.sysbuild @@ -0,0 +1,4 @@ +source "share/sysbuild/Kconfig" + +config NRF_DEFAULT_EMPTY + default y if SOC_SERIES_NRF53X diff --git a/samples/esb/esb_prx_ble/README.rst b/samples/esb/esb_prx_ble/README.rst new file mode 100644 index 00000000000..33ee03db6e9 --- /dev/null +++ b/samples/esb/esb_prx_ble/README.rst @@ -0,0 +1,132 @@ +.. _esb_prx_ble: + +Enhanced ShockBurst: Receiver with Bluetooth LE +################################################ + +.. contents:: + :local: + :depth: 2 + +The sample shows how to use the :ref:`ug_esb` protocol in receiver mode concurrently with Bluetooth® LE protocol. +It demonstrates how to configure the Enhanced ShockBurst protocol to receive packets while simultaneously running Bluetooth LE services. + +Requirements +************ + +The sample supports the following development kits: + +.. table-from-sample-yaml:: + +Additionally, if you want to test the Enhanced ShockBurst Transmitter functionality, you need to build and run the :ref:`esb_ptx` sample. +You can use any two of the listed development kits and mix different development kits. + +Overview +******** + +The sample consists of one Receiver that uses the :ref:`esb_README` library in combination with Bluetooth LE functionality. +After building and programming the sample on a development kit, you can test that packets that are sent by the kit that runs the :ref:`Transmitter ` sample are picked up by the kit that runs the Receiver sample. +Successful communication is indicated by LED changes. + +The Receiver sample listens for packets and sends an ACK when a packet is received. +If packets are successfully received from the Transmitter, the LED pattern changes every time a packet is received. + +The sample demonstrates cooperative operation between ESB and Bluetooth LE protocols using the MPSL (Multiprotocol Service Layer) time slot mechanism. +This mechanism allows both protocols to share radio time without interference. +The sample runs the :ref:`lbs_readme` alongside the ESB receiver functionality, enabling simultaneous wireless communication using both protocols. + +User interface +*************** + +All LEDs: + Indicate that packets are sent or received. + The first four packets turn on the LEDs sequentially. + The next four packets turn them off again in the same order. + +.. tabs:: + + .. group-tab:: nRF52 and nRF53 DKs + + LED 1: + Lit when the development kit is connected. + + LED 2: + Lit when the development kit is controlled remotely from the connected device. + + LED 3 and LED 4: + Indicate that packets are received. + + Button 1: + Send a notification with the button state: "pressed" or "released". + + .. group-tab:: nRF54 DKs + + LED 0: + Lit when the development kit is connected. + + LED 1: + Lit when the development kit is controlled remotely from the connected device. + + LED 2 and LED 3: + Indicate that packets are received. + + Button 0: + Send a notification with the button state: "pressed" or "released". + +Configuration +************* + +|config| + +Building and running +******************** + +The Receiver sample can be found under :file:`samples/esb/esb_prx_ble` in the |NCS| folder structure. + +See :ref:`building` and :ref:`programming` for information about how to build and program the application, respectively. + +.. include:: /includes/nRF54H20_erase_UICR.txt + +FEM support +=========== + +.. include:: /includes/sample_fem_support.txt + +Testing +======= + +This sample combines ESB receiver functionality with Bluetooth LE LBS service, and both protocols can be tested independently. + +Testing ESB functionality +------------------------- + +To test the ESB receiver functionality, follow the testing procedure described in the :ref:`Testing section of the Enhanced ShockBurst: Receiver ` sample documentation. +In brief, you need to program the Transmitter sample (:ref:`esb_ptx`) on another development kit and observe that the LEDs change synchronously on both kits as packets are transmitted and received. + +Testing LBS service +------------------- + +To test the Bluetooth LE LBS service functionality, follow the testing procedure described in the :ref:`Testing section of LBS ` sample documentation. +You can use a smartphone or tablet with the `nRF Connect for Mobile`_ or `nRF Blinky`_ application to connect to the device (advertising as ``Nordic_LBS``), control the LED remotely, and receive button press notifications. + +Dependencies +************ + +This sample uses the following |NCS| libraries: + +* :ref:`esb_readme` +* :ref:`ug_ble` +* :ref:`mpsl` +* :ref:`lbs_readme` + +In addition, it uses the following Zephyr libraries: + +* :file:`include/zephyr/types.h` +* :ref:`zephyr:logging_api` +* :ref:`zephyr:kernel_api`: + + * :file:`include/kernel.h` + * :file:`include/irq.h` + +* :ref:`zephyr:api_peripherals`: + + * :file:`include/gpio.h` diff --git a/samples/esb/esb_prx_ble/boards/nrf54h20dk_nrf54h20_cpurad.overlay b/samples/esb/esb_prx_ble/boards/nrf54h20dk_nrf54h20_cpurad.overlay new file mode 100644 index 00000000000..d41bd5b4e5f --- /dev/null +++ b/samples/esb/esb_prx_ble/boards/nrf54h20dk_nrf54h20_cpurad.overlay @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/ { + leds { + compatible = "gpio-leds"; + + led0: led_0 { + gpios = < &gpio9 0 GPIO_ACTIVE_HIGH >; + label = "Green LED 0"; + }; + + led1: led_1 { + gpios = < &gpio9 1 GPIO_ACTIVE_HIGH >; + label = "Green LED 1"; + }; + + led2: led_2 { + gpios = < &gpio9 2 GPIO_ACTIVE_HIGH >; + label = "Green LED 2"; + }; + + led3: led_3 { + gpios = < &gpio9 3 GPIO_ACTIVE_HIGH >; + label = "Green LED 3"; + }; + }; + + aliases { + led0 = &led0; + led1 = &led1; + led2 = &led2; + led3 = &led3; + }; + + cpurad_cpusys_errata216_mboxes: errata216_mboxes { + compatible = "zephyr,mbox-ipm"; + status = "okay"; + mboxes = < &cpusys_vevif 0x14 >, < &cpusys_vevif 0x15 >; + mbox-names = "on_req", "off_req"; + }; +}; + +&gpio9 { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&gpiote130 { + owned-channels = <0 1 2 3 4 5 6 7>; + status = "okay"; +}; + +&dppic020 { + status = "okay"; + source-channels = < 0 1 2 3 4 5 >; + sink-channels = < 6 7 8 9 10 11 >; +}; diff --git a/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l05_cpuapp.conf b/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l05_cpuapp.conf new file mode 100644 index 00000000000..5384eb4fe47 --- /dev/null +++ b/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l05_cpuapp.conf @@ -0,0 +1,8 @@ +# +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Enable DPPI driver +CONFIG_NRFX_DPPI10=y diff --git a/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l10_cpuapp.conf b/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l10_cpuapp.conf new file mode 100644 index 00000000000..5384eb4fe47 --- /dev/null +++ b/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l10_cpuapp.conf @@ -0,0 +1,8 @@ +# +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Enable DPPI driver +CONFIG_NRFX_DPPI10=y diff --git a/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l15_cpuapp.conf b/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l15_cpuapp.conf new file mode 100644 index 00000000000..5384eb4fe47 --- /dev/null +++ b/samples/esb/esb_prx_ble/boards/nrf54l15dk_nrf54l15_cpuapp.conf @@ -0,0 +1,8 @@ +# +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Enable DPPI driver +CONFIG_NRFX_DPPI10=y diff --git a/samples/esb/esb_prx_ble/boards/nrf54lm20dk_nrf54lm20a_cpuapp.conf b/samples/esb/esb_prx_ble/boards/nrf54lm20dk_nrf54lm20a_cpuapp.conf new file mode 100644 index 00000000000..5384eb4fe47 --- /dev/null +++ b/samples/esb/esb_prx_ble/boards/nrf54lm20dk_nrf54lm20a_cpuapp.conf @@ -0,0 +1,8 @@ +# +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Enable DPPI driver +CONFIG_NRFX_DPPI10=y diff --git a/samples/esb/esb_prx_ble/boards/nrf54lv10dk_nrf54lv10a_cpuapp.conf b/samples/esb/esb_prx_ble/boards/nrf54lv10dk_nrf54lv10a_cpuapp.conf new file mode 100644 index 00000000000..5384eb4fe47 --- /dev/null +++ b/samples/esb/esb_prx_ble/boards/nrf54lv10dk_nrf54lv10a_cpuapp.conf @@ -0,0 +1,8 @@ +# +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Enable DPPI driver +CONFIG_NRFX_DPPI10=y diff --git a/samples/esb/esb_prx_ble/prj.conf b/samples/esb/esb_prx_ble/prj.conf new file mode 100644 index 00000000000..d9211e67410 --- /dev/null +++ b/samples/esb/esb_prx_ble/prj.conf @@ -0,0 +1,32 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# +CONFIG_NCS_SAMPLES_DEFAULTS=y +CONFIG_ESB=y +CONFIG_DK_LIBRARY=y +CONFIG_CLOCK_CONTROL=y + +CONFIG_ESB_MPSL_TIMESLOT=y +CONFIG_MPSL_TIMESLOT_SESSION_COUNT=2 + +CONFIG_BT=y +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_DEVICE_NAME="Nordic_LBS" + +# Enable the LBS service +CONFIG_BT_LBS=y +CONFIG_BT_LBS_POLL_BUTTON=y +CONFIG_BT_GATT_CLIENT=y +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 + +# Bluetooth LE configuration +# Adjust connection parameters to your needs +CONFIG_BT_PERIPHERAL_PREF_MIN_INT=800 +CONFIG_BT_PERIPHERAL_PREF_MAX_INT=800 +CONFIG_BT_PERIPHERAL_PREF_LATENCY=0 +CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400 + +# Enable DEBUG level logging +CONFIG_ESB_PRX_BLE_LOG_LEVEL_DBG=y diff --git a/samples/esb/esb_prx_ble/sample.yaml b/samples/esb/esb_prx_ble/sample.yaml new file mode 100644 index 00000000000..2cace157b72 --- /dev/null +++ b/samples/esb/esb_prx_ble/sample.yaml @@ -0,0 +1,38 @@ +sample: + name: ESB prx BLE Sample +common: + harness: console + harness_config: + type: multi_line + ordered: true + regex: + - "Starting Enhanced ShockBurst prx with Peripheral LBS sample" + - "Bluetooth initialized" + - "Advertising successfully started" + - "ESB initialized" + - "Setting up for packet reception" + - "Initialization complete" + timeout: 15 + +tests: + sample.esb.prx.ble.build: + sysbuild: true + integration_platforms: + - nrf54h20dk/nrf54h20/cpurad + - nrf54l15dk/nrf54l05/cpuapp + - nrf54l15dk/nrf54l10/cpuapp + - nrf54l15dk/nrf54l15/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp + - nrf54lv10dk/nrf54lv10a/cpuapp + platform_allow: + - nrf54h20dk/nrf54h20/cpurad + - nrf54l15dk/nrf54l05/cpuapp + - nrf54l15dk/nrf54l10/cpuapp + - nrf54l15dk/nrf54l15/cpuapp + - nrf54lm20dk/nrf54lm20a/cpuapp + - nrf54lv10dk/nrf54lv10a/cpuapp + tags: + - esb + - ci_build + - sysbuild + - ci_samples_esb diff --git a/samples/esb/esb_prx_ble/src/main.c b/samples/esb/esb_prx_ble/src/main.c new file mode 100644 index 00000000000..ee10e85e15f --- /dev/null +++ b/samples/esb/esb_prx_ble/src/main.c @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(CONFIG_CLOCK_CONTROL_NRF2) +#include +#endif +#include +#if NRF54L_ERRATA_20_PRESENT +#include +#endif /* NRF54L_ERRATA_20_PRESENT */ +#if defined(NRF54LM20A_ENGA_XXAA) +#include +#endif /* defined(NRF54LM20A_ENGA_XXAA) */ + +#include +#include +#include +#include +#include + +#include + +#include + +LOG_MODULE_REGISTER(esb_prx_ble, CONFIG_ESB_PRX_BLE_LOG_LEVEL); + +#define DEVICE_NAME CONFIG_BT_DEVICE_NAME +#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) + +#define CON_STATUS_LED DK_LED1 +#define USER_LED DK_LED2 +#define ESB_LED_1 DK_LED3 +#define ESB_LED_2 DK_LED4 +#define USER_BUTTON DK_BTN1_MSK + +static bool app_button_state; +static struct k_work adv_work; + +static struct esb_payload rx_payload; +static struct esb_payload tx_payload = ESB_CREATE_PAYLOAD(0, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17); + +static const struct bt_data ad[] = { + BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), + BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), +}; + +static const struct bt_data sd[] = { + BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_LBS_VAL), +}; + +static void adv_work_handler(struct k_work *work) +{ + int err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_2, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); + + if (err) { + LOG_ERR("Advertising failed to start (err %d)", err); + return; + } + + LOG_INF("Advertising successfully started"); +} + +static void advertising_start(void) +{ + k_work_submit(&adv_work); +} + +static void connected(struct bt_conn *conn, uint8_t err) +{ + if (err) { + LOG_ERR("Connection failed, err 0x%02x %s", err, bt_hci_err_to_str(err)); + return; + } + + LOG_INF("Connected"); + + dk_set_led_on(CON_STATUS_LED); +} + +static void disconnected(struct bt_conn *conn, uint8_t reason) +{ + LOG_INF("Disconnected, reason 0x%02x %s", reason, bt_hci_err_to_str(reason)); + + dk_set_led_off(CON_STATUS_LED); +} + +static void recycled_cb(void) +{ + LOG_INF("Connection object available from previous conn. Disconnect is complete!"); + advertising_start(); +} + +BT_CONN_CB_DEFINE(conn_callbacks) = { + .connected = connected, + .disconnected = disconnected, + .recycled = recycled_cb, +}; + +static void app_led_cb(bool led_state) +{ + dk_set_led(USER_LED, led_state); +} + +static bool app_button_cb(void) +{ + return app_button_state; +} + +static struct bt_lbs_cb lbs_callbacks = { + .led_cb = app_led_cb, + .button_cb = app_button_cb, +}; + +static void button_changed(uint32_t button_state, uint32_t has_changed) +{ + if (has_changed & USER_BUTTON) { + uint32_t user_button_state = button_state & USER_BUTTON; + + bt_lbs_send_button_state(user_button_state); + app_button_state = user_button_state ? true : false; + } +} + +#if defined(CONFIG_CLOCK_CONTROL_NRF) +int clocks_start(void) +{ + int err; + int res; + struct onoff_manager *clk_mgr; + struct onoff_client clk_cli; + + clk_mgr = z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF); + if (!clk_mgr) { + LOG_ERR("Unable to get the Clock manager"); + return -ENXIO; + } + + sys_notify_init_spinwait(&clk_cli.notify); + + err = onoff_request(clk_mgr, &clk_cli); + if (err < 0) { + LOG_ERR("Clock request failed: %d", err); + return err; + } + + do { + err = sys_notify_fetch_result(&clk_cli.notify, &res); + if (!err && res) { + LOG_ERR("Clock could not be started: %d", res); + return res; + } + } while (err); + +#if NRF54L_ERRATA_20_PRESENT + if (nrf54l_errata_20()) { + nrf_power_task_trigger(NRF_POWER, NRF_POWER_TASK_CONSTLAT); + } +#endif /* NRF54L_ERRATA_20_PRESENT */ + +#if defined(NRF54LM20A_ENGA_XXAA) + /* MLTPAN-39 */ + nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_PLLSTART); +#endif + + LOG_DBG("HF clock started"); + return 0; +} + +#elif defined(CONFIG_CLOCK_CONTROL_NRF2) + +int clocks_start(void) +{ + int err; + int res; + const struct device *radio_clk_dev = + DEVICE_DT_GET_OR_NULL(DT_CLOCKS_CTLR(DT_NODELABEL(radio))); + struct onoff_client radio_cli; + + /** Keep radio domain powered all the time to reduce latency. */ + nrf_lrcconf_poweron_force_set(NRF_LRCCONF010, NRF_LRCCONF_POWER_DOMAIN_1, true); + + sys_notify_init_spinwait(&radio_cli.notify); + + err = nrf_clock_control_request(radio_clk_dev, NULL, &radio_cli); + + do { + err = sys_notify_fetch_result(&radio_cli.notify, &res); + if (!err && res) { + LOG_ERR("Clock could not be started: %d", res); + return res; + } + } while (err == -EAGAIN); + + nrf_lrcconf_clock_always_run_force_set(NRF_LRCCONF000, 0, true); + nrf_lrcconf_task_trigger(NRF_LRCCONF000, NRF_LRCCONF_TASK_CLKSTART_0); + + LOG_DBG("HF clock started"); + + return 0; +} + +#else +BUILD_ASSERT(false, "No Clock Control driver"); +#endif /* defined(CONFIG_CLOCK_CONTROL_NRF2) */ + +static void leds_update(uint8_t value) +{ + bool led1_state = !(value % 8 > 2 && value % 8 <= 6); + bool led2_state = !(value % 8 > 3); + + dk_set_led(ESB_LED_1, led1_state); + dk_set_led(ESB_LED_2, led2_state); +} + +void event_handler(struct esb_evt const *event) +{ + switch (event->evt_id) { + case ESB_EVENT_TX_SUCCESS: + LOG_DBG("TX SUCCESS EVENT"); + break; + case ESB_EVENT_TX_FAILED: + LOG_DBG("TX FAILED EVENT"); + break; + case ESB_EVENT_RX_RECEIVED: + int err; + + while ((err = esb_read_rx_payload(&rx_payload)) == 0) { + LOG_DBG("Packet received, len %d : " + "0x%02x, 0x%02x, 0x%02x, 0x%02x, " + "0x%02x, 0x%02x, 0x%02x, 0x%02x", + rx_payload.length, rx_payload.data[0], + rx_payload.data[1], rx_payload.data[2], + rx_payload.data[3], rx_payload.data[4], + rx_payload.data[5], rx_payload.data[6], + rx_payload.data[7]); + + leds_update(rx_payload.data[1]); + } + if (err && err != -ENODATA) { + LOG_ERR("Error while reading rx packet"); + } + break; + case ESB_EVENT_TIMESLOT_FAILED: + LOG_ERR("TIMESLOT FAILED EVENT"); + break; + } +} + +int esb_initialize(void) +{ + int err; + /* These are arbitrary default addresses. In end user products + * different addresses should be used for each set of devices. + */ + uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7}; + uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2}; + uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8}; + + struct esb_config config = ESB_DEFAULT_CONFIG; + + config.protocol = ESB_PROTOCOL_ESB_DPL; + config.bitrate = ESB_BITRATE_2MBPS; + config.mode = ESB_MODE_PRX; + config.event_handler = event_handler; + config.selective_auto_ack = true; + if (IS_ENABLED(CONFIG_ESB_FAST_SWITCHING)) { + config.use_fast_ramp_up = true; + } + + err = esb_init(&config); + if (err) { + return err; + } + + err = esb_set_base_address_0(base_addr_0); + if (err) { + return err; + } + + err = esb_set_base_address_1(base_addr_1); + if (err) { + return err; + } + + err = esb_set_prefixes(addr_prefix, ARRAY_SIZE(addr_prefix)); + if (err) { + return err; + } + + return 0; +} + +int main(void) +{ + int err; + + LOG_INF("Starting Enhanced ShockBurst prx with Peripheral LBS sample"); + + err = dk_leds_init(); + if (err) { + LOG_ERR("LEDs init failed (err %d)", err); + return 0; + } + + err = dk_buttons_init(button_changed); + if (err) { + LOG_ERR("Cannot init buttons (err: %d)", err); + } + + err = bt_enable(NULL); + if (err) { + LOG_ERR("Bluetooth init failed (err %d)", err); + return 0; + } + + LOG_INF("Bluetooth initialized"); + + if (IS_ENABLED(CONFIG_SETTINGS)) { + settings_load(); + } + + err = bt_lbs_init(&lbs_callbacks); + if (err) { + LOG_ERR("Failed to init LBS (err:%d)", err); + return 0; + } + + k_work_init(&adv_work, adv_work_handler); + advertising_start(); + + err = clocks_start(); + if (err) { + LOG_ERR("Clocks start failed, err %d", err); + return 0; + } + + err = esb_initialize(); + if (err) { + LOG_ERR("ESB initialization failed, err %d", err); + return 0; + } + + LOG_INF("ESB initialized"); + + err = esb_write_payload(&tx_payload); + if (err) { + LOG_ERR("Write payload, err %d", err); + return 0; + } + + LOG_INF("Setting up for packet reception"); + + err = esb_start_rx(); + if (err) { + LOG_ERR("RX setup failed, err %d", err); + return 0; + } + + LOG_INF("Initialization complete"); + + return 0; +} diff --git a/samples/esb/esb_ptx/README.rst b/samples/esb/esb_ptx/README.rst index 9eee63d1f60..b8e2b7a284c 100644 --- a/samples/esb/esb_ptx/README.rst +++ b/samples/esb/esb_ptx/README.rst @@ -57,6 +57,8 @@ FEM support .. include:: /includes/sample_fem_support.txt +.. _esb_ptx_testing: + Testing =======