DevicePio

Trait DevicePio 

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

Allows a device to be attached to a PIO bus.

§Example

struct DummyDevice {
    config: Mutex<u32>,
}

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

    fn pio_write(&self, _base: PioAddress, _offset: PioAddressOffset, data: &[u8]) {
        let mut config = self.config.lock().expect("failed to acquire lock");
        *config = u32::from(data[0]) & 0xff;
    }
}

Required Methods§

Source

fn pio_read(&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(&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

Implementations on Foreign Types§

Source§

impl<T: DevicePio + ?Sized> DevicePio for Arc<T>

Source§

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

Source§

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

Source§

impl<T: MutDevicePio + ?Sized> DevicePio for Mutex<T>

Source§

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

Source§

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

Implementors§