Skip to content

Conversation

@rriveramcrus
Copy link
Contributor

Adds a haptic driver API and a DRV2605 haptic device driver.

@rriveramcrus rriveramcrus force-pushed the haptic_init branch 4 times, most recently from 5852a26 to e90af08 Compare July 26, 2024 17:43
Comment on lines 13 to 14
Copy link
Contributor

@bjarki-andreasen bjarki-andreasen Jul 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the configuration of the haptic device is vendor/device specific, it is more efficient to move the/all configuration functions to the vendor/device specific header :)

Specifically, the API haptics_source_config(dev, HAPTICS_SOURCE_ROM, &rom_data); is not portable, whereas haptics_start_output(dev); is.

Forcing the config struct, in this case struct drv2605_rom_data rom_data = {}; to be passed by void reference through a "generic" API is less safe than creating a specific API for the drv2605 which takes a type safe combination of arguments, like:

int haptics_drv2605_source_config_rom(const struct device *dev, const struct drv2605_rom_data *data);

Which is completely type safe (except for the *dev pointer but that's a Zephyr thing).

In summary, device specific configs/features which are not generic enough to be abstractly used by the application (meaning one can switch from one haptic device of one vendor to another, without changing the application), write device specific typesafe APIs for it. Only expose the generic APIs in the haptics API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, I see your point here.

Comment on lines 23 to 39
Copy link
Contributor

@bjarki-andreasen bjarki-andreasen Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct should be moved to the drv2605 header :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also use actual Doxygen comment tags :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically only use dashes in dts properties, and exclude the vendor prefix, so ti,actuator-mode would be actuator-mode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically string enums are formatted like macros, with no spaces, and shortened as much as possible:

- "1X"
- "2X"
...
- "DISABLED"

This makes it easy to directly use the value within the drivers by concatenation like:

#define TI_FEEDBACK_BRAKE_FACTOR_1X 1
#define TI_FEEDBACK_BRAKE_FACTOR_2X 2
...

uint8_t break_factor = _CONCAT(TI_FEEDBACK_BRAKE_FACTOR_, DT_INST_STRING_TOKEN(inst, ti_feedback_brake_factor))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Comment on lines 13 to 18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use the HAPTICS_INIT_PRIORITY in the device driver :) Additionally, to add driver specific configs, hide them behind

if HAPTICS_DRV2605
...
endif

rather than depends on HAPTICS_DRV2605

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, I'll just use HAPTICS_INIT_PRIORITY :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source struct should be moved here instead of being defined in the haptic.h header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The device driver should select already selects the driver automatically using depends on DT_HAS_TI_DRV2605_ENABLED and default y making this selection redundant :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Copy link
Contributor

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good :)

@rriveramcrus rriveramcrus marked this pull request as ready for review August 5, 2024 15:29
@zephyrbot zephyrbot added area: Samples Samples platform: TI SimpleLink Texas Instruments SimpleLink MCU labels Aug 5, 2024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sample should live in samples/drivers/haptics/drv2605
Also please add some kind of README :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack and ack

Comment on lines 23 to 39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also use actual Doxygen comment tags :)

Copy link
Contributor

@kartben kartben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just spotted minor doxygen issue, lgtm otherwise - thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important to keep the first arg to retval a single token (see ex https://builds.zephyrproject.io/zephyr/pr/76343/docs/doxygen/html/group__haptics__interface.html#ga96e0b0fad35d6535adad7536a9411f44)

Suggested change
* @retval < 0 if failed
* @retval <0 if failed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @retval < 0 if failed
* @retval <0 if failed

rriveramcrus and others added 5 commits August 6, 2024 21:18
Introduces a haptics API for use with LRA driver ICs to
create haptic feedback events.

Signed-off-by: Ricardo Rivera-Matos <[email protected]>
Adds the devicetree bindings for the DRV2605 haptic driver IC.

Signed-off-by: Ricardo Rivera-Matos <[email protected]>
Adds support for the DRV2605 haptic driver.

Signed-off-by: Ricardo Rivera-Matos <[email protected]>
Adds Haptics build test

Signed-off-by: Ricardo Rivera-Matos <[email protected]>
Adds a sample application for the DRV2605 haptic driver IC.

Signed-off-by: Ricardo Rivera-Matos <[email protected]>
Copy link
Member

@fabiobaltieri fabiobaltieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

Copy link
Member

@fabiobaltieri fabiobaltieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a maintainers file entry as well?

@carlescufi
Copy link
Member

@bjarki-andreasen can you take another look please?

@carlescufi carlescufi merged commit 0c7e877 into zephyrproject-rtos:main Aug 8, 2024
@rriveramcrus
Copy link
Contributor Author

@fabiobaltieri,

Can you add a maintainers file entry as well?

Will do in a subsequent PR later today.

Comment on lines +604 to +608
.en_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, ti_en_gpios, {}), \
.in_trig_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, ti_in_trig_gpios, {}), \
.feedback_brake_factor = DT_INST_ENUM_IDX_OR(inst, ti_feedback_brake_factor, 3), \
.loop_gain = DT_INST_ENUM_IDX_OR(inst, ti_loop_gain, 2), \
.actuator_mode = DT_INST_ENUM_IDX_OR(inst, ti_actuator_mode, 0), \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these properties exist in the binding, either due to bad names (start with ti, ... here but not in the yaml file), or not even defined at all in the yaml file (ex. en-gpios), so there is a lot of dead code and potentially a very stuck drv2605 when the EN input pin actually needs to be driven high to even be active :)

Note that i don't think we need/want ti, prefix in the first place

@kartben
Copy link
Contributor

kartben commented Nov 14, 2024

@rriveramcrus any chance you could assemble a couple bullet points to add haptics to the release notes?

@rriveramcrus
Copy link
Contributor Author

@rriveramcrus any chance you could assemble a couple bullet points to add haptics to the release notes?

@kartben , Yes I can. (#81409)

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

Labels

area: Samples Samples platform: TI SimpleLink Texas Instruments SimpleLink MCU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants