checkpoint
This commit is contained in:
parent
8069017df0
commit
842d8b26a6
3 changed files with 18 additions and 5 deletions
4
.rustfmt.toml
Normal file
4
.rustfmt.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
group_imports = "StdExternalCrate"
|
||||||
|
wrap_comments = true
|
||||||
|
edition = "2021"
|
||||||
|
|
@ -25,3 +25,7 @@ bench = false
|
||||||
codegen-units = 1 # better optimizations
|
codegen-units = 1 # better optimizations
|
||||||
debug = true # symbols are nice and they don't increase the size on Flash
|
debug = true # symbols are nice and they don't increase the size on Flash
|
||||||
lto = true # better optimizations
|
lto = true # better optimizations
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = "z"
|
||||||
|
debug = true
|
||||||
|
|
|
||||||
15
src/main.rs
15
src/main.rs
|
|
@ -1,9 +1,13 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use stm32f3xx_hal::{self as hal, adc, pac, prelude::*};
|
use defmt_rtt as _;
|
||||||
|
#[allow(deprecated)]
|
||||||
use {defmt_rtt as _, panic_halt as _};
|
use hal::pwm::{tim16, tim2, tim3};
|
||||||
|
use panic_halt as _;
|
||||||
|
use stm32f3xx_hal::{
|
||||||
|
self as hal, adc, flash::FlashExt, gpio::GpioExt, hal::PwmPin, pac, prelude::*, rcc::RccExt,
|
||||||
|
};
|
||||||
|
|
||||||
static POT_MAX: u16 = 4095;
|
static POT_MAX: u16 = 4095;
|
||||||
|
|
||||||
|
|
@ -13,7 +17,9 @@ mod motor;
|
||||||
#[cortex_m_rt::entry]
|
#[cortex_m_rt::entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let sp = pac::Peripherals::take().unwrap();
|
let sp = pac::Peripherals::take().unwrap();
|
||||||
|
let mut flash = sp.FLASH.constrain();
|
||||||
let mut rcc = sp.RCC.constrain();
|
let mut rcc = sp.RCC.constrain();
|
||||||
|
let clocks = rcc.cfgr.freeze(&mut flash.acr);
|
||||||
let mut gpiob = sp.GPIOB.split(&mut rcc.ahb);
|
let mut gpiob = sp.GPIOB.split(&mut rcc.ahb);
|
||||||
let mut led = gpiob
|
let mut led = gpiob
|
||||||
.pb2
|
.pb2
|
||||||
|
|
@ -21,8 +27,6 @@ fn main() -> ! {
|
||||||
|
|
||||||
let mut pot = gpiob.pb1.into_analog(&mut gpiob.moder, &mut gpiob.pupdr);
|
let mut pot = gpiob.pb1.into_analog(&mut gpiob.moder, &mut gpiob.pupdr);
|
||||||
|
|
||||||
let mut flash = sp.FLASH.constrain();
|
|
||||||
let clocks = rcc.cfgr.freeze(&mut flash.acr);
|
|
||||||
let cp = cortex_m::Peripherals::take().unwrap();
|
let cp = cortex_m::Peripherals::take().unwrap();
|
||||||
let mut delay = hal::delay::Delay::new(cp.SYST, clocks);
|
let mut delay = hal::delay::Delay::new(cp.SYST, clocks);
|
||||||
|
|
||||||
|
|
@ -34,6 +38,7 @@ fn main() -> ! {
|
||||||
&adc_common,
|
&adc_common,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cortex_m::asm::wfi();
|
||||||
loop {
|
loop {
|
||||||
let pot_out: u16 = padc.read(&mut pot).unwrap_or(0);
|
let pot_out: u16 = padc.read(&mut pot).unwrap_or(0);
|
||||||
let pot_out = (POT_MAX - pot_out) as f32 / POT_MAX as f32;
|
let pot_out = (POT_MAX - pot_out) as f32 / POT_MAX as f32;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue