-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: main
Are you sure you want to change the base?
Conversation
b0f99c9
to
35a883d
Compare
drivers/adc-dac/ad5592r/ad5593r.h
Outdated
#define AD5593R_MODE_GPIO_READBACK (6 << 4) | ||
#define AD5593R_MODE_REG_READBACK (7 << 4) | ||
|
||
#define STOP_BIT 1 |
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.
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
drivers/adc-dac/ad5592r/ad5593r.h
Outdated
#define AD5593R_MODE_REG_READBACK (7 << 4) | ||
|
||
#define STOP_BIT 1 | ||
#define RESTART_BIT 0 |
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.
same for RESTART_BIT
35a883d
to
bee6889
Compare
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 |
bee6889
to
7867222
Compare
if (!dev) | ||
return -1; | ||
|
||
ret = ad5592r_base_reg_read(dev, AD5592R_REG_PD, &temp_reg_val); |
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.
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
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.
Updated with these changes now
7867222
to
12ede21
Compare
if (adc_range) | ||
status |= AD5592R_REG_CTRL_ADC_RANGE; | ||
else | ||
status &= ~AD5592R_REG_CTRL_ADC_RANGE; |
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.
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. |
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 wouldn't name it status, rename it to enable
, then it's even more clear what it does
also, check out cppcheck and astyle CI results |
b195a94
to
0465a0e
Compare
Fixed all the review comments and the checks are passing now |
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.
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.
drivers/adc-dac/ad5592r/ad5592r.c
Outdated
|
||
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, |
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.
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 |
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.
Unrelated change (may have added a white space by mistake).
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 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; |
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.
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?
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.
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.
drivers/adc-dac/ad5592r/ad5593r.c
Outdated
|
||
dev = (struct ad5592r_dev *)no_os_malloc(sizeof(*dev)); |
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.
no_os_calloc()
enum ad559xr_range adc_range; | ||
enum ad559xr_range dac_range; | ||
bool adc_buf; | ||
uint16_t cached_dac[8]; |
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'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()
.
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.
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.
0465a0e
to
b2d8cdd
Compare
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]>
b2d8cdd
to
bcc4e0f
Compare
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. |
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
PR Checklist