Suggest against the DEVNAME_params[] paradigm

It is currently suggested that drivers should provide a DEVNAME_params[] in a DEVNAME_params.h file. This logic seems to stem from the need to be able to iterate the list of devices and init them in the appropriate subsystem (vfs, saul, network stack). For devices which don’t really fit into a subsystem (example: dfplayer), they are inited by auto_init.

The problem I have with this paradigm, is that when a device must be interacted with directly (as oppused to through a subsystem), the paradigm hides initialization errors, and frustrates any use of named devices.

Taking dfplayer as an example. auto_init loops through and inits each. If the init fails, a error is logged to the console, but the application has no way to know. The application now fetches the driver handles based on an index number using dfplayer_get(unsigned num) and uses them without knowing that the init failed.

The index number, of course, can be defined in board.h mitigating the application having to figure out which devise is which, but this can be frustrating for non trivial setups. Take the example:


mydev_params_t mydev_params[] = {
    {
        ...
    },
#if CONFIG_FOO 
   {
        ...
    },
#endif
#if CONFIG_BAR
    {
        ...
    },
#endif
};

#if CONFIG_FOO
#define MYDEV_FOO 1
#endif

#if CONFIG_FOO && CONFIG_BAR
#define MYDEV_BAR 2
#elif CONFIG_BAR
#define MYDEV_BAR 1
#endif

contrast this with

mydev_params_t baz_dev_params = { ... }

#if CONFIG_FOO
mydev_params_t foo_dev_params = { ... }
#endif

#if CONFIG_BAR
mydev_params_t bar_dev_params = { ... }
#endif

Initializing could then be handled by passing an init function pointer to subsystems when registering devices (int (*init)(void* dev, const void* params)), or they could be handled by adding pointers to an XFA in the case that the device doesn’t belong to any subsystem.