-
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.
doc: hardware: Move LED example to a separate page
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
Showing
5 changed files
with
107 additions
and
4 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
98 changes: 98 additions & 0 deletions
98
doc/nrf/app_dev/config_and_build/hardware/add_new_led_example.rst
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,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>`. |
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
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
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