Audio Demo with DISCO Board, takes control samples, waits for user input, samples regularly.

Dependencies:   CMSIS_DSP_401 STM32L4xx_HAL_Driver mbed-src_DISO_AUDIO_DEMO

Committer:
EricLew
Date:
Sun Dec 13 19:12:11 2015 +0000
Revision:
0:3eee9435dd17
Audio Demo using DISCO Board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EricLew 0:3eee9435dd17 1 /**
EricLew 0:3eee9435dd17 2 ******************************************************************************
EricLew 0:3eee9435dd17 3 * @file stm32l476g_discovery.c
EricLew 0:3eee9435dd17 4 * @author MCD Application Team
EricLew 0:3eee9435dd17 5 * @version V1.0.1
EricLew 0:3eee9435dd17 6 * @date 16-September-2015
EricLew 0:3eee9435dd17 7 * @brief This file provides a set of firmware functions to manage Leds,
EricLew 0:3eee9435dd17 8 * push-button and joystick of STM32L476G-Discovery board (MB1184)
EricLew 0:3eee9435dd17 9 ******************************************************************************
EricLew 0:3eee9435dd17 10 * @attention
EricLew 0:3eee9435dd17 11 *
EricLew 0:3eee9435dd17 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
EricLew 0:3eee9435dd17 13 *
EricLew 0:3eee9435dd17 14 * Redistribution and use in source and binary forms, with or without modification,
EricLew 0:3eee9435dd17 15 * are permitted provided that the following conditions are met:
EricLew 0:3eee9435dd17 16 * 1. Redistributions of source code must retain the above copyright notice,
EricLew 0:3eee9435dd17 17 * this list of conditions and the following disclaimer.
EricLew 0:3eee9435dd17 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
EricLew 0:3eee9435dd17 19 * this list of conditions and the following disclaimer in the documentation
EricLew 0:3eee9435dd17 20 * and/or other materials provided with the distribution.
EricLew 0:3eee9435dd17 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
EricLew 0:3eee9435dd17 22 * may be used to endorse or promote products derived from this software
EricLew 0:3eee9435dd17 23 * without specific prior written permission.
EricLew 0:3eee9435dd17 24 *
EricLew 0:3eee9435dd17 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
EricLew 0:3eee9435dd17 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
EricLew 0:3eee9435dd17 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
EricLew 0:3eee9435dd17 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
EricLew 0:3eee9435dd17 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
EricLew 0:3eee9435dd17 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
EricLew 0:3eee9435dd17 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
EricLew 0:3eee9435dd17 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
EricLew 0:3eee9435dd17 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
EricLew 0:3eee9435dd17 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
EricLew 0:3eee9435dd17 35 *
EricLew 0:3eee9435dd17 36 ******************************************************************************
EricLew 0:3eee9435dd17 37 */
EricLew 0:3eee9435dd17 38
EricLew 0:3eee9435dd17 39 /* Includes ------------------------------------------------------------------*/
EricLew 0:3eee9435dd17 40 #include "stm32l476g_discovery.h"
EricLew 0:3eee9435dd17 41
EricLew 0:3eee9435dd17 42 /** @addtogroup BSP
EricLew 0:3eee9435dd17 43 * @{
EricLew 0:3eee9435dd17 44 */
EricLew 0:3eee9435dd17 45
EricLew 0:3eee9435dd17 46 /** @defgroup STM32L476G_DISCOVERY STM32L476G-DISCOVERY
EricLew 0:3eee9435dd17 47 * @{
EricLew 0:3eee9435dd17 48 */
EricLew 0:3eee9435dd17 49
EricLew 0:3eee9435dd17 50 /** @defgroup STM32L476G_DISCOVERY_Common STM32L476G-DISCOVERY Common
EricLew 0:3eee9435dd17 51 * @{
EricLew 0:3eee9435dd17 52 */
EricLew 0:3eee9435dd17 53
EricLew 0:3eee9435dd17 54 /** @defgroup STM32L476G_DISCOVERY_Private_TypesDefinitions Private Types Definitions
EricLew 0:3eee9435dd17 55 * @brief This file provides firmware functions to manage Leds, push-buttons,
EricLew 0:3eee9435dd17 56 * COM ports, SD card on SPI and temperature sensor (TS751) available on
EricLew 0:3eee9435dd17 57 * STM32L476G-DISCOVERY discoveryuation board from STMicroelectronics.
EricLew 0:3eee9435dd17 58 * @{
EricLew 0:3eee9435dd17 59 */
EricLew 0:3eee9435dd17 60
EricLew 0:3eee9435dd17 61 /**
EricLew 0:3eee9435dd17 62 * @}
EricLew 0:3eee9435dd17 63 */
EricLew 0:3eee9435dd17 64
EricLew 0:3eee9435dd17 65 /** @defgroup STM32L476G_DISCOVERY_Private_Defines Private Defines
EricLew 0:3eee9435dd17 66 * @{
EricLew 0:3eee9435dd17 67 */
EricLew 0:3eee9435dd17 68
EricLew 0:3eee9435dd17 69 /**
EricLew 0:3eee9435dd17 70 * @brief STM32L476G DISCOVERY BSP Driver version number V1.0.1
EricLew 0:3eee9435dd17 71 */
EricLew 0:3eee9435dd17 72 #define __STM32L476G_DISCOVERY_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
EricLew 0:3eee9435dd17 73 #define __STM32L476G_DISCOVERY_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
EricLew 0:3eee9435dd17 74 #define __STM32L476G_DISCOVERY_BSP_VERSION_SUB2 (0x01) /*!< [15:8] sub2 version */
EricLew 0:3eee9435dd17 75 #define __STM32L476G_DISCOVERY_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
EricLew 0:3eee9435dd17 76 #define __STM32L476G_DISCOVERY_BSP_VERSION ((__STM32L476G_DISCOVERY_BSP_VERSION_MAIN << 24)\
EricLew 0:3eee9435dd17 77 |(__STM32L476G_DISCOVERY_BSP_VERSION_SUB1 << 16)\
EricLew 0:3eee9435dd17 78 |(__STM32L476G_DISCOVERY_BSP_VERSION_SUB2 << 8 )\
EricLew 0:3eee9435dd17 79 |(__STM32L476G_DISCOVERY_BSP_VERSION_RC))
EricLew 0:3eee9435dd17 80 /**
EricLew 0:3eee9435dd17 81 * @}
EricLew 0:3eee9435dd17 82 */
EricLew 0:3eee9435dd17 83
EricLew 0:3eee9435dd17 84
EricLew 0:3eee9435dd17 85 /** @defgroup STM32L476G_DISCOVERY_Private_Macros Private Macros
EricLew 0:3eee9435dd17 86 * @{
EricLew 0:3eee9435dd17 87 */
EricLew 0:3eee9435dd17 88
EricLew 0:3eee9435dd17 89 /**
EricLew 0:3eee9435dd17 90 * @}
EricLew 0:3eee9435dd17 91 */
EricLew 0:3eee9435dd17 92
EricLew 0:3eee9435dd17 93
EricLew 0:3eee9435dd17 94 /** @defgroup STM32L476G_DISCOVERY_Exported_Variables Exported Variables
EricLew 0:3eee9435dd17 95 * @{
EricLew 0:3eee9435dd17 96 */
EricLew 0:3eee9435dd17 97
EricLew 0:3eee9435dd17 98 /**
EricLew 0:3eee9435dd17 99 * @brief LED variables
EricLew 0:3eee9435dd17 100 */
EricLew 0:3eee9435dd17 101 #if defined (USE_STM32L476G_DISCO_REVC) || defined (USE_STM32L476G_DISCO_REVB)
EricLew 0:3eee9435dd17 102 GPIO_TypeDef* LED_PORT[LEDn] = {LED4_GPIO_PORT,
EricLew 0:3eee9435dd17 103 LED5_GPIO_PORT};
EricLew 0:3eee9435dd17 104
EricLew 0:3eee9435dd17 105 const uint16_t LED_PIN[LEDn] = {LED4_PIN,
EricLew 0:3eee9435dd17 106 LED5_PIN};
EricLew 0:3eee9435dd17 107 #elif defined (USE_STM32L476G_DISCO_REVA)
EricLew 0:3eee9435dd17 108 GPIO_TypeDef* LED_PORT[LEDn] = {LED3_GPIO_PORT,
EricLew 0:3eee9435dd17 109 LED4_GPIO_PORT};
EricLew 0:3eee9435dd17 110
EricLew 0:3eee9435dd17 111 const uint16_t LED_PIN[LEDn] = {LED3_PIN,
EricLew 0:3eee9435dd17 112 LED4_PIN};
EricLew 0:3eee9435dd17 113 #endif
EricLew 0:3eee9435dd17 114
EricLew 0:3eee9435dd17 115
EricLew 0:3eee9435dd17 116 /**
EricLew 0:3eee9435dd17 117 * @brief JOYSTICK variables
EricLew 0:3eee9435dd17 118 */
EricLew 0:3eee9435dd17 119 GPIO_TypeDef* JOY_PORT[JOYn] = {SEL_JOY_GPIO_PORT,
EricLew 0:3eee9435dd17 120 DOWN_JOY_GPIO_PORT,
EricLew 0:3eee9435dd17 121 LEFT_JOY_GPIO_PORT,
EricLew 0:3eee9435dd17 122 RIGHT_JOY_GPIO_PORT,
EricLew 0:3eee9435dd17 123 UP_JOY_GPIO_PORT};
EricLew 0:3eee9435dd17 124
EricLew 0:3eee9435dd17 125 const uint16_t JOY_PIN[JOYn] = {SEL_JOY_PIN,
EricLew 0:3eee9435dd17 126 LEFT_JOY_PIN,
EricLew 0:3eee9435dd17 127 RIGHT_JOY_PIN,
EricLew 0:3eee9435dd17 128 DOWN_JOY_PIN,
EricLew 0:3eee9435dd17 129 UP_JOY_PIN};
EricLew 0:3eee9435dd17 130
EricLew 0:3eee9435dd17 131 const uint8_t JOY_IRQn[JOYn] = {SEL_JOY_EXTI_IRQn,
EricLew 0:3eee9435dd17 132 LEFT_JOY_EXTI_IRQn,
EricLew 0:3eee9435dd17 133 RIGHT_JOY_EXTI_IRQn,
EricLew 0:3eee9435dd17 134 DOWN_JOY_EXTI_IRQn,
EricLew 0:3eee9435dd17 135 UP_JOY_EXTI_IRQn};
EricLew 0:3eee9435dd17 136
EricLew 0:3eee9435dd17 137 /**
EricLew 0:3eee9435dd17 138 * @brief BUS variables
EricLew 0:3eee9435dd17 139 */
EricLew 0:3eee9435dd17 140 #if defined(HAL_I2C_MODULE_ENABLED)
EricLew 0:3eee9435dd17 141 uint32_t I2c1Timeout = DISCOVERY_I2C2_TIMEOUT_MAX; /*<! Value of Timeout when I2C1 communication fails */
EricLew 0:3eee9435dd17 142 uint32_t I2c2Timeout = DISCOVERY_I2C2_TIMEOUT_MAX; /*<! Value of Timeout when I2C2 communication fails */
EricLew 0:3eee9435dd17 143 static I2C_HandleTypeDef I2c1Handle;
EricLew 0:3eee9435dd17 144 static I2C_HandleTypeDef I2c2Handle;
EricLew 0:3eee9435dd17 145 #endif /* HAL_I2C_MODULE_ENABLED */
EricLew 0:3eee9435dd17 146
EricLew 0:3eee9435dd17 147 #if defined(HAL_SPI_MODULE_ENABLED)
EricLew 0:3eee9435dd17 148
EricLew 0:3eee9435dd17 149 /* LL definition */
EricLew 0:3eee9435dd17 150 #define __SPI_DIRECTION_2LINES(__HANDLE__) do{\
EricLew 0:3eee9435dd17 151 CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE);\
EricLew 0:3eee9435dd17 152 }while(0);
EricLew 0:3eee9435dd17 153
EricLew 0:3eee9435dd17 154 #define __SPI_DIRECTION_2LINES_RXONLY(__HANDLE__) do{\
EricLew 0:3eee9435dd17 155 CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE);\
EricLew 0:3eee9435dd17 156 SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_RXONLY);\
EricLew 0:3eee9435dd17 157 }while(0);
EricLew 0:3eee9435dd17 158
EricLew 0:3eee9435dd17 159 #define __SPI_DIRECTION_1LINE_TX(__HANDLE__) do{\
EricLew 0:3eee9435dd17 160 CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE);\
EricLew 0:3eee9435dd17 161 SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE);\
EricLew 0:3eee9435dd17 162 }while(0);
EricLew 0:3eee9435dd17 163
EricLew 0:3eee9435dd17 164 #define __SPI_DIRECTION_1LINE_RX(__HANDLE__) do {\
EricLew 0:3eee9435dd17 165 CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE);\
EricLew 0:3eee9435dd17 166 SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIMODE);\
EricLew 0:3eee9435dd17 167 } while(0);
EricLew 0:3eee9435dd17 168
EricLew 0:3eee9435dd17 169
EricLew 0:3eee9435dd17 170 uint32_t SpixTimeout = SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */
EricLew 0:3eee9435dd17 171 static SPI_HandleTypeDef SpiHandle;
EricLew 0:3eee9435dd17 172 #endif /* HAL_SPI_MODULE_ENABLED */
EricLew 0:3eee9435dd17 173
EricLew 0:3eee9435dd17 174 /**
EricLew 0:3eee9435dd17 175 * @}
EricLew 0:3eee9435dd17 176 */
EricLew 0:3eee9435dd17 177
EricLew 0:3eee9435dd17 178 /** @defgroup STM32L476G_DISCOVERY_Private_FunctionPrototypes Private Functions
EricLew 0:3eee9435dd17 179 * @{
EricLew 0:3eee9435dd17 180 */
EricLew 0:3eee9435dd17 181 /**************************** Bus functions ************************************/
EricLew 0:3eee9435dd17 182 /* I2C2 bus function */
EricLew 0:3eee9435dd17 183 #if defined(HAL_I2C_MODULE_ENABLED)
EricLew 0:3eee9435dd17 184 static void I2C2_Init(void);
EricLew 0:3eee9435dd17 185 static void I2C2_MspInit(I2C_HandleTypeDef *hi2c);
EricLew 0:3eee9435dd17 186 static void I2C2_DeInit(void);
EricLew 0:3eee9435dd17 187 static void I2C2_MspDeInit(I2C_HandleTypeDef *hi2c);
EricLew 0:3eee9435dd17 188 static void I2C2_WriteData(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t Value);
EricLew 0:3eee9435dd17 189 static HAL_StatusTypeDef I2C2_WriteBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length);
EricLew 0:3eee9435dd17 190 static uint8_t I2C2_ReadData(uint16_t Addr, uint16_t Reg, uint16_t RegSize);
EricLew 0:3eee9435dd17 191 static HAL_StatusTypeDef I2C2_ReadBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length);
EricLew 0:3eee9435dd17 192 static void I2C2_Error (void);
EricLew 0:3eee9435dd17 193
EricLew 0:3eee9435dd17 194 static void I2C1_Init(void);
EricLew 0:3eee9435dd17 195 static void I2C1_MspInit(I2C_HandleTypeDef *hi2c);
EricLew 0:3eee9435dd17 196 static void I2C1_DeInit(void);
EricLew 0:3eee9435dd17 197 static void I2C1_MspDeInit(I2C_HandleTypeDef *hi2c);
EricLew 0:3eee9435dd17 198 static HAL_StatusTypeDef I2C1_WriteBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length);
EricLew 0:3eee9435dd17 199 static HAL_StatusTypeDef I2C1_ReadBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length);
EricLew 0:3eee9435dd17 200 static void I2C1_Error (void);
EricLew 0:3eee9435dd17 201 #endif/* HAL_I2C_MODULE_ENABLED */
EricLew 0:3eee9435dd17 202
EricLew 0:3eee9435dd17 203 /* SPIx bus function */
EricLew 0:3eee9435dd17 204 #if defined(HAL_SPI_MODULE_ENABLED)
EricLew 0:3eee9435dd17 205 static void SPIx_Init(void);
EricLew 0:3eee9435dd17 206 static void SPIx_MspInit(SPI_HandleTypeDef *hspi);
EricLew 0:3eee9435dd17 207 static void SPIx_DeInit(void);
EricLew 0:3eee9435dd17 208 static void SPIx_MspDeInit(void);
EricLew 0:3eee9435dd17 209 static uint8_t SPIx_WriteRead(uint8_t Byte);
EricLew 0:3eee9435dd17 210 static void SPIx_Write(uint8_t byte);
EricLew 0:3eee9435dd17 211 static uint8_t SPIx_Read(void);
EricLew 0:3eee9435dd17 212 #endif
EricLew 0:3eee9435dd17 213
EricLew 0:3eee9435dd17 214 /**************************** Link functions ***********************************/
EricLew 0:3eee9435dd17 215 #if defined(HAL_I2C_MODULE_ENABLED)
EricLew 0:3eee9435dd17 216 /* Link functions for EEPROM peripheral over I2C */
EricLew 0:3eee9435dd17 217 void EEPROM_I2C_IO_Init(void);
EricLew 0:3eee9435dd17 218 HAL_StatusTypeDef EEPROM_I2C_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
EricLew 0:3eee9435dd17 219 HAL_StatusTypeDef EEPROM_I2C_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
EricLew 0:3eee9435dd17 220 HAL_StatusTypeDef EEPROM_I2C_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
EricLew 0:3eee9435dd17 221
EricLew 0:3eee9435dd17 222 /* Link functions for Audio Codec peripheral */
EricLew 0:3eee9435dd17 223 void AUDIO_IO_Init(void);
EricLew 0:3eee9435dd17 224 void AUDIO_IO_DeInit(void);
EricLew 0:3eee9435dd17 225 void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
EricLew 0:3eee9435dd17 226 uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg);
EricLew 0:3eee9435dd17 227 void AUDIO_IO_Delay(uint32_t delay);
EricLew 0:3eee9435dd17 228 #endif/* HAL_I2C_MODULE_ENABLED */
EricLew 0:3eee9435dd17 229
EricLew 0:3eee9435dd17 230 #if defined(HAL_SPI_MODULE_ENABLED)
EricLew 0:3eee9435dd17 231 /* Link function for COMPASS / ACCELERO peripheral */
EricLew 0:3eee9435dd17 232 void ACCELERO_IO_Init(void);
EricLew 0:3eee9435dd17 233 void ACCELERO_IO_DeInit(void);
EricLew 0:3eee9435dd17 234 void ACCELERO_IO_ITConfig(void);
EricLew 0:3eee9435dd17 235 void ACCELERO_IO_Write(uint8_t RegisterAddr, uint8_t Value);
EricLew 0:3eee9435dd17 236 uint8_t ACCELERO_IO_Read(uint8_t RegisterAddr);
EricLew 0:3eee9435dd17 237
EricLew 0:3eee9435dd17 238 void MAGNETO_IO_Init(void);
EricLew 0:3eee9435dd17 239 void MAGNETO_IO_DeInit(void);
EricLew 0:3eee9435dd17 240 void MAGNETO_IO_ITConfig(void);
EricLew 0:3eee9435dd17 241 void MAGNETO_IO_Write(uint8_t RegisterAddr, uint8_t Value);
EricLew 0:3eee9435dd17 242 uint8_t MAGNETO_IO_Read(uint8_t RegisterAddr);
EricLew 0:3eee9435dd17 243
EricLew 0:3eee9435dd17 244
EricLew 0:3eee9435dd17 245 /* Link functions for GYRO peripheral */
EricLew 0:3eee9435dd17 246 void GYRO_IO_Init(void);
EricLew 0:3eee9435dd17 247 void GYRO_IO_DeInit(void);
EricLew 0:3eee9435dd17 248 void GYRO_IO_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite);
EricLew 0:3eee9435dd17 249 void GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead);
EricLew 0:3eee9435dd17 250
EricLew 0:3eee9435dd17 251 #endif
EricLew 0:3eee9435dd17 252
EricLew 0:3eee9435dd17 253 #if defined(HAL_I2C_MODULE_ENABLED)
EricLew 0:3eee9435dd17 254 /* Link functions IOExpander */
EricLew 0:3eee9435dd17 255 void IOE_Init(void);
EricLew 0:3eee9435dd17 256 void IOE_ITConfig(void);
EricLew 0:3eee9435dd17 257 void IOE_Delay(uint32_t Delay);
EricLew 0:3eee9435dd17 258 void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
EricLew 0:3eee9435dd17 259 uint8_t IOE_Read(uint8_t Addr, uint8_t Reg);
EricLew 0:3eee9435dd17 260 uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
EricLew 0:3eee9435dd17 261
EricLew 0:3eee9435dd17 262 /* Link functions for IDD measurment */
EricLew 0:3eee9435dd17 263 void MFX_IO_Init(void);
EricLew 0:3eee9435dd17 264 void MFX_IO_DeInit(void);
EricLew 0:3eee9435dd17 265 void MFX_IO_ITConfig (void);
EricLew 0:3eee9435dd17 266 void MFX_IO_EnableWakeupPin(void);
EricLew 0:3eee9435dd17 267 void MFX_IO_Wakeup(void);
EricLew 0:3eee9435dd17 268 void MFX_IO_Delay(uint32_t delay);
EricLew 0:3eee9435dd17 269 void MFX_IO_Write(uint16_t addr, uint8_t reg, uint8_t value);
EricLew 0:3eee9435dd17 270 uint8_t MFX_IO_Read(uint16_t addr, uint8_t reg);
EricLew 0:3eee9435dd17 271 void MFX_IO_WriteMultiple(uint16_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
EricLew 0:3eee9435dd17 272 uint16_t MFX_IO_ReadMultiple(uint16_t addr, uint8_t reg, uint8_t *buffer, uint16_t length);
EricLew 0:3eee9435dd17 273 #endif/* HAL_I2C_MODULE_ENABLED */
EricLew 0:3eee9435dd17 274 /**
EricLew 0:3eee9435dd17 275 * @}
EricLew 0:3eee9435dd17 276 */
EricLew 0:3eee9435dd17 277
EricLew 0:3eee9435dd17 278 /** @defgroup STM32L476G_DISCOVERY_Exported_Functions Exported Functions
EricLew 0:3eee9435dd17 279 * @{
EricLew 0:3eee9435dd17 280 */
EricLew 0:3eee9435dd17 281
EricLew 0:3eee9435dd17 282 /**
EricLew 0:3eee9435dd17 283 * @brief This method returns the STM32L476 DISCOVERY BSP Driver revision
EricLew 0:3eee9435dd17 284 * @retval version : 0xXYZR (8bits for each decimal, R for RC)
EricLew 0:3eee9435dd17 285 */
EricLew 0:3eee9435dd17 286 uint32_t BSP_GetVersion(void)
EricLew 0:3eee9435dd17 287 {
EricLew 0:3eee9435dd17 288 return __STM32L476G_DISCOVERY_BSP_VERSION;
EricLew 0:3eee9435dd17 289 }
EricLew 0:3eee9435dd17 290
EricLew 0:3eee9435dd17 291 /**
EricLew 0:3eee9435dd17 292 * @brief This method returns the STM32L476 DISCOVERY supply mode
EricLew 0:3eee9435dd17 293 * @retval Code of current supply mode
EricLew 0:3eee9435dd17 294 * This code can be one of following:
EricLew 0:3eee9435dd17 295 * @arg SUPPLY_MODE_EXTERNAL
EricLew 0:3eee9435dd17 296 * @arg SUPPLY_MODE_BATTERY
EricLew 0:3eee9435dd17 297 */
EricLew 0:3eee9435dd17 298 SupplyMode_TypeDef BSP_SupplyModeDetection(void)
EricLew 0:3eee9435dd17 299 {
EricLew 0:3eee9435dd17 300 SupplyMode_TypeDef supplymode = SUPPLY_MODE_ERROR;
EricLew 0:3eee9435dd17 301 GPIO_InitTypeDef GPIO_InitStruct;
EricLew 0:3eee9435dd17 302
EricLew 0:3eee9435dd17 303 BATTERY_DETECTION_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 304
EricLew 0:3eee9435dd17 305 /* COMP GPIO pin configuration */
EricLew 0:3eee9435dd17 306 GPIO_InitStruct.Pin = BATTERY_DETECTION_PIN;
EricLew 0:3eee9435dd17 307 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
EricLew 0:3eee9435dd17 308 GPIO_InitStruct.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 309 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 310 HAL_GPIO_Init(BATTERY_DETECTION_GPIO_PORT, &GPIO_InitStruct);
EricLew 0:3eee9435dd17 311
EricLew 0:3eee9435dd17 312 HAL_Delay(400);
EricLew 0:3eee9435dd17 313 if(HAL_GPIO_ReadPin(BATTERY_DETECTION_GPIO_PORT, GPIO_InitStruct.Pin) != GPIO_PIN_RESET)
EricLew 0:3eee9435dd17 314 {
EricLew 0:3eee9435dd17 315 supplymode = SUPPLY_MODE_EXTERNAL;
EricLew 0:3eee9435dd17 316 }
EricLew 0:3eee9435dd17 317 else
EricLew 0:3eee9435dd17 318 {
EricLew 0:3eee9435dd17 319 supplymode = SUPPLY_MODE_BATTERY;
EricLew 0:3eee9435dd17 320 }
EricLew 0:3eee9435dd17 321
EricLew 0:3eee9435dd17 322 HAL_GPIO_DeInit(BATTERY_DETECTION_GPIO_PORT, GPIO_InitStruct.Pin);
EricLew 0:3eee9435dd17 323
EricLew 0:3eee9435dd17 324 return supplymode;
EricLew 0:3eee9435dd17 325 }
EricLew 0:3eee9435dd17 326
EricLew 0:3eee9435dd17 327 #if defined (USE_STM32L476G_DISCO_REVC) || defined (USE_STM32L476G_DISCO_REVB)
EricLew 0:3eee9435dd17 328 /**
EricLew 0:3eee9435dd17 329 * @brief Configures LED GPIOs.
EricLew 0:3eee9435dd17 330 * @param Led: Specifies the Led to be configured.
EricLew 0:3eee9435dd17 331 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 332 * @arg LED4
EricLew 0:3eee9435dd17 333 * @arg LED5
EricLew 0:3eee9435dd17 334 * @retval None
EricLew 0:3eee9435dd17 335 */
EricLew 0:3eee9435dd17 336 #elif defined (USE_STM32L476G_DISCO_REVA)
EricLew 0:3eee9435dd17 337 /**
EricLew 0:3eee9435dd17 338 * @brief Configures LED GPIOs.
EricLew 0:3eee9435dd17 339 * @param Led: Specifies the Led to be configured.
EricLew 0:3eee9435dd17 340 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 341 * @arg LED3
EricLew 0:3eee9435dd17 342 * @arg LED4
EricLew 0:3eee9435dd17 343 * @retval None
EricLew 0:3eee9435dd17 344 */
EricLew 0:3eee9435dd17 345 #endif
EricLew 0:3eee9435dd17 346 void BSP_LED_Init(Led_TypeDef Led)
EricLew 0:3eee9435dd17 347 {
EricLew 0:3eee9435dd17 348 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 349
EricLew 0:3eee9435dd17 350 /* Enable the GPIO_LED clock */
EricLew 0:3eee9435dd17 351 LEDx_GPIO_CLK_ENABLE(Led);
EricLew 0:3eee9435dd17 352
EricLew 0:3eee9435dd17 353 /* Configure the GPIO_LED pin */
EricLew 0:3eee9435dd17 354 GPIO_InitStructure.Pin = LED_PIN[Led];
EricLew 0:3eee9435dd17 355 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 356 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 357 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 358
EricLew 0:3eee9435dd17 359 HAL_GPIO_Init(LED_PORT[Led], &GPIO_InitStructure);
EricLew 0:3eee9435dd17 360
EricLew 0:3eee9435dd17 361 HAL_GPIO_WritePin(LED_PORT[Led], GPIO_InitStructure.Pin, GPIO_PIN_RESET);
EricLew 0:3eee9435dd17 362 }
EricLew 0:3eee9435dd17 363
EricLew 0:3eee9435dd17 364 #if defined (USE_STM32L476G_DISCO_REVC) || defined (USE_STM32L476G_DISCO_REVB)
EricLew 0:3eee9435dd17 365 /**
EricLew 0:3eee9435dd17 366 * @brief Unconfigures LED GPIOs.
EricLew 0:3eee9435dd17 367 * @param Led: Specifies the Led to be unconfigured.
EricLew 0:3eee9435dd17 368 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 369 * @arg LED4
EricLew 0:3eee9435dd17 370 * @arg LED5
EricLew 0:3eee9435dd17 371 * @retval None
EricLew 0:3eee9435dd17 372 */
EricLew 0:3eee9435dd17 373 #elif defined (USE_STM32L476G_DISCO_REVA)
EricLew 0:3eee9435dd17 374 /**
EricLew 0:3eee9435dd17 375 * @brief Unconfigures LED GPIOs.
EricLew 0:3eee9435dd17 376 * @param Led: Specifies the Led to be unconfigured.
EricLew 0:3eee9435dd17 377 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 378 * @arg LED3
EricLew 0:3eee9435dd17 379 * @arg LED4
EricLew 0:3eee9435dd17 380 * @retval None
EricLew 0:3eee9435dd17 381 */
EricLew 0:3eee9435dd17 382 #endif
EricLew 0:3eee9435dd17 383 void BSP_LED_DeInit(Led_TypeDef Led)
EricLew 0:3eee9435dd17 384 {
EricLew 0:3eee9435dd17 385 /* Enable the GPIO_LED clock */
EricLew 0:3eee9435dd17 386 LEDx_GPIO_CLK_ENABLE(Led);
EricLew 0:3eee9435dd17 387
EricLew 0:3eee9435dd17 388 HAL_GPIO_DeInit(LED_PORT[Led], LED_PIN[Led]);
EricLew 0:3eee9435dd17 389 }
EricLew 0:3eee9435dd17 390
EricLew 0:3eee9435dd17 391 #if defined (USE_STM32L476G_DISCO_REVC) || defined (USE_STM32L476G_DISCO_REVB)
EricLew 0:3eee9435dd17 392 /**
EricLew 0:3eee9435dd17 393 * @brief Turns selected LED On.
EricLew 0:3eee9435dd17 394 * @param Led: Specifies the Led to be set on.
EricLew 0:3eee9435dd17 395 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 396 * @arg LED4
EricLew 0:3eee9435dd17 397 * @arg LED5
EricLew 0:3eee9435dd17 398 * @retval None
EricLew 0:3eee9435dd17 399 */
EricLew 0:3eee9435dd17 400 #elif defined (USE_STM32L476G_DISCO_REVA)
EricLew 0:3eee9435dd17 401 /**
EricLew 0:3eee9435dd17 402 * @brief Turns selected LED On.
EricLew 0:3eee9435dd17 403 * @param Led: Specifies the Led to be set on.
EricLew 0:3eee9435dd17 404 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 405 * @arg LED3
EricLew 0:3eee9435dd17 406 * @arg LED4
EricLew 0:3eee9435dd17 407 * @retval None
EricLew 0:3eee9435dd17 408 */
EricLew 0:3eee9435dd17 409 #endif
EricLew 0:3eee9435dd17 410 void BSP_LED_On(Led_TypeDef Led)
EricLew 0:3eee9435dd17 411 {
EricLew 0:3eee9435dd17 412 HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
EricLew 0:3eee9435dd17 413 }
EricLew 0:3eee9435dd17 414
EricLew 0:3eee9435dd17 415 #if defined (USE_STM32L476G_DISCO_REVC) || defined (USE_STM32L476G_DISCO_REVB)
EricLew 0:3eee9435dd17 416 /**
EricLew 0:3eee9435dd17 417 * @brief Turns selected LED Off.
EricLew 0:3eee9435dd17 418 * @param Led: Specifies the Led to be set off.
EricLew 0:3eee9435dd17 419 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 420 * @arg LED4
EricLew 0:3eee9435dd17 421 * @arg LED5
EricLew 0:3eee9435dd17 422 * @retval None
EricLew 0:3eee9435dd17 423 */
EricLew 0:3eee9435dd17 424 #elif defined (USE_STM32L476G_DISCO_REVA)
EricLew 0:3eee9435dd17 425 /**
EricLew 0:3eee9435dd17 426 * @brief Turns selected LED Off.
EricLew 0:3eee9435dd17 427 * @param Led: Specifies the Led to be set off.
EricLew 0:3eee9435dd17 428 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 429 * @arg LED3
EricLew 0:3eee9435dd17 430 * @arg LED4
EricLew 0:3eee9435dd17 431 * @retval None
EricLew 0:3eee9435dd17 432 */
EricLew 0:3eee9435dd17 433 #endif
EricLew 0:3eee9435dd17 434 void BSP_LED_Off(Led_TypeDef Led)
EricLew 0:3eee9435dd17 435 {
EricLew 0:3eee9435dd17 436 HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
EricLew 0:3eee9435dd17 437 }
EricLew 0:3eee9435dd17 438
EricLew 0:3eee9435dd17 439 #if defined (USE_STM32L476G_DISCO_REVC) || defined (USE_STM32L476G_DISCO_REVB)
EricLew 0:3eee9435dd17 440 /**
EricLew 0:3eee9435dd17 441 * @brief Toggles the selected LED.
EricLew 0:3eee9435dd17 442 * @param Led: Specifies the Led to be toggled.
EricLew 0:3eee9435dd17 443 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 444 * @arg LED4
EricLew 0:3eee9435dd17 445 * @arg LED5
EricLew 0:3eee9435dd17 446 * @retval None
EricLew 0:3eee9435dd17 447 */
EricLew 0:3eee9435dd17 448 #elif defined (USE_STM32L476G_DISCO_REVA)
EricLew 0:3eee9435dd17 449 /**
EricLew 0:3eee9435dd17 450 * @brief Toggles the selected LED.
EricLew 0:3eee9435dd17 451 * @param Led: Specifies the Led to be toggled.
EricLew 0:3eee9435dd17 452 * This parameter can be one of following parameters:
EricLew 0:3eee9435dd17 453 * @arg LED3
EricLew 0:3eee9435dd17 454 * @arg LED4
EricLew 0:3eee9435dd17 455 * @retval None
EricLew 0:3eee9435dd17 456 */
EricLew 0:3eee9435dd17 457 #endif
EricLew 0:3eee9435dd17 458 void BSP_LED_Toggle(Led_TypeDef Led)
EricLew 0:3eee9435dd17 459 {
EricLew 0:3eee9435dd17 460 HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
EricLew 0:3eee9435dd17 461 }
EricLew 0:3eee9435dd17 462
EricLew 0:3eee9435dd17 463 /**
EricLew 0:3eee9435dd17 464 * @brief Configures all buttons of the joystick in GPIO or EXTI modes.
EricLew 0:3eee9435dd17 465 * @param Joy_Mode: Joystick mode.
EricLew 0:3eee9435dd17 466 * This parameter can be one of the following values:
EricLew 0:3eee9435dd17 467 * @arg JOY_MODE_GPIO: Joystick pins will be used as simple IOs
EricLew 0:3eee9435dd17 468 * @arg JOY_MODE_EXTI: Joystick pins will be connected to EXTI line
EricLew 0:3eee9435dd17 469 * with interrupt generation capability
EricLew 0:3eee9435dd17 470 * @retval HAL_OK: if all initializations are OK. Other value if error.
EricLew 0:3eee9435dd17 471 */
EricLew 0:3eee9435dd17 472 uint8_t BSP_JOY_Init(JOYMode_TypeDef Joy_Mode)
EricLew 0:3eee9435dd17 473 {
EricLew 0:3eee9435dd17 474 JOYState_TypeDef joykey;
EricLew 0:3eee9435dd17 475 GPIO_InitTypeDef GPIO_InitStruct;
EricLew 0:3eee9435dd17 476
EricLew 0:3eee9435dd17 477 /* Initialized the Joystick. */
EricLew 0:3eee9435dd17 478 for(joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++)
EricLew 0:3eee9435dd17 479 {
EricLew 0:3eee9435dd17 480 /* Enable the JOY clock */
EricLew 0:3eee9435dd17 481 JOYx_GPIO_CLK_ENABLE(joykey);
EricLew 0:3eee9435dd17 482
EricLew 0:3eee9435dd17 483 GPIO_InitStruct.Pin = JOY_PIN[joykey];
EricLew 0:3eee9435dd17 484 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
EricLew 0:3eee9435dd17 485 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 486
EricLew 0:3eee9435dd17 487 if (Joy_Mode == JOY_MODE_GPIO)
EricLew 0:3eee9435dd17 488 {
EricLew 0:3eee9435dd17 489 /* Configure Joy pin as input */
EricLew 0:3eee9435dd17 490 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
EricLew 0:3eee9435dd17 491 HAL_GPIO_Init(JOY_PORT[joykey], &GPIO_InitStruct);
EricLew 0:3eee9435dd17 492 }
EricLew 0:3eee9435dd17 493 else if (Joy_Mode == JOY_MODE_EXTI)
EricLew 0:3eee9435dd17 494 {
EricLew 0:3eee9435dd17 495 /* Configure Joy pin as input with External interrupt */
EricLew 0:3eee9435dd17 496 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
EricLew 0:3eee9435dd17 497 HAL_GPIO_Init(JOY_PORT[joykey], &GPIO_InitStruct);
EricLew 0:3eee9435dd17 498
EricLew 0:3eee9435dd17 499 /* Enable and set Joy EXTI Interrupt to the lowest priority */
EricLew 0:3eee9435dd17 500 HAL_NVIC_SetPriority((IRQn_Type)(JOY_IRQn[joykey]), 0x0F, 0x00);
EricLew 0:3eee9435dd17 501 HAL_NVIC_EnableIRQ((IRQn_Type)(JOY_IRQn[joykey]));
EricLew 0:3eee9435dd17 502 }
EricLew 0:3eee9435dd17 503 }
EricLew 0:3eee9435dd17 504
EricLew 0:3eee9435dd17 505 return HAL_OK;
EricLew 0:3eee9435dd17 506 }
EricLew 0:3eee9435dd17 507
EricLew 0:3eee9435dd17 508 /**
EricLew 0:3eee9435dd17 509 * @brief Unonfigures all GPIOs used as buttons of the joystick.
EricLew 0:3eee9435dd17 510 * @retval None.
EricLew 0:3eee9435dd17 511 */
EricLew 0:3eee9435dd17 512 void BSP_JOY_DeInit(void)
EricLew 0:3eee9435dd17 513 {
EricLew 0:3eee9435dd17 514 JOYState_TypeDef joykey;
EricLew 0:3eee9435dd17 515
EricLew 0:3eee9435dd17 516 /* Initialized the Joystick. */
EricLew 0:3eee9435dd17 517 for(joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++)
EricLew 0:3eee9435dd17 518 {
EricLew 0:3eee9435dd17 519 /* Enable the JOY clock */
EricLew 0:3eee9435dd17 520 JOYx_GPIO_CLK_ENABLE(joykey);
EricLew 0:3eee9435dd17 521
EricLew 0:3eee9435dd17 522 HAL_GPIO_DeInit(JOY_PORT[joykey], JOY_PIN[joykey]);
EricLew 0:3eee9435dd17 523 }
EricLew 0:3eee9435dd17 524 }
EricLew 0:3eee9435dd17 525
EricLew 0:3eee9435dd17 526 /**
EricLew 0:3eee9435dd17 527 * @brief Returns the current joystick status.
EricLew 0:3eee9435dd17 528 * @retval Code of the joystick key pressed
EricLew 0:3eee9435dd17 529 * This code can be one of the following values:
EricLew 0:3eee9435dd17 530 * @arg JOY_NONE
EricLew 0:3eee9435dd17 531 * @arg JOY_SEL
EricLew 0:3eee9435dd17 532 * @arg JOY_DOWN
EricLew 0:3eee9435dd17 533 * @arg JOY_LEFT
EricLew 0:3eee9435dd17 534 * @arg JOY_RIGHT
EricLew 0:3eee9435dd17 535 * @arg JOY_UP
EricLew 0:3eee9435dd17 536 */
EricLew 0:3eee9435dd17 537 JOYState_TypeDef BSP_JOY_GetState(void)
EricLew 0:3eee9435dd17 538 {
EricLew 0:3eee9435dd17 539 JOYState_TypeDef joykey;
EricLew 0:3eee9435dd17 540
EricLew 0:3eee9435dd17 541 for (joykey = JOY_SEL; joykey < (JOY_SEL + JOYn) ; joykey++)
EricLew 0:3eee9435dd17 542 {
EricLew 0:3eee9435dd17 543 if (HAL_GPIO_ReadPin(JOY_PORT[joykey], JOY_PIN[joykey]) == GPIO_PIN_SET)
EricLew 0:3eee9435dd17 544 {
EricLew 0:3eee9435dd17 545 /* Return Code Joystick key pressed */
EricLew 0:3eee9435dd17 546 return joykey;
EricLew 0:3eee9435dd17 547 }
EricLew 0:3eee9435dd17 548 }
EricLew 0:3eee9435dd17 549
EricLew 0:3eee9435dd17 550 /* No Joystick key pressed */
EricLew 0:3eee9435dd17 551 return JOY_NONE;
EricLew 0:3eee9435dd17 552 }
EricLew 0:3eee9435dd17 553
EricLew 0:3eee9435dd17 554 /**
EricLew 0:3eee9435dd17 555 * @}
EricLew 0:3eee9435dd17 556 */
EricLew 0:3eee9435dd17 557
EricLew 0:3eee9435dd17 558 /** @defgroup STM32L476G_DISCOVERY_BusOperations_Functions Bus Operations Functions
EricLew 0:3eee9435dd17 559 * @{
EricLew 0:3eee9435dd17 560 */
EricLew 0:3eee9435dd17 561
EricLew 0:3eee9435dd17 562 /*******************************************************************************
EricLew 0:3eee9435dd17 563 BUS OPERATIONS
EricLew 0:3eee9435dd17 564 *******************************************************************************/
EricLew 0:3eee9435dd17 565 #if defined(HAL_SPI_MODULE_ENABLED)
EricLew 0:3eee9435dd17 566 /******************************* SPI Routines**********************************/
EricLew 0:3eee9435dd17 567 /**
EricLew 0:3eee9435dd17 568 * @brief SPIx Bus initialization
EricLew 0:3eee9435dd17 569 * @retval None
EricLew 0:3eee9435dd17 570 */
EricLew 0:3eee9435dd17 571 static void SPIx_Init(void)
EricLew 0:3eee9435dd17 572 {
EricLew 0:3eee9435dd17 573 if(HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
EricLew 0:3eee9435dd17 574 {
EricLew 0:3eee9435dd17 575 /* SPI Config */
EricLew 0:3eee9435dd17 576 SpiHandle.Instance = DISCOVERY_SPIx;
EricLew 0:3eee9435dd17 577 /* SPI baudrate is set to 10 MHz (PCLK1/SPI_BaudRatePrescaler = 80/8 = 10 MHz)
EricLew 0:3eee9435dd17 578 to verify these constraints:
EricLew 0:3eee9435dd17 579 lsm303c SPI interface max baudrate is 10MHz for write/read
EricLew 0:3eee9435dd17 580 PCLK1 max frequency is set to 80 MHz
EricLew 0:3eee9435dd17 581 */
EricLew 0:3eee9435dd17 582 SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
EricLew 0:3eee9435dd17 583 SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
EricLew 0:3eee9435dd17 584 SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
EricLew 0:3eee9435dd17 585 SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
EricLew 0:3eee9435dd17 586 SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
EricLew 0:3eee9435dd17 587 SpiHandle.Init.CRCPolynomial = 7;
EricLew 0:3eee9435dd17 588 SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
EricLew 0:3eee9435dd17 589 SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
EricLew 0:3eee9435dd17 590 SpiHandle.Init.NSS = SPI_NSS_SOFT;
EricLew 0:3eee9435dd17 591 SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
EricLew 0:3eee9435dd17 592 SpiHandle.Init.Mode = SPI_MODE_MASTER;
EricLew 0:3eee9435dd17 593
EricLew 0:3eee9435dd17 594 SPIx_MspInit(&SpiHandle);
EricLew 0:3eee9435dd17 595 HAL_SPI_Init(&SpiHandle);
EricLew 0:3eee9435dd17 596 }
EricLew 0:3eee9435dd17 597 }
EricLew 0:3eee9435dd17 598
EricLew 0:3eee9435dd17 599 /**
EricLew 0:3eee9435dd17 600 * @brief SPI MSP Init
EricLew 0:3eee9435dd17 601 * @param hspi: SPI handle
EricLew 0:3eee9435dd17 602 * @retval None
EricLew 0:3eee9435dd17 603 */
EricLew 0:3eee9435dd17 604 static void SPIx_MspInit(SPI_HandleTypeDef *hspi)
EricLew 0:3eee9435dd17 605 {
EricLew 0:3eee9435dd17 606 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 607
EricLew 0:3eee9435dd17 608 /* Enable SPIx clock */
EricLew 0:3eee9435dd17 609 DISCOVERY_SPIx_CLOCK_ENABLE();
EricLew 0:3eee9435dd17 610
EricLew 0:3eee9435dd17 611 /* enable SPIx gpio clock */
EricLew 0:3eee9435dd17 612 DISCOVERY_SPIx_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 613
EricLew 0:3eee9435dd17 614 /* configure SPIx SCK, MOSI and MISO */
EricLew 0:3eee9435dd17 615 GPIO_InitStructure.Pin = (DISCOVERY_SPIx_SCK_PIN | DISCOVERY_SPIx_MOSI_PIN | DISCOVERY_SPIx_MISO_PIN);
EricLew 0:3eee9435dd17 616 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
EricLew 0:3eee9435dd17 617 GPIO_InitStructure.Pull = GPIO_NOPULL; // GPIO_PULLDOWN;
EricLew 0:3eee9435dd17 618 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
EricLew 0:3eee9435dd17 619 GPIO_InitStructure.Alternate = DISCOVERY_SPIx_AF;
EricLew 0:3eee9435dd17 620 HAL_GPIO_Init(DISCOVERY_SPIx_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 621 }
EricLew 0:3eee9435dd17 622
EricLew 0:3eee9435dd17 623 /**
EricLew 0:3eee9435dd17 624 * @brief SPIx Bus Deinitialization
EricLew 0:3eee9435dd17 625 * @retval None
EricLew 0:3eee9435dd17 626 */
EricLew 0:3eee9435dd17 627 void SPIx_DeInit(void)
EricLew 0:3eee9435dd17 628 {
EricLew 0:3eee9435dd17 629 if(HAL_SPI_GetState(&SpiHandle) != HAL_SPI_STATE_RESET)
EricLew 0:3eee9435dd17 630 {
EricLew 0:3eee9435dd17 631 /* SPI Deinit */
EricLew 0:3eee9435dd17 632 HAL_SPI_DeInit(&SpiHandle);
EricLew 0:3eee9435dd17 633 SPIx_MspDeInit();
EricLew 0:3eee9435dd17 634 }
EricLew 0:3eee9435dd17 635 }
EricLew 0:3eee9435dd17 636
EricLew 0:3eee9435dd17 637 /**
EricLew 0:3eee9435dd17 638 * @brief SPI MSP DeInit
EricLew 0:3eee9435dd17 639 * @retval None
EricLew 0:3eee9435dd17 640 */
EricLew 0:3eee9435dd17 641 static void SPIx_MspDeInit(void)
EricLew 0:3eee9435dd17 642 {
EricLew 0:3eee9435dd17 643 /* enable SPIx gpio clock */
EricLew 0:3eee9435dd17 644 DISCOVERY_SPIx_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 645
EricLew 0:3eee9435dd17 646 /* Unconfigure SPIx SCK, MOSI and MISO */
EricLew 0:3eee9435dd17 647 HAL_GPIO_DeInit(DISCOVERY_SPIx_GPIO_PORT, (DISCOVERY_SPIx_SCK_PIN | DISCOVERY_SPIx_MOSI_PIN | DISCOVERY_SPIx_MISO_PIN));
EricLew 0:3eee9435dd17 648
EricLew 0:3eee9435dd17 649 DISCOVERY_SPIx_GPIO_FORCE_RESET();
EricLew 0:3eee9435dd17 650 DISCOVERY_SPIx_GPIO_RELEASE_RESET();
EricLew 0:3eee9435dd17 651
EricLew 0:3eee9435dd17 652 /* Disable SPIx clock */
EricLew 0:3eee9435dd17 653 DISCOVERY_SPIx_CLOCK_DISABLE();
EricLew 0:3eee9435dd17 654 }
EricLew 0:3eee9435dd17 655
EricLew 0:3eee9435dd17 656 /**
EricLew 0:3eee9435dd17 657 * @brief Sends a Byte through the SPI interface and return the Byte received
EricLew 0:3eee9435dd17 658 * from the SPI bus.
EricLew 0:3eee9435dd17 659 * @param Byte : Byte send.
EricLew 0:3eee9435dd17 660 * @retval none.
EricLew 0:3eee9435dd17 661 */
EricLew 0:3eee9435dd17 662 static uint8_t SPIx_WriteRead(uint8_t Byte)
EricLew 0:3eee9435dd17 663 {
EricLew 0:3eee9435dd17 664 uint8_t receivedbyte;
EricLew 0:3eee9435dd17 665
EricLew 0:3eee9435dd17 666 /* Enable the SPI */
EricLew 0:3eee9435dd17 667 __HAL_SPI_ENABLE(&SpiHandle);
EricLew 0:3eee9435dd17 668 /* check TXE flag */
EricLew 0:3eee9435dd17 669 while((SpiHandle.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE);
EricLew 0:3eee9435dd17 670
EricLew 0:3eee9435dd17 671 /* Write the data */
EricLew 0:3eee9435dd17 672 *((__IO uint8_t*)&SpiHandle.Instance->DR) = Byte;
EricLew 0:3eee9435dd17 673
EricLew 0:3eee9435dd17 674 while((SpiHandle.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE);
EricLew 0:3eee9435dd17 675 receivedbyte = *((__IO uint8_t*)&SpiHandle.Instance->DR);
EricLew 0:3eee9435dd17 676
EricLew 0:3eee9435dd17 677 /* Wait BSY flag */
EricLew 0:3eee9435dd17 678 while((SpiHandle.Instance->SR & SPI_FLAG_FTLVL) != SPI_FTLVL_EMPTY);
EricLew 0:3eee9435dd17 679 while((SpiHandle.Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY);
EricLew 0:3eee9435dd17 680
EricLew 0:3eee9435dd17 681 /* disable the SPI */
EricLew 0:3eee9435dd17 682 __HAL_SPI_DISABLE(&SpiHandle);
EricLew 0:3eee9435dd17 683
EricLew 0:3eee9435dd17 684 return receivedbyte;
EricLew 0:3eee9435dd17 685 }
EricLew 0:3eee9435dd17 686
EricLew 0:3eee9435dd17 687 /**
EricLew 0:3eee9435dd17 688 * @brief Sends a Byte through the SPI interface.
EricLew 0:3eee9435dd17 689 * @param Byte : Byte to send.
EricLew 0:3eee9435dd17 690 * @retval none.
EricLew 0:3eee9435dd17 691 */
EricLew 0:3eee9435dd17 692 static void SPIx_Write(uint8_t Byte)
EricLew 0:3eee9435dd17 693 {
EricLew 0:3eee9435dd17 694 /* Enable the SPI */
EricLew 0:3eee9435dd17 695 __HAL_SPI_ENABLE(&SpiHandle);
EricLew 0:3eee9435dd17 696 /* check TXE flag */
EricLew 0:3eee9435dd17 697 while((SpiHandle.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE);
EricLew 0:3eee9435dd17 698
EricLew 0:3eee9435dd17 699 /* Write the data */
EricLew 0:3eee9435dd17 700 *((__IO uint8_t*)&SpiHandle.Instance->DR) = Byte;
EricLew 0:3eee9435dd17 701
EricLew 0:3eee9435dd17 702 /* Wait BSY flag */
EricLew 0:3eee9435dd17 703 while((SpiHandle.Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY);
EricLew 0:3eee9435dd17 704
EricLew 0:3eee9435dd17 705 /* disable the SPI */
EricLew 0:3eee9435dd17 706 __HAL_SPI_DISABLE(&SpiHandle);
EricLew 0:3eee9435dd17 707 }
EricLew 0:3eee9435dd17 708
EricLew 0:3eee9435dd17 709 #if defined(__ICCARM__)
EricLew 0:3eee9435dd17 710 #pragma optimize=none
EricLew 0:3eee9435dd17 711 #endif
EricLew 0:3eee9435dd17 712 /**
EricLew 0:3eee9435dd17 713 * @brief Receives a Byte from the SPI bus.
EricLew 0:3eee9435dd17 714 * @retval The received byte value
EricLew 0:3eee9435dd17 715 */
EricLew 0:3eee9435dd17 716 static uint8_t SPIx_Read(void)
EricLew 0:3eee9435dd17 717 {
EricLew 0:3eee9435dd17 718 uint8_t receivedbyte;
EricLew 0:3eee9435dd17 719
EricLew 0:3eee9435dd17 720 __HAL_SPI_ENABLE(&SpiHandle);
EricLew 0:3eee9435dd17 721 __DSB();
EricLew 0:3eee9435dd17 722 __DSB();
EricLew 0:3eee9435dd17 723 __DSB();
EricLew 0:3eee9435dd17 724 __DSB();
EricLew 0:3eee9435dd17 725 __DSB();
EricLew 0:3eee9435dd17 726 __DSB();
EricLew 0:3eee9435dd17 727 __DSB();
EricLew 0:3eee9435dd17 728 __DSB();
EricLew 0:3eee9435dd17 729 __HAL_SPI_DISABLE(&SpiHandle);
EricLew 0:3eee9435dd17 730
EricLew 0:3eee9435dd17 731 while((SpiHandle.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE);
EricLew 0:3eee9435dd17 732 /* read the received data */
EricLew 0:3eee9435dd17 733 receivedbyte = *(__IO uint8_t *)&SpiHandle.Instance->DR;
EricLew 0:3eee9435dd17 734
EricLew 0:3eee9435dd17 735 /* Wait for the BSY flag reset */
EricLew 0:3eee9435dd17 736 while((SpiHandle.Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY);
EricLew 0:3eee9435dd17 737
EricLew 0:3eee9435dd17 738
EricLew 0:3eee9435dd17 739 return receivedbyte;
EricLew 0:3eee9435dd17 740 }
EricLew 0:3eee9435dd17 741 #endif /* HAL_SPI_MODULE_ENABLED */
EricLew 0:3eee9435dd17 742
EricLew 0:3eee9435dd17 743
EricLew 0:3eee9435dd17 744 #if defined(HAL_I2C_MODULE_ENABLED)
EricLew 0:3eee9435dd17 745 /******************************* I2C Routines**********************************/
EricLew 0:3eee9435dd17 746 /**
EricLew 0:3eee9435dd17 747 * @brief Discovery I2C1 Bus initialization
EricLew 0:3eee9435dd17 748 * @retval None
EricLew 0:3eee9435dd17 749 */
EricLew 0:3eee9435dd17 750 static void I2C1_Init(void)
EricLew 0:3eee9435dd17 751 {
EricLew 0:3eee9435dd17 752 if(HAL_I2C_GetState(&I2c1Handle) == HAL_I2C_STATE_RESET)
EricLew 0:3eee9435dd17 753 {
EricLew 0:3eee9435dd17 754 I2c1Handle.Instance = DISCOVERY_I2C1;
EricLew 0:3eee9435dd17 755 I2c1Handle.Init.Timing = DISCOVERY_I2C1_TIMING;
EricLew 0:3eee9435dd17 756 I2c1Handle.Init.OwnAddress1 = 0;
EricLew 0:3eee9435dd17 757 I2c1Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
EricLew 0:3eee9435dd17 758 I2c1Handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
EricLew 0:3eee9435dd17 759 I2c1Handle.Init.OwnAddress2 = 0;
EricLew 0:3eee9435dd17 760 I2c1Handle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
EricLew 0:3eee9435dd17 761 I2c1Handle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
EricLew 0:3eee9435dd17 762
EricLew 0:3eee9435dd17 763 /* Init the I2C */
EricLew 0:3eee9435dd17 764 I2C1_MspInit(&I2c1Handle);
EricLew 0:3eee9435dd17 765 HAL_I2C_Init(&I2c1Handle);
EricLew 0:3eee9435dd17 766 }
EricLew 0:3eee9435dd17 767 }
EricLew 0:3eee9435dd17 768
EricLew 0:3eee9435dd17 769 /**
EricLew 0:3eee9435dd17 770 * @brief Discovery I2C1 MSP Initialization
EricLew 0:3eee9435dd17 771 * @param hi2c: I2C handle
EricLew 0:3eee9435dd17 772 * @retval None
EricLew 0:3eee9435dd17 773 */
EricLew 0:3eee9435dd17 774 static void I2C1_MspInit(I2C_HandleTypeDef *hi2c)
EricLew 0:3eee9435dd17 775 {
EricLew 0:3eee9435dd17 776 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 777 RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct;
EricLew 0:3eee9435dd17 778
EricLew 0:3eee9435dd17 779 /* IOSV bit MUST be set to access GPIO port G[2:15] */
EricLew 0:3eee9435dd17 780 __HAL_RCC_PWR_CLK_ENABLE();
EricLew 0:3eee9435dd17 781 HAL_PWREx_EnableVddIO2();
EricLew 0:3eee9435dd17 782
EricLew 0:3eee9435dd17 783 if (hi2c->Instance == DISCOVERY_I2C1)
EricLew 0:3eee9435dd17 784 {
EricLew 0:3eee9435dd17 785 /*##-1- Configure the Discovery I2C clock source. The clock is derived from the SYSCLK #*/
EricLew 0:3eee9435dd17 786 RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
EricLew 0:3eee9435dd17 787 RCC_PeriphCLKInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
EricLew 0:3eee9435dd17 788 HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
EricLew 0:3eee9435dd17 789
EricLew 0:3eee9435dd17 790 /*##-2- Configure the GPIOs ################################################*/
EricLew 0:3eee9435dd17 791 /* Enable GPIO clock */
EricLew 0:3eee9435dd17 792 DISCOVERY_I2C1_SDA_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 793 DISCOVERY_I2C1_SCL_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 794
EricLew 0:3eee9435dd17 795 /* Configure I2C Rx/Tx as alternate function */
EricLew 0:3eee9435dd17 796 GPIO_InitStructure.Pin = DISCOVERY_I2C1_SCL_PIN | DISCOVERY_I2C1_SDA_PIN;
EricLew 0:3eee9435dd17 797 GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
EricLew 0:3eee9435dd17 798 GPIO_InitStructure.Pull = GPIO_PULLUP;
EricLew 0:3eee9435dd17 799 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 800 GPIO_InitStructure.Alternate = DISCOVERY_I2C1_SCL_SDA_AF;
EricLew 0:3eee9435dd17 801 HAL_GPIO_Init(DISCOVERY_I2C1_SCL_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 802
EricLew 0:3eee9435dd17 803 /*##-3- Configure the Discovery I2C1 peripheral #######################################*/
EricLew 0:3eee9435dd17 804 /* Enable Discovery I2C1 clock */
EricLew 0:3eee9435dd17 805 DISCOVERY_I2C1_CLK_ENABLE();
EricLew 0:3eee9435dd17 806
EricLew 0:3eee9435dd17 807 /* Force and release the I2C Peripheral Clock Reset */
EricLew 0:3eee9435dd17 808 DISCOVERY_I2C1_FORCE_RESET();
EricLew 0:3eee9435dd17 809 DISCOVERY_I2C1_RELEASE_RESET();
EricLew 0:3eee9435dd17 810
EricLew 0:3eee9435dd17 811 /* Enable and set Discovery I2C1 Interrupt to the highest priority */
EricLew 0:3eee9435dd17 812 HAL_NVIC_SetPriority(DISCOVERY_I2C1_EV_IRQn, 0x00, 0);
EricLew 0:3eee9435dd17 813 HAL_NVIC_EnableIRQ(DISCOVERY_I2C1_EV_IRQn);
EricLew 0:3eee9435dd17 814
EricLew 0:3eee9435dd17 815 /* Enable and set Discovery I2C1 Interrupt to the highest priority */
EricLew 0:3eee9435dd17 816 HAL_NVIC_SetPriority(DISCOVERY_I2C1_ER_IRQn, 0x00, 0);
EricLew 0:3eee9435dd17 817 HAL_NVIC_EnableIRQ(DISCOVERY_I2C1_ER_IRQn);
EricLew 0:3eee9435dd17 818 }
EricLew 0:3eee9435dd17 819 }
EricLew 0:3eee9435dd17 820
EricLew 0:3eee9435dd17 821 /**
EricLew 0:3eee9435dd17 822 * @brief Discovery I2C1 Bus Deitialization
EricLew 0:3eee9435dd17 823 * @retval None
EricLew 0:3eee9435dd17 824 */
EricLew 0:3eee9435dd17 825 static void I2C1_DeInit(void)
EricLew 0:3eee9435dd17 826 {
EricLew 0:3eee9435dd17 827 if(HAL_I2C_GetState(&I2c1Handle) != HAL_I2C_STATE_RESET)
EricLew 0:3eee9435dd17 828 {
EricLew 0:3eee9435dd17 829 /* Deinit the I2C */
EricLew 0:3eee9435dd17 830 HAL_I2C_DeInit(&I2c1Handle);
EricLew 0:3eee9435dd17 831 I2C1_MspDeInit(&I2c1Handle);
EricLew 0:3eee9435dd17 832 }
EricLew 0:3eee9435dd17 833 }
EricLew 0:3eee9435dd17 834
EricLew 0:3eee9435dd17 835 /**
EricLew 0:3eee9435dd17 836 * @brief Discovery I2C1 MSP Deinitialization
EricLew 0:3eee9435dd17 837 * @param hi2c: I2C handle
EricLew 0:3eee9435dd17 838 * @retval None
EricLew 0:3eee9435dd17 839 */
EricLew 0:3eee9435dd17 840 static void I2C1_MspDeInit(I2C_HandleTypeDef *hi2c)
EricLew 0:3eee9435dd17 841 {
EricLew 0:3eee9435dd17 842 if(hi2c->Instance == DISCOVERY_I2C1)
EricLew 0:3eee9435dd17 843 {
EricLew 0:3eee9435dd17 844 /*##-1- Unconfigure the GPIOs ################################################*/
EricLew 0:3eee9435dd17 845 /* Enable GPIO clock */
EricLew 0:3eee9435dd17 846 DISCOVERY_I2C1_SDA_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 847 DISCOVERY_I2C1_SCL_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 848
EricLew 0:3eee9435dd17 849 /* Deinit Rx/Tx pins */
EricLew 0:3eee9435dd17 850 HAL_GPIO_DeInit(DISCOVERY_I2C1_SCL_GPIO_PORT, (DISCOVERY_I2C1_SCL_PIN | DISCOVERY_I2C1_SDA_PIN));
EricLew 0:3eee9435dd17 851
EricLew 0:3eee9435dd17 852 /*##-2- Unconfigure the Discovery I2C1 peripheral ############################*/
EricLew 0:3eee9435dd17 853 /* Force & Release the I2C Peripheral Clock Reset */
EricLew 0:3eee9435dd17 854 DISCOVERY_I2C1_FORCE_RESET();
EricLew 0:3eee9435dd17 855 DISCOVERY_I2C1_RELEASE_RESET();
EricLew 0:3eee9435dd17 856
EricLew 0:3eee9435dd17 857 /* Disable Discovery I2C1 clock */
EricLew 0:3eee9435dd17 858 DISCOVERY_I2C1_CLK_DISABLE();
EricLew 0:3eee9435dd17 859
EricLew 0:3eee9435dd17 860 /* Disable Discovery I2C1 interrupts */
EricLew 0:3eee9435dd17 861 HAL_NVIC_DisableIRQ(DISCOVERY_I2C1_EV_IRQn);
EricLew 0:3eee9435dd17 862 HAL_NVIC_DisableIRQ(DISCOVERY_I2C1_ER_IRQn);
EricLew 0:3eee9435dd17 863
EricLew 0:3eee9435dd17 864 __HAL_RCC_PWR_CLK_ENABLE();
EricLew 0:3eee9435dd17 865 HAL_PWREx_DisableVddIO2();
EricLew 0:3eee9435dd17 866 }
EricLew 0:3eee9435dd17 867 }
EricLew 0:3eee9435dd17 868
EricLew 0:3eee9435dd17 869 /**
EricLew 0:3eee9435dd17 870 * @brief Write a value in a register of the device through BUS.
EricLew 0:3eee9435dd17 871 * @param Addr: Device address on BUS Bus.
EricLew 0:3eee9435dd17 872 * @param Reg: The target register address to write
EricLew 0:3eee9435dd17 873 * @param RegSize: The target register size (can be 8BIT or 16BIT)
EricLew 0:3eee9435dd17 874 * @param pBuffer: The target register value to be written
EricLew 0:3eee9435dd17 875 * @param Length: buffer size to be written
EricLew 0:3eee9435dd17 876 * @retval None
EricLew 0:3eee9435dd17 877 */
EricLew 0:3eee9435dd17 878 static HAL_StatusTypeDef I2C1_WriteBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length)
EricLew 0:3eee9435dd17 879 {
EricLew 0:3eee9435dd17 880 HAL_StatusTypeDef status = HAL_OK;
EricLew 0:3eee9435dd17 881
EricLew 0:3eee9435dd17 882 status = HAL_I2C_Mem_Write(&I2c1Handle, Addr, (uint16_t)Reg, RegSize, pBuffer, Length, I2c1Timeout);
EricLew 0:3eee9435dd17 883
EricLew 0:3eee9435dd17 884 /* Check the communication status */
EricLew 0:3eee9435dd17 885 if(status != HAL_OK)
EricLew 0:3eee9435dd17 886 {
EricLew 0:3eee9435dd17 887 /* Re-Initiaize the BUS */
EricLew 0:3eee9435dd17 888 I2C1_Error();
EricLew 0:3eee9435dd17 889 }
EricLew 0:3eee9435dd17 890 return status;
EricLew 0:3eee9435dd17 891 }
EricLew 0:3eee9435dd17 892
EricLew 0:3eee9435dd17 893 /**
EricLew 0:3eee9435dd17 894 * @brief Reads multiple data on the BUS.
EricLew 0:3eee9435dd17 895 * @param Addr: I2C Address
EricLew 0:3eee9435dd17 896 * @param Reg: Reg Address
EricLew 0:3eee9435dd17 897 * @param RegSize : The target register size (can be 8BIT or 16BIT)
EricLew 0:3eee9435dd17 898 * @param pBuffer: pointer to read data buffer
EricLew 0:3eee9435dd17 899 * @param Length: length of the data
EricLew 0:3eee9435dd17 900 * @retval 0 if no problems to read multiple data
EricLew 0:3eee9435dd17 901 */
EricLew 0:3eee9435dd17 902 static HAL_StatusTypeDef I2C1_ReadBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length)
EricLew 0:3eee9435dd17 903 {
EricLew 0:3eee9435dd17 904 HAL_StatusTypeDef status = HAL_OK;
EricLew 0:3eee9435dd17 905
EricLew 0:3eee9435dd17 906 status = HAL_I2C_Mem_Read(&I2c1Handle, Addr, (uint16_t)Reg, RegSize, pBuffer, Length, I2c1Timeout);
EricLew 0:3eee9435dd17 907
EricLew 0:3eee9435dd17 908 /* Check the communication status */
EricLew 0:3eee9435dd17 909 if(status != HAL_OK)
EricLew 0:3eee9435dd17 910 {
EricLew 0:3eee9435dd17 911 /* Re-Initiaize the BUS */
EricLew 0:3eee9435dd17 912 I2C1_Error();
EricLew 0:3eee9435dd17 913 }
EricLew 0:3eee9435dd17 914 return status;
EricLew 0:3eee9435dd17 915 }
EricLew 0:3eee9435dd17 916
EricLew 0:3eee9435dd17 917 /**
EricLew 0:3eee9435dd17 918 * @brief Discovery I2C1 error treatment function
EricLew 0:3eee9435dd17 919 * @retval None
EricLew 0:3eee9435dd17 920 */
EricLew 0:3eee9435dd17 921 static void I2C1_Error (void)
EricLew 0:3eee9435dd17 922 {
EricLew 0:3eee9435dd17 923 /* De-initialize the I2C communication BUS */
EricLew 0:3eee9435dd17 924 HAL_I2C_DeInit(&I2c1Handle);
EricLew 0:3eee9435dd17 925
EricLew 0:3eee9435dd17 926 /* Re- Initiaize the I2C communication BUS */
EricLew 0:3eee9435dd17 927 I2C1_Init();
EricLew 0:3eee9435dd17 928 }
EricLew 0:3eee9435dd17 929
EricLew 0:3eee9435dd17 930 /**
EricLew 0:3eee9435dd17 931 * @brief Discovery I2C2 Bus initialization
EricLew 0:3eee9435dd17 932 * @retval None
EricLew 0:3eee9435dd17 933 */
EricLew 0:3eee9435dd17 934 static void I2C2_Init(void)
EricLew 0:3eee9435dd17 935 {
EricLew 0:3eee9435dd17 936 if(HAL_I2C_GetState(&I2c2Handle) == HAL_I2C_STATE_RESET)
EricLew 0:3eee9435dd17 937 {
EricLew 0:3eee9435dd17 938 I2c2Handle.Instance = DISCOVERY_I2C2;
EricLew 0:3eee9435dd17 939 I2c2Handle.Init.Timing = DISCOVERY_I2C2_TIMING;
EricLew 0:3eee9435dd17 940 I2c2Handle.Init.OwnAddress1 = 0;
EricLew 0:3eee9435dd17 941 I2c2Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
EricLew 0:3eee9435dd17 942 I2c2Handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
EricLew 0:3eee9435dd17 943 I2c2Handle.Init.OwnAddress2 = 0;
EricLew 0:3eee9435dd17 944 I2c2Handle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
EricLew 0:3eee9435dd17 945 I2c2Handle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
EricLew 0:3eee9435dd17 946
EricLew 0:3eee9435dd17 947 /* Init the I2C */
EricLew 0:3eee9435dd17 948 I2C2_MspInit(&I2c2Handle);
EricLew 0:3eee9435dd17 949 HAL_I2C_Init(&I2c2Handle);
EricLew 0:3eee9435dd17 950 }
EricLew 0:3eee9435dd17 951 }
EricLew 0:3eee9435dd17 952
EricLew 0:3eee9435dd17 953 /**
EricLew 0:3eee9435dd17 954 * @brief Discovery I2C2 MSP Initialization
EricLew 0:3eee9435dd17 955 * @param hi2c: I2C2 handle
EricLew 0:3eee9435dd17 956 * @retval None
EricLew 0:3eee9435dd17 957 */
EricLew 0:3eee9435dd17 958 static void I2C2_MspInit(I2C_HandleTypeDef *hi2c)
EricLew 0:3eee9435dd17 959 {
EricLew 0:3eee9435dd17 960 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 961 RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct;
EricLew 0:3eee9435dd17 962
EricLew 0:3eee9435dd17 963 if (hi2c->Instance == DISCOVERY_I2C2)
EricLew 0:3eee9435dd17 964 {
EricLew 0:3eee9435dd17 965 /*##-1- Configure the Discovery I2C2 clock source. The clock is derived from the SYSCLK #*/
EricLew 0:3eee9435dd17 966 RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C2;
EricLew 0:3eee9435dd17 967 RCC_PeriphCLKInitStruct.I2c2ClockSelection = RCC_I2C2CLKSOURCE_SYSCLK;
EricLew 0:3eee9435dd17 968 HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
EricLew 0:3eee9435dd17 969
EricLew 0:3eee9435dd17 970 /*##-2- Configure the GPIOs ################################################*/
EricLew 0:3eee9435dd17 971 /* Enable GPIO clock */
EricLew 0:3eee9435dd17 972 DISCOVERY_I2C2_SDA_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 973 DISCOVERY_I2C2_SCL_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 974
EricLew 0:3eee9435dd17 975 /* Configure I2C Rx/Tx as alternate function */
EricLew 0:3eee9435dd17 976 GPIO_InitStructure.Pin = DISCOVERY_I2C2_SCL_PIN | DISCOVERY_I2C2_SDA_PIN;
EricLew 0:3eee9435dd17 977 GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
EricLew 0:3eee9435dd17 978 GPIO_InitStructure.Pull = GPIO_PULLUP;
EricLew 0:3eee9435dd17 979 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 980 GPIO_InitStructure.Alternate = DISCOVERY_I2C2_SCL_SDA_AF;
EricLew 0:3eee9435dd17 981 HAL_GPIO_Init(DISCOVERY_I2C2_SCL_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 982
EricLew 0:3eee9435dd17 983 /*##-3- Configure the Discovery I2C2 peripheral #############################*/
EricLew 0:3eee9435dd17 984 /* Enable Discovery_I2C2 clock */
EricLew 0:3eee9435dd17 985 DISCOVERY_I2C2_CLK_ENABLE();
EricLew 0:3eee9435dd17 986
EricLew 0:3eee9435dd17 987 /* Force and release the I2C Peripheral Clock Reset */
EricLew 0:3eee9435dd17 988 DISCOVERY_I2C2_FORCE_RESET();
EricLew 0:3eee9435dd17 989 DISCOVERY_I2C2_RELEASE_RESET();
EricLew 0:3eee9435dd17 990
EricLew 0:3eee9435dd17 991 /* Enable and set Discovery I2C2 Interrupt to the highest priority */
EricLew 0:3eee9435dd17 992 HAL_NVIC_SetPriority(DISCOVERY_I2C2_EV_IRQn, 0x00, 0);
EricLew 0:3eee9435dd17 993 HAL_NVIC_EnableIRQ(DISCOVERY_I2C2_EV_IRQn);
EricLew 0:3eee9435dd17 994
EricLew 0:3eee9435dd17 995 /* Enable and set Discovery I2C2 Interrupt to the highest priority */
EricLew 0:3eee9435dd17 996 HAL_NVIC_SetPriority(DISCOVERY_I2C2_ER_IRQn, 0x00, 0);
EricLew 0:3eee9435dd17 997 HAL_NVIC_EnableIRQ(DISCOVERY_I2C2_ER_IRQn);
EricLew 0:3eee9435dd17 998 }
EricLew 0:3eee9435dd17 999 }
EricLew 0:3eee9435dd17 1000
EricLew 0:3eee9435dd17 1001 /**
EricLew 0:3eee9435dd17 1002 * @brief Discovery I2C2 Bus Deinitialization
EricLew 0:3eee9435dd17 1003 * @retval None
EricLew 0:3eee9435dd17 1004 */
EricLew 0:3eee9435dd17 1005 static void I2C2_DeInit(void)
EricLew 0:3eee9435dd17 1006 {
EricLew 0:3eee9435dd17 1007 if(HAL_I2C_GetState(&I2c2Handle) != HAL_I2C_STATE_RESET)
EricLew 0:3eee9435dd17 1008 {
EricLew 0:3eee9435dd17 1009 /* DeInit the I2C */
EricLew 0:3eee9435dd17 1010 HAL_I2C_DeInit(&I2c2Handle);
EricLew 0:3eee9435dd17 1011 I2C2_MspDeInit(&I2c2Handle);
EricLew 0:3eee9435dd17 1012 }
EricLew 0:3eee9435dd17 1013 }
EricLew 0:3eee9435dd17 1014
EricLew 0:3eee9435dd17 1015 /**
EricLew 0:3eee9435dd17 1016 * @brief Discovery I2C2 MSP DeInitialization
EricLew 0:3eee9435dd17 1017 * @param hi2c: I2C2 handle
EricLew 0:3eee9435dd17 1018 * @retval None
EricLew 0:3eee9435dd17 1019 */
EricLew 0:3eee9435dd17 1020 static void I2C2_MspDeInit(I2C_HandleTypeDef *hi2c)
EricLew 0:3eee9435dd17 1021 {
EricLew 0:3eee9435dd17 1022 if (hi2c->Instance == DISCOVERY_I2C2)
EricLew 0:3eee9435dd17 1023 {
EricLew 0:3eee9435dd17 1024 /*##-1- Unconfigure the GPIOs ################################################*/
EricLew 0:3eee9435dd17 1025 /* Enable GPIO clock */
EricLew 0:3eee9435dd17 1026 DISCOVERY_I2C2_SDA_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1027 DISCOVERY_I2C2_SCL_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1028
EricLew 0:3eee9435dd17 1029 /* Configure I2C Rx/Tx as alternate function */
EricLew 0:3eee9435dd17 1030 HAL_GPIO_DeInit(DISCOVERY_I2C2_SCL_GPIO_PORT, (DISCOVERY_I2C2_SCL_PIN | DISCOVERY_I2C2_SDA_PIN));
EricLew 0:3eee9435dd17 1031
EricLew 0:3eee9435dd17 1032 /*##-2- Unconfigure the Discovery I2C2 peripheral ############################*/
EricLew 0:3eee9435dd17 1033 /* Force and release I2C Peripheral */
EricLew 0:3eee9435dd17 1034 DISCOVERY_I2C2_FORCE_RESET();
EricLew 0:3eee9435dd17 1035 DISCOVERY_I2C2_RELEASE_RESET();
EricLew 0:3eee9435dd17 1036
EricLew 0:3eee9435dd17 1037 /* Disable Discovery I2C2 clock */
EricLew 0:3eee9435dd17 1038 DISCOVERY_I2C2_CLK_DISABLE();
EricLew 0:3eee9435dd17 1039
EricLew 0:3eee9435dd17 1040 /* Disable Discovery I2C2 interrupts */
EricLew 0:3eee9435dd17 1041 HAL_NVIC_DisableIRQ(DISCOVERY_I2C2_EV_IRQn);
EricLew 0:3eee9435dd17 1042 HAL_NVIC_DisableIRQ(DISCOVERY_I2C2_ER_IRQn);
EricLew 0:3eee9435dd17 1043 }
EricLew 0:3eee9435dd17 1044 }
EricLew 0:3eee9435dd17 1045
EricLew 0:3eee9435dd17 1046 /**
EricLew 0:3eee9435dd17 1047 * @brief Write a value in a register of the device through BUS.
EricLew 0:3eee9435dd17 1048 * @param Addr: Device address on BUS Bus.
EricLew 0:3eee9435dd17 1049 * @param Reg: The target register address to write
EricLew 0:3eee9435dd17 1050 * @param RegSize: The target register size (can be 8BIT or 16BIT)
EricLew 0:3eee9435dd17 1051 * @param Value: The target register value to be written
EricLew 0:3eee9435dd17 1052 * @retval None
EricLew 0:3eee9435dd17 1053 */
EricLew 0:3eee9435dd17 1054 static void I2C2_WriteData(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t Value)
EricLew 0:3eee9435dd17 1055 {
EricLew 0:3eee9435dd17 1056 HAL_StatusTypeDef status = HAL_OK;
EricLew 0:3eee9435dd17 1057
EricLew 0:3eee9435dd17 1058 status = HAL_I2C_Mem_Write(&I2c2Handle, Addr, (uint16_t)Reg, RegSize, &Value, 1, I2c2Timeout);
EricLew 0:3eee9435dd17 1059
EricLew 0:3eee9435dd17 1060 /* Check the communication status */
EricLew 0:3eee9435dd17 1061 if(status != HAL_OK)
EricLew 0:3eee9435dd17 1062 {
EricLew 0:3eee9435dd17 1063 /* Re-Initiaize the BUS */
EricLew 0:3eee9435dd17 1064 I2C2_Error();
EricLew 0:3eee9435dd17 1065 }
EricLew 0:3eee9435dd17 1066 }
EricLew 0:3eee9435dd17 1067
EricLew 0:3eee9435dd17 1068 /**
EricLew 0:3eee9435dd17 1069 * @brief Write a value in a register of the device through BUS.
EricLew 0:3eee9435dd17 1070 * @param Addr: Device address on BUS Bus.
EricLew 0:3eee9435dd17 1071 * @param Reg: The target register address to write
EricLew 0:3eee9435dd17 1072 * @param RegSize: The target register size (can be 8BIT or 16BIT)
EricLew 0:3eee9435dd17 1073 * @param pBuffer: The target register value to be written
EricLew 0:3eee9435dd17 1074 * @param Length: buffer size to be written
EricLew 0:3eee9435dd17 1075 * @retval None
EricLew 0:3eee9435dd17 1076 */
EricLew 0:3eee9435dd17 1077 static HAL_StatusTypeDef I2C2_WriteBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length)
EricLew 0:3eee9435dd17 1078 {
EricLew 0:3eee9435dd17 1079 HAL_StatusTypeDef status = HAL_OK;
EricLew 0:3eee9435dd17 1080
EricLew 0:3eee9435dd17 1081 status = HAL_I2C_Mem_Write(&I2c2Handle, Addr, (uint16_t)Reg, RegSize, pBuffer, Length, I2c2Timeout);
EricLew 0:3eee9435dd17 1082
EricLew 0:3eee9435dd17 1083 /* Check the communication status */
EricLew 0:3eee9435dd17 1084 if(status != HAL_OK)
EricLew 0:3eee9435dd17 1085 {
EricLew 0:3eee9435dd17 1086 /* Re-Initiaize the BUS */
EricLew 0:3eee9435dd17 1087 I2C2_Error();
EricLew 0:3eee9435dd17 1088 }
EricLew 0:3eee9435dd17 1089
EricLew 0:3eee9435dd17 1090 return status;
EricLew 0:3eee9435dd17 1091 }
EricLew 0:3eee9435dd17 1092
EricLew 0:3eee9435dd17 1093 /**
EricLew 0:3eee9435dd17 1094 * @brief Read a register of the device through BUS
EricLew 0:3eee9435dd17 1095 * @param Addr: Device address on BUS
EricLew 0:3eee9435dd17 1096 * @param Reg: The target register address to read
EricLew 0:3eee9435dd17 1097 * @param RegSize: The target register size (can be 8BIT or 16BIT)
EricLew 0:3eee9435dd17 1098 * @retval read register value
EricLew 0:3eee9435dd17 1099 */
EricLew 0:3eee9435dd17 1100 static uint8_t I2C2_ReadData(uint16_t Addr, uint16_t Reg, uint16_t RegSize)
EricLew 0:3eee9435dd17 1101 {
EricLew 0:3eee9435dd17 1102 HAL_StatusTypeDef status = HAL_OK;
EricLew 0:3eee9435dd17 1103 uint8_t value = 0x0;
EricLew 0:3eee9435dd17 1104
EricLew 0:3eee9435dd17 1105 status = HAL_I2C_Mem_Read(&I2c2Handle, Addr, Reg, RegSize, &value, 1, I2c2Timeout);
EricLew 0:3eee9435dd17 1106
EricLew 0:3eee9435dd17 1107 /* Check the communication status */
EricLew 0:3eee9435dd17 1108 if(status != HAL_OK)
EricLew 0:3eee9435dd17 1109 {
EricLew 0:3eee9435dd17 1110 /* Re-Initiaize the BUS */
EricLew 0:3eee9435dd17 1111 I2C2_Error();
EricLew 0:3eee9435dd17 1112 }
EricLew 0:3eee9435dd17 1113
EricLew 0:3eee9435dd17 1114 return value;
EricLew 0:3eee9435dd17 1115 }
EricLew 0:3eee9435dd17 1116
EricLew 0:3eee9435dd17 1117 /**
EricLew 0:3eee9435dd17 1118 * @brief Reads multiple data on the BUS.
EricLew 0:3eee9435dd17 1119 * @param Addr: I2C Address
EricLew 0:3eee9435dd17 1120 * @param Reg: Reg Address
EricLew 0:3eee9435dd17 1121 * @param RegSize : The target register size (can be 8BIT or 16BIT)
EricLew 0:3eee9435dd17 1122 * @param pBuffer: pointer to read data buffer
EricLew 0:3eee9435dd17 1123 * @param Length: length of the data
EricLew 0:3eee9435dd17 1124 * @retval 0 if no problems to read multiple data
EricLew 0:3eee9435dd17 1125 */
EricLew 0:3eee9435dd17 1126 static HAL_StatusTypeDef I2C2_ReadBuffer(uint16_t Addr, uint16_t Reg, uint16_t RegSize, uint8_t *pBuffer, uint16_t Length)
EricLew 0:3eee9435dd17 1127 {
EricLew 0:3eee9435dd17 1128 HAL_StatusTypeDef status = HAL_OK;
EricLew 0:3eee9435dd17 1129
EricLew 0:3eee9435dd17 1130 status = HAL_I2C_Mem_Read(&I2c2Handle, Addr, (uint16_t)Reg, RegSize, pBuffer, Length, I2c2Timeout);
EricLew 0:3eee9435dd17 1131
EricLew 0:3eee9435dd17 1132 /* Check the communication status */
EricLew 0:3eee9435dd17 1133 if(status != HAL_OK)
EricLew 0:3eee9435dd17 1134 {
EricLew 0:3eee9435dd17 1135 /* Re-Initiaize the BUS */
EricLew 0:3eee9435dd17 1136 I2C2_Error();
EricLew 0:3eee9435dd17 1137 }
EricLew 0:3eee9435dd17 1138
EricLew 0:3eee9435dd17 1139 return status;
EricLew 0:3eee9435dd17 1140 }
EricLew 0:3eee9435dd17 1141
EricLew 0:3eee9435dd17 1142 /**
EricLew 0:3eee9435dd17 1143 * @brief Discovery I2C2 error treatment function
EricLew 0:3eee9435dd17 1144 * @retval None
EricLew 0:3eee9435dd17 1145 */
EricLew 0:3eee9435dd17 1146 static void I2C2_Error (void)
EricLew 0:3eee9435dd17 1147 {
EricLew 0:3eee9435dd17 1148 /* De-initialize the I2C communication BUS */
EricLew 0:3eee9435dd17 1149 HAL_I2C_DeInit(&I2c2Handle);
EricLew 0:3eee9435dd17 1150
EricLew 0:3eee9435dd17 1151 /* Re- Initiaize the I2C communication BUS */
EricLew 0:3eee9435dd17 1152 I2C2_Init();
EricLew 0:3eee9435dd17 1153 }
EricLew 0:3eee9435dd17 1154 #endif /*HAL_I2C_MODULE_ENABLED*/
EricLew 0:3eee9435dd17 1155
EricLew 0:3eee9435dd17 1156
EricLew 0:3eee9435dd17 1157 /*******************************************************************************
EricLew 0:3eee9435dd17 1158 LINK OPERATIONS
EricLew 0:3eee9435dd17 1159 *******************************************************************************/
EricLew 0:3eee9435dd17 1160 #if defined(HAL_SPI_MODULE_ENABLED)
EricLew 0:3eee9435dd17 1161 /*********************** LINK ACCELEROMETER ***********************************/
EricLew 0:3eee9435dd17 1162 /**
EricLew 0:3eee9435dd17 1163 * @brief Configures COMPASS/ACCELEROMETER io interface.
EricLew 0:3eee9435dd17 1164 * @retval None
EricLew 0:3eee9435dd17 1165 */
EricLew 0:3eee9435dd17 1166 void ACCELERO_IO_Init(void)
EricLew 0:3eee9435dd17 1167 {
EricLew 0:3eee9435dd17 1168 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 1169
EricLew 0:3eee9435dd17 1170 /* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */
EricLew 0:3eee9435dd17 1171 ACCELERO_CS_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1172 GPIO_InitStructure.Pin = ACCELERO_CS_PIN;
EricLew 0:3eee9435dd17 1173 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1174 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1175 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1176 HAL_GPIO_Init(ACCELERO_CS_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1177
EricLew 0:3eee9435dd17 1178 /* Deselect : Chip Select high */
EricLew 0:3eee9435dd17 1179 ACCELERO_CS_HIGH();
EricLew 0:3eee9435dd17 1180
EricLew 0:3eee9435dd17 1181 SPIx_Init();
EricLew 0:3eee9435dd17 1182 }
EricLew 0:3eee9435dd17 1183
EricLew 0:3eee9435dd17 1184 /**
EricLew 0:3eee9435dd17 1185 * @brief De-Configures COMPASS/ACCELEROMETER io interface.
EricLew 0:3eee9435dd17 1186 * @retval None
EricLew 0:3eee9435dd17 1187 */
EricLew 0:3eee9435dd17 1188 void ACCELERO_IO_DeInit(void)
EricLew 0:3eee9435dd17 1189 {
EricLew 0:3eee9435dd17 1190 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 1191
EricLew 0:3eee9435dd17 1192 /* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */
EricLew 0:3eee9435dd17 1193 ACCELERO_CS_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1194 GPIO_InitStructure.Pin = ACCELERO_CS_PIN;
EricLew 0:3eee9435dd17 1195 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1196 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1197 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1198 HAL_GPIO_Init(ACCELERO_CS_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1199
EricLew 0:3eee9435dd17 1200 /* Deselect : Chip Select high */
EricLew 0:3eee9435dd17 1201 ACCELERO_CS_HIGH();
EricLew 0:3eee9435dd17 1202
EricLew 0:3eee9435dd17 1203 /* Uninitialize SPI bus */
EricLew 0:3eee9435dd17 1204 SPIx_DeInit();
EricLew 0:3eee9435dd17 1205 }
EricLew 0:3eee9435dd17 1206
EricLew 0:3eee9435dd17 1207 /**
EricLew 0:3eee9435dd17 1208 * @brief Configures COMPASS / ACCELERO click IT
EricLew 0:3eee9435dd17 1209 * @retval None
EricLew 0:3eee9435dd17 1210 */
EricLew 0:3eee9435dd17 1211 void ACCELERO_IO_ITConfig(void)
EricLew 0:3eee9435dd17 1212 {
EricLew 0:3eee9435dd17 1213 }
EricLew 0:3eee9435dd17 1214
EricLew 0:3eee9435dd17 1215 /**
EricLew 0:3eee9435dd17 1216 * @brief Writes one byte to the COMPASS / ACCELEROMETER.
EricLew 0:3eee9435dd17 1217 * @param RegisterAddr specifies the COMPASS / ACCELEROMETER register to be written.
EricLew 0:3eee9435dd17 1218 * @param Value : Data to be written
EricLew 0:3eee9435dd17 1219 * @retval None
EricLew 0:3eee9435dd17 1220 */
EricLew 0:3eee9435dd17 1221 void ACCELERO_IO_Write(uint8_t RegisterAddr, uint8_t Value)
EricLew 0:3eee9435dd17 1222 {
EricLew 0:3eee9435dd17 1223 ACCELERO_CS_LOW();
EricLew 0:3eee9435dd17 1224 __SPI_DIRECTION_1LINE_TX(&SpiHandle);
EricLew 0:3eee9435dd17 1225 /* call SPI Read data bus function */
EricLew 0:3eee9435dd17 1226 SPIx_Write(RegisterAddr);
EricLew 0:3eee9435dd17 1227 SPIx_Write(Value);
EricLew 0:3eee9435dd17 1228 ACCELERO_CS_HIGH();
EricLew 0:3eee9435dd17 1229 }
EricLew 0:3eee9435dd17 1230
EricLew 0:3eee9435dd17 1231 /**
EricLew 0:3eee9435dd17 1232 * @brief Reads a block of data from the COMPASS / ACCELEROMETER.
EricLew 0:3eee9435dd17 1233 * @param RegisterAddr : specifies the COMPASS / ACCELEROMETER internal address register to read from
EricLew 0:3eee9435dd17 1234 * @retval ACCELEROMETER register value
EricLew 0:3eee9435dd17 1235 */
EricLew 0:3eee9435dd17 1236 uint8_t ACCELERO_IO_Read(uint8_t RegisterAddr)
EricLew 0:3eee9435dd17 1237 {
EricLew 0:3eee9435dd17 1238 RegisterAddr = RegisterAddr | ((uint8_t)0x80);
EricLew 0:3eee9435dd17 1239 ACCELERO_CS_LOW();
EricLew 0:3eee9435dd17 1240 __SPI_DIRECTION_1LINE_TX(&SpiHandle);
EricLew 0:3eee9435dd17 1241 SPIx_Write(RegisterAddr);
EricLew 0:3eee9435dd17 1242 __SPI_DIRECTION_1LINE_RX(&SpiHandle);
EricLew 0:3eee9435dd17 1243 uint8_t val = SPIx_Read();
EricLew 0:3eee9435dd17 1244 ACCELERO_CS_HIGH();
EricLew 0:3eee9435dd17 1245 return val;
EricLew 0:3eee9435dd17 1246 }
EricLew 0:3eee9435dd17 1247
EricLew 0:3eee9435dd17 1248 /********************************* LINK MAGNETO *******************************/
EricLew 0:3eee9435dd17 1249 /**
EricLew 0:3eee9435dd17 1250 * @brief Configures COMPASS/MAGNETO SPI interface.
EricLew 0:3eee9435dd17 1251 * @retval None
EricLew 0:3eee9435dd17 1252 */
EricLew 0:3eee9435dd17 1253 void MAGNETO_IO_Init(void)
EricLew 0:3eee9435dd17 1254 {
EricLew 0:3eee9435dd17 1255 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 1256
EricLew 0:3eee9435dd17 1257 /* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */
EricLew 0:3eee9435dd17 1258 MAGNETO_CS_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1259 GPIO_InitStructure.Pin = MAGNETO_CS_PIN;
EricLew 0:3eee9435dd17 1260 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1261 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1262 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1263 HAL_GPIO_Init(MAGNETO_CS_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1264
EricLew 0:3eee9435dd17 1265 /* Deselect : Chip Select high */
EricLew 0:3eee9435dd17 1266 MAGNETO_CS_HIGH();
EricLew 0:3eee9435dd17 1267
EricLew 0:3eee9435dd17 1268 SPIx_Init();
EricLew 0:3eee9435dd17 1269 }
EricLew 0:3eee9435dd17 1270
EricLew 0:3eee9435dd17 1271 /**
EricLew 0:3eee9435dd17 1272 * @brief de-Configures COMPASS/MAGNETO SPI interface.
EricLew 0:3eee9435dd17 1273 * @retval None
EricLew 0:3eee9435dd17 1274 */
EricLew 0:3eee9435dd17 1275 void MAGNETO_IO_DeInit(void)
EricLew 0:3eee9435dd17 1276 {
EricLew 0:3eee9435dd17 1277 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 1278
EricLew 0:3eee9435dd17 1279 /* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */
EricLew 0:3eee9435dd17 1280 MAGNETO_CS_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1281 GPIO_InitStructure.Pin = MAGNETO_CS_PIN;
EricLew 0:3eee9435dd17 1282 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1283 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1284 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1285 HAL_GPIO_Init(MAGNETO_CS_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1286
EricLew 0:3eee9435dd17 1287 /* Deselect : Chip Select high */
EricLew 0:3eee9435dd17 1288 MAGNETO_CS_HIGH();
EricLew 0:3eee9435dd17 1289
EricLew 0:3eee9435dd17 1290 HAL_GPIO_DeInit(MAGNETO_CS_GPIO_PORT, MAGNETO_INT1_PIN|MAGNETO_DRDY_PIN);
EricLew 0:3eee9435dd17 1291
EricLew 0:3eee9435dd17 1292
EricLew 0:3eee9435dd17 1293 /* Uninitialize SPI bus */
EricLew 0:3eee9435dd17 1294 SPIx_DeInit();
EricLew 0:3eee9435dd17 1295 }
EricLew 0:3eee9435dd17 1296
EricLew 0:3eee9435dd17 1297 /**
EricLew 0:3eee9435dd17 1298 * @brief Writes one byte to the COMPASS/MAGNETO.
EricLew 0:3eee9435dd17 1299 * @param RegisterAddr specifies the COMPASS/MAGNETO register to be written.
EricLew 0:3eee9435dd17 1300 * @param Value : Data to be written
EricLew 0:3eee9435dd17 1301 * @retval None
EricLew 0:3eee9435dd17 1302 */
EricLew 0:3eee9435dd17 1303 void MAGNETO_IO_Write(uint8_t RegisterAddr, uint8_t Value)
EricLew 0:3eee9435dd17 1304 {
EricLew 0:3eee9435dd17 1305 MAGNETO_CS_LOW();
EricLew 0:3eee9435dd17 1306 __SPI_DIRECTION_1LINE_TX(&SpiHandle);
EricLew 0:3eee9435dd17 1307 /* call SPI Read data bus function */
EricLew 0:3eee9435dd17 1308 SPIx_Write(RegisterAddr);
EricLew 0:3eee9435dd17 1309 SPIx_Write(Value);
EricLew 0:3eee9435dd17 1310 MAGNETO_CS_HIGH();
EricLew 0:3eee9435dd17 1311 }
EricLew 0:3eee9435dd17 1312
EricLew 0:3eee9435dd17 1313 /**
EricLew 0:3eee9435dd17 1314 * @brief Reads a block of data from the COMPASS/MAGNETO.
EricLew 0:3eee9435dd17 1315 * @param RegisterAddr : specifies the COMPASS/MAGNETO internal address register to read from
EricLew 0:3eee9435dd17 1316 * @retval ACCELEROMETER register value
EricLew 0:3eee9435dd17 1317 */
EricLew 0:3eee9435dd17 1318 uint8_t MAGNETO_IO_Read(uint8_t RegisterAddr)
EricLew 0:3eee9435dd17 1319 {
EricLew 0:3eee9435dd17 1320 MAGNETO_CS_LOW();
EricLew 0:3eee9435dd17 1321 __SPI_DIRECTION_1LINE_TX(&SpiHandle);
EricLew 0:3eee9435dd17 1322 SPIx_Write(RegisterAddr | 0x80);
EricLew 0:3eee9435dd17 1323 __SPI_DIRECTION_1LINE_RX(&SpiHandle);
EricLew 0:3eee9435dd17 1324 uint8_t val = SPIx_Read();
EricLew 0:3eee9435dd17 1325 MAGNETO_CS_HIGH();
EricLew 0:3eee9435dd17 1326 return val;
EricLew 0:3eee9435dd17 1327 }
EricLew 0:3eee9435dd17 1328
EricLew 0:3eee9435dd17 1329 /********************************* LINK GYRO *****************************/
EricLew 0:3eee9435dd17 1330 /**
EricLew 0:3eee9435dd17 1331 * @brief Configures the GYRO SPI interface.
EricLew 0:3eee9435dd17 1332 * @retval None
EricLew 0:3eee9435dd17 1333 */
EricLew 0:3eee9435dd17 1334 void GYRO_IO_Init(void)
EricLew 0:3eee9435dd17 1335 {
EricLew 0:3eee9435dd17 1336 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 1337
EricLew 0:3eee9435dd17 1338
EricLew 0:3eee9435dd17 1339 /* Case GYRO not used in the demonstration software except being set in
EricLew 0:3eee9435dd17 1340 low power mode.
EricLew 0:3eee9435dd17 1341 To avoid access conflicts with accelerometer and magnetometer,
EricLew 0:3eee9435dd17 1342 initialize XL_CS and MAG_CS pins then deselect these I/O */
EricLew 0:3eee9435dd17 1343 ACCELERO_CS_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1344 GPIO_InitStructure.Pin = ACCELERO_CS_PIN;
EricLew 0:3eee9435dd17 1345 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1346 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1347 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1348 HAL_GPIO_Init(ACCELERO_CS_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1349
EricLew 0:3eee9435dd17 1350 /* Deselect : Chip Select high */
EricLew 0:3eee9435dd17 1351 ACCELERO_CS_HIGH();
EricLew 0:3eee9435dd17 1352
EricLew 0:3eee9435dd17 1353 /* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */
EricLew 0:3eee9435dd17 1354 MAGNETO_CS_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1355 GPIO_InitStructure.Pin = MAGNETO_CS_PIN;
EricLew 0:3eee9435dd17 1356 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1357 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1358 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1359 HAL_GPIO_Init(MAGNETO_CS_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1360
EricLew 0:3eee9435dd17 1361 /* Deselect : Chip Select high */
EricLew 0:3eee9435dd17 1362 MAGNETO_CS_HIGH();
EricLew 0:3eee9435dd17 1363
EricLew 0:3eee9435dd17 1364
EricLew 0:3eee9435dd17 1365 /* Configure the Gyroscope Control pins ---------------------------------*/
EricLew 0:3eee9435dd17 1366 /* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */
EricLew 0:3eee9435dd17 1367 GYRO_CS_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1368 GPIO_InitStructure.Pin = GYRO_CS_PIN;
EricLew 0:3eee9435dd17 1369 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1370 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1371 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1372 HAL_GPIO_Init(GYRO_CS_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1373
EricLew 0:3eee9435dd17 1374 /* Deselect : Chip Select high */
EricLew 0:3eee9435dd17 1375 GYRO_CS_HIGH();
EricLew 0:3eee9435dd17 1376
EricLew 0:3eee9435dd17 1377 /* Enable INT1, INT2 GPIO clock and Configure GPIO PINs to detect Interrupts */
EricLew 0:3eee9435dd17 1378 GYRO_INT1_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1379 GPIO_InitStructure.Pin = GYRO_INT1_PIN;
EricLew 0:3eee9435dd17 1380 GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
EricLew 0:3eee9435dd17 1381 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1382 GPIO_InitStructure.Pull= GPIO_NOPULL;
EricLew 0:3eee9435dd17 1383 HAL_GPIO_Init(GYRO_INT1_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1384
EricLew 0:3eee9435dd17 1385 GYRO_INT2_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1386 GPIO_InitStructure.Pin = GYRO_INT2_PIN;
EricLew 0:3eee9435dd17 1387 HAL_GPIO_Init(GYRO_INT2_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1388
EricLew 0:3eee9435dd17 1389 SPIx_Init();
EricLew 0:3eee9435dd17 1390
EricLew 0:3eee9435dd17 1391 }
EricLew 0:3eee9435dd17 1392
EricLew 0:3eee9435dd17 1393
EricLew 0:3eee9435dd17 1394 /**
EricLew 0:3eee9435dd17 1395 * @brief de-Configures GYRO SPI interface.
EricLew 0:3eee9435dd17 1396 * @retval None
EricLew 0:3eee9435dd17 1397 */
EricLew 0:3eee9435dd17 1398 void GYRO_IO_DeInit(void)
EricLew 0:3eee9435dd17 1399 {
EricLew 0:3eee9435dd17 1400 GPIO_InitTypeDef GPIO_InitStructure;
EricLew 0:3eee9435dd17 1401 /* Enable CS GPIO clock */
EricLew 0:3eee9435dd17 1402 GYRO_CS_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1403
EricLew 0:3eee9435dd17 1404 GPIO_InitStructure.Pin = GYRO_CS_PIN;
EricLew 0:3eee9435dd17 1405 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1406 GPIO_InitStructure.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1407 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1408 HAL_GPIO_Init(GYRO_CS_GPIO_PORT, &GPIO_InitStructure);
EricLew 0:3eee9435dd17 1409
EricLew 0:3eee9435dd17 1410 /* Deselect : Chip Select high */
EricLew 0:3eee9435dd17 1411 GYRO_CS_HIGH();
EricLew 0:3eee9435dd17 1412
EricLew 0:3eee9435dd17 1413 GYRO_INT1_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1414 GYRO_INT2_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1415
EricLew 0:3eee9435dd17 1416 /* Uninitialize the INT1/INT2 Pins */
EricLew 0:3eee9435dd17 1417 HAL_GPIO_DeInit(GYRO_INT1_GPIO_PORT, GYRO_INT1_PIN);
EricLew 0:3eee9435dd17 1418 HAL_GPIO_DeInit(GYRO_INT2_GPIO_PORT, GYRO_INT2_PIN);
EricLew 0:3eee9435dd17 1419
EricLew 0:3eee9435dd17 1420 /* Uninitialize SPI bus */
EricLew 0:3eee9435dd17 1421 SPIx_DeInit();
EricLew 0:3eee9435dd17 1422 }
EricLew 0:3eee9435dd17 1423
EricLew 0:3eee9435dd17 1424 /**
EricLew 0:3eee9435dd17 1425 * @brief Writes one byte to the GYRO.
EricLew 0:3eee9435dd17 1426 * @param pBuffer : pointer to the buffer containing the data to be written to the GYRO.
EricLew 0:3eee9435dd17 1427 * @param WriteAddr : GYRO's internal address to write to.
EricLew 0:3eee9435dd17 1428 * @param NumByteToWrite: Number of bytes to write.
EricLew 0:3eee9435dd17 1429 * @retval None
EricLew 0:3eee9435dd17 1430 */
EricLew 0:3eee9435dd17 1431 void GYRO_IO_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite)
EricLew 0:3eee9435dd17 1432 {
EricLew 0:3eee9435dd17 1433 /* Configure the MS bit:
EricLew 0:3eee9435dd17 1434 - When 0, the address will remain unchanged in multiple read/write commands.
EricLew 0:3eee9435dd17 1435 - When 1, the address will be auto incremented in multiple read/write commands.
EricLew 0:3eee9435dd17 1436 */
EricLew 0:3eee9435dd17 1437 if(NumByteToWrite > 0x01)
EricLew 0:3eee9435dd17 1438 {
EricLew 0:3eee9435dd17 1439 WriteAddr |= (uint8_t)MULTIPLEBYTE_CMD;
EricLew 0:3eee9435dd17 1440 }
EricLew 0:3eee9435dd17 1441 /* Set chip select Low at the start of the transmission */
EricLew 0:3eee9435dd17 1442 GYRO_CS_LOW();
EricLew 0:3eee9435dd17 1443 __SPI_DIRECTION_2LINES(&SpiHandle);
EricLew 0:3eee9435dd17 1444
EricLew 0:3eee9435dd17 1445 /* Send the Address of the indexed register */
EricLew 0:3eee9435dd17 1446 SPIx_WriteRead(WriteAddr);
EricLew 0:3eee9435dd17 1447
EricLew 0:3eee9435dd17 1448 /* Send the data that will be written into the device (MSB First) */
EricLew 0:3eee9435dd17 1449 while(NumByteToWrite >= 0x01)
EricLew 0:3eee9435dd17 1450 {
EricLew 0:3eee9435dd17 1451 SPIx_WriteRead(*pBuffer);
EricLew 0:3eee9435dd17 1452 NumByteToWrite--;
EricLew 0:3eee9435dd17 1453 pBuffer++;
EricLew 0:3eee9435dd17 1454 }
EricLew 0:3eee9435dd17 1455
EricLew 0:3eee9435dd17 1456 /* Set chip select High at the end of the transmission */
EricLew 0:3eee9435dd17 1457 GYRO_CS_HIGH();
EricLew 0:3eee9435dd17 1458 }
EricLew 0:3eee9435dd17 1459
EricLew 0:3eee9435dd17 1460 /**
EricLew 0:3eee9435dd17 1461 * @brief Reads a block of data from the GYROSCOPE.
EricLew 0:3eee9435dd17 1462 * @param pBuffer : pointer to the buffer that receives the data read from the GYROSCOPE.
EricLew 0:3eee9435dd17 1463 * @param ReadAddr : GYROSCOPE's internal address to read from.
EricLew 0:3eee9435dd17 1464 * @param NumByteToRead : number of bytes to read from the GYROSCOPE.
EricLew 0:3eee9435dd17 1465 * @retval None
EricLew 0:3eee9435dd17 1466 */
EricLew 0:3eee9435dd17 1467 void GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead)
EricLew 0:3eee9435dd17 1468 {
EricLew 0:3eee9435dd17 1469 if(NumByteToRead > 0x01)
EricLew 0:3eee9435dd17 1470 {
EricLew 0:3eee9435dd17 1471 ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD);
EricLew 0:3eee9435dd17 1472 }
EricLew 0:3eee9435dd17 1473 else
EricLew 0:3eee9435dd17 1474 {
EricLew 0:3eee9435dd17 1475 ReadAddr |= (uint8_t)READWRITE_CMD;
EricLew 0:3eee9435dd17 1476 }
EricLew 0:3eee9435dd17 1477 /* Set chip select Low at the start of the transmission */
EricLew 0:3eee9435dd17 1478 GYRO_CS_LOW();
EricLew 0:3eee9435dd17 1479 __SPI_DIRECTION_2LINES(&SpiHandle);
EricLew 0:3eee9435dd17 1480 /* Send the Address of the indexed register */
EricLew 0:3eee9435dd17 1481 SPIx_WriteRead(ReadAddr);
EricLew 0:3eee9435dd17 1482
EricLew 0:3eee9435dd17 1483 /* Receive the data that will be read from the device (MSB First) */
EricLew 0:3eee9435dd17 1484 while(NumByteToRead > 0x00)
EricLew 0:3eee9435dd17 1485 {
EricLew 0:3eee9435dd17 1486 /* Send dummy byte (0x00) to generate the SPI clock to GYROSCOPE (Slave device) */
EricLew 0:3eee9435dd17 1487 *pBuffer = SPIx_WriteRead(0x00);
EricLew 0:3eee9435dd17 1488 NumByteToRead--;
EricLew 0:3eee9435dd17 1489 pBuffer++;
EricLew 0:3eee9435dd17 1490 }
EricLew 0:3eee9435dd17 1491
EricLew 0:3eee9435dd17 1492 /* Set chip select High at the end of the transmission */
EricLew 0:3eee9435dd17 1493 GYRO_CS_HIGH();
EricLew 0:3eee9435dd17 1494 }
EricLew 0:3eee9435dd17 1495 #endif /* HAL_SPI_MODULE_ENABLED */
EricLew 0:3eee9435dd17 1496
EricLew 0:3eee9435dd17 1497 #if defined(HAL_I2C_MODULE_ENABLED)
EricLew 0:3eee9435dd17 1498 /********************************* LINK MFX ***********************************/
EricLew 0:3eee9435dd17 1499 /**
EricLew 0:3eee9435dd17 1500 * @brief Initializes MFX low level.
EricLew 0:3eee9435dd17 1501 * @retval None
EricLew 0:3eee9435dd17 1502 */
EricLew 0:3eee9435dd17 1503 void MFX_IO_Init(void)
EricLew 0:3eee9435dd17 1504 {
EricLew 0:3eee9435dd17 1505 /* I2C2 init */
EricLew 0:3eee9435dd17 1506 I2C2_Init();
EricLew 0:3eee9435dd17 1507 }
EricLew 0:3eee9435dd17 1508 /**
EricLew 0:3eee9435dd17 1509 * @brief Deinitializes MFX low level.
EricLew 0:3eee9435dd17 1510 * @retval None
EricLew 0:3eee9435dd17 1511 */
EricLew 0:3eee9435dd17 1512 void MFX_IO_DeInit(void)
EricLew 0:3eee9435dd17 1513 {
EricLew 0:3eee9435dd17 1514 GPIO_InitTypeDef GPIO_InitStruct;
EricLew 0:3eee9435dd17 1515
EricLew 0:3eee9435dd17 1516 /* Enable wakeup gpio clock */
EricLew 0:3eee9435dd17 1517 IDD_WAKEUP_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1518
EricLew 0:3eee9435dd17 1519 /* MFX wakeup pin configuration */
EricLew 0:3eee9435dd17 1520 GPIO_InitStruct.Pin = IDD_WAKEUP_PIN;
EricLew 0:3eee9435dd17 1521 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1522 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
EricLew 0:3eee9435dd17 1523 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
EricLew 0:3eee9435dd17 1524 HAL_GPIO_Init(IDD_WAKEUP_GPIO_PORT, &GPIO_InitStruct);
EricLew 0:3eee9435dd17 1525
EricLew 0:3eee9435dd17 1526 /* DeInit interrupt pin : disable IRQ before to avoid spurious interrupt */
EricLew 0:3eee9435dd17 1527 HAL_NVIC_DisableIRQ((IRQn_Type)(IDD_INT_EXTI_IRQn));
EricLew 0:3eee9435dd17 1528 IDD_INT_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1529 HAL_GPIO_DeInit(IDD_INT_GPIO_PORT, IDD_INT_PIN);
EricLew 0:3eee9435dd17 1530
EricLew 0:3eee9435dd17 1531 /* I2C2 Deinit */
EricLew 0:3eee9435dd17 1532 I2C2_DeInit();
EricLew 0:3eee9435dd17 1533 }
EricLew 0:3eee9435dd17 1534
EricLew 0:3eee9435dd17 1535 /**
EricLew 0:3eee9435dd17 1536 * @brief Configures MFX low level interrupt.
EricLew 0:3eee9435dd17 1537 * @retval None
EricLew 0:3eee9435dd17 1538 */
EricLew 0:3eee9435dd17 1539 void MFX_IO_ITConfig(void)
EricLew 0:3eee9435dd17 1540 {
EricLew 0:3eee9435dd17 1541 GPIO_InitTypeDef GPIO_InitStruct;
EricLew 0:3eee9435dd17 1542
EricLew 0:3eee9435dd17 1543 /* Enable the GPIO clock */
EricLew 0:3eee9435dd17 1544 IDD_INT_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1545
EricLew 0:3eee9435dd17 1546 /* MFX_OUT_IRQ (normally used for EXTI_WKUP) */
EricLew 0:3eee9435dd17 1547 GPIO_InitStruct.Pin = IDD_INT_PIN;
EricLew 0:3eee9435dd17 1548 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
EricLew 0:3eee9435dd17 1549 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1550 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
EricLew 0:3eee9435dd17 1551 HAL_GPIO_Init(IDD_INT_GPIO_PORT, &GPIO_InitStruct);
EricLew 0:3eee9435dd17 1552
EricLew 0:3eee9435dd17 1553 /* Enable and set GPIO EXTI Interrupt to the lowest priority */
EricLew 0:3eee9435dd17 1554 HAL_NVIC_SetPriority((IRQn_Type)(IDD_INT_EXTI_IRQn), 0x0F, 0x0F);
EricLew 0:3eee9435dd17 1555 HAL_NVIC_EnableIRQ((IRQn_Type)(IDD_INT_EXTI_IRQn));
EricLew 0:3eee9435dd17 1556 }
EricLew 0:3eee9435dd17 1557
EricLew 0:3eee9435dd17 1558 /**
EricLew 0:3eee9435dd17 1559 * @brief Configures MFX wke up pin.
EricLew 0:3eee9435dd17 1560 * @retval None
EricLew 0:3eee9435dd17 1561 */
EricLew 0:3eee9435dd17 1562 void MFX_IO_EnableWakeupPin(void)
EricLew 0:3eee9435dd17 1563 {
EricLew 0:3eee9435dd17 1564 GPIO_InitTypeDef GPIO_InitStruct;
EricLew 0:3eee9435dd17 1565
EricLew 0:3eee9435dd17 1566 /* Enable wakeup gpio clock */
EricLew 0:3eee9435dd17 1567 IDD_WAKEUP_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1568
EricLew 0:3eee9435dd17 1569 /* MFX wakeup pin configuration */
EricLew 0:3eee9435dd17 1570 GPIO_InitStruct.Pin = IDD_WAKEUP_PIN;
EricLew 0:3eee9435dd17 1571 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1572 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
EricLew 0:3eee9435dd17 1573 GPIO_InitStruct.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1574 HAL_GPIO_Init(IDD_WAKEUP_GPIO_PORT, &GPIO_InitStruct);
EricLew 0:3eee9435dd17 1575 }
EricLew 0:3eee9435dd17 1576
EricLew 0:3eee9435dd17 1577 /**
EricLew 0:3eee9435dd17 1578 * @brief Wakeup MFX.
EricLew 0:3eee9435dd17 1579 * @retval None
EricLew 0:3eee9435dd17 1580 */
EricLew 0:3eee9435dd17 1581 void MFX_IO_Wakeup(void)
EricLew 0:3eee9435dd17 1582 {
EricLew 0:3eee9435dd17 1583 /* Set Wakeup pin to high to wakeup Idd measurement component from standby mode */
EricLew 0:3eee9435dd17 1584 HAL_GPIO_WritePin(IDD_WAKEUP_GPIO_PORT, IDD_WAKEUP_PIN, GPIO_PIN_SET);
EricLew 0:3eee9435dd17 1585
EricLew 0:3eee9435dd17 1586 /* Wait */
EricLew 0:3eee9435dd17 1587 HAL_Delay(1);
EricLew 0:3eee9435dd17 1588
EricLew 0:3eee9435dd17 1589 /* Set gpio pin basck to low */
EricLew 0:3eee9435dd17 1590 HAL_GPIO_WritePin(IDD_WAKEUP_GPIO_PORT, IDD_WAKEUP_PIN, GPIO_PIN_RESET);
EricLew 0:3eee9435dd17 1591 }
EricLew 0:3eee9435dd17 1592
EricLew 0:3eee9435dd17 1593 /**
EricLew 0:3eee9435dd17 1594 * @brief MFX writes single data.
EricLew 0:3eee9435dd17 1595 * @param Addr: I2C address
EricLew 0:3eee9435dd17 1596 * @param Reg: Register address
EricLew 0:3eee9435dd17 1597 * @param Value: Data to be written
EricLew 0:3eee9435dd17 1598 * @retval None
EricLew 0:3eee9435dd17 1599 */
EricLew 0:3eee9435dd17 1600 void MFX_IO_Write(uint16_t Addr, uint8_t Reg, uint8_t Value)
EricLew 0:3eee9435dd17 1601 {
EricLew 0:3eee9435dd17 1602 I2C2_WriteData(Addr, Reg, I2C_MEMADD_SIZE_8BIT, Value);
EricLew 0:3eee9435dd17 1603 }
EricLew 0:3eee9435dd17 1604
EricLew 0:3eee9435dd17 1605 /**
EricLew 0:3eee9435dd17 1606 * @brief MFX reads single data.
EricLew 0:3eee9435dd17 1607 * @param Addr: I2C address
EricLew 0:3eee9435dd17 1608 * @param Reg: Register address
EricLew 0:3eee9435dd17 1609 * @retval Read data
EricLew 0:3eee9435dd17 1610 */
EricLew 0:3eee9435dd17 1611 uint8_t MFX_IO_Read(uint16_t Addr, uint8_t Reg)
EricLew 0:3eee9435dd17 1612 {
EricLew 0:3eee9435dd17 1613 return I2C2_ReadData(Addr, Reg, I2C_MEMADD_SIZE_8BIT);
EricLew 0:3eee9435dd17 1614 }
EricLew 0:3eee9435dd17 1615
EricLew 0:3eee9435dd17 1616 /**
EricLew 0:3eee9435dd17 1617 * @brief MFX reads multiple data.
EricLew 0:3eee9435dd17 1618 * @param Addr: I2C address
EricLew 0:3eee9435dd17 1619 * @param Reg: Register address
EricLew 0:3eee9435dd17 1620 * @param Buffer: Pointer to data buffer
EricLew 0:3eee9435dd17 1621 * @param Length: Length of the data
EricLew 0:3eee9435dd17 1622 * @retval Number of read data
EricLew 0:3eee9435dd17 1623 */
EricLew 0:3eee9435dd17 1624 uint16_t MFX_IO_ReadMultiple(uint16_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
EricLew 0:3eee9435dd17 1625 {
EricLew 0:3eee9435dd17 1626 return I2C2_ReadBuffer(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
EricLew 0:3eee9435dd17 1627 }
EricLew 0:3eee9435dd17 1628
EricLew 0:3eee9435dd17 1629 /**
EricLew 0:3eee9435dd17 1630 * @brief MFX writes multiple data.
EricLew 0:3eee9435dd17 1631 * @param Addr: I2C address
EricLew 0:3eee9435dd17 1632 * @param Reg: Register address
EricLew 0:3eee9435dd17 1633 * @param Buffer: Pointer to data buffer
EricLew 0:3eee9435dd17 1634 * @param Length: Length of the data
EricLew 0:3eee9435dd17 1635 * @retval None
EricLew 0:3eee9435dd17 1636 */
EricLew 0:3eee9435dd17 1637 void MFX_IO_WriteMultiple(uint16_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length)
EricLew 0:3eee9435dd17 1638 {
EricLew 0:3eee9435dd17 1639 I2C2_WriteBuffer(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, Buffer, Length);
EricLew 0:3eee9435dd17 1640 }
EricLew 0:3eee9435dd17 1641
EricLew 0:3eee9435dd17 1642 /**
EricLew 0:3eee9435dd17 1643 * @brief MFX delay
EricLew 0:3eee9435dd17 1644 * @param Delay: Delay in ms
EricLew 0:3eee9435dd17 1645 * @retval None
EricLew 0:3eee9435dd17 1646 */
EricLew 0:3eee9435dd17 1647 void MFX_IO_Delay(uint32_t Delay)
EricLew 0:3eee9435dd17 1648 {
EricLew 0:3eee9435dd17 1649 HAL_Delay(Delay);
EricLew 0:3eee9435dd17 1650 }
EricLew 0:3eee9435dd17 1651
EricLew 0:3eee9435dd17 1652
EricLew 0:3eee9435dd17 1653 /********************************* LINK AUDIO *********************************/
EricLew 0:3eee9435dd17 1654 /**
EricLew 0:3eee9435dd17 1655 * @brief Initializes Audio low level.
EricLew 0:3eee9435dd17 1656 * @retval None
EricLew 0:3eee9435dd17 1657 */
EricLew 0:3eee9435dd17 1658 void AUDIO_IO_Init(void)
EricLew 0:3eee9435dd17 1659 {
EricLew 0:3eee9435dd17 1660 GPIO_InitTypeDef GPIO_InitStruct;
EricLew 0:3eee9435dd17 1661
EricLew 0:3eee9435dd17 1662 /* Enable Reset GPIO Clock */
EricLew 0:3eee9435dd17 1663 AUDIO_RESET_GPIO_CLK_ENABLE();
EricLew 0:3eee9435dd17 1664
EricLew 0:3eee9435dd17 1665 /* Audio reset pin configuration */
EricLew 0:3eee9435dd17 1666 GPIO_InitStruct.Pin = AUDIO_RESET_PIN;
EricLew 0:3eee9435dd17 1667 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
EricLew 0:3eee9435dd17 1668 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
EricLew 0:3eee9435dd17 1669 GPIO_InitStruct.Pull = GPIO_NOPULL;
EricLew 0:3eee9435dd17 1670 HAL_GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStruct);
EricLew 0:3eee9435dd17 1671
EricLew 0:3eee9435dd17 1672 /* I2C bus init */
EricLew 0:3eee9435dd17 1673 I2C1_Init();
EricLew 0:3eee9435dd17 1674
EricLew 0:3eee9435dd17 1675 /* Power Down the codec */
EricLew 0:3eee9435dd17 1676 CODEC_AUDIO_POWER_OFF();
EricLew 0:3eee9435dd17 1677
EricLew 0:3eee9435dd17 1678 /* wait for a delay to insure registers erasing */
EricLew 0:3eee9435dd17 1679 HAL_Delay(5);
EricLew 0:3eee9435dd17 1680
EricLew 0:3eee9435dd17 1681 /* Power on the codec */
EricLew 0:3eee9435dd17 1682 CODEC_AUDIO_POWER_ON();
EricLew 0:3eee9435dd17 1683
EricLew 0:3eee9435dd17 1684 /* wait for a delay to insure registers erasing */
EricLew 0:3eee9435dd17 1685 HAL_Delay(5);
EricLew 0:3eee9435dd17 1686 }
EricLew 0:3eee9435dd17 1687
EricLew 0:3eee9435dd17 1688 /**
EricLew 0:3eee9435dd17 1689 * @brief Deinitializes Audio low level.
EricLew 0:3eee9435dd17 1690 * @retval None
EricLew 0:3eee9435dd17 1691 */
EricLew 0:3eee9435dd17 1692 void AUDIO_IO_DeInit(void) /* TO DO */
EricLew 0:3eee9435dd17 1693 {
EricLew 0:3eee9435dd17 1694 GPIO_InitTypeDef GPIO_InitStruct;
EricLew 0:3eee9435dd17 1695
EricLew 0:3eee9435dd17 1696 /***********************************************************************/
EricLew 0:3eee9435dd17 1697 /* In case of battery-supplied powered, there is no audio codec-based
EricLew 0:3eee9435dd17 1698 features available. Set audio codec I/O default setting */
EricLew 0:3eee9435dd17 1699 /***********************************************************************/
EricLew 0:3eee9435dd17 1700 __HAL_RCC_GPIOE_CLK_ENABLE();
EricLew 0:3eee9435dd17 1701 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP ;
EricLew 0:3eee9435dd17 1702 GPIO_InitStruct.Pin = (GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);
EricLew 0:3eee9435dd17 1703 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
EricLew 0:3eee9435dd17 1704 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
EricLew 0:3eee9435dd17 1705 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
EricLew 0:3eee9435dd17 1706 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET);
EricLew 0:3eee9435dd17 1707 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_RESET);
EricLew 0:3eee9435dd17 1708 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_RESET);
EricLew 0:3eee9435dd17 1709 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_5, GPIO_PIN_RESET);
EricLew 0:3eee9435dd17 1710 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6, GPIO_PIN_RESET);
EricLew 0:3eee9435dd17 1711
EricLew 0:3eee9435dd17 1712 /* I2C bus Deinit */
EricLew 0:3eee9435dd17 1713 I2C1_DeInit();
EricLew 0:3eee9435dd17 1714 }
EricLew 0:3eee9435dd17 1715
EricLew 0:3eee9435dd17 1716 /**
EricLew 0:3eee9435dd17 1717 * @brief Writes a single data.
EricLew 0:3eee9435dd17 1718 * @param Addr: I2C address
EricLew 0:3eee9435dd17 1719 * @param Reg: Reg address
EricLew 0:3eee9435dd17 1720 * @param Value: Data to be written
EricLew 0:3eee9435dd17 1721 * @retval None
EricLew 0:3eee9435dd17 1722 */
EricLew 0:3eee9435dd17 1723 void AUDIO_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
EricLew 0:3eee9435dd17 1724 {
EricLew 0:3eee9435dd17 1725 I2C1_WriteBuffer(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1);
EricLew 0:3eee9435dd17 1726 }
EricLew 0:3eee9435dd17 1727
EricLew 0:3eee9435dd17 1728 /**
EricLew 0:3eee9435dd17 1729 * @brief Reads a single data.
EricLew 0:3eee9435dd17 1730 * @param Addr: I2C address
EricLew 0:3eee9435dd17 1731 * @param Reg: Reg address
EricLew 0:3eee9435dd17 1732 * @retval Data to be read
EricLew 0:3eee9435dd17 1733 */
EricLew 0:3eee9435dd17 1734 uint8_t AUDIO_IO_Read(uint8_t Addr, uint8_t Reg)
EricLew 0:3eee9435dd17 1735 {
EricLew 0:3eee9435dd17 1736 uint8_t Read_Value = 0;
EricLew 0:3eee9435dd17 1737
EricLew 0:3eee9435dd17 1738 I2C1_ReadBuffer((uint16_t) Addr, (uint16_t) Reg, I2C_MEMADD_SIZE_8BIT, &Read_Value, 1);
EricLew 0:3eee9435dd17 1739
EricLew 0:3eee9435dd17 1740 return Read_Value;
EricLew 0:3eee9435dd17 1741 }
EricLew 0:3eee9435dd17 1742
EricLew 0:3eee9435dd17 1743 /**
EricLew 0:3eee9435dd17 1744 * @brief AUDIO Codec delay
EricLew 0:3eee9435dd17 1745 * @param Delay: Delay in ms
EricLew 0:3eee9435dd17 1746 * @retval None
EricLew 0:3eee9435dd17 1747 */
EricLew 0:3eee9435dd17 1748 void AUDIO_IO_Delay(uint32_t Delay)
EricLew 0:3eee9435dd17 1749 {
EricLew 0:3eee9435dd17 1750 HAL_Delay(Delay);
EricLew 0:3eee9435dd17 1751 }
EricLew 0:3eee9435dd17 1752 #endif /* HAL_I2C_MODULE_ENABLED */
EricLew 0:3eee9435dd17 1753
EricLew 0:3eee9435dd17 1754 /**
EricLew 0:3eee9435dd17 1755 * @}
EricLew 0:3eee9435dd17 1756 */
EricLew 0:3eee9435dd17 1757
EricLew 0:3eee9435dd17 1758 /**
EricLew 0:3eee9435dd17 1759 * @}
EricLew 0:3eee9435dd17 1760 */
EricLew 0:3eee9435dd17 1761
EricLew 0:3eee9435dd17 1762 /**
EricLew 0:3eee9435dd17 1763 * @}
EricLew 0:3eee9435dd17 1764 */
EricLew 0:3eee9435dd17 1765
EricLew 0:3eee9435dd17 1766 /**
EricLew 0:3eee9435dd17 1767 * @}
EricLew 0:3eee9435dd17 1768 */
EricLew 0:3eee9435dd17 1769
EricLew 0:3eee9435dd17 1770 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
EricLew 0:3eee9435dd17 1771
EricLew 0:3eee9435dd17 1772