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