Crate iqs5xx

Crate iqs5xx 

Source
Expand description

IQS5xx capacitive touchpad controller device driver

This crate provides a device driver for the Azoteq IQS5xx capacitive touchpad controller.

The IQS5xx touchpad connects to the target via I2C and two GPIO pins. The embedded_hal blocking::i2c and digital::v2 interfaces are used, so should work with any target that provides these.

§Examples

Examples using the Raspberry PI Pico to report touchpad events via defmt_rtt and to act as a basic USB mouse are located in the examples/rp-pico directory.

An IQS5xx device is created with:

    let sda_pin = pins.gpio0.into_mode::<gpio::FunctionI2C>();
    let scl_pin = pins.gpio1.into_mode::<gpio::FunctionI2C>();
    let i2c = bsp::hal::I2C::i2c0(
        pac.I2C0,
        sda_pin,
        scl_pin,
        400.kHz(),
        &mut pac.RESETS,
        &clocks.system_clock,
    );
    let rdy_pin = pins.gpio3.into_floating_input();
    let rst_pin = pins.gpio2.into_push_pull_output();
    let mut iqs = iqs5xx::IQS5xx::new(i2c, iqs5xx::DEFAULT_I2C_ADDR, rdy_pin, rst_pin);

After initialization, accesses to the IQS5xx device should be wrapped in a call to iqs.transact(). This ensures the IQS5xx device is ready (indicated by the RDY pin) and signals the end of the transaction to the device:

    let res = iqs.transact(&mut delay, |iqs| { iqs.get_report() });
    match res {
        Ok(report) => {
            info!(
                "{:02x}:{:02x}:{:02x}:{:02x}, {}: {}, {}",
                report.events0, report.events1, report.sys_info0, report.sys_info1,
                report.num_fingers, report.rel_x, report.rel_y
            );
            for i in 0..report.num_fingers as usize {
                let t = &report.touches[i];
                info!("{},{} : {} : {}", t.abs_x, t.abs_y, t.strength, t.size);
            }

            let event = iqs5xx::Event::from(&report);
            if event != iqs5xx::Event::None {
                info!("Event: {}", event);
            }
        }
        Err(_) => {
            warn!("Error");
        }
    }

The caller can use interrupts on the ready pin to avoid busy waits by polling for events. The transact() function should be called from the interrupt handler or a task scheduled from the interrupt handler. Interrupts should be cleared with clear_irq().

Modules§

registers
Register IDs for IQS5xx

Structs§

DeviceInfo
Product and version information of the IQS5xx device
IQS5xx
IQS5xx driver
Report
Status report from trackpad
Touch
Fields describing a touch

Enums§

Error
Errors produced by the IQS5xx device
Event
Events derived from status report

Constants§

DEFAULT_I2C_ADDR
Default I2C device address for IQS5xx devices

Type Aliases§

Result