-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[PoC] drivers/adc_ng: Common ADC API and implementation #13248
base: master
Are you sure you want to change the base?
Conversation
4b40748
to
f046143
Compare
FEATURES_PROVIDED += arch_8bit | ||
FEATURES_PROVIDED += arch_avr8 | ||
FEATURES_PROVIDED += atmega_pcint0 | ||
FEATURES_PROVIDED += periph_adc_ng |
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 be defined in board definitions. Otherwise, a board is not able to use only an external ADC if the feature is provided by the MCU because of the following condition in adc_ng.c
:
Line 24 in 4661b92
#if (ADC_NG_NUMOF == 1) && defined(MODULE_PERIPH_ADC_NG) |
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.
Features and modules are conceptional not the same, even though for most (all?) features with periph_%
a module with the same name exists and is automatically used, if the corresponding feature is used.
So: Just because the feature is provided, it is not automatically used. The FEATURES_OPTIONAL += periph_adc_ng
in drivers/Makefile.dep
that is done when adc_ng
is used would indeed pull that feature (and therefore) the corresponding module in. But that could be prevented by FEATURES_BLACKLIST += periph_adc_ng
.
I'm not sure if this is super elegant. Maybe it would be better to provide an adc_ng_default
pseudo-module that would pull in all ADC-NG backends supported by a board.
The PoC was also updated to reflect the current state of the API. But I didn't manage to apply all feedback yet; I will do so tomorrow (hopefully) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
One thing I noticed is that there is no provision to sample more than one channel per ADC without re-initializing it. The channel is selected in |
That's a valid point. There could be a footgun in that the ADC might not be able to switch between channels for a given configuration it is in. E.g. many ADCs have a channel that is wired to an internal NTC for temperature measurements. I read at least in one datasheet that stated one "must use" a particular reference voltage for it. Likely the result of none-compliance are just a high level of noise or so, but I'm not sure. I guess a driver could have |
I spend some time thinking about this. I do not want to drop the channel argument from the initialization function. Some ADCs enable the ADC MUX when they are powered up no matter what, and some ADC MUXs can only select a valid input. In this case, the driver would have to blindly guess what channel to connect to. But not every channel is compatible with all settings, so this "default channel selection" can be a bit involved. If however the caller has to directly pass the channel it want to get the first sample from as argument, things are easy for the driver. I also don't like adding a channel argument to the sample function. I would like to keep the function to retrieve a sample as trivial as possible. For ADCs that do not support DMA (or drivers that have not implemented it) requesting samples in a busy loop is the only option to get samples as fast as possible. Keeping this function trivial can increase the sample rate a bit. The sample rate will be particularly affected if How about this instead: Adding a dedicated function to swap the channel while keeping the ADC running? This should still be faster than re-initializing the ADC when a channel needs to be changed, but we can afford to pay for an |
I think this could be a good idea. I was playing around with the SPI driver and noticed it has a use pattern where you must call |
This API aims to provided an alternative to the periph ADC API with the following improvements: - Support for multiple ADC devices (both external and peripheral ADCs) - Support for selecting the reference voltage - Convenience functions to convert into meaningful physical units It is written to allow coexistence with the existing periph ADC API.
Implemented the periph/adc API on top of the adc_ng API. This allows application using the periph ADC API to also use external ADCs.
Otherwise waiting for IRQs during periph_init() results in a deadlock.
Can this be a draft? |
Contribution description
This PR depends on and includes #13247. It adds:
Testing procedure
The test application can be used with an ATmega powered board. It drops you in a shell that allows you to test all of the functions of the ADC NG API exposed as separate shell commands. (Currently almost 3KiB RAM are used due to constant data being placed in RAM on AVR. Using
PROGMEM
could improve the situation to allow it running e.g. on the Arduino UNO; but that is out of scope.)Issues/PRs references
#13247