-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Add haptic feedback interface #76343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5852a26 to
e90af08
Compare
samples/drivers/drv2605/src/main.c
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
e90af08 to
057f4d5
Compare
include/zephyr/drivers/haptics.h
Outdated
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
dts/bindings/haptics/ti,drv2605.yaml
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
dts/bindings/haptics/ti,drv2605.yaml
Outdated
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
drivers/haptics/Kconfig.drv2605
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
samples/drivers/drv2605/prj.conf
Outdated
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
057f4d5 to
3eef55c
Compare
bjarki-andreasen
left a comment
There was a problem hiding this 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 :)
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack and ack
include/zephyr/drivers/haptics.h
Outdated
There was a problem hiding this comment.
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 :)
994b21e to
5139e90
Compare
kartben
left a comment
There was a problem hiding this 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!
There was a problem hiding this comment.
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)
| * @retval < 0 if failed | |
| * @retval <0 if failed |
include/zephyr/drivers/haptics.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
include/zephyr/drivers/haptics.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @retval < 0 if failed | |
| * @retval <0 if failed |
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]>
5139e90 to
70d1392
Compare
fabiobaltieri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
fabiobaltieri
left a comment
There was a problem hiding this 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?
|
@bjarki-andreasen can you take another look please? |
Will do in a subsequent PR later today. |
| .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), \ |
There was a problem hiding this comment.
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
|
@rriveramcrus any chance you could assemble a couple bullet points to add haptics to the release notes? |
|
Adds a haptic driver API and a DRV2605 haptic device driver.