/*
$License:
Copyright (C) 2011-2012 InvenSense Corporation, All Rights Reserved.
See included License.txt for License information.
$
*/
/**
* @addtogroup DRIVERS Sensor Driver Layer
* @brief Hardware drivers to communicate with sensors via I2C.
*
* @{
* @file inv_mpu.c
* @brief An I2C-based driver for Invensense gyroscopes.
* @details This driver currently works for the following devices:
* MPU6050
* MPU6500
* MPU9150 (or MPU6050 w/ AK8975 on the auxiliary bus)
* MPU9250 (or MPU6500 w/ AK8963 on the auxiliary bus)
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "include.h"
#define MPU6050 //定义我们使用的传感器为MPU6050
#define MOTION_DRIVER_TARGET_MSP430 //定义驱动部分,采用MSP430的驱动(移植到STM32F1)
/* The following functions must be defined for this platform:
* i2c_write(unsigned char slave_addr, unsigned char reg_addr,
* unsigned char length, unsigned char const *data)
* i2c_read(unsigned char slave_addr, unsigned char reg_addr,
* unsigned char length, unsigned char *data)
* delay_ms(unsigned long num_ms)
* get_ms(unsigned long *count)
* reg_int_cb(void (*cb)(void), unsigned char port, unsigned char pin)
* labs(long x)
* fabsf(float x)
* min(int a, int b)
*/
#if defined MOTION_DRIVER_TARGET_MSP430
//#include "msp430.h"
//#include "msp430_i2c.h"
//#include "msp430_clock.h"
//#include "msp430_interrupt.h"
#define i2c_write MPU_Write_Len
#define i2c_read MPU_Read_Len
#define delay_ms delay_ms
#define get_ms mget_ms
//static inline int reg_int_cb(struct int_param_s *int_param)
//{
// return msp430_reg_int_cb(int_param->cb, int_param->pin, int_param->lp_exit,
// int_param->active_low);
//}
#define log_i printf //打印信息
#define log_e printf //打印信息
/* labs is already defined by TI's toolchain. */
/* fabs is for doubles. fabsf is for floats. */
#define fabs fabsf
#define min(a,b) ((a<b)?a:b)
#elif defined EMPL_TARGET_MSP430
#include "msp430.h"
#include "msp430_i2c.h"
#include "msp430_clock.h"
#include "msp430_interrupt.h"
#include "log.h"
#define i2c_write msp430_i2c_write
#define i2c_read msp430_i2c_read
#define delay_ms msp430_delay_ms
#define get_ms msp430_get_clock_ms
static inline int reg_int_cb(struct int_param_s *int_param)
{
return msp430_reg_int_cb(int_param->cb, int_param->pin, int_param->lp_exit,
int_param->active_low);
}
#define log_i MPL_LOGI
#define log_e MPL_LOGE
/* labs is already defined by TI's toolchain. */
/* fabs is for doubles. fabsf is for floats. */
#define fabs fabsf
#define min(a,b) ((a<b)?a:b)
#elif defined EMPL_TARGET_UC3L0
/* Instead of using the standard TWI driver from the ASF library, we're using
* a TWI driver that follows the slave address + register address convention.
*/
#include "twi.h"
#include "delay.h"
#include "sysclk.h"
#include "log.h"
#include "sensors_xplained.h"
#include "uc3l0_clock.h"
#define i2c_write(a, b, c, d) twi_write(a, b, d, c)
#define i2c_read(a, b, c, d) twi_read(a, b, d, c)
/* delay_ms is a function already defined in ASF. */
#define get_ms uc3l0_get_clock_ms
static inline int reg_int_cb(struct int_param_s *int_param)
{
sensor_board_irq_connect(int_param->pin, int_param->cb, int_param->arg);
return 0;
}
#define log_i MPL_LOGI
#define log_e MPL_LOGE
/* UC3 is a 32-bit processor, so abs and labs are equivalent. */
#define labs abs
#define fabs(x) (((x)>0)?(x):-(x))
#else
#error Gyro driver is missing the system layer implementations.
#endif
#if !defined MPU6050 && !defined MPU9150 && !defined MPU6500 && !defined MPU9250
#error Which gyro are you using? Define MPUxxxx in your compiler options.
#endif
/* Time for some messy macro work. =]
* #define MPU9150
* is equivalent to..
* #define MPU6050
* #define AK8975_SECONDARY
*
* #define MPU9250
* is equivalent to..
* #define MPU6500
* #define AK8963_SECONDARY
*/
#if defined MPU9150
#ifndef MPU6050
#define MPU6050
#endif /* #ifndef MPU6050 */
#if defined AK8963_SECONDARY
#error "MPU9150 and AK8963_SECONDARY cannot both be defined."
#elif !defined AK8975_SECONDARY /* #if defined AK8963_SECONDARY */
#define AK8975_SECONDARY
#endif /* #if defined AK8963_SECONDARY */
#elif defined MPU9250 /* #if defined MPU9150 */
#ifndef MPU6500
#define MPU6500
#endif /* #ifndef MPU6500 */
#if defined AK8975_SECONDARY
#error "MPU9250 and AK8975_SECONDARY cannot both be defined."
#elif !defined AK8963_SECONDARY /* #if defined AK8975_SECONDARY */
#define AK8963_SECONDARY
#endif /* #if defined AK8975_SECONDARY */
#endif /* #if defined MPU9150 */
#if defined AK8975_SECONDARY || defined AK8963_SECONDARY
#define AK89xx_SECONDARY
#else
/* #warning "No compass = less profit for Invensense. Lame." */
#endif
static int set_int_enable(unsigned char enable);
/* Hardware registers needed by driver. */
struct gyro_reg_s {
unsigned char who_am_i;
unsigned char rate_div;
unsigned char lpf;
unsigned char prod_id;
unsigned char user_ctrl;
unsigned char fifo_en;
unsigned char gyro_cfg;
unsigned char accel_cfg;
// unsigned char accel_cfg2;
// unsigned char lp_accel_odr;
unsigned char motion_thr;
unsigned char motion_dur;
unsigned char fifo_count_h;
unsigned char fifo_r_w;
unsigned char raw_gyro;
unsigned char raw_accel;
unsigned char temp;
unsigned char int_enable;
unsigned char dmp_int_status;
unsigned char int_status;
// unsigned char accel_intel;
unsigned char pwr_mgmt_1;
unsigned char pwr_mgmt_2;
unsigned char int_pin_cfg;
unsigned char mem_r_w;
unsigned char accel_offs;
unsigned char i2c_mst;
unsigned char bank_sel;
unsigned char mem_start_addr;
unsigned char prgm_start_h;
#if defined AK89xx_SECONDARY
unsigned char s0_addr;
unsigned char s0_reg;
unsigned char s0_ctrl;
unsigned char s1_addr;
unsigned char s1_reg;
unsigned char s1_ctrl;
unsigned char s4_ctrl;
unsigned char s0_do;
unsigned char s1_do;
unsigned char i2c_delay_ctrl;
unsigned char raw_compass;
/* The I2C_MST_VDDIO bit is in this register. */
unsigned char yg_offs_tc;
#endif
};
/* Information specific to a particular device. */
struct hw_s {
unsigned char addr;
unsigned short max_fifo;
unsigned char num_reg;
unsigned short temp_sens;
short temp_offset;
unsigned short bank_size;
#if defined AK89xx_SECONDARY
unsigned short compass_fsr;
#endif
};
/* When entering motion interrupt mode, the driver keeps track of the
* previous state so that it can be restored at a later time.
* TODO: This is tacky. Fix it.
*/
struct motion_int_cache_s {
unsigned short gyro_fsr;
unsigned char accel_fsr;
unsigned short lpf;
unsigned short sample_rate;
unsigned char sensors_on;
unsigned char fifo_sensors;
unsigned char dmp_on;
};
/* Cached chip configuration data.
* TODO: A lot of these can be handled with a bitmask.
*/
struct chip_cfg_s {
/* Matches gyro_cfg >> 3 & 0x03 */
unsigned char gyro_fsr;
/* Matches accel_cfg >> 3 & 0x03 */
unsigned char accel_fsr;
/* Enabled sensors. Uses same masks as fifo_en, NOT pwr_mgmt_2. */
unsigned char sensors;
/* Matches config register. */
unsigned char lpf;
unsigned char clk_src;
/* Sample rate, NOT rate divider. */
unsigned short sample_rate;
/* Matches fifo_en register. */
unsigned char fifo_enable;
没有合适的资源?快使用搜索试试~ 我知道了~
s9keaz128 串口升级方案 1:上位机qt5源码 2:单片机底层与应用程序3:烧写文档4:原理图
共428个文件
h:143个
c:99个
dll:47个
需积分: 0 6 下载量 13 浏览量
2024-02-02
19:46:42
上传
评论
收藏 21.9MB RAR 举报
温馨提示
s9keaz128 串口升级方案 1:上位机qt5源码 2:单片机底层与应用程序源码 3:烧写文档 4:原理图
资源推荐
资源详情
资源评论
收起资源包目录
s9keaz128 串口升级方案 1:上位机qt5源码 2:单片机底层与应用程序3:烧写文档4:原理图 (428个子文件)
KEAZ128Boot.Debug.cspy.bat 2KB
KEAZ128App.Debug.cspy.bat 2KB
KEAZ128Boot.Release.cspy.bat 2KB
Project.bin 19KB
KEAZ128.bin 19KB
KEAZ128.bin 19KB
KEAZ128Boot.pbd.browse 1.15MB
inv_mpu.c 87KB
inv_mpu.c 87KB
flash.c 65KB
flash.c 65KB
inv_mpu_dmp_motion_driver.c 57KB
inv_mpu_dmp_motion_driver.c 57KB
LQ12864.c 39KB
LQ12864.c 39KB
ftm.c 32KB
ftm.c 32KB
ics.c 29KB
ics.c 29KB
i2c.c 22KB
i2c.c 22KB
printf.c 17KB
printf.c 17KB
printf.c 14KB
printf.c 14KB
uart.c 14KB
uart.c 14KB
mscan.c 14KB
mscan.c 14KB
AES.c 13KB
AES.c 13KB
wdog.c 12KB
wdog.c 12KB
bootloader.c 12KB
sim.c 11KB
sim.c 11KB
softVersions.c 11KB
adc.c 11KB
adc.c 11KB
crc.c 10KB
board.c 10KB
kbi.c 10KB
kbi.c 10KB
spi.c 10KB
spi.c 10KB
uif.c 9KB
uif.c 9KB
crc.c 8KB
pit.c 7KB
pit.c 7KB
memtest.c 7KB
memtest.c 7KB
acmp.c 7KB
acmp.c 7KB
MPU6050.c 7KB
MPU6050.c 7KB
pwt.c 6KB
pwt.c 6KB
MPU9250.c 6KB
MPU9250.c 6KB
rtc.c 6KB
rtc.c 6KB
pmc.c 5KB
pmc.c 5KB
softVersions.c 5KB
HalMscan.c 5KB
flash_if.c 4KB
queue.c 4KB
queue.c 4KB
fifo.c 4KB
8700_2100.c 4KB
8700_2100.c 4KB
fifo.c 4KB
flash_if.c 4KB
LQKEY.c 4KB
LQKEY.c 4KB
HalIO.c 4KB
HalIIC.c 3KB
LQLED.c 3KB
LQLED.c 3KB
systick.c 3KB
systick.c 3KB
arm_cm0.c 3KB
arm_cm0.c 3KB
nvic.c 3KB
nvic.c 3KB
HalPWT.c 3KB
system_SKEAZ1284.c 3KB
system_SKEAZ1284.c 3KB
MPUIIC.c 3KB
MPUIIC.c 3KB
HalUart.c 3KB
io.c 2KB
io.c 2KB
assert.c 2KB
assert.c 2KB
Serial_oscilloscope.c 2KB
Serial_oscilloscope.c 2KB
HalPWM.c 745B
fun.c 646B
共 428 条
- 1
- 2
- 3
- 4
- 5
资源评论
一人科技
- 粉丝: 106
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- html+css+'青春献礼二十大 红色旅游助乡村'为主题的网页设计 2022年参与学校网页设计比赛时完成的
- Unity 模型布尔运算插件
- eCANtools工具,CAN资料包
- 129335283047061xiazaigongjuxiang(去重软件).apk
- Android环境检测工具,检测ksu,lsp,magisk等
- WordPress后台美化插件QuarterAdmin分享
- PCB_Project单片机绘制 (2024-5-11 22-22-13).zip
- nccl-local-repo-ubuntu2204-2.21.5-cuda12.4-1.0-1-amd64
- STM32移植LVGL源码工程 stm32移植GUI-Guider源码 LVGL移植源码
- Screenshot_20240522_084328_com.tencent.mm.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功