Skip to content

Generics and Lra support#1

Draft
jacobrosenthal wants to merge 18 commits into
wez:masterfrom
jacobrosenthal:generics
Draft

Generics and Lra support#1
jacobrosenthal wants to merge 18 commits into
wez:masterfrom
jacobrosenthal:generics

Conversation

@jacobrosenthal
Copy link
Copy Markdown

Hey, thanks for the library.

Drv260x is kind of my hello world driver and I found your work. Are you interested in genericising this library to support drv2604 and also lra motors or would you prefer I just fork?

This is the just the start of what I was thinking. The goal is to use type state to enforce functions only in certain modes. Id like to next force all the difference modes with types, like the current default internal trigger mode be explicit with .into_trigger(), or elsewhere Ive called this ROM mode. Likewise you could consume that state and do into_pwm() instead.

After that Id like to get a builder pattern going, especially to enforce the complexity of the LRA setup and calibration. maybe something like

let config = drv::Default();
lra.voltage = x;
lra.clamp = y;
lra.drive_time = z;

let mut haptic = Drv::<_, Drv2605Lra>::builder(i2c)
.setup(config) //this will use precalibrated values if they exist, or do a calibrate if they dont.. or you could pass .otp() instead of .setup() which would fail if otp bit wasnt set on chip. 
.connect()?;
let mut haptic = haptic.into_pwm();

@jacobrosenthal
Copy link
Copy Markdown
Author

For future travelers here. I found an api without generics (but thus only a single chip drv2605l, and not holding the motor type lra or erm in the typestate either) or a builder (I found a configuration with two seperate new fn for erm or lra and individual enums for loading the calibration that does most of what I wanted instead) I havent confirmed the lra stuff yet, but heres some more commits.

    let mut haptic = Drv2605l::erm(
        twi,
        drv2605::ErmCalibration::Load(drv2605::LoadParams {
            comp: 15,
            bemf: 134,
            gain: 2,
        }),
    )
    .unwrap();
    haptic.set_standby(false).unwrap();

    // rom mode using built in effects, choose the correct Library for your
    // motor characteristics
    haptic.set_mode_rom(drv2605::Library::B).unwrap();

    // set one effect to happen when go bit enabled
    haptic
        .set_rom_single(drv2605::Effect::TransitionRampDownLongSmoothOne100to0)
        .unwrap();

@jacobrosenthal
Copy link
Copy Markdown
Author

Published drv2605l here
https://crates.io/crates/drv2605l

Ill leave this open for people to find but wont be making noise here anymore :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant