简体   繁体   English

如何在我的iio_info结构中添加write_raw函数

[英]How to add write_raw function in my iio_info structure

I am writing a driver using iio framework. 我正在使用iio框架编写驱动程序。 So far it goes well. 到目前为止一切顺利。 All the inputs and sysfs entries are working perfectly and the values measured are fine. 所有输入和sysfs条目都完美地工作,并且测量的值很好。 (It is very well documented and it is easy). (这是非常好的记录,很容易)。 But I need a small extension to be able to write on one of the channels. 但我需要一个小扩展才能在其中一个频道上写。 When I add my function in iio_info the compiler issues me an error: 当我在iio_info中添加我的函数时,编译器发出错误:

drivers/iio/adc/iio-ccuss.c:197:15: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .write_raw = ccuss_iio_write_raw,
               ^~~~~~~~~~~~~~~~~~~

It is very weird for me. 这对我来说很奇怪。 I even can't believe I am asking shamelessly this here but I am very frustrated. 我甚至不敢相信我在这里无耻地问这个,但我很沮丧。 I lost almost half day with that. 我失去了差不多半天。 My structure is: 我的结构是:

static const struct iio_info ccuss_iio_info = {
    .driver_module = THIS_MODULE,
    .attrs = &ccuss_iio_attribute_group,
    .read_raw = ccuss_iio_read_raw,
    .write_raw = ccuss_iio_write_raw,
};

my channel types are IIO_VOLTAGE, IIO_TEMP and IIO_HUMIDITYRELATIVE. 我的频道类型是IIO_VOLTAGE,IIO_TEMP和IIO_HUMIDITYRELATIVE。 I am start thinking to make it as an device attribute :-( if I do not receive an answer in the next 12 hours. 我开始考虑将其作为设备属性:-(如果我在接下来的12小时内没有收到答案。

Update: just to be more visible, according Murphy's comment. 根据墨菲的评论,更新:更加明显。

static int ccuss_iio_write_raw(struct iio_dev *iio,
                        struct iio_chan_spec const *channel, int *val1,
                        int *val2, long mask);

PS I do not want to remove this error by the most known way. PS我不想以最熟知的方式删除此错误。 The QA (and me) will be unhappy. QA(和我)会不高兴。 Thanks 谢谢

According to the reference the write_raw() function is declared as follows: 根据引用write_raw()函数声明如下:

int (*write_raw)(
    struct iio_dev *indio_dev,
    struct iio_chan_spec const *chan,
    int val,
    int val2,
    long mask);

Your implementation is declared like this: 您的实现声明如下:

 static int ccuss_iio_write_raw(
     struct iio_dev *iio,
     struct iio_chan_spec const *channel,
     int *val1,
     int *val2,
     long mask);

So you declare the two integer parameters as pointers, but they are expected to be passed by value. 因此,您将两个整数参数声明为指针,但它们应按值传递。 I think that's the mismatch that causes the "incompatible pointer type" error. 我认为这是导致“不兼容的指针类型”错误的不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM