forked for landscape mode text

Dependents:   DISCO-F429ZI_LCDTS_demo_richard

Fork of BSP_DISCO_F429ZI by ST

Committer:
pierrebizouard
Date:
Fri Mar 16 09:50:17 2018 +0000
Revision:
5:a76cfea518cc
Parent:
2:53d9067a4feb
final version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jerome Coutant 1:2371382139dd 1 /**
Jerome Coutant 1:2371382139dd 2 ******************************************************************************
Jerome Coutant 1:2371382139dd 3 * @file stm32f429i_discovery.c
Jerome Coutant 1:2371382139dd 4 * @author MCD Application Team
Jerome Coutant 1:2371382139dd 5 * @brief This file provides set of firmware functions to manage Leds and
Jerome Coutant 1:2371382139dd 6 * push-button available on STM32F429I-Discovery Kit from STMicroelectronics.
Jerome Coutant 1:2371382139dd 7 ******************************************************************************
Jerome Coutant 1:2371382139dd 8 * @attention
Jerome Coutant 1:2371382139dd 9 *
Jerome Coutant 1:2371382139dd 10 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
Jerome Coutant 1:2371382139dd 11 *
Jerome Coutant 1:2371382139dd 12 * Redistribution and use in source and binary forms, with or without modification,
Jerome Coutant 1:2371382139dd 13 * are permitted provided that the following conditions are met:
Jerome Coutant 1:2371382139dd 14 * 1. Redistributions of source code must retain the above copyright notice,
Jerome Coutant 1:2371382139dd 15 * this list of conditions and the following disclaimer.
Jerome Coutant 1:2371382139dd 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
Jerome Coutant 1:2371382139dd 17 * this list of conditions and the following disclaimer in the documentation
Jerome Coutant 1:2371382139dd 18 * and/or other materials provided with the distribution.
Jerome Coutant 1:2371382139dd 19 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Jerome Coutant 1:2371382139dd 20 * may be used to endorse or promote products derived from this software
Jerome Coutant 1:2371382139dd 21 * without specific prior written permission.
Jerome Coutant 1:2371382139dd 22 *
Jerome Coutant 1:2371382139dd 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Jerome Coutant 1:2371382139dd 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Jerome Coutant 1:2371382139dd 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Jerome Coutant 1:2371382139dd 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Jerome Coutant 1:2371382139dd 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Jerome Coutant 1:2371382139dd 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Jerome Coutant 1:2371382139dd 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Jerome Coutant 1:2371382139dd 30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Jerome Coutant 1:2371382139dd 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Jerome Coutant 1:2371382139dd 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jerome Coutant 1:2371382139dd 33 *
Jerome Coutant 1:2371382139dd 34 ******************************************************************************
Jerome Coutant 1:2371382139dd 35 */
Jerome Coutant 1:2371382139dd 36
Jerome Coutant 1:2371382139dd 37 /* Includes ------------------------------------------------------------------*/
Jerome Coutant 1:2371382139dd 38 #include "stm32f429i_discovery.h"
Jerome Coutant 1:2371382139dd 39 #include "cmsis_nvic.h" // // Added for mbed
Jerome Coutant 1:2371382139dd 40
Jerome Coutant 1:2371382139dd 41 // Added for mbed. This function replaces HAL_Delay()
Jerome Coutant 1:2371382139dd 42 void wait_ms(int ms);
Jerome Coutant 1:2371382139dd 43
Jerome Coutant 1:2371382139dd 44 /** @defgroup BSP BSP
Jerome Coutant 1:2371382139dd 45 * @{
Jerome Coutant 1:2371382139dd 46 */
Jerome Coutant 1:2371382139dd 47
Jerome Coutant 1:2371382139dd 48 /** @defgroup STM32F429I_DISCOVERY STM32F429I DISCOVERY
Jerome Coutant 1:2371382139dd 49 * @{
Jerome Coutant 1:2371382139dd 50 */
Jerome Coutant 1:2371382139dd 51
Jerome Coutant 1:2371382139dd 52 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL STM32F429I DISCOVERY LOW LEVEL
Jerome Coutant 1:2371382139dd 53 * @brief This file provides set of firmware functions to manage Leds and push-button
Jerome Coutant 1:2371382139dd 54 * available on STM32F429I-Discovery Kit from STMicroelectronics.
Jerome Coutant 1:2371382139dd 55 * @{
Jerome Coutant 1:2371382139dd 56 */
Jerome Coutant 1:2371382139dd 57
Jerome Coutant 1:2371382139dd 58 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32F429I DISCOVERY LOW LEVEL Private TypesDefinitions
Jerome Coutant 1:2371382139dd 59 * @{
Jerome Coutant 1:2371382139dd 60 */
Jerome Coutant 1:2371382139dd 61 /**
Jerome Coutant 1:2371382139dd 62 * @}
Jerome Coutant 1:2371382139dd 63 */
Jerome Coutant 1:2371382139dd 64
Jerome Coutant 1:2371382139dd 65 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_Defines STM32F429I DISCOVERY LOW LEVEL Private Defines
Jerome Coutant 1:2371382139dd 66 * @{
Jerome Coutant 1:2371382139dd 67 */
Jerome Coutant 1:2371382139dd 68
Jerome Coutant 1:2371382139dd 69 /**
Jerome Coutant 2:53d9067a4feb 70 * @brief STM32F429I DISCO BSP Driver version number V2.1.6
Jerome Coutant 1:2371382139dd 71 */
Jerome Coutant 1:2371382139dd 72 #define __STM32F429I_DISCO_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */
Jerome Coutant 1:2371382139dd 73 #define __STM32F429I_DISCO_BSP_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */
Jerome Coutant 2:53d9067a4feb 74 #define __STM32F429I_DISCO_BSP_VERSION_SUB2 (0x06) /*!< [15:8] sub2 version */
Jerome Coutant 1:2371382139dd 75 #define __STM32F429I_DISCO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
Jerome Coutant 1:2371382139dd 76 #define __STM32F429I_DISCO_BSP_VERSION ((__STM32F429I_DISCO_BSP_VERSION_MAIN << 24)\
Jerome Coutant 1:2371382139dd 77 |(__STM32F429I_DISCO_BSP_VERSION_SUB1 << 16)\
Jerome Coutant 1:2371382139dd 78 |(__STM32F429I_DISCO_BSP_VERSION_SUB2 << 8 )\
Jerome Coutant 1:2371382139dd 79 |(__STM32F429I_DISCO_BSP_VERSION_RC))
Jerome Coutant 1:2371382139dd 80 /**
Jerome Coutant 1:2371382139dd 81 * @}
Jerome Coutant 1:2371382139dd 82 */
Jerome Coutant 1:2371382139dd 83
Jerome Coutant 1:2371382139dd 84 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_Macros STM32F429I DISCOVERY LOW LEVEL Private Macros
Jerome Coutant 1:2371382139dd 85 * @{
Jerome Coutant 1:2371382139dd 86 */
Jerome Coutant 1:2371382139dd 87 /**
Jerome Coutant 1:2371382139dd 88 * @}
Jerome Coutant 1:2371382139dd 89 */
Jerome Coutant 1:2371382139dd 90
Jerome Coutant 1:2371382139dd 91 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_Variables STM32F429I DISCOVERY LOW LEVEL Private Variables
Jerome Coutant 1:2371382139dd 92 * @{
Jerome Coutant 1:2371382139dd 93 */
Jerome Coutant 1:2371382139dd 94 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT,
Jerome Coutant 1:2371382139dd 95 LED4_GPIO_PORT};
Jerome Coutant 1:2371382139dd 96
Jerome Coutant 1:2371382139dd 97 const uint16_t GPIO_PIN[LEDn] = {LED3_PIN,
Jerome Coutant 1:2371382139dd 98 LED4_PIN};
Jerome Coutant 1:2371382139dd 99
Jerome Coutant 1:2371382139dd 100 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT};
Jerome Coutant 1:2371382139dd 101 const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN};
Jerome Coutant 1:2371382139dd 102 const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn};
Jerome Coutant 1:2371382139dd 103
Jerome Coutant 1:2371382139dd 104 uint32_t I2cxTimeout = I2Cx_TIMEOUT_MAX; /*<! Value of Timeout when I2C communication fails */
Jerome Coutant 1:2371382139dd 105 uint32_t SpixTimeout = SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */
Jerome Coutant 1:2371382139dd 106
Jerome Coutant 1:2371382139dd 107 I2C_HandleTypeDef EEP_I2cHandle;
Jerome Coutant 1:2371382139dd 108 static SPI_HandleTypeDef SpiHandle;
Jerome Coutant 1:2371382139dd 109 static uint8_t Is_LCD_IO_Initialized = 0;
Jerome Coutant 1:2371382139dd 110
Jerome Coutant 1:2371382139dd 111 /**
Jerome Coutant 1:2371382139dd 112 * @}
Jerome Coutant 1:2371382139dd 113 */
Jerome Coutant 1:2371382139dd 114
Jerome Coutant 1:2371382139dd 115 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32F429I DISCOVERY LOW LEVEL Private FunctionPrototypes
Jerome Coutant 1:2371382139dd 116 * @{
Jerome Coutant 1:2371382139dd 117 */
Jerome Coutant 1:2371382139dd 118 /* I2Cx bus function */
Jerome Coutant 1:2371382139dd 119 static void I2Cx_Init(void);
Jerome Coutant 1:2371382139dd 120 static void I2Cx_ITConfig(void);
Jerome Coutant 1:2371382139dd 121 static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value);
Jerome Coutant 1:2371382139dd 122 static void I2Cx_WriteBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
Jerome Coutant 1:2371382139dd 123 static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg);
Jerome Coutant 1:2371382139dd 124 static uint8_t I2Cx_ReadBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
Jerome Coutant 1:2371382139dd 125 static void I2Cx_Error(void);
Jerome Coutant 1:2371382139dd 126 static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c);
Jerome Coutant 1:2371382139dd 127 #ifdef EE_M24LR64
Jerome Coutant 1:2371382139dd 128 static HAL_StatusTypeDef I2Cx_WriteBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length);
Jerome Coutant 1:2371382139dd 129 static HAL_StatusTypeDef I2Cx_ReadBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length);
Jerome Coutant 1:2371382139dd 130 static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
Jerome Coutant 1:2371382139dd 131 static void EEPROM_I2C_DMA_TX_IRQHandler(void);
Jerome Coutant 1:2371382139dd 132 static void EEPROM_I2C_DMA_RX_IRQHandler(void);
Jerome Coutant 1:2371382139dd 133 #endif /* EE_M24LR64 */
Jerome Coutant 1:2371382139dd 134
Jerome Coutant 1:2371382139dd 135 /* SPIx bus function */
Jerome Coutant 1:2371382139dd 136 static void SPIx_Init(void);
Jerome Coutant 1:2371382139dd 137 static void SPIx_Write(uint16_t Value);
Jerome Coutant 1:2371382139dd 138 static uint32_t SPIx_Read(uint8_t ReadSize);
Jerome Coutant 1:2371382139dd 139 static uint8_t SPIx_WriteRead(uint8_t Byte);
Jerome Coutant 1:2371382139dd 140 static void SPIx_Error(void);
Jerome Coutant 1:2371382139dd 141 static void SPIx_MspInit(SPI_HandleTypeDef *hspi);
Jerome Coutant 1:2371382139dd 142
Jerome Coutant 1:2371382139dd 143 /* Link function for LCD peripheral */
Jerome Coutant 1:2371382139dd 144 void LCD_IO_Init(void);
Jerome Coutant 1:2371382139dd 145 void LCD_IO_WriteData(uint16_t RegValue);
Jerome Coutant 1:2371382139dd 146 void LCD_IO_WriteReg(uint8_t Reg);
Jerome Coutant 1:2371382139dd 147 uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
Jerome Coutant 1:2371382139dd 148 void LCD_Delay(uint32_t delay);
Jerome Coutant 1:2371382139dd 149
Jerome Coutant 1:2371382139dd 150 /* IOExpander IO functions */
Jerome Coutant 1:2371382139dd 151 void IOE_Init(void);
Jerome Coutant 1:2371382139dd 152 void IOE_ITConfig(void);
Jerome Coutant 1:2371382139dd 153 void IOE_Delay(uint32_t Delay);
Jerome Coutant 1:2371382139dd 154 void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
Jerome Coutant 1:2371382139dd 155 uint8_t IOE_Read(uint8_t Addr, uint8_t Reg);
Jerome Coutant 1:2371382139dd 156 uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
Jerome Coutant 1:2371382139dd 157 void IOE_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
Jerome Coutant 1:2371382139dd 158
Jerome Coutant 1:2371382139dd 159 /* Link function for GYRO peripheral */
Jerome Coutant 1:2371382139dd 160 void GYRO_IO_Init(void);
Jerome Coutant 1:2371382139dd 161 void GYRO_IO_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite);
Jerome Coutant 1:2371382139dd 162 void GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead);
Jerome Coutant 1:2371382139dd 163
Jerome Coutant 1:2371382139dd 164 #ifdef EE_M24LR64
Jerome Coutant 1:2371382139dd 165 /* Link function for I2C EEPROM peripheral */
Jerome Coutant 1:2371382139dd 166 void EEPROM_IO_Init(void);
Jerome Coutant 1:2371382139dd 167 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
Jerome Coutant 1:2371382139dd 168 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
Jerome Coutant 1:2371382139dd 169 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
Jerome Coutant 1:2371382139dd 170 #endif /* EE_M24LR64 */
Jerome Coutant 1:2371382139dd 171
Jerome Coutant 1:2371382139dd 172 /**
Jerome Coutant 1:2371382139dd 173 * @}
Jerome Coutant 1:2371382139dd 174 */
Jerome Coutant 1:2371382139dd 175
Jerome Coutant 1:2371382139dd 176 /** @defgroup STM32F429I_DISCOVERY_LOW_LEVEL_Private_Functions STM32F429I DISCOVERY LOW LEVEL Private Functions
Jerome Coutant 1:2371382139dd 177 * @{
Jerome Coutant 1:2371382139dd 178 */
Jerome Coutant 1:2371382139dd 179
Jerome Coutant 1:2371382139dd 180 /**
Jerome Coutant 1:2371382139dd 181 * @brief This method returns the STM32F429I DISCO BSP Driver revision
Jerome Coutant 1:2371382139dd 182 * @retval version: 0xXYZR (8bits for each decimal, R for RC)
Jerome Coutant 1:2371382139dd 183 */
Jerome Coutant 1:2371382139dd 184 uint32_t BSP_GetVersion(void)
Jerome Coutant 1:2371382139dd 185 {
Jerome Coutant 1:2371382139dd 186 return __STM32F429I_DISCO_BSP_VERSION;
Jerome Coutant 1:2371382139dd 187 }
Jerome Coutant 1:2371382139dd 188
Jerome Coutant 1:2371382139dd 189 /**
Jerome Coutant 1:2371382139dd 190 * @brief Configures LED GPIO.
Jerome Coutant 1:2371382139dd 191 * @param Led: Specifies the Led to be configured.
Jerome Coutant 1:2371382139dd 192 * This parameter can be one of following parameters:
Jerome Coutant 1:2371382139dd 193 * @arg LED3
Jerome Coutant 1:2371382139dd 194 * @arg LED4
Jerome Coutant 1:2371382139dd 195 */
Jerome Coutant 1:2371382139dd 196 void BSP_LED_Init(Led_TypeDef Led)
Jerome Coutant 1:2371382139dd 197 {
Jerome Coutant 1:2371382139dd 198 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 1:2371382139dd 199
Jerome Coutant 1:2371382139dd 200 /* Enable the GPIO_LED Clock */
Jerome Coutant 1:2371382139dd 201 LEDx_GPIO_CLK_ENABLE(Led);
Jerome Coutant 1:2371382139dd 202
Jerome Coutant 1:2371382139dd 203 /* Configure the GPIO_LED pin */
Jerome Coutant 1:2371382139dd 204 GPIO_InitStruct.Pin = GPIO_PIN[Led];
Jerome Coutant 1:2371382139dd 205 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
Jerome Coutant 1:2371382139dd 206 GPIO_InitStruct.Pull = GPIO_PULLUP;
Jerome Coutant 1:2371382139dd 207 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
Jerome Coutant 1:2371382139dd 208
Jerome Coutant 1:2371382139dd 209 HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
Jerome Coutant 1:2371382139dd 210
Jerome Coutant 1:2371382139dd 211 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
Jerome Coutant 1:2371382139dd 212 }
Jerome Coutant 1:2371382139dd 213
Jerome Coutant 1:2371382139dd 214 /**
Jerome Coutant 1:2371382139dd 215 * @brief Turns selected LED On.
Jerome Coutant 1:2371382139dd 216 * @param Led: Specifies the Led to be set on.
Jerome Coutant 1:2371382139dd 217 * This parameter can be one of following parameters:
Jerome Coutant 1:2371382139dd 218 * @arg LED3
Jerome Coutant 1:2371382139dd 219 * @arg LED4
Jerome Coutant 1:2371382139dd 220 */
Jerome Coutant 1:2371382139dd 221 void BSP_LED_On(Led_TypeDef Led)
Jerome Coutant 1:2371382139dd 222 {
Jerome Coutant 1:2371382139dd 223 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
Jerome Coutant 1:2371382139dd 224 }
Jerome Coutant 1:2371382139dd 225
Jerome Coutant 1:2371382139dd 226 /**
Jerome Coutant 1:2371382139dd 227 * @brief Turns selected LED Off.
Jerome Coutant 1:2371382139dd 228 * @param Led: Specifies the Led to be set off.
Jerome Coutant 1:2371382139dd 229 * This parameter can be one of following parameters:
Jerome Coutant 1:2371382139dd 230 * @arg LED3
Jerome Coutant 1:2371382139dd 231 * @arg LED4
Jerome Coutant 1:2371382139dd 232 */
Jerome Coutant 1:2371382139dd 233 void BSP_LED_Off(Led_TypeDef Led)
Jerome Coutant 1:2371382139dd 234 {
Jerome Coutant 1:2371382139dd 235 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
Jerome Coutant 1:2371382139dd 236 }
Jerome Coutant 1:2371382139dd 237
Jerome Coutant 1:2371382139dd 238 /**
Jerome Coutant 1:2371382139dd 239 * @brief Toggles the selected LED.
Jerome Coutant 1:2371382139dd 240 * @param Led: Specifies the Led to be toggled.
Jerome Coutant 1:2371382139dd 241 * This parameter can be one of following parameters:
Jerome Coutant 1:2371382139dd 242 * @arg LED3
Jerome Coutant 1:2371382139dd 243 * @arg LED4
Jerome Coutant 1:2371382139dd 244 */
Jerome Coutant 1:2371382139dd 245 void BSP_LED_Toggle(Led_TypeDef Led)
Jerome Coutant 1:2371382139dd 246 {
Jerome Coutant 1:2371382139dd 247 HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
Jerome Coutant 1:2371382139dd 248 }
Jerome Coutant 1:2371382139dd 249
Jerome Coutant 1:2371382139dd 250 /**
Jerome Coutant 1:2371382139dd 251 * @brief Configures Button GPIO and EXTI Line.
Jerome Coutant 1:2371382139dd 252 * @param Button: Specifies the Button to be configured.
Jerome Coutant 1:2371382139dd 253 * This parameter should be: BUTTON_KEY
Jerome Coutant 1:2371382139dd 254 * @param ButtonMode: Specifies Button mode.
Jerome Coutant 1:2371382139dd 255 * This parameter can be one of following parameters:
Jerome Coutant 1:2371382139dd 256 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
Jerome Coutant 1:2371382139dd 257 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
Jerome Coutant 1:2371382139dd 258 * generation capability
Jerome Coutant 1:2371382139dd 259 */
Jerome Coutant 1:2371382139dd 260 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
Jerome Coutant 1:2371382139dd 261 {
Jerome Coutant 1:2371382139dd 262 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 1:2371382139dd 263
Jerome Coutant 1:2371382139dd 264 /* Enable the BUTTON Clock */
Jerome Coutant 1:2371382139dd 265 BUTTONx_GPIO_CLK_ENABLE(Button);
Jerome Coutant 1:2371382139dd 266
Jerome Coutant 1:2371382139dd 267 if (ButtonMode == BUTTON_MODE_GPIO)
Jerome Coutant 1:2371382139dd 268 {
Jerome Coutant 1:2371382139dd 269 /* Configure Button pin as input */
Jerome Coutant 1:2371382139dd 270 GPIO_InitStruct.Pin = BUTTON_PIN[Button];
Jerome Coutant 1:2371382139dd 271 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
Jerome Coutant 1:2371382139dd 272 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
Jerome Coutant 1:2371382139dd 273 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
Jerome Coutant 1:2371382139dd 274 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
Jerome Coutant 1:2371382139dd 275 }
Jerome Coutant 1:2371382139dd 276
Jerome Coutant 1:2371382139dd 277 if (ButtonMode == BUTTON_MODE_EXTI)
Jerome Coutant 1:2371382139dd 278 {
Jerome Coutant 1:2371382139dd 279 /* Configure Button pin as input with External interrupt */
Jerome Coutant 1:2371382139dd 280 GPIO_InitStruct.Pin = BUTTON_PIN[Button];
Jerome Coutant 1:2371382139dd 281 GPIO_InitStruct.Pull = GPIO_NOPULL;
Jerome Coutant 1:2371382139dd 282 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
Jerome Coutant 1:2371382139dd 283 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
Jerome Coutant 1:2371382139dd 284
Jerome Coutant 1:2371382139dd 285 /* Enable and set Button EXTI Interrupt to the lowest priority */
Jerome Coutant 1:2371382139dd 286 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
Jerome Coutant 1:2371382139dd 287 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
Jerome Coutant 1:2371382139dd 288 }
Jerome Coutant 1:2371382139dd 289 }
Jerome Coutant 1:2371382139dd 290
Jerome Coutant 1:2371382139dd 291 /**
Jerome Coutant 1:2371382139dd 292 * @brief Returns the selected Button state.
Jerome Coutant 1:2371382139dd 293 * @param Button: Specifies the Button to be checked.
Jerome Coutant 1:2371382139dd 294 * This parameter should be: BUTTON_KEY
Jerome Coutant 1:2371382139dd 295 * @retval The Button GPIO pin value.
Jerome Coutant 1:2371382139dd 296 */
Jerome Coutant 1:2371382139dd 297 uint32_t BSP_PB_GetState(Button_TypeDef Button)
Jerome Coutant 1:2371382139dd 298 {
Jerome Coutant 1:2371382139dd 299 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
Jerome Coutant 1:2371382139dd 300 }
Jerome Coutant 1:2371382139dd 301
Jerome Coutant 1:2371382139dd 302 /*******************************************************************************
Jerome Coutant 1:2371382139dd 303 BUS OPERATIONS
Jerome Coutant 1:2371382139dd 304 *******************************************************************************/
Jerome Coutant 1:2371382139dd 305
Jerome Coutant 1:2371382139dd 306 /******************************* I2C Routines *********************************/
Jerome Coutant 1:2371382139dd 307
Jerome Coutant 1:2371382139dd 308 /**
Jerome Coutant 1:2371382139dd 309 * @brief I2Cx MSP Initialization
Jerome Coutant 1:2371382139dd 310 * @param hi2c: I2C handle
Jerome Coutant 1:2371382139dd 311 */
Jerome Coutant 1:2371382139dd 312 static void I2Cx_MspInit(I2C_HandleTypeDef *hi2c)
Jerome Coutant 1:2371382139dd 313 {
Jerome Coutant 1:2371382139dd 314 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 1:2371382139dd 315 #ifdef EE_M24LR64
Jerome Coutant 1:2371382139dd 316 static DMA_HandleTypeDef hdma_tx;
Jerome Coutant 1:2371382139dd 317 static DMA_HandleTypeDef hdma_rx;
Jerome Coutant 1:2371382139dd 318
Jerome Coutant 1:2371382139dd 319 I2C_HandleTypeDef* pI2cHandle;
Jerome Coutant 1:2371382139dd 320 pI2cHandle = &EEP_I2cHandle;
Jerome Coutant 1:2371382139dd 321 #endif /* EE_M24LR64 */
Jerome Coutant 1:2371382139dd 322
Jerome Coutant 1:2371382139dd 323 if (hi2c->Instance == DISCOVERY_I2Cx)
Jerome Coutant 1:2371382139dd 324 {
Jerome Coutant 1:2371382139dd 325 /* Configure the GPIOs ---------------------------------------------------*/
Jerome Coutant 1:2371382139dd 326 /* Enable GPIO clock */
Jerome Coutant 1:2371382139dd 327 DISCOVERY_I2Cx_SDA_GPIO_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 328 DISCOVERY_I2Cx_SCL_GPIO_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 329
Jerome Coutant 1:2371382139dd 330 /* Configure I2C Tx as alternate function */
Jerome Coutant 1:2371382139dd 331 GPIO_InitStruct.Pin = DISCOVERY_I2Cx_SCL_PIN;
Jerome Coutant 1:2371382139dd 332 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
Jerome Coutant 1:2371382139dd 333 GPIO_InitStruct.Pull = GPIO_NOPULL;
Jerome Coutant 1:2371382139dd 334 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
Jerome Coutant 1:2371382139dd 335 GPIO_InitStruct.Alternate = DISCOVERY_I2Cx_SCL_SDA_AF;
Jerome Coutant 1:2371382139dd 336 HAL_GPIO_Init(DISCOVERY_I2Cx_SCL_GPIO_PORT, &GPIO_InitStruct);
Jerome Coutant 1:2371382139dd 337
Jerome Coutant 1:2371382139dd 338 /* Configure I2C Rx as alternate function */
Jerome Coutant 1:2371382139dd 339 GPIO_InitStruct.Pin = DISCOVERY_I2Cx_SDA_PIN;
Jerome Coutant 1:2371382139dd 340 HAL_GPIO_Init(DISCOVERY_I2Cx_SDA_GPIO_PORT, &GPIO_InitStruct);
Jerome Coutant 1:2371382139dd 341
Jerome Coutant 1:2371382139dd 342
Jerome Coutant 1:2371382139dd 343 /* Configure the Discovery I2Cx peripheral -------------------------------*/
Jerome Coutant 1:2371382139dd 344 /* Enable I2C3 clock */
Jerome Coutant 1:2371382139dd 345 DISCOVERY_I2Cx_CLOCK_ENABLE();
Jerome Coutant 1:2371382139dd 346
Jerome Coutant 1:2371382139dd 347 /* Force the I2C Peripheral Clock Reset */
Jerome Coutant 1:2371382139dd 348 DISCOVERY_I2Cx_FORCE_RESET();
Jerome Coutant 1:2371382139dd 349
Jerome Coutant 1:2371382139dd 350 /* Release the I2C Peripheral Clock Reset */
Jerome Coutant 1:2371382139dd 351 DISCOVERY_I2Cx_RELEASE_RESET();
Jerome Coutant 1:2371382139dd 352
Jerome Coutant 1:2371382139dd 353 /* Enable and set Discovery I2Cx Interrupt to the lowest priority */
Jerome Coutant 1:2371382139dd 354 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_EV_IRQn, 0x0F, 0);
Jerome Coutant 1:2371382139dd 355 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_EV_IRQn);
Jerome Coutant 1:2371382139dd 356
Jerome Coutant 1:2371382139dd 357 /* Enable and set Discovery I2Cx Interrupt to the lowest priority */
Jerome Coutant 1:2371382139dd 358 HAL_NVIC_SetPriority(DISCOVERY_I2Cx_ER_IRQn, 0x0F, 0);
Jerome Coutant 1:2371382139dd 359 HAL_NVIC_EnableIRQ(DISCOVERY_I2Cx_ER_IRQn);
Jerome Coutant 1:2371382139dd 360
Jerome Coutant 1:2371382139dd 361 #ifdef EE_M24LR64
Jerome Coutant 1:2371382139dd 362 /* I2C DMA TX and RX channels configuration */
Jerome Coutant 1:2371382139dd 363 /* Enable the DMA clock */
Jerome Coutant 1:2371382139dd 364 EEPROM_I2C_DMA_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 365
Jerome Coutant 1:2371382139dd 366 /* Configure the DMA stream for the EE I2C peripheral TX direction */
Jerome Coutant 1:2371382139dd 367 /* Configure the DMA Stream */
Jerome Coutant 1:2371382139dd 368 hdma_tx.Instance = EEPROM_I2C_DMA_STREAM_TX;
Jerome Coutant 1:2371382139dd 369 /* Set the parameters to be configured */
Jerome Coutant 1:2371382139dd 370 hdma_tx.Init.Channel = EEPROM_I2C_DMA_CHANNEL;
Jerome Coutant 1:2371382139dd 371 hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
Jerome Coutant 1:2371382139dd 372 hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE;
Jerome Coutant 1:2371382139dd 373 hdma_tx.Init.MemInc = DMA_MINC_ENABLE;
Jerome Coutant 1:2371382139dd 374 hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
Jerome Coutant 1:2371382139dd 375 hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
Jerome Coutant 1:2371382139dd 376 hdma_tx.Init.Mode = DMA_NORMAL;
Jerome Coutant 1:2371382139dd 377 hdma_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
Jerome Coutant 1:2371382139dd 378 hdma_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
Jerome Coutant 1:2371382139dd 379 hdma_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
Jerome Coutant 1:2371382139dd 380 hdma_tx.Init.MemBurst = DMA_MBURST_SINGLE;
Jerome Coutant 1:2371382139dd 381 hdma_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
Jerome Coutant 1:2371382139dd 382
Jerome Coutant 1:2371382139dd 383 /* Associate the initilalized hdma_tx handle to the the pI2cHandle handle */
Jerome Coutant 1:2371382139dd 384 __HAL_LINKDMA(pI2cHandle, hdmatx, hdma_tx);
Jerome Coutant 1:2371382139dd 385
Jerome Coutant 1:2371382139dd 386 /* Configure the DMA Stream */
Jerome Coutant 1:2371382139dd 387 HAL_DMA_Init(&hdma_tx);
Jerome Coutant 1:2371382139dd 388
Jerome Coutant 1:2371382139dd 389 // Added for mbed
Jerome Coutant 1:2371382139dd 390 /* Configure and enable I2C DMA TX Channel interrupt */
Jerome Coutant 1:2371382139dd 391 //HAL_NVIC_SetPriority((IRQn_Type)(EEPROM_I2C_DMA_TX_IRQn), EEPROM_I2C_DMA_PREPRIO, 0);
Jerome Coutant 1:2371382139dd 392 //HAL_NVIC_EnableIRQ((IRQn_Type)(EEPROM_I2C_DMA_TX_IRQn));
Jerome Coutant 1:2371382139dd 393 // Enable interrupt
Jerome Coutant 1:2371382139dd 394 IRQn_Type irqn = (IRQn_Type)(EEPROM_I2C_DMA_TX_IRQn);
Jerome Coutant 1:2371382139dd 395 NVIC_ClearPendingIRQ(irqn);
Jerome Coutant 1:2371382139dd 396 NVIC_DisableIRQ(irqn);
Jerome Coutant 1:2371382139dd 397 NVIC_SetPriority(irqn, EEPROM_I2C_DMA_PREPRIO);
Jerome Coutant 1:2371382139dd 398 NVIC_SetVector(irqn, (uint32_t)EEPROM_I2C_DMA_TX_IRQHandler);
Jerome Coutant 1:2371382139dd 399 NVIC_EnableIRQ(irqn);
Jerome Coutant 1:2371382139dd 400
Jerome Coutant 1:2371382139dd 401 /* Configure the DMA stream for the EE I2C peripheral TX direction */
Jerome Coutant 1:2371382139dd 402 /* Configure the DMA Stream */
Jerome Coutant 1:2371382139dd 403 hdma_rx.Instance = EEPROM_I2C_DMA_STREAM_RX;
Jerome Coutant 1:2371382139dd 404 /* Set the parameters to be configured */
Jerome Coutant 1:2371382139dd 405 hdma_rx.Init.Channel = EEPROM_I2C_DMA_CHANNEL;
Jerome Coutant 1:2371382139dd 406 hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
Jerome Coutant 1:2371382139dd 407 hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE;
Jerome Coutant 1:2371382139dd 408 hdma_rx.Init.MemInc = DMA_MINC_ENABLE;
Jerome Coutant 1:2371382139dd 409 hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
Jerome Coutant 1:2371382139dd 410 hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
Jerome Coutant 1:2371382139dd 411 hdma_rx.Init.Mode = DMA_NORMAL;
Jerome Coutant 1:2371382139dd 412 hdma_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
Jerome Coutant 1:2371382139dd 413 hdma_rx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
Jerome Coutant 1:2371382139dd 414 hdma_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
Jerome Coutant 1:2371382139dd 415 hdma_rx.Init.MemBurst = DMA_MBURST_SINGLE;
Jerome Coutant 1:2371382139dd 416 hdma_rx.Init.PeriphBurst = DMA_PBURST_SINGLE;
Jerome Coutant 1:2371382139dd 417
Jerome Coutant 1:2371382139dd 418 /* Associate the initilalized hdma_rx handle to the the pI2cHandle handle*/
Jerome Coutant 1:2371382139dd 419 __HAL_LINKDMA(pI2cHandle, hdmarx, hdma_rx);
Jerome Coutant 1:2371382139dd 420
Jerome Coutant 1:2371382139dd 421 /* Configure the DMA Stream */
Jerome Coutant 1:2371382139dd 422 HAL_DMA_Init(&hdma_rx);
Jerome Coutant 1:2371382139dd 423
Jerome Coutant 1:2371382139dd 424 // Added for mbed
Jerome Coutant 1:2371382139dd 425 /* Configure and enable I2C DMA RX Channel interrupt */
Jerome Coutant 1:2371382139dd 426 //HAL_NVIC_SetPriority((IRQn_Type)(EEPROM_I2C_DMA_RX_IRQn), EEPROM_I2C_DMA_PREPRIO, 0);
Jerome Coutant 1:2371382139dd 427 //HAL_NVIC_EnableIRQ((IRQn_Type)(EEPROM_I2C_DMA_RX_IRQn));
Jerome Coutant 1:2371382139dd 428 // Enable interrupt
Jerome Coutant 1:2371382139dd 429 irqn = (IRQn_Type)(EEPROM_I2C_DMA_RX_IRQn);
Jerome Coutant 1:2371382139dd 430 NVIC_ClearPendingIRQ(irqn);
Jerome Coutant 1:2371382139dd 431 NVIC_DisableIRQ(irqn);
Jerome Coutant 1:2371382139dd 432 NVIC_SetPriority(irqn, EEPROM_I2C_DMA_PREPRIO);
Jerome Coutant 1:2371382139dd 433 NVIC_SetVector(irqn, (uint32_t)EEPROM_I2C_DMA_RX_IRQHandler);
Jerome Coutant 1:2371382139dd 434 NVIC_EnableIRQ(irqn);
Jerome Coutant 1:2371382139dd 435
Jerome Coutant 1:2371382139dd 436 #endif /* EE_M24LR64 */
Jerome Coutant 1:2371382139dd 437 }
Jerome Coutant 1:2371382139dd 438 }
Jerome Coutant 1:2371382139dd 439
Jerome Coutant 1:2371382139dd 440 /**
Jerome Coutant 1:2371382139dd 441 * @brief I2Cx Bus initialization.
Jerome Coutant 1:2371382139dd 442 */
Jerome Coutant 1:2371382139dd 443 static void I2Cx_Init(void)
Jerome Coutant 1:2371382139dd 444 {
Jerome Coutant 1:2371382139dd 445 if(HAL_I2C_GetState(&EEP_I2cHandle) == HAL_I2C_STATE_RESET)
Jerome Coutant 1:2371382139dd 446 {
Jerome Coutant 1:2371382139dd 447 EEP_I2cHandle.Instance = DISCOVERY_I2Cx;
Jerome Coutant 1:2371382139dd 448 EEP_I2cHandle.Init.ClockSpeed = BSP_I2C_SPEED;
Jerome Coutant 1:2371382139dd 449 EEP_I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
Jerome Coutant 1:2371382139dd 450 EEP_I2cHandle.Init.OwnAddress1 = 0;
Jerome Coutant 1:2371382139dd 451 EEP_I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
Jerome Coutant 1:2371382139dd 452 EEP_I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
Jerome Coutant 1:2371382139dd 453 EEP_I2cHandle.Init.OwnAddress2 = 0;
Jerome Coutant 1:2371382139dd 454 EEP_I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
Jerome Coutant 1:2371382139dd 455 EEP_I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
Jerome Coutant 1:2371382139dd 456
Jerome Coutant 1:2371382139dd 457 /* Init the I2C */
Jerome Coutant 1:2371382139dd 458 I2Cx_MspInit(&EEP_I2cHandle);
Jerome Coutant 1:2371382139dd 459 HAL_I2C_Init(&EEP_I2cHandle);
Jerome Coutant 1:2371382139dd 460 }
Jerome Coutant 1:2371382139dd 461 }
Jerome Coutant 1:2371382139dd 462
Jerome Coutant 1:2371382139dd 463 /**
Jerome Coutant 1:2371382139dd 464 * @brief Configures Interruption pin for I2C communication.
Jerome Coutant 1:2371382139dd 465 */
Jerome Coutant 1:2371382139dd 466 static void I2Cx_ITConfig(void)
Jerome Coutant 1:2371382139dd 467 {
Jerome Coutant 1:2371382139dd 468 GPIO_InitTypeDef GPIO_InitStruct;
Jerome Coutant 1:2371382139dd 469
Jerome Coutant 1:2371382139dd 470 /* Enable the GPIO EXTI Clock */
Jerome Coutant 1:2371382139dd 471 STMPE811_INT_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 472
Jerome Coutant 1:2371382139dd 473 GPIO_InitStruct.Pin = STMPE811_INT_PIN;
Jerome Coutant 1:2371382139dd 474 GPIO_InitStruct.Pull = GPIO_PULLUP;
Jerome Coutant 1:2371382139dd 475 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
Jerome Coutant 1:2371382139dd 476 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
Jerome Coutant 1:2371382139dd 477 HAL_GPIO_Init(STMPE811_INT_GPIO_PORT, &GPIO_InitStruct);
Jerome Coutant 1:2371382139dd 478
Jerome Coutant 1:2371382139dd 479 /* Enable and set GPIO EXTI Interrupt to the highest priority */
Jerome Coutant 1:2371382139dd 480 HAL_NVIC_SetPriority((IRQn_Type)(STMPE811_INT_EXTI), 0x0F, 0x00);
Jerome Coutant 1:2371382139dd 481 HAL_NVIC_EnableIRQ((IRQn_Type)(STMPE811_INT_EXTI));
Jerome Coutant 1:2371382139dd 482 }
Jerome Coutant 1:2371382139dd 483
Jerome Coutant 1:2371382139dd 484 /**
Jerome Coutant 1:2371382139dd 485 * @brief Writes a value in a register of the device through BUS.
Jerome Coutant 1:2371382139dd 486 * @param Addr: Device address on BUS Bus.
Jerome Coutant 1:2371382139dd 487 * @param Reg: The target register address to write
Jerome Coutant 1:2371382139dd 488 * @param Value: The target register value to be written
Jerome Coutant 1:2371382139dd 489 */
Jerome Coutant 1:2371382139dd 490 static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value)
Jerome Coutant 1:2371382139dd 491 {
Jerome Coutant 1:2371382139dd 492 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 1:2371382139dd 493
Jerome Coutant 1:2371382139dd 494 status = HAL_I2C_Mem_Write(&EEP_I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1, I2cxTimeout);
Jerome Coutant 1:2371382139dd 495
Jerome Coutant 1:2371382139dd 496 /* Check the communication status */
Jerome Coutant 1:2371382139dd 497 if(status != HAL_OK)
Jerome Coutant 1:2371382139dd 498 {
Jerome Coutant 1:2371382139dd 499 /* Re-Initialize the BUS */
Jerome Coutant 1:2371382139dd 500 I2Cx_Error();
Jerome Coutant 1:2371382139dd 501 }
Jerome Coutant 1:2371382139dd 502 }
Jerome Coutant 1:2371382139dd 503
Jerome Coutant 1:2371382139dd 504 /**
Jerome Coutant 1:2371382139dd 505 * @brief Writes a value in a register of the device through BUS.
Jerome Coutant 1:2371382139dd 506 * @param Addr: Device address on BUS Bus.
Jerome Coutant 1:2371382139dd 507 * @param Reg: The target register address to write
Jerome Coutant 1:2371382139dd 508 * @param pBuffer: The target register value to be written
Jerome Coutant 1:2371382139dd 509 * @param Length: buffer size to be written
Jerome Coutant 1:2371382139dd 510 */
Jerome Coutant 1:2371382139dd 511 static void I2Cx_WriteBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
Jerome Coutant 1:2371382139dd 512 {
Jerome Coutant 1:2371382139dd 513 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 1:2371382139dd 514
Jerome Coutant 1:2371382139dd 515 status = HAL_I2C_Mem_Write(&EEP_I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Length, I2cxTimeout);
Jerome Coutant 1:2371382139dd 516
Jerome Coutant 1:2371382139dd 517 /* Check the communication status */
Jerome Coutant 1:2371382139dd 518 if(status != HAL_OK)
Jerome Coutant 1:2371382139dd 519 {
Jerome Coutant 1:2371382139dd 520 /* Re-Initialize the BUS */
Jerome Coutant 1:2371382139dd 521 I2Cx_Error();
Jerome Coutant 1:2371382139dd 522 }
Jerome Coutant 1:2371382139dd 523 }
Jerome Coutant 1:2371382139dd 524
Jerome Coutant 1:2371382139dd 525 /**
Jerome Coutant 1:2371382139dd 526 * @brief Reads a register of the device through BUS.
Jerome Coutant 1:2371382139dd 527 * @param Addr: Device address on BUS Bus.
Jerome Coutant 1:2371382139dd 528 * @param Reg: The target register address to write
Jerome Coutant 1:2371382139dd 529 * @retval Data read at register address
Jerome Coutant 1:2371382139dd 530 */
Jerome Coutant 1:2371382139dd 531 static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg)
Jerome Coutant 1:2371382139dd 532 {
Jerome Coutant 1:2371382139dd 533 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 1:2371382139dd 534 uint8_t value = 0;
Jerome Coutant 1:2371382139dd 535
Jerome Coutant 1:2371382139dd 536 status = HAL_I2C_Mem_Read(&EEP_I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &value, 1, I2cxTimeout);
Jerome Coutant 1:2371382139dd 537
Jerome Coutant 1:2371382139dd 538 /* Check the communication status */
Jerome Coutant 1:2371382139dd 539 if(status != HAL_OK)
Jerome Coutant 1:2371382139dd 540 {
Jerome Coutant 1:2371382139dd 541 /* Re-Initialize the BUS */
Jerome Coutant 1:2371382139dd 542 I2Cx_Error();
Jerome Coutant 1:2371382139dd 543
Jerome Coutant 1:2371382139dd 544 }
Jerome Coutant 1:2371382139dd 545 return value;
Jerome Coutant 1:2371382139dd 546 }
Jerome Coutant 1:2371382139dd 547
Jerome Coutant 1:2371382139dd 548 /**
Jerome Coutant 1:2371382139dd 549 * @brief Reads multiple data on the BUS.
Jerome Coutant 1:2371382139dd 550 * @param Addr: I2C Address
Jerome Coutant 1:2371382139dd 551 * @param Reg: Reg Address
Jerome Coutant 1:2371382139dd 552 * @param pBuffer: pointer to read data buffer
Jerome Coutant 1:2371382139dd 553 * @param Length: length of the data
Jerome Coutant 1:2371382139dd 554 * @retval 0 if no problems to read multiple data
Jerome Coutant 1:2371382139dd 555 */
Jerome Coutant 1:2371382139dd 556 static uint8_t I2Cx_ReadBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
Jerome Coutant 1:2371382139dd 557 {
Jerome Coutant 1:2371382139dd 558 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 1:2371382139dd 559
Jerome Coutant 1:2371382139dd 560 status = HAL_I2C_Mem_Read(&EEP_I2cHandle, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer, Length, I2cxTimeout);
Jerome Coutant 1:2371382139dd 561
Jerome Coutant 1:2371382139dd 562 /* Check the communication status */
Jerome Coutant 1:2371382139dd 563 if(status == HAL_OK)
Jerome Coutant 1:2371382139dd 564 {
Jerome Coutant 1:2371382139dd 565 return 0;
Jerome Coutant 1:2371382139dd 566 }
Jerome Coutant 1:2371382139dd 567 else
Jerome Coutant 1:2371382139dd 568 {
Jerome Coutant 1:2371382139dd 569 /* Re-Initialize the BUS */
Jerome Coutant 1:2371382139dd 570 I2Cx_Error();
Jerome Coutant 1:2371382139dd 571
Jerome Coutant 1:2371382139dd 572 return 1;
Jerome Coutant 1:2371382139dd 573 }
Jerome Coutant 1:2371382139dd 574 }
Jerome Coutant 1:2371382139dd 575
Jerome Coutant 1:2371382139dd 576 #ifdef EE_M24LR64
Jerome Coutant 1:2371382139dd 577 /**
Jerome Coutant 1:2371382139dd 578 * @brief Writes a value in a register of the device through BUS in using DMA mode.
Jerome Coutant 1:2371382139dd 579 * @param Addr: Device address on BUS Bus.
Jerome Coutant 1:2371382139dd 580 * @param Reg: The target register address to write
Jerome Coutant 1:2371382139dd 581 * @param pBuffer: The target register value to be written
Jerome Coutant 1:2371382139dd 582 * @param Length: buffer size to be written
Jerome Coutant 1:2371382139dd 583 * @retval HAL status
Jerome Coutant 1:2371382139dd 584 */
Jerome Coutant 1:2371382139dd 585 static HAL_StatusTypeDef I2Cx_WriteBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length)
Jerome Coutant 1:2371382139dd 586 {
Jerome Coutant 1:2371382139dd 587 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 1:2371382139dd 588
Jerome Coutant 1:2371382139dd 589 status = HAL_I2C_Mem_Write_DMA(&EEP_I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_16BIT, pBuffer, Length);
Jerome Coutant 1:2371382139dd 590
Jerome Coutant 1:2371382139dd 591 /* Check the communication status */
Jerome Coutant 1:2371382139dd 592 if(status != HAL_OK)
Jerome Coutant 1:2371382139dd 593 {
Jerome Coutant 1:2371382139dd 594 /* Re-Initialize the BUS */
Jerome Coutant 1:2371382139dd 595 I2Cx_Error();
Jerome Coutant 1:2371382139dd 596 }
Jerome Coutant 1:2371382139dd 597
Jerome Coutant 1:2371382139dd 598 return status;
Jerome Coutant 1:2371382139dd 599 }
Jerome Coutant 1:2371382139dd 600
Jerome Coutant 1:2371382139dd 601 /**
Jerome Coutant 1:2371382139dd 602 * @brief Reads multiple data on the BUS in using DMA mode.
Jerome Coutant 1:2371382139dd 603 * @param Addr: I2C Address
Jerome Coutant 1:2371382139dd 604 * @param Reg: Reg Address
Jerome Coutant 1:2371382139dd 605 * @param pBuffer: pointer to read data buffer
Jerome Coutant 1:2371382139dd 606 * @param Length: length of the data
Jerome Coutant 1:2371382139dd 607 * @retval HAL status
Jerome Coutant 1:2371382139dd 608 */
Jerome Coutant 1:2371382139dd 609 static HAL_StatusTypeDef I2Cx_ReadBufferDMA(uint8_t Addr, uint16_t Reg, uint8_t *pBuffer, uint16_t Length)
Jerome Coutant 1:2371382139dd 610 {
Jerome Coutant 1:2371382139dd 611 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 1:2371382139dd 612
Jerome Coutant 1:2371382139dd 613 status = HAL_I2C_Mem_Read_DMA(&EEP_I2cHandle, Addr, Reg, I2C_MEMADD_SIZE_16BIT, pBuffer, Length);
Jerome Coutant 1:2371382139dd 614
Jerome Coutant 1:2371382139dd 615 /* Check the communication status */
Jerome Coutant 1:2371382139dd 616 if(status != HAL_OK)
Jerome Coutant 1:2371382139dd 617 {
Jerome Coutant 1:2371382139dd 618 /* Re-Initialize the BUS */
Jerome Coutant 1:2371382139dd 619 I2Cx_Error();
Jerome Coutant 1:2371382139dd 620 }
Jerome Coutant 1:2371382139dd 621
Jerome Coutant 1:2371382139dd 622 return status;
Jerome Coutant 1:2371382139dd 623 }
Jerome Coutant 1:2371382139dd 624
Jerome Coutant 1:2371382139dd 625 /**
Jerome Coutant 1:2371382139dd 626 * @brief Checks if target device is ready for communication.
Jerome Coutant 1:2371382139dd 627 * @note This function is used with Memory devices
Jerome Coutant 1:2371382139dd 628 * @param DevAddress: Target device address
Jerome Coutant 1:2371382139dd 629 * @param Trials: Number of trials
Jerome Coutant 1:2371382139dd 630 * @retval HAL status
Jerome Coutant 1:2371382139dd 631 */
Jerome Coutant 1:2371382139dd 632 static HAL_StatusTypeDef I2Cx_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
Jerome Coutant 1:2371382139dd 633 {
Jerome Coutant 1:2371382139dd 634 return (HAL_I2C_IsDeviceReady(&EEP_I2cHandle, DevAddress, Trials, I2cxTimeout));
Jerome Coutant 1:2371382139dd 635 }
Jerome Coutant 1:2371382139dd 636 #endif /* EE_M24LR64 */
Jerome Coutant 1:2371382139dd 637
Jerome Coutant 1:2371382139dd 638 /**
Jerome Coutant 1:2371382139dd 639 * @brief I2Cx error treatment function
Jerome Coutant 1:2371382139dd 640 */
Jerome Coutant 1:2371382139dd 641 static void I2Cx_Error(void)
Jerome Coutant 1:2371382139dd 642 {
Jerome Coutant 1:2371382139dd 643 /* De-initialize the I2C communication BUS */
Jerome Coutant 1:2371382139dd 644 HAL_I2C_DeInit(&EEP_I2cHandle);
Jerome Coutant 1:2371382139dd 645
Jerome Coutant 1:2371382139dd 646 /* Re-Initialize the I2C communication BUS */
Jerome Coutant 1:2371382139dd 647 I2Cx_Init();
Jerome Coutant 1:2371382139dd 648 }
Jerome Coutant 1:2371382139dd 649
Jerome Coutant 1:2371382139dd 650 /******************************* SPI Routines *********************************/
Jerome Coutant 1:2371382139dd 651
Jerome Coutant 1:2371382139dd 652 /**
Jerome Coutant 1:2371382139dd 653 * @brief SPIx Bus initialization
Jerome Coutant 1:2371382139dd 654 */
Jerome Coutant 1:2371382139dd 655 static void SPIx_Init(void)
Jerome Coutant 1:2371382139dd 656 {
Jerome Coutant 1:2371382139dd 657 if(HAL_SPI_GetState(&SpiHandle) == HAL_SPI_STATE_RESET)
Jerome Coutant 1:2371382139dd 658 {
Jerome Coutant 1:2371382139dd 659 /* SPI configuration -----------------------------------------------------*/
Jerome Coutant 1:2371382139dd 660 SpiHandle.Instance = DISCOVERY_SPIx;
Jerome Coutant 1:2371382139dd 661 /* SPI baudrate is set to 5.6 MHz (PCLK2/SPI_BaudRatePrescaler = 90/16 = 5.625 MHz)
Jerome Coutant 1:2371382139dd 662 to verify these constraints:
Jerome Coutant 1:2371382139dd 663 - ILI9341 LCD SPI interface max baudrate is 10MHz for write and 6.66MHz for read
Jerome Coutant 1:2371382139dd 664 - l3gd20 SPI interface max baudrate is 10MHz for write/read
Jerome Coutant 1:2371382139dd 665 - PCLK2 frequency is set to 90 MHz
Jerome Coutant 1:2371382139dd 666 */
Jerome Coutant 1:2371382139dd 667 SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
Jerome Coutant 1:2371382139dd 668
Jerome Coutant 1:2371382139dd 669 /* On STM32F429I-Discovery, LCD ID cannot be read then keep a common configuration */
Jerome Coutant 1:2371382139dd 670 /* for LCD and GYRO (SPI_DIRECTION_2LINES) */
Jerome Coutant 1:2371382139dd 671 /* Note: To read a register a LCD, SPI_DIRECTION_1LINE should be set */
Jerome Coutant 1:2371382139dd 672 SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;
Jerome Coutant 1:2371382139dd 673 SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
Jerome Coutant 1:2371382139dd 674 SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
Jerome Coutant 1:2371382139dd 675 SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
Jerome Coutant 1:2371382139dd 676 SpiHandle.Init.CRCPolynomial = 7;
Jerome Coutant 1:2371382139dd 677 SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
Jerome Coutant 1:2371382139dd 678 SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;
Jerome Coutant 1:2371382139dd 679 SpiHandle.Init.NSS = SPI_NSS_SOFT;
Jerome Coutant 1:2371382139dd 680 SpiHandle.Init.TIMode = SPI_TIMODE_DISABLED;
Jerome Coutant 1:2371382139dd 681 SpiHandle.Init.Mode = SPI_MODE_MASTER;
Jerome Coutant 1:2371382139dd 682
Jerome Coutant 1:2371382139dd 683 SPIx_MspInit(&SpiHandle);
Jerome Coutant 1:2371382139dd 684 HAL_SPI_Init(&SpiHandle);
Jerome Coutant 1:2371382139dd 685 }
Jerome Coutant 1:2371382139dd 686 }
Jerome Coutant 1:2371382139dd 687
Jerome Coutant 1:2371382139dd 688 /**
Jerome Coutant 1:2371382139dd 689 * @brief Reads 4 bytes from device.
Jerome Coutant 1:2371382139dd 690 * @param ReadSize: Number of bytes to read (max 4 bytes)
Jerome Coutant 1:2371382139dd 691 * @retval Value read on the SPI
Jerome Coutant 1:2371382139dd 692 */
Jerome Coutant 1:2371382139dd 693 static uint32_t SPIx_Read(uint8_t ReadSize)
Jerome Coutant 1:2371382139dd 694 {
Jerome Coutant 1:2371382139dd 695 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 1:2371382139dd 696 uint32_t readvalue;
Jerome Coutant 1:2371382139dd 697
Jerome Coutant 1:2371382139dd 698 status = HAL_SPI_Receive(&SpiHandle, (uint8_t*) &readvalue, ReadSize, SpixTimeout);
Jerome Coutant 1:2371382139dd 699
Jerome Coutant 1:2371382139dd 700 /* Check the communication status */
Jerome Coutant 1:2371382139dd 701 if(status != HAL_OK)
Jerome Coutant 1:2371382139dd 702 {
Jerome Coutant 1:2371382139dd 703 /* Re-Initialize the BUS */
Jerome Coutant 1:2371382139dd 704 SPIx_Error();
Jerome Coutant 1:2371382139dd 705 }
Jerome Coutant 1:2371382139dd 706
Jerome Coutant 1:2371382139dd 707 return readvalue;
Jerome Coutant 1:2371382139dd 708 }
Jerome Coutant 1:2371382139dd 709
Jerome Coutant 1:2371382139dd 710 /**
Jerome Coutant 1:2371382139dd 711 * @brief Writes a byte to device.
Jerome Coutant 1:2371382139dd 712 * @param Value: value to be written
Jerome Coutant 1:2371382139dd 713 */
Jerome Coutant 1:2371382139dd 714 static void SPIx_Write(uint16_t Value)
Jerome Coutant 1:2371382139dd 715 {
Jerome Coutant 1:2371382139dd 716 HAL_StatusTypeDef status = HAL_OK;
Jerome Coutant 1:2371382139dd 717
Jerome Coutant 1:2371382139dd 718 status = HAL_SPI_Transmit(&SpiHandle, (uint8_t*) &Value, 1, SpixTimeout);
Jerome Coutant 1:2371382139dd 719
Jerome Coutant 1:2371382139dd 720 /* Check the communication status */
Jerome Coutant 1:2371382139dd 721 if(status != HAL_OK)
Jerome Coutant 1:2371382139dd 722 {
Jerome Coutant 1:2371382139dd 723 /* Re-Initialize the BUS */
Jerome Coutant 1:2371382139dd 724 SPIx_Error();
Jerome Coutant 1:2371382139dd 725 }
Jerome Coutant 1:2371382139dd 726 }
Jerome Coutant 1:2371382139dd 727
Jerome Coutant 1:2371382139dd 728 /**
Jerome Coutant 1:2371382139dd 729 * @brief Sends a Byte through the SPI interface and return the Byte received
Jerome Coutant 1:2371382139dd 730 * from the SPI bus.
Jerome Coutant 1:2371382139dd 731 * @param Byte: Byte send.
Jerome Coutant 1:2371382139dd 732 * @retval The received byte value
Jerome Coutant 1:2371382139dd 733 */
Jerome Coutant 1:2371382139dd 734 static uint8_t SPIx_WriteRead(uint8_t Byte)
Jerome Coutant 1:2371382139dd 735 {
Jerome Coutant 1:2371382139dd 736 uint8_t receivedbyte = 0;
Jerome Coutant 1:2371382139dd 737
Jerome Coutant 1:2371382139dd 738 /* Send a Byte through the SPI peripheral */
Jerome Coutant 1:2371382139dd 739 /* Read byte from the SPI bus */
Jerome Coutant 1:2371382139dd 740 if(HAL_SPI_TransmitReceive(&SpiHandle, (uint8_t*) &Byte, (uint8_t*) &receivedbyte, 1, SpixTimeout) != HAL_OK)
Jerome Coutant 1:2371382139dd 741 {
Jerome Coutant 1:2371382139dd 742 SPIx_Error();
Jerome Coutant 1:2371382139dd 743 }
Jerome Coutant 1:2371382139dd 744
Jerome Coutant 1:2371382139dd 745 return receivedbyte;
Jerome Coutant 1:2371382139dd 746 }
Jerome Coutant 1:2371382139dd 747
Jerome Coutant 1:2371382139dd 748 /**
Jerome Coutant 1:2371382139dd 749 * @brief SPIx error treatment function.
Jerome Coutant 1:2371382139dd 750 */
Jerome Coutant 1:2371382139dd 751 static void SPIx_Error(void)
Jerome Coutant 1:2371382139dd 752 {
Jerome Coutant 1:2371382139dd 753 /* De-initialize the SPI communication BUS */
Jerome Coutant 1:2371382139dd 754 HAL_SPI_DeInit(&SpiHandle);
Jerome Coutant 1:2371382139dd 755
Jerome Coutant 1:2371382139dd 756 /* Re- Initialize the SPI communication BUS */
Jerome Coutant 1:2371382139dd 757 SPIx_Init();
Jerome Coutant 1:2371382139dd 758 }
Jerome Coutant 1:2371382139dd 759
Jerome Coutant 1:2371382139dd 760 /**
Jerome Coutant 1:2371382139dd 761 * @brief SPI MSP Init.
Jerome Coutant 1:2371382139dd 762 * @param hspi: SPI handle
Jerome Coutant 1:2371382139dd 763 */
Jerome Coutant 1:2371382139dd 764 static void SPIx_MspInit(SPI_HandleTypeDef *hspi)
Jerome Coutant 1:2371382139dd 765 {
Jerome Coutant 1:2371382139dd 766 GPIO_InitTypeDef GPIO_InitStructure;
Jerome Coutant 1:2371382139dd 767
Jerome Coutant 1:2371382139dd 768 /* Enable SPIx clock */
Jerome Coutant 1:2371382139dd 769 DISCOVERY_SPIx_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 770
Jerome Coutant 1:2371382139dd 771 /* Enable DISCOVERY_SPI GPIO clock */
Jerome Coutant 1:2371382139dd 772 DISCOVERY_SPIx_GPIO_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 773
Jerome Coutant 1:2371382139dd 774 /* configure SPI SCK, MOSI and MISO */
Jerome Coutant 1:2371382139dd 775 GPIO_InitStructure.Pin = (DISCOVERY_SPIx_SCK_PIN | DISCOVERY_SPIx_MOSI_PIN | DISCOVERY_SPIx_MISO_PIN);
Jerome Coutant 1:2371382139dd 776 GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
Jerome Coutant 1:2371382139dd 777 GPIO_InitStructure.Pull = GPIO_PULLDOWN;
Jerome Coutant 1:2371382139dd 778 GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
Jerome Coutant 1:2371382139dd 779 GPIO_InitStructure.Alternate = DISCOVERY_SPIx_AF;
Jerome Coutant 1:2371382139dd 780 HAL_GPIO_Init(DISCOVERY_SPIx_GPIO_PORT, &GPIO_InitStructure);
Jerome Coutant 1:2371382139dd 781 }
Jerome Coutant 1:2371382139dd 782
Jerome Coutant 1:2371382139dd 783 /********************************* LINK LCD ***********************************/
Jerome Coutant 1:2371382139dd 784
Jerome Coutant 1:2371382139dd 785 /**
Jerome Coutant 1:2371382139dd 786 * @brief Configures the LCD_SPI interface.
Jerome Coutant 1:2371382139dd 787 */
Jerome Coutant 1:2371382139dd 788 void LCD_IO_Init(void)
Jerome Coutant 1:2371382139dd 789 {
Jerome Coutant 1:2371382139dd 790 GPIO_InitTypeDef GPIO_InitStructure;
Jerome Coutant 1:2371382139dd 791
Jerome Coutant 1:2371382139dd 792 if(Is_LCD_IO_Initialized == 0)
Jerome Coutant 1:2371382139dd 793 {
Jerome Coutant 1:2371382139dd 794 Is_LCD_IO_Initialized = 1;
Jerome Coutant 1:2371382139dd 795
Jerome Coutant 1:2371382139dd 796 /* Configure NCS in Output Push-Pull mode */
Jerome Coutant 1:2371382139dd 797 LCD_WRX_GPIO_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 798 GPIO_InitStructure.Pin = LCD_WRX_PIN;
Jerome Coutant 1:2371382139dd 799 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
Jerome Coutant 1:2371382139dd 800 GPIO_InitStructure.Pull = GPIO_NOPULL;
Jerome Coutant 1:2371382139dd 801 GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
Jerome Coutant 1:2371382139dd 802 HAL_GPIO_Init(LCD_WRX_GPIO_PORT, &GPIO_InitStructure);
Jerome Coutant 1:2371382139dd 803
Jerome Coutant 1:2371382139dd 804 LCD_RDX_GPIO_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 805 GPIO_InitStructure.Pin = LCD_RDX_PIN;
Jerome Coutant 1:2371382139dd 806 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
Jerome Coutant 1:2371382139dd 807 GPIO_InitStructure.Pull = GPIO_NOPULL;
Jerome Coutant 1:2371382139dd 808 GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
Jerome Coutant 1:2371382139dd 809 HAL_GPIO_Init(LCD_RDX_GPIO_PORT, &GPIO_InitStructure);
Jerome Coutant 1:2371382139dd 810
Jerome Coutant 1:2371382139dd 811 /* Configure the LCD Control pins ----------------------------------------*/
Jerome Coutant 1:2371382139dd 812 LCD_NCS_GPIO_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 813
Jerome Coutant 1:2371382139dd 814 /* Configure NCS in Output Push-Pull mode */
Jerome Coutant 1:2371382139dd 815 GPIO_InitStructure.Pin = LCD_NCS_PIN;
Jerome Coutant 1:2371382139dd 816 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
Jerome Coutant 1:2371382139dd 817 GPIO_InitStructure.Pull = GPIO_NOPULL;
Jerome Coutant 1:2371382139dd 818 GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
Jerome Coutant 1:2371382139dd 819 HAL_GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
Jerome Coutant 1:2371382139dd 820
Jerome Coutant 1:2371382139dd 821 /* Set or Reset the control line */
Jerome Coutant 1:2371382139dd 822 LCD_CS_LOW();
Jerome Coutant 1:2371382139dd 823 LCD_CS_HIGH();
Jerome Coutant 1:2371382139dd 824
Jerome Coutant 1:2371382139dd 825 SPIx_Init();
Jerome Coutant 1:2371382139dd 826 }
Jerome Coutant 1:2371382139dd 827 }
Jerome Coutant 1:2371382139dd 828
Jerome Coutant 1:2371382139dd 829 /**
Jerome Coutant 1:2371382139dd 830 * @brief Writes register value.
Jerome Coutant 1:2371382139dd 831 */
Jerome Coutant 1:2371382139dd 832 void LCD_IO_WriteData(uint16_t RegValue)
Jerome Coutant 1:2371382139dd 833 {
Jerome Coutant 1:2371382139dd 834 /* Set WRX to send data */
Jerome Coutant 1:2371382139dd 835 LCD_WRX_HIGH();
Jerome Coutant 1:2371382139dd 836
Jerome Coutant 1:2371382139dd 837 /* Reset LCD control line(/CS) and Send data */
Jerome Coutant 1:2371382139dd 838 LCD_CS_LOW();
Jerome Coutant 1:2371382139dd 839 SPIx_Write(RegValue);
Jerome Coutant 1:2371382139dd 840
Jerome Coutant 1:2371382139dd 841 /* Deselect: Chip Select high */
Jerome Coutant 1:2371382139dd 842 LCD_CS_HIGH();
Jerome Coutant 1:2371382139dd 843 }
Jerome Coutant 1:2371382139dd 844
Jerome Coutant 1:2371382139dd 845 /**
Jerome Coutant 1:2371382139dd 846 * @brief Writes register address.
Jerome Coutant 1:2371382139dd 847 */
Jerome Coutant 1:2371382139dd 848 void LCD_IO_WriteReg(uint8_t Reg)
Jerome Coutant 1:2371382139dd 849 {
Jerome Coutant 1:2371382139dd 850 /* Reset WRX to send command */
Jerome Coutant 1:2371382139dd 851 LCD_WRX_LOW();
Jerome Coutant 1:2371382139dd 852
Jerome Coutant 1:2371382139dd 853 /* Reset LCD control line(/CS) and Send command */
Jerome Coutant 1:2371382139dd 854 LCD_CS_LOW();
Jerome Coutant 1:2371382139dd 855 SPIx_Write(Reg);
Jerome Coutant 1:2371382139dd 856
Jerome Coutant 1:2371382139dd 857 /* Deselect: Chip Select high */
Jerome Coutant 1:2371382139dd 858 LCD_CS_HIGH();
Jerome Coutant 1:2371382139dd 859 }
Jerome Coutant 1:2371382139dd 860
Jerome Coutant 1:2371382139dd 861 /**
Jerome Coutant 1:2371382139dd 862 * @brief Reads register value.
Jerome Coutant 1:2371382139dd 863 * @param RegValue Address of the register to read
Jerome Coutant 1:2371382139dd 864 * @param ReadSize Number of bytes to read
Jerome Coutant 1:2371382139dd 865 * @retval Content of the register value
Jerome Coutant 1:2371382139dd 866 */
Jerome Coutant 1:2371382139dd 867 uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize)
Jerome Coutant 1:2371382139dd 868 {
Jerome Coutant 1:2371382139dd 869 uint32_t readvalue = 0;
Jerome Coutant 1:2371382139dd 870
Jerome Coutant 1:2371382139dd 871 /* Select: Chip Select low */
Jerome Coutant 1:2371382139dd 872 LCD_CS_LOW();
Jerome Coutant 1:2371382139dd 873
Jerome Coutant 1:2371382139dd 874 /* Reset WRX to send command */
Jerome Coutant 1:2371382139dd 875 LCD_WRX_LOW();
Jerome Coutant 1:2371382139dd 876
Jerome Coutant 1:2371382139dd 877 SPIx_Write(RegValue);
Jerome Coutant 1:2371382139dd 878
Jerome Coutant 1:2371382139dd 879 readvalue = SPIx_Read(ReadSize);
Jerome Coutant 1:2371382139dd 880
Jerome Coutant 1:2371382139dd 881 /* Set WRX to send data */
Jerome Coutant 1:2371382139dd 882 LCD_WRX_HIGH();
Jerome Coutant 1:2371382139dd 883
Jerome Coutant 1:2371382139dd 884 /* Deselect: Chip Select high */
Jerome Coutant 1:2371382139dd 885 LCD_CS_HIGH();
Jerome Coutant 1:2371382139dd 886
Jerome Coutant 1:2371382139dd 887 return readvalue;
Jerome Coutant 1:2371382139dd 888 }
Jerome Coutant 1:2371382139dd 889
Jerome Coutant 1:2371382139dd 890 /**
Jerome Coutant 1:2371382139dd 891 * @brief Wait for loop in ms.
Jerome Coutant 1:2371382139dd 892 * @param Delay in ms.
Jerome Coutant 1:2371382139dd 893 */
Jerome Coutant 1:2371382139dd 894 void LCD_Delay(uint32_t Delay)
Jerome Coutant 1:2371382139dd 895 {
Jerome Coutant 1:2371382139dd 896 //HAL_Delay(Delay);
Jerome Coutant 1:2371382139dd 897 wait_ms(Delay);
Jerome Coutant 1:2371382139dd 898 }
Jerome Coutant 1:2371382139dd 899
Jerome Coutant 1:2371382139dd 900 /*******************************************************************************
Jerome Coutant 1:2371382139dd 901 LINK OPERATIONS
Jerome Coutant 1:2371382139dd 902 *******************************************************************************/
Jerome Coutant 1:2371382139dd 903
Jerome Coutant 1:2371382139dd 904 /********************************* LINK IOE ***********************************/
Jerome Coutant 1:2371382139dd 905
Jerome Coutant 1:2371382139dd 906 /**
Jerome Coutant 1:2371382139dd 907 * @brief IOE Low Level Initialization.
Jerome Coutant 1:2371382139dd 908 */
Jerome Coutant 1:2371382139dd 909 void IOE_Init(void)
Jerome Coutant 1:2371382139dd 910 {
Jerome Coutant 1:2371382139dd 911 I2Cx_Init();
Jerome Coutant 1:2371382139dd 912 }
Jerome Coutant 1:2371382139dd 913
Jerome Coutant 1:2371382139dd 914 /**
Jerome Coutant 1:2371382139dd 915 * @brief IOE Low Level Interrupt configuration.
Jerome Coutant 1:2371382139dd 916 */
Jerome Coutant 1:2371382139dd 917 void IOE_ITConfig(void)
Jerome Coutant 1:2371382139dd 918 {
Jerome Coutant 1:2371382139dd 919 I2Cx_ITConfig();
Jerome Coutant 1:2371382139dd 920 }
Jerome Coutant 1:2371382139dd 921
Jerome Coutant 1:2371382139dd 922 /**
Jerome Coutant 1:2371382139dd 923 * @brief IOE Writes single data operation.
Jerome Coutant 1:2371382139dd 924 * @param Addr: I2C Address
Jerome Coutant 1:2371382139dd 925 * @param Reg: Reg Address
Jerome Coutant 1:2371382139dd 926 * @param Value: Data to be written
Jerome Coutant 1:2371382139dd 927 */
Jerome Coutant 1:2371382139dd 928 void IOE_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
Jerome Coutant 1:2371382139dd 929 {
Jerome Coutant 1:2371382139dd 930 I2Cx_WriteData(Addr, Reg, Value);
Jerome Coutant 1:2371382139dd 931 }
Jerome Coutant 1:2371382139dd 932
Jerome Coutant 1:2371382139dd 933 /**
Jerome Coutant 1:2371382139dd 934 * @brief IOE Reads single data.
Jerome Coutant 1:2371382139dd 935 * @param Addr: I2C Address
Jerome Coutant 1:2371382139dd 936 * @param Reg: Reg Address
Jerome Coutant 1:2371382139dd 937 * @retval The read data
Jerome Coutant 1:2371382139dd 938 */
Jerome Coutant 1:2371382139dd 939 uint8_t IOE_Read(uint8_t Addr, uint8_t Reg)
Jerome Coutant 1:2371382139dd 940 {
Jerome Coutant 1:2371382139dd 941 return I2Cx_ReadData(Addr, Reg);
Jerome Coutant 1:2371382139dd 942 }
Jerome Coutant 1:2371382139dd 943
Jerome Coutant 1:2371382139dd 944 /**
Jerome Coutant 1:2371382139dd 945 * @brief IOE Writes multiple data.
Jerome Coutant 1:2371382139dd 946 * @param Addr: I2C Address
Jerome Coutant 1:2371382139dd 947 * @param Reg: Reg Address
Jerome Coutant 1:2371382139dd 948 * @param pBuffer: pointer to data buffer
Jerome Coutant 1:2371382139dd 949 * @param Length: length of the data
Jerome Coutant 1:2371382139dd 950 */
Jerome Coutant 1:2371382139dd 951 void IOE_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
Jerome Coutant 1:2371382139dd 952 {
Jerome Coutant 1:2371382139dd 953 I2Cx_WriteBuffer(Addr, Reg, pBuffer, Length);
Jerome Coutant 1:2371382139dd 954 }
Jerome Coutant 1:2371382139dd 955
Jerome Coutant 1:2371382139dd 956 /**
Jerome Coutant 1:2371382139dd 957 * @brief IOE Reads multiple data.
Jerome Coutant 1:2371382139dd 958 * @param Addr: I2C Address
Jerome Coutant 1:2371382139dd 959 * @param Reg: Reg Address
Jerome Coutant 1:2371382139dd 960 * @param pBuffer: pointer to data buffer
Jerome Coutant 1:2371382139dd 961 * @param Length: length of the data
Jerome Coutant 1:2371382139dd 962 * @retval 0 if no problems to read multiple data
Jerome Coutant 1:2371382139dd 963 */
Jerome Coutant 1:2371382139dd 964 uint16_t IOE_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
Jerome Coutant 1:2371382139dd 965 {
Jerome Coutant 1:2371382139dd 966 return I2Cx_ReadBuffer(Addr, Reg, pBuffer, Length);
Jerome Coutant 1:2371382139dd 967 }
Jerome Coutant 1:2371382139dd 968
Jerome Coutant 1:2371382139dd 969 /**
Jerome Coutant 1:2371382139dd 970 * @brief IOE Delay.
Jerome Coutant 1:2371382139dd 971 * @param Delay in ms
Jerome Coutant 1:2371382139dd 972 */
Jerome Coutant 1:2371382139dd 973 void IOE_Delay(uint32_t Delay)
Jerome Coutant 1:2371382139dd 974 {
Jerome Coutant 1:2371382139dd 975 //HAL_Delay(Delay);
Jerome Coutant 1:2371382139dd 976 wait_ms(Delay);
Jerome Coutant 1:2371382139dd 977 }
Jerome Coutant 1:2371382139dd 978
Jerome Coutant 1:2371382139dd 979 /********************************* LINK GYROSCOPE *****************************/
Jerome Coutant 1:2371382139dd 980
Jerome Coutant 1:2371382139dd 981 /**
Jerome Coutant 1:2371382139dd 982 * @brief Configures the Gyroscope SPI interface.
Jerome Coutant 1:2371382139dd 983 */
Jerome Coutant 1:2371382139dd 984 void GYRO_IO_Init(void)
Jerome Coutant 1:2371382139dd 985 {
Jerome Coutant 1:2371382139dd 986 GPIO_InitTypeDef GPIO_InitStructure;
Jerome Coutant 1:2371382139dd 987
Jerome Coutant 1:2371382139dd 988 /* Configure the Gyroscope Control pins ------------------------------------*/
Jerome Coutant 1:2371382139dd 989 /* Enable CS GPIO clock and Configure GPIO PIN for Gyroscope Chip select */
Jerome Coutant 1:2371382139dd 990 GYRO_CS_GPIO_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 991 GPIO_InitStructure.Pin = GYRO_CS_PIN;
Jerome Coutant 1:2371382139dd 992 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
Jerome Coutant 1:2371382139dd 993 GPIO_InitStructure.Pull = GPIO_NOPULL;
Jerome Coutant 1:2371382139dd 994 GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
Jerome Coutant 1:2371382139dd 995 HAL_GPIO_Init(GYRO_CS_GPIO_PORT, &GPIO_InitStructure);
Jerome Coutant 1:2371382139dd 996
Jerome Coutant 1:2371382139dd 997 /* Deselect: Chip Select high */
Jerome Coutant 1:2371382139dd 998 GYRO_CS_HIGH();
Jerome Coutant 1:2371382139dd 999
Jerome Coutant 1:2371382139dd 1000 /* Enable INT1, INT2 GPIO clock and Configure GPIO PINs to detect Interrupts */
Jerome Coutant 1:2371382139dd 1001 GYRO_INT_GPIO_CLK_ENABLE();
Jerome Coutant 1:2371382139dd 1002 GPIO_InitStructure.Pin = GYRO_INT1_PIN | GYRO_INT2_PIN;
Jerome Coutant 1:2371382139dd 1003 GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
Jerome Coutant 1:2371382139dd 1004 GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
Jerome Coutant 1:2371382139dd 1005 GPIO_InitStructure.Pull= GPIO_NOPULL;
Jerome Coutant 1:2371382139dd 1006 HAL_GPIO_Init(GYRO_INT_GPIO_PORT, &GPIO_InitStructure);
Jerome Coutant 1:2371382139dd 1007
Jerome Coutant 1:2371382139dd 1008 SPIx_Init();
Jerome Coutant 1:2371382139dd 1009 }
Jerome Coutant 1:2371382139dd 1010
Jerome Coutant 1:2371382139dd 1011 /**
Jerome Coutant 1:2371382139dd 1012 * @brief Writes one byte to the Gyroscope.
Jerome Coutant 1:2371382139dd 1013 * @param pBuffer: Pointer to the buffer containing the data to be written to the Gyroscope.
Jerome Coutant 1:2371382139dd 1014 * @param WriteAddr: Gyroscope's internal address to write to.
Jerome Coutant 1:2371382139dd 1015 * @param NumByteToWrite: Number of bytes to write.
Jerome Coutant 1:2371382139dd 1016 */
Jerome Coutant 1:2371382139dd 1017 void GYRO_IO_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite)
Jerome Coutant 1:2371382139dd 1018 {
Jerome Coutant 1:2371382139dd 1019 /* Configure the MS bit:
Jerome Coutant 1:2371382139dd 1020 - When 0, the address will remain unchanged in multiple read/write commands.
Jerome Coutant 1:2371382139dd 1021 - When 1, the address will be auto incremented in multiple read/write commands.
Jerome Coutant 1:2371382139dd 1022 */
Jerome Coutant 1:2371382139dd 1023 if(NumByteToWrite > 0x01)
Jerome Coutant 1:2371382139dd 1024 {
Jerome Coutant 1:2371382139dd 1025 WriteAddr |= (uint8_t)MULTIPLEBYTE_CMD;
Jerome Coutant 1:2371382139dd 1026 }
Jerome Coutant 1:2371382139dd 1027 /* Set chip select Low at the start of the transmission */
Jerome Coutant 1:2371382139dd 1028 GYRO_CS_LOW();
Jerome Coutant 1:2371382139dd 1029
Jerome Coutant 1:2371382139dd 1030 /* Send the Address of the indexed register */
Jerome Coutant 1:2371382139dd 1031 SPIx_WriteRead(WriteAddr);
Jerome Coutant 1:2371382139dd 1032
Jerome Coutant 1:2371382139dd 1033 /* Send the data that will be written into the device (MSB First) */
Jerome Coutant 1:2371382139dd 1034 while(NumByteToWrite >= 0x01)
Jerome Coutant 1:2371382139dd 1035 {
Jerome Coutant 1:2371382139dd 1036 SPIx_WriteRead(*pBuffer);
Jerome Coutant 1:2371382139dd 1037 NumByteToWrite--;
Jerome Coutant 1:2371382139dd 1038 pBuffer++;
Jerome Coutant 1:2371382139dd 1039 }
Jerome Coutant 1:2371382139dd 1040
Jerome Coutant 1:2371382139dd 1041 /* Set chip select High at the end of the transmission */
Jerome Coutant 1:2371382139dd 1042 GYRO_CS_HIGH();
Jerome Coutant 1:2371382139dd 1043 }
Jerome Coutant 1:2371382139dd 1044
Jerome Coutant 1:2371382139dd 1045 /**
Jerome Coutant 1:2371382139dd 1046 * @brief Reads a block of data from the Gyroscope.
Jerome Coutant 1:2371382139dd 1047 * @param pBuffer: Pointer to the buffer that receives the data read from the Gyroscope.
Jerome Coutant 1:2371382139dd 1048 * @param ReadAddr: Gyroscope's internal address to read from.
Jerome Coutant 1:2371382139dd 1049 * @param NumByteToRead: Number of bytes to read from the Gyroscope.
Jerome Coutant 1:2371382139dd 1050 */
Jerome Coutant 1:2371382139dd 1051 void GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead)
Jerome Coutant 1:2371382139dd 1052 {
Jerome Coutant 1:2371382139dd 1053 if(NumByteToRead > 0x01)
Jerome Coutant 1:2371382139dd 1054 {
Jerome Coutant 1:2371382139dd 1055 ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD);
Jerome Coutant 1:2371382139dd 1056 }
Jerome Coutant 1:2371382139dd 1057 else
Jerome Coutant 1:2371382139dd 1058 {
Jerome Coutant 1:2371382139dd 1059 ReadAddr |= (uint8_t)READWRITE_CMD;
Jerome Coutant 1:2371382139dd 1060 }
Jerome Coutant 1:2371382139dd 1061 /* Set chip select Low at the start of the transmission */
Jerome Coutant 1:2371382139dd 1062 GYRO_CS_LOW();
Jerome Coutant 1:2371382139dd 1063
Jerome Coutant 1:2371382139dd 1064 /* Send the Address of the indexed register */
Jerome Coutant 1:2371382139dd 1065 SPIx_WriteRead(ReadAddr);
Jerome Coutant 1:2371382139dd 1066
Jerome Coutant 1:2371382139dd 1067 /* Receive the data that will be read from the device (MSB First) */
Jerome Coutant 1:2371382139dd 1068 while(NumByteToRead > 0x00)
Jerome Coutant 1:2371382139dd 1069 {
Jerome Coutant 1:2371382139dd 1070 /* Send dummy byte (0x00) to generate the SPI clock to Gyroscope (Slave device) */
Jerome Coutant 1:2371382139dd 1071 *pBuffer = SPIx_WriteRead(DUMMY_BYTE);
Jerome Coutant 1:2371382139dd 1072 NumByteToRead--;
Jerome Coutant 1:2371382139dd 1073 pBuffer++;
Jerome Coutant 1:2371382139dd 1074 }
Jerome Coutant 1:2371382139dd 1075
Jerome Coutant 1:2371382139dd 1076 /* Set chip select High at the end of the transmission */
Jerome Coutant 1:2371382139dd 1077 GYRO_CS_HIGH();
Jerome Coutant 1:2371382139dd 1078 }
Jerome Coutant 1:2371382139dd 1079
Jerome Coutant 1:2371382139dd 1080
Jerome Coutant 1:2371382139dd 1081 #ifdef EE_M24LR64
Jerome Coutant 1:2371382139dd 1082
Jerome Coutant 1:2371382139dd 1083 /******************************** LINK I2C EEPROM *****************************/
Jerome Coutant 1:2371382139dd 1084
Jerome Coutant 1:2371382139dd 1085 /**
Jerome Coutant 1:2371382139dd 1086 * @brief Initializes peripherals used by the I2C EEPROM driver.
Jerome Coutant 1:2371382139dd 1087 */
Jerome Coutant 1:2371382139dd 1088 void EEPROM_IO_Init(void)
Jerome Coutant 1:2371382139dd 1089 {
Jerome Coutant 1:2371382139dd 1090 I2Cx_Init();
Jerome Coutant 1:2371382139dd 1091 }
Jerome Coutant 1:2371382139dd 1092
Jerome Coutant 1:2371382139dd 1093 /**
Jerome Coutant 1:2371382139dd 1094 * @brief Writes data to I2C EEPROM driver in using DMA channel.
Jerome Coutant 1:2371382139dd 1095 * @param DevAddress: Target device address
Jerome Coutant 1:2371382139dd 1096 * @param MemAddress: Internal memory address
Jerome Coutant 1:2371382139dd 1097 * @param pBuffer: Pointer to data buffer
Jerome Coutant 1:2371382139dd 1098 * @param BufferSize: Amount of data to be sent
Jerome Coutant 1:2371382139dd 1099 * @retval HAL status
Jerome Coutant 1:2371382139dd 1100 */
Jerome Coutant 1:2371382139dd 1101 HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
Jerome Coutant 1:2371382139dd 1102 {
Jerome Coutant 1:2371382139dd 1103 return (I2Cx_WriteBufferDMA(DevAddress, MemAddress, pBuffer, BufferSize));
Jerome Coutant 1:2371382139dd 1104 }
Jerome Coutant 1:2371382139dd 1105
Jerome Coutant 1:2371382139dd 1106 /**
Jerome Coutant 1:2371382139dd 1107 * @brief Reads data from I2C EEPROM driver in using DMA channel.
Jerome Coutant 1:2371382139dd 1108 * @param DevAddress: Target device address
Jerome Coutant 1:2371382139dd 1109 * @param MemAddress: Internal memory address
Jerome Coutant 1:2371382139dd 1110 * @param pBuffer: Pointer to data buffer
Jerome Coutant 1:2371382139dd 1111 * @param BufferSize: Amount of data to be read
Jerome Coutant 1:2371382139dd 1112 * @retval HAL status
Jerome Coutant 1:2371382139dd 1113 */
Jerome Coutant 1:2371382139dd 1114 HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
Jerome Coutant 1:2371382139dd 1115 {
Jerome Coutant 1:2371382139dd 1116 return (I2Cx_ReadBufferDMA(DevAddress, MemAddress, pBuffer, BufferSize));
Jerome Coutant 1:2371382139dd 1117 }
Jerome Coutant 1:2371382139dd 1118
Jerome Coutant 1:2371382139dd 1119 /**
Jerome Coutant 1:2371382139dd 1120 * @brief Checks if target device is ready for communication.
Jerome Coutant 1:2371382139dd 1121 * @note This function is used with Memory devices
Jerome Coutant 1:2371382139dd 1122 * @param DevAddress: Target device address
Jerome Coutant 1:2371382139dd 1123 * @param Trials: Number of trials
Jerome Coutant 1:2371382139dd 1124 * @retval HAL status
Jerome Coutant 1:2371382139dd 1125 */
Jerome Coutant 1:2371382139dd 1126 HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
Jerome Coutant 1:2371382139dd 1127 {
Jerome Coutant 1:2371382139dd 1128 return (I2Cx_IsDeviceReady(DevAddress, Trials));
Jerome Coutant 1:2371382139dd 1129 }
Jerome Coutant 1:2371382139dd 1130
Jerome Coutant 1:2371382139dd 1131 // Added for mbed
Jerome Coutant 1:2371382139dd 1132 /**
Jerome Coutant 1:2371382139dd 1133 * @brief This function handles sEE DMA TX interrupt request.
Jerome Coutant 1:2371382139dd 1134 * @param None
Jerome Coutant 1:2371382139dd 1135 * @retval None
Jerome Coutant 1:2371382139dd 1136 */
Jerome Coutant 1:2371382139dd 1137 static void EEPROM_I2C_DMA_TX_IRQHandler(void)
Jerome Coutant 1:2371382139dd 1138 {
Jerome Coutant 1:2371382139dd 1139 HAL_DMA_IRQHandler(EEP_I2cHandle.hdmatx);
Jerome Coutant 1:2371382139dd 1140 }
Jerome Coutant 1:2371382139dd 1141
Jerome Coutant 1:2371382139dd 1142 /**
Jerome Coutant 1:2371382139dd 1143 * @brief This function handles sEE DMA RX interrupt request.
Jerome Coutant 1:2371382139dd 1144 * @param None
Jerome Coutant 1:2371382139dd 1145 * @retval None
Jerome Coutant 1:2371382139dd 1146 */
Jerome Coutant 1:2371382139dd 1147 static void EEPROM_I2C_DMA_RX_IRQHandler(void)
Jerome Coutant 1:2371382139dd 1148 {
Jerome Coutant 1:2371382139dd 1149 HAL_DMA_IRQHandler(EEP_I2cHandle.hdmarx);
Jerome Coutant 1:2371382139dd 1150 }
Jerome Coutant 1:2371382139dd 1151
Jerome Coutant 1:2371382139dd 1152 #endif /* EE_M24LR64 */
Jerome Coutant 1:2371382139dd 1153
Jerome Coutant 1:2371382139dd 1154 /**
Jerome Coutant 1:2371382139dd 1155 * @}
Jerome Coutant 1:2371382139dd 1156 */
Jerome Coutant 1:2371382139dd 1157
Jerome Coutant 1:2371382139dd 1158 /**
Jerome Coutant 1:2371382139dd 1159 * @}
Jerome Coutant 1:2371382139dd 1160 */
Jerome Coutant 1:2371382139dd 1161
Jerome Coutant 1:2371382139dd 1162 /**
Jerome Coutant 1:2371382139dd 1163 * @}
Jerome Coutant 1:2371382139dd 1164 */
Jerome Coutant 1:2371382139dd 1165
Jerome Coutant 1:2371382139dd 1166 /**
Jerome Coutant 1:2371382139dd 1167 * @}
Jerome Coutant 1:2371382139dd 1168 */
Jerome Coutant 1:2371382139dd 1169
Jerome Coutant 1:2371382139dd 1170 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/