Lines Matching +full:num +full:- +full:channels

1 // SPDX-License-Identifier: GPL-2.0-only
12 * generic_buffer -n <device_name> -t <trigger_name>
38 * enum autochan - state for the automatic channel enabling mechanism
47 * size_from_channelarray() - calculate the storage size of a scan
48 * @channels: the channel info array
49 * @num_channels: number of channels
51 * Has the side effect of filling the channels[i].location values used
54 static unsigned int size_from_channelarray(struct iio_channel_info *channels, int num_channels) in size_from_channelarray() argument
61 if (channels[i].bytes > max) in size_from_channelarray()
62 max = channels[i].bytes; in size_from_channelarray()
63 if (bytes % channels[i].bytes == 0) in size_from_channelarray()
64 channels[i].location = bytes; in size_from_channelarray()
66 channels[i].location = bytes - bytes % channels[i].bytes in size_from_channelarray()
67 + channels[i].bytes; in size_from_channelarray()
69 bytes = channels[i].location + channels[i].bytes; in size_from_channelarray()
79 bytes += max - misalignment; in size_from_channelarray()
90 input >>= info->shift; in print1byte()
91 input &= info->mask; in print1byte()
92 if (info->is_signed) { in print1byte()
93 int8_t val = (int8_t)(input << (8 - info->bits_used)) >> in print1byte()
94 (8 - info->bits_used); in print1byte()
95 printf("%05f ", ((float)val + info->offset) * info->scale); in print1byte()
97 printf("%05f ", ((float)input + info->offset) * info->scale); in print1byte()
104 if (info->be) in print2byte()
113 input >>= info->shift; in print2byte()
114 input &= info->mask; in print2byte()
115 if (info->is_signed) { in print2byte()
116 int16_t val = (int16_t)(input << (16 - info->bits_used)) >> in print2byte()
117 (16 - info->bits_used); in print2byte()
118 printf("%05f ", ((float)val + info->offset) * info->scale); in print2byte()
120 printf("%05f ", ((float)input + info->offset) * info->scale); in print2byte()
127 if (info->be) in print4byte()
136 input >>= info->shift; in print4byte()
137 input &= info->mask; in print4byte()
138 if (info->is_signed) { in print4byte()
139 int32_t val = (int32_t)(input << (32 - info->bits_used)) >> in print4byte()
140 (32 - info->bits_used); in print4byte()
141 printf("%05f ", ((float)val + info->offset) * info->scale); in print4byte()
143 printf("%05f ", ((float)input + info->offset) * info->scale); in print4byte()
150 if (info->be) in print8byte()
159 input >>= info->shift; in print8byte()
160 input &= info->mask; in print8byte()
161 if (info->is_signed) { in print8byte()
162 int64_t val = (int64_t)(input << (64 - info->bits_used)) >> in print8byte()
163 (64 - info->bits_used); in print8byte()
165 if (info->scale == 1.0f && info->offset == 0.0f) in print8byte()
169 ((float)val + info->offset) * info->scale); in print8byte()
171 printf("%05f ", ((float)input + info->offset) * info->scale); in print8byte()
176 * process_scan() - print out the values in SI units
178 * @channels: information about the channels.
181 * @num_channels: number of channels
183 static void process_scan(char *data, struct iio_channel_info *channels, in process_scan() argument
189 switch (channels[k].bytes) { in process_scan()
192 print1byte(*(uint8_t *)(data + channels[k].location), in process_scan()
193 &channels[k]); in process_scan()
196 print2byte(*(uint16_t *)(data + channels[k].location), in process_scan()
197 &channels[k]); in process_scan()
200 print4byte(*(uint32_t *)(data + channels[k].location), in process_scan()
201 &channels[k]); in process_scan()
204 print8byte(*(uint64_t *)(data + channels[k].location), in process_scan()
205 &channels[k]); in process_scan()
222 scanelemdir[sizeof(scanelemdir)-1] = '\0'; in enable_disable_all_channels()
226 fprintf(stderr, "Enabling/disabling channels: can't open %s\n", in enable_disable_all_channels()
228 return -EIO; in enable_disable_all_channels()
231 ret = -ENOENT; in enable_disable_all_channels()
233 if (iioutils_check_suffix(ent->d_name, "_en")) { in enable_disable_all_channels()
236 ent->d_name); in enable_disable_all_channels()
237 ret = write_sysfs_int(ent->d_name, scanelemdir, in enable_disable_all_channels()
241 ent->d_name); in enable_disable_all_channels()
245 if (closedir(dp) == -1) { in enable_disable_all_channels()
246 perror("Enabling/disabling channels: " in enable_disable_all_channels()
248 return -errno; in enable_disable_all_channels()
257 " -a Auto-activate all available channels\n" in print_usage()
258 " -A Force-activate ALL channels\n" in print_usage()
259 " -b <n> The buffer which to open (by index), default 0\n" in print_usage()
260 " -c <n> Do n conversions, or loop forever if n < 0\n" in print_usage()
261 " -e Disable wait for event (new data)\n" in print_usage()
262 " -g Use trigger-less mode\n" in print_usage()
263 " -l <n> Set buffer length to n samples\n" in print_usage()
264 " --device-name -n <name>\n" in print_usage()
265 " --device-num -N <num>\n" in print_usage()
267 " --trigger-name -t <name>\n" in print_usage()
268 " --trigger-num -T <num>\n" in print_usage()
270 " -w <n> Set delay between reads in us (event-less mode)\n"); in print_usage()
285 /* Disconnect the trigger - just write a dummy name. */ in cleanup()
290 strerror(-ret)); in cleanup()
299 strerror(-ret)); in cleanup()
302 /* Disable channels if auto-enabled */ in cleanup()
306 fprintf(stderr, "Failed to disable all channels\n"); in cleanup()
315 exit(-signum); in sig_handler()
328 exit(-1); in register_cleanup()
334 { "device-name", 1, 0, 'n' },
335 { "device-num", 1, 0, 'N' },
336 { "trigger-name", 1, 0, 't' },
337 { "trigger-num", 1, 0, 'T' },
352 int fd = -1; in main()
353 int buf_fd = -1; in main()
360 int dev_num = -1, trig_num = -1; in main()
368 struct iio_channel_info *channels = NULL; in main() local
373 NULL)) != -1) { in main()
386 ret = -errno; in main()
390 ret = -ERANGE; in main()
399 ret = -errno; in main()
414 ret = -errno; in main()
426 ret = -errno; in main()
437 return -errno; in main()
443 ret = -errno; in main()
449 ret = -1; in main()
458 ret = -1; in main()
461 fprintf(stderr, "Only one of --device-num or --device-name needs to be set\n"); in main()
463 ret = -1; in main()
477 return -ENOMEM; in main()
482 ret = -ENOMEM; in main()
493 printf("trigger-less mode selected\n"); in main()
498 return -ENOMEM; in main()
502 ret = -ENOMEM; in main()
520 "%s-dev%d", device_name, dev_num); in main()
522 ret = -ENOMEM; in main()
527 /* Look for this "-devN" trigger */ in main()
530 /* OK try the simpler "-trigger" suffix instead */ in main()
533 "%s-trigger", device_name); in main()
535 ret = -ENOMEM; in main()
552 * Parse the files in scan_elements to identify what channels are in main()
555 ret = build_channel_array(dev_dir_name, buffer_idx, &channels, &num_channels); in main()
563 fprintf(stderr, "Auto-channels selected but some channels " in main()
565 fprintf(stderr, "Proceeding without activating any channels\n"); in main()
570 fprintf(stderr, "Enabling all channels\n"); in main()
574 fprintf(stderr, "Failed to enable all channels\n"); in main()
578 /* This flags that we need to disable the channels again */ in main()
581 ret = build_channel_array(dev_dir_name, buffer_idx, &channels, in main()
590 fprintf(stderr, "Still no channels after " in main()
591 "auto-enabling, giving up\n"); in main()
598 "No channels are enabled, we have nothing to scan.\n"); in main()
599 fprintf(stderr, "Enable channels manually in " in main()
601 "/*_en or pass -a to autoenable channels and " in main()
603 ret = -ENOENT; in main()
615 ret = -ENOMEM; in main()
622 ret = -errno; in main()
628 ret = -EFAULT; in main()
650 ret = -ENOMEM; in main()
656 if (fd == -1) { /* TODO: If it isn't there make the node */ in main()
657 ret = -errno; in main()
666 if (ret == -1 || buf_fd == -1) { in main()
667 ret = -errno; in main()
668 if (ret == -ENODEV || ret == -EINVAL) in main()
687 buf_dir_name, strerror(-ret)); in main()
691 scan_size = size_from_channelarray(channels, num_channels); in main()
696 ret = -EFAULT; in main()
703 ret = -ENOMEM; in main()
715 if (read_size > -1 || errno != EBUSY) { in main()
716 ret = -EFAULT; in main()
723 if (close(fd) == -1) in main()
725 fd = -1; in main()
734 ret = poll(&pfd, 1, -1); in main()
736 ret = -errno; in main()
758 process_scan(data + scan_size * i, channels, in main()
765 if (fd >= 0 && close(fd) == -1) in main()
767 if (buf_fd >= 0 && close(buf_fd) == -1) in main()
772 for (i = num_channels - 1; i >= 0; i--) { in main()
773 free(channels[i].name); in main()
774 free(channels[i].generic_name); in main()
776 free(channels); in main()