How to write a driver for a sensor with either SPI or I2C interface?

I started to write a driver for a series of sensors that come in two flavors : either SPI or I2C. A specific part has just one interface, depending on the part number you order.

I started to write a driver, but I only have the SPI version at hand.

Should both versions be supported in the same driver package? If yes, what’s the clean way to do it? Are there examples in RIOT? If no, how should the packages be named?

I opened an issue:

You can look at e.g. the lis2dh12 driver, it supports both I2C and SPI transport.

You will find that the register interface is the same for both, so it’s enough to implement only the read and write functions for both I2C and SPI with a common interface.

This is then selected via the pseudo-modules lis2dh12_i2c and lis2dh12_spi respectively.

If you only have one version of the device at hand, you of course don’t have to implement the other transport, but it would be good to future proof the code in that matter that the bus access is well capsuled so adding the other transport is easy in the future.