use crate as sys;
pub const GPIO_NUMBER: usize = 16;
#[inline]
pub unsafe extern "C" fn furi_hal_gpio_write(gpio: *const sys::GpioPin, state: bool) {
let gpio = unsafe { *gpio };
let port = gpio.port;
let pin = gpio.pin;
unsafe { furi_hal_gpio_write_port_pin(port, pin, state) }
}
#[inline]
pub unsafe extern "C" fn furi_hal_gpio_write_port_pin(
port: *mut sys::GPIO_TypeDef,
pin: u16,
state: bool,
) {
unsafe {
core::ptr::write_volatile(
&mut (*port).BSRR,
(pin as u32) << if state { 0 } else { GPIO_NUMBER },
);
}
}
#[inline]
pub unsafe extern "C" fn furi_hal_gpio_read(gpio: *const sys::GpioPin) -> bool {
let gpio = unsafe { *gpio };
let port = gpio.port;
let pin = gpio.pin;
unsafe { furi_hal_gpio_read_port_pin(port, pin) }
}
#[inline]
pub unsafe extern "C" fn furi_hal_gpio_read_port_pin(
port: *mut sys::GPIO_TypeDef,
pin: u16,
) -> bool {
let port = unsafe { *port };
let input_data_register_value = unsafe { core::ptr::read_volatile(&port.IDR) };
input_data_register_value & pin as u32 != 0x00
}