-
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers: unify default parameter definition scheme #7519
Description
Looking at the existing scheme we use when defining a device's default parameters, there seem to be a slight variation of styles used -> comment style for default values, xx_CUSTOM vs. xx_BOARD vs. xx_DEFAULT...
Furthermore, we have a source of error in all of them: in case there is more than one device defined by a board (-> xx_BOARD has more than one entry), the SAUL reg info field has still only a single one. This leads to out-of-bound access to the SAUL info array during initialization...
So I propose to unify all default parameter files to the following scheme:
/**
* @name Default configuration parameters for device DEVX
* @{
*/
#ifndef DEVX_PARAM_ABC
#define DEVX_PARAM_ABC ...
#endif
#ifndef DEVX_PARAM_TTT
#define DEVX_PARAM_TTT ...
#endif
#ifndef DEVX_PARAMS
#define DEVX_PARAMS { .abc = DEVX_PARAM_ABC, \
.ttt = DEVX_PARAM_TTT }
#endif
#ifndef DEVX_SAULINFO
#define DEVX_SAULINFO { .name = "devx" }
#endif
/** @} */
/**
* @brief DEVX configuration
*/
static const devx_params_t devx_params[] = {
DEVX_PARAMS
};
/**
* @brief SAUL registry entires
*/
static const saul_reg_info_t devx_saul_reg_info[] = {
DEVX_SAULINFO
};This way, if a board or application can override the device config by re-defining the DEVX_PARAMS and DEVX_SAULINFO.
We can further add a check to the auto-init code, that makes sure that the number of defined devices and the number of defined SAUL infos matches:
#define INFO_NUM (sizeof(devx_saul_reg_info) / sizeof(devx_saul_reg_info[0]))
#define PARAM_NUM (sizeof(devx_params) / sizeof(devx_params[0]))
assert(INFO_NUM == PARAM_NUM);What do you guys think about this?