pub struct Buttons {}

impl Buttons {
    pub unsafe fn get_button(button_id: u8) -> bool {
        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 }
    }
}

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 {
                core::ptr::write_volatile(LED_IP_ADDRESS, value | (state as u64) << (led_id + 4))
            }
        } else {
            unsafe {
                core::ptr::write_volatile(LED_IP_ADDRESS, value & !((state as u64) << (led_id + 4)))
            }
        }
    }
}

pub const LED_IP_ADDRESS: *mut u64 = 0x30000000 as *mut u64;
