-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: dac: Add drivers for TI DAC family X311 on SPI bus #90811
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
base: main
Are you sure you want to change the base?
Conversation
|
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
martinjaeger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review. I missed this PR. In the future, just feel free to ping the maintainer if you don't get any feedback after a few weeks.
See my comments below.
drivers/dac/dac_tx311.c
Outdated
| if ((config->resolution > DACX311_MAX_RESOLUTION) || | ||
| (config->resolution < DACX311_MIN_RESOLUTION)) { | ||
| LOG_ERR("Unsupported resolution %d", config->resolution); | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| if (config->power_down_mode > 3) { | ||
| LOG_ERR("Unsupported power mode %d", config->power_down_mode); | ||
| return -ENOTSUP; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could already be checked at build-time with BUILD_ASSERT macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adjusted the code to use two BUILD_ASSERT macros. The check on the resolution value was removed, since it is "hard-coded" for each variant (see end of file).
drivers/dac/dac_tx311.c
Outdated
| if (1000 * config->max_freq_khz < config->bus.config.frequency) { | ||
| LOG_ERR("SCLK frequency too high: '%d' Hz", config->bus.config.frequency); | ||
| return -ENOTSUP; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can't check this at build-time. But can we put it into a driver init function, so that it's already checked before entering main?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an init function, but this check became a BUILD_ASSERT macro since it represents a chip specific max frequency that is not changing.
drivers/dac/dac_tx311.c
Outdated
| /* Set bit resolution for this chip variant */ | ||
| data->resolution = config->resolution; | ||
|
|
||
| /* Set the power mode (shifted to upper bits) */ | ||
| data->power_down_mode = FIELD_PREP(BIT_MASK(2) << DACX311_MAX_RESOLUTION, | ||
| config->power_down_mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also go into a driver init function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, and changed the code.
drivers/dac/dac_tx311.c
Outdated
| data->configured |= BIT(channel_cfg->channel_id); | ||
|
|
||
| /* Set bit resolution for this chip variant */ | ||
| data->resolution = config->resolution; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be like this?
| data->resolution = config->resolution; | |
| data->resolution = channel_cfg->resolution; |
And in this case, we should also check if the desired resolution is supported by the chip.
|
|
||
| struct dacx311_config { | ||
| struct spi_dt_spec bus; | ||
| uint8_t resolution; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is actually the max resolution supported by the chip, but we can configure it for lower resolution, right? Should we then name it max_resolution to make the meaning more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each chip variant has a fixed resolution. The entry in this struct is present in order to use the same code logic for the different chip variants. This value is different for each variant.
|
Please also add the driver to |
|
@martinjaeger : Thanks for the review! I will first resolve the merge conflict and then work on your comments. |
a048710 to
cb4da7e
Compare
|
cb4da7e to
d69d758
Compare
|
martinjaeger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My previous comments were not addressed yet.
d69d758 to
1bb6885
Compare
|
Did not have time to work in this over the last months. Hopefully, I can in the next weeks. |
1bb6885 to
fe4d7b1
Compare
Working on this, next. |
fe4d7b1 to
c25cc8c
Compare
Add shared code in 'dac_tx311.c' and configuration files. Support power mode bits via configuration. Signed-off-by: Andreas Wolf <[email protected]>
c25cc8c to
dc0dc90
Compare
|



Summary
This PR submits the device driver code for the Texas Instrument chip family DAC N311, with N indicating the resolution (see below).
These chips provide a single output channel and support "power mode" selection by reserving the two MSB values for this.
There is a single "register" that is updated with each 16-bit write to the chip via SPI.
Code Changes
The driver was code was modeled after DAC drivers for other chip families, where different resolutions are supported.
Kconfig.tx311enables the driver when a matching entry is added to the device tree;dac_tx311.c) processes the device tree to set the correct resolution value;power-down-modeto set the power mode bits.Tests
Normal Mode
This driver was developed to control the TI 6311 DAC chip that is part of an external PCB. The SPI bus was connected to a Raspberry Pico W and a sample program was created to generate a "saw tooth" signal with a period of a few seconds and the power mode set to "normal".
A oscilloscope was connected to the
Voutpin of the chip to confirm the full voltage range, 0 to 3.3 V, is produced.Resistor to GND Mode
The power mode was set to "power-down-100k" and the test program was recompiled. The DAC output shows no saw-tooth signal.