zephyr/samples/drivers/dac
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
..
boards
src includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h> 2022-09-05 16:31:47 +02:00
CMakeLists.txt
README.rst
prj.conf
sample.yaml

README.rst

.. _dac-sample:

Digital-to-Analog Converter (DAC)
#################################

Overview
********

This sample demonstrates how to use the DAC driver API.

Building and Running
********************

The DAC output is defined in the board's devicetree and pinmux file.

The board's :ref:`/zephyr,user <dt-zephyr-user>` node must have ``dac``,
``dac-channel-id``, and ``dac-resolution`` properties set. See the predefined
overlays in :zephyr_file:`samples/drivers/dac/boards` for examples.

Building and Running for ST Nucleo L073RZ
=========================================
The sample can be built and executed for the
:ref:`nucleo_l073rz_board` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: nucleo_l073rz
   :goals: build flash
   :compact:

Building and Running for ST Nucleo L152RE
=========================================
The sample can be built and executed for the
:ref:`nucleo_l152re_board` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: nucleo_l152re
   :goals: build flash
   :compact:

Building and Running for ST Nucleo F767ZI
=========================================
The sample can be built and executed for the
:ref:`nucleo_f767zi_board` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: nucleo_f767zi
   :goals: build flash
   :compact:

Building and Running for ST Disco F3
=========================================
The sample can be built and executed for the
:ref:`stm32f3_disco_board` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: stm32f3_disco
   :goals: build flash
   :compact:

Building and Running for ST Nucleo F429ZI
=========================================
The sample can be built and executed for the
:ref:`nucleo_f429zi_board` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: nucleo_f429zi
   :goals: build flash
   :compact:

Building and Running for STM32L562E DK
======================================
The sample can be built and executed for the
:ref:`stm32l562e_dk_board` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: stm32l562e_dk
   :goals: build flash
   :compact:

Building and Running for ST Nucleo L552ZE Q
===========================================
The sample can be built and executed for the
:ref:`nucleo_l552ze_q_board` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: nucleo_l552ze_q
   :goals: build flash
   :compact:

Building and Running for NXP TWR-KE18F
======================================
The sample can be built and executed for the :ref:`twr_ke18f` as
follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: twr_ke18f
   :goals: build flash
   :compact:

DAC output is available on pin A32 of the primary TWR elevator
connector.

Building and Running for NXP FRDM-K64F
======================================
The sample can be built and executed for the :ref:`frdm_k64f` as
follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: frdm_k64f
   :goals: build flash
   :compact:

DAC output is available on connector J4 pin 11.

Building and Running for BL652
==============================
The BL652 DVK PCB contains a footprint for a MCP4725 to use as an external
DAC. Note this is not populated by default. The sample can be built and
executed for the :ref:`bl652_dvk` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: bl652_dvk
   :goals: build flash
   :compact:

DAC output is available on pin 1 of the MCP4725.

Building and Running for BL653
==============================
The BL653 DVK PCB contains a footprint for a MCP4725 to use as an external
DAC. Note this is not populated by default. The sample can be built and
executed for the :ref:`bl653_dvk` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: bl653_dvk
   :goals: build flash
   :compact:

DAC output is available on pin 1 of the MCP4725.

Building and Running for BL654
==============================
The BL654 DVK PCB contains a footprint for a MCP4725 to use as an external
DAC. Note this is not populated by default. The sample can be built and
executed for the :ref:`bl654_dvk` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: bl654_dvk
   :goals: build flash
   :compact:

DAC output is available on pin 1 of the MCP4725.

Building and Running for BL5340
===============================
The BL5340 DVK PCB contains a MCP4725 to use as a DAC. The sample can be
built and executed for the :ref:`bl5340_dvk` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: bl5340_dvk_cpuapp
   :goals: build flash
   :compact:

DAC output is available on pin 1 of the MCP4725.

Building and Running for GD32450I-EVAL
======================================
The sample can be built and executed for the
:ref:`gd32f450i_eval` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: gd32f450i_eval
   :goals: build flash
   :compact:

Bridge the JP23 to DAC with the jumper cap, then DAC output will available on JP7.

Building and Running for Longan Nano and Longan Nano Lite
=========================================================
The sample can be built and executed for the
:ref:`longan_nano` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: longan_nano
   :goals: build flash
   :compact:

also can run for the
:ref: `longan_nano_lite` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/dac
   :board: longan_nano_lite
   :goals: build flash
   :compact:

Sample output
=============

You should see a sawtooth signal with an amplitude of the DAC reference
voltage and a period of approx. 4 seconds at the DAC output pin specified
by the board.

The following output is printed:

.. code-block:: console

   Generating sawtooth signal at DAC channel 1.

.. note:: If the DAC is not supported, the output will be an error message.