- Sharing a driver between similar devices
Re: Sharing a driver between similar devices
"Michael Hope via lists.zephyrproject.org"
> Hi there. I'm porting Zephyr to the Arduino Nano 33 IOT. The board has a
> LSM6DS3 IMU which is very similar to the LSM6DSL that's already supported
> by Zephyr and I'd like to re-use it.
> I've refactored  the lsm6dsl driver to be multi-instance. What's the
> best way of then using the same driver for two different compats? The best
> I've come up with is  but that has name collision issues.
Have you tried to set some state in the config structure based on the
value of DT_NODE_HAS_COMPAT(DT_DRV_INST(your_instance_number), some_compat)?
That sounds good.
The second part of the problem is iterating over both the lsm6dsl and lsm6ds3 types. Doing two DT_INST_FOREACH_STATUS_OKAY(fn), one for each compat, can give name collisions. Any ideas?
> Note that the chips also have a different WHO_AM_I value, so need very
> slightly different configuration.
E.g. setting the WHO_AM_I in your config struct based on this, and using
that in your init functions to disambiguate.
> : https://github.com/zephyrproject-rtos/zephyr/pull/27064
> -- Michael
Join firstname.lastname@example.org to automatically receive all group messages.