Paul Cercueil | 167d311 | 2014-02-18 12:23:53 +0100 | [diff] [blame] | 1 | #include "debug.h" |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 2 | #include "iio-private.h" |
| 3 | |
Paul Cercueil | 167d311 | 2014-02-18 12:23:53 +0100 | [diff] [blame] | 4 | #include <errno.h> |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 5 | #include <stdio.h> |
Paul Cercueil | 167d311 | 2014-02-18 12:23:53 +0100 | [diff] [blame] | 6 | #include <string.h> |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 7 | |
| 8 | const char * iio_channel_get_id(const struct iio_channel *chn) |
| 9 | { |
| 10 | return chn->id; |
| 11 | } |
| 12 | |
| 13 | const char * iio_channel_get_name(const struct iio_channel *chn) |
| 14 | { |
| 15 | return chn->name; |
| 16 | } |
| 17 | |
Paul Cercueil | 35a0131 | 2014-02-20 10:56:57 +0100 | [diff] [blame^] | 18 | bool iio_channel_is_output(const struct iio_channel *chn) |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 19 | { |
Paul Cercueil | 35a0131 | 2014-02-20 10:56:57 +0100 | [diff] [blame^] | 20 | return chn->is_output; |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | unsigned int iio_channel_get_attrs_count(const struct iio_channel *chn) |
| 24 | { |
| 25 | return chn->nb_attrs; |
| 26 | } |
| 27 | |
| 28 | const char * iio_channel_get_attr(const struct iio_channel *chn, |
| 29 | unsigned int index) |
| 30 | { |
| 31 | if (index >= chn->nb_attrs) |
| 32 | return NULL; |
| 33 | else |
| 34 | return chn->attrs[index]; |
| 35 | } |
| 36 | |
| 37 | ssize_t iio_channel_attr_read(const struct iio_channel *chn, |
| 38 | const char *attr, char *dst, size_t len) |
| 39 | { |
Paul Cercueil | 6a01360 | 2014-02-19 12:37:39 +0100 | [diff] [blame] | 40 | if (chn->dev->ctx->ops->read_channel_attr) |
| 41 | return chn->dev->ctx->ops->read_channel_attr(chn, |
| 42 | attr, dst, len); |
| 43 | else |
| 44 | return -ENOSYS; |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | ssize_t iio_channel_attr_write(const struct iio_channel *chn, |
| 48 | const char *attr, const char *src) |
| 49 | { |
Paul Cercueil | 6a01360 | 2014-02-19 12:37:39 +0100 | [diff] [blame] | 50 | if (chn->dev->ctx->ops->write_channel_attr) |
| 51 | return chn->dev->ctx->ops->write_channel_attr(chn, attr, src); |
| 52 | else |
| 53 | return -ENOSYS; |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 54 | } |
Paul Cercueil | 0023624 | 2014-02-18 15:09:06 +0100 | [diff] [blame] | 55 | |
| 56 | void free_channel(struct iio_channel *chn) |
| 57 | { |
| 58 | unsigned int i; |
| 59 | for (i = 0; i < chn->nb_attrs; i++) |
| 60 | free((char *) chn->attrs[i]); |
| 61 | if (chn->nb_attrs) |
| 62 | free(chn->attrs); |
| 63 | if (chn->name) |
| 64 | free((char *) chn->name); |
| 65 | if (chn->id) |
| 66 | free((char *) chn->id); |
| 67 | free(chn); |
| 68 | } |