1 /*
2 * Copyright (c) 2018 Prevas A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/shell/shell.h>
8 #include <stdlib.h>
9 #include <zephyr/drivers/adc.h>
10 #include <ctype.h>
11 #include <zephyr/sys/util.h>
12 #include <zephyr/devicetree.h>
13
14
15 #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
16 #include <zephyr/logging/log.h>
17 LOG_MODULE_REGISTER(adc_shell);
18
19 #define CMD_HELP_ACQ_TIME \
20 "Configure acquisition time." \
21 "\nUsage: acq_time <time> <unit>" \
22 "\nunits: us, ns, ticks\n"
23
24 #define CMD_HELP_CHANNEL \
25 "Configure ADC channel\n" \
26
27 #define CMD_HELP_CH_ID \
28 "Configure channel id\n" \
29 "Usage: id <channel_id>\n"
30
31 #define CMD_HELP_DIFF \
32 "Configure differential\n" \
33 "Usage: differential <0||1>\n"
34
35 #define CMD_HELP_CH_NEG \
36 "Configure channel negative input\n" \
37 "Usage: negative <negative_input_id>\n"
38
39 #define CMD_HELP_CH_POS \
40 "Configure channel positive input\n" \
41 "Usage: positive <positive_input_id>\n"
42
43 #define CMD_HELP_READ \
44 "Read adc value\n" \
45 "Usage: read <channel>\n"
46
47 #define CMD_HELP_RES \
48 "Configure resolution\n" \
49 "Usage: resolution <resolution>\n"
50
51 #define CMD_HELP_REF "Configure reference\n"
52 #define CMD_HELP_GAIN "Configure gain.\n"
53 #define CMD_HELP_PRINT "Print current configuration"
54
55 #define ADC_HDL_LIST_ENTRY(node_id) \
56 { \
57 .dev = DEVICE_DT_GET(node_id), \
58 .channel_config = \
59 { \
60 .gain = ADC_GAIN_1, \
61 .reference = ADC_REF_INTERNAL, \
62 .acquisition_time = ADC_ACQ_TIME_DEFAULT, \
63 .channel_id = 0, \
64 }, \
65 .resolution = 0, \
66 },
67
68 #define CHOSEN_STR_LEN 20
69 static char chosen_reference[CHOSEN_STR_LEN + 1] = "INTERNAL";
70 static char chosen_gain[CHOSEN_STR_LEN + 1] = "1";
71
72 static struct adc_hdl {
73 const struct device *dev;
74 struct adc_channel_cfg channel_config;
75 uint8_t resolution;
76 } adc_list[] = {
77 /* zephyr-keep-sorted-start */
78 DT_FOREACH_STATUS_OKAY(adi_ad4114_adc, ADC_HDL_LIST_ENTRY)
79 DT_FOREACH_STATUS_OKAY(adi_ad559x_adc, ADC_HDL_LIST_ENTRY)
80 DT_FOREACH_STATUS_OKAY(atmel_sam0_adc, ADC_HDL_LIST_ENTRY)
81 DT_FOREACH_STATUS_OKAY(atmel_sam_adc, ADC_HDL_LIST_ENTRY)
82 DT_FOREACH_STATUS_OKAY(atmel_sam_afec, ADC_HDL_LIST_ENTRY)
83 DT_FOREACH_STATUS_OKAY(espressif_esp32_adc, ADC_HDL_LIST_ENTRY)
84 DT_FOREACH_STATUS_OKAY(gd_gd32_adc, ADC_HDL_LIST_ENTRY)
85 DT_FOREACH_STATUS_OKAY(infineon_cat1_adc, ADC_HDL_LIST_ENTRY)
86 DT_FOREACH_STATUS_OKAY(infineon_xmc4xxx_adc, ADC_HDL_LIST_ENTRY)
87 DT_FOREACH_STATUS_OKAY(ite_it8xxx2_adc, ADC_HDL_LIST_ENTRY)
88 DT_FOREACH_STATUS_OKAY(lltc_ltc2451, ADC_HDL_LIST_ENTRY)
89 DT_FOREACH_STATUS_OKAY(maxim_max11102, ADC_HDL_LIST_ENTRY)
90 DT_FOREACH_STATUS_OKAY(maxim_max11103, ADC_HDL_LIST_ENTRY)
91 DT_FOREACH_STATUS_OKAY(maxim_max11105, ADC_HDL_LIST_ENTRY)
92 DT_FOREACH_STATUS_OKAY(maxim_max11106, ADC_HDL_LIST_ENTRY)
93 DT_FOREACH_STATUS_OKAY(maxim_max11110, ADC_HDL_LIST_ENTRY)
94 DT_FOREACH_STATUS_OKAY(maxim_max11111, ADC_HDL_LIST_ENTRY)
95 DT_FOREACH_STATUS_OKAY(maxim_max11115, ADC_HDL_LIST_ENTRY)
96 DT_FOREACH_STATUS_OKAY(maxim_max11116, ADC_HDL_LIST_ENTRY)
97 DT_FOREACH_STATUS_OKAY(maxim_max11117, ADC_HDL_LIST_ENTRY)
98 DT_FOREACH_STATUS_OKAY(maxim_max11253, ADC_HDL_LIST_ENTRY)
99 DT_FOREACH_STATUS_OKAY(maxim_max11254, ADC_HDL_LIST_ENTRY)
100 DT_FOREACH_STATUS_OKAY(microchip_mcp3204, ADC_HDL_LIST_ENTRY)
101 DT_FOREACH_STATUS_OKAY(microchip_mcp3208, ADC_HDL_LIST_ENTRY)
102 DT_FOREACH_STATUS_OKAY(microchip_xec_adc, ADC_HDL_LIST_ENTRY)
103 DT_FOREACH_STATUS_OKAY(nordic_nrf_adc, ADC_HDL_LIST_ENTRY)
104 DT_FOREACH_STATUS_OKAY(nordic_nrf_saadc, ADC_HDL_LIST_ENTRY)
105 DT_FOREACH_STATUS_OKAY(nuvoton_npcx_adc, ADC_HDL_LIST_ENTRY)
106 DT_FOREACH_STATUS_OKAY(nuvoton_numaker_adc, ADC_HDL_LIST_ENTRY)
107 DT_FOREACH_STATUS_OKAY(nxp_adc12, ADC_HDL_LIST_ENTRY)
108 DT_FOREACH_STATUS_OKAY(nxp_gau_adc, ADC_HDL_LIST_ENTRY)
109 DT_FOREACH_STATUS_OKAY(nxp_kinetis_adc16, ADC_HDL_LIST_ENTRY)
110 DT_FOREACH_STATUS_OKAY(nxp_lpc_lpadc, ADC_HDL_LIST_ENTRY)
111 DT_FOREACH_STATUS_OKAY(nxp_mcux_12b1msps_sar, ADC_HDL_LIST_ENTRY)
112 DT_FOREACH_STATUS_OKAY(nxp_s32_adc_sar, ADC_HDL_LIST_ENTRY)
113 DT_FOREACH_STATUS_OKAY(nxp_vf610_adc, ADC_HDL_LIST_ENTRY)
114 DT_FOREACH_STATUS_OKAY(raspberrypi_pico_adc, ADC_HDL_LIST_ENTRY)
115 DT_FOREACH_STATUS_OKAY(renesas_smartbond_adc, ADC_HDL_LIST_ENTRY)
116 DT_FOREACH_STATUS_OKAY(renesas_smartbond_sdadc, ADC_HDL_LIST_ENTRY)
117 DT_FOREACH_STATUS_OKAY(silabs_gecko_adc, ADC_HDL_LIST_ENTRY)
118 DT_FOREACH_STATUS_OKAY(silabs_gecko_iadc, ADC_HDL_LIST_ENTRY)
119 DT_FOREACH_STATUS_OKAY(st_stm32_adc, ADC_HDL_LIST_ENTRY)
120 DT_FOREACH_STATUS_OKAY(st_stm32f1_adc, ADC_HDL_LIST_ENTRY)
121 DT_FOREACH_STATUS_OKAY(st_stm32f4_adc, ADC_HDL_LIST_ENTRY)
122 DT_FOREACH_STATUS_OKAY(telink_b91_adc, ADC_HDL_LIST_ENTRY)
123 DT_FOREACH_STATUS_OKAY(ti_ads1013, ADC_HDL_LIST_ENTRY)
124 DT_FOREACH_STATUS_OKAY(ti_ads1014, ADC_HDL_LIST_ENTRY)
125 DT_FOREACH_STATUS_OKAY(ti_ads1015, ADC_HDL_LIST_ENTRY)
126 DT_FOREACH_STATUS_OKAY(ti_ads1112, ADC_HDL_LIST_ENTRY)
127 DT_FOREACH_STATUS_OKAY(ti_ads1113, ADC_HDL_LIST_ENTRY)
128 DT_FOREACH_STATUS_OKAY(ti_ads1114, ADC_HDL_LIST_ENTRY)
129 DT_FOREACH_STATUS_OKAY(ti_ads1115, ADC_HDL_LIST_ENTRY)
130 DT_FOREACH_STATUS_OKAY(ti_ads1119, ADC_HDL_LIST_ENTRY)
131 DT_FOREACH_STATUS_OKAY(ti_ads114s08, ADC_HDL_LIST_ENTRY)
132 DT_FOREACH_STATUS_OKAY(ti_ads7052, ADC_HDL_LIST_ENTRY)
133 DT_FOREACH_STATUS_OKAY(ti_cc13xx_cc26xx_adc, ADC_HDL_LIST_ENTRY)
134 DT_FOREACH_STATUS_OKAY(ti_cc32xx_adc, ADC_HDL_LIST_ENTRY)
135 DT_FOREACH_STATUS_OKAY(ti_lmp90077, ADC_HDL_LIST_ENTRY)
136 DT_FOREACH_STATUS_OKAY(ti_lmp90078, ADC_HDL_LIST_ENTRY)
137 DT_FOREACH_STATUS_OKAY(ti_lmp90079, ADC_HDL_LIST_ENTRY)
138 DT_FOREACH_STATUS_OKAY(ti_lmp90080, ADC_HDL_LIST_ENTRY)
139 DT_FOREACH_STATUS_OKAY(ti_lmp90097, ADC_HDL_LIST_ENTRY)
140 DT_FOREACH_STATUS_OKAY(ti_lmp90098, ADC_HDL_LIST_ENTRY)
141 DT_FOREACH_STATUS_OKAY(ti_lmp90099, ADC_HDL_LIST_ENTRY)
142 DT_FOREACH_STATUS_OKAY(ti_lmp90100, ADC_HDL_LIST_ENTRY)
143 DT_FOREACH_STATUS_OKAY(ti_tla2021, ADC_HDL_LIST_ENTRY)
144 DT_FOREACH_STATUS_OKAY(ti_tla2022, ADC_HDL_LIST_ENTRY)
145 DT_FOREACH_STATUS_OKAY(ti_tla2024, ADC_HDL_LIST_ENTRY)
146 DT_FOREACH_STATUS_OKAY(zephyr_adc_emul, ADC_HDL_LIST_ENTRY)
147 /* zephyr-keep-sorted-stop */
148 };
149
get_adc(const char * device_label)150 static struct adc_hdl *get_adc(const char *device_label)
151 {
152 for (int i = 0; i < ARRAY_SIZE(adc_list); i++) {
153 if (!strcmp(device_label, adc_list[i].dev->name)) {
154 return &adc_list[i];
155 }
156 }
157
158 /* This will never happen because ADC was prompted by shell */
159 __ASSERT_NO_MSG(false);
160 return NULL;
161 }
162
cmd_adc_ch_id(const struct shell * sh,size_t argc,char ** argv)163 static int cmd_adc_ch_id(const struct shell *sh, size_t argc, char **argv)
164 {
165 /* -2: index of ADC label name */
166 struct adc_hdl *adc = get_adc(argv[-2]);
167 int retval = 0;
168
169 if (!device_is_ready(adc->dev)) {
170 shell_error(sh, "ADC device not ready");
171 return -ENODEV;
172 }
173
174 if (isdigit((unsigned char)argv[1][0]) == 0) {
175 shell_error(sh, "<channel> must be digits");
176 return -EINVAL;
177 }
178
179 adc->channel_config.channel_id = (uint8_t)strtol(argv[1], NULL, 10);
180 retval = adc_channel_setup(adc->dev, &adc->channel_config);
181 LOG_DBG("Channel setup returned %i", retval);
182
183 return retval;
184 }
185
cmd_adc_ch_diff(const struct shell * sh,size_t argc,char ** argv)186 static int cmd_adc_ch_diff(const struct shell *sh, size_t argc, char **argv)
187 {
188 /* -2: index of ADC label name */
189 struct adc_hdl *adc = get_adc(argv[-2]);
190 int retval = 0;
191 char *endptr;
192 long diff;
193
194 if (!device_is_ready(adc->dev)) {
195 shell_error(sh, "ADC device not ready");
196 return -ENODEV;
197 }
198
199 endptr = argv[1];
200 diff = strtol(argv[1], &endptr, 10);
201 if ((endptr == argv[1]) || ((diff != 0) && (diff != 1))) {
202 shell_error(sh, "<differential> must be 0 or 1");
203 return -EINVAL;
204 }
205
206 adc->channel_config.differential = (uint8_t)diff;
207 retval = adc_channel_setup(adc->dev, &adc->channel_config);
208 LOG_DBG("Channel setup returned %i", retval);
209
210 return retval;
211 }
212
cmd_adc_ch_neg(const struct shell * sh,size_t argc,char ** argv)213 static int cmd_adc_ch_neg(const struct shell *sh, size_t argc, char **argv)
214 {
215 #if CONFIG_ADC_CONFIGURABLE_INPUTS
216 /* -2: index of ADC label name */
217 struct adc_hdl *adc = get_adc(argv[-2]);
218 int retval = 0;
219
220 if (!device_is_ready(adc->dev)) {
221 shell_error(sh, "ADC device not ready");
222 return -ENODEV;
223 }
224
225 if (isdigit((unsigned char)argv[1][0]) == 0) {
226 shell_error(sh, "<negative input> must be digits");
227 return -EINVAL;
228 }
229
230 adc->channel_config.input_negative = (uint8_t)strtol(argv[1], NULL, 10);
231 retval = adc_channel_setup(adc->dev, &adc->channel_config);
232 LOG_DBG("Channel setup returned %i", retval);
233
234 return retval;
235 #else
236 return -EINVAL;
237 #endif
238 }
239
cmd_adc_ch_pos(const struct shell * sh,size_t argc,char ** argv)240 static int cmd_adc_ch_pos(const struct shell *sh, size_t argc, char **argv)
241 {
242 #if CONFIG_ADC_CONFIGURABLE_INPUTS
243 /* -2: index of ADC label name */
244 struct adc_hdl *adc = get_adc(argv[-2]);
245 int retval = 0;
246
247 if (!device_is_ready(adc->dev)) {
248 shell_error(sh, "ADC device not ready");
249 return -ENODEV;
250 }
251
252 if (isdigit((unsigned char)argv[1][0]) == 0) {
253 shell_error(sh, "<positive input> must be digits");
254 return -EINVAL;
255 }
256
257 adc->channel_config.input_positive = (uint8_t)strtol(argv[1], NULL, 10);
258 retval = adc_channel_setup(adc->dev, &adc->channel_config);
259 LOG_DBG("Channel setup returned %i", retval);
260
261 return retval;
262 #else
263 return -EINVAL;
264 #endif
265 }
266
cmd_adc_gain(const struct shell * sh,size_t argc,char ** argv,void * data)267 static int cmd_adc_gain(const struct shell *sh, size_t argc, char **argv,
268 void *data)
269 {
270 /* -2: index of ADC label name */
271 struct adc_hdl *adc = get_adc(argv[-2]);
272 enum adc_gain gain = (enum adc_gain)data;
273 int retval = -EINVAL;
274
275 if (!device_is_ready(adc->dev)) {
276 shell_error(sh, "ADC device not ready");
277 return -ENODEV;
278 }
279
280 adc->channel_config.gain = gain;
281 int len = strlen(argv[0]) > CHOSEN_STR_LEN ? CHOSEN_STR_LEN
282 : strlen(argv[0]);
283 memcpy(chosen_gain, argv[0], len);
284 chosen_gain[len] = '\0';
285 retval = adc_channel_setup(adc->dev, &adc->channel_config);
286 LOG_DBG("Channel setup returned %i", retval);
287
288 return retval;
289 }
290
cmd_adc_acq(const struct shell * sh,size_t argc,char ** argv)291 static int cmd_adc_acq(const struct shell *sh, size_t argc, char **argv)
292 {
293 /* -1 index of ADC label name */
294 struct adc_hdl *adc = get_adc(argv[-1]);
295 uint16_t acq_time;
296 int retval;
297
298 if (!device_is_ready(adc->dev)) {
299 shell_error(sh, "ADC device not ready");
300 return -ENODEV;
301 }
302
303 if (isdigit((unsigned char)argv[1][0]) == 0) {
304 shell_error(sh, "<time> must be digits");
305 return -EINVAL;
306 }
307
308 acq_time = (uint16_t)strtol(argv[1], NULL, 10);
309 if (!strcmp(argv[2], "us")) {
310 adc->channel_config.acquisition_time =
311 ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, acq_time);
312 } else if (!strcmp(argv[2], "ns")) {
313 adc->channel_config.acquisition_time =
314 ADC_ACQ_TIME(ADC_ACQ_TIME_NANOSECONDS, acq_time);
315 } else if (!strcmp(argv[2], "ticks")) {
316 adc->channel_config.acquisition_time =
317 ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, acq_time);
318 } else {
319 adc->channel_config.acquisition_time =
320 ADC_ACQ_TIME_DEFAULT;
321 }
322 retval = adc_channel_setup(adc->dev, &adc->channel_config);
323 LOG_DBG("Channel setup returned %i", retval);
324
325 return retval;
326 }
cmd_adc_reso(const struct shell * sh,size_t argc,char ** argv)327 static int cmd_adc_reso(const struct shell *sh, size_t argc, char **argv)
328 {
329 /* -1 index of ADC label name */
330 struct adc_hdl *adc = get_adc(argv[-1]);
331 int retval;
332
333 if (!device_is_ready(adc->dev)) {
334 shell_error(sh, "ADC device not ready");
335 return -ENODEV;
336 }
337
338 if (isdigit((unsigned char)argv[1][0]) == 0) {
339 shell_error(sh, "<resolution> must be digits");
340 return -EINVAL;
341 }
342
343 adc->resolution = (uint8_t)strtol(argv[1], NULL, 10);
344 retval = adc_channel_setup(adc->dev, &adc->channel_config);
345
346 return retval;
347 }
348
cmd_adc_ref(const struct shell * sh,size_t argc,char ** argv,void * data)349 static int cmd_adc_ref(const struct shell *sh, size_t argc, char **argv,
350 void *data)
351 {
352 /* -2 index of ADC label name */
353 struct adc_hdl *adc = get_adc(argv[-2]);
354 enum adc_reference reference = (enum adc_reference)data;
355 int retval = -EINVAL;
356
357 if (!device_is_ready(adc->dev)) {
358 shell_error(sh, "ADC device not ready");
359 return -ENODEV;
360 }
361
362 int len = strlen(argv[0]) > CHOSEN_STR_LEN ? CHOSEN_STR_LEN
363 : strlen(argv[0]);
364 memcpy(chosen_reference, argv[0], len);
365 chosen_reference[len] = '\0';
366
367 adc->channel_config.reference = reference;
368 retval = adc_channel_setup(adc->dev, &adc->channel_config);
369 LOG_DBG("Channel setup returned %i", retval);
370
371 return retval;
372 }
373
374 #define BUFFER_SIZE 1
cmd_adc_read(const struct shell * sh,size_t argc,char ** argv)375 static int cmd_adc_read(const struct shell *sh, size_t argc, char **argv)
376 {
377 uint8_t adc_channel_id = strtol(argv[1], NULL, 10);
378 /* -1 index of adc label name */
379 struct adc_hdl *adc = get_adc(argv[-1]);
380 int16_t m_sample_buffer[BUFFER_SIZE];
381 int retval;
382
383 if (!device_is_ready(adc->dev)) {
384 shell_error(sh, "ADC device not ready");
385 return -ENODEV;
386 }
387
388 adc->channel_config.channel_id = adc_channel_id;
389 const struct adc_sequence sequence = {
390 .channels = BIT(adc->channel_config.channel_id),
391 .buffer = m_sample_buffer,
392 .buffer_size = sizeof(m_sample_buffer),
393 .resolution = adc->resolution,
394 };
395
396 retval = adc_read(adc->dev, &sequence);
397 if (retval >= 0) {
398 shell_print(sh, "read: %i", m_sample_buffer[0]);
399 }
400
401 return retval;
402 }
403
cmd_adc_print(const struct shell * sh,size_t argc,char ** argv)404 static int cmd_adc_print(const struct shell *sh, size_t argc, char **argv)
405 {
406 /* -1 index of ADC label name */
407 struct adc_hdl *adc = get_adc(argv[-1]);
408
409 shell_print(sh, "%s:\n"
410 "Gain: %s\n"
411 "Reference: %s\n"
412 "Acquisition Time: %u\n"
413 "Channel ID: %u\n"
414 "Differential: %u\n"
415 "Resolution: %u",
416 adc->dev->name,
417 chosen_gain,
418 chosen_reference,
419 adc->channel_config.acquisition_time,
420 adc->channel_config.channel_id,
421 adc->channel_config.differential,
422 adc->resolution);
423 #if CONFIG_ADC_CONFIGURABLE_INPUTS
424 shell_print(sh, "Input positive: %u",
425 adc->channel_config.input_positive);
426 if (adc->channel_config.differential != 0) {
427 shell_print(sh, "Input negative: %u",
428 adc->channel_config.input_negative);
429 }
430 #endif
431 return 0;
432 }
433
434 SHELL_SUBCMD_DICT_SET_CREATE(sub_ref_cmds, cmd_adc_ref,
435 (VDD_1, ADC_REF_VDD_1, "VDD"),
436 (VDD_1_2, ADC_REF_VDD_1_2, "VDD/2"),
437 (VDD_1_3, ADC_REF_VDD_1_3, "VDD/3"),
438 (VDD_1_4, ADC_REF_VDD_1_4, "VDD/4"),
439 (INTERNAL, ADC_REF_INTERNAL, "Internal"),
440 (EXTERNAL_0, ADC_REF_EXTERNAL0, "External, input 0"),
441 (EXTERNAL_1, ADC_REF_EXTERNAL1, "External, input 1")
442 );
443
444 SHELL_SUBCMD_DICT_SET_CREATE(sub_gain_cmds, cmd_adc_gain,
445 (GAIN_1_6, ADC_GAIN_1_6, "x 1/6"),
446 (GAIN_1_5, ADC_GAIN_1_5, "x 1/5"),
447 (GAIN_1_4, ADC_GAIN_1_4, "x 1/4"),
448 (GAIN_1_3, ADC_GAIN_1_3, "x 1/3"),
449 (GAIN_1_2, ADC_GAIN_1_2, "x 1/2"),
450 (GAIN_2_3, ADC_GAIN_2_3, "x 2/3"),
451 (GAIN_1, ADC_GAIN_1, "x 1"),
452 (GAIN_2, ADC_GAIN_2, "x 2"),
453 (GAIN_3, ADC_GAIN_3, "x 3"),
454 (GAIN_4, ADC_GAIN_4, "x 4"),
455 (GAIN_8, ADC_GAIN_8, "x 8"),
456 (GAIN_16, ADC_GAIN_16, "x 16"),
457 (GAIN_32, ADC_GAIN_32, "x 32"),
458 (GAIN_64, ADC_GAIN_64, "x 64")
459 );
460
461 SHELL_STATIC_SUBCMD_SET_CREATE(sub_channel_cmds,
462 SHELL_CMD_ARG(id, NULL, CMD_HELP_CH_ID, cmd_adc_ch_id, 2, 0),
463 SHELL_CMD_ARG(differential, NULL, CMD_HELP_DIFF, cmd_adc_ch_diff, 2, 0),
464 SHELL_COND_CMD_ARG(CONFIG_ADC_CONFIGURABLE_INPUTS,
465 negative, NULL, CMD_HELP_CH_NEG, cmd_adc_ch_neg, 2, 0),
466 SHELL_COND_CMD_ARG(CONFIG_ADC_CONFIGURABLE_INPUTS,
467 positive, NULL, CMD_HELP_CH_POS, cmd_adc_ch_pos, 2, 0),
468 SHELL_SUBCMD_SET_END
469 );
470
471 SHELL_STATIC_SUBCMD_SET_CREATE(sub_adc_cmds,
472 /* Alphabetically sorted. */
473 SHELL_CMD_ARG(acq_time, NULL, CMD_HELP_ACQ_TIME, cmd_adc_acq, 3, 0),
474 SHELL_CMD_ARG(channel, &sub_channel_cmds, CMD_HELP_CHANNEL, NULL, 3, 0),
475 SHELL_CMD(gain, &sub_gain_cmds, CMD_HELP_GAIN, NULL),
476 SHELL_CMD_ARG(print, NULL, CMD_HELP_PRINT, cmd_adc_print, 1, 0),
477 SHELL_CMD_ARG(read, NULL, CMD_HELP_READ, cmd_adc_read, 2, 0),
478 SHELL_CMD(reference, &sub_ref_cmds, CMD_HELP_REF, NULL),
479 SHELL_CMD_ARG(resolution, NULL, CMD_HELP_RES, cmd_adc_reso, 2, 0),
480 SHELL_SUBCMD_SET_END /* Array terminated. */
481 );
482
cmd_adc_dev_get(size_t idx,struct shell_static_entry * entry)483 static void cmd_adc_dev_get(size_t idx, struct shell_static_entry *entry)
484 {
485 if (idx < ARRAY_SIZE(adc_list)) {
486 entry->syntax = adc_list[idx].dev->name;
487 entry->handler = NULL;
488 entry->subcmd = &sub_adc_cmds;
489 entry->help = "Select subcommand for ADC property label.";
490 } else {
491 entry->syntax = NULL;
492 }
493 }
494 SHELL_DYNAMIC_CMD_CREATE(sub_adc_dev, cmd_adc_dev_get);
495
496 SHELL_CMD_REGISTER(adc, &sub_adc_dev, "ADC commands", NULL);
497