【Linux Manpage】libi2c - i2c库介绍

NAME

libi2c - publicly accessible functions provided by the i2c library
libi2c - 由i2c库提供的可公开访问的函数库

SYNOPSIS 概述

下面这些接口,便是i2c lib库提供的api接口,我们可以在编程时调用这些接口。

#include <linux/i2c.h>
#include <i2c/smbus.h>
/* Universal SMBus transaction */
__s32 i2c_smbus_access(int file, char read_write, __u8 command,
                       int size, union i2c_smbus_data *data);
/* Simple SMBus transactions */
__s32 i2c_smbus_write_quick(int file, __u8 value);
__s32 i2c_smbus_read_byte(int file);
__s32 i2c_smbus_write_byte(int file, __u8 value);
__s32 i2c_smbus_read_byte_data(int file, __u8 command);
__s32 i2c_smbus_write_byte_data(int file, __u8 command, __u8 value);
__s32 i2c_smbus_read_word_data(int file, __u8 command);
__s32 i2c_smbus_write_word_data(int file, __u8 command, __u16 value);
__s32 i2c_smbus_process_call(int file, __u8 command, __u16 value);
/* Block SMBus (and non-SMBus) transactions */
__s32 i2c_smbus_read_block_data(int file, __u8 command, __u8 *values);
__s32 i2c_smbus_write_block_data(int file, __u8 command, __u8 length,
                                 const __u8 *values);
__s32 i2c_smbus_block_process_call(int file, __u8 command, __u8 length,
                                   __u8 *values);
__s32 i2c_smbus_read_i2c_block_data(int file, __u8 command, __u8 length,
                                    __u8 *values);
__s32 i2c_smbus_write_i2c_block_data(int file, __u8 command, __u8 length,
                                     const __u8 *values);
描述

此库向用户空间提供了一个类似in-kernel的SMBus-level API。每个函数都是对i2c-dev处理适当的ioctl调用的一个包装器。i2c-dev的内核驱动会将ioctl转换为in-kernel的等效函数调用,并将结果传回给用户空间的调用者。

i2c_smbus_access() 是运行任何SMBus事务的通用函数。你必须自己填写和链接数据结构。它在成功时返回0,或在错误时返回一个负的errno值。在实践中,你应该永远不需要直接调用这个函数,而是使用下面的一个特定函数,它将准备好数据,然后为你调用它。

i2c_smbus_write_quick() 运行一个SMBus "快速命令 "事务。

i2c_smbus_write_byte() 运行一个SMBus "发送byte "事务。

i2c_smbus_write_byte_data() 运行一个SMBus "写byte "事务。

i2c_smbus_write_word_data() 运行一个SMBus "写word "事务。

这些写事务函数在成功时返回0。出错时,会返回一个负的errno值。

i2c_smbus_read_byte() 运行一个SMBus "接收byte "事务。

i2c_smbus_read_byte_data() 运行一个SMBus "读byte "事务。

i2c_smbus_read_word_data() 运行一个SMBus "读word "事务。

i2c_smbus_process_call() 运行一个SMBus "进程调用 "事务。

这些读事务函数在成功时返回读取的字节或字值。出错时,会返回一个负的errno值。

i2c_smbus_write_block_data() 运行一个SMBus "block写入 "事务。

i2c_smbus_read_block_data() 运行一个SMBus "Block 读取 "事务。

i2c_smbus_block_process_call() 运行一个SMBus "块写-块读进程调用 "事务。

这些块交易函数在成功时返回0。出错时,会返回一个负的errno值。块的长度被限制为32字节。

i2c_smbus_write_i2c_block_data() 运行一个 "I2CBlock 写 "事务。这通常用于向EEPROM写入4kb大小的数据。

i2c_smbus_read_i2c_block_data() 运行一个 "I2CBlock 读 "事务。这通常用于从4kb大小的EEPROM中读取。

虽然在技术上不是SMBus规范的一部分,但这些I2C块传输被许多SMBus主机控制器所支持。这些块交易功能在成功时返回0。如果出错,将返回一个负的errno值。像它们的SMBus对应程序一样,块的长度被限制在32字节。

数据结构
结构i2c_smbus_ioctl_data用于通过i2c-dev驱动向内核发送数据和从内核获取数据。它将由i2c_smbus_access()为你填写,所以你不需要关心这些细节。

Union i2c_smbus_data用于存储所有可能的SMBus数据。

union i2c_smbus_data {
__u8 byte;
__u16 word;
__u8 block[I2C_SMBUS_BLOCK_MAX + 2]};

block[0]用于长度并且最后一个字节被保留。如果你使用高层函数,这个结构将为你填好,所以你不必关心细节。只有当你直接调用i2c_smbus_access()时,你才需要自己填写它。

参考:
https://manpages.debian.org/testing/i2c-tools/libi2c.3.en.html
AUTHOR
Simon G. Vogl, Frodo Looijaard, Jean Delvare and others

推荐:这个网站可以查linux command的介绍
https://boxmatrix.info/wiki/Property:gpiodetect

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AiFool

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值