/*
$License:
Copyright (C) 2015 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_icm20608.c
* @brief An I2C-based driver for Invensense 6-axis ICM20608
* @details This driver currently works for the following devices:
* ICM20608
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "inv_icm20608.h"
#include "invensense.h"
#include "invensense_adv.h"
#include "eMPL_outputs.h"
#include "mltypes.h"
/* 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 EMPL_TARGET_STM32F4
#include "myiic.h"
#include "icm20608.h"
#include "delay.h"
#include "log.h"
unsigned char *mpl_key = (unsigned char*)"eMPL 5.1";
#define i2c_write ICM_Write_Len
#define i2c_read ICM_Read_Len
#define delay_ms delay_ms
#define get_ms get_tick_count
#define log_i printf
#define log_e printf
#define min(a,b) ((a<b)?a:b)
#else
#error Gyro driver is missing the system layer implementations.
#endif
#if !defined ICM20608
#error Which gyro are you using? Define ICM20608 in your compiler options.
#endif
static int set_int_enable(unsigned char enable);
/* Hardware registers needed by driver. */
struct sensor_reg_s {
unsigned char who_am_i;
unsigned char rate_div;
unsigned char lpf;
unsigned char prod_id;
unsigned char xg_offs_usr;
unsigned char yg_offs_usr;
unsigned char zg_offs_usr;
unsigned char user_ctrl;
unsigned char fifo_en;
unsigned char gyro_cfg;
unsigned char accel_cfg;
unsigned char accel_cfg2;
unsigned char lp_mode_cfg;
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 xa_offset;
unsigned char ya_offset;
unsigned char za_offset;
unsigned char i2c_mst;
unsigned char bank_sel;
unsigned char mem_start_addr;
unsigned char prgm_start_h;
unsigned char fifo_wm_th;
unsigned char signal_reset;
unsigned char st_gyro;
unsigned char st_accel;
};
/* 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;
};
/* 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 gyro_lpf;
unsigned short accel_lpf;
unsigned short sample_rate;
unsigned char sensors_on;
unsigned char fifo_sensors;
};
struct chip_cfg_s {
/* Matches gyro_cfg >> 3 & 0x03 */
unsigned char gyro_fsr;
/* Matches accel_cfg >> 3 & 0x03 */
unsigned char accel_fsr;
/* Matches lp_mode_cfg >> 4 & 0x07 */
unsigned char gyro_avgf;
/* Matches accel_cfg2 >> 4 & 0x03 */
unsigned char accel_avgf;
/* Enabled sensors. Uses same masks as fifo_en, NOT pwr_mgmt_2. */
unsigned char sensors;
/* Matches config register. */
unsigned char gyro_lpf;
unsigned char accel_lpf;
unsigned char clk_src;
/* Sample rate, NOT rate divider. */
unsigned short sample_rate;
/* Matches fifo_en register. */
unsigned char fifo_enable;
/* Matches int enable register. */
unsigned char int_enable;
/* 1 if devices on auxiliary I2C bus appear on the primary. */
unsigned char bypass_mode;
/* 1 if device in low-power accel-only mode. */
unsigned char lp_accel_mode;
/* 1 if interrupts are only triggered on motion events. */
unsigned char int_motion_only;
struct motion_int_cache_s cache;
/* 1 for active low interrupts. */
unsigned char active_low_int;
/* 1 for latched interrupts. */
unsigned char latched_int;
};
/* Information for self-test. */
struct test_s {
unsigned long gyro_sens;
unsigned long accel_sens;
unsigned char reg_rate_div;
unsigned char reg_lpf;
unsigned char reg_gyro_fsr;
unsigned char reg_accel_fsr;
unsigned short wait_ms;
unsigned char packet_thresh;
float min_dps;
float max_dps;
float max_gyro_var;
float min_g;
float max_g;
float max_accel_var;
float max_g_offset;
unsigned short sample_wait_ms;
};
/* Gyro driver state variables. */
struct gyro_state_s {
const struct sensor_reg_s *reg;
const struct hw_s *hw;
struct chip_cfg_s chip_cfg;
const struct test_s *test;
};
/* Gyro Filter configurations. */
enum lpf_e {
INV_GYRO_FILTER_250Hz = 0,
INV_GYRO_FILTER_176HZ,
INV_GYRO_FILTER_92HZ,
INV_GYRO_FILTER_41HZ,
INV_GYRO_FILTER_20HZ,
INV_GYRO_FILTER_10HZ,
INV_GYRO_FILTER_5HZ,
INV_GYRO_FILTER_3200HZ,
NUM_GYRO_FILTER
};
/* Accel Filter configurations. */
enum lpf_a_e {
INV_ACCEL_FILTER_218Hz = 0,
INV_ACCEL_FILTER_218HZ,
INV_ACCEL_FILTER_99HZ,
INV_ACCEL_FILTER_45HZ,
INV_ACCEL_FILTER_21HZ,
INV_ACCEL_FILTER_10HZ,
INV_ACCEL_FILTER_5HZ,
INV_ACCEL_FILTER_420HZ,
NUM_ACCEL_FILTER
};
/* Full scale ranges. */
enum gyro_fsr_e {
INV_FSR_250DPS = 0,
INV_FSR_500DPS,
INV_FSR_1000DPS,
INV_FSR_2000DPS,
NUM_GYRO_FSR
};
/* Full scale ranges. */
enum accel_fsr_e {
INV_FSR_2G = 0,
INV_FSR_4G,
INV_FSR_8G,
INV_FSR_16G,
NUM_ACCEL_FSR
};
/* Accel Averaging Filters. */
enum accel_avgf_e {
INV_ACCEL_4X_AVG = 0,
INV_ACCEL_8X_AVG,
INV_ACCEL_16X_AVG,
INV_ACCEL_32X_AVG,
NUM_ACCEL_AVG
};
/* Clock sources. */
enum clock_sel_e {
INV_CLK_INTERNAL = 0,
INV_CLK_PLL,
NUM_CLK
};
/* Low-power accel wakeup rates. */
enum lp_accel_rate_e {
INV_LPA_0_24HZ,
INV_LPA_0_49HZ,
INV_LPA_0_98HZ,
INV_LPA_1_95HZ,
INV_LPA_3_91HZ,
INV_LPA_7_81HZ,
INV_LPA_15_63HZ,
INV_LPA_31_25HZ,
INV_LPA_62_5HZ,
INV_LPA_125HZ,
INV_LPA_250HZ,
INV_LPA_500HZ
};
#define BIT_I2C_MST_VDDIO (0x80)
#define BIT_FIFO_EN (0x40)
#define BIT_DMP_EN (0x80)
#define BIT_FIFO_RST (0x04)
#define BIT_DMP_RST (0x08)
#define BIT_FIFO_OVERFLOW (0x10)
#define BIT_DATA_RDY_EN (0x01)
#define BIT_DMP_INT_EN (0x02)
#define BIT_MOT_INT_EN (0x40)
#define BITS_FSR (0x18)
#define BITS_LPF (0x07)
#define BITS_HPF (0x07)
#define BITS_CLK (0x07)
#define BIT_FIFO_SIZE_1024 (0x40)
#define BIT_FIFO_SIZE_2048 (0x80)
#define BIT_FIFO_SIZE_4096 (0xC0)
#define BIT_RESET (0x80)
#define BIT_SLEEP (0x40)
#define BIT_S0_DELAY_EN (0x01)
#define BIT_S2_DELAY_EN (0x04)
#define BITS_SLAVE_LENGTH (0x0F)
#define BIT_SL
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
STM32F750驱动SD卡读写【支持STM32F7系列单片机_寄存器库驱动】.zip (161个子文件)
libmpllib.a 415KB
inv_icm20608.c 72KB
lcd.c 59KB
data_builder.c 45KB
sdmmc_sdcard.c 38KB
ml_math_func.c 25KB
hal_outputs.c 18KB
ltdc.c 18KB
results_holder.c 16KB
touch.c 15KB
usmart.c 15KB
sys.c 13KB
ov5640.c 12KB
usmart_str.c 12KB
eMPL_outputs.c 11KB
w25qxx.c 11KB
norflash.c 11KB
rtc.c 9KB
gt9147.c 8KB
ft5206.c 8KB
can.c 8KB
oled.c 8KB
gt9271.c 7KB
delay.c 7KB
sdram.c 7KB
storage_manager.c 7KB
24l01.c 7KB
stmflash.c 6KB
icm20608.c 6KB
dcmi.c 6KB
log_stm32.c 6KB
malloc.c 6KB
qspi.c 6KB
timer.c 5KB
test.c 4KB
tpad.c 4KB
remote.c 4KB
mpu.c 4KB
usart.c 4KB
24cxx.c 4KB
ds18b20.c 4KB
ctiic.c 3KB
rs485.c 3KB
start_manager.c 3KB
adc.c 3KB
myiic.c 3KB
ap3216c.c 3KB
dma.c 3KB
sccb.c 3KB
wkup.c 3KB
dht11.c 2KB
spi.c 2KB
pcf8574.c 2KB
wdg.c 2KB
exti.c 2KB
mpl.c 2KB
message_layer.c 2KB
key.c 2KB
usmart_config.c 1KB
usart2.c 1KB
dac.c 1KB
rng.c 1KB
mlmath.c 1KB
led.c 791B
stm32f750xx.h 1.49MB
core_cm7.h 141KB
font.h 65KB
oledfont.h 34KB
ov5640af.h 28KB
sdmmc_sdcard.h 25KB
cmsis_armcc.h 25KB
log.h 10KB
data_builder.h 9KB
mltypes.h 9KB
ov5640cfg.h 9KB
stm32f7xx.h 9KB
cmsis_compiler.h 6KB
usmart.h 6KB
lcd.h 6KB
icm20608.h 5KB
ml_math_func.h 5KB
24l01.h 5KB
inv_icm20608.h 4KB
system_stm32f7xx.h 4KB
sys.h 4KB
usmart_str.h 3KB
malloc.h 3KB
touch.h 3KB
ltdc.h 3KB
results_holder.h 3KB
norflash.h 3KB
w25qxx.h 3KB
mlmath.h 2KB
mlos.h 2KB
stmflash.h 2KB
ov5640.h 2KB
gt9271.h 2KB
ft5206.h 2KB
oled.h 2KB
hal_outputs.h 2KB
共 161 条
- 1
- 2
资源评论
不脱发的程序猿
- 粉丝: 24w+
- 资源: 5763
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 本仓库包含我们队伍2019年数模美赛题目A、我们的代码及论文
- 基于JavaWeb图书管理系统课程设计软件源码+数据库+实验报告
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本122.0.6172.0)
- WesternDigital-SSD-Dashboard-v4.2.2.5
- 计算机视觉,课后习题部分解答(章毓晋)
- “推荐系统”相关资源推荐
- 软件工程期末复习笔记 快速冲刺
- 毕业设计基于Spring Boot的健身房管理系统源码+数据库+使用文档(高分项目)
- 基于Selenium的Java爬虫实战(内含谷歌浏览器Chrom和Chromedriver版本122.0.6170.3)
- 安卓实践:计算器、简单商城
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功