STSW-STLKT01: Drivers/BSP/SensorTile/SensorTile.h Source File

STSW-STLKT01

STSW-STLKT01
SensorTile.h
Go to the documentation of this file.
1 
38 /* IMPORTANT: in order to compile with RevA following flag shall be defined */
39 /* in the preprocessor options: USE_SENSORTILE_REVA !!!!!!!!!! */
40 
41 /* Define to prevent recursive inclusion -------------------------------------*/
42 #ifndef __SENSORTILE_H
43 #define __SENSORTILE_H
44 
45 #ifdef __cplusplus
46  extern "C" {
47 #endif
48 
49 /* Includes ------------------------------------------------------------------*/
50 #include "stm32l4xx_hal.h"
51 #include "accelerometer.h"
52 #include "gyroscope.h"
53 
54 
55 #define LSM303AGR_ACC_WHO_AM_I 0x33
56 #define LSM303AGR_MAG_WHO_AM_I 0x40
57 #define HTS221_WHO_AM_I_VAL (uint8_t)0xBC
58 
74 typedef enum
75 {
76  LED1 = 0,
77  LEDSWD = 1
78 }Led_TypeDef;
79 
80 
81 typedef enum
82 {
83 // TEMPERATURE_SENSORS_AUTO = -1, /* Always first element and equal to -1 */
84  LSM6DSM = 0, /* LSM6DSM. */
85  LSM303AGR_X, /* LSM303AGR Accelerometer */
86  LSM303AGR_M, /* LSM303AGR Magnetometer */
87  LPS22HB /* LPS22HB */
88 } SPI_Device_t;
89 
98 #define LEDn 2
99 
100 #define LED1_PIN GPIO_PIN_12
101 #define LED1_GPIO_PORT GPIOG
102 #define LED1_GPIO_CLK_ENABLE() __GPIOG_CLK_ENABLE()
103 #define LED1_GPIO_CLK_DISABLE() __GPIOG_CLK_DISABLE()
104 
105 #define LEDSWD_PIN GPIO_PIN_14
106 #define LEDSWD_GPIO_PORT GPIOA
107 #define LEDSWD_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
108 #define LEDSWD_GPIO_CLK_DISABLE() __GPIOA_CLK_DISABLE()
109 
110 #define LEDx_GPIO_CLK_ENABLE(__INDEX__) do{if((__INDEX__) == 0) LED1_GPIO_CLK_ENABLE(); \
111  if((__INDEX__) == 1) LEDSWD_GPIO_CLK_ENABLE(); \
112  }while(0)
113 
114 #define LEDx_GPIO_CLK_DISABLE(__INDEX__) do{if((__INDEX__) == 0) LED1_GPIO_CLK_DISABLE(); \
115  if((__INDEX__) == 1) LEDSWD_GPIO_CLK_DISABLE(); \
116  }while(0)
117 
118 #define LSM6DSM_INT2_GPIO_PORT GPIOA
119 #define LSM6DSM_INT2_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
120 #define LSM6DSM_INT2_GPIO_CLK_DISABLE() __GPIOA_CLK_DISABLE()
121 #define LSM6DSM_INT2_PIN GPIO_PIN_2
122 #define LSM6DSM_INT2_EXTI_IRQn EXTI2_IRQn
123 
124 
125 #define SENSORTILE_SENSORS_SPI SPI2
126 
127 #define SENSORTILE_SENSORS_SPI_Port GPIOB
128 #define SENSORTILE_SENSORS_SPI_MOSI_Pin GPIO_PIN_15
129 #define SENSORTILE_SENSORS_SPI_SCK_Pin GPIO_PIN_13
130 
131 #define SENSORTILE_SENSORS_SPI_CLK_ENABLE() __SPI2_CLK_ENABLE()
132 #define SENSORTILE_SENSORS_SPI_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
133 
134 #define SENSORTILE_LSM6DSM_SPI_CS_Port GPIOB
135 #define SENSORTILE_LSM6DSM_SPI_CS_Pin GPIO_PIN_12
136 #define SENSORTILE_LSM6DSM_SPI_CS_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
137 
138 #define SENSORTILE_LSM303AGR_X_SPI_CS_Port GPIOC
139 #define SENSORTILE_LSM303AGR_X_SPI_CS_Pin GPIO_PIN_4
140 #define SENSORTILE_LSM303AGR_X_SPI_CS_GPIO_CLK_ENABLE() __GPIOC_CLK_ENABLE()
141 
142 #define SENSORTILE_LSM303AGR_M_SPI_CS_Port GPIOB
143 #define SENSORTILE_LSM303AGR_M_SPI_CS_Pin GPIO_PIN_1
144 #define SENSORTILE_LSM303AGR_M_SPI_CS_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
145 
146 #define SENSORTILE_LPS22HB_SPI_CS_Port GPIOA
147 #define SENSORTILE_LPS22HB_SPI_CS_Pin GPIO_PIN_3
148 #define SENSORTILE_LPS22HB_SPI_CS_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
149 
150 
151  /* I2C clock speed configuration (in Hz) */
152 #define I2C_SENSORTILE_TIMING_1000KHZ 0x00D00E28 /* Analog Filter ON, Rise time 120ns, Fall time 25ns */
153 #define I2C_SENSORTILE_TIMING_400KHZ 0x10801541
154 #define I2C_SENSORTILE_TIMING_100KHZ 0x10909CEC
155 
156  /* I2C peripheral configuration defines */
157 #define SENSORTILE_I2C_ONBOARD_SENSORS I2C3
158 #define SENSORTILE_I2C_ONBOARD_SENSORS_CLK_ENABLE() __I2C3_CLK_ENABLE()
159 #define SENSORTILE_I2C_ONBOARD_SENSORS_SCL_SDA_GPIO_CLK_ENABLE() __GPIOC_CLK_ENABLE()
160 #define SENSORTILE_I2C_ONBOARD_SENSORS_RCC_PERIPHCLK RCC_PERIPHCLK_I2C3
161 #define SENSORTILE_I2C_ONBOARD_SENSORS_I2CCLKSOURCE RCC_I2C3CLKSOURCE_SYSCLK
162 #define SENSORTILE_I2C_ONBOARD_SENSORS_SCL_SDA_AF GPIO_AF4_I2C3
163 #define SENSORTILE_I2C_ONBOARD_SENSORS_SCL_SDA_GPIO_PORT GPIOC
164 #define SENSORTILE_I2C_ONBOARD_SENSORS_SCL_PIN GPIO_PIN_0
165 #define SENSORTILE_I2C_ONBOARD_SENSORS_SDA_PIN GPIO_PIN_1
166 
167 #define SENSORTILE_I2C_ONBOARD_SENSORS_FORCE_RESET() __I2C3_FORCE_RESET()
168 #define SENSORTILE_I2C_ONBOARD_SENSORS_RELEASE_RESET() __I2C3_RELEASE_RESET()
169 
170 /* I2C interrupt requests */
171 #define SENSORTILE_I2C_ONBOARD_SENSORS_EV_IRQn I2C3_EV_IRQn
172 #define SENSORTILE_I2C_ONBOARD_SENSORS_ER_IRQn I2C3_ER_IRQn
173 
174 /* Maximum Timeout values for flags waiting loops. These timeouts are not based
175  on accurate values, they just guarantee that the application will not remain
176  stuck if the SPI communication is corrupted.
177  You may modify these timeout values depending on CPU frequency and application
178  conditions (interrupts routines ...). */
179 #define SENSORTILE_I2C_ONBOARD_SENSORS_TIMEOUT_MAX 0x1000 /*<! The value of the maximal timeout for BUS waiting loops */
180 
181 #ifdef USE_FREERTOS
182  #define SENSORTILE_I2C_ONBOARD_SENSORS_MUTEX I2C3_Mutex_id
183  #define SENSORTILE_I2C_ONBOARD_SENSORS_MUTEX_TAKE() osMutexWait(SENSORTILE_I2C_ONBOARD_SENSORS_MUTEX, 0)
184  #define SENSORTILE_I2C_ONBOARD_SENSORS_MUTEX_RELEASE() osMutexRelease(SENSORTILE_I2C_ONBOARD_SENSORS_MUTEX)
185 #else
186  #define SENSORTILE_I2C_ONBOARD_SENSORS_MUTEX 0
187  #define SENSORTILE_I2C_ONBOARD_SENSORS_MUTEX_TAKE() 0
188  #define SENSORTILE_I2C_ONBOARD_SENSORS_MUTEX_RELEASE() 0
189 #endif
190 
191 
192 /*##################### SD ###################################*/
193 /* Chip Select macro definition */
194 #define SENSORTILE_SD_CS_LOW() HAL_GPIO_WritePin(SENSORTILE_SD_CS_GPIO_PORT, SENSORTILE_SD_CS_PIN, GPIO_PIN_RESET)
195 #define SENSORTILE_SD_CS_HIGH() HAL_GPIO_WritePin(SENSORTILE_SD_CS_GPIO_PORT, SENSORTILE_SD_CS_PIN, GPIO_PIN_SET)
196 
200 #define SENSORTILE_SD_CS_PIN GPIO_PIN_12
201 #define SENSORTILE_SD_CS_GPIO_PORT GPIOG
202 #define SENSORTILE_SD_CS_GPIO_CLK_ENABLE() __GPIOG_CLK_ENABLE()
203 #define SENSORTILE_SD_CS_GPIO_CLK_DISABLE() __GPIOG_CLK_DISABLE()
204 
205 #define SENSORTILE_SD_DUMMY_BYTE 0xFF
206 #define SENSORTILE_SD_NO_RESPONSE_EXPECTED 0x80
207 
208 
209 /*##################### SPI3 SensorTile ###################################*/
210 #define SENSORTILE_SD_SPI SPI3
211 #define SENSORTILE_SD_SPI_CLK_ENABLE() __SPI3_CLK_ENABLE()
212 
213 #define SENSORTILE_SD_SPI_SCK_AF GPIO_AF6_SPI3
214 #define SENSORTILE_SD_SPI_SCK_GPIO_PORT GPIOG
215 #define SENSORTILE_SD_SPI_SCK_PIN GPIO_PIN_9
216 #define SENSORTILE_SD_SPI_SCK_GPIO_CLK_ENABLE() __GPIOG_CLK_ENABLE()
217 #define SENSORTILE_SD_SPI_SCK_GPIO_CLK_DISABLE() __GPIOG_CLK_DISABLE()
218 
219 #define SENSORTILE_SD_SPI_MISO_MOSI_AF GPIO_AF6_SPI3
220 #define SENSORTILE_SD_SPI_MISO_MOSI_GPIO_PORT GPIOG
221 #define SENSORTILE_SD_SPI_MISO_MOSI_GPIO_CLK_ENABLE() __GPIOG_CLK_ENABLE()
222 #define SENSORTILE_SD_SPI_MISO_MOSI_GPIO_CLK_DISABLE() __GPIOG_CLK_DISABLE()
223 #define SENSORTILE_SD_SPI_MISO_PIN GPIO_PIN_10
224 #define SENSORTILE_SD_SPI_MOSI_PIN GPIO_PIN_11
225 /* Maximum Timeout values for flags waiting loops. These timeouts are not based
226  on accurate values, they just guarantee that the application will not remain
227  stuck if the SPI communication is corrupted.
228  You may modify these timeout values depending on CPU frequency and application
229  conditions (interrupts routines ...). */
230 #define SENSORTILE_SD_SPI_TIMEOUT_MAX 1000
231 
246 uint32_t BSP_GetVersion(void);
247 void BSP_LED_Init(Led_TypeDef Led);
248 void BSP_LED_DeInit(Led_TypeDef Led);
249 void BSP_LED_On(Led_TypeDef Led);
250 void BSP_LED_Off(Led_TypeDef Led);
251 void BSP_LED_Toggle(Led_TypeDef Led);
252 DrvStatusTypeDef Sensor_IO_I2C_Init( void );
253 DrvStatusTypeDef Sensor_IO_SPI_Init( void );
254 uint8_t Sensor_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
255 uint8_t Sensor_IO_I2C_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
256 uint8_t Sensor_IO_SPI_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
257 uint8_t Sensor_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
258 uint8_t Sensor_IO_I2C_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
259 uint8_t Sensor_IO_SPI_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
260 uint8_t Sensor_IO_SPI_CS_Init_All(void);
261 uint8_t Sensor_IO_SPI_CS_Init(void *handle);
262 uint8_t Sensor_IO_SPI_CS_Enable(void *handle);
263 uint8_t Sensor_IO_SPI_CS_Disable(void *handle);
264 DrvStatusTypeDef LSM6DSM_Sensor_IO_ITConfig( void );
265 
266 void SD_IO_CS_Init(void);
267 void SD_IO_CS_DeInit(void);
268 
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 #endif /* __SENSORTILE_H */
290 
291 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void BSP_LED_Off(Led_TypeDef Led)
Turns selected LED Off.
Definition: SensorTile.c:241
uint32_t BSP_GetVersion(void)
This method returns the STM32446E EVAL BSP Driver revision.
Definition: SensorTile.c:159
void BSP_LED_Toggle(Led_TypeDef Led)
Toggles the selected LED.
Definition: SensorTile.c:263
uint8_t Sensor_IO_Write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite)
Writes a buffer to the sensor.
Definition: SensorTile.c:427
uint8_t Sensor_IO_Read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead)
Reads from the sensor to a buffer.
Definition: SensorTile.c:490
DrvStatusTypeDef Sensor_IO_SPI_Init(void)
Configures sensor SPI interface.
Definition: SensorTile.c:293
uint8_t Sensor_IO_I2C_Write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite)
Writes a buffer to the sensor by I2C.
Definition: SensorTile.c:472
void BSP_LED_DeInit(Led_TypeDef Led)
DeInit LEDs.
Definition: SensorTile.c:204
void BSP_LED_Init(Led_TypeDef Led)
Configures LEDs.
Definition: SensorTile.c:172
uint8_t Sensor_IO_I2C_Read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead)
Reads from the sensor to a buffer by I2C.
Definition: SensorTile.c:534
DrvStatusTypeDef LSM6DSM_Sensor_IO_ITConfig(void)
Configures sensor interrupts interface for LSM6DSM sensor.
Definition: SensorTile.c:664
DrvStatusTypeDef Sensor_IO_I2C_Init(void)
Configures sensor SPI interface.
Definition: SensorTile.c:274
uint8_t Sensor_IO_SPI_Write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite)
Writes a buffer to the sensor.
Definition: SensorTile.c:553
void BSP_LED_On(Led_TypeDef Led)
Turns selected LED On.
Definition: SensorTile.c:219
uint8_t Sensor_IO_SPI_Read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead)
Reads a from the sensor to buffer.
Definition: SensorTile.c:581
Generated by   doxygen 1.8.13