[riot-notifications] [RIOT-OS/RIOT] RFC: Change of sensor and actoator API & auto initialization (#11826)

Marian Buschsieweke notifications at github.com
Thu Jul 11 06:39:20 CEST 2019


#### The Problem
Currently sensors and actuators are only auto-initialized when SAUL is used. This is not only inconvenient by itself, but also makes using both SAUL and the native driver API impossible. (One use case: Debugging via the `saul` shell command while the application uses the native interface for accessing additional device-specific features. Another use case: Different "apps" running as separate threads on the same device, where one app is portable and using SAUL, while the other needs to access device-specific features not available through SAUL.)

##### The Issue in Detail

E.g. in the auto init code of the `dht` driver the device descriptors are allocated here:

https://github.com/RIOT-OS/RIOT/blob/6b094a78a943bcbd74d21a7ce83840c1fdcdc0a6/sys/auto_init/saul/auto_init_dht.c#L35-L38

With them being `static`, it is impossible (without resorting to nasty hacks) to access the auto initialized descriptors. And having two device descriptors referring to the same device is something that will cause bad things to happen.

Even if we would remove the `static` qualifier from all device descriptor arrays, using `&dht_devs[0]` is kind of ugly.

### Proposed Solution

A sensor `foo` should provide to types: 

``` C
typedef struct {
     foo_params_t params;
     int state;
     ....
} foo_dev_t;

typedef uint8_t foo_t;
```

In the auto-init code we would have

``` C
foo_dev_t foo_devs[N_FOO_DEVS];
```

So `foo_dev_t` would contain the data/configuration/state of a device, and `foo_t` would be the index in `foo_devs`. The auto-init code must initialize all available sensors regardless of whether SAUL is used. If SAUL is used, it must additionally register the initialized sensors.

The API of foo should look than like this:

``` C
int foo_read(foo_t dev, uint16_t *dest);
....
```

This would also be more consistent with other RIOT APIs, e.g. `gpio_t`, `spi_t`, `i2c_t` etc. are also "simple types" that one can pass as value, while e.g. `bmx280_t` is something you really want to pass as reference. Also a POSIX file descriptor is an `int`, the newly proposed device descriptor would be much better match to POSIX descriptors than a potentially large `struct`.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/issues/11826
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190710/a1b23a3b/attachment-0001.html>


More information about the notifications mailing list