# gpiohs.rs - source
Source of the Rust file `/home/runner/.cargo/git/checkouts/k210-soc-513b01293da09fa1/09a0742/src/gpiohs.rs`.
Keywords: rust, rustlang, rust-lang

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41

    #![allow(unused)]

    //! GPIOHS peripheral
    //use k210_hal::pac;
    use k210_pac as pac;

    use super::gpio;
    use super::utils::{set_bit,get_bit};

    // TODO embedded-hal::digital::v2::{InputPin, OutputPin}

    /** Set input/output direction for a GPIOHS pin */
    pub fn set_direction(pin: u8, direction: gpio::direction) {
        unsafe {
            let ptr = pac::GPIOHS::ptr();
            (*ptr)
                .output_en
                .modify(|r, w| w.bits(set_bit(r.bits(), pin, direction == gpio::direction::OUTPUT)));
            (*ptr)
                .input_en
                .modify(|r, w| w.bits(set_bit(r.bits(), pin, direction == gpio::direction::INPUT)));
        }
    }

    /** Set output value for a GPIOHS pin */
    pub fn set_pin(pin: u8, value: bool) {
        unsafe {
            let ptr = pac::GPIOHS::ptr();
            (*ptr)
                .output_val
                .modify(|r, w| w.bits(set_bit(r.bits(), pin, value)));
        }
    }

    /** Get input value for a GPIOHS pin */
    pub fn get_pin(pin: u8) -> bool {
        unsafe {
            let ptr = pac::GPIOHS::ptr();
            get_bit((*ptr).input_val.read().bits(), pin)
        }
    }