-
Notifications
You must be signed in to change notification settings - Fork 48
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
Implement Observable POC #157
Draft
usbalbin
wants to merge
12
commits into
stm32-rs:staged-pac
Choose a base branch
from
usbalbin:observable_peripherals
base: staged-pac
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+425
−420
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
312436d
Implement Observable POC
usbalbin 845448e
Fix comp_w_dac example
usbalbin d1c6c22
Use ObservationLock
usbalbin 46d43fe
Add more trait bounds
usbalbin 1e332f9
impl Deref for Observed
usbalbin fa03e3b
Add Observed things to opamp
usbalbin 97fd4e4
Add rough doc of Observable::observe
usbalbin c9c5695
Update doc
usbalbin 34aa3c6
Add example of using pin.observe
usbalbin 595723c
Fix opamp for g431 etc.
usbalbin 8fa58c9
Fix example
usbalbin 62e65e1
Use proto-hal for 'entitlement' instead of 'observation'
usbalbin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//! ## Origin | ||
//! | ||
//! This code has been taken from the stm32g0xx-hal project and modified slightly to support | ||
//! STM32G4xx MCUs. | ||
|
||
//#![deny(warnings)] | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
mod utils; | ||
use utils::logger::info; | ||
extern crate cortex_m_rt as rt; | ||
|
||
use fugit::ExtU32 as _; | ||
use hal::{ | ||
adc::AdcClaim as _, | ||
comparator::{ComparatorExt, ComparatorSplit, Config}, | ||
delay::SYSTDelayExt as _, | ||
gpio::GpioExt, | ||
rcc::RccExt, | ||
stm32, | ||
}; | ||
use proto_hal::stasis::Freeze; | ||
use rt::entry; | ||
use stm32g4xx_hal::{self as hal, adc::config::SampleTime, delay::DelayExt as _}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let cp = cortex_m::Peripherals::take().unwrap(); | ||
let dp = stm32::Peripherals::take().unwrap(); | ||
let mut rcc = dp.RCC.constrain(); | ||
|
||
let gpioa = dp.GPIOA.split(&mut rcc); | ||
|
||
let (comp1, ..) = dp.COMP.split(&mut rcc); | ||
|
||
let (pa1, [pa1_token]) = gpioa // <- The pin to keep track of | ||
.pa1 | ||
.into_analog() | ||
.freeze(); | ||
let pa0 = gpioa.pa0.into_analog(); // <- Reference voltage | ||
|
||
// Only pa1_token and pa0 consumed here | ||
let comp1 = comp1.comparator(pa1_token, pa0, Config::default(), &rcc.clocks); | ||
let _comp1 = comp1.enable(); // <-- TODO: Do things with comparator | ||
|
||
let mut delay = cp.SYST.delay(&rcc.clocks); | ||
let mut adc = dp.ADC1.claim_and_configure( | ||
stm32g4xx_hal::adc::ClockSource::SystemClock, | ||
&rcc, | ||
stm32g4xx_hal::adc::config::AdcConfig::default(), | ||
&mut delay, | ||
false, | ||
); | ||
|
||
// Can not reconfigure pa1 here | ||
loop { | ||
// Can still use pa1 here | ||
let sample = adc.convert(&pa1, SampleTime::Cycles_640_5); | ||
info!("Reading: {}", sample); | ||
delay.delay(1000.millis()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This does not work. Both
Channel
andEntitlementLock
(or ratherP
i suppose) are from outside this crate. There are also errors about conflicting implementations with the other opamps below.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 the simplest solution is to make a local trait like
AdcChannel
which requiresembedded_hal::adc::Channel
and then it would work.I'm not very familiar with what you're doing here though. I'll think on it.
You could also do concrete implementations since this is macro generated anyway.
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.
Yeah that would probably be the simplest solution. I'll give it a go