drivers: dac: add driver for the NXP DAC12
Add driver shim for the NXP Digital-to-Analog (DAC12) module. Signed-off-by: Florijan Plohl <florijan.plohl@norik.com>
This commit is contained in:
parent
a7ad18db46
commit
7692e3db3f
4 changed files with 146 additions and 0 deletions
|
@ -6,6 +6,7 @@ zephyr_library()
|
||||||
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_DAC_MCUX_LPDAC dac_mcux_lpdac.c)
|
zephyr_library_sources_ifdef(CONFIG_DAC_MCUX_LPDAC dac_mcux_lpdac.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_DAC_MCUX_DAC dac_mcux_dac.c)
|
zephyr_library_sources_ifdef(CONFIG_DAC_MCUX_DAC dac_mcux_dac.c)
|
||||||
|
zephyr_library_sources_ifdef(CONFIG_DAC_MCUX_DAC12 dac_mcux_dac12.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_DAC_MCUX_DAC32 dac_mcux_dac32.c)
|
zephyr_library_sources_ifdef(CONFIG_DAC_MCUX_DAC32 dac_mcux_dac32.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_DAC_STM32 dac_stm32.c)
|
zephyr_library_sources_ifdef(CONFIG_DAC_STM32 dac_stm32.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_DAC_SAM dac_sam.c)
|
zephyr_library_sources_ifdef(CONFIG_DAC_SAM dac_sam.c)
|
||||||
|
|
|
@ -11,6 +11,13 @@ config DAC_MCUX_DAC
|
||||||
help
|
help
|
||||||
Enable the driver for the NXP Kinetis MCUX DAC.
|
Enable the driver for the NXP Kinetis MCUX DAC.
|
||||||
|
|
||||||
|
config DAC_MCUX_DAC12
|
||||||
|
bool "NXP MCUX DAC12 driver"
|
||||||
|
default y
|
||||||
|
depends on DT_HAS_NXP_DAC12_ENABLED
|
||||||
|
help
|
||||||
|
Enable the driver for the NXP MCUX DAC12.
|
||||||
|
|
||||||
config DAC_MCUX_DAC32
|
config DAC_MCUX_DAC32
|
||||||
bool "NXP Kinetis MCUX DAC32 driver"
|
bool "NXP Kinetis MCUX DAC32 driver"
|
||||||
default y
|
default y
|
||||||
|
|
110
drivers/dac/dac_mcux_dac12.c
Normal file
110
drivers/dac/dac_mcux_dac12.c
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Henrik Brix Andersen <henrik@brixandersen.dk>
|
||||||
|
* Copyright (c) 2023, NXP
|
||||||
|
* Copyright (c) 2025 PHYTEC America LLC
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DT_DRV_COMPAT nxp_dac12
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/drivers/dac.h>
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
|
||||||
|
#include <fsl_dac12.h>
|
||||||
|
|
||||||
|
LOG_MODULE_REGISTER(dac_mcux_dac12, CONFIG_DAC_LOG_LEVEL);
|
||||||
|
|
||||||
|
struct mcux_dac12_config {
|
||||||
|
DAC_Type *base;
|
||||||
|
dac12_reference_voltage_source_t reference;
|
||||||
|
bool buffered;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mcux_dac12_data {
|
||||||
|
bool configured;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int mcux_dac12_channel_setup(const struct device *dev,
|
||||||
|
const struct dac_channel_cfg *channel_cfg)
|
||||||
|
{
|
||||||
|
const struct mcux_dac12_config *config = dev->config;
|
||||||
|
struct mcux_dac12_data *data = dev->data;
|
||||||
|
dac12_config_t dac12_config;
|
||||||
|
|
||||||
|
if (channel_cfg->channel_id != 0) {
|
||||||
|
LOG_ERR("unsupported channel %d", channel_cfg->channel_id);
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channel_cfg->resolution != 12) {
|
||||||
|
LOG_ERR("unsupported resolution %d", channel_cfg->resolution);
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channel_cfg->internal) {
|
||||||
|
LOG_ERR("Internal channels not supported");
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
DAC12_GetDefaultConfig(&dac12_config);
|
||||||
|
dac12_config.referenceVoltageSource = config->reference;
|
||||||
|
|
||||||
|
DAC12_Init(config->base, &dac12_config);
|
||||||
|
DAC12_Enable(config->base, true);
|
||||||
|
|
||||||
|
data->configured = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mcux_dac12_write_value(const struct device *dev, uint8_t channel, uint32_t value)
|
||||||
|
{
|
||||||
|
const struct mcux_dac12_config *config = dev->config;
|
||||||
|
struct mcux_dac12_data *data = dev->data;
|
||||||
|
|
||||||
|
if (!data->configured) {
|
||||||
|
LOG_ERR("channel not initialized");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channel != 0) {
|
||||||
|
LOG_ERR("unsupported channel %d", channel);
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value >= 4096) {
|
||||||
|
LOG_ERR("value %d out of range", value);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
DAC12_SetData(config->base, value);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct dac_driver_api mcux_dac12_driver_api = {
|
||||||
|
.channel_setup = mcux_dac12_channel_setup,
|
||||||
|
.write_value = mcux_dac12_write_value,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define TO_DAC12_VREF_SRC(val) _DO_CONCAT(kDAC12_ReferenceVoltageSourceAlt, val)
|
||||||
|
|
||||||
|
#define MCUX_DAC12_INIT(n) \
|
||||||
|
static struct mcux_dac12_data mcux_dac12_data_##n; \
|
||||||
|
\
|
||||||
|
static const struct mcux_dac12_config mcux_dac12_config_##n = { \
|
||||||
|
.base = (DAC_Type *)DT_INST_REG_ADDR(n), \
|
||||||
|
.reference = \
|
||||||
|
TO_DAC12_VREF_SRC(DT_INST_PROP(n, voltage_reference)), \
|
||||||
|
.buffered = DT_INST_PROP(n, buffered), \
|
||||||
|
}; \
|
||||||
|
\
|
||||||
|
DEVICE_DT_INST_DEFINE(n, NULL, NULL, \
|
||||||
|
&mcux_dac12_data_##n, \
|
||||||
|
&mcux_dac12_config_##n, \
|
||||||
|
POST_KERNEL, CONFIG_DAC_INIT_PRIORITY, \
|
||||||
|
&mcux_dac12_driver_api);
|
||||||
|
|
||||||
|
DT_INST_FOREACH_STATUS_OKAY(MCUX_DAC12_INIT)
|
28
dts/bindings/dac/nxp,dac12.yaml
Normal file
28
dts/bindings/dac/nxp,dac12.yaml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# Copyright (c) 2020 Henrik Brix Andersen <henrik@brixandersen.dk>
|
||||||
|
# Copyright (c) 2025 PHYTEC America LLC
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
description: NXP MCUX DAC12
|
||||||
|
|
||||||
|
compatible: "nxp,dac12"
|
||||||
|
|
||||||
|
include: dac-controller.yaml
|
||||||
|
|
||||||
|
properties:
|
||||||
|
reg:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
voltage-reference:
|
||||||
|
type: int
|
||||||
|
required: true
|
||||||
|
description: DAC voltage reference select
|
||||||
|
|
||||||
|
buffered:
|
||||||
|
type: boolean
|
||||||
|
description: Enable output buffer
|
||||||
|
|
||||||
|
"#io-channel-cells":
|
||||||
|
const: 1
|
||||||
|
|
||||||
|
io-channel-cells:
|
||||||
|
- output
|
Loading…
Add table
Add a link
Reference in a new issue