MutDevicePio

Trait MutDevicePio 

Source
pub trait MutDevicePio {
    // Required methods
    fn pio_read(
        &mut self,
        base: PioAddress,
        offset: PioAddressOffset,
        data: &mut [u8],
    );
    fn pio_write(
        &mut self,
        base: PioAddress,
        offset: PioAddressOffset,
        data: &[u8],
    );
}
Expand description

Same as DevicePio but the methods are invoked with a mutable self borrow.

§Example

struct DummyDevice {
    config: u32,
}

impl MutDevicePio for DummyDevice {
    fn pio_read(&mut self, _base: PioAddress, _offset: PioAddressOffset, data: &mut [u8]) {
        if data.len() > 4 {
            return;
        }
        for (idx, iter) in data.iter_mut().enumerate() {
            *iter = (self.config >> (idx * 8) & 0xff) as u8;
        }
    }

    fn pio_write(&mut self, _base: PioAddress, _offset: PioAddressOffset, data: &[u8]) {
        self.config = u32::from(data[0]) & 0xff;
    }
}

Required Methods§

Source

fn pio_read( &mut self, base: PioAddress, offset: PioAddressOffset, data: &mut [u8], )

Handle a read operation on the device.

§Arguments
  • base: base address on a PIO bus
  • offset: base address’ offset
  • data: a buffer provided by the caller to store the read data
Source

fn pio_write(&mut self, base: PioAddress, offset: PioAddressOffset, data: &[u8])

Handle a write operation to the device.

§Arguments
  • base: base address on a PIO bus
  • offset: base address’ offset
  • data: a buffer provided by the caller holding the data to write

Implementors§