V1.0
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
*****************************************************************************
|
||||
* @file ak8975.h
|
||||
* @author WWJ
|
||||
* @version v1.0
|
||||
* @date 2019/04/09
|
||||
* @environment stm32f407
|
||||
* @brief
|
||||
*****************************************************************************
|
||||
**/
|
||||
|
||||
#ifndef _MMC5983_H
|
||||
#define _MMC5983_H
|
||||
#include "bsp.h"
|
||||
|
||||
#define X 0
|
||||
#define Y 1
|
||||
#define Z 2
|
||||
#define XYZ 3
|
||||
|
||||
#define MAX(A, B) (A > B) ? A : B;
|
||||
#define MIN(A, B) (A < B) ? A : B;
|
||||
|
||||
#define MMC5983_X_OUT_H 0X00 //Device ID = 0x48
|
||||
#define MMC5983_X_OUT_L 0X01
|
||||
#define MMC5983_Y_OUT_H 0X02
|
||||
#define MMC5983_Y_OUT_L 0X03
|
||||
#define MMC5983_Z_OUT_H 0X04
|
||||
#define MMC5983_Z_OUT_L 0X05
|
||||
#define MMC5983_XYZ_OUT 0X06
|
||||
#define MMC5983_TMP_OUT 0X07
|
||||
#define MMC5983_STATUS 0X08
|
||||
#define MMC5983_CTRL_0 0X09
|
||||
#define MMC5983_CTRL_1 0X0A
|
||||
#define MMC5983_CTRL_2 0X0B
|
||||
#define MMC5983_CTRL_3 0X0C
|
||||
#define MMC5983_ID 0X2F
|
||||
|
||||
#define MMC5983_ADDRESS 0x30
|
||||
#define MMC5983_MAG_SCALE_16BIT 0.24414f
|
||||
#define MMC5983_MAG_SCALE_18BIT 0.061035f
|
||||
|
||||
#define MMC5983Delay(x) delay_ms(x)
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t Meas_M_Done: 1;
|
||||
uint8_t Meas_T_Done: 1;
|
||||
uint8_t Res0: 2;
|
||||
uint8_t OTP_Read_Done: 1;
|
||||
uint8_t Res1: 3;
|
||||
}Bit;
|
||||
uint8_t Byte;
|
||||
}MMC5983RegStatus;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t TM_M: 1;
|
||||
uint8_t TM_T: 1;
|
||||
uint8_t NT_meas_done_en: 1;
|
||||
uint8_t Set: 1;
|
||||
uint8_t Reset: 1;
|
||||
uint8_t Auto_SR_en: 1;
|
||||
uint8_t OTP_Read: 1;
|
||||
uint8_t Res0: 1;
|
||||
}Bit;
|
||||
uint8_t Byte;
|
||||
}MMC5983RegCtrl0;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t BW: 2;
|
||||
uint8_t X_Inhibit: 1;
|
||||
uint8_t YZ_Inhibit: 2;
|
||||
uint8_t Res0: 2;
|
||||
uint8_t SW_RST: 1;
|
||||
}Bit;
|
||||
uint8_t Byte;
|
||||
}MMC5983RegCtrl1;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t Cm_freq: 3;
|
||||
uint8_t Cmm_en: 1;
|
||||
uint8_t Prd_set: 3;
|
||||
uint8_t En_prd_set: 1;
|
||||
}Bit;
|
||||
uint8_t Byte;
|
||||
}MMC5983RegCtrl2;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t Res0: 1;
|
||||
uint8_t St_enp: 1;
|
||||
uint8_t St_enm: 1;
|
||||
uint8_t Res1: 3;
|
||||
uint8_t Spi_3w: 1;
|
||||
uint8_t Res2: 1;
|
||||
}Bit;
|
||||
uint8_t Byte;
|
||||
}MMC5983RegCtrl3;
|
||||
|
||||
typedef enum{
|
||||
MMC5983_STATUS_IDLE,
|
||||
MMC5983_STATUS_START,
|
||||
MMC5983_STATUS_DELAY,
|
||||
MMC5983_STATUS_WAIT_DELAY,
|
||||
MMC5983_STATUS_READ,
|
||||
MMC5983_STATUS_WAIT_READ,
|
||||
MMC5983_STATUS_STOP,
|
||||
}MMC5983Status_m;
|
||||
|
||||
|
||||
typedef struct {
|
||||
MMC5983Status_m Status;
|
||||
uint16_t MMC5983Delay1mSCnt;
|
||||
float Mag[3];
|
||||
int32_t Mag_Original[XYZ];
|
||||
}MMC5983Var_t;
|
||||
|
||||
void MMC5983LoopHandler(void);
|
||||
void MMC59831mSRoutine(void);
|
||||
void MMC5983Init(void);
|
||||
void MMC5983Start(void);
|
||||
void MMC5983Stop(void);
|
||||
void MMC5983IntCallBack(void);
|
||||
|
||||
void MMC5983Calib(void);
|
||||
void MMC5983GetADValue(int32_t *Mag);
|
||||
void MMC5983_Get_Mag(float *mag);
|
||||
MMC5983Status_m GetMMC5983Status(void);
|
||||
void MMC5983StartRead(void);
|
||||
bool GetMMC5983CalibStatus(void);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* end of ak8975.h */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user