in CodeSnippets/Peripherals/ADC/AdvancedFunctions/advanced_functions.c [351:372]
static int PollAdc(int adcControllerFd, ADC_ChannelId channelId, uint32_t *outSampleValue)
{
if (adcControllerFd < 0) {
Log_Debug("ERROR: Invalid file descriptor.\n");
return -1;
}
struct iio_ioctl_raw_channel_info rawChannelInfo = {
.size = sizeof(rawChannelInfo), .index = (int)(channelId), .mask = IIO_IOCTL_CHAN_INFO_RAW};
int result = ioctl(adcControllerFd, (int)IIO_READ_RAW_CHANNEL_INFO_IOCTL, &rawChannelInfo);
if (result < 0) {
Log_Debug(
"ERROR: ioctl call failed with error \"%s (%d)\" for request "
"IIO_READ_RAW_CHANNEL_INFO_IOCTL.\n",
strerror(errno), errno);
return -1;
}
*outSampleValue = (uint32_t)(rawChannelInfo.val);
return 0;
}