samples: dac: move HW config to /zephyr,user
Require board overlays to configure the sample in the /zephyr,user node, and access the device with DEVICE_DT_GET instead of device_get_binding(). Update the documentation and move existing board configuration to overlays. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
c48bcaae0a
commit
baf93a1821
14 changed files with 104 additions and 32 deletions
|
@ -13,6 +13,10 @@ 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
|
||||
|
|
7
samples/drivers/dac/boards/arduino_zero.overlay
Normal file
7
samples/drivers/dac/boards/arduino_zero.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac0>;
|
||||
dac-channel-id = <0>;
|
||||
dac-resolution = <10>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/frdm_k22f.overlay
Normal file
7
samples/drivers/dac/boards/frdm_k22f.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac0>;
|
||||
dac-channel-id = <0>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/frdm_k64f.overlay
Normal file
7
samples/drivers/dac/boards/frdm_k64f.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac0>;
|
||||
dac-channel-id = <0>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/nucleo_f091rc.overlay
Normal file
7
samples/drivers/dac/boards/nucleo_f091rc.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <1>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/nucleo_f429zi.overlay
Normal file
7
samples/drivers/dac/boards/nucleo_f429zi.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <1>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/nucleo_f767zi.overlay
Normal file
7
samples/drivers/dac/boards/nucleo_f767zi.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <1>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/nucleo_g071rb.overlay
Normal file
7
samples/drivers/dac/boards/nucleo_g071rb.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <1>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/nucleo_g431rb.overlay
Normal file
7
samples/drivers/dac/boards/nucleo_g431rb.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <1>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/nucleo_l073rz.overlay
Normal file
7
samples/drivers/dac/boards/nucleo_l073rz.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <1>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/nucleo_l152re.overlay
Normal file
7
samples/drivers/dac/boards/nucleo_l152re.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <1>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/ronoth_lodev.overlay
Normal file
7
samples/drivers/dac/boards/ronoth_lodev.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <1>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
7
samples/drivers/dac/boards/twr_ke18f.overlay
Normal file
7
samples/drivers/dac/boards/twr_ke18f.overlay
Normal file
|
@ -0,0 +1,7 @@
|
|||
/ {
|
||||
zephyr,user {
|
||||
dac = <&dac0>;
|
||||
dac-channel-id = <0>;
|
||||
dac-resolution = <12>;
|
||||
};
|
||||
};
|
|
@ -8,37 +8,23 @@
|
|||
#include <sys/printk.h>
|
||||
#include <drivers/dac.h>
|
||||
|
||||
#if defined(CONFIG_BOARD_NUCLEO_F091RC) || \
|
||||
defined(CONFIG_BOARD_NUCLEO_G071RB) || \
|
||||
defined(CONFIG_BOARD_NUCLEO_G431RB) || \
|
||||
defined(CONFIG_BOARD_NUCLEO_L073RZ) || \
|
||||
defined(CONFIG_BOARD_NUCLEO_L152RE) || \
|
||||
defined(CONFIG_BOARD_NUCLEO_F429ZI) || \
|
||||
defined(CONFIG_BOARD_NUCLEO_F767ZI) || \
|
||||
defined(CONFIG_BOARD_RONOTH_LODEV)
|
||||
#define DAC_DEVICE_NAME DT_LABEL(DT_NODELABEL(dac1))
|
||||
#define DAC_CHANNEL_ID 1
|
||||
#define DAC_RESOLUTION 12
|
||||
#elif defined(CONFIG_BOARD_TWR_KE18F)
|
||||
#define DAC_DEVICE_NAME DT_LABEL(DT_NODELABEL(dac0))
|
||||
#define DAC_CHANNEL_ID 0
|
||||
#define DAC_RESOLUTION 12
|
||||
#elif defined(CONFIG_BOARD_FRDM_K64F)
|
||||
#define DAC_DEVICE_NAME DT_LABEL(DT_NODELABEL(dac0))
|
||||
#define DAC_CHANNEL_ID 0
|
||||
#define DAC_RESOLUTION 12
|
||||
#elif defined(CONFIG_BOARD_FRDM_K22F)
|
||||
#define DAC_DEVICE_NAME DT_LABEL(DT_NODELABEL(dac0))
|
||||
#define DAC_CHANNEL_ID 0
|
||||
#define DAC_RESOLUTION 12
|
||||
#elif defined(CONFIG_BOARD_ARDUINO_ZERO)
|
||||
#define DAC_DEVICE_NAME DT_LABEL(DT_NODELABEL(dac0))
|
||||
#define DAC_CHANNEL_ID 0
|
||||
#define DAC_RESOLUTION 10
|
||||
#define ZEPHYR_USER_NODE DT_PATH(zephyr_user)
|
||||
|
||||
#if (DT_NODE_HAS_PROP(ZEPHYR_USER_NODE, dac) && \
|
||||
DT_NODE_HAS_PROP(ZEPHYR_USER_NODE, dac_channel_id) && \
|
||||
DT_NODE_HAS_PROP(ZEPHYR_USER_NODE, dac_resolution))
|
||||
#define DAC_NODE DT_PHANDLE(ZEPHYR_USER_NODE, dac)
|
||||
#define DAC_CHANNEL_ID DT_PROP(ZEPHYR_USER_NODE, dac_channel_id)
|
||||
#define DAC_RESOLUTION DT_PROP(ZEPHYR_USER_NODE, dac_resolution)
|
||||
#else
|
||||
#error "Unsupported board."
|
||||
#error "Unsupported board: see README and check /zephyr,user node"
|
||||
#define DAC_NODE DT_INVALID_NODE
|
||||
#define DAC_CHANNEL_ID 0
|
||||
#define DAC_RESOLUTION 0
|
||||
#endif
|
||||
|
||||
static const struct device *dac_dev = DEVICE_DT_GET(DAC_NODE);
|
||||
|
||||
static const struct dac_channel_cfg dac_ch_cfg = {
|
||||
.channel_id = DAC_CHANNEL_ID,
|
||||
.resolution = DAC_RESOLUTION
|
||||
|
@ -46,10 +32,8 @@ static const struct dac_channel_cfg dac_ch_cfg = {
|
|||
|
||||
void main(void)
|
||||
{
|
||||
const struct device *dac_dev = device_get_binding(DAC_DEVICE_NAME);
|
||||
|
||||
if (!dac_dev) {
|
||||
printk("Cannot get DAC device\n");
|
||||
if (!device_is_ready(dac_dev)) {
|
||||
printk("DAC device %s is not ready\n", dac_dev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue