一、kernel/include/linux/iio/iio.h
1.iio_dev結構體
struct iio_dev {int id;struct module *driver_module;int modes;//表示設備支持的不同操作模式int currentmode;//表示設備實際使用的模式struct device dev;//表示IIO設備所依賴的struct設備(根據Linux設備型號)struct iio_event_interface *event_interface;struct iio_buffer *buffer;//數據緩沖區,在使用觸發緩沖區模式時會推送到用戶空間struct list_head buffer_list;int scan_bytes;//這是捕獲并饋送到緩沖區的字節數。struct mutex mlock;const unsigned long *available_scan_masks;//允許的位掩碼的可選數組unsigned masklength;const unsigned long *active_scan_mask;//啟用通道的位掩碼,只有來自這些通道的數據能被推入緩沖區bool scan_timestamp;//否將捕獲時間戳推入緩沖區unsigned scan_index_timestamp;struct iio_trigger *trig;//當前設備觸發器(支持緩沖模式時)bool trig_readonly;struct iio_poll_func *pollfunc;//在接收的觸發器上運行的函數struct iio_poll_func *pollfunc_event;struct iio_chan_spec const *channels;//表示通道規范結構,用于描述設備具有的每個通道int num_channels;//表示通道中指定的通道數struct list_head channel_attr_list;struct attribute_group chan_attr_group;const char *name;//表示設備名稱const struct iio_info *info;//來自驅動程序的回調和持續信息clockid_t clock_id;struct mutex info_exist_lock;const struct iio_buffer_setup_ops *setup_ops;//啟用/禁用緩沖區之前和之后調用的回調函數集struct cdev chrdev;//由IIO核心創建的關聯字符設備
#define IIO_MAX_GROUPS 6const struct attribute_group *groups[IIO_MAX_GROUPS + 1];int groupcounter;unsigned long flags;
#if defined(CONFIG_DEBUG_FS)struct dentry *debugfs_dentry;unsigned cached_reg_addr;
#endif
};
enum max3012_led_idx {MAX30102_LED_RED,MAX30102_LED_IR,MAX30105_LED_GREEN,
};
//可選
static const unsigned long max30102_scan_masks[] = {BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR),0
};
static const unsigned long max30105_scan_masks[] = {BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR),BIT(MAX30102_LED_RED) | BIT(MAX30102_LED_IR) |BIT(MAX30105_LED_GREEN),0
};
indio_dev->available_scan_masks = max30105_scan_masks;
for_each_set_bit(bit, indio_dev->active_scan_mask,indio_dev->masklength) {ret = kmx61_read_measurement(data, base, bit);if (ret < 0) {mutex_unlock(&data->lock);goto err;}buffer[i++] = ret;}
2.iio_info結構體
//kernel/include/linux/iio/iio.h
struct iio_info {const struct attribute_group *event_attrs;const struct attribute_group *attrs;//表示設備屬性//用戶讀取設備sysfs文件屬性時的回調運行int (*read_raw)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask);int (*read_raw_multi)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int max_len,int *vals,int *val_len,long mask);int (*read_avail)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,const int **vals,int *type,int *length,long mask);//用于將值寫入設備的回調int (*write_raw)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int val,int val2,long mask);int (*write_raw_get_fmt)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,long mask);int (*read_event_config)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir);int (*write_event_config)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir,int state);int (*read_event_value)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir,enum iio_event_info info, int *val, int *val2);int (*write_event_value)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir,enum iio_event_info info, int val, int val2);int (*validate_trigger)(struct iio_dev *indio_dev,struct iio_trigger *trig);int (*update_scan_mode)(struct iio_dev *indio_dev,const unsigned long *scan_mask);int (*debugfs_reg_access)(struct iio_dev *indio_dev,unsigned reg, unsigned writeval,unsigned *readval);int (*of_xlate)(struct iio_dev *indio_dev,const struct of_phandle_args *iiospec);int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned val);int (*hwfifo_flush_to_buffer)(struct iio_dev *indio_dev,unsigned count);
};
//示例
static const struct iio_info kmx61_acc_info = {.read_raw = kmx61_read_raw,.write_raw = kmx61_write_raw,.attrs = &kmx61_acc_attribute_group,.read_event_value = kmx61_read_event,.write_event_value = kmx61_write_event,.read_event_config = kmx61_read_event_config,.write_event_config = kmx61_write_event_config,.validate_trigger = kmx61_acc_validate_trigger,
};
indio_dev->info = &kmx61_acc_info;
3.iio_chan_spec結構體
//通道代表單條采集線
struct iio_chan_spec {enum iio_chan_type type;//指定了通道的測量類型int channel;//指定.indexed設置為1時的通道索引int channel2;//指定.modified設置為1時的通道修飾unsigned long address;
//scan_index and scan_type: 當使用緩沖區觸發器時,這些字段用于標識緩沖區中的元素int scan_index;//設置緩沖區內捕獲的通道的位置,.scan_index=-1將阻止通道緩沖捕獲struct {char sign; //'s' or 'u'描述有符號和無符號u8 realbits;//有效位數u8 storagebits;//Realbits + paddingu8 shift;u8 repeat;enum iio_endian endianness; //little or big endian,字節序} scan_type;long info_mask_separate;//將屬性標記為特定于此通道long info_mask_separate_available;long info_mask_shared_by_type;//將該屬性標記為由相同類型的所有通道共享long info_mask_shared_by_type_available;long info_mask_shared_by_dir;//將屬性標記為由同一方向的所有通道共享long info_mask_shared_by_dir_available;long info_mask_shared_by_all;//將屬性標記為所有通道共享long info_mask_shared_by_all_available;const struct iio_event_spec *event_spec;unsigned int num_event_specs;const struct iio_chan_spec_ext_info *ext_info;//描述一個channel擴展屬性相關的信息,包括屬性名稱、讀寫接口等const char *extend_name;const char *datasheet_name;unsigned modified:1;//指定是否將修飾符應用于此通道屬性名稱,飾符設置在.channel2中unsigned indexed:1;//指定通道屬性名稱是否具有索引,若是,在.channel字段中指定索引unsigned output:1; //channel是輸出unsigned differential:1;
};
//type對應的通道類型根據iio_chan_type_name_spec
static const char * const iio_chan_type_name_spec[] = {[IIO_VOLTAGE] = "voltage",[IIO_CURRENT] = "current",[IIO_POWER] = "power",[IIO_ACCEL] = "accel",
};
//channel2字段根據modifier=1時iio_modifier_names
static const char * const iio_modifier_names[] = {[IIO_MOD_X] = "x",[IIO_MOD_Y] = "y",[IIO_MOD_Z] = "z",[IIO_MOD_X_AND_Y] = "x&y",
};
//info_mask取決于char數組iio_chan_info_postfix中的通道信息掩碼
static const char * const iio_chan_info_postfix[] = {[IIO_CHAN_INFO_RAW] = "raw",[IIO_CHAN_INFO_PROCESSED] = "input",[IIO_CHAN_INFO_SCALE] = "scale",[IIO_CHAN_INFO_OFFSET] = "offset",
};
參考鏈接請點擊而此處
IIO子系統概述請點擊此處
在學習中進步,如有錯誤,請多多批評指正
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态