Skip to content

Commit 59c0ee7

Browse files
iioutil/iiocpp: Add initial libiio v1 wrapper
Signed-off-by: Andrei-Fabian-Pop <Andreifabian.Pop@analog.com>
1 parent 2028176 commit 59c0ee7

File tree

18 files changed

+1269
-1
lines changed

18 files changed

+1269
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2025 Analog Devices Inc.
3+
*
4+
* This file is part of Scopy
5+
* (see https://www.github.com/analogdevicesinc/scopy).
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
#ifndef IIOATTRIBUTE_H
22+
#define IIOATTRIBUTE_H
23+
24+
#include "scopy-iioutil_export.h"
25+
#include <QObject>
26+
#include <iio/iio.h>
27+
28+
namespace scopy {
29+
class SCOPY_IIOUTIL_EXPORT IIOAttribute : public QObject
30+
{
31+
Q_OBJECT
32+
protected:
33+
IIOAttribute(QObject *parent = nullptr);
34+
~IIOAttribute();
35+
36+
public:
37+
IIOAttribute(const IIOAttribute &) = delete;
38+
IIOAttribute &operator=(const IIOAttribute &) = delete;
39+
40+
static IIOAttribute *GetInstance();
41+
42+
static ssize_t read_raw(const iio_attr *attr, char *dst, size_t len);
43+
static ssize_t write_raw(const iio_attr *attr, const void *src, size_t len);
44+
static const char *get_name(const iio_attr *attr);
45+
static const char *get_filename(const iio_attr *attr);
46+
static const char *get_static_value(const iio_attr *attr);
47+
48+
private:
49+
static IIOAttribute *pinstance_;
50+
};
51+
} // namespace scopy
52+
53+
#endif // IIOATTRIBUTE_H
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2024 Analog Devices Inc.
3+
*
4+
* This file is part of Scopy
5+
* (see https://www.github.com/analogdevicesinc/scopy).
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#ifndef IIOBLOCK_H
23+
#define IIOBLOCK_H
24+
25+
#include "iiocpp/iioresult.h"
26+
#include "scopy-iioutil_export.h"
27+
#include <QObject>
28+
#include <iio/iio.h>
29+
30+
namespace scopy {
31+
class SCOPY_IIOUTIL_EXPORT IIOBlock : public QObject
32+
{
33+
Q_OBJECT
34+
protected:
35+
IIOBlock(QObject *parent = nullptr);
36+
~IIOBlock();
37+
38+
public:
39+
IIOBlock(const IIOBlock &) = delete;
40+
IIOBlock &operator=(const IIOBlock &) = delete;
41+
42+
static IIOBlock *GetInstance();
43+
44+
static IIOResult<iio_block *> create_block(iio_buffer *buffer, size_t size);
45+
static void destroy(iio_block *block);
46+
static int get_dmabuf_fd(const iio_block *block);
47+
static int disable_cpu_access(iio_block *block, bool disable);
48+
static void *start(const iio_block *block);
49+
static void *first(const iio_block *block, const iio_channel *chn);
50+
static ssize_t foreach_sample(const iio_block *block, const iio_channels_mask *mask,
51+
ssize_t (*callback)(const iio_channel *chn, void *src, size_t bytes, void *d),
52+
void *data);
53+
static int enqueue(iio_block *block, size_t bytes_used, bool cyclic);
54+
static int dequeue(iio_block *block, bool nonblock);
55+
static iio_buffer *get_buffer(const iio_block *block);
56+
57+
private:
58+
static IIOBlock *pinstance_;
59+
};
60+
} // namespace scopy
61+
62+
#endif // IIOBLOCK_H
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2025 Analog Devices Inc.
3+
*
4+
* This file is part of Scopy
5+
* (see https://www.github.com/analogdevicesinc/scopy).
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
#ifndef IIOBUFFER_H
22+
#define IIOBUFFER_H
23+
24+
#include "iiocpp/iioresult.h"
25+
#include "scopy-iioutil_export.h"
26+
#include <QObject>
27+
#include <iio/iio.h>
28+
29+
namespace scopy {
30+
class SCOPY_IIOUTIL_EXPORT IIOBuffer : public QObject
31+
{
32+
Q_OBJECT
33+
34+
protected:
35+
IIOBuffer(QObject *parent = nullptr);
36+
~IIOBuffer();
37+
38+
public:
39+
IIOBuffer(const IIOBuffer &) = delete;
40+
IIOBuffer &operator=(const IIOBuffer &) = delete;
41+
42+
static IIOBuffer *GetInstance();
43+
44+
static const iio_device *get_device(const iio_buffer *buf);
45+
static unsigned int get_attrs_count(const iio_buffer *buf);
46+
static IIOResult<const iio_attr *> get_attr(const iio_buffer *buf, unsigned int index);
47+
static IIOResult<const iio_attr *> find_attr(const iio_buffer *buf, const char *name);
48+
static IIOResult<iio_buffer *> create_buffer(const iio_device *dev, unsigned int idx,
49+
const iio_channels_mask *mask);
50+
static void set_data(iio_buffer *buf, void *data);
51+
static void *get_data(const iio_buffer *buf);
52+
static void destroy(iio_buffer *buf);
53+
static void cancel(iio_buffer *buf);
54+
static int enable(iio_buffer *buf);
55+
static int disable(iio_buffer *buf);
56+
static const iio_channels_mask *get_channels_mask(const iio_buffer *buf);
57+
58+
private:
59+
static IIOBuffer *pinstance_;
60+
};
61+
} // namespace scopy
62+
63+
#endif // IIOBUFFER_H
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2025 Analog Devices Inc.
3+
*
4+
* This file is part of Scopy
5+
* (see https://www.github.com/analogdevicesinc/scopy).
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
#ifndef IIOCHANNEL_H
22+
#define IIOCHANNEL_H
23+
24+
#include "iiocpp/iioresult.h"
25+
#include "scopy-iioutil_export.h"
26+
#include <QObject>
27+
#include <iio/iio.h>
28+
29+
namespace scopy {
30+
class SCOPY_IIOUTIL_EXPORT IIOChannel : public QObject
31+
{
32+
Q_OBJECT
33+
protected:
34+
IIOChannel(QObject *parent = nullptr);
35+
~IIOChannel();
36+
37+
public:
38+
IIOChannel(const IIOChannel &) = delete;
39+
IIOChannel &operator=(const IIOChannel &) = delete;
40+
41+
static IIOChannel *GetInstance();
42+
43+
static const iio_device *get_device(const iio_channel *chn);
44+
static const char *get_id(const iio_channel *chn);
45+
static const char *get_name(const iio_channel *chn);
46+
static const char *get_label(const iio_channel *chn);
47+
static bool is_output(const iio_channel *chn);
48+
static bool is_scan_element(const iio_channel *chn);
49+
static unsigned int get_attrs_count(const iio_channel *chn);
50+
static IIOResult<const iio_attr *> get_attr(const iio_channel *chn, unsigned int index);
51+
static IIOResult<const iio_attr *> find_attr(const iio_channel *chn, const char *name);
52+
static void enable(const iio_channel *chn, iio_channels_mask *mask);
53+
static void disable(const iio_channel *chn, iio_channels_mask *mask);
54+
static bool is_enabled(const iio_channel *chn, const iio_channels_mask *mask);
55+
static size_t read(const iio_channel *chn, const iio_block *block, void *dst, size_t len, bool raw);
56+
static size_t write(const iio_channel *chn, iio_block *block, const void *src, size_t len, bool raw);
57+
static void set_data(iio_channel *chn, void *data);
58+
static void *get_data(const iio_channel *chn);
59+
static enum iio_chan_type get_type(const iio_channel *chn);
60+
static enum iio_modifier get_modifier(const iio_channel *chn);
61+
62+
private:
63+
static IIOChannel *pinstance_;
64+
};
65+
} // namespace scopy
66+
67+
#endif // IIOCHANNEL_H

iioutil/include/iioutil/iiocpp/iiocontext.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,46 @@
2121
#ifndef IIOCONTEXT_H
2222
#define IIOCONTEXT_H
2323

24+
#include "iiocpp/iioresult.h"
2425
#include "scopy-iioutil_export.h"
25-
#include <iio.h>
26+
#include <iio/iio.h>
2627
#include <QObject>
2728

2829
namespace scopy {
2930
class SCOPY_IIOUTIL_EXPORT IIOContext : public QObject
3031
{
3132
Q_OBJECT
33+
protected:
34+
IIOContext(QObject *parent = nullptr);
35+
~IIOContext();
36+
3237
public:
38+
IIOContext(const IIOContext &) = delete;
39+
IIOContext &operator=(const IIOContext &) = delete;
40+
41+
static IIOContext *GetInstance();
42+
43+
static IIOResult<iio_context *> create_context(const iio_context_params *params, const char *uri);
44+
static void destroy(iio_context *ctx);
45+
static unsigned int get_version_major(const iio_context *ctx);
46+
static unsigned int get_version_minor(const iio_context *ctx);
47+
static const char *get_version_tag(const iio_context *ctx);
48+
static IIOResult<char *> get_xml(const iio_context *ctx);
49+
static const char *get_name(const iio_context *ctx);
50+
static const char *get_description(const iio_context *ctx);
51+
static unsigned int get_attrs_count(const iio_context *ctx);
52+
static IIOResult<const iio_attr *> get_attr(const iio_context *ctx, unsigned int index);
53+
static IIOResult<const iio_attr *> find_attr(const iio_context *ctx, const char *name);
54+
static unsigned int get_devices_count(const iio_context *ctx);
55+
static IIOResult<iio_device *> get_device(const iio_context *ctx, unsigned int index);
56+
static IIOResult<iio_device *> find_device(const iio_context *ctx, const char *name);
57+
static int set_timeout(iio_context *ctx, unsigned int timeout_ms);
58+
static const iio_context_params *get_params(const iio_context *ctx);
59+
static void set_data(iio_context *ctx, void *data);
60+
static void *get_data(const iio_context *ctx);
61+
62+
private:
63+
static IIOContext *pinstance_;
3364
};
3465

3566
} // namespace scopy
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2024 Analog Devices Inc.
3+
*
4+
* This file is part of Scopy
5+
* (see https://www.github.com/analogdevicesinc/scopy).
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
#ifndef IIODEVICE_H
23+
#define IIODEVICE_H
24+
25+
#include "iiocpp/iioresult.h"
26+
#include "scopy-iioutil_export.h"
27+
#include <QObject>
28+
#include <iio/iio.h>
29+
30+
namespace scopy {
31+
class SCOPY_IIOUTIL_EXPORT IIODevice : public QObject
32+
{
33+
Q_OBJECT
34+
protected:
35+
IIODevice(QObject *parent = nullptr);
36+
~IIODevice();
37+
38+
public:
39+
IIODevice(const IIODevice &) = delete;
40+
IIODevice &operator=(const IIODevice &) = delete;
41+
42+
static IIODevice *GetInstance();
43+
44+
static const iio_context *get_context(const iio_device *dev);
45+
static const char *get_id(const iio_device *dev);
46+
static const char *get_name(const iio_device *dev);
47+
static const char *get_label(const iio_device *dev);
48+
static unsigned int get_channels_count(const iio_device *dev);
49+
static unsigned int get_attrs_count(const iio_device *dev);
50+
static IIOResult<const iio_channel *> get_channel(const iio_device *dev, unsigned int index);
51+
static IIOResult<const iio_attr *> get_attr(const iio_device *dev, unsigned int index);
52+
static IIOResult<iio_channel *> find_channel(const iio_device *dev, const char *name, bool output);
53+
static IIOResult<const iio_attr *> find_attr(const iio_device *dev, const char *name);
54+
static void set_data(iio_device *dev, void *data);
55+
static void *get_data(const iio_device *dev);
56+
static IIOResult<const iio_device *> get_trigger(const iio_device *dev);
57+
static int set_trigger(iio_device *dev, const iio_device *trigger);
58+
static bool is_trigger(const iio_device *dev);
59+
60+
private:
61+
static IIODevice *pinstance_;
62+
};
63+
} // namespace scopy
64+
65+
#endif // IIODEVICE_H

0 commit comments

Comments
 (0)