-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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: adc_shell: rework commands #28599
drivers: adc_shell: rework commands #28599
Conversation
@avigreen1978 may you please test it? |
33e1c9c
to
01bf417
Compare
drivers/adc/adc_shell.c
Outdated
#define ADC_HDL_LIST_ENTRY(inst) \ | ||
{ \ | ||
.device_name = DT_INST_LABEL(inst), \ | ||
.device_name = inst, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading it right (otherwise, please discard this comment):
While this is working and doing the expected thing, the use of inst
is misleading here.
In DT macros, we're usually calling INST the ordinal number of the node (2nd, 3rd, ..).
In ADC_HDL_LIST_ENTRY
, the argument is actually the label property value ("ADC_X" string).
So, to clarify this piece of code, I'd switch argument to something less misleading: node_label
or similar.
EDIT: Reason for which I care is that I think this is the piece of code is likely to be useful and reused in other parts of the code. So let's make it as clear as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will update the naming. It is a property label like ADC_0
or ADC_1
.
@jakub-uC basic test ok |
01bf417
to
fe4bfa2
Compare
623827d
to
7308b4b
Compare
7308b4b
to
577dc12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved from my side, but need ADC friends reviews.
577dc12
to
282444d
Compare
282444d
to
c47619a
Compare
drivers/adc/adc_shell.c
Outdated
SHELL_CMD(EXT0, NULL, "EXT0", cmd_adc_ref), | ||
SHELL_CMD(EXT1, NULL, "EXT1", cmd_adc_ref), | ||
SHELL_SUBCMD_SET_END /* Array terminated. */ | ||
SHELL_CMD_ARG(VDD_1, NULL, "VDD", cmd_adc_ref, 1, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could think at some point about shell extension which would allow creating subcommand with a dictionary. In that case argv would contain direct value. Something like
SHELL_STATIC_SUBCMD_DICT_CREATE(sub, dictionary_array)
where array contains string + value. String for tab handle, value passed to command handler. That would make code much compact in cases like this and there are many cases like this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May you please create an issue for that?
drivers/adc/adc_shell.c
Outdated
"Configure resolution\n" \ | ||
"Usage: resolution <resolution>\n" | ||
|
||
#define CMD_HELP_REF "Configure resolution\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolution => reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
drivers/adc/adc_shell.c
Outdated
&adc_list[chosen_adc].channel_config); | ||
|
||
if (IS_ENABLED(CONFIG_ADC_CONFIGURABLE_INPUTS)) { | ||
adc->channel_config.input_positive = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be hard-coded. Users should be able to select the input to use. And this value may be even invalid for some drivers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anangl Do you think it is a good idea to add one more command for setting this value?
c47619a
to
463d5b0
Compare
@anangl please take another look |
drivers/adc/adc_shell.c
Outdated
|
||
#define CMD_HELP_CH_ID \ | ||
"Configure channel id\n" \ | ||
"Usage: channel <channel_id>\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be
"Usage: channel <channel_id>\n" | |
"Usage: id <channel_id>\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
drivers/adc/adc_shell.c
Outdated
{ .string = "ADC_GAIN_8", .gain = ADC_GAIN_8 }, | ||
{ .string = "ADC_GAIN_16", .gain = ADC_GAIN_16 }, | ||
{ .string = "ADC_GAIN_32", .gain = ADC_GAIN_32 }, | ||
{ .string = "ADC_GAIN_64", .gain = ADC_GAIN_64 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add ADC_GAIN_128
as well (here and in sub_gain_cmds
), as it was added in adc.h
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
463d5b0
to
b59dd63
Compare
Last dev review we'd discussed #28566 and identified a generic way to associate devices with specific APIs. @jakub-uC are you pursuing that approach? Would doing that supersede this proposal? It's a little hard to understand what this is doing since it packs a bunch of refactoring/reformatting along with the described device access change into a single commit. I think there's a device access change in there somewhere. |
@pabigot : I think we can merge this PR and next it could be updated according to your proposal. The most important parts of the code of this change are here:
Here: A list of strings is created here:
I believe it is also part of the code that you would need to change according to your proposal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From #28599 (comment)
@pabigot : I think we can merge this PR and next it could be updated according to your proposal.
The most important parts of the code of this change are here:
This ideally would have been done in multiple, focused commits. Among all the re-ordering of help and structure definitions, conversion from array index to pointer, etc it's not at all clear what was done and why. Since this already has three approvals I'm not going to block this, but I'm not going to approve it because it's not worth the time to try to figure it all out.
@jakub-uC what about using dictionary commands? Are you plan it in this PR? |
@nordic-krch : Yes I am reworking that and splitting to different commits. |
Changed gain and reference commands to dictionary commands. This change removes an obsolete look-up table (string <-> value) for gain and reference commands. Now, each modification of gain or reference value will require only a dictionary command update. Signed-off-by: Jakub Rzeszutko <[email protected]>
Use dedicated shell macros so argument count can be validated before the command handler is executed. This change simplifies the command handlers implementation inside the adc_shell file. Signed-off-by: Jakub Rzeszutko <[email protected]>
The channel command has been extended with subcommands: id, positive, and negetive. Some boards require positive input configuration before measurement can be started. Signed-off-by: Jakub Rzeszutko <[email protected]>
ADC shell commands can be only executed on the property label existing in the device tree. It is realized by the dynamic subcommand returning existing ADC Label. Signed-off-by: Jakub Rzeszutko <[email protected]>
b59dd63
to
b097382
Compare
@pabigot I've tried to make reasonable commits. The most important is the last commit: In order to prompt valid ADC labels I've implemented dynamic command that is realized by the function If we know that the ADC label, for example, |
ADC shell commands can be only executed on the property label exiting in the device tree. It is realized by the dynamic subcommand returning the existing ADC Label.
Fixes #27350
Signed-off-by: Jakub Rzeszutko [email protected]