-
Notifications
You must be signed in to change notification settings - Fork 8.2k
[RFC][DNM] drivers: adc: new API proposal #6176
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6176 +/- ##
=======================================
Coverage 58.59% 58.59%
=======================================
Files 464 464
Lines 47483 47483
Branches 8796 8796
=======================================
Hits 27822 27822
Misses 15823 15823
Partials 3838 3838Continue to review full report at Codecov.
|
tbursztyka
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.
samples value size will depend on resolution, so 8, 16, 24, 32, 64...?
Instead, I would make in void *, and depending on the resolution, the driver would fill it in accordingly.
Only thing would be that driver would check the buffer length vs resolution at first.
Just thinking out loud, I don't have much experience in ADCs (besides the awful adc_ti_adc108s102 I did back in the days)
include/adc.h
Outdated
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 description?
include/adc.h
Outdated
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.
so 0 would mean bare result?
include/adc.h
Outdated
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.
ticks is hw dependent. Wouldn't it be better to work on µs or ms? (Well, µs is only supported through busy wait loop)
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'm torn on this one. It's a pain to do the conversion in the driver and often inefficient due to divide operations, but I can see the value in having common units like us or ms for the application.
galak
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.
I get why adc_channel_setup() takes a dev pointer and the others dont, but the inconsistency is unfortunate.
include/adc.h
Outdated
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 should add defines & macros to access the fields your are defining.
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.
Do these things ever change on a per-channel basis? They don't on NXP devices
include/adc.h
Outdated
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.
Wonder if sample_cfg should be separated from sample_results
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 would be more consistent with spi to separate them
include/adc.h
Outdated
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 comment seems incorrect.
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 should document the following - is it required to call adc_channel_setup before adc_read*?
include/adc.h
Outdated
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.
any reason channel_id isn't in adc_channel_cfg?
include/adc.h
Outdated
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.
6 bits for the acquisition time looks a bit short, as 63 microseconds may be too small if you sample a high-impedance source or your ADC runs on a very slow clock.
On the other hand, 1us is rather high if you go high speed. For the STM32L4A6, I can setup Tacq as low as 30 nanoseconds.
So maybe we need a more flexible approach to specify the conversion time?
include/adc.h
Outdated
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.
s16_t is not enough, I used external 24-bit ADC in the past. And you need more bits when doing oversampling.
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.
Agreed
|
A missing feature is the ability to setup the trigger source. Here a software trigger is implied, but we have to use hardware triggers sometime. I do not see a straightforward way to setup it as it is usually hardware dependant, but maybe some kind of driver-specific API (like uart_drv_cmd() or Linux ioctl) ? |
|
I will be on vacation all next week. I'll address all the comments (already existing ones and any new that may appear, and are welcome) when I'm back. |
MaureenHelm
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.
A missing feature is the ability to setup the trigger source. Here a software trigger is implied, but we have to use hardware triggers sometime. I do not see a straightforward way to setup it as it is usually hardware dependant,
Agreed
include/adc.h
Outdated
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 would be more consistent with spi to separate them
include/adc.h
Outdated
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'm torn on this one. It's a pain to do the conversion in the driver and often inefficient due to divide operations, but I can see the value in having common units like us or ms for the application.
include/adc.h
Outdated
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.
Agreed
include/adc.h
Outdated
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.
Do these things ever change on a per-channel basis? They don't on NXP devices
include/adc.h
Outdated
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.
Please add the dev pointer argument back and remove it from the adc_config struct
0fdcbc6 to
3b03667
Compare
|
Tried to address gathered feedback, to some extent at least. |
include/adc.h
Outdated
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.
tiny left over from previous PR push
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.
Right. I haven't tried asynchronous part yet. That's why I haven't got any compile error for this.
tbursztyka
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.
tiny changes requested. (mostly on struct alignment)
include/adc.h
Outdated
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.
to be consistent with other APIs, create function typedefs for the functions first
include/adc.h
Outdated
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 would reorder the attributes so these 2 u8_t would be at the end of the struct.
include/adc.h
Outdated
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 would move this attribute at the end of the struct
include/adc.h
Outdated
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.
move these 2 attributes at the beginning of the struct
include/adc.h
Outdated
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.
Do they need to be unique? (no duplicates)
include/adc.h
Outdated
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.
Maybe this should be channel_count? It's a little confusing to have "samplings" and "samples" be different things
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 simplified the structure and used a bit-mask for specifying the channels to be included in the sampling. The previous proposal with the channel_ids pointer and sample_count was too confusing and probably troublesome in implementation (regarding duplicates, as you pointed out in the comment above, and order of the channels).
My idea was to define a sampling as reading of samples from one or more channels. Such samplings can be then arranged in sequences with optional triggers. I added more comments in the header file and changed some names to hopefully present the idea clearer. I am open to change the terminology to a better one. English is not my native language so the names I propose may not be the best (or even good enough) ones.
include/adc.h
Outdated
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.
Are the triggers one-off or recurring (such as from a hardware timer)? Can you explain the difference between the DELAY triggers and the SAMPLE_RATE trigger?
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 need to work more on these. The rough idea, just to start with something, was that the DELAY triggers will be done in software (with some sleeping or busy loop before doing next sampling) and the SAMPLE_RATE one (the name was rather a place holder) by hardware, e.g. some timer providing means to achieve accurate sampling intervals.
include/adc.h
Outdated
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.
A sampling is a group of channels?
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.
Yes. I added better, hopefully, descriptions of the structure and its fields.
include/adc.h
Outdated
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.
Are these numbers non-integer gain factors? We will need more values in the enum, as the nxp adc supports gain factors of {1,2,4,8,16,32,64}
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.
Yes, these are fractional factors. I added proper comments, and renamed "prescaling" to "gain".
3b03667 to
e12acbf
Compare
|
Updated the proposal according to the recent suggestions. Added more descriptions to make things clearer. |
e12acbf to
433bf0b
Compare
This is a proposal of a new API for ADC driver to address reported issues (zephyrproject-rtos#3980) and clarify confusing things, like the buffer length. Asynchronous requests and channel configuration were added as well. Signed-off-by: Andrzej Głąbek <[email protected]>
433bf0b to
d279047
Compare
|
I updated the proposal once more. I got rid of the |
Updated API calls and added a few new test cases so that the new possibilities of the API could be presented and checked. Signed-off-by: Andrzej Głąbek <[email protected]>
d279047 to
c171e53
Compare
|
Seems fine to me. |
|
Replaced by #7691. |
This is an initial proposal of a new API for the ADC driver, so that we could start discussion and conclude what is actually needed in the API, and what will be convenient to use.
I tried to keep similarity with the new SPI API (#5921).
A few questions/doubts that I have:
s16_tfor sample values?@nashif @carlescufi @tbursztyka @MaureenHelm @andrewboie @galak