Mandelbrot
This commit is contained in:
@@ -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)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user