I2C裝置驅動程式

2021-06-18 14:40:08 字數 1713 閱讀 7691

i2c裝置驅動程式框架

1. 分配乙個i2c_driver結構體

2. 設定

attach_adapter // 它直接呼叫 i2c_probe(adap, 裝置位址, 發現這個裝置後要呼叫的函式);

detach_client  // 解除安裝這個驅動後,如果之前發現能夠支援的裝置,則呼叫它來清理

3. 註冊:i2c_add_driver

#include

#include

#include

#include

#include

#include

#include

#include

#include

static unsigned short ignore      = ;

static unsigned short normal_addr = ; /* 位址值是7位 */

/* 改為0x60的話, 由於不存在裝置位址為0x60的裝置, 所以at24cxx_detect不被呼叫 */

static unsigned short force_addr = ;

static unsigned short * forces = ;

static struct i2c_client_address_data addr_data = ;

static struct i2c_driver at24cxx_driver;

static int major;

static struct class *cls;

struct i2c_client *at24cxx_client;

static ssize_t at24cxx_read(struct file *file, char __user *buf, size_t size, loff_t * offset)

else

return -eio; }

static ssize_t at24cxx_write(struct file *file, const char __user *buf, size_t size, loff_t *offset)

static struct file_operations at24cxx_fops = ;

static int at24cxx_detect(struct i2c_adapter *adapter, int address, int kind)

static int at24cxx_attach(struct i2c_adapter *adapter)

static int at24cxx_detach(struct i2c_client *client)

/* 1. 分配乙個i2c_driver結構體 */

/* 2. 設定i2c_driver結構體 */

static struct i2c_driver at24cxx_driver = ,

.attach_adapter = at24cxx_attach,

.detach_client  = at24cxx_detach, };

static int at24cxx_init(void)

static void at24cxx_exit(void)

module_init(at24cxx_init);

module_exit(at24cxx_exit);

module_license("gpl");

i2c驅動程式

使用者空間 使用者應用程式 核心空間 sys,dev i2c客戶驅動程式 硬體 i2c裝置 i2c控制器 資料結構 i2c driver include linux i2c.h 代表乙個i2c驅動程式 i2c client address data include linux i2c.h i2c客戶...

i2c裝置驅動

1,i2c 裝置註冊 static struct i2c board info i2c2 devices i2c裝置一般在板級 中註冊 static void msm8916 add i2c deivces void 2,i2c驅動註冊 include static const struct i2c...

linux之I2C驅動程式

韋老師的筆記,供自己以後學習 linux核心i2c分析思路 怎麼寫i2c裝置驅動程式?1.分配乙個i2c driver結構體 2.設定 attach adapter 它直接呼叫 i2c probe adap,裝置位址,發現這個裝置後要呼叫的函式 detach client 解除安裝這個驅動後,如果之...