TM STM32F4xx Libraries  v1.0.0
Libraries for STM32F4xx devices from Tilen Majerle
tm_stm32f4_hmc5883l.h
1 
30 #ifndef TM_HMC5883L_H
31 #define TM_HMC5883L_H 100
32 
33 /* C++ detection */
34 #ifdef __cplusplus
35 extern C {
36 #endif
37 
64 #include "stm32f4xx.h"
65 #include "stm32f4xx_rcc.h"
66 #include "defines.h"
67 #include "tm_stm32f4_i2c.h"
68 #include "tm_stm32f4_gpio.h"
69 #include "tm_stm32f4_exti.h"
70 
83 /* Default I2C for sensor */
84 #ifndef HMC5883L_I2C
85 #define HMC5883L_I2C I2C3
86 #define HMC5883L_I2C_PINSPACK TM_I2C_PinsPack_1
87 #endif
88 
89 /* I2C clock speed */
90 #ifndef HMC5883L_I2C_CLOCK
91 #define HMC5883L_I2C_CLOCK 400000
92 #endif
93 
94 /* I2C address for HMC5883L */
95 #define HMC5883L_I2C_ADDR 0x3C
96 
97 /* Data ready for HMC5883L */
98 #ifndef HMC5883L_DRDY_PIN
99 #define HMC5883L_DRDY_PORT GPIOC
100 #define HMC5883L_DRDY_PIN GPIO_PIN_3
101 #endif
102 
113 #define HMC5883L_CONFA 0x00
114 #define HMC5883L_CONFB 0x01
115 #define HMC5883L_MODE 0x02
116 #define HMC5883L_DATAXM 0x03
117 #define HMC5883L_DATAXL 0x04
118 #define HMC5883L_DATAZM 0x05
119 #define HMC5883L_DATAZL 0x06
120 #define HMC5883L_DATAYM 0x07
121 #define HMC5883L_DATAYL 0x08
122 #define HMC5883L_STATUS 0x09
123 #define HMC5883L_IDA 0x0A
124 #define HMC5883L_IDB 0x0B
125 #define HMC5883L_IDC 0x0C
141 typedef enum {
142  TM_HMC5883L_Result_Ok = 0x00,
143  TM_HMC5883L_Result_Error,
144  TM_HMC5883L_Result_DeviceNotConnected
145 } TM_HMC5883L_Result_t;
146 
147 typedef enum {
148  TM_HMC5883L_Gain_0_88 = 0x00,
149  TM_HMC5883L_Gain_1_3 = 0x20,
150  TM_HMC5883L_Gain_1_9 = 0x40,
151  TM_HMC5883L_Gain_2_5 = 0x60,
152  TM_HMC5883L_Gain_4_0 = 0x80,
153  TM_HMC5883L_Gain_4_7 = 0xA0,
154  TM_HMC5883L_Gain_5_6 = 0xC0,
155  TM_HMC5883L_Gain_8_1 = 0xE0
156 } TM_HMC5883L_Gain_t;
157 
158 typedef enum {
159  TM_HMC5883L_OutputRate_0_75Hz = 0x00,
160  TM_HMC5883L_OutputRate_1_5Hz = 0x04,
161  TM_HMC5883L_OutputRate_3Hz = 0x08,
162  TM_HMC5883L_OutputRate_7_5Hz = 0x0C,
163  TM_HMC5883L_OutputRate_15Hz = 0x10,
164  TM_HMC5883L_OutputRate_30Hz = 0x14,
165  TM_HMC5883L_OutputRate_75Hz = 0x18
166 } TM_HMC5883L_OutputRate_t;
167 
168 typedef struct {
169  uint8_t ID[3];
170  float X;
171  float Y;
172  float Z;
173 } TM_HMC5883L_t;
174 
185 TM_HMC5883L_Result_t TM_HMC5883L_Init(TM_HMC5883L_t* HMC5883L, TM_HMC5883L_Gain_t Gain, TM_HMC5883L_OutputRate_t OutputRate);
186 
187 TM_HMC5883L_Result_t TM_HMC5883L_DataReady(TM_HMC5883L_t* HMC5883L);
188 
189 TM_HMC5883L_Result_t TM_HMC5883L_Read(TM_HMC5883L_t* HMC5883L);
190 
191 TM_HMC5883L_Result_t TM_HMC5883L_ProcessInterrupt(TM_HMC5883L_t* HMC5883L);
192 
205 /* C++ detection */
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 #endif
Definition: tm_stm32f4_hmc5883l.h:168