资源简介
I2C地址为A0A1A2所决定 从0x20~0x27
支持扩展IO的中断方式
代码片段和文件信息
/*
* Chip I2C Driver
*
* Copyright (C) 2014 Vergil Cola (vpcola@gmail.com)
*
* 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 version 2 of the License.
*
* This driver shows how to create a minimal i2c driver for Raspberry Pi.
* The arbitrary i2c hardware sits on 0x21 using the MCP23017 chip.
*
* PORTA is connected to output leds while PORTB of MCP23017 is connected
* to dip switches.
*
*/
#define DEBUG 1
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define CHIP_I2C_DEVICE_NAME “mcp23017“
#define INTB_IRQ RK30_PIN4_PD3
struct delayed_work work;
struct i2c_client *client_g ;
/* Define the addresses to scan. Of course we know that our
* hardware is found on 0x21 the chip_i2c_detect() function
* below is used by the kernel to enumerate the i2c bus the function
* returns 0 for success or -ENODEV if the device is not found.
* The kernel enumerates this array for i2c addresses. This
* structure is also passed as a member to the i2c_driver struct.
**/
static const unsigned short normal_i2c[] = { 0x20 0x21 I2C_CLIENT_END };
/* Our drivers id table */
static const struct i2c_device_id chip_i2c_id[] = {
{ “mcp23017“ 0 }
{}
};
MODULE_DEVICE_TABLE(i2c chip_i2c_id);
/* Each client has that uses the driver stores data in this structure */
struct chip_data {
struct mutex update_lock;
unsigned long led_last_updated; /* In jiffies */
unsigned long switch_last_read; /* In jiffies */
int kind;
/* TODO: additional client driver data here */
};
/**
* The following variables are used by the exposed
* fileops (character device driver) functions to
* allow our driver to be opened by normal file operations
* - open/close/read/write from user space.
*/
static struct class * chip_i2c_class = NULL;
static struct device * chip_i2c_device = NULL;
static int chip_i2c_major;
/* Define the global i2c_client structure used by this
* driver. We use this for the file operations (chardev)
* functions to access the i2c_client.
*/
static struct i2c_client * chip_i2c_client = NULL;
/* We define a mutex so that only one process at a time
* can access our driver at /dev. Any other process
* attempting to open this driver will return -EBUSY.
*/
static DEFINE_MUTEX(chip_i2c_mutex);
/* We define the MCP23017 registers. We only need to set the
* direction registers for input and output
**/
#define REG_CHIP_DIR_PORTA 0x00 //配置GPIOA输入或者输出 0:输出 1:输入
#define REG
相关资源
- Linux下sar工具使用
- linux高性能服务器编程源码66818
- windows-linux基线离线扫描脚本.zip
- SLE-15-SP2-Full-x86_64-GM-Media2.iso
- iMX6从uboot到linux启动完成一直保持LO
- 基于Linux的模拟文件系统管理的设计与
- 嵌入式系统linux学习心得
- centos-6.4-x86_64位百度云链接
- unix linux 等的xerces安装及配置
- Linux试题
- linux下telnet源代码
- Linux 0.11下信号量的简单实现——用生
- linux ubuntu
- linux下多线程socket通信完整源码文件
- 深入理解Linux内核第三版中文版+英文
- 最全Linux C 库函数官方中文API手册
- UbuntuLinux下通过ndiswrapper安装无线网卡
- deepin-scrot
- linux下Questasim10/Modelsim安装以及破解方
- how linux works 精通linux 中文版 第二版
- 在Linux环境下模拟实现简单命令解释器
- IT机房搬迁实施方案
- 马哥Linux2016全套视频教程及随堂笔记
- 山东大学linux期末复习资料.zip
- Linuxc聊天室,有日志功能可群聊可私
- 简易路由器-demo
- 2018年Linux系统安全检查、加固shell脚本
- 上传项目到Linux服务器
- CentOS-7-x86_64-DVD-1611.iso镜像
- LinuxFTP简单实现、
评论
共有 条评论