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