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