-
Notifications
You must be signed in to change notification settings - Fork 182
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
RFC: add support for ADC #51
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.
Thanks for the PR, most of it looks great!
I added some comments that are mostly nitpicks but would be nice if you could address :)
Thanks for review, I will address comments and re-submit. Let me know if you are OK with multiple force-push updates for the same PR. |
@geomatsi Feel free to force-push away. |
Default value is the slowest possible ADC clock PCLK2 / 8. This is to make sure that 14MHz threshold is not exceeded. Meanwhile ADC clock is configurable, so its frequency may be tweaked to meet certain practical needs, e.g. speed vs power saving choice. User specified value is approximated using supported prescaler values 2/4/6/8. Invalid specified frequency (e.g. too high) will result in the slowest possible ADC clock PCLK2 / 8. Example: let p = stm32::Peripherals::take().unwrap(); let mut flash = p.FLASH.constrain(); let mut rcc = p.RCC.constrain(); let clocks = rcc.cfgr.adcclk(2.mhz()).freeze(&mut flash.acr); Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
Implement adc embedded_hal traits Channel and OneShot for ADC1 on stm32f10x chips. Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
Some stm32f10x chips support multiple ADC blocks. For instance, stm32f103 medium-density chips has two ADC blocks. This commit makes use of rust macros to provide framework that supports description of multiple ADC blocks. The following ADC blocks are enabled for now: - stm32f100: ADC1 - stm32f101: ADC1 - stm32f103: ADC1, ADC2 Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
Add ADC example that covers the following functionality: - ADC clock configuration - making use of the only available ADC block on stm32f10[01] - making use of both available ADC blocks on stm32f103 Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
Hi all, This PR has been updated. Here is a brief summary of changes.
Regards, |
Hi @therealprof , @TheZoq2 Ok, then lets start with blocking version and merge current solution. I will experiment with multiple channel readings while working on vacuum cleaner firmware. So I will check out non-blocking implementations including #19 as well as mentioned in your comments. Regards, |
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.
LGTM
Looks good to me as well, thanks! |
Summary
This PR adds the following bits:
This PR is based on #19 by @TheZoq2 . As per request from @therealprof , it has been reworked following stm32f0x ADC implementation. Besides, some implementation details follow stm32f4x ADC implementation.
Limitations
Implementation notes
To simplify review, ADC implementation is split into the following two parts:
Current implementation enables the following ADC blocks:
Note that XL-density stm32f103 chips support ADC3 as well. Besides, gpio-to-channel mapping is different on those chips. Meanwhile it can be also embraced by suggested implementation. For instance, something like the following should work: