Skip to content

drivers: Existing sensor drivers that are working for a couple of sensors #10129

@gschorcht

Description

@gschorcht

Description

How do we deal with sensors for which there is no specific sensor driver but that are working with an existing sensor driver? Examples:

  • MPU9250 is working with MPU9150 driver
  • SHT21 is working with HTU21D driver
  • LSM9DS1 magnetometer part is working with LIS3MDL driver since LSM9DS1 = LSM6DS0 + LIS3MDL
  • LSM9DS0 gyro and accelerometer parts are working with L3GD20H driver since LSM9DS0 = LSM303 + L3GD20H

For a user, it is not obvious from the driver names for these examples that they also work for the other sensors.

From my point of view, possible approaches would be:

  • Document for which sensors the driver is also working. Not easy to figure out for the user since doxygen includes only symbols in the search index.
  • Implement a complete new driver. Makes probably no sense due to code duplication.
  • Rename the driver, e.g., mpu9150 renamed to mpu9x59. This might produce compatibility issues for applications that already used the driver.
  • Realize a wrapper around the existing driver.

The realization of a wrapper seems to be a feasible approach. Such a wrapper would only consist of

  • a driver include file drivers/include/<driver>.h
  • a driver parameters file drivers/<driver>/include/<driver>_params.h

The driver include file drivers/include/<driver>.h would include the wrapped driver header file and rename symbols that are visible for the application, for example drivers/include/mpu9250.h

#include "mpu9150.h"

#define MPU9250_DEFAULT_SAMPLE_RATE     MPU9150_DEFAULT_SAMPLE_RATE
...
#define mpu9250_t           mpu9150_t
#define mpu9250_params_t    mpu9150_params_t
...

The driver parameters file drivers/<driver>/include/<driver>_params.h would include the wrapped driver paremeters file and rename symbol names that are visible for the application, for example

#include "mpu9150_params.h"

#define mpu9250_params   mpu9150_params

Then the application could use the wrapper as a driver.

#include "mpu9250.h"
#include "mpu9250_params.h"
...
mpu9250_init(&dev, &mpu9250_params);
...

In that way also sensors could be supported that are combinations of other sensors like LSM9DS1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: driversArea: Device driversState: WIPState: The PR is still work-in-progress and its code is not in its final presentable form yetState: don't staleState: Tell state-bot to ignore this issueType: questionThe issue poses a question regarding usage of RIOT

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions