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:adc-dac:ad5592r: Driver Enhancement #2414

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

D-Disha
Copy link
Collaborator

@D-Disha D-Disha commented Jan 16, 2025

  1. Added driver apis for adc range, dac range, power down,set internal reference and set adc buffer to the base driver.
  2. Added API to enable busy indicatir on AD5592r
  3. Removed static for spi nop API for visibilty.
  4. Moved some macros from ad5593.c to header file for visibility.

Pull Request Description

Please replace this with a detailed description and motivation of the changes.
You can tick the checkboxes below with an 'x' between square brackets or just check them after publishing the PR.
If this PR contains a breaking change, list dependent PRs and try to push all related PRs at the same time.

PR Type

  • [] Bug fix (change that fixes an issue)
  • New feature (change that adds new functionality)
  • Breaking change (has dependencies in other repos or will cause CI to fail)

PR Checklist

  • I have followed the Coding style guidelines
  • I have performed a self-review of the changes
  • I have commented my code, at least hard-to-understand parts
  • I have build all projects affected by the changes in this PR
  • I have tested in hardware affected projects, at the relevant boards
  • I have signed off all commits from this PR
  • I have updated the documentation (wiki pages, ReadMe etc), if applies

#define AD5593R_MODE_GPIO_READBACK (6 << 4)
#define AD5593R_MODE_REG_READBACK (7 << 4)

#define STOP_BIT 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh i would drop this STOP_BIT, it's pretty clear what it does, no need to have a macro for it

alternatively, prefix it, because at some point there is going to be a name clash

#define AD5593R_MODE_REG_READBACK (7 << 4)

#define STOP_BIT 1
#define RESTART_BIT 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for RESTART_BIT

@D-Disha
Copy link
Collaborator Author

D-Disha commented Jan 20, 2025

Change log: Added power down configuration to init sequence as well. Initialized dev->num_of_channels and ldac mode as it is used by the driver. Corrected typo in commit message

@D-Disha D-Disha requested a review from buha January 20, 2025 09:40
if (!dev)
return -1;

ret = ad5592r_base_reg_read(dev, AD5592R_REG_PD, &temp_reg_val);
Copy link
Contributor

@buha buha Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of this read - process - write sequence that you repeat in all these functions you could have a function named ad5592r_base_reg_update which does the sequence once and then you call it however many times needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with these changes now

if (adc_range)
status |= AD5592R_REG_CTRL_ADC_RANGE;
else
status &= ~AD5592R_REG_CTRL_ADC_RANGE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can rewrite this whole part more compact as:

uint16_t status = adc_range ? AD5592R_REG_CTRL_ADC_RANGE : 0;

or even ditch the status local variable and put it all inline in the function call, although that's maybe a bit too much

* Set ADC Buffer for the device
*
* @param dev - The device structure.
* @param status - Status to enable/disable adc buffer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wouldn't name it status, rename it to enable, then it's even more clear what it does

@buha
Copy link
Contributor

buha commented Jan 22, 2025

also, check out cppcheck and astyle CI results

@D-Disha D-Disha force-pushed the ad559xr-updates branch 3 times, most recently from b195a94 to 0465a0e Compare January 22, 2025 11:27
@D-Disha
Copy link
Collaborator Author

D-Disha commented Jan 23, 2025

also, check out cppcheck and astyle CI results

Fixed all the review comments and the checks are passing now

@D-Disha D-Disha requested a review from buha January 23, 2025 04:52
Copy link
Contributor

@CiprianRegus CiprianRegus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments from my side. Also, for future contributions like this one, it would be worth splitting your work into multiple commits, since the changes are not directly related to each other.


temp_reg_val = enable ? AD5592R_REG_GPIO_OUT_EN_ADC_NOT_BUSY : 0;

ret = ad5592r_base_reg_update(dev, AD5592R_REG_GPIO_OUT_EN, temp_reg_val,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return directly

@@ -19,7 +19,7 @@
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AS IS AND ANY EXPRESS OR
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AS IS AND ANY EXPRESS OR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change (may have added a white space by mistake).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy pasted those lines again from the preexisting files. Not sure what is wrong here. It still shows up in the diff

if (ret < 0)
return ret;

dev->adc_range = adc_range;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually avoid caching register values at the driver level, since the value could be changed by a direct register access. There are some cases where you may want to do that to avoid recurrent register reads, but it doesn't look like it applies here. Is there a reason for which you may want these values to be stored?

Copy link
Collaborator Author

@D-Disha D-Disha Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adc and dac range are runtime attributes in the IIO firmware where a user can change the values on the fly. This in turn updates the scale value of the device.

Hence, I considered it best to have it as a device member instead of doing multiple reads.
I have also had it as a part of init_param member as well so the user can easily update the ranges compile time as well if needed.


dev = (struct ad5592r_dev *)no_os_malloc(sizeof(*dev));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no_os_calloc()

enum ad559xr_range adc_range;
enum ad559xr_range dac_range;
bool adc_buf;
uint16_t cached_dac[8];
Copy link
Contributor

@CiprianRegus CiprianRegus Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say having initial values for the DAC output is a bit awkward. There is already ad5592r_write_dac(), so you could use that in the application after ad5592r_init().

Copy link
Collaborator Author

@D-Disha D-Disha Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cached_dac was present as a device member in the existing no-os drivers already. Having it as a part of init_param as well will help user change the dac output values compile time through our user configuration file.

1. Added driver apis for reg updtae,adc range, dac range, power down,set
internal reference and set adc buffer to the base driver.
2. Added API to enable busy indicator on AD5592r
3. Removed static for spi nop API for visibilty.
4. Moved some macros from ad5593.c to header file for visibility.
5. Renamed start and stop macros.

Signed-off-by: Disha D <[email protected]>
@buha
Copy link
Contributor

buha commented Jan 27, 2025

As @CiprianRegus said, please split work into multiple commits in the future. The reason is, if one is bad and gets merged, we can revert it and keep the other good ones for users to benefit. So if you feel like listing 5 items in the commit message, you probably have to split the commit into 5 commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants