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, bitoffsetdrives/reflects the line;base + 0x04: direction register, bitoffsetset = 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: usizePhysical base address of the GPIO controller register block.
offset: u32Bit index of this line within the controller’s 32-bit registers.
active_low: boolWhen true, logical high/low are inverted relative to the electrical level.
Implementations§
Source§impl GpioPin
impl GpioPin
Sourcepub const DATA_REG_OFFSET: usize = 0x00
pub const DATA_REG_OFFSET: usize = 0x00
Offset of the data (set/clear via read-modify-write) register.
Sourcepub const DIR_REG_OFFSET: usize = 0x04
pub const DIR_REG_OFFSET: usize = 0x04
Offset of the direction register (bit set = output).
Sourcepub fn is_configured(&self) -> bool
pub fn is_configured(&self) -> bool
Returns true when this pin points at a real controller (base != 0).
Sourcefn write_data(&self, val: u32)
fn write_data(&self, val: u32)
Writes the data register.
Sourcefn rmw_bit(&self, reg_offset: usize, set: bool)
fn rmw_bit(&self, reg_offset: usize, set: bool)
Sets or clears bit offset of a register via volatile read-modify-write.
Sourcepub fn set_direction_input(&self)
pub fn set_direction_input(&self)
Configures the line as input (direction bit cleared).
Sourcepub fn set_direction_output(&self)
pub fn set_direction_output(&self)
Configures the line as output (direction bit set).