核心元素¶
工業 I/O 核心為編寫用於許多不同型別的嵌入式感測器的驅動程式提供了一個統一的框架,併為操作感測器的使用者空間應用程式提供了一個標準介面。 該實現可以在 drivers/iio/industrialio-* 下找到
工業 I/O 裝置¶
struct iio_dev- 工業 I/O 裝置iio_device_alloc()- 從驅動程式分配一個iio_deviio_device_free()- 從驅動程式釋放一個iio_deviio_device_register()- 向 IIO 子系統註冊一個裝置iio_device_unregister()- 從 IIO 子系統登出一個裝置
IIO 裝置通常對應於單個硬體感測器,它提供驅動程式處理裝置所需的所有資訊。 讓我們首先看一下嵌入在 IIO 裝置中的功能,然後我們將展示裝置驅動程式如何使用 IIO 裝置。
使用者空間應用程式可以透過兩種方式與 IIO 驅動程式進行互動。
/sys/bus/iio/devices/iio:deviceX/,這表示一個硬體感測器,並將同一晶片的資料通道組合在一起。/dev/iio:deviceX,字元裝置節點介面,用於緩衝資料傳輸和事件資訊檢索。
典型的 IIO 驅動程式將自己註冊為 I2C 或 SPI 驅動程式,並將建立兩個例程,probe 和 remove。
在 probe 中
呼叫
iio_device_alloc(),它為 IIO 裝置分配記憶體。使用驅動程式特定資訊(例如裝置名稱、裝置通道)初始化 IIO 裝置欄位。
呼叫
iio_device_register(),這會將設備註冊到 IIO 核心。 呼叫此函式後,裝置已準備好接受來自使用者空間應用程式的請求。
在 remove 中,我們以相反的順序釋放 probe 中分配的資源
iio_device_unregister(),從 IIO 核心登出裝置。iio_device_free(),釋放為 IIO 裝置分配的記憶體。
IIO 裝置 sysfs 介面¶
屬性是 sysfs 檔案,用於公開晶片資訊,並允許應用程式設定各種配置引數。 對於索引為 X 的裝置,屬性可以在 /sys/bus/iio/devices/iio:deviceX/ 目錄下找到。 常見屬性有
name,物理晶片的描述。dev,顯示與/dev/iio:deviceX節點關聯的主裝置號:次裝置號對。sampling_frequency_available,裝置可用的離散取樣頻率值集。IIO 裝置的可用標準屬性在 Linux 核心原始碼的 :file:Documentation/ABI/testing/sysfs-bus-iio 檔案中進行了描述。
IIO 裝置通道¶
struct iio_chan_spec - 單個通道的規範
IIO 裝置通道是資料通道的表示。 一個 IIO 裝置可以有一個或多個通道。 例如
溫度計感測器有一個通道,表示溫度測量。
帶有兩個通道的光感測器,指示可見光譜和紅外光譜中的測量值。
加速度計最多可以有 3 個通道,表示 X、Y 和 Z 軸上的加速度。
IIO 通道由 struct iio_chan_spec 描述。 上面示例中溫度感測器的溫度計驅動程式必須按如下方式描述其通道
static const struct iio_chan_spec temp_channel[] = {
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
},
};
暴露給使用者空間的通道 sysfs 屬性以位掩碼的形式指定。 根據它們的共享資訊,可以在以下掩碼之一中設定屬性
info_mask_separate,屬性將特定於此通道
info_mask_shared_by_type,屬性由同一型別的所有通道共享
info_mask_shared_by_dir,屬性由同一方向的所有通道共享
info_mask_shared_by_all,屬性由所有通道共享
當每個通道型別有多個數據通道時,我們有兩種方法來區分它們
將
iio_chan_spec的 .modified 欄位設定為 1。 修飾符使用同一iio_chan_spec結構的 .channel2 欄位指定,並用於指示通道的物理唯一特徵,例如其方向或光譜響應。 例如,光感測器可以有兩個通道,一個用於紅外光,一個用於紅外光和可見光。將
iio_chan_spec的 .indexed 欄位設定為 1。 在這種情況下,通道只是另一個例項,其索引由 .channel 欄位指定。
以下是如何使用通道的修飾符
static const struct iio_chan_spec light_channels[] = {
{
.type = IIO_INTENSITY,
.modified = 1,
.channel2 = IIO_MOD_LIGHT_IR,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
{
.type = IIO_INTENSITY,
.modified = 1,
.channel2 = IIO_MOD_LIGHT_BOTH,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
}
此通道的定義將生成兩個單獨的 sysfs 檔案,用於原始資料檢索
/sys/bus/iio/devices/iio:deviceX/in_intensity_ir_raw/sys/bus/iio/devices/iio:deviceX/in_intensity_both_raw
一個用於處理的資料的檔案
/sys/bus/iio/devices/iio:deviceX/in_illuminance_input
一個用於取樣頻率的共享 sysfs 檔案
/sys/bus/iio/devices/iio:deviceX/sampling_frequency.
以下是如何使用通道的索引
static const struct iio_chan_spec light_channels[] = {
{
.type = IIO_VOLTAGE,
.indexed = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
},
{
.type = IIO_VOLTAGE,
.indexed = 1,
.channel = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
},
}
這將生成兩個單獨的屬性檔案,用於原始資料檢索
/sys/bus/iio/devices/iio:deviceX/in_voltage0_raw,表示通道 0 的電壓測量。/sys/bus/iio/devices/iio:deviceX/in_voltage1_raw,表示通道 1 的電壓測量。
更多詳細資訊¶
-
struct iio_chan_spec_ext_info¶
擴充套件通道資訊屬性
定義:
struct iio_chan_spec_ext_info {
const char *name;
enum iio_shared_by shared;
ssize_t (*read)(struct iio_dev *, uintptr_t private, struct iio_chan_spec const *, char *buf);
ssize_t (*write)(struct iio_dev *, uintptr_t private,struct iio_chan_spec const *, const char *buf, size_t len);
uintptr_t private;
};
成員
name資訊屬性名稱
shared此屬性是否在所有通道之間共享。
read此資訊屬性的讀取回調,可以為 NULL。
write此資訊屬性的寫入回撥,可以為 NULL。
private驅動程式私有的資料。
-
struct iio_enum¶
列舉通道資訊屬性
定義:
struct iio_enum {
const char * const *items;
unsigned int num_items;
int (*set)(struct iio_dev *, const struct iio_chan_spec *, unsigned int);
int (*get)(struct iio_dev *, const struct iio_chan_spec *);
};
成員
items一個字串陣列。
num_items專案陣列的長度。
set設定回撥函式,可以為 NULL。
get獲取回撥函式,可以為 NULL。
描述
iio_enum 結構可用於實現列舉樣式的通道屬性。 列舉樣式屬性是指具有一組對映到無符號整數值的字串的屬性。 IIO 列舉輔助程式碼負責在值和字串之間進行對映,以及生成一個包含所有可用專案列表的 “_available” 檔案。 當屬性更新時,將呼叫設定回撥。 最後一個引數是新啟用的專案的索引。 獲取回撥將用於查詢當前活動的專案,並應返回其索引。
-
IIO_ENUM¶
IIO_ENUM (_name, _shared, _e)
初始化列舉擴充套件通道屬性
-
IIO_ENUM_AVAILABLE¶
IIO_ENUM_AVAILABLE (_name, _shared, _e)
初始化列舉可用擴充套件通道屬性
引數
_name屬性名稱(“_available” 將附加到該名稱)
_shared屬性是否在所有通道之間共享
_e指向 iio_enum 結構的指標
描述
建立一個只讀屬性,該屬性以空格分隔的列表形式列出所有可用的列舉項。 這通常應與 IIO_ENUM() 一起使用
-
struct iio_mount_matrix¶
iio 安裝矩陣
定義:
struct iio_mount_matrix {
const char *rotation[9];
};
成員
rotation定義感測器與主硬體對齊方式的 3 維空間旋轉矩陣
-
IIO_MOUNT_MATRIX¶
IIO_MOUNT_MATRIX (_shared, _get)
初始化安裝矩陣擴充套件通道屬性
引數
_shared屬性是否在所有通道之間共享
_get指向 iio_get_mount_matrix_t 訪問器的指標
-
struct iio_event_spec¶
通道事件的規範
定義:
struct iio_event_spec {
enum iio_event_type type;
enum iio_event_direction dir;
unsigned long mask_separate;
unsigned long mask_shared_by_type;
unsigned long mask_shared_by_dir;
unsigned long mask_shared_by_all;
};
成員
type事件的型別
dir事件的方向
mask_separate列舉 iio_event_info 值的位掩碼。 在此掩碼中設定的屬性將按通道註冊。
mask_shared_by_type列舉 iio_event_info 值的位掩碼。 在此掩碼中設定的屬性將由通道型別共享。
mask_shared_by_dir列舉 iio_event_info 值的位掩碼。 在此掩碼中設定的屬性將由通道型別和方向共享。
mask_shared_by_all列舉 iio_event_info 值的位掩碼。 在此掩碼中設定的屬性將由所有通道共享。
-
struct iio_scan_type¶
緩衝區中通道資料格式的規範
定義:
struct iio_scan_type {
char sign;
u8 realbits;
u8 storagebits;
u8 shift;
u8 repeat;
enum iio_endian endianness;
};
成員
sign‘s’ 或 ‘u’,用於指定有符號或無符號
realbits資料的有效位數
storagebitsRealbits + 填充
shift在遮蔽 realbits 之前,向右移動此值。
repeatreal/storage 位重複的次數。 當 repeat 元素大於 1 時,sysfs 中的 type 元素將顯示一個 repeat 值。 否則,將省略重複次數。
endianness小端或大端
-
struct iio_chan_spec¶
單個通道的規範
定義:
struct iio_chan_spec {
enum iio_chan_type type;
int channel;
int channel2;
unsigned long address;
int scan_index;
union {
struct iio_scan_type scan_type;
struct {
const struct iio_scan_type *ext_scan_type;
unsigned int num_ext_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;
const char *extend_name;
const char *datasheet_name;
unsigned int modified:1;
unsigned int indexed:1;
unsigned int output:1;
unsigned int differential:1;
unsigned int has_ext_scan_type:1;
};
成員
type通道正在進行什麼型別的測量。
channel我們希望為通道分配什麼編號。
channel2如果差分通道有第二個編號,則這是它。 如果設定了 modified,則此處的值指定修飾符。
address驅動程式特定的識別符號。
scan_index單調索引,用於在從緩衝區讀取時提供掃描中的排序。
{unnamed_union}anonymous
scan_type描述掃描型別的結構 - 與 ext_scan_type 互斥。
{unnamed_struct}anonymous
ext_scan_type用於通道存在多個掃描格式的罕見情況。 當使用此選項時,必須設定標誌 has_ext_scan_type,並且驅動程式必須在
struct iio_info中實現 get_current_scan_type。num_ext_scan_typeext_scan_type 中的元素數。
info_mask_separate要匯出哪些特定於此通道的資訊。
info_mask_separate_available要匯出哪些特定於此通道的可用性資訊。
info_mask_shared_by_type要匯出哪些由同一型別的所有通道共享的資訊。
info_mask_shared_by_type_available要匯出哪些由同一型別的所有通道共享的可用性資訊。
info_mask_shared_by_dir要匯出哪些由同一方向的所有通道共享的資訊。
info_mask_shared_by_dir_available要匯出哪些由同一方向的所有通道共享的可用性資訊。
info_mask_shared_by_all要匯出哪些由所有通道共享的資訊。
info_mask_shared_by_all_available要匯出哪些由所有通道共享的可用性資訊。
event_spec應為此通道註冊的事件陣列。
num_event_specsevent_spec 陣列的大小。
ext_info此通道的擴充套件資訊屬性陣列。 該陣列以 NULL 結尾,最後一個元素應將其 name 欄位設定為 NULL。
extend_name允許使用資訊性的名稱標記通道屬性。請注意,這與修改器不同,它對程式碼等沒有影響。此欄位已棄用,建議使用 iio_info->read_label() 來覆蓋標籤,與 extend_name 不同,它不影響 sysfs 檔名。
datasheet_name核心中用於通道對映的名稱。它應該對應於資料表中通道首次引用的名稱 (例如,IND),或最接近的複合名稱 (例如,IND-INC)。
modified修改器是否應用於此通道。這些取決於通道型別。修改器在 channel2 中設定。例如,IIO_MOD_X 用於關於“x”軸的軸向感測器。
indexed指定通道具有數字索引。如果不是,通道索引號將被 sysfs 屬性抑制,但不會被事件程式碼抑制。
output通道是輸出。
differential通道是差分的。
has_ext_scan_type如果使用 ext_scan_type 代替 scan_type,則為 True。
-
bool iio_channel_has_info(const struct iio_chan_spec *chan, enum iio_chan_info_enum type)¶
檢查通道是否支援資訊屬性
引數
const struct iio_chan_spec *chan要查詢的通道
enum iio_chan_info_enum type要檢查的資訊屬性的型別
描述
如果通道支援報告給定資訊屬性型別的值,則返回 true,否則返回 false。
-
bool iio_channel_has_available(const struct iio_chan_spec *chan, enum iio_chan_info_enum type)¶
檢查通道是否具有 available 屬性
引數
const struct iio_chan_spec *chan要查詢的通道
enum iio_chan_info_enum type要檢查的 available 屬性的型別
描述
如果通道支援報告給定屬性型別的可用值,則返回 true,否則返回 false。
-
struct iio_info¶
關於裝置的常量資訊
定義:
struct iio_info {
const struct attribute_group *event_attrs;
const struct attribute_group *attrs;
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 (*read_label)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan, char *label);
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, bool 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 (*read_event_label)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,enum iio_event_type type,enum iio_event_direction dir, char *label);
int (*validate_trigger)(struct iio_dev *indio_dev, struct iio_trigger *trig);
int (*get_current_scan_type)(const struct iio_dev *indio_dev, const struct iio_chan_spec *chan);
int (*update_scan_mode)(struct iio_dev *indio_dev, const unsigned long *scan_mask);
int (*debugfs_reg_access)(struct iio_dev *indio_dev,unsigned int reg, unsigned int writeval, unsigned int *readval);
int (*fwnode_xlate)(struct iio_dev *indio_dev, const struct fwnode_reference_args *iiospec);
int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned int val);
int (*hwfifo_flush_to_buffer)(struct iio_dev *indio_dev, unsigned int count);
};
成員
event_attrs事件控制屬性
attrs通用裝置屬性
read_raw用於從裝置請求值的函式。mask 指定哪個值。請注意,0 表示讀取有問題的通道。返回值將指定裝置返回的值的型別。val 和 val2 將包含構成返回值的元素。
read_raw_multi用於從裝置返回值的函式。mask 指定哪個值。請注意,0 表示讀取有問題的通道。返回值將指定裝置返回的值的型別。vals 指標包含構成返回值的元素。max_len 指定 vals 指標可以包含的最大元素數。val_len 用於返回 vals 中有效元素的長度。
read_avail用於從裝置返回可用值的函式。mask 指定哪個值。請注意,0 表示有問題的通道的可用值。返回值指定在 vals 中返回的是 IIO_AVAIL_LIST 還是 IIO_AVAIL_RANGE。vals 的型別在 type 中返回,vals 的數量在 length 中返回。對於範圍,始終返回三個 vals:min、step 和 max。對於列表,列舉所有可能的值。
write_raw用於將值寫入裝置的函式。引數與 read_raw 的引數相同。
read_label用於請求指定標籤的標籤名稱的函式,以便更好地識別通道。
write_raw_get_fmt回撥函式,用於查詢預期的格式/精度。如果驅動程式未設定,則 write_raw 返回 IIO_VAL_INT_PLUS_MICRO。
read_event_config查明是否啟用了事件。
write_event_config設定是否啟用了事件。
read_event_value讀取與事件關聯的配置值。
write_event_value寫入事件的配置值。
read_event_label用於請求指定標籤的標籤名稱的函式,以便更好地識別事件。
validate_trigger噹噹前觸發器發生更改時,用於驗證觸發器的函式。
get_current_scan_type必須由在通道規範中使用 ext_scan_type 的驅動程式實現,以返回通道當前活動的 ext_scan 型別的索引。
update_scan_mode用於在通道發生更改時配置裝置和掃描緩衝區的函式
debugfs_reg_access用於讀取或寫入裝置暫存器值的函式
fwnode_xlate基於 fwnode 的函式指標,用於獲取通道說明符索引。
hwfifo_set_watermark用於設定當前硬體 fifo 水位線的函式指標;有關硬體 fifo 如何執行的詳細資訊,請參閱 ABI 檔案測試/sysfs-bus-iio 中的 hwfifo_* 條目
hwfifo_flush_to_buffer用於將儲存在硬體 fifo 中的樣本重新整理到裝置緩衝區的函式指標。驅動程式不應重新整理超過 count 個樣本。該函式必須返回重新整理的樣本數,如果未重新整理樣本則返回 0,如果未重新整理樣本並且存在錯誤則返回負整數。
-
struct iio_buffer_setup_ops¶
與緩衝區設定相關的回撥
定義:
struct iio_buffer_setup_ops {
int (*preenable)(struct iio_dev *);
int (*postenable)(struct iio_dev *);
int (*predisable)(struct iio_dev *);
int (*postdisable)(struct iio_dev *);
bool (*validate_scan_mask)(struct iio_dev *indio_dev, const unsigned long *scan_mask);
};
成員
preenable[驅動程式] 在將緩衝區標記為啟用之前執行的函式
postenable[驅動程式] 在將緩衝區標記為啟用之後執行的函式
predisable[驅動程式] 在將緩衝區標記為停用之前執行的函式
postdisable[驅動程式] 在將緩衝區標記為停用之後執行的函式
validate_scan_mask[驅動程式] 用於檢查給定掃描掩碼對於裝置是否有效的函式回撥。
-
struct iio_dev¶
工業 I/O 裝置
定義:
struct iio_dev {
int modes;
struct device dev;
struct iio_buffer *buffer;
int scan_bytes;
const unsigned long *available_scan_masks;
unsigned int __private masklength;
const unsigned long *active_scan_mask;
bool __private scan_timestamp;
struct iio_trigger *trig;
struct iio_poll_func *pollfunc;
struct iio_poll_func *pollfunc_event;
struct iio_chan_spec const *channels;
int num_channels;
const char *name;
const char *label;
const struct iio_info *info;
const struct iio_buffer_setup_ops *setup_ops;
void *__private priv;
};
成員
modes[驅動程式] 列出 IIO 裝置支援的所有操作模式的位掩碼。此列表應在註冊 IIO 裝置之前初始化。它也可以由 IIO 核心填充,作為在驅動程式中啟用特定功能的結果 (請參閱 iio_triggered_event_setup())。
dev[驅動程式] 裝置結構,應分配父級和所有者
buffer[驅動程式] 任何存在的緩衝區
scan_bytes[內部] 捕獲的位元組數,用於饋送到緩衝區解複用器
available_scan_masks[驅動程式] 允許的位掩碼的可選陣列。按偏好順序對陣列進行排序,最優先的掩碼排在最前面。
masklength[內部] 從通道建立的掩碼長度
active_scan_mask[內部] 緩衝區請求的所有掃描掩碼的並集
scan_timestamp[內部] 如果任何緩衝區已請求時間戳,則設定
trig[內部] 當前裝置觸發器(緩衝區模式)
pollfunc[驅動程式] 在收到觸發器時執行的函式
pollfunc_event[驅動程式] 在收到事件觸發器時執行的函式
channels[驅動程式] 通道規範結構表
num_channels[驅動程式] 在 channels 中指定的通道數。
name[驅動程式] 裝置的名稱。
label[驅動程式] 用於標識此裝置的唯一名稱
info[驅動程式] 來自驅動程式的回撥和常量資訊
setup_ops[驅動程式] 在緩衝區啟用/停用之前和之後呼叫的回撥
priv[驅動程式] 對驅動程式的私有資訊的引用 必須 僅 透過 iio_priv() 輔助函式訪問
-
iio_device_register¶
iio_device_register (indio_dev)
向 IIO 子系統註冊裝置
引數
indio_dev由裝置驅動程式填充的裝置結構
-
devm_iio_device_register¶
devm_iio_device_register (dev, indio_dev)
資源管理的
iio_device_register()
引數
dev要為其分配 iio_dev 的裝置
indio_dev由裝置驅動程式填充的裝置結構
描述
管理的 iio_device_register。使用此函式註冊的 IIO 裝置會在驅動程式分離時自動登出。此函式在內部呼叫 iio_device_register()。有關更多資訊,請參閱該函式。
返回
成功時返回 0,失敗時返回負錯誤號。
-
void iio_device_put(struct iio_dev *indio_dev)¶
struct device的引用計數取消分配
引數
struct iio_dev *indio_dev包含裝置的 IIO 裝置結構
引數
struct device *dev嵌入在 IIO 裝置中的裝置
注意
該裝置必須是 IIO 裝置,否則結果是未定義的。
引數
struct iio_dev *indio_devIIO 裝置結構
返回
傳遞的 IIO 裝置
引數
struct iio_dev *indio_devIIO 裝置結構
struct device *parent對父裝置物件的引用
描述
必須在 IIO 裝置分配(透過 devm_iio_device_alloc())& IIO 設備註冊(透過 iio_device_register() 和 devm_iio_device_register()))之間呼叫此實用程式。預設情況下,裝置分配還會將父裝置分配給 IIO 裝置物件。在使用 devm_iio_device_alloc() 的情況下,有時父裝置必須與用於管理分配的裝置不同。在這種情況下,應使用此輔助函式來更改父裝置,因此需要在分配 & 註冊之間呼叫它。
引數
struct iio_dev *indio_devIIO 裝置結構
void *data特定於驅動程式的資料
描述
允許將任意指標附加到 IIO 裝置,稍後可以透過 iio_device_get_drvdata() 檢索該指標。
-
IIO_DECLARE_BUFFER_WITH_TS¶
IIO_DECLARE_BUFFER_WITH_TS (type, name, count)
宣告帶有時間戳的緩衝區
引數
type緩衝區的元素型別
name緩衝區的識別符號名稱
count緩衝區中的元素數
描述
宣告一個可以安全地與 iio_push_to_buffer_with_ts() 一起使用的緩衝區。除了為 type 的 count 元素分配足夠的空間外,它還在緩衝區的末尾為 s64 時間戳分配空間,並確保時間戳的正確對齊。
-
IIO_DECLARE_DMA_BUFFER_WITH_TS¶
IIO_DECLARE_DMA_BUFFER_WITH_TS (type, name, count)
宣告一個 DMA 對齊的帶有時間戳的緩衝區
引數
type緩衝區的元素型別
name緩衝區的識別符號名稱
count緩衝區中的元素數
描述
與 IIO_DECLARE_BUFFER_WITH_TS() 相同,但它使用 __aligned(IIO_DMA_MINALIGN) 來確保緩衝區不與 struct 中排在它之前的任何內容共享快取行。這不應該用於堆疊分配的緩衝區,因為堆疊記憶體通常不能用於 DMA。
引數
struct iio_dev *indio_dev裝置的 IIO 裝置結構
引數
struct iio_dev *indio_dev與將暫停觸發器的裝置關聯的 iio_dev
描述
成功時返回 0,否則返回負數
-
int iio_device_resume_triggering(struct iio_dev *indio_dev)¶
恢復附加到先前使用
iio_device_suspend_triggering()暫停的 iio_dev 的觸發器
引數
struct iio_dev *indio_dev與將恢復觸發器的裝置關聯的 iio_dev
描述
成功時返回 0,否則返回負數
-
const struct iio_scan_type *iio_get_current_scan_type(const struct iio_dev *indio_dev, const struct iio_chan_spec *chan)¶
獲取通道的當前掃描型別
引數
const struct iio_dev *indio_dev要獲取掃描型別的 IIO 裝置
const struct iio_chan_spec *chan要獲取掃描型別的通道
描述
大多數裝置每個通道只有一個掃描型別,可以直接訪問而無需呼叫此函式。在通道規範中實現 ext_scan_type 的核心 IIO 程式碼和驅動程式應使用此函式來獲取通道的當前掃描型別。
返回
通道的當前掃描型別或錯誤。
引數
const struct iio_dev *indio_dev要獲取掩碼長度的 IIO 裝置
-
iio_for_each_active_channel¶
iio_for_each_active_channel (indio_dev, chan)
迭代活動通道
引數
indio_devIIO 裝置
chan儲存已啟用通道的索引
-
IIO_DEGREE_TO_RAD¶
IIO_DEGREE_TO_RAD (deg)
將度數轉換為弧度
引數
deg以度數為單位的值
描述
返回從度數轉換為弧度的給定值
-
IIO_RAD_TO_DEGREE¶
IIO_RAD_TO_DEGREE (rad)
將弧度轉換為度數
引數
rad以弧度為單位的值
描述
返回從弧度轉換為度數的給定值
-
IIO_G_TO_M_S_2¶
IIO_G_TO_M_S_2 (g)
將 g 轉換為米/秒**2
引數
g以 g 為單位的值
描述
返回從 g 轉換為米/秒**2 的給定值
-
IIO_M_S_2_TO_G¶
IIO_M_S_2_TO_G (ms2)
將米/秒**2 轉換為 g
引數
ms2以米/秒**2 為單位的值
描述
返回從米/秒**2 轉換為 g 的給定值
引數
struct iio_dev *indio_dev正在查詢其 ID 的裝置結構
描述
IIO 裝置 ID 是一個唯一的索引,例如用於字元裝置 /dev/iio:device[ID] 的命名。
返回
裝置的唯一 ID。
引數
struct iio_dev *indio_dev裝置的 IIO 裝置結構
返回
如果啟用了緩衝區,則為 True。
引數
struct iio_dev *indio_dev包含裝置的 IIO 裝置結構
clockid_t clock_id要設定的時間戳時鐘 POSIX 識別符號。
返回
成功時為 0,或為負錯誤程式碼。
引數
const struct iio_dev *indio_dev包含裝置的 IIO 裝置結構
返回
裝置的當前時間戳時鐘的時鐘 ID。
引數
const struct iio_dev *indio_dev裝置
返回
事件的時間戳,以納秒為單位。
-
int iio_read_mount_matrix(struct device *dev, struct iio_mount_matrix *matrix)¶
從裝置 "mount-matrix" 屬性檢索 iio 裝置安裝矩陣
引數
struct device *dev分配了安裝矩陣屬性的裝置
struct iio_mount_matrix *matrix儲存檢索到的矩陣的位置
描述
如果裝置未分配任何安裝矩陣屬性,則將填充預設的 3x3 單位矩陣。
返回
成功時為 0,失敗時為負錯誤程式碼。
-
ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)¶
將 IIO 值格式化為其字串表示形式
引數
char *buf格式化值寫入的緩衝區,假設它足夠大(即 PAGE_SIZE)。
unsigned int typeIIO_VAL_* 常量之一。 這決定了 val 和 val2 引數的格式。
int sizevals 中包含的 IIO 值條目的數量
int *vals指向值的指標,確切含義取決於 type 引數。
返回
預設為 0,失敗時為負數,或者屬於 IIO_VAL_* 常量的型別的總寫入字元數。
-
int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer, int *fract)¶
從字串解析定點數
引數
const char *str要解析的字串
int fract_mult第一位小數的乘數,應為 10 的冪
int *integer數字的整數部分
int *fract數字的小數部分
返回
成功時為 0,如果無法解析字串,則為負錯誤程式碼。
引數
struct device *parent父裝置。
int sizeof_priv要為私有結構分配的空間。
返回
成功時指向已分配的 iio_dev 的指標,失敗時為 NULL。
引數
struct iio_dev *dev與裝置關聯的 iio_dev
-
struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)¶
資源管理的
iio_device_alloc()
引數
struct device *parent為其分配 iio_dev 的裝置,以及此 IIO 裝置的父裝置
int sizeof_priv要為私有結構分配的空間。
描述
託管的 iio_device_alloc。 使用此函式分配的 iio_dev 會在驅動程式分離時自動釋放。
返回
成功時指向已分配的 iio_dev 的指標,失敗時為 NULL。
引數
struct iio_dev *indio_dev包含活動和可用掃描掩碼的 IIO 裝置
返回
如果未設定 active_scan_mask,則為索引或 -EINVAL
引數
struct iio_dev *indio_dev表示裝置的裝置結構。
引數
struct iio_dev *indio_dev與裝置關聯的 iio_dev
描述
如果裝置處於直接模式,則保證保持該狀態,直到呼叫 __iio_device_release_direct() 為止。
與 __iio_device_release_direct() 一起使用。
驅動程式應僅呼叫 iio_device_claim_direct()。
返回
成功時為 true,失敗時為 false。
引數
struct iio_dev *indio_dev與裝置關聯的 iio_dev
描述
釋放宣告。 不再保證裝置保持在直接模式。
驅動程式應僅呼叫 iio_device_release_direct()。
與 __iio_device_claim_direct() 一起使用
引數
struct iio_dev *indio_dev與裝置關聯的 iio_dev
描述
如果裝置處於緩衝區模式,則保證保持該狀態,直到呼叫 iio_device_release_buffer_mode() 為止。
與 iio_device_release_buffer_mode() 一起使用。
返回
成功時為 0,失敗時為 -EBUSY。
引數
struct iio_dev *indio_dev與裝置關聯的 iio_dev
描述
釋放宣告。 不再保證裝置保持在緩衝區模式。
與 iio_device_claim_buffer_mode() 一起使用。
引數
struct iio_dev *indio_dev裝置的 IIO 裝置結構