你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下i2c与时钟芯片PCF8563的通信

[日期:2013-01-25] 来源:Linux社区  作者:hdw10 [字体:大 中 小]

i2c.h

********* ******************************************************

#ifndef I2C_H
#define I2C_H

#include <linux/types.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <linux/rtc.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>

#define I2C_DEFAULT_TIMEOUT  1
#define I2C_DEFAULT_RETRY  3

#define PCF8563_REG_SC          0x02
#define PCF8563_REG_MN          0x03
#define PCF8563_REG_HR          0x04
#define PCF8563_REG_DM          0x05
#define PCF8563_REG_DW          0x06
#define PCF8563_REG_MO          0x07
#define PCF8563_REG_YR          0x08

#define PCF8563_MO_C            0x80

typedef unsigned char          u8;
typedef unsigned short          u16;
typedef unsigned int            u32;
typedef unsigned long long      u64;
typedef signed char            s8;
typedef short                  s16;           
typedef int                    s32;
typedef long long              s64;

static const unsigned char rtc_days_in_month[] = {
        31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};

unsigned bcd2bin(unsigned char val);

unsigned bcd2bin(unsigned char val);

static int
__i2c_send(int fd, struct i2c_rdwr_ioctl_data *data);

static int
__i2c_set(int fd, unsigned int timeout, unsigned int retry);

int
i2c_read_data(u16 addr, u8 offset, u8 *val);

int
i2c_write_data(u16 addr, u8 offset, u8 val);

int
i2c_open(unsigned char* dev, unsigned int timeout, unsigned int retry);

#endif

linux
相关资讯       Linux I2C  PCF8563 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款