Date
1 - 6 of 6
Sharing a driver between similar devices
Michael Hope
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 [1] 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 [2] but that has name collision issues. Note that the chips also have a different WHO_AM_I value, so need very slightly different configuration. -- Michael
|
|
Bolivar, Marti
Hi Michael,
"Michael Hope via lists.zephyrproject.org" <michaelh=juju.nz@lists.zephyrproject.org> writes: Hi there. I'm porting Zephyr to the Arduino Nano 33 IOT. The board has aHave 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)? E.g. setting the WHO_AM_I in your config struct based on this, and using that in your init functions to disambiguate. Thanks, Martí
|
|
Michael Hope
On Fri, 24 Jul 2020 at 22:06, Bolivar, Marti <Marti.Bolivar@...> wrote: Hi Michael, 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? -- Michael
|
|
Peter A. Bigot
I believe https://github.com/zephyrproject-rtos/zephyr/issues/20287 is relevant to this problem. At the time there was no solution; now it may be that
DT_NODE_HAS_COMPAT(DT_DRV_INST(N), other_compat) handles it if just you iterate over the base lsm6dsl device.
|
|
Michael,
Some interesting thoughts but it might be worth having a look at the lsm9ds0_mfd driver, it has configuration options for the various sensor functions. This might be a good guide to help achieve what you're planning. Billy..
|
|
Bolivar, Marti
Michael Hope <michaelh@juju.nz> writes:
On Fri, 24 Jul 2020 at 22:06, Bolivar, Marti <Marti.Bolivar@nordicsemi.no>Could you please describe the collisions in more detail? I checked the patch in your footnote [2] below but I'm not seeing the issue, sorry. Taking a guess, though, if there's an issue with naming a global variable for a device config or data field within the "fn" expansion, perhaps pasting DT_DRV_COMPAT onto the relevant variable names using the ## preprocessor operator is a fix? Thanks, Martí
|
|