1#![no_std]
2#![no_main]
3
4use core::panic::PanicInfo;
5
6use embedded_hal::digital::{InputPin, StatefulOutputPin};
7use hal_mik32::gpio::port_0::{Pin09, Pin10};
8use hal_mik32::gpio::{self, DriveStrength};
9use hal_mik32::rcc::RCC;
10
11#[unsafe(no_mangle)]
14pub extern "C" fn main() -> ! {
15 let rcc_config = RCC::default();
16 RCC::init(&rcc_config).unwrap();
17 let _gpio0 = gpio::init_port::<0>();
18
19 let mut led_pin = Pin09::new()
20 .into_output()
21 .with_drive_strength(DriveStrength::Ma8);
22 let mut button_pin = Pin10::new().into_pull_down_input();
23 let mut button_was_pressed = false;
24
25 loop {
26 let button_is_pressed = button_pin.is_high().unwrap();
27
28 if button_is_pressed && !button_was_pressed {
29 let _ = led_pin.toggle();
30 }
31
32 button_was_pressed = button_is_pressed;
33 delay(10_000);
34 }
35}
36
37#[inline(always)]
38fn delay(spins: u32) {
39 for _ in 0..spins {
40 core::hint::spin_loop();
41 }
42}
43
44#[panic_handler]
45fn panic(_info: &PanicInfo) -> ! {
46 loop {
47 core::hint::spin_loop();
48 }
49}
50
51#[unsafe(no_mangle)]
52#[inline(never)]
53pub extern "C" fn trap_handler() {
54 loop {
55 core::hint::spin_loop();
56 }
57}