drv_qmc6310.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef __QMC6310_H
  2. #define __QMC6310_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include "sdk_common.h"
  7. #include "SEGGER_RTT.h"
  8. #include "usr_config.h"
  9. /* vendor chip id*/
  10. #define QMC6310U_IIC_ADDR (0x1c<<1)
  11. #define QMC6310N_IIC_ADDR (0x3c<<1)
  12. #define QMC6310_CHIP_ID_REG 0x00
  13. /*data output register*/
  14. #define QMC6310_DATA_OUT_X_LSB_REG 0x01
  15. #define QMC6310_DATA_OUT_X_MSB_REG 0x02
  16. #define QMC6310_DATA_OUT_Y_LSB_REG 0x03
  17. #define QMC6310_DATA_OUT_Y_MSB_REG 0x04
  18. #define QMC6310_DATA_OUT_Z_LSB_REG 0x05
  19. #define QMC6310_DATA_OUT_Z_MSB_REG 0x06
  20. /*Status registers */
  21. #define QMC6310_STATUS_REG 0x09
  22. /* configuration registers */
  23. #define QMC6310_CTL_REG_ONE 0x0A /* Contrl register one */
  24. #define QMC6310_CTL_REG_TWO 0x0B /* Contrl register two */
  25. /* Magnetic Sensor Operating Mode MODE[1:0]*/
  26. #define QMC6310_SUSPEND_MODE 0x00
  27. #define QMC6310_NORMAL_MODE 0x01
  28. #define QMC6310_SINGLE_MODE 0x02
  29. #define QMC6310_H_PFM_MODE 0x03
  30. /*data output rate OSR2[2:0]*/
  31. #define OUTPUT_DATA_RATE_800HZ 0x00
  32. #define OUTPUT_DATA_RATE_400HZ 0x01
  33. #define OUTPUT_DATA_RATE_200HZ 0x02
  34. #define OUTPUT_DATA_RATE_100HZ 0x03
  35. /*oversample Ratio OSR[1]*/
  36. #define OVERSAMPLE_RATE_256 0x01
  37. #define OVERSAMPLE_RATE_128 0x00
  38. #define SET_RESET_ON 0x00
  39. #define SET_ONLY_ON 0x01
  40. #define SET_RESET_OFF 0x02
  41. #define QMC6310_DEFAULT_DELAY 200
  42. enum{
  43. AXIS_X = 0,
  44. AXIS_Y = 1,
  45. AXIS_Z = 2,
  46. AXIS_TOTAL
  47. };
  48. typedef struct{
  49. signed char sign[3];
  50. unsigned char map[3];
  51. } QMC6310_map;
  52. #define QMC6310_100HZ 0x39 //161ua
  53. #define QMC6310_10HZ 0x31
  54. int qmc6310_04_Init(uint8_t hz);//1ms
  55. int qmc6310_04_ReConfigure(uint8_t hz); // qmc6310_01_Suspend + qmc6310_01_ReConfigure = 885us
  56. int qmc6310_04_Suspend(void);
  57. int qmc6310_04_CheckIsConfigure(uint8_t hz);
  58. uint8_t qmc6310_04_read_mag_xyz(float *data);//457us
  59. int qmc6310_05_Init(uint8_t hz);
  60. int qmc6310_05_ReConfigure(uint8_t hz);
  61. int qmc6310_05_Suspend(void);
  62. int qmc6310_05_CheckIsConfigure(uint8_t hz);
  63. uint8_t qmc6310_05_read_mag_xyz(float *data);
  64. #endif