Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: dac: dacx3608: add broadcast register for synchronized output #74633

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions drivers/dac/dac_dacx3608.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ static int dacx3608_write_value(const struct device *dev, uint8_t channel,
uint16_t regval;
int ret;

if (channel > DACX3608_MAX_CHANNEL - 1) {
const bool brdcast = (channel == DAC_CHANNEL_BROADCAST) ? 1 : 0;

if (!brdcast && (channel > DACX3608_MAX_CHANNEL - 1)) {
LOG_ERR("Unsupported channel %d", channel);
return -ENOTSUP;
}

if (!(data->configured & BIT(channel))) {
/*
* Check if channel is initialized
* If broadcast channel is used, check if any channel is initialized
*/
if ((brdcast && !data->configured) || (!(data->configured & BIT(channel)))) {
LOG_ERR("Channel %d not initialized", channel);
return -EINVAL;
}
Expand All @@ -157,7 +163,9 @@ static int dacx3608_write_value(const struct device *dev, uint8_t channel,
regval = value << 2;
regval &= 0xFFFF;

ret = dacx3608_reg_write(dev, DACX3608_REG_DACA_DATA + channel, regval);
const uint8_t reg = brdcast ? DACX3608_REG_BRDCAST : DACX3608_REG_DACA_DATA + channel;

ret = dacx3608_reg_write(dev, reg, regval);
if (ret) {
LOG_ERR("Unable to set value %d on channel %d", value, channel);
return -EIO;
Expand Down
6 changes: 6 additions & 0 deletions include/zephyr/drivers/dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ extern "C" {
* @{
*/

/**
* @brief Broadcast channel identifier for DACs that support it.
* @note Only for use in dac_write_value().
*/
#define DAC_CHANNEL_BROADCAST 0xFF

/**
* @brief Structure for specifying the configuration of a DAC channel.
*/
Expand Down
Loading