Best method for using I2C via system call by user

I have a PCT2075 temp sensor that I am communicating with over I2C and works fine in a simple program. Now I'm trying to implement this functionality from a user level function. User mode will not have access to GPIO, so I figure that I would implement a system call to call a read(). I'm not sure of the design pattern for this functionality. I figure this needs to be a static mut, but Im having trouble with it.

    let dr = DeviceResources::take().unwrap();
    let p = dr.peripherals;
    let pins = dr.pins;

    // Configure clocks
    let clocks = hifive1::clock::configure(
        p.PRCI,
        p.AONCLK,
        320.mhz().into()
    );

    // Configure UART for stdout
    hifive1::stdout::configure(
        p.UART0,
        pin!(pins, uart0_tx),
        pin!(pins, uart0_rx),
        115_200.bps(),
        clocks,
    );

    // Configure I2C
    let sda = pin!(pins, i2c0_sda).into_iof0();
    let scl = pin!(pins, i2c0_scl).into_iof0();
    let mut i2c = I2c::new(p.I2C0, sda, scl, Speed::Normal, clocks);

Static mut attempt

Pub static mut TEMP_SENSOR = Option<I2c<I2C0, (Pin12<IOF0<NoInvert>>, Pin13<IOF0<NoInvert>>)>> = None;
unsafe{
    TEMP_SENSOR.replace(
        I2c::new(p.I2C0, sda, scl, Speed::Normal, clocks)
...
}
Match TEMP_SENSOR.unwrap().write_read(
    ...
)

This gives me super long type does not implment copy trait. And yes, this code is ugly

I'm not really happy with my solution, but I did get it to work.
I had to add to_mut() to the static variable.

Match TEMP_SENSOR.to_mut().unwrap().write_read(
    ...
){}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.