Mandelbrot

This commit is contained in:
2025-12-02 17:30:03 +01:00
parent fc2a63d7f1
commit d5699f2da3
6 changed files with 92 additions and 131 deletions

View File

@@ -2,7 +2,10 @@ pub struct Buttons {}
impl Buttons {
pub unsafe fn get_button(button_id: u8) -> bool {
unsafe { ((*LED_IP_ADDRESS) >> button_id) & 0b1 == 0b1 }
unsafe { (core::ptr::read_volatile(LED_IP_ADDRESS) >> button_id) & 0b1 == 0b1 }
}
pub unsafe fn is_button_pressed() -> bool {
unsafe { core::ptr::read_volatile(LED_IP_ADDRESS) != 0 }
}
}
@@ -10,10 +13,15 @@ pub struct Leds {}
impl Leds {
pub unsafe fn set_led(led_id: u8, state: bool) {
let value = unsafe { core::ptr::read_volatile(LED_IP_ADDRESS) };
if state {
unsafe { *LED_IP_ADDRESS |= (state as u64) << (led_id + 4) }
unsafe {
core::ptr::write_volatile(LED_IP_ADDRESS, value | (state as u64) << (led_id + 4))
}
} else {
unsafe { *LED_IP_ADDRESS &= !((state as u64) << (led_id + 4)) }
unsafe {
core::ptr::write_volatile(LED_IP_ADDRESS, value & !((state as u64) << (led_id + 4)))
}
}
}
}