Restore F1 example chip

This commit is contained in:
chemicstry 2022-08-04 03:07:42 +03:00
parent 5f01e56728
commit d990740dd5
2 changed files with 1 additions and 38 deletions

View File

@ -6,7 +6,7 @@ version = "0.1.0"
[dependencies] [dependencies]
embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] } embassy-util = { version = "0.1.0", path = "../../embassy-util", features = ["defmt"] }
embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] } embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "defmt-timestamp-uptime", "time-tick-32768hz"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103rc", "unstable-pac", "memory-x", "time-driver-any"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any"] }
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] } embassy-usb-serial = { version = "0.1.0", path = "../../embassy-usb-serial", features = ["defmt"] }

View File

@ -1,37 +0,0 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::*;
use embassy_executor::executor::Spawner;
use embassy_stm32::dac::{Channel, Dac, Value};
use embassy_stm32::Peripherals;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner, p: Peripherals) -> ! {
info!("Hello World, dude!");
let mut dac = Dac::new_1ch(p.DAC, p.PA4);
loop {
for v in 0..=255 {
unwrap!(dac.set(Channel::Ch1, Value::Bit8(to_sine_wave(v))));
unwrap!(dac.trigger(Channel::Ch1));
}
}
}
use micromath::F32Ext;
fn to_sine_wave(v: u8) -> u8 {
if v >= 128 {
// top half
let r = 3.14 * ((v - 128) as f32 / 128.0);
(r.sin() * 128.0 + 127.0) as u8
} else {
// bottom half
let r = 3.14 + 3.14 * (v as f32 / 128.0);
(r.sin() * 128.0 + 127.0) as u8
}
}