-
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: API change of macros ADC_LINE and DAC_LINE #10504
Conversation
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.
NAK as currently written.
I think this does not fit the intent of ADC_LINE(x)
and DAC_LINE(x)
. The documentation is not clear, but I think that based on the usage in e.g. tests/periph_adc
and tests/periph_dac
that these macros are intended to map an ordinal to the MCU specific encoding of adc_t line
or dac_t line
(which is internally encoded as a tuple of device and pin). If there was an equivalent macro for periph/gpio
it would the inverse function of GPIO_PIN(x,y)
.
The documentation for ADC_LINE(x)
and DAC_LINE(x)
definitely needs some improvement to clarify what it actually does. Also, I think that an equivalent of GPIO_PIN(x,y)
for periph/adc
and periph/dac
could be added, just not in this way.
Any suggestion? For me, the intent of the So why not to say, device 0 is the MCU and all other devices are extensions. Maybe, @haukepetersen could clearify that. |
I think that another pair of macros could be added that are the inverse functions of We should see what @haukepetersen has to say first though. |
Sorry for only seeing this now (don't have much time to spare for periph stuff lately)... I don't like this change, as it defeats the 'line' concept: the idea is, to have from a users perspective only a set of logical lines. It is up to the driver implementation and board configuration, to map these lines onto E.g. look at #7277 (a little outdated, but can't find any other example right now): here some different channels on different ADC devices are mapped onto logical lines like this: static const adc_conf_t adc_config[] = {
 { .pin = GPIO_PIN(PORT_A, 3), .dev = ADC_1, .chan = 3 },
 { .pin = GPIO_PIN(PORT_C, 0), .dev = ADC_1, .chan = 10 },
 { .pin = GPIO_PIN(PORT_C, 3), .dev = ADC_1, .chan = 13 },
 { .pin = GPIO_PIN(PORT_F, 3), .dev = ADC_3, .chan = 9 },
 { .pin = GPIO_PIN(PORT_F, 5), .dev = ADC_3, .chan = 15 },
 { .pin = GPIO_PIN(PORT_F, 10), .dev = ADC_3, .chan = 8 }
 }; Remember, that this config is CPU specific to STM32 devices and it is up to the CPU to define a config format that makes sense... In general I am pretty convinced that the way forward with the |
That's okay for me. The concept behind the was not really clear to me from the documentation. Therefore I were asking for clarification. My intention to introduce ADC_LINE(x,y) was simply to have a consistent way of how channels are addressed when we have not only onboard ADC devices but also external ADC devices. The question arose in conjunction with the PR #10527 and PR #10512 when I was looking for a way to determine the total number of existing channels and to iterate over all these channels. for (int i = 0; i < ADC_DEV_NUMOF; i++) {
for (int j = 0; j < adc_channels(ADC_DEV(x)); j++) {
adc_sample(ADC_LINE(x, y), res);
}
}
Without having /* first the onboard channels */
for (int i = 0; i < ADC_NUMOF; i++) {
adc_sample(ADC_LINE(x), res);
}
/* and then the channels provided by external devices */
for (int i = 0; i < ADC_EXT_NUMOF; i++) {
for (int j = 0; j < adc_channels(ADC_EXT_LINE(i,0)); j++) {
adc_sample(ADC_EXT_LINE(i, j), res);
}
} The definition of a |
There was a suggestion from @ZetaR60 for dealing with |
One further question about the existing interface I have is: How should the |
@haukepetersen Just to be clear about what you said: Does |
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. For DAC devices another solution is required. |
Contribution description
This PR changes the definition of the
ADC_LINE
andDAC_LINE
macros to make them more consistent withGPIO_PIN
macro, andThe need to change them came up during the development of the extension APIs for ADC and DAC extension API as required by issue #9582 and already realized for GPIO in PR #9860.
According to the documentation of ADC and DAC
An ADC line in this context is a tuple consisting out of a hardware ADC device (an ADC functional unit on the MCU) and an ADC channel connected to pin.
Similar to the ADC driver interface (ADC), the DAC interface uses the concept of lines, corresponds to a tuple of a DAC device and a DAC output channel.
a line refers to a channel
y
of devicex
. Thus, the*_LINE
macros should be defined with two parametersx
andy
, the device and the channel. According to the default definition ofGPIO_PIN
, which uses the same concept, the definitions should look like:The channels of the MCU, if there are, would then be device 0.
Changing the macros in this way would it make possible to define the
ADC_EXT_LINE
andDAC_EXT_LINE
macros in the extension APIs in a consistent way with GPIO extension API wherex
refers the extension device andy
the channel.Testing procedure
The following test applications have to pass on any board that support ADC and DAC peripherals:
Issues/PRs references
#9582 Issue with proposal for peripheral extension API
#9860 and #9958 Implementation of GPIO extension API