123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*****************************************************************************
- Motion.h
- *****************************************************************************/
- #ifndef _MOTION_H
- #define _MOTION_H
- /*****************************************************************************/
- typedef enum {SENSOR_NULL=0,SENSOR_LSM303=1,SENSOR_LSM6DS3=2} MOTION_SENSOR_TYPE;
- #define SENSITIVITY_ACC 0.061 /*0.061/0.122/0.244 mg/LSB */
- #define SENSITIVITY_MAG 0.580 /* mgauss/LSB */
- #define ACC_THRESHOLD (int)(100.0/SENSITIVITY_ACC) //加速度阈值 100mg
- #define MOTION_CS_XL_PIN GPIO_Pin_12
- #define MOTION_CS_XL_PORT GPIOA
- #define MOTION_CS_MAG_PIN GPIO_Pin_11
- #define MOTION_CS_MAG_PORT GPIOA
- #define MOTION_SDA_PIN GPIO_Pin_15
- #define MOTION_SDA_PORT GPIOB
- #define MOTION_CLK_PIN GPIO_Pin_13
- #define MOTION_CLK_PORT GPIOB
- #define MOTION_CS_XL_HIGH MOTION_CS_XL_PORT->BSRR = MOTION_CS_XL_PIN
- #define MOTION_CS_XL_LOW MOTION_CS_XL_PORT->BRR = MOTION_CS_XL_PIN
- #define MOTION_CS_MAG_HIGH MOTION_CS_MAG_PORT->BSRR = MOTION_CS_MAG_PIN
- #define MOTION_CS_MAG_LOW MOTION_CS_MAG_PORT->BRR = MOTION_CS_MAG_PIN
- #define MOTION_SDA_HIGH MOTION_SDA_PORT->BSRR = MOTION_SDA_PIN
- #define MOTION_SDA_LOW MOTION_SDA_PORT->BRR = MOTION_SDA_PIN
- #define MOTION_CLK_HIGH MOTION_CLK_PORT->BSRR = MOTION_CLK_PIN
- #define MOTION_CLK_LOW MOTION_CLK_PORT->BRR = MOTION_CLK_PIN
- #define MOTION_SDA_READ GPIO_ReadInputDataBit(MOTION_SDA_PORT,MOTION_SDA_PIN)
- #define MAG_WHO_AM_I_VALUE 0x3d
- #define ACC_WHO_AM_I_VALUE 0x41
- #define DELAY_NOP do{__nop();__nop();__nop();__nop();__nop();__nop();}while(0)
- extern MOTION_SENSOR_TYPE MotionSensorType;
- typedef struct SUT_MOTION
- {
- short Ax;
- short Ay;
- short Az;
- short Mx;
- short My;
- short Mz;
- unsigned char Flag;//触发标志,0--静止 1--Ax方向突变 2--Ay方向突变
-
- }SUT_MOTION;
- extern SUT_MOTION sutMotion;
- void DelayNs(unsigned short ns);
- int MotionInit(void);
- int MotionReadAccel(short *pX,short *pY,short *pZ);
- int MotionReadMagne(short *pX,short *pY,short *pZ);
- void MotionTest(void);
- void MotionLoop(void);
- /////////////////////////////////////////////////////////////////////////////
- /*****************************************************************************/
- #endif
|