/******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
*
* File Name : l3gd20_gyr_sysfs.c
* Authors : MH - C&I BU - Application Team
* : Carmine Iascone (carmine.iascone@st.com)
* : Matteo Dameno (matteo.dameno@st.com)
* : Both authors are willing to be considered the contact
* : and update points for the driver.
* Version : V 1.1.5.2 sysfs
* Date : 2011/Nov/11
* Description : L3GD20 digital output gyroscope sensor API
*
********************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THE PRESENT SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, FOR THE SOLE
* PURPOSE TO SUPPORT YOUR APPLICATION DEVELOPMENT.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
********************************************************************************
* REVISON HISTORY
*
* VERSION | DATE | AUTHORS | DESCRIPTION
* 1.0 | 2010/May/02 | Carmine Iascone | First Release
* 1.1.3 | 2011/Jun/24 | Matteo Dameno | Corrects ODR Bug
* 1.1.4 | 2011/Sep/02 | Matteo Dameno | SMB Bus Mng,
* | | | forces BDU setting
* 1.1.5 | 2011/Sep/24 | Matteo Dameno | Introduces FIFO Feat.
* 1.1.5.2 | 2011/Nov/11 | Matteo Dameno | enable gpio_int to be
* | | | passed as parameter at
* | | | module loading time;
* | | | corrects polling
* | | | bug at end of probing;
* 1.1.5.3 | 2011/Dec/20 | Matteo Dameno | corrects error in
* | | | I2C SADROOT; Modifies
* | | | resume suspend func.
*******************************************************************************/
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/input-polldev.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/moduleparam.h>
#include "l3gd20.h"
#include <mach/system.h>
#include <mach/hardware.h>
#include <mach/sys_config.h>
#include <linux/init-input.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_PM)
#include <linux/pm.h>
#endif
/** Maximum polled-device-reported rot speed value value in dps*/
#define FS_MAX 32768
/* l3gd20 gyroscope registers */
#define WHO_AM_I 0x0F
#define CTRL_REG1 0x20 /* CTRL REG1 */
#define CTRL_REG2 0x21 /* CTRL REG2 */
#define CTRL_REG3 0x22 /* CTRL_REG3 */
#define CTRL_REG4 0x23 /* CTRL_REG4 */
#define CTRL_REG5 0x24 /* CTRL_REG5 */
#define REFERENCE 0x25 /* REFERENCE REG */
#define FIFO_CTRL_REG 0x2E /* FIFO CONTROL REGISTER */
#define FIFO_SRC_REG 0x2F /* FIFO SOURCE REGISTER */
#define OUT_X_L 0x28 /* 1st AXIS OUT REG of 6 */
#define AXISDATA_REG OUT_X_L
/* CTRL_REG1 */
#define ALL_ZEROES 0x00
#define PM_OFF 0x00
#define PM_NORMAL 0x08
#define ENABLE_ALL_AXES 0x07
#define ENABLE_NO_AXES 0x00
#define BW00 0x00
#define BW01 0x10
#define BW10 0x20
#define BW11 0x30
#define ODR095 0x00 /* ODR = 95Hz */
#define ODR190 0x40 /* ODR = 190Hz */
#define ODR380 0x80 /* ODR = 380Hz */
#define ODR760 0xC0 /* ODR = 760Hz */
/* CTRL_REG3 bits */
#define I2_DRDY 0x08
#define I2_WTM 0x04
#define I2_OVRUN 0x02
#define I2_EMPTY 0x01
#define I2_NONE 0x00
#define I2_MASK 0x0F
/* CTRL_REG4 bits */
#define FS_MASK 0x30
#define BDU_ENABLE 0x80
/* CTRL_REG5 bits */
#define FIFO_ENABLE 0x40
#define HPF_ENALBE 0x11
/* FIFO_CTRL_REG bits */
#define FIFO_MODE_MASK 0xE0
#define FIFO_MODE_BYPASS 0x00
#define FIFO_MODE_FIFO 0x20
#define FIFO_MODE_STREAM 0x40
#define FIFO_MODE_STR2FIFO 0x60
#define FIFO_MODE_BYPASS2STR 0x80
#define FIFO_WATERMARK_MASK 0x1F
#define FIFO_STORED_DATA_MASK 0x1F
#define FUZZ 0
#define FLAT 0
#define I2C_AUTO_INCREMENT 0x80
/* RESUME STATE INDICES */
#define RES_CTRL_REG1 0
#define RES_CTRL_REG2 1
#define RES_CTRL_REG3 2
#define RES_CTRL_REG4 3
#define RES_CTRL_REG5 4
#define RES_FIFO_CTRL_REG 5
#define RESUME_ENTRIES 6
#define DEBUG 0
/** Registers Contents */
#define WHOAMI_L3GD20 0x00D4 /* Expected content for WAI register*/
static int int1_gpio = DEFAULT_INT1_GPIO;
static int int2_gpio = DEFAULT_INT2_GPIO;
/* module_param(int1_gpio, int, S_IRUGO); */
module_param(int2_gpio, int, S_IRUGO);
struct reg_r {
u8 address;
u8 value;
};
static struct status_registers {
struct reg_r who_am_i;
} status_registers = {
.who_am_i.address=WHO_AM_I, .who_am_i.value=WHOAMI_L3GD20,
};
/* Addresses to scan */
static const unsigned short normal_i2c[2] = {0x6a,I2C_CLIENT_END};
static int i2c_num = 0;
static const unsigned short i2c_address[] = {0x6a, 0x6b};
static struct sensor_config_info config_info = {
.input_type = GYR_TYPE,
};
static u32 debug_mask = 0;
#define dprintk(level_mask, fmt, arg...) if (unlikely(debug_mask & level_mask)) \
printk(KERN_DEBUG fmt , ## arg)
module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
/*
* L3GD20 gyroscope data
* brief structure containing gyroscope values for yaw, pitch and roll in
* signed short
*/
struct l3gd20_triple {
short x, /* x-axis angular rate data. */
y, /* y-axis angluar rate data. */
z; /* z-axis angular rate data. */
};
struct output_rate {
int poll_rate_ms;
u8 mask;
};
static const struct output_rate odr_table[] = {
{ 2, ODR760|BW10},
{ 3, ODR380|BW01},
{ 6, ODR190|BW00},
{ 11, ODR095|BW00},
};
static int use_smbus;
static struct l3gd20_gyr_platform_data default_l3gd20_gyr_pdata = {
.fs_range = L3GD20_GYR_FS_2000DPS,
.axis_map_x = 0,
.axis_map_y = 1,
.axis_map_z = 2,
.negate_x = 0,
.negate_y = 0,
.negate_z = 0,
.poll_interval = 100,
.min_interval = L3GD20_MIN_POLL_PERIOD_MS, /* 2ms */
.gpio_int1 = DEFAULT_INT1_GPIO,
.gpio_int2 = DEFAULT_INT2_GPIO, /* int for fifo */
.watermark = 0,
.fifomode = 0,
.init = NULL,
.exit = NULL,
.power_on = NULL,
.power_off = NULL,
};
struct l3gd20_data {
struct i2c_client *client;
struct l3gd20_gyr_platform_data *pdata;
struct mutex lock;
struct input_polled_dev *input_poll_dev;
int hw_initialized;
atomic_t enabled;
u8 reg_addr;
u8 resume_state[RESUME_ENTRIES];
int irq2;
struct work_struct irq2_work;
struct workqueue_struct *irq2_work_queue;
bool polling_enabled;
#ifdef CONFIG_HAS_EARLYSUSPEND
struct early_suspend early_suspend;
#endif
};
#ifdef CONFIG_HAS_EARLYSUSPEND
static void l3gd20_early_suspend(struct early_suspend *h);
static void l3gd20_late_resume(struct early_suspend *h);
#endif
/**
* gyr_detect - Device detection callback for automatic device creation
* return value:
* = 0; success;
* < 0; err
*/
static int gyr_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;
int ret;
int err = -1;
u8 buf[1];
u8 cmd;
dprintk(DEBUG_INIT, "enter func %s. \n", __FUNCTION__);
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV;
if(config_info.twi_id == adapter->nr){
for(i2c_num = 0; i2c_num < (sizeof(i2c_address)/sizeof(i2c_address[0]));i2c_num++){
l3gd20_gyr.rar_gyr 陀螺仪_l3gd20_陀螺仪L3GD20
版权申诉
174 浏览量
2022-09-19
22:25:35
上传
评论
收藏 11KB RAR 举报
邓凌佳
- 粉丝: 65
- 资源: 1万+
最新资源
- 基于Javascript和Python的微商城项目设计源码 - MicroMall
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
- 基于Vue和微信小程序的监理日志系统设计源码 - supervisionLog
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈