嵌入式linux之IIC驱动

IIC介绍:

SDA信号线和SCL时钟线

http://blog.sina.com.cn/s/blog_9815359e01012c6k.html

http://www.cnblogs.com/jason-lu/archive/2012/11/24/2786406.html

http://blog.sina.com.cn/s/blog_7cae47280101mne2.html

实例解析IIC驱动程序的两种实现方式

http://blog.chinaunix.net/uid-27041925-id-3630192.html

log.chinaunix.net/uid-27041925-id-3630234.html

http://blog.chinaunix.net/uid-27041925-id-3629918.html

下面两个函数就完成了I2C总线层驱动模块的注册和注销。
static int __init i2c_adap_s3c_init(void)
{ //注册平台设备
return platform_driver_register(&s3c24xx_i2c_driver);
}
static void __exit i2c_adap_s3c_exit(void)
{ //注销平台设备
platform_driver_unregister(&s3c24xx_i2c_driver);
}
那我们来看看这个平台设备吧。
static struct platform_driver s3c24xx_i2c_driver = {
.probe            = s3c24xx_i2c_probe,  //探测函数
.remove          = s3c24xx_i2c_remove,
.id_table  = s3c24xx_driver_ids,
.driver            = {
        .owner    = THIS_MODULE,
        .name      = "s3c-i2c",
        .pm  = S3C24XX_DEV_PM_OPS,
},
};

这个平台设备总线驱动模型连接了实际的物理适配器(即IIC控制器)和对应的IIC控制器的驱动.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一段标准的嵌入式LinuxIIC驱动代码,供参考: ``` #include <linux/module.h> #include <linux/i2c.h> #include <linux/init.h> static int i2c_driver_probe(struct i2c_client *client, const struct i2c_device_id *id) { printk(KERN_INFO "I2C driver probe function called\n"); // TODO: Add initialization code here return 0; } static int i2c_driver_remove(struct i2c_client *client) { printk(KERN_INFO "I2C driver remove function called\n"); // TODO: Add cleanup code here return 0; } // Define the list of I2C devices that this driver supports static const struct i2c_device_id i2c_driver_id[] = { { "my_i2c_device", 0 }, {}, }; MODULE_DEVICE_TABLE(i2c, i2c_driver_id); // Define the I2C driver structure static struct i2c_driver i2c_driver = { .driver = { .name = "my_i2c_driver", .owner = THIS_MODULE, }, .probe = i2c_driver_probe, .remove = i2c_driver_remove, .id_table = i2c_driver_id, }; // Register the I2C driver static int __init i2c_driver_init(void) { int ret; printk(KERN_INFO "I2C driver initialization function called\n"); ret = i2c_add_driver(&i2c_driver); if (ret < 0) { printk(KERN_ERR "Failed to register I2C driver\n"); return ret; } return 0; } // Unregister the I2C driver static void __exit i2c_driver_exit(void) { printk(KERN_INFO "I2C driver exit function called\n"); i2c_del_driver(&i2c_driver); } module_init(i2c_driver_init); module_exit(i2c_driver_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("I2C driver for my device"); ``` 需要注意的是,这段代码仅为示例代码,具体实现要根据具体的I2C设备和需求进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值