62 lines
1.8 KiB
C
62 lines
1.8 KiB
C
#ifndef __SHAKE_DETECT_H
|
||
#define __SHAKE_DETECT_H
|
||
|
||
#include <stdint.h>
|
||
|
||
#define LIS3DSH_I2C_MASTER_NUM 0
|
||
#define LIS3DSH_I2C_SEL_IO 11 // 地址选择
|
||
#define LIS3DSH_I2C_MASTER_SDA_IO 12
|
||
#define LIS3DSH_I2C_MASTER_SCL_IO 13
|
||
#define LIS3DSH_I2C_MASTER_FREQ_HZ 400000
|
||
#define LIS3DSH_I2C_SALVE_ADDR_L 0x18 // 7bit地址0b0011000
|
||
#define LIS3DSH_I2C_MASTER_TIMEOUT_MS 1000
|
||
#define ACK_CHECK_EN 0x1
|
||
#define ACK_CHECK_DIS 0x0
|
||
|
||
#define LIS3DSH_INT1_IO 9 // 数据就绪信号
|
||
#define LIS3DSH_CS_IO 10 // SPI I2C模式选择,1-I2C
|
||
#define LIS3DSH_LED_IO 3
|
||
#define BOOT_TIME 10
|
||
|
||
|
||
#define N_SAMPLES 1024
|
||
#define ANGLE_N_SAMPLES 128 // 需能整除N_SAMPLES
|
||
|
||
// 三轴加速度,已经过解析,单位g
|
||
typedef struct
|
||
{
|
||
float a[3]; // x,y,z
|
||
} lis3dsh_a_data_t;
|
||
|
||
typedef struct
|
||
{
|
||
int feq_min_id; // 注意,单位并不是HZ,为: 1600/N_SAMPLES HZ
|
||
int feq_max_id;
|
||
float enter_amplitude_th;
|
||
float exit_amplitude_th;
|
||
uint8_t channel1; // FFT可以同时计算两轴的频谱图,选择[1,2,3]->[x,y,z]
|
||
uint8_t channel2;
|
||
uint8_t select; // 选择进行震动检测的是频谱图,选择[1,2,3]->[ch1,ch2,both]
|
||
} shake_detect_cfg_t;
|
||
|
||
typedef struct
|
||
{
|
||
float wind[N_SAMPLES];
|
||
float y_cf[N_SAMPLES * 2];
|
||
float *y1_cf;
|
||
float *y2_cf;
|
||
float sum_y[N_SAMPLES / 2];
|
||
int is_shake;
|
||
} fft_data_t;
|
||
|
||
typedef struct
|
||
{
|
||
float x;
|
||
float y;
|
||
float z;
|
||
} angle_data_t;
|
||
|
||
void shake_detect_init(void);
|
||
void lis3dsh_calculating_angle(float ax, float ay, float az, float *pitch, float *roll, float *yaw);
|
||
|
||
#endif |