资源简介
i2cdetect :检测i2c芯片是否存在
i2cdump :检测i2c寄存器
i2cget :从i2c芯片寄存器种读取数据
i2cset :设置i2c寄存器
isadump:监测isa寄存器
代码片段和文件信息
/***************************************************************************
copyright : (C) by 2002-2003 Stefano Barbato
email : stefano@codesink.org
$Id: 24cXX.c 4230 2006-11-10 09:22:12Z khali $
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License or *
* (at your option) any later version. *
* *
***************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “24cXX.h“
static int i2c_write_1b(struct eeprom *e __u8 buf)
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
r = i2c_smbus_write_byte(e->fd buf);
if(r < 0)
fprintf(stderr “Error i2c_write_1b: %s\n“ strerror(errno));
usleep(10);
return r;
}
static int i2c_write_2b(struct eeprom *e __u8 buf[2])
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
r = i2c_smbus_write_byte_data(e->fd buf[0] buf[1]);
if(r < 0)
fprintf(stderr “Error i2c_write_2b: %s\n“ strerror(errno));
usleep(10);
return r;
}
static int i2c_write_3b(struct eeprom *e __u8 buf[3])
{
int r;
// we must simulate a plain I2C byte write with SMBus functions
// the __u16 data field will be byte swapped by the SMBus protocol
r = i2c_smbus_write_word_data(e->fd buf[0] buf[2] << 8 | buf[1]);
if(r < 0)
fprintf(stderr “Error i2c_write_3b: %s\n“ strerror(errno));
usleep(10);
return r;
}
#define CHECK_I2C_FUNC( var label ) \
do { if(0 == (var & label)) { \
fprintf(stderr “\nError: “ \
#label “ function is required. Program halted.\n\n“); \
exit(1); } \
} while(0);
int eeprom_open(char *dev_fqn int addr int type struct eeprom* e)
{
int fd r;
unsigned long funcs;
e->fd = e->addr = 0;
e->dev = 0;
fd = open(dev_fqn O_RDWR);
if(fd <= 0)
return -1;
// get funcs list
if((r = ioctl(fd I2C_FUNCS &funcs) < 0))
return r;
// check for req funcs
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_BYTE );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_BYTE );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_BYTE_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_BYTE_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_READ_WORD_DATA );
CHECK_I2C_FUNC( funcs I2C_FUNC_SMBUS_WRITE_WORD_DATA );
// set working device
if( ( r = ioctl(fd I2C_SLAVE addr)) < 0)
return r;
e->fd =
相关资源
- linux进程监控和进程守护程序
- QT串口通讯(linux)
- linux网络编程课程设计
- linux下的实时语音聊天程序源码adpcm编
- 纯C实现语音合成支持windows和linux,亲
- 在Linux下的NAMD安装教程
- Linux 弹球游戏
- Linux下QT tcp接收Zedboard发送的RGB888视频
- linux PL2303 usb转串口驱动源码
- 自行实现的Linux内核USB鼠标驱动
- 2014马哥linux基础视频教程百度网盘8
- linux下Lammps 成功并行安装教程 高清
- Linux 下gtk+2.0的贪吃蛇帮助文档及其源
- V4L2视频采集与h264编码
- jdk-8u11-linux-x64.tar.gz
- linux加密perl 脚本工具
- container-selinux-2.9-4.el7.noarch.rpm
- 基于linux的飞鸽传书软件源代码有注释
- 跟老男孩学Linux运维:Web集群实战$
- 马哥Linux高端运维云计算-就业班
- zlib-1.2.7
- Linux学生管理系统
- Linux+shell编程课程设计——Linux用户管
- TensorFlow实现人脸识别(1)------Linux下
- linux安装nginx一键脚本自己用过
- 基于Linux QT显示zigbee数据
- Linux操作系统试题附答案
- bluez-demo
- bison-devel
- LINUX端口扫描源代码(C实现)
评论
共有 条评论