no-OS
Macros | Functions | Variables
iio_adc_demo.c File Reference

Implementation of iio_adc_demo. More...

#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "no_os_error.h"
#include "no_os_util.h"
#include "iio_adc_demo.h"
#include "iio.h"
Include dependency graph for iio_adc_demo.c:

Macros

#define ADC_DEMO_ATTR(_name, _priv)
 
#define IIO_DEMO_ADC_CHANNEL(_idx)
 

Functions

int get_adc_demo_attr (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
 get attributes for adc. More...
 
int set_adc_demo_attr (void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
 set attributes for adc. More...
 
int32_t adc_submit_samples (struct iio_device_data *dev_data)
 function for reading samples from the device. More...
 
int32_t adc_demo_trigger_handler (struct iio_device_data *dev_data)
 Handles trigger: reads one data-set and writes it to the buffer. More...
 

Variables

struct scan_type adc_scan_type
 
struct iio_attribute adc_channel_attributes []
 
struct iio_attribute iio_adc_global_attributes []
 
struct iio_device adc_demo_iio_descriptor
 

Detailed Description

Implementation of iio_adc_demo.

Author
Andrei Drimbarean (andre.nosp@m.i.dr.nosp@m.imbar.nosp@m.ean@.nosp@m.analo.nosp@m.g.co.nosp@m.m)

Copyright 2021(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ ADC_DEMO_ATTR

#define ADC_DEMO_ATTR (   _name,
  _priv 
)
Value:
{\
.name = _name,\
.priv = _priv,\
.store = set_adc_demo_attr \
}

◆ IIO_DEMO_ADC_CHANNEL

#define IIO_DEMO_ADC_CHANNEL (   _idx)
Value:
{\
.name = "adc_in_ch" # _idx,\
.ch_type = IIO_VOLTAGE,\
.channel = _idx,\
.scan_index = _idx,\
.indexed = true,\
.scan_type = &adc_scan_type,\
.attributes = adc_channel_attributes,\
.ch_out = false,\
}

Function Documentation

◆ adc_demo_trigger_handler()

int32_t adc_demo_trigger_handler ( struct iio_device_data dev_data)

Handles trigger: reads one data-set and writes it to the buffer.

Parameters
dev_data- The iio device data structure.
Returns
ret - Result of the handling procedure. In case of success, the size of the written data is returned.

◆ adc_submit_samples()

int32_t adc_submit_samples ( struct iio_device_data dev_data)

function for reading samples from the device.

Parameters
dev_data- The iio device data structure.
Returns
the number of read samples.

◆ get_adc_demo_attr()

int get_adc_demo_attr ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info channel,
intptr_t  attr_id 
)

get attributes for adc.

Parameters
device-Physical instance of a iio_demo_device.
buf- Where value is stored.
len- Maximum length of value to be stored in buf.
channel- Channel properties.
attr_id- Attribute ID
Returns
Length of chars written in buf, or negative value on failure.

◆ set_adc_demo_attr()

int set_adc_demo_attr ( void *  device,
char *  buf,
uint32_t  len,
const struct iio_ch_info channel,
intptr_t  attr_id 
)

set attributes for adc.

Parameters
device- Physical instance of a iio_demo_device.
buf- Value to be written to attribute.
len- Length of the data in "buf".
channel- Channel properties.
attr_id- Attribute ID
Returns
: Number of bytes written to device, or negative value on failure.

Variable Documentation

◆ adc_channel_attributes

struct iio_attribute adc_channel_attributes[]
Initial value:

◆ adc_demo_iio_descriptor

struct iio_device adc_demo_iio_descriptor
Initial value:
= {
.num_ch = TOTAL_ADC_CHANNELS,
.channels = iio_adc_channels,
.debug_attributes = NULL,
.buffer_attributes = NULL,
.pre_enable = update_adc_channels,
.post_disable = close_adc_channels,
.trigger_handler = (int32_t (*)())adc_demo_trigger_handler,
.submit = (int32_t (*)())adc_submit_samples,
.debug_reg_read = (int32_t (*)()) adc_demo_reg_read,
.debug_reg_write = (int32_t (*)()) adc_demo_reg_write
}

◆ adc_scan_type

struct scan_type adc_scan_type
Initial value:
= {
.sign = 's',
.realbits = 16,
.storagebits = 16,
.shift = 0,
.is_big_endian = false
}

◆ iio_adc_global_attributes

struct iio_attribute iio_adc_global_attributes[]
Initial value:
ADC_CHANNEL_ATTR
@ ADC_CHANNEL_ATTR
Definition: adc_demo.h:90
END_ATTRIBUTES_ARRAY
#define END_ATTRIBUTES_ARRAY
Definition: iio_types.h:116
adc_demo_trigger_handler
int32_t adc_demo_trigger_handler(struct iio_device_data *dev_data)
Handles trigger: reads one data-set and writes it to the buffer.
Definition: iio_adc_demo.c:182
adc_channel_attributes
struct iio_attribute adc_channel_attributes[]
Definition: iio_adc_demo.c:235
TOTAL_ADC_CHANNELS
#define TOTAL_ADC_CHANNELS
Definition: adc_demo.h:52
get_adc_demo_attr
int get_adc_demo_attr(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
get attributes for adc.
Definition: iio_adc_demo.c:76
close_adc_channels
int32_t close_adc_channels(void *dev)
close all channels
Definition: adc_demo.c:136
ADC_GLOBAL_ATTR
@ ADC_GLOBAL_ATTR
Definition: adc_demo.h:91
ADC_DEMO_ATTR
#define ADC_DEMO_ATTR(_name, _priv)
Definition: iio_adc_demo.c:220
adc_demo_reg_read
int32_t adc_demo_reg_read(struct adc_demo_desc *desc, uint8_t reg_index, uint8_t *readval)
read function for the adc demo driver
Definition: adc_demo.c:157
IIO_VOLTAGE
@ IIO_VOLTAGE
Definition: iio_types.h:65
set_adc_demo_attr
int set_adc_demo_attr(void *device, char *buf, uint32_t len, const struct iio_ch_info *channel, intptr_t attr_id)
set attributes for adc.
Definition: iio_adc_demo.c:107
adc_scan_type
struct scan_type adc_scan_type
Definition: iio_adc_demo.c:227
iio_channel::attributes
struct iio_attribute * attributes
Definition: iio_types.h:186
update_adc_channels
int32_t update_adc_channels(void *dev, uint32_t mask)
active adc channels
Definition: adc_demo.c:116
NULL
#define NULL
Definition: wrapper.h:64
adc_demo_reg_write
int32_t adc_demo_reg_write(struct adc_demo_desc *desc, uint8_t reg_index, uint8_t writeval)
write function for the adc demo driver
Definition: adc_demo.c:175
adc_submit_samples
int32_t adc_submit_samples(struct iio_device_data *dev_data)
function for reading samples from the device.
Definition: iio_adc_demo.c:137
iio_adc_global_attributes
struct iio_attribute iio_adc_global_attributes[]
Definition: iio_adc_demo.c:240