• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

boards/03-Apr-2024-1412

dts/bindings/03-Apr-2024-148

src/03-Apr-2024-4931

CMakeLists.txtD03-Apr-2024240 96

README.rstD03-Apr-20241.9 KiB5738

prj.confD03-Apr-202414 21

sample.yamlD03-Apr-2024440 1918

README.rst

1.. zephyr:code-sample:: gpio-custom-dts-binding
2   :name: GPIO with custom Devicetree binding
3   :relevant-api: gpio_interface devicetree-generic-id devicetree-generic-exist
4
5   Use custom Devicetree binding to control a GPIO.
6
7Overview
8********
9
10In Zephyr, all hardware-specific configuration is described in the devicetree.
11
12Consequently, also GPIO pins are configured in the devicetree and assigned to a specific purpose
13using a compatible.
14
15This is in contrast to other embedded environments like Arduino, where e.g. the direction (input /
16output) of a GPIO pin is configured in the application firmware.
17
18For typical use cases like LEDs or buttons, the existing :dtcompatible:`gpio-leds` or
19:dtcompatible:`gpio-keys` compatibles can be used.
20
21This sample demonstrates how to use a GPIO pin for other purposes with a custom devicetree binding.
22
23We assume that a load with high current demands should be switched on or off via a MOSFET. The
24custom devicetree binding for the power output controlled via a GPIO pin is specified in the file
25:zephyr_file:`samples/basic/custom_dts_binding/dts/bindings/power-switch.yaml`. The gate driver for
26the MOSFET would be connected to the pin as specified in the ``.overlay`` file in the boards
27folder.
28
29Building and Running
30********************
31
32For each board that should be supported, a ``.overlay`` file has to be defined
33in the ``boards`` subfolder.
34
35Afterwards, the sample can be built and executed for the ``<board>`` as follows:
36
37.. zephyr-app-commands::
38   :zephyr-app: samples/basic/custom_dts_binding
39   :board: <board>
40   :goals: build flash
41   :compact:
42
43For demonstration purposes, some boards use the GPIO pin of the built-in LED.
44
45Sample output
46=============
47
48The GPIO pin should be switched to active level after one second.
49
50The following output is printed:
51
52.. code-block:: console
53
54   Initializing pin with inactive level.
55   Waiting one second.
56   Setting pin to active level.
57