feat: add more example programs
This commit is contained in:
parent
1aac7bd456
commit
806a5ac871
4 changed files with 83 additions and 2 deletions
|
@ -6,7 +6,7 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
hal = { package = "stm32l0xx-hal", version = "0.10.0", features = [
|
||||
"mcu-STM32L053R8Hx", # mcu-STM32L053R8Hx or mcu-STM32L053R8Tx not sure
|
||||
"mcu-STM32L053R8Tx",
|
||||
"rt",
|
||||
] }
|
||||
cortex-m-rt = "0.7.5"
|
||||
|
|
36
examples/blinky-press.rs
Executable file
36
examples/blinky-press.rs
Executable file
|
@ -0,0 +1,36 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use hal::{pac, prelude::*, rcc::Config};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
|
||||
// Configure the clock.
|
||||
let mut rcc = dp.RCC.freeze(Config::hsi16());
|
||||
|
||||
let gpioa = dp.GPIOA.split(&mut rcc);
|
||||
let gpioc = dp.GPIOC.split(&mut rcc);
|
||||
|
||||
// Configure PA5 as output.
|
||||
let mut led = gpioa.pa5.into_push_pull_output();
|
||||
let mut button = gpioc.pc13.into_pull_down_input();
|
||||
|
||||
// Get the delay provider.
|
||||
let mut delay = cp.SYST.delay(rcc.clocks);
|
||||
|
||||
loop {
|
||||
if button.is_low().expect("button.is_low failed") {
|
||||
led.set_high().unwrap();
|
||||
} else {
|
||||
led.set_low().unwrap();
|
||||
}
|
||||
|
||||
delay.delay_ms(10_u16);
|
||||
}
|
||||
}
|
45
examples/blinky-toggle.rs
Executable file
45
examples/blinky-toggle.rs
Executable file
|
@ -0,0 +1,45 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use hal::{pac, prelude::*, rcc::Config};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
|
||||
// Configure the clock.
|
||||
let mut rcc = dp.RCC.freeze(Config::hsi16());
|
||||
|
||||
let gpioa = dp.GPIOA.split(&mut rcc);
|
||||
let gpioc = dp.GPIOC.split(&mut rcc);
|
||||
|
||||
// Configure PA5 as output.
|
||||
let mut led = gpioa.pa5.into_push_pull_output();
|
||||
let button = gpioc.pc13.into_pull_down_input();
|
||||
|
||||
// Get the delay provider.
|
||||
let mut _delay = cp.SYST.delay(rcc.clocks);
|
||||
|
||||
let mut is_on: bool;
|
||||
let mut was_on: bool = false;
|
||||
#[allow(unused_variables)] // it is used later??
|
||||
let mut enable_led: bool = false;
|
||||
|
||||
loop {
|
||||
is_on = button.is_low().unwrap();
|
||||
if is_on != was_on {
|
||||
enable_led ^= true;
|
||||
}
|
||||
if is_on {
|
||||
led.set_high().unwrap();
|
||||
} else {
|
||||
led.set_low().unwrap();
|
||||
}
|
||||
|
||||
was_on = is_on;
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ fn main() -> ! {
|
|||
// the RCC register.
|
||||
let gpioa = dp.GPIOA.split(&mut rcc);
|
||||
|
||||
// Configure PA1 as output.
|
||||
// Configure PA5 as output.
|
||||
let mut led = gpioa.pa5.into_push_pull_output();
|
||||
|
||||
// Get the delay provider.
|
||||
|
|
Loading…
Add table
Reference in a new issue