Skip to main content

GpioPin

Struct GpioPin 

Source
pub struct GpioPin {
    pub base: usize,
    pub offset: u32,
    pub active_low: bool,
}
Expand description

A single memory-mapped GPIO line of the FPGA GPIO controller that backs the NBUS bit-banging protocol.

§Register layout

The controller is expected to expose two 32-bit registers relative to base:

  • base + 0x00: data register, bit offset drives/reflects the line;
  • base + 0x04: direction register, bit offset set = output, cleared = input.

All accesses are volatile read-modify-write so concurrent lines of the same controller are preserved.

An unconfigured pin (base == 0) reports Self::is_configured == false; transactions that need it are rejected instead of silently doing nothing.

Fields§

§base: usize

Physical base address of the GPIO controller register block.

§offset: u32

Bit index of this line within the controller’s 32-bit registers.

§active_low: bool

When true, logical high/low are inverted relative to the electrical level.

Implementations§

Source§

impl GpioPin

Source

pub const DATA_REG_OFFSET: usize = 0x00

Offset of the data (set/clear via read-modify-write) register.

Source

pub const DIR_REG_OFFSET: usize = 0x04

Offset of the direction register (bit set = output).

Source

pub fn is_configured(&self) -> bool

Returns true when this pin points at a real controller (base != 0).

Source

fn read_data(&self) -> u32

Reads the data register.

Source

fn write_data(&self, val: u32)

Writes the data register.

Source

fn rmw_bit(&self, reg_offset: usize, set: bool)

Sets or clears bit offset of a register via volatile read-modify-write.

Source

pub fn set_high(&self)

Drives the line to its logical-high level.

Source

pub fn set_low(&self)

Drives the line to its logical-low level.

Source

pub fn get_value(&self) -> bool

Samples the current logical level of the line.

Source

pub fn set_direction_input(&self)

Configures the line as input (direction bit cleared).

Source

pub fn set_direction_output(&self)

Configures the line as output (direction bit set).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.