Skip to content

Commit 5f3c63b

Browse files
committed
Clean up examples
1 parent bc73e38 commit 5f3c63b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

examples/comp.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ fn main() -> ! {
3232
let pa0 = gpioa.pa0.into_analog();
3333
let comp1 = comp1.comparator(pa1, pa0, Config::default(), &rcc.clocks);
3434
let comp1 = comp1.enable();
35+
36+
// led1 pa1 will be updated manually when to match comp1 value
3537
let mut led1 = gpioa.pa5.into_push_pull_output();
3638

3739
let pa7 = gpioa.pa7.into_analog();
@@ -50,6 +52,7 @@ fn main() -> ! {
5052
let _comp2 = comp2.enable().lock();
5153

5254
loop {
55+
// Read comp1 output and update led1 accordingly
5356
match comp1.output() {
5457
true => led1.set_high().unwrap(),
5558
false => led1.set_low().unwrap(),

examples/comp_w_dac.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ fn main() -> ! {
2525
let mut delay = cp.SYST.delay(&rcc.clocks);
2626

2727
let gpioa = dp.GPIOA.split(&mut rcc);
28-
let dac1ch1 = dp.DAC1.constrain((gpioa.pa4, Dac1IntSig1), &mut rcc);
2928

29+
// Set up DAC to output to pa4 and to internal signal Dac1IntSig1
30+
// which just so happens is compatible with comp1
31+
let dac1ch1 = dp.DAC1.constrain((gpioa.pa4, Dac1IntSig1), &mut rcc);
3032
let mut dac = dac1ch1.calibrate_buffer(&mut delay).enable();
3133

3234
let (comp1, _comp2, ..) = dp.COMP.split(&mut rcc);
3335
let pa1 = gpioa.pa1.into_analog();
36+
37+
// Set up comparator with pa1 as positive, and the DAC as negative input
3438
let comp = comp1.comparator(
3539
pa1,
3640
&dac,
@@ -47,6 +51,12 @@ fn main() -> ! {
4751
let mut dir = Direction::Upcounting;
4852
let mut val = 0;
4953

54+
// Manually step the DAC's value to produce a triangle wave
55+
//
56+
// This will produce a pwm-like signal at pa0 with the duty controlled by pa1
57+
// where
58+
// * 0V at p1 => 0% duty
59+
// * VDDA at p1 => 100% duty
5060
loop {
5161
dac.set_value(val);
5262
match val {

examples/dac.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,28 @@ fn main() -> ! {
3131
let gpioa = dp.GPIOA.split(&mut rcc);
3232
let (dac1ch1, dac1ch2) = dp.DAC1.constrain((gpioa.pa4, gpioa.pa5), &mut rcc);
3333

34+
// dac_manual will have its value set manually
3435
let mut dac_manual = dac1ch1.calibrate_buffer(&mut delay).enable();
36+
37+
// dac_generator will have its value set automatically from its internal noise generator
3538
let mut dac_generator = dac1ch2.enable_generator(GeneratorConfig::noise(11));
3639

3740
let mut dir = Direction::Upcounting;
3841
let mut val = 0;
3942

4043
loop {
44+
// This will pull out a new value from the noise generator and apply it to the DAC
4145
dac_generator.trigger();
46+
47+
// This will manually set the DAC's value
4248
dac_manual.set_value(val);
4349
match val {
4450
0 => dir = Direction::Upcounting,
4551
4095 => dir = Direction::Downcounting,
4652
_ => (),
4753
};
4854

55+
// Step manually set value as a triangle wave
4956
match dir {
5057
Direction::Upcounting => val += 1,
5158
Direction::Downcounting => val -= 1,

0 commit comments

Comments
 (0)