aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-01 11:45:23 +0000
committerGitHub <[email protected]>2022-01-01 11:45:23 +0000
commitc0e94a7042a9a91bbdef64ad0177cee21816c793 (patch)
tree8c821090c5a5286ed7d4a061932be3c781647688 /examples
parentf9a1c1fb51334af0bba5e7e970e34241f5f15f05 (diff)
parentde70f1c30272793dfc353b56f0cc97780467549e (diff)
Merge #563
563: Initial ADC support for on STM32F1xx r=Dirbaio a=sjoerdsimons Add an ADC implementation for F1 based chips. Primarily tested using ADC1, proper functionality for ADC2 probably needs some extra work as it's mainly a slave and can't e.g. measure vrefint by itself. Needs https://github.com/embassy-rs/stm32-data/pull/115 Co-authored-by: Sjoerd Simons <[email protected]> Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f1/Cargo.toml3
-rw-r--r--examples/stm32f1/src/bin/adc.rs29
2 files changed, 32 insertions, 0 deletions
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml
index 84773b91b..765e91b5d 100644
--- a/examples/stm32f1/Cargo.toml
+++ b/examples/stm32f1/Cargo.toml
@@ -20,3 +20,6 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
20futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 20futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
21heapless = { version = "0.7.5", default-features = false } 21heapless = { version = "0.7.5", default-features = false }
22nb = "1.0.0" 22nb = "1.0.0"
23
24[profile.dev]
25opt-level = "s"
diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs
new file mode 100644
index 000000000..de2214630
--- /dev/null
+++ b/examples/stm32f1/src/bin/adc.rs
@@ -0,0 +1,29 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[path = "../example_common.rs"]
6mod example_common;
7
8use embassy::executor::Spawner;
9use embassy::time::Delay;
10use embassy_stm32::adc::Adc;
11use embassy_stm32::Peripherals;
12use embassy_traits::delay::Delay as _;
13use example_common::*;
14
15#[embassy::main]
16async fn main(_spawner: Spawner, p: Peripherals) {
17 info!("Hello World!");
18
19 let mut adc = Adc::new(p.ADC1, &mut Delay);
20 let mut pin = p.PB1;
21
22 let mut vref = adc.enable_vref(&mut Delay);
23 adc.calibrate(&mut vref);
24 loop {
25 let v = adc.read(&mut pin);
26 info!("--> {} - {} mV", v, adc.to_millivolts(v));
27 Delay.delay_ms(100).await;
28 }
29}