-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/gd32v: add periph_adc support #19188
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
858c53d
to
38055cb
Compare
This needs a rebase |
38055cb
to
15fd668
Compare
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.
looks good, please squash directly
cpu/gd32v/periph/adc.c
Outdated
/** | ||
* @brief Maximum allowed ADC clock speed | ||
*/ | ||
#define MAX_ADC_SPEED (MHZ(14)) |
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.
#define MAX_ADC_SPEED (MHZ(14)) | |
#define MAX_ADC_SPEED MHZ(14) |
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.
That's just a leftover from code for STM32F1 which was (14000000U)
.
cpu/gd32v/periph/adc.c
Outdated
|
||
static inline ADC0_Type *dev(adc_t line) | ||
{ | ||
return (ADC0_Type *)(ADC0_BASE + (adc_config[line].dev << 10)); |
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 think that's a bit optimistic if more family members are added, there is no grantee the ADCs will all be continuous in memory.
return (ADC0_Type *)(ADC0_BASE + (adc_config[line].dev << 10)); | |
switch (adc_config[line].dev) { | |
case 0: | |
return ADC0_BASE; | |
#if ADC_DEVS > 1 | |
case 1: | |
return ADC1_BASE; | |
#endif | |
#if ADC_DEVS > 2 | |
case 2: | |
return ADC2_BASE; | |
#endif | |
default: | |
assert(0); | |
return NULL; | |
} |
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.
That's the way how STM32F1 dealt with it. The question is whether there will ever be more families for which this code could be used. It is more likely that other families will need their own ADC low level drivers like for STM32. At the moment I wouldn't allow the case ADC_DEVS > 2
.
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 is more likely that other families will need their own ADC low level drivers like for STM32
The STM32 families don't all need their own ADC driver, they pretty much all use the same ADC IP. The ADC driver mess on STM32 is due to a lack of cleanup - and that has been always postponed with the new ADC API on the horizon.
cpu/gd32v/periph/adc.c
Outdated
if (dev(line) != ADC0) { | ||
return -3; | ||
} |
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.
if (dev(line) != ADC0) { | |
return -3; | |
} | |
assert(dev(line) == ADC0); |
since that'd be an error in the board config, let this fail loudly.
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.
That's just the code from STM32F1. Using assert
here makes perfect sense, especially since the API does not define -3 as a possible return value. In fact, I had already thought about an assert
.
3fa77ab
to
5448969
Compare
bors merge |
5448969
to
e6bf881
Compare
e6bf881
to
31e778b
Compare
31e778b
to
3be68cb
Compare
After the failed last run due to the |
bors merge |
🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
19188: cpu/gd32v: add periph_adc support r=gschorcht a=gschorcht ### Contribution description This PR provides the `periph_adc` support and is one of a bunch of follow up PRs that complete the peripheral drivers for GD32VF103. This PR depends on PR #19170 and includes this PR to be compilable since includes the ADC configuration also for Sipeed Longan Nano board. ### Testing procedure `tests/periph_adc` should work on any GD32VF103 board. ### Issues/PRs references Depends on PR #19170 Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Build failed: |
3be68cb
to
57463cb
Compare
bors merge |
Build succeeded: |
Contribution description
This PR provides the
periph_adc
support and is one of a bunch of follow up PRs that complete the peripheral drivers for GD32VF103.This PR depends on PR #19170 and includes this PR to be compilable since includes the ADC configuration also for Sipeed Longan Nano board.
Testing procedure
tests/periph_adc
should work on any GD32VF103 board.Issues/PRs references
Depends on PR #19170