-
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
periph/adc: support for ADC extension API #10527
Conversation
4d914a1
to
532915e
Compare
9ce8525
to
bb27217
Compare
adc_* functions are changed to be inline functions for redirection of calls either to low level or to extenstion API functions dependent on the line identifier. Macro definitions for extension API added. Function to get the number of ADC channels added.
adc_init and adc_sample functions renamed to adc_init_ll and adc_sample_ll
adc_channels renamed to adc_config to avoid conflicts with new adc_channels function
adc_channels renamed to adc_config to avoid conflicts with new adc_channels function
contains the extension redirection and not support function device
1b6d95f
to
7a4b50b
Compare
@ZetaR60 I have tried the approach you proposed in #9582 (comment) for the ADC extension API in a separate branch. This branch creates the defines #ifndef ADC_NUMOF_LL
#define ADC_NUMOF_LL (0U)
#endif
#define ADC_NUMOF (ADC_NUMOF_LL + ADC_EXT_NUMOF)
#define ADC_LINE(x) (x < ADC_NUMOF_LL \
? ADC_LINE_LL(x) \
: ADC_EXT_LINE(x - ADC_NUMOF_LL)) and an example of an ADC extension configuration with 4 ADC extension devices as following: #define ADC_EXT_DEV0_NUMOF (4)
#define ADC_EXT_DEV1_NUMOF (2)
#define ADC_EXT_DEV2_NUMOF (8)
#define ADC_EXT_DEV3_NUMOF (0)
#define ADC_EXT_DEV0_OFFSET (0)
#define ADC_EXT_DEV1_OFFSET (ADC_EXT_DEV0_OFFSET + ADC_EXT_DEV0_NUMOF)
#define ADC_EXT_DEV2_OFFSET (ADC_EXT_DEV1_OFFSET + ADC_EXT_DEV1_NUMOF)
#define ADC_EXT_DEV3_OFFSET (ADC_EXT_DEV2_OFFSET + ADC_EXT_DEV2_NUMOF)
#define ADC_EXT_NUMOF (ADC_EXT_DEV0_NUMOF + \
ADC_EXT_DEV1_NUMOF + \
ADC_EXT_DEV2_NUMOF + \
ADC_EXT_DEV3_NUMOF)
#define ADC_EXT_LINE(x) (x < ADC_EXT_DEV1_OFFSET \
? ADC_EXT_LINE_REV(0, (x - ADC_EXT_DEV0_OFFSET)) \
: (x < ADC_EXT_DEV2_OFFSET \
? ADC_EXT_LINE_REV(1, (x - ADC_EXT_DEV1_OFFSET)) \
: (x < ADC_EXT_DEV3_OFFSET \
? ADC_EXT_LINE_REV(2, (x - ADC_EXT_DEV2_OFFSET)) \
: ADC_EXT_LINE_REV(3, (x - ADC_EXT_DEV3_OFFSET))))) With this approach, it is indeed possible to iterate from 0 to If you would like to take a look you will find the code at |
@gschorcht I have attempted to address this in #9582 |
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. |
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. |
This PR is closed in favor of PR #13247 which should allow to integrate external ADC devices. |
Contribution description
This is an implementation of the extension API as proposed in #9582 for ADC extensions. It corresponds to the implementation of the GPIO extension API in #9860 and #9958. The PR contains the following contributions:
adc_*_ll
indrivers/include/periph.h
.adc_*
functions to redirect a function call either to the low level functionsadc_*_ll
or to theadc_ext_*
function provided by an ADC extension device driver.adc_channels
which returns the number of channels of a device, in case of MCU channels simplyADC_NUMOF
. This new function makes it possible to get the information from a certain device how many channels it has and allows to iterate over the all channels of all devices.adc_*_ll
for all CPUs that support ADC channels.adc_channels
was renamed toadc_config
to solve conflicts with the new functionadc_channels
.The ADC extension API does not require feature
periph_adc
which makes it possible to extend boards that do not provide ADC capabilities by the MCU by external ADC modules.Testing procedure
A test case is provided that implements a soft-driver for the ADC extension interface. The test case uses this driver to confirm that interception and redirection of the API call are working properly. This has been tested and is working properly on esp8266-esp-12x, esp32-wroom-32 and arduino-mega2560.
To test only the ADC extension API use
To test the ADC extension API together with internal ADC channels use
In that case feature
periph_adc
is required of course.Issues/PRs references
Implements #9582
Corresponds to #9860 and #9958
The changes in the
makefiles/pseudomodules.mk
and indrivers/Makefile.include
made to get it working are the same as in #9958. These changes might be removed once #9958 is merged.