TM STM32F4xx Libraries  v1.0.0
Libraries for STM32F4xx devices from Tilen Majerle
tm_stm32f4_l3gd20.h
1 
30 #ifndef TM_L3GD20_H
31 #define TM_L3GD20_H 110
32 
33 /* C++ detection */
34 #ifdef __cplusplus
35 extern C {
36 #endif
37 
100 #include "stm32f4xx.h"
101 #include "stm32f4xx_rcc.h"
102 #include "stm32f4xx_gpio.h"
103 #include "defines.h"
104 #include "tm_stm32f4_spi.h"
105 #include "tm_stm32f4_gpio.h"
106 
113 /* Default SPI, used on STM32F429 Discovery board */
114 #ifndef L3GD20_SPI
115 #define L3GD20_SPI SPI5
116 #define L3GD20_SPI_PINSPACK TM_SPI_PinsPack_1
117 #endif
118 
119 /* Default CS pin on STM32F429 Discovery board */
120 #ifndef L3GD20_CS_PIN
121 #define L3GD20_CS_PORT GPIOC
122 #define L3GD20_CS_PIN GPIO_PIN_1
123 #endif
124 
125 /* Pin macros */
126 #define L3GD20_CS_LOW TM_GPIO_SetPinLow(L3GD20_CS_PORT, L3GD20_CS_PIN)
127 #define L3GD20_CS_HIGH TM_GPIO_SetPinHigh(L3GD20_CS_PORT, L3GD20_CS_PIN)
128 
129 /* Identification number */
130 #define L3GD20_WHO_AM_I 0xD4
131 
132 /* Registers addresses */
133 #define L3GD20_REG_WHO_AM_I 0x0F
134 #define L3GD20_REG_CTRL_REG1 0x20
135 #define L3GD20_REG_CTRL_REG2 0x21
136 #define L3GD20_REG_CTRL_REG3 0x22
137 #define L3GD20_REG_CTRL_REG4 0x23
138 #define L3GD20_REG_CTRL_REG5 0x24
139 #define L3GD20_REG_REFERENCE 0x25
140 #define L3GD20_REG_OUT_TEMP 0x26
141 #define L3GD20_REG_STATUS_REG 0x27
142 #define L3GD20_REG_OUT_X_L 0x28
143 #define L3GD20_REG_OUT_X_H 0x29
144 #define L3GD20_REG_OUT_Y_L 0x2A
145 #define L3GD20_REG_OUT_Y_H 0x2B
146 #define L3GD20_REG_OUT_Z_L 0x2C
147 #define L3GD20_REG_OUT_Z_H 0x2D
148 #define L3GD20_REG_FIFO_CTRL_REG 0x2E
149 #define L3GD20_REG_FIFO_SRC_REG 0x2F
150 #define L3GD20_REG_INT1_CFG 0x30
151 #define L3GD20_REG_INT1_SRC 0x31
152 #define L3GD20_REG_INT1_TSH_XH 0x32
153 #define L3GD20_REG_INT1_TSH_XL 0x33
154 #define L3GD20_REG_INT1_TSH_YH 0x34
155 #define L3GD20_REG_INT1_TSH_YL 0x35
156 #define L3GD20_REG_INT1_TSH_ZH 0x36
157 #define L3GD20_REG_INT1_TSH_ZL 0x37
158 #define L3GD20_REG_INT1_DURATION 0x38
159 
160 /* Sensitivity factors, datasheet pg. 9 */
161 #define L3GD20_SENSITIVITY_250 8.75 /* 8.75 mdps/digit */
162 #define L3GD20_SENSITIVITY_500 17.5 /* 17.5 mdps/digit */
163 #define L3GD20_SENSITIVITY_2000 70 /* 70 mdps/digit */
164 
178 typedef struct {
179  int16_t X;
180  int16_t Y;
181  int16_t Z;
182 } TM_L3GD20_t;
183 
187 typedef enum {
191 
195 typedef enum {
200 
219 
226 
239 /* C++ detection */
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif
245 
TM_L3GD20_Result_t TM_L3GD20_Init(TM_L3GD20_Scale_t scale)
Initializes L3GD20 sensor.
int16_t Z
Definition: tm_stm32f4_l3gd20.h:181
TM_L3GD20_Result_t
L3GD20 Result enumerations.
Definition: tm_stm32f4_l3gd20.h:187
Definition: tm_stm32f4_l3gd20.h:197
int16_t X
Definition: tm_stm32f4_l3gd20.h:179
Definition: tm_stm32f4_l3gd20.h:198
L3GD20 main working structure.
Definition: tm_stm32f4_l3gd20.h:178
int16_t Y
Definition: tm_stm32f4_l3gd20.h:180
Definition: tm_stm32f4_l3gd20.h:188
Definition: tm_stm32f4_l3gd20.h:196
Definition: tm_stm32f4_l3gd20.h:189
TM_L3GD20_Result_t TM_L3GD20_Read(TM_L3GD20_t *L3DG20_Data)
Reads rotation data from sensor.
TM_L3GD20_Scale_t
Enumeration for scale select.
Definition: tm_stm32f4_l3gd20.h:195