Skip to content

Commit

Permalink
doc: hardware: Move LED example to a separate page
Browse files Browse the repository at this point in the history
Moved the steps for adding a LED node from VSC extension docs to a new
page under Configuring devicetree.
VSC-2802.

Signed-off-by: Grzegorz Ferenc <[email protected]>
  • Loading branch information
greg-fer committed Jan 15, 2025
1 parent a14701b commit fc20246
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
6 changes: 2 additions & 4 deletions doc/nrf/app_dev/config_and_build/hardware/add_new_driver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ In most of the cases you want to make it possible to configure some properties o
For example, a sensor may need to allow configuring used GPIO pins or communication interface.

A driver instance can be made configurable through a devicetree node that is compatible with a specific binding.
The devicetree bindings provide structure for the devicetree by declaring requirements for the content of devicetree nodes.
The :ref:`compatible <zephyr:dt-bindings-compatible>` property defines compatibility of a devicetree node with a devicetree binding.

|devicetree_bindings|

You can create a devicetree binding YAML file for your driver in the :file:`dts/bindings` directory of your project.
If applicable, you can also use one of the existing DTS bindings available in the |NCS| or Zephyr.
For implementation examples, see :file:`nrf/dts/bindings` and :file:`zephyr/dts/bindings` directories.
See also :ref:`zephyr:devicetree` documentation for more information about devicetree.

For more information about devicetree bindings, read the :ref:`documentation about them in Zephyr <zephyr:dt-binding-compat>`.

.. rst-class:: numbered-step

Create the driver files
Expand Down
98 changes: 98 additions & 0 deletions doc/nrf/app_dev/config_and_build/hardware/add_new_led_example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
.. _add_new_led_example:

Adding a dimmable LED node
##########################

.. contents::
:local:
:depth: 2

This example demonstrates how to add support for a dimmable LED node to your board in an overlay file.

You can implement this example either by manually editing devicetree files or by using the |nRFVSC| with its `Devicetree language support`_ and the :ref:`Devicetree Visual Editor <How to work with Devicetree Visual Editor>` (which is recommended).

For more advanced LED control, you can also use the :ref:`Common Application Framework (CAF) <lib_caf>`'s :ref:`LEDs module <caf_leds>`, which provides additional features like LED effects and power management integration.

Implementation overview
***********************

This example uses Zephyr's generic binding for PWM LED controllers named ``pwm-leds``.

|devicetree_bindings|

See also the following related documentation:

* :ref:`zephyr:pwm_api` - Zephyr's PWM driver API documentation
* :ref:`zephyr:dt-guide` - Zephyr's devicetree user guide

.. rst-class:: numbered-step

Open or create the overlay file to edit
***************************************

Overlay files are a category of devicetree's :ref:`zephyr:devicetree-in-out-files`.
These files can override node property values in multiple ways.

You can add them to your configuration :ref:`manually <zephyr:set-devicetree-overlays>` or by using the |nRFVSC| (see `How to create devicetree files`_).

.. rst-class:: numbered-step

Add the PWM LED controller node
*******************************

Complete the following steps:

1. Add the controller node `pwmleds` under the root node in devicetree.
1. Add the `pwm-leds` binding for the driver to pick up.
1. Add LEDs as child nodes on the `pwmleds` controller node, with `pwms` and `label` properties.
1. Make sure the `pwms` property of the `phandle-array` type points to a PWM instance.
The PWM instance takes the pin number as its only parameter.

The following code example uses pins 6 and 7 on the GPIO port 0 (`&pwm0`):

.. code-block:: C
/ { // Devicetree root
// ...
pwmleds { // Controller node
compatible = "pwm-leds"; // Compatible binding
led_pwm_1 {
pwms = <&pwm0 6>; // Pin assigned to GPIO port 0 for LED 1
label = "PWM LED 1";
};
led_pwm_2 {
pwms = <&pwm0 7>; // Pin assigned to GPIO port 0 for LED 2
label = "PWM LED 2";
};
};
};
.. rst-class:: numbered-step

Configure the PWM node
**********************

Enable the referenced PWM0 node by setting `status = "okay"` and configuring the node's channels.
For this, you can use the `&pwm0` node label reference on the root of the file:

.. code-block:: C
&pwm0 {
status = "okay"; // Status
ch0-pin = <6>; // Pin assignment for channel 0
ch1-pin = <7>; // Pin assignment for channel 1
};
.. rst-class:: numbered-step

Enable the LED PWM driver
*************************

Enable the LED PWM driver by adding the following line to your board's :file:`prj.conf` file:

.. code-block:: none
CONFIG_LED_PWM=y
Once you have added the LED PWM driver, you :ref:`build your application <building>` and :ref:`program it to your board <programming>`.
1 change: 1 addition & 0 deletions doc/nrf/app_dev/config_and_build/hardware/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ In particular, :ref:`zephyr:set-devicetree-overlays` explains how the base devic
:caption: Subpages:

add_new_driver
add_new_led_example
pin_control
use_gpio_pin_directly
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ Documentation

* New page :ref:`thingy53_precompiled` under :ref:`ug_thingy53`.
This page includes some of the information previously located on the standalone page for getting started with Nordic Thingy:53.
* New page :ref:`add_new_led_example` under :ref:`configuring_devicetree`.
This page includes information previously located in the |nRFVSC| documentation.

* Removed the standalone page for getting started with Nordic Thingy:53.
The contents of this page have been moved to the :ref:`thingy53_precompiled` page and to the `Programmer app <Programming Nordic Thingy:53_>`_ documentation.
4 changes: 4 additions & 0 deletions doc/nrf/shortcuts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,7 @@
.. |filter_samples_by_board| replace:: If you want to list samples available for one or more specific boards, `use the nRF Connect for Visual Studio Code extension to filter them <Browse samples_>`_.

.. |54H_engb_2_8| replace:: The nRF54H20 DK Engineering A and B (up to version 0.8.2) are no longer supported starting with |NCS| v2.9.0.

.. |devicetree_bindings| replace:: The devicetree bindings provide structure for the devicetree by declaring requirements for the content of devicetree nodes.
The :ref:`compatible <zephyr:dt-bindings-compatible>` property defines compatibility of a devicetree node with a devicetree binding.
For more information about devicetree bindings, read the :ref:`documentation about them in Zephyr <zephyr:dt-binding-compat>`.

0 comments on commit fc20246

Please sign in to comment.