Motion.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*****************************************************************************
  2. Motion.h
  3. *****************************************************************************/
  4. #ifndef _MOTION_H
  5. #define _MOTION_H
  6. /*****************************************************************************/
  7. typedef enum {SENSOR_NULL=0,SENSOR_LSM303=1,SENSOR_LSM6DS3=2} MOTION_SENSOR_TYPE;
  8. #define SENSITIVITY_ACC 0.061 /*0.061/0.122/0.244 mg/LSB */
  9. #define SENSITIVITY_MAG 0.580 /* mgauss/LSB */
  10. #define ACC_THRESHOLD (int)(100.0/SENSITIVITY_ACC) //加速度阈值 100mg
  11. #define MOTION_CS_XL_PIN GPIO_Pin_12
  12. #define MOTION_CS_XL_PORT GPIOA
  13. #define MOTION_CS_MAG_PIN GPIO_Pin_11
  14. #define MOTION_CS_MAG_PORT GPIOA
  15. #define MOTION_SDA_PIN GPIO_Pin_15
  16. #define MOTION_SDA_PORT GPIOB
  17. #define MOTION_CLK_PIN GPIO_Pin_13
  18. #define MOTION_CLK_PORT GPIOB
  19. #define MOTION_CS_XL_HIGH MOTION_CS_XL_PORT->BSRR = MOTION_CS_XL_PIN
  20. #define MOTION_CS_XL_LOW MOTION_CS_XL_PORT->BRR = MOTION_CS_XL_PIN
  21. #define MOTION_CS_MAG_HIGH MOTION_CS_MAG_PORT->BSRR = MOTION_CS_MAG_PIN
  22. #define MOTION_CS_MAG_LOW MOTION_CS_MAG_PORT->BRR = MOTION_CS_MAG_PIN
  23. #define MOTION_SDA_HIGH MOTION_SDA_PORT->BSRR = MOTION_SDA_PIN
  24. #define MOTION_SDA_LOW MOTION_SDA_PORT->BRR = MOTION_SDA_PIN
  25. #define MOTION_CLK_HIGH MOTION_CLK_PORT->BSRR = MOTION_CLK_PIN
  26. #define MOTION_CLK_LOW MOTION_CLK_PORT->BRR = MOTION_CLK_PIN
  27. #define MOTION_SDA_READ GPIO_ReadInputDataBit(MOTION_SDA_PORT,MOTION_SDA_PIN)
  28. #define MAG_WHO_AM_I_VALUE 0x3d
  29. #define ACC_WHO_AM_I_VALUE 0x41
  30. #define DELAY_NOP do{__nop();__nop();__nop();__nop();__nop();__nop();}while(0)
  31. extern MOTION_SENSOR_TYPE MotionSensorType;
  32. typedef struct SUT_MOTION
  33. {
  34. short Ax;
  35. short Ay;
  36. short Az;
  37. short Mx;
  38. short My;
  39. short Mz;
  40. unsigned char Flag;//触发标志,0--静止 1--Ax方向突变 2--Ay方向突变
  41. }SUT_MOTION;
  42. extern SUT_MOTION sutMotion;
  43. void DelayNs(unsigned short ns);
  44. int MotionInit(void);
  45. int MotionReadAccel(short *pX,short *pY,short *pZ);
  46. int MotionReadMagne(short *pX,short *pY,short *pZ);
  47. void MotionTest(void);
  48. void MotionLoop(void);
  49. /////////////////////////////////////////////////////////////////////////////
  50. /*****************************************************************************/
  51. #endif