-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: unify default parameter definition scheme #7519
Comments
You're right regarding the inconsistent naming (and usage), which should be adapted. However, I always thought it would (and should be possible) to have multiple devices of the same kind, i.e., there is an onboard sensor and I want to attach a second sensor of the same kind. Hence, it would be
Though, I'm unsure if that's even possible, i.e., this would require specific address config for I2C for instance. |
Yes, it is (and should be) possible to define more than one device of a type. Using the style I proposed above, you would simply do the following in e.g. your #define DEVX_PARAMS { .abc = foo, .ttt = bar }, \
{ .abc = tut, .ttt = muh } But now that I look at this, we could maybe pull the arrays outer parenthesis into the define, to make it better readable: // default:
#ifndef DEVX_PARAMS
#define DEVX_PARAMS {{ .abc = DEVX_PARAM_ABC, \
{ .ttt = DEVX_PARAM_TTT }}
#endif
// optional override by the board:
#define DEVX_PARAMS {{ .abc = foo, .ttt = bar }, \
{ .abc = tut, .ttt = muh }}
// leading to
static const devx_params_t devx_params[] = DEVX_PARAMS; |
But having the complete array in |
No, you can still override the whole file by supplying a |
I think we are not on the same page (yet)? I know that I can override the config by shipping However, my suggestions was to specify the array as: static const devx_params_t devx_params[] = {
#ifdef DEVX_PARAMS_BOARD
DEVX_PARAMS_BOARD,
#endif
#ifdef DEVX_PARAMS_CUSTOM
DEVX_PARAMS_CUSTOM
#endif
}; with that I can have a board specific config (for an onboard device) and/or a custom application config for an additional device of the same kind - or even none. Think of the PhyNode with the HDC1000 and now I want to attach another HDC1000 with jumper wires. The |
Ah, now I see. I think this scenario is quite rare (though not unrealistic) and for such a case I think defining a custom The suggestion you proposed above has IMHO some disadvantages:
But thinking about this, we should not add the 'outer' parenthesis to the static const devx_params_t devx_params[] = {
DEVX_PARAMS_BOARD,
{ .abc = blubb, .ttt = muh }
}; in the custom, application specific |
DEVX_PARAMS_BOARD,
{ .abc = blubb, .ttt = muh } yeah, that's better! |
Ok, so this would lead to the template I first suggested on top, do you agree? |
well, yes ... but, now I'm convinced, too 😄 |
I agree that it would be good to do some clean up in the driver params code, but I dislike introducing a lot of new preprocessor defines. I have seen in our existing tree how old defines remain in the header files even though the driver using them has been refactored to use a different configuration. Putting the configuration directly in the struct definitions lead to compilation errors if the driver is refactored, and the configuration will have to be cleaned up immediately, preventing this kind of pollution. |
I agree with @gebart, that the macro base device configuration is not perfect. But on the other hand, this is the only working and configurable solution that we have found so far. So I would maybe split this in to phases: |
@haukepetersen, @smlng, @kYc0o, are you interested in giving me some review help with all the related PRs ? |
I'm on them and though some are simple, others need more review since you introduce big (necessary) changes, which are not trivial. It's a lot (like the first PR) but at least now it's easier to review one by one. I'll keep you updated. Maybe we need to add some check boxes in this issue or a new one to track the progress and keep people informed about the API changes. |
To simplify the tracking of remaining PRs, I put here the related list:
|
Maybe @kYc0o you want to have a look ? |
Do you really want to get them in while the I2C embargo is ongoing? |
That would be nice, I won't have to rebase them after :) |
And the embargo is at a very early stage (waiting for CPU implementations). |
Another solution would be to close those PRs and to reopen them on the embargo branch |
After the I2C rework, the remaining adapted drivers were merged. So I consider this issue as resolved and will close it. Feel free to reopen if you disagree. |
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:
This way, if a board or application can override the device config by re-defining the
DEVX_PARAMS
andDEVX_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:
What do you guys think about this?
The text was updated successfully, but these errors were encountered: