001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:13413ea9a877 1 /**
ganlikun 0:13413ea9a877 2 ******************************************************************************
ganlikun 0:13413ea9a877 3 * @file stm32f4xx_hal_fmpi2c.c
ganlikun 0:13413ea9a877 4 * @author MCD Application Team
ganlikun 0:13413ea9a877 5 * @version V1.7.1
ganlikun 0:13413ea9a877 6 * @date 14-April-2017
ganlikun 0:13413ea9a877 7 * @brief FMPI2C HAL module driver.
ganlikun 0:13413ea9a877 8 * This file provides firmware functions to manage the following
ganlikun 0:13413ea9a877 9 * functionalities of the Inter Integrated Circuit (FMPI2C) peripheral:
ganlikun 0:13413ea9a877 10 * + Initialization and de-initialization functions
ganlikun 0:13413ea9a877 11 * + IO operation functions
ganlikun 0:13413ea9a877 12 * + Peripheral State and Errors functions
ganlikun 0:13413ea9a877 13 *
ganlikun 0:13413ea9a877 14 @verbatim
ganlikun 0:13413ea9a877 15 ==============================================================================
ganlikun 0:13413ea9a877 16 ##### How to use this driver #####
ganlikun 0:13413ea9a877 17 ==============================================================================
ganlikun 0:13413ea9a877 18 [..]
ganlikun 0:13413ea9a877 19 The FMPI2C HAL driver can be used as follows:
ganlikun 0:13413ea9a877 20
ganlikun 0:13413ea9a877 21 (#) Declare a FMPI2C_HandleTypeDef handle structure, for example:
ganlikun 0:13413ea9a877 22 FMPI2C_HandleTypeDef hfmpi2c;
ganlikun 0:13413ea9a877 23
ganlikun 0:13413ea9a877 24 (#)Initialize the FMPI2C low level resources by implementing the HAL_FMPI2C_MspInit() API:
ganlikun 0:13413ea9a877 25 (##) Enable the FMPI2Cx interface clock
ganlikun 0:13413ea9a877 26 (##) FMPI2C pins configuration
ganlikun 0:13413ea9a877 27 (+++) Enable the clock for the FMPI2C GPIOs
ganlikun 0:13413ea9a877 28 (+++) Configure FMPI2C pins as alternate function open-drain
ganlikun 0:13413ea9a877 29 (##) NVIC configuration if you need to use interrupt process
ganlikun 0:13413ea9a877 30 (+++) Configure the FMPI2Cx interrupt priority
ganlikun 0:13413ea9a877 31 (+++) Enable the NVIC FMPI2C IRQ Channel
ganlikun 0:13413ea9a877 32 (##) DMA Configuration if you need to use DMA process
ganlikun 0:13413ea9a877 33 (+++) Declare a DMA_HandleTypeDef handle structure for the transmit or receive channel
ganlikun 0:13413ea9a877 34 (+++) Enable the DMAx interface clock using
ganlikun 0:13413ea9a877 35 (+++) Configure the DMA handle parameters
ganlikun 0:13413ea9a877 36 (+++) Configure the DMA Tx or Rx channel
ganlikun 0:13413ea9a877 37 (+++) Associate the initialized DMA handle to the hfmpi2c DMA Tx or Rx handle
ganlikun 0:13413ea9a877 38 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on
ganlikun 0:13413ea9a877 39 the DMA Tx or Rx channel
ganlikun 0:13413ea9a877 40
ganlikun 0:13413ea9a877 41 (#) Configure the Communication Clock Timing, Own Address1, Master Addressing mode, Dual Addressing mode,
ganlikun 0:13413ea9a877 42 Own Address2, Own Address2 Mask, General call and Nostretch mode in the hfmpi2c Init structure.
ganlikun 0:13413ea9a877 43
ganlikun 0:13413ea9a877 44 (#) Initialize the FMPI2C registers by calling the HAL_FMPI2C_Init(), configures also the low level Hardware
ganlikun 0:13413ea9a877 45 (GPIO, CLOCK, NVIC...etc) by calling the customized HAL_FMPI2C_MspInit(&hfmpi2c) API.
ganlikun 0:13413ea9a877 46
ganlikun 0:13413ea9a877 47 (#) To check if target device is ready for communication, use the function HAL_FMPI2C_IsDeviceReady()
ganlikun 0:13413ea9a877 48
ganlikun 0:13413ea9a877 49 (#) For FMPI2C IO and IO MEM operations, three operation modes are available within this driver :
ganlikun 0:13413ea9a877 50
ganlikun 0:13413ea9a877 51 *** Polling mode IO operation ***
ganlikun 0:13413ea9a877 52 =================================
ganlikun 0:13413ea9a877 53 [..]
ganlikun 0:13413ea9a877 54 (+) Transmit in master mode an amount of data in blocking mode using HAL_FMPI2C_Master_Transmit()
ganlikun 0:13413ea9a877 55 (+) Receive in master mode an amount of data in blocking mode using HAL_FMPI2C_Master_Receive()
ganlikun 0:13413ea9a877 56 (+) Transmit in slave mode an amount of data in blocking mode using HAL_FMPI2C_Slave_Transmit()
ganlikun 0:13413ea9a877 57 (+) Receive in slave mode an amount of data in blocking mode using HAL_FMPI2C_Slave_Receive()
ganlikun 0:13413ea9a877 58
ganlikun 0:13413ea9a877 59 *** Polling mode IO MEM operation ***
ganlikun 0:13413ea9a877 60 =====================================
ganlikun 0:13413ea9a877 61 [..]
ganlikun 0:13413ea9a877 62 (+) Write an amount of data in blocking mode to a specific memory address using HAL_FMPI2C_Mem_Write()
ganlikun 0:13413ea9a877 63 (+) Read an amount of data in blocking mode from a specific memory address using HAL_FMPI2C_Mem_Read()
ganlikun 0:13413ea9a877 64
ganlikun 0:13413ea9a877 65
ganlikun 0:13413ea9a877 66 *** Interrupt mode IO operation ***
ganlikun 0:13413ea9a877 67 ===================================
ganlikun 0:13413ea9a877 68 [..]
ganlikun 0:13413ea9a877 69 (+) Transmit in master mode an amount of data in non-blocking mode using HAL_FMPI2C_Master_Transmit_IT()
ganlikun 0:13413ea9a877 70 (+) At transmission end of transfer, HAL_FMPI2C_MasterTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 71 add his own code by customization of function pointer HAL_FMPI2C_MasterTxCpltCallback()
ganlikun 0:13413ea9a877 72 (+) Receive in master mode an amount of data in non-blocking mode using HAL_FMPI2C_Master_Receive_IT()
ganlikun 0:13413ea9a877 73 (+) At reception end of transfer, HAL_FMPI2C_MasterRxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 74 add his own code by customization of function pointer HAL_FMPI2C_MasterRxCpltCallback()
ganlikun 0:13413ea9a877 75 (+) Transmit in slave mode an amount of data in non-blocking mode using HAL_FMPI2C_Slave_Transmit_IT()
ganlikun 0:13413ea9a877 76 (+) At transmission end of transfer, HAL_FMPI2C_SlaveTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 77 add his own code by customization of function pointer HAL_FMPI2C_SlaveTxCpltCallback()
ganlikun 0:13413ea9a877 78 (+) Receive in slave mode an amount of data in non-blocking mode using HAL_FMPI2C_Slave_Receive_IT()
ganlikun 0:13413ea9a877 79 (+) At reception end of transfer, HAL_FMPI2C_SlaveRxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 80 add his own code by customization of function pointer HAL_FMPI2C_SlaveRxCpltCallback()
ganlikun 0:13413ea9a877 81 (+) In case of transfer Error, HAL_FMPI2C_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 82 add his own code by customization of function pointer HAL_FMPI2C_ErrorCallback()
ganlikun 0:13413ea9a877 83 (+) Abort a master FMPI2C process communication with Interrupt using HAL_FMPI2C_Master_Abort_IT()
ganlikun 0:13413ea9a877 84 (+) End of abort process, HAL_FMPI2C_MasterRxCpltCallback() or HAL_FMPI2C_MasterTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 85 add his own code by customization of function pointer HAL_FMPI2C_MasterRxCpltCallback() or HAL_FMPI2C_MasterTxCpltCallback()
ganlikun 0:13413ea9a877 86 (+) Discard a slave FMPI2C process communication using __HAL_FMPI2C_GENERATE_NACK() macro.
ganlikun 0:13413ea9a877 87 This action will inform Master to generate a Stop condition to discard the communication.
ganlikun 0:13413ea9a877 88
ganlikun 0:13413ea9a877 89
ganlikun 0:13413ea9a877 90 *** Interrupt mode IO sequential operation ***
ganlikun 0:13413ea9a877 91 ===================================
ganlikun 0:13413ea9a877 92 [..]
ganlikun 0:13413ea9a877 93 (@) These interfaces allow to manage a sequential transfer with a repeated start condition
ganlikun 0:13413ea9a877 94 when a direction change during transfer
ganlikun 0:13413ea9a877 95 [..]
ganlikun 0:13413ea9a877 96 (+) A specific option field manage the different steps of a sequential transfer
ganlikun 0:13413ea9a877 97 (+) Option field values are defined through FMPI2C_XFEROPTIONS and are listed below:
ganlikun 0:13413ea9a877 98 (++) FMPI2C_FIRST_AND_LAST_FRAME: No sequential usage, functionnal is same as associated interfaces in no sequential mode
ganlikun 0:13413ea9a877 99 (++) FMPI2C_FIRST_FRAME: Sequential usage, this option allow to manage a sequence with start condition, address
ganlikun 0:13413ea9a877 100 and data to transfer without a final stop condition
ganlikun 0:13413ea9a877 101 (++) FMPI2C_FIRST_AND_NEXT_FRAME: Sequential usage (Master only), this option allow to manage a sequence with start condition, address
ganlikun 0:13413ea9a877 102 and data to transfer without a final stop condition, an then permit a call the same master sequential interface
ganlikun 0:13413ea9a877 103 several times (like HAL_FMPI2C_Master_Sequential_Transmit_IT() then HAL_FMPI2C_Master_Sequential_Transmit_IT())
ganlikun 0:13413ea9a877 104 (++) FMPI2C_NEXT_FRAME: Sequential usage, this option allow to manage a sequence with a restart condition, address
ganlikun 0:13413ea9a877 105 and with new data to transfer if the direction change or manage only the new data to transfer
ganlikun 0:13413ea9a877 106 if no direction change and without a final stop condition in both cases
ganlikun 0:13413ea9a877 107 (++) FMPI2C_LAST_FRAME: Sequential usage, this option allow to manage a sequance with a restart condition, address
ganlikun 0:13413ea9a877 108 and with new data to transfer if the direction change or manage only the new data to transfer
ganlikun 0:13413ea9a877 109 if no direction change and with a final stop condition in both cases
ganlikun 0:13413ea9a877 110
ganlikun 0:13413ea9a877 111 (+) Differents sequential FMPI2C interfaces are listed below:
ganlikun 0:13413ea9a877 112 (++) Sequential transmit in master FMPI2C mode an amount of data in non-blocking mode using HAL_FMPI2C_Master_Sequential_Transmit_IT()
ganlikun 0:13413ea9a877 113 (+++) At transmission end of current frame transfer, HAL_FMPI2C_MasterTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 114 add his own code by customization of function pointer HAL_FMPI2C_MasterTxCpltCallback()
ganlikun 0:13413ea9a877 115 (++) Sequential receive in master FMPI2C mode an amount of data in non-blocking mode using HAL_FMPI2C_Master_Sequential_Receive_IT()
ganlikun 0:13413ea9a877 116 (+++) At reception end of current frame transfer, HAL_FMPI2C_MasterRxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 117 add his own code by customization of function pointer HAL_FMPI2C_MasterRxCpltCallback()
ganlikun 0:13413ea9a877 118 (++) Abort a master FMPI2C process communication with Interrupt using HAL_FMPI2C_Master_Abort_IT()
ganlikun 0:13413ea9a877 119 (+++) End of abort process, HAL_FMPI2C_AbortCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 120 add his own code by customization of function pointer HAL_FMPI2C_AbortCpltCallback()
ganlikun 0:13413ea9a877 121 (+++) mean HAL_FMPI2C_MasterTxCpltCallback() in case of previous state was master transmit
ganlikun 0:13413ea9a877 122 (+++) mean HAL_FMPI2C_MasterRxCpltCallback() in case of previous state was master receive
ganlikun 0:13413ea9a877 123 (++) Enable/disable the Address listen mode in slave FMPI2C mode using HAL_FMPI2C_EnableListen_IT() HAL_FMPI2C_DisableListen_IT()
ganlikun 0:13413ea9a877 124 (+++) When address slave FMPI2C match, HAL_FMPI2C_AddrCallback() is executed and user can
ganlikun 0:13413ea9a877 125 add his own code to check the Address Match Code and the transmission direction request by master (Write/Read).
ganlikun 0:13413ea9a877 126 (+++) At Listen mode end HAL_FMPI2C_ListenCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 127 add his own code by customization of function pointer HAL_FMPI2C_ListenCpltCallback()
ganlikun 0:13413ea9a877 128 (++) Sequential transmit in slave FMPI2C mode an amount of data in non-blocking mode using HAL_FMPI2C_Slave_Sequential_Transmit_IT()
ganlikun 0:13413ea9a877 129 (+++) At transmission end of current frame transfer, HAL_FMPI2C_SlaveTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 130 add his own code by customization of function pointer HAL_FMPI2C_SlaveTxCpltCallback()
ganlikun 0:13413ea9a877 131 (++) Sequential receive in slave FMPI2C mode an amount of data in non-blocking mode using HAL_FMPI2C_Slave_Sequential_Receive_IT()
ganlikun 0:13413ea9a877 132 (+++) At reception end of current frame transfer, HAL_FMPI2C_SlaveRxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 133 add his own code by customization of function pointer HAL_FMPI2C_SlaveRxCpltCallback()
ganlikun 0:13413ea9a877 134 (++) In case of transfer Error, HAL_FMPI2C_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 135 add his own code by customization of function pointer HAL_FMPI2C_ErrorCallback()
ganlikun 0:13413ea9a877 136 (++) Abort a master FMPI2C process communication with Interrupt using HAL_FMPI2C_Master_Abort_IT()
ganlikun 0:13413ea9a877 137 (++) End of abort process, HAL_FMPI2C_AbortCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 138 add his own code by customization of function pointer HAL_FMPI2C_AbortCpltCallback()
ganlikun 0:13413ea9a877 139 (++) Discard a slave FMPI2C process communication using __HAL_FMPI2C_GENERATE_NACK() macro.
ganlikun 0:13413ea9a877 140 This action will inform Master to generate a Stop condition to discard the communication.
ganlikun 0:13413ea9a877 141
ganlikun 0:13413ea9a877 142 *** Interrupt mode IO MEM operation ***
ganlikun 0:13413ea9a877 143 =======================================
ganlikun 0:13413ea9a877 144 [..]
ganlikun 0:13413ea9a877 145 (+) Write an amount of data in non-blocking mode with Interrupt to a specific memory address using
ganlikun 0:13413ea9a877 146 HAL_FMPI2C_Mem_Write_IT()
ganlikun 0:13413ea9a877 147 (+) At Memory end of write transfer, HAL_FMPI2C_MemTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 148 add his own code by customization of function pointer HAL_FMPI2C_MemTxCpltCallback()
ganlikun 0:13413ea9a877 149 (+) Read an amount of data in non-blocking mode with Interrupt from a specific memory address using
ganlikun 0:13413ea9a877 150 HAL_FMPI2C_Mem_Read_IT()
ganlikun 0:13413ea9a877 151 (+) At Memory end of read transfer, HAL_FMPI2C_MemRxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 152 add his own code by customization of function pointer HAL_FMPI2C_MemRxCpltCallback()
ganlikun 0:13413ea9a877 153 (+) In case of transfer Error, HAL_FMPI2C_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 154 add his own code by customization of function pointer HAL_FMPI2C_ErrorCallback()
ganlikun 0:13413ea9a877 155
ganlikun 0:13413ea9a877 156 *** DMA mode IO operation ***
ganlikun 0:13413ea9a877 157 ==============================
ganlikun 0:13413ea9a877 158 [..]
ganlikun 0:13413ea9a877 159 (+) Transmit in master mode an amount of data in non-blocking mode (DMA) using
ganlikun 0:13413ea9a877 160 HAL_FMPI2C_Master_Transmit_DMA()
ganlikun 0:13413ea9a877 161 (+) At transmission end of transfer, HAL_FMPI2C_MasterTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 162 add his own code by customization of function pointer HAL_FMPI2C_MasterTxCpltCallback()
ganlikun 0:13413ea9a877 163 (+) Receive in master mode an amount of data in non-blocking mode (DMA) using
ganlikun 0:13413ea9a877 164 HAL_FMPI2C_Master_Receive_DMA()
ganlikun 0:13413ea9a877 165 (+) At reception end of transfer, HAL_FMPI2C_MasterRxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 166 add his own code by customization of function pointer HAL_FMPI2C_MasterRxCpltCallback()
ganlikun 0:13413ea9a877 167 (+) Transmit in slave mode an amount of data in non-blocking mode (DMA) using
ganlikun 0:13413ea9a877 168 HAL_FMPI2C_Slave_Transmit_DMA()
ganlikun 0:13413ea9a877 169 (+) At transmission end of transfer, HAL_FMPI2C_SlaveTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 170 add his own code by customization of function pointer HAL_FMPI2C_SlaveTxCpltCallback()
ganlikun 0:13413ea9a877 171 (+) Receive in slave mode an amount of data in non-blocking mode (DMA) using
ganlikun 0:13413ea9a877 172 HAL_FMPI2C_Slave_Receive_DMA()
ganlikun 0:13413ea9a877 173 (+) At reception end of transfer, HAL_FMPI2C_SlaveRxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 174 add his own code by customization of function pointer HAL_FMPI2C_SlaveRxCpltCallback()
ganlikun 0:13413ea9a877 175 (+) In case of transfer Error, HAL_FMPI2C_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 176 add his own code by customization of function pointer HAL_FMPI2C_ErrorCallback()
ganlikun 0:13413ea9a877 177 (+) Abort a master FMPI2C process communication with Interrupt using HAL_FMPI2C_Master_Abort_IT()
ganlikun 0:13413ea9a877 178 (+) End of abort process, HAL_FMPI2C_MasterRxCpltCallback() or HAL_FMPI2C_MasterTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 179 add his own code by customization of function pointer HAL_FMPI2C_MasterRxCpltCallback() or HAL_FMPI2C_MasterTxCpltCallback()
ganlikun 0:13413ea9a877 180 (+) Discard a slave FMPI2C process communication using __HAL_FMPI2C_GENERATE_NACK() macro.
ganlikun 0:13413ea9a877 181 This action will inform Master to generate a Stop condition to discard the communication.
ganlikun 0:13413ea9a877 182
ganlikun 0:13413ea9a877 183 *** DMA mode IO MEM operation ***
ganlikun 0:13413ea9a877 184 =================================
ganlikun 0:13413ea9a877 185 [..]
ganlikun 0:13413ea9a877 186 (+) Write an amount of data in non-blocking mode with DMA to a specific memory address using
ganlikun 0:13413ea9a877 187 HAL_FMPI2C_Mem_Write_DMA()
ganlikun 0:13413ea9a877 188 (+) At Memory end of write transfer, HAL_FMPI2C_MemTxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 189 add his own code by customization of function pointer HAL_FMPI2C_MemTxCpltCallback()
ganlikun 0:13413ea9a877 190 (+) Read an amount of data in non-blocking mode with DMA from a specific memory address using
ganlikun 0:13413ea9a877 191 HAL_FMPI2C_Mem_Read_DMA()
ganlikun 0:13413ea9a877 192 (+) At Memory end of read transfer, HAL_FMPI2C_MemRxCpltCallback() is executed and user can
ganlikun 0:13413ea9a877 193 add his own code by customization of function pointer HAL_FMPI2C_MemRxCpltCallback()
ganlikun 0:13413ea9a877 194 (+) In case of transfer Error, HAL_FMPI2C_ErrorCallback() function is executed and user can
ganlikun 0:13413ea9a877 195 add his own code by customization of function pointer HAL_FMPI2C_ErrorCallback()
ganlikun 0:13413ea9a877 196
ganlikun 0:13413ea9a877 197
ganlikun 0:13413ea9a877 198 *** FMPI2C HAL driver macros list ***
ganlikun 0:13413ea9a877 199 ==================================
ganlikun 0:13413ea9a877 200 [..]
ganlikun 0:13413ea9a877 201 Below the list of most used macros in FMPI2C HAL driver.
ganlikun 0:13413ea9a877 202
ganlikun 0:13413ea9a877 203 (+) __HAL_FMPI2C_ENABLE: Enable the FMPI2C peripheral
ganlikun 0:13413ea9a877 204 (+) __HAL_FMPI2C_DISABLE: Disable the FMPI2C peripheral
ganlikun 0:13413ea9a877 205 (+) __HAL_FMPI2C_GENERATE_NACK: Generate a Non-Acknowledge FMPI2C peripheral in Slave mode
ganlikun 0:13413ea9a877 206 (+) __HAL_FMPI2C_GET_FLAG: Check whether the specified FMPI2C flag is set or not
ganlikun 0:13413ea9a877 207 (+) __HAL_FMPI2C_CLEAR_FLAG: Clear the specified FMPI2C pending flag
ganlikun 0:13413ea9a877 208 (+) __HAL_FMPI2C_ENABLE_IT: Enable the specified FMPI2C interrupt
ganlikun 0:13413ea9a877 209 (+) __HAL_FMPI2C_DISABLE_IT: Disable the specified FMPI2C interrupt
ganlikun 0:13413ea9a877 210
ganlikun 0:13413ea9a877 211 [..]
ganlikun 0:13413ea9a877 212 (@) You can refer to the FMPI2C HAL driver header file for more useful macros
ganlikun 0:13413ea9a877 213
ganlikun 0:13413ea9a877 214 @endverbatim
ganlikun 0:13413ea9a877 215 ******************************************************************************
ganlikun 0:13413ea9a877 216 * @attention
ganlikun 0:13413ea9a877 217 *
ganlikun 0:13413ea9a877 218 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:13413ea9a877 219 *
ganlikun 0:13413ea9a877 220 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:13413ea9a877 221 * are permitted provided that the following conditions are met:
ganlikun 0:13413ea9a877 222 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:13413ea9a877 223 * this list of conditions and the following disclaimer.
ganlikun 0:13413ea9a877 224 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:13413ea9a877 225 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:13413ea9a877 226 * and/or other materials provided with the distribution.
ganlikun 0:13413ea9a877 227 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:13413ea9a877 228 * may be used to endorse or promote products derived from this software
ganlikun 0:13413ea9a877 229 * without specific prior written permission.
ganlikun 0:13413ea9a877 230 *
ganlikun 0:13413ea9a877 231 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:13413ea9a877 232 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:13413ea9a877 233 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:13413ea9a877 234 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:13413ea9a877 235 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:13413ea9a877 236 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:13413ea9a877 237 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:13413ea9a877 238 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:13413ea9a877 239 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:13413ea9a877 240 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:13413ea9a877 241 *
ganlikun 0:13413ea9a877 242 ******************************************************************************
ganlikun 0:13413ea9a877 243 */
ganlikun 0:13413ea9a877 244
ganlikun 0:13413ea9a877 245 /* Includes ------------------------------------------------------------------*/
ganlikun 0:13413ea9a877 246 #include "stm32f4xx_hal.h"
ganlikun 0:13413ea9a877 247
ganlikun 0:13413ea9a877 248 /** @addtogroup STM32F4xx_HAL_Driver
ganlikun 0:13413ea9a877 249 * @{
ganlikun 0:13413ea9a877 250 */
ganlikun 0:13413ea9a877 251
ganlikun 0:13413ea9a877 252 /** @defgroup FMPI2C FMPI2C
ganlikun 0:13413ea9a877 253 * @brief FMPI2C HAL module driver
ganlikun 0:13413ea9a877 254 * @{
ganlikun 0:13413ea9a877 255 */
ganlikun 0:13413ea9a877 256
ganlikun 0:13413ea9a877 257 #ifdef HAL_FMPI2C_MODULE_ENABLED
ganlikun 0:13413ea9a877 258
ganlikun 0:13413ea9a877 259 #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) ||\
ganlikun 0:13413ea9a877 260 defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
ganlikun 0:13413ea9a877 261
ganlikun 0:13413ea9a877 262 /* Private typedef -----------------------------------------------------------*/
ganlikun 0:13413ea9a877 263 /* Private define ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 264
ganlikun 0:13413ea9a877 265 /** @defgroup FMPI2C_Private_Define FMPI2C Private Define
ganlikun 0:13413ea9a877 266 * @{
ganlikun 0:13413ea9a877 267 */
ganlikun 0:13413ea9a877 268 #define TIMING_CLEAR_MASK 0xF0FFFFFFU /*!< FMPI2C TIMING clear register Mask */
ganlikun 0:13413ea9a877 269 #define FMPI2C_TIMEOUT_ADDR 10000U /*!< 10 s */
ganlikun 0:13413ea9a877 270 #define FMPI2C_TIMEOUT_BUSY 25U /*!< 25 ms */
ganlikun 0:13413ea9a877 271 #define FMPI2C_TIMEOUT_DIR 25U /*!< 25 ms */
ganlikun 0:13413ea9a877 272 #define FMPI2C_TIMEOUT_RXNE 25U /*!< 25 ms */
ganlikun 0:13413ea9a877 273 #define FMPI2C_TIMEOUT_STOPF 25U /*!< 25 ms */
ganlikun 0:13413ea9a877 274 #define FMPI2C_TIMEOUT_TC 25U /*!< 25 ms */
ganlikun 0:13413ea9a877 275 #define FMPI2C_TIMEOUT_TCR 25U /*!< 25 ms */
ganlikun 0:13413ea9a877 276 #define FMPI2C_TIMEOUT_TXIS 25U /*!< 25 ms */
ganlikun 0:13413ea9a877 277 #define FMPI2C_TIMEOUT_FLAG 25U /*!< 25 ms */
ganlikun 0:13413ea9a877 278
ganlikun 0:13413ea9a877 279 #define MAX_NBYTE_SIZE 255U
ganlikun 0:13413ea9a877 280 #define SlaveAddr_SHIFT 7U
ganlikun 0:13413ea9a877 281 #define SlaveAddr_MSK 0x06U
ganlikun 0:13413ea9a877 282
ganlikun 0:13413ea9a877 283 /* Private define for @ref PreviousState usage */
ganlikun 0:13413ea9a877 284 #define FMPI2C_STATE_MSK ((uint32_t)((HAL_FMPI2C_STATE_BUSY_TX | HAL_FMPI2C_STATE_BUSY_RX) & (~((uint32_t)HAL_FMPI2C_STATE_READY)))) /*!< Mask State define, keep only RX and TX bits */
ganlikun 0:13413ea9a877 285 #define FMPI2C_STATE_NONE ((uint32_t)(HAL_FMPI2C_MODE_NONE)) /*!< Default Value */
ganlikun 0:13413ea9a877 286 #define FMPI2C_STATE_MASTER_BUSY_TX ((uint32_t)((HAL_FMPI2C_STATE_BUSY_TX & FMPI2C_STATE_MSK) | HAL_FMPI2C_MODE_MASTER)) /*!< Master Busy TX, combinaison of State LSB and Mode enum */
ganlikun 0:13413ea9a877 287 #define FMPI2C_STATE_MASTER_BUSY_RX ((uint32_t)((HAL_FMPI2C_STATE_BUSY_RX & FMPI2C_STATE_MSK) | HAL_FMPI2C_MODE_MASTER)) /*!< Master Busy RX, combinaison of State LSB and Mode enum */
ganlikun 0:13413ea9a877 288 #define FMPI2C_STATE_SLAVE_BUSY_TX ((uint32_t)((HAL_FMPI2C_STATE_BUSY_TX & FMPI2C_STATE_MSK) | HAL_FMPI2C_MODE_SLAVE)) /*!< Slave Busy TX, combinaison of State LSB and Mode enum */
ganlikun 0:13413ea9a877 289 #define FMPI2C_STATE_SLAVE_BUSY_RX ((uint32_t)((HAL_FMPI2C_STATE_BUSY_RX & FMPI2C_STATE_MSK) | HAL_FMPI2C_MODE_SLAVE)) /*!< Slave Busy RX, combinaison of State LSB and Mode enum */
ganlikun 0:13413ea9a877 290 #define FMPI2C_STATE_MEM_BUSY_TX ((uint32_t)((HAL_FMPI2C_STATE_BUSY_TX & FMPI2C_STATE_MSK) | HAL_FMPI2C_MODE_MEM)) /*!< Memory Busy TX, combinaison of State LSB and Mode enum */
ganlikun 0:13413ea9a877 291 #define FMPI2C_STATE_MEM_BUSY_RX ((uint32_t)((HAL_FMPI2C_STATE_BUSY_RX & FMPI2C_STATE_MSK) | HAL_FMPI2C_MODE_MEM)) /*!< Memory Busy RX, combinaison of State LSB and Mode enum */
ganlikun 0:13413ea9a877 292
ganlikun 0:13413ea9a877 293
ganlikun 0:13413ea9a877 294 /* Private define to centralize the enable/disable of Interrupts */
ganlikun 0:13413ea9a877 295 #define FMPI2C_XFER_TX_IT 0x00000001U
ganlikun 0:13413ea9a877 296 #define FMPI2C_XFER_RX_IT 0x00000002U
ganlikun 0:13413ea9a877 297 #define FMPI2C_XFER_LISTEN_IT 0x00000004U
ganlikun 0:13413ea9a877 298
ganlikun 0:13413ea9a877 299 #define FMPI2C_XFER_ERROR_IT 0x00000011U
ganlikun 0:13413ea9a877 300 #define FMPI2C_XFER_CPLT_IT 0x00000012U
ganlikun 0:13413ea9a877 301 #define FMPI2C_XFER_RELOAD_IT 0x00000012U
ganlikun 0:13413ea9a877 302
ganlikun 0:13413ea9a877 303 /* Private define Sequential Transfer Options default/reset value */
ganlikun 0:13413ea9a877 304 #define FMPI2C_NO_OPTION_FRAME 0xFFFF0000U
ganlikun 0:13413ea9a877 305 /**
ganlikun 0:13413ea9a877 306 * @}
ganlikun 0:13413ea9a877 307 */
ganlikun 0:13413ea9a877 308
ganlikun 0:13413ea9a877 309 /* Private macro -------------------------------------------------------------*/
ganlikun 0:13413ea9a877 310 #define FMPI2C_GET_DMA_REMAIN_DATA(__HANDLE__) ((((__HANDLE__)->State) == HAL_FMPI2C_STATE_BUSY_TX) ? \
ganlikun 0:13413ea9a877 311 ((uint32_t)((__HANDLE__)->hdmatx->Instance->NDTR)) : \
ganlikun 0:13413ea9a877 312 ((uint32_t)((__HANDLE__)->hdmarx->Instance->NDTR)))
ganlikun 0:13413ea9a877 313
ganlikun 0:13413ea9a877 314 /* Private variables ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 315 /* Private function prototypes -----------------------------------------------*/
ganlikun 0:13413ea9a877 316
ganlikun 0:13413ea9a877 317 /** @defgroup FMPI2C_Private_Functions FMPI2C Private Functions
ganlikun 0:13413ea9a877 318 * @{
ganlikun 0:13413ea9a877 319 */
ganlikun 0:13413ea9a877 320 /* Private functions to handle DMA transfer */
ganlikun 0:13413ea9a877 321 static void FMPI2C_DMAMasterTransmitCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 322 static void FMPI2C_DMAMasterReceiveCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 323 static void FMPI2C_DMASlaveTransmitCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 324 static void FMPI2C_DMASlaveReceiveCplt(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 325 static void FMPI2C_DMAError(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 326 static void FMPI2C_DMAAbort(DMA_HandleTypeDef *hdma);
ganlikun 0:13413ea9a877 327
ganlikun 0:13413ea9a877 328 /* Private functions to handle IT transfer */
ganlikun 0:13413ea9a877 329 static void FMPI2C_ITAddrCplt (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags);
ganlikun 0:13413ea9a877 330 static void FMPI2C_ITMasterSequentialCplt (FMPI2C_HandleTypeDef *hfmpi2c);
ganlikun 0:13413ea9a877 331 static void FMPI2C_ITSlaveSequentialCplt (FMPI2C_HandleTypeDef *hfmpi2c);
ganlikun 0:13413ea9a877 332 static void FMPI2C_ITMasterCplt (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags);
ganlikun 0:13413ea9a877 333 static void FMPI2C_ITSlaveCplt (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags);
ganlikun 0:13413ea9a877 334 static void FMPI2C_ITListenCplt (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags);
ganlikun 0:13413ea9a877 335 static void FMPI2C_ITError (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags);
ganlikun 0:13413ea9a877 336
ganlikun 0:13413ea9a877 337 /* Private functions to handle IT transfer */
ganlikun 0:13413ea9a877 338 static HAL_StatusTypeDef FMPI2C_RequestMemoryWrite (FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout, uint32_t Tickstart);
ganlikun 0:13413ea9a877 339 static HAL_StatusTypeDef FMPI2C_RequestMemoryRead (FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout, uint32_t Tickstart);
ganlikun 0:13413ea9a877 340
ganlikun 0:13413ea9a877 341 /* Private functions for FMPI2C transfer IRQ handler */
ganlikun 0:13413ea9a877 342 static HAL_StatusTypeDef FMPI2C_Master_ISR_IT(struct __FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags, uint32_t ITSources);
ganlikun 0:13413ea9a877 343 static HAL_StatusTypeDef FMPI2C_Slave_ISR_IT(struct __FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags, uint32_t ITSources);
ganlikun 0:13413ea9a877 344 static HAL_StatusTypeDef FMPI2C_Master_ISR_DMA(struct __FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags, uint32_t ITSources);
ganlikun 0:13413ea9a877 345 static HAL_StatusTypeDef FMPI2C_Slave_ISR_DMA(struct __FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags, uint32_t ITSources);
ganlikun 0:13413ea9a877 346
ganlikun 0:13413ea9a877 347 /* Private functions to handle flags during polling transfer */
ganlikun 0:13413ea9a877 348 static HAL_StatusTypeDef FMPI2C_WaitOnFlagUntilTimeout (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart);
ganlikun 0:13413ea9a877 349 static HAL_StatusTypeDef FMPI2C_WaitOnTXISFlagUntilTimeout (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Timeout, uint32_t Tickstart);
ganlikun 0:13413ea9a877 350 static HAL_StatusTypeDef FMPI2C_WaitOnRXNEFlagUntilTimeout (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Timeout, uint32_t Tickstart);
ganlikun 0:13413ea9a877 351 static HAL_StatusTypeDef FMPI2C_WaitOnSTOPFlagUntilTimeout (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Timeout, uint32_t Tickstart);
ganlikun 0:13413ea9a877 352 static HAL_StatusTypeDef FMPI2C_IsAcknowledgeFailed (FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Timeout, uint32_t Tickstart);
ganlikun 0:13413ea9a877 353
ganlikun 0:13413ea9a877 354 /* Private functions to centralize the enable/disable of Interrupts */
ganlikun 0:13413ea9a877 355 static HAL_StatusTypeDef FMPI2C_Enable_IRQ (FMPI2C_HandleTypeDef *hfmpi2c, uint16_t InterruptRequest);
ganlikun 0:13413ea9a877 356 static HAL_StatusTypeDef FMPI2C_Disable_IRQ (FMPI2C_HandleTypeDef *hfmpi2c, uint16_t InterruptRequest);
ganlikun 0:13413ea9a877 357
ganlikun 0:13413ea9a877 358 /* Private functions to flush TXDR register */
ganlikun 0:13413ea9a877 359 static void FMPI2C_Flush_TXDR (FMPI2C_HandleTypeDef *hfmpi2c);
ganlikun 0:13413ea9a877 360
ganlikun 0:13413ea9a877 361 /* Private functions to handle start, restart or stop a transfer */
ganlikun 0:13413ea9a877 362 static void FMPI2C_TransferConfig (FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request);
ganlikun 0:13413ea9a877 363 /**
ganlikun 0:13413ea9a877 364 * @}
ganlikun 0:13413ea9a877 365 */
ganlikun 0:13413ea9a877 366
ganlikun 0:13413ea9a877 367 /* Exported functions --------------------------------------------------------*/
ganlikun 0:13413ea9a877 368
ganlikun 0:13413ea9a877 369 /** @defgroup FMPI2C_Exported_Functions FMPI2C Exported Functions
ganlikun 0:13413ea9a877 370 * @{
ganlikun 0:13413ea9a877 371 */
ganlikun 0:13413ea9a877 372
ganlikun 0:13413ea9a877 373 /** @defgroup FMPI2C_Exported_Functions_Group1 Initialization and de-initialization functions
ganlikun 0:13413ea9a877 374 * @brief Initialization and Configuration functions
ganlikun 0:13413ea9a877 375 *
ganlikun 0:13413ea9a877 376 @verbatim
ganlikun 0:13413ea9a877 377 ===============================================================================
ganlikun 0:13413ea9a877 378 ##### Initialization and de-initialization functions #####
ganlikun 0:13413ea9a877 379 ===============================================================================
ganlikun 0:13413ea9a877 380 [..] This subsection provides a set of functions allowing to initialize and
ganlikun 0:13413ea9a877 381 deinitialize the FMPI2Cx peripheral:
ganlikun 0:13413ea9a877 382
ganlikun 0:13413ea9a877 383 (+) User must Implement HAL_FMPI2C_MspInit() function in which he configures
ganlikun 0:13413ea9a877 384 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
ganlikun 0:13413ea9a877 385
ganlikun 0:13413ea9a877 386 (+) Call the function HAL_FMPI2C_Init() to configure the selected device with
ganlikun 0:13413ea9a877 387 the selected configuration:
ganlikun 0:13413ea9a877 388 (++) Clock Timing
ganlikun 0:13413ea9a877 389 (++) Own Address 1
ganlikun 0:13413ea9a877 390 (++) Addressing mode (Master, Slave)
ganlikun 0:13413ea9a877 391 (++) Dual Addressing mode
ganlikun 0:13413ea9a877 392 (++) Own Address 2
ganlikun 0:13413ea9a877 393 (++) Own Address 2 Mask
ganlikun 0:13413ea9a877 394 (++) General call mode
ganlikun 0:13413ea9a877 395 (++) Nostretch mode
ganlikun 0:13413ea9a877 396
ganlikun 0:13413ea9a877 397 (+) Call the function HAL_FMPI2C_DeInit() to restore the default configuration
ganlikun 0:13413ea9a877 398 of the selected FMPI2Cx peripheral.
ganlikun 0:13413ea9a877 399
ganlikun 0:13413ea9a877 400 @endverbatim
ganlikun 0:13413ea9a877 401 * @{
ganlikun 0:13413ea9a877 402 */
ganlikun 0:13413ea9a877 403
ganlikun 0:13413ea9a877 404 /**
ganlikun 0:13413ea9a877 405 * @brief Initializes the FMPI2C according to the specified parameters
ganlikun 0:13413ea9a877 406 * in the FMPI2C_InitTypeDef and initialize the associated handle.
ganlikun 0:13413ea9a877 407 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 408 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 409 * @retval HAL status
ganlikun 0:13413ea9a877 410 */
ganlikun 0:13413ea9a877 411 HAL_StatusTypeDef HAL_FMPI2C_Init(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 412 {
ganlikun 0:13413ea9a877 413 /* Check the FMPI2C handle allocation */
ganlikun 0:13413ea9a877 414 if(hfmpi2c == NULL)
ganlikun 0:13413ea9a877 415 {
ganlikun 0:13413ea9a877 416 return HAL_ERROR;
ganlikun 0:13413ea9a877 417 }
ganlikun 0:13413ea9a877 418
ganlikun 0:13413ea9a877 419 /* Check the parameters */
ganlikun 0:13413ea9a877 420 assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
ganlikun 0:13413ea9a877 421 assert_param(IS_FMPI2C_OWN_ADDRESS1(hfmpi2c->Init.OwnAddress1));
ganlikun 0:13413ea9a877 422 assert_param(IS_FMPI2C_ADDRESSING_MODE(hfmpi2c->Init.AddressingMode));
ganlikun 0:13413ea9a877 423 assert_param(IS_FMPI2C_DUAL_ADDRESS(hfmpi2c->Init.DualAddressMode));
ganlikun 0:13413ea9a877 424 assert_param(IS_FMPI2C_OWN_ADDRESS2(hfmpi2c->Init.OwnAddress2));
ganlikun 0:13413ea9a877 425 assert_param(IS_FMPI2C_OWN_ADDRESS2_MASK(hfmpi2c->Init.OwnAddress2Masks));
ganlikun 0:13413ea9a877 426 assert_param(IS_FMPI2C_GENERAL_CALL(hfmpi2c->Init.GeneralCallMode));
ganlikun 0:13413ea9a877 427 assert_param(IS_FMPI2C_NO_STRETCH(hfmpi2c->Init.NoStretchMode));
ganlikun 0:13413ea9a877 428
ganlikun 0:13413ea9a877 429 if(hfmpi2c->State == HAL_FMPI2C_STATE_RESET)
ganlikun 0:13413ea9a877 430 {
ganlikun 0:13413ea9a877 431 /* Allocate lock resource and initialize it */
ganlikun 0:13413ea9a877 432 hfmpi2c->Lock = HAL_UNLOCKED;
ganlikun 0:13413ea9a877 433
ganlikun 0:13413ea9a877 434 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
ganlikun 0:13413ea9a877 435 HAL_FMPI2C_MspInit(hfmpi2c);
ganlikun 0:13413ea9a877 436 }
ganlikun 0:13413ea9a877 437
ganlikun 0:13413ea9a877 438 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
ganlikun 0:13413ea9a877 439
ganlikun 0:13413ea9a877 440 /* Disable the selected FMPI2C peripheral */
ganlikun 0:13413ea9a877 441 __HAL_FMPI2C_DISABLE(hfmpi2c);
ganlikun 0:13413ea9a877 442
ganlikun 0:13413ea9a877 443 /*---------------------------- FMPI2Cx TIMINGR Configuration ------------------*/
ganlikun 0:13413ea9a877 444 /* Configure FMPI2Cx: Frequency range */
ganlikun 0:13413ea9a877 445 hfmpi2c->Instance->TIMINGR = hfmpi2c->Init.Timing & TIMING_CLEAR_MASK;
ganlikun 0:13413ea9a877 446
ganlikun 0:13413ea9a877 447 /*---------------------------- FMPI2Cx OAR1 Configuration ---------------------*/
ganlikun 0:13413ea9a877 448 /* Disable Own Address1 before set the Own Address1 configuration */
ganlikun 0:13413ea9a877 449 hfmpi2c->Instance->OAR1 &= ~FMPI2C_OAR1_OA1EN;
ganlikun 0:13413ea9a877 450
ganlikun 0:13413ea9a877 451 /* Configure FMPI2Cx: Own Address1 and ack own address1 mode */
ganlikun 0:13413ea9a877 452 if(hfmpi2c->Init.OwnAddress1 != 0U)
ganlikun 0:13413ea9a877 453 {
ganlikun 0:13413ea9a877 454 if(hfmpi2c->Init.AddressingMode == FMPI2C_ADDRESSINGMODE_7BIT)
ganlikun 0:13413ea9a877 455 {
ganlikun 0:13413ea9a877 456 hfmpi2c->Instance->OAR1 = (FMPI2C_OAR1_OA1EN | hfmpi2c->Init.OwnAddress1);
ganlikun 0:13413ea9a877 457 }
ganlikun 0:13413ea9a877 458 else /* FMPI2C_ADDRESSINGMODE_10BIT */
ganlikun 0:13413ea9a877 459 {
ganlikun 0:13413ea9a877 460 hfmpi2c->Instance->OAR1 = (FMPI2C_OAR1_OA1EN | FMPI2C_OAR1_OA1MODE | hfmpi2c->Init.OwnAddress1);
ganlikun 0:13413ea9a877 461 }
ganlikun 0:13413ea9a877 462 }
ganlikun 0:13413ea9a877 463
ganlikun 0:13413ea9a877 464 /*---------------------------- FMPI2Cx CR2 Configuration ----------------------*/
ganlikun 0:13413ea9a877 465 /* Configure FMPI2Cx: Addressing Master mode */
ganlikun 0:13413ea9a877 466 if(hfmpi2c->Init.AddressingMode == FMPI2C_ADDRESSINGMODE_10BIT)
ganlikun 0:13413ea9a877 467 {
ganlikun 0:13413ea9a877 468 hfmpi2c->Instance->CR2 = (FMPI2C_CR2_ADD10);
ganlikun 0:13413ea9a877 469 }
ganlikun 0:13413ea9a877 470 /* Enable the AUTOEND by default, and enable NACK (should be disable only during Slave process */
ganlikun 0:13413ea9a877 471 hfmpi2c->Instance->CR2 |= (FMPI2C_CR2_AUTOEND | FMPI2C_CR2_NACK);
ganlikun 0:13413ea9a877 472
ganlikun 0:13413ea9a877 473 /*---------------------------- FMPI2Cx OAR2 Configuration ---------------------*/
ganlikun 0:13413ea9a877 474 /* Disable Own Address2 before set the Own Address2 configuration */
ganlikun 0:13413ea9a877 475 hfmpi2c->Instance->OAR2 &= ~FMPI2C_DUALADDRESS_ENABLE;
ganlikun 0:13413ea9a877 476
ganlikun 0:13413ea9a877 477 /* Configure FMPI2Cx: Dual mode and Own Address2 */
ganlikun 0:13413ea9a877 478 hfmpi2c->Instance->OAR2 = (hfmpi2c->Init.DualAddressMode | hfmpi2c->Init.OwnAddress2 | (hfmpi2c->Init.OwnAddress2Masks << 8));
ganlikun 0:13413ea9a877 479
ganlikun 0:13413ea9a877 480 /*---------------------------- FMPI2Cx CR1 Configuration ----------------------*/
ganlikun 0:13413ea9a877 481 /* Configure FMPI2Cx: Generalcall and NoStretch mode */
ganlikun 0:13413ea9a877 482 hfmpi2c->Instance->CR1 = (hfmpi2c->Init.GeneralCallMode | hfmpi2c->Init.NoStretchMode);
ganlikun 0:13413ea9a877 483
ganlikun 0:13413ea9a877 484 /* Enable the selected FMPI2C peripheral */
ganlikun 0:13413ea9a877 485 __HAL_FMPI2C_ENABLE(hfmpi2c);
ganlikun 0:13413ea9a877 486
ganlikun 0:13413ea9a877 487 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 488 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 489 hfmpi2c->PreviousState = FMPI2C_STATE_NONE;
ganlikun 0:13413ea9a877 490 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 491
ganlikun 0:13413ea9a877 492 return HAL_OK;
ganlikun 0:13413ea9a877 493 }
ganlikun 0:13413ea9a877 494
ganlikun 0:13413ea9a877 495 /**
ganlikun 0:13413ea9a877 496 * @brief DeInitialize the FMPI2C peripheral.
ganlikun 0:13413ea9a877 497 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 498 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 499 * @retval HAL status
ganlikun 0:13413ea9a877 500 */
ganlikun 0:13413ea9a877 501 HAL_StatusTypeDef HAL_FMPI2C_DeInit(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 502 {
ganlikun 0:13413ea9a877 503 /* Check the FMPI2C handle allocation */
ganlikun 0:13413ea9a877 504 if(hfmpi2c == NULL)
ganlikun 0:13413ea9a877 505 {
ganlikun 0:13413ea9a877 506 return HAL_ERROR;
ganlikun 0:13413ea9a877 507 }
ganlikun 0:13413ea9a877 508
ganlikun 0:13413ea9a877 509 /* Check the parameters */
ganlikun 0:13413ea9a877 510 assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
ganlikun 0:13413ea9a877 511
ganlikun 0:13413ea9a877 512 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
ganlikun 0:13413ea9a877 513
ganlikun 0:13413ea9a877 514 /* Disable the FMPI2C Peripheral Clock */
ganlikun 0:13413ea9a877 515 __HAL_FMPI2C_DISABLE(hfmpi2c);
ganlikun 0:13413ea9a877 516
ganlikun 0:13413ea9a877 517 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
ganlikun 0:13413ea9a877 518 HAL_FMPI2C_MspDeInit(hfmpi2c);
ganlikun 0:13413ea9a877 519
ganlikun 0:13413ea9a877 520 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 521 hfmpi2c->State = HAL_FMPI2C_STATE_RESET;
ganlikun 0:13413ea9a877 522 hfmpi2c->PreviousState = FMPI2C_STATE_NONE;
ganlikun 0:13413ea9a877 523 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 524
ganlikun 0:13413ea9a877 525 /* Release Lock */
ganlikun 0:13413ea9a877 526 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 527
ganlikun 0:13413ea9a877 528 return HAL_OK;
ganlikun 0:13413ea9a877 529 }
ganlikun 0:13413ea9a877 530
ganlikun 0:13413ea9a877 531 /**
ganlikun 0:13413ea9a877 532 * @brief Initialize the FMPI2C MSP.
ganlikun 0:13413ea9a877 533 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 534 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 535 * @retval None
ganlikun 0:13413ea9a877 536 */
ganlikun 0:13413ea9a877 537 __weak void HAL_FMPI2C_MspInit(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 538 {
ganlikun 0:13413ea9a877 539 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 540 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 541
ganlikun 0:13413ea9a877 542 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 543 the HAL_FMPI2C_MspInit could be implemented in the user file
ganlikun 0:13413ea9a877 544 */
ganlikun 0:13413ea9a877 545 }
ganlikun 0:13413ea9a877 546
ganlikun 0:13413ea9a877 547 /**
ganlikun 0:13413ea9a877 548 * @brief DeInitialize the FMPI2C MSP.
ganlikun 0:13413ea9a877 549 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 550 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 551 * @retval None
ganlikun 0:13413ea9a877 552 */
ganlikun 0:13413ea9a877 553 __weak void HAL_FMPI2C_MspDeInit(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 554 {
ganlikun 0:13413ea9a877 555 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 556 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 557
ganlikun 0:13413ea9a877 558 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 559 the HAL_FMPI2C_MspDeInit could be implemented in the user file
ganlikun 0:13413ea9a877 560 */
ganlikun 0:13413ea9a877 561 }
ganlikun 0:13413ea9a877 562
ganlikun 0:13413ea9a877 563 /**
ganlikun 0:13413ea9a877 564 * @}
ganlikun 0:13413ea9a877 565 */
ganlikun 0:13413ea9a877 566
ganlikun 0:13413ea9a877 567 /** @defgroup FMPI2C_Exported_Functions_Group2 Input and Output operation functions
ganlikun 0:13413ea9a877 568 * @brief Data transfers functions
ganlikun 0:13413ea9a877 569 *
ganlikun 0:13413ea9a877 570 @verbatim
ganlikun 0:13413ea9a877 571 ===============================================================================
ganlikun 0:13413ea9a877 572 ##### IO operation functions #####
ganlikun 0:13413ea9a877 573 ===============================================================================
ganlikun 0:13413ea9a877 574 [..]
ganlikun 0:13413ea9a877 575 This subsection provides a set of functions allowing to manage the FMPI2C data
ganlikun 0:13413ea9a877 576 transfers.
ganlikun 0:13413ea9a877 577
ganlikun 0:13413ea9a877 578 (#) There are two modes of transfer:
ganlikun 0:13413ea9a877 579 (++) Blocking mode : The communication is performed in the polling mode.
ganlikun 0:13413ea9a877 580 The status of all data processing is returned by the same function
ganlikun 0:13413ea9a877 581 after finishing transfer.
ganlikun 0:13413ea9a877 582 (++) No-Blocking mode : The communication is performed using Interrupts
ganlikun 0:13413ea9a877 583 or DMA. These functions return the status of the transfer startup.
ganlikun 0:13413ea9a877 584 The end of the data processing will be indicated through the
ganlikun 0:13413ea9a877 585 dedicated FMPI2C IRQ when using Interrupt mode or the DMA IRQ when
ganlikun 0:13413ea9a877 586 using DMA mode.
ganlikun 0:13413ea9a877 587
ganlikun 0:13413ea9a877 588 (#) Blocking mode functions are :
ganlikun 0:13413ea9a877 589 (++) HAL_FMPI2C_Master_Transmit()
ganlikun 0:13413ea9a877 590 (++) HAL_FMPI2C_Master_Receive()
ganlikun 0:13413ea9a877 591 (++) HAL_FMPI2C_Slave_Transmit()
ganlikun 0:13413ea9a877 592 (++) HAL_FMPI2C_Slave_Receive()
ganlikun 0:13413ea9a877 593 (++) HAL_FMPI2C_Mem_Write()
ganlikun 0:13413ea9a877 594 (++) HAL_FMPI2C_Mem_Read()
ganlikun 0:13413ea9a877 595 (++) HAL_FMPI2C_IsDeviceReady()
ganlikun 0:13413ea9a877 596
ganlikun 0:13413ea9a877 597 (#) No-Blocking mode functions with Interrupt are :
ganlikun 0:13413ea9a877 598 (++) HAL_FMPI2C_Master_Transmit_IT()
ganlikun 0:13413ea9a877 599 (++) HAL_FMPI2C_Master_Receive_IT()
ganlikun 0:13413ea9a877 600 (++) HAL_FMPI2C_Slave_Transmit_IT()
ganlikun 0:13413ea9a877 601 (++) HAL_FMPI2C_Slave_Receive_IT()
ganlikun 0:13413ea9a877 602 (++) HAL_FMPI2C_Master_Sequential_Transmit_IT()
ganlikun 0:13413ea9a877 603 (++) HAL_FMPI2C_Master_Sequential_Receive_IT()
ganlikun 0:13413ea9a877 604 (++) HAL_FMPI2C_Slave_Sequential_Transmit_IT()
ganlikun 0:13413ea9a877 605 (++) HAL_FMPI2C_Slave_Sequential_Receive_IT()
ganlikun 0:13413ea9a877 606 (++) HAL_FMPI2C_Mem_Write_IT()
ganlikun 0:13413ea9a877 607 (++) HAL_FMPI2C_Mem_Read_IT()
ganlikun 0:13413ea9a877 608
ganlikun 0:13413ea9a877 609 (#) No-Blocking mode functions with DMA are :
ganlikun 0:13413ea9a877 610 (++) HAL_FMPI2C_Master_Transmit_DMA()
ganlikun 0:13413ea9a877 611 (++) HAL_FMPI2C_Master_Receive_DMA()
ganlikun 0:13413ea9a877 612 (++) HAL_FMPI2C_Slave_Transmit_DMA()
ganlikun 0:13413ea9a877 613 (++) HAL_FMPI2C_Slave_Receive_DMA()
ganlikun 0:13413ea9a877 614 (++) HAL_FMPI2C_Mem_Write_DMA()
ganlikun 0:13413ea9a877 615 (++) HAL_FMPI2C_Mem_Read_DMA()
ganlikun 0:13413ea9a877 616
ganlikun 0:13413ea9a877 617 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
ganlikun 0:13413ea9a877 618 (++) HAL_FMPI2C_MemTxCpltCallback()
ganlikun 0:13413ea9a877 619 (++) HAL_FMPI2C_MemRxCpltCallback()
ganlikun 0:13413ea9a877 620 (++) HAL_FMPI2C_MasterTxCpltCallback()
ganlikun 0:13413ea9a877 621 (++) HAL_FMPI2C_MasterRxCpltCallback()
ganlikun 0:13413ea9a877 622 (++) HAL_FMPI2C_SlaveTxCpltCallback()
ganlikun 0:13413ea9a877 623 (++) HAL_FMPI2C_SlaveRxCpltCallback()
ganlikun 0:13413ea9a877 624 (++) HAL_FMPI2C_ErrorCallback()
ganlikun 0:13413ea9a877 625 (++) HAL_FMPI2C_AbortCpltCallback()
ganlikun 0:13413ea9a877 626
ganlikun 0:13413ea9a877 627 @endverbatim
ganlikun 0:13413ea9a877 628 * @{
ganlikun 0:13413ea9a877 629 */
ganlikun 0:13413ea9a877 630
ganlikun 0:13413ea9a877 631 /**
ganlikun 0:13413ea9a877 632 * @brief Transmits in master mode an amount of data in blocking mode.
ganlikun 0:13413ea9a877 633 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 634 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 635 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 636 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 637 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 638 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 639 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 640 * @retval HAL status
ganlikun 0:13413ea9a877 641 */
ganlikun 0:13413ea9a877 642 HAL_StatusTypeDef HAL_FMPI2C_Master_Transmit(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 643 {
ganlikun 0:13413ea9a877 644 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 645
ganlikun 0:13413ea9a877 646 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 647 {
ganlikun 0:13413ea9a877 648 /* Process Locked */
ganlikun 0:13413ea9a877 649 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 650
ganlikun 0:13413ea9a877 651 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 652 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 653
ganlikun 0:13413ea9a877 654 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_BUSY, SET, FMPI2C_TIMEOUT_BUSY, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 655 {
ganlikun 0:13413ea9a877 656 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 657 }
ganlikun 0:13413ea9a877 658
ganlikun 0:13413ea9a877 659 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 660 hfmpi2c->Mode = HAL_FMPI2C_MODE_MASTER;
ganlikun 0:13413ea9a877 661 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 662
ganlikun 0:13413ea9a877 663 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 664 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 665 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 666 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 667
ganlikun 0:13413ea9a877 668 /* Send Slave Address */
ganlikun 0:13413ea9a877 669 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 670 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 671 {
ganlikun 0:13413ea9a877 672 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 673 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_GENERATE_START_WRITE);
ganlikun 0:13413ea9a877 674 }
ganlikun 0:13413ea9a877 675 else
ganlikun 0:13413ea9a877 676 {
ganlikun 0:13413ea9a877 677 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 678 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_GENERATE_START_WRITE);
ganlikun 0:13413ea9a877 679 }
ganlikun 0:13413ea9a877 680
ganlikun 0:13413ea9a877 681 while(hfmpi2c->XferSize > 0U)
ganlikun 0:13413ea9a877 682 {
ganlikun 0:13413ea9a877 683 /* Wait until TXIS flag is set */
ganlikun 0:13413ea9a877 684 if(FMPI2C_WaitOnTXISFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 685 {
ganlikun 0:13413ea9a877 686 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 687 {
ganlikun 0:13413ea9a877 688 return HAL_ERROR;
ganlikun 0:13413ea9a877 689 }
ganlikun 0:13413ea9a877 690 else
ganlikun 0:13413ea9a877 691 {
ganlikun 0:13413ea9a877 692 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 693 }
ganlikun 0:13413ea9a877 694 }
ganlikun 0:13413ea9a877 695 /* Write data to TXDR */
ganlikun 0:13413ea9a877 696 hfmpi2c->Instance->TXDR = (*hfmpi2c->pBuffPtr++);
ganlikun 0:13413ea9a877 697 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 698 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 699
ganlikun 0:13413ea9a877 700 if((hfmpi2c->XferSize == 0U) && (hfmpi2c->XferCount!=0U))
ganlikun 0:13413ea9a877 701 {
ganlikun 0:13413ea9a877 702 /* Wait until TCR flag is set */
ganlikun 0:13413ea9a877 703 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_TCR, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 704 {
ganlikun 0:13413ea9a877 705 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 706 }
ganlikun 0:13413ea9a877 707
ganlikun 0:13413ea9a877 708 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 709 {
ganlikun 0:13413ea9a877 710 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 711 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 712 }
ganlikun 0:13413ea9a877 713 else
ganlikun 0:13413ea9a877 714 {
ganlikun 0:13413ea9a877 715 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 716 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 717 }
ganlikun 0:13413ea9a877 718 }
ganlikun 0:13413ea9a877 719 }
ganlikun 0:13413ea9a877 720
ganlikun 0:13413ea9a877 721 /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */
ganlikun 0:13413ea9a877 722 /* Wait until STOPF flag is set */
ganlikun 0:13413ea9a877 723 if(FMPI2C_WaitOnSTOPFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 724 {
ganlikun 0:13413ea9a877 725 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 726 {
ganlikun 0:13413ea9a877 727 return HAL_ERROR;
ganlikun 0:13413ea9a877 728 }
ganlikun 0:13413ea9a877 729 else
ganlikun 0:13413ea9a877 730 {
ganlikun 0:13413ea9a877 731 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 732 }
ganlikun 0:13413ea9a877 733 }
ganlikun 0:13413ea9a877 734
ganlikun 0:13413ea9a877 735 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 736 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 737
ganlikun 0:13413ea9a877 738 /* Clear Configuration Register 2 */
ganlikun 0:13413ea9a877 739 FMPI2C_RESET_CR2(hfmpi2c);
ganlikun 0:13413ea9a877 740
ganlikun 0:13413ea9a877 741 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 742 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 743
ganlikun 0:13413ea9a877 744 /* Process Unlocked */
ganlikun 0:13413ea9a877 745 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 746
ganlikun 0:13413ea9a877 747 return HAL_OK;
ganlikun 0:13413ea9a877 748 }
ganlikun 0:13413ea9a877 749 else
ganlikun 0:13413ea9a877 750 {
ganlikun 0:13413ea9a877 751 return HAL_BUSY;
ganlikun 0:13413ea9a877 752 }
ganlikun 0:13413ea9a877 753 }
ganlikun 0:13413ea9a877 754
ganlikun 0:13413ea9a877 755 /**
ganlikun 0:13413ea9a877 756 * @brief Receives in master mode an amount of data in blocking mode.
ganlikun 0:13413ea9a877 757 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 758 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 759 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 760 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 761 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 762 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 763 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 764 * @retval HAL status
ganlikun 0:13413ea9a877 765 */
ganlikun 0:13413ea9a877 766 HAL_StatusTypeDef HAL_FMPI2C_Master_Receive(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 767 {
ganlikun 0:13413ea9a877 768 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 769
ganlikun 0:13413ea9a877 770 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 771 {
ganlikun 0:13413ea9a877 772 /* Process Locked */
ganlikun 0:13413ea9a877 773 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 774
ganlikun 0:13413ea9a877 775 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 776 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 777
ganlikun 0:13413ea9a877 778 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_BUSY, SET, FMPI2C_TIMEOUT_BUSY, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 779 {
ganlikun 0:13413ea9a877 780 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 781 }
ganlikun 0:13413ea9a877 782
ganlikun 0:13413ea9a877 783 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 784 hfmpi2c->Mode = HAL_FMPI2C_MODE_MASTER;
ganlikun 0:13413ea9a877 785 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 786
ganlikun 0:13413ea9a877 787 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 788 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 789 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 790 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 791
ganlikun 0:13413ea9a877 792 /* Send Slave Address */
ganlikun 0:13413ea9a877 793 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 794 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 795 {
ganlikun 0:13413ea9a877 796 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 797 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_GENERATE_START_READ);
ganlikun 0:13413ea9a877 798 }
ganlikun 0:13413ea9a877 799 else
ganlikun 0:13413ea9a877 800 {
ganlikun 0:13413ea9a877 801 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 802 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_GENERATE_START_READ);
ganlikun 0:13413ea9a877 803 }
ganlikun 0:13413ea9a877 804
ganlikun 0:13413ea9a877 805 while(hfmpi2c->XferSize > 0U)
ganlikun 0:13413ea9a877 806 {
ganlikun 0:13413ea9a877 807 /* Wait until RXNE flag is set */
ganlikun 0:13413ea9a877 808 if(FMPI2C_WaitOnRXNEFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 809 {
ganlikun 0:13413ea9a877 810 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 811 {
ganlikun 0:13413ea9a877 812 return HAL_ERROR;
ganlikun 0:13413ea9a877 813 }
ganlikun 0:13413ea9a877 814 else
ganlikun 0:13413ea9a877 815 {
ganlikun 0:13413ea9a877 816 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 817 }
ganlikun 0:13413ea9a877 818 }
ganlikun 0:13413ea9a877 819
ganlikun 0:13413ea9a877 820 /* Read data from RXDR */
ganlikun 0:13413ea9a877 821 (*hfmpi2c->pBuffPtr++) = hfmpi2c->Instance->RXDR;
ganlikun 0:13413ea9a877 822 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 823 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 824
ganlikun 0:13413ea9a877 825 if((hfmpi2c->XferSize == 0U) && (hfmpi2c->XferCount != 0U))
ganlikun 0:13413ea9a877 826 {
ganlikun 0:13413ea9a877 827 /* Wait until TCR flag is set */
ganlikun 0:13413ea9a877 828 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_TCR, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 829 {
ganlikun 0:13413ea9a877 830 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 831 }
ganlikun 0:13413ea9a877 832
ganlikun 0:13413ea9a877 833 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 834 {
ganlikun 0:13413ea9a877 835 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 836 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 837 }
ganlikun 0:13413ea9a877 838 else
ganlikun 0:13413ea9a877 839 {
ganlikun 0:13413ea9a877 840 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 841 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 842 }
ganlikun 0:13413ea9a877 843 }
ganlikun 0:13413ea9a877 844 }
ganlikun 0:13413ea9a877 845
ganlikun 0:13413ea9a877 846 /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */
ganlikun 0:13413ea9a877 847 /* Wait until STOPF flag is set */
ganlikun 0:13413ea9a877 848 if(FMPI2C_WaitOnSTOPFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 849 {
ganlikun 0:13413ea9a877 850 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 851 {
ganlikun 0:13413ea9a877 852 return HAL_ERROR;
ganlikun 0:13413ea9a877 853 }
ganlikun 0:13413ea9a877 854 else
ganlikun 0:13413ea9a877 855 {
ganlikun 0:13413ea9a877 856 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 857 }
ganlikun 0:13413ea9a877 858 }
ganlikun 0:13413ea9a877 859
ganlikun 0:13413ea9a877 860 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 861 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 862
ganlikun 0:13413ea9a877 863 /* Clear Configuration Register 2 */
ganlikun 0:13413ea9a877 864 FMPI2C_RESET_CR2(hfmpi2c);
ganlikun 0:13413ea9a877 865
ganlikun 0:13413ea9a877 866 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 867 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 868
ganlikun 0:13413ea9a877 869 /* Process Unlocked */
ganlikun 0:13413ea9a877 870 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 871
ganlikun 0:13413ea9a877 872 return HAL_OK;
ganlikun 0:13413ea9a877 873 }
ganlikun 0:13413ea9a877 874 else
ganlikun 0:13413ea9a877 875 {
ganlikun 0:13413ea9a877 876 return HAL_BUSY;
ganlikun 0:13413ea9a877 877 }
ganlikun 0:13413ea9a877 878 }
ganlikun 0:13413ea9a877 879
ganlikun 0:13413ea9a877 880 /**
ganlikun 0:13413ea9a877 881 * @brief Transmits in slave mode an amount of data in blocking mode.
ganlikun 0:13413ea9a877 882 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 883 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 884 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 885 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 886 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 887 * @retval HAL status
ganlikun 0:13413ea9a877 888 */
ganlikun 0:13413ea9a877 889 HAL_StatusTypeDef HAL_FMPI2C_Slave_Transmit(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 890 {
ganlikun 0:13413ea9a877 891 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 892
ganlikun 0:13413ea9a877 893 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 894 {
ganlikun 0:13413ea9a877 895 if((pData == NULL ) || (Size == 0U))
ganlikun 0:13413ea9a877 896 {
ganlikun 0:13413ea9a877 897 return HAL_ERROR;
ganlikun 0:13413ea9a877 898 }
ganlikun 0:13413ea9a877 899 /* Process Locked */
ganlikun 0:13413ea9a877 900 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 901
ganlikun 0:13413ea9a877 902 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 903 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 904
ganlikun 0:13413ea9a877 905 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 906 hfmpi2c->Mode = HAL_FMPI2C_MODE_SLAVE;
ganlikun 0:13413ea9a877 907 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 908
ganlikun 0:13413ea9a877 909 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 910 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 911 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 912 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 913
ganlikun 0:13413ea9a877 914 /* Enable Address Acknowledge */
ganlikun 0:13413ea9a877 915 hfmpi2c->Instance->CR2 &= ~FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 916
ganlikun 0:13413ea9a877 917 /* Wait until ADDR flag is set */
ganlikun 0:13413ea9a877 918 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_ADDR, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 919 {
ganlikun 0:13413ea9a877 920 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 921 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 922 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 923 }
ganlikun 0:13413ea9a877 924
ganlikun 0:13413ea9a877 925 /* Clear ADDR flag */
ganlikun 0:13413ea9a877 926 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 927
ganlikun 0:13413ea9a877 928 /* If 10bit addressing mode is selected */
ganlikun 0:13413ea9a877 929 if(hfmpi2c->Init.AddressingMode == FMPI2C_ADDRESSINGMODE_10BIT)
ganlikun 0:13413ea9a877 930 {
ganlikun 0:13413ea9a877 931 /* Wait until ADDR flag is set */
ganlikun 0:13413ea9a877 932 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_ADDR, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 933 {
ganlikun 0:13413ea9a877 934 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 935 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 936 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 937 }
ganlikun 0:13413ea9a877 938
ganlikun 0:13413ea9a877 939 /* Clear ADDR flag */
ganlikun 0:13413ea9a877 940 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 941 }
ganlikun 0:13413ea9a877 942
ganlikun 0:13413ea9a877 943 /* Wait until DIR flag is set Transmitter mode */
ganlikun 0:13413ea9a877 944 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_DIR, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 945 {
ganlikun 0:13413ea9a877 946 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 947 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 948 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 949 }
ganlikun 0:13413ea9a877 950
ganlikun 0:13413ea9a877 951 while(hfmpi2c->XferCount > 0U)
ganlikun 0:13413ea9a877 952 {
ganlikun 0:13413ea9a877 953 /* Wait until TXIS flag is set */
ganlikun 0:13413ea9a877 954 if(FMPI2C_WaitOnTXISFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 955 {
ganlikun 0:13413ea9a877 956 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 957 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 958
ganlikun 0:13413ea9a877 959 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 960 {
ganlikun 0:13413ea9a877 961 return HAL_ERROR;
ganlikun 0:13413ea9a877 962 }
ganlikun 0:13413ea9a877 963 else
ganlikun 0:13413ea9a877 964 {
ganlikun 0:13413ea9a877 965 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 966 }
ganlikun 0:13413ea9a877 967 }
ganlikun 0:13413ea9a877 968
ganlikun 0:13413ea9a877 969 /* Write data to TXDR */
ganlikun 0:13413ea9a877 970 hfmpi2c->Instance->TXDR = (*hfmpi2c->pBuffPtr++);
ganlikun 0:13413ea9a877 971 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 972 }
ganlikun 0:13413ea9a877 973
ganlikun 0:13413ea9a877 974 /* Wait until STOP flag is set */
ganlikun 0:13413ea9a877 975 if(FMPI2C_WaitOnSTOPFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 976 {
ganlikun 0:13413ea9a877 977 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 978 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 979
ganlikun 0:13413ea9a877 980 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 981 {
ganlikun 0:13413ea9a877 982 /* Normal use case for Transmitter mode */
ganlikun 0:13413ea9a877 983 /* A NACK is generated to confirm the end of transfer */
ganlikun 0:13413ea9a877 984 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 985 }
ganlikun 0:13413ea9a877 986 else
ganlikun 0:13413ea9a877 987 {
ganlikun 0:13413ea9a877 988 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 989 }
ganlikun 0:13413ea9a877 990 }
ganlikun 0:13413ea9a877 991
ganlikun 0:13413ea9a877 992 /* Clear STOP flag */
ganlikun 0:13413ea9a877 993 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 994
ganlikun 0:13413ea9a877 995 /* Wait until BUSY flag is reset */
ganlikun 0:13413ea9a877 996 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_BUSY, SET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 997 {
ganlikun 0:13413ea9a877 998 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 999 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1000 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1001 }
ganlikun 0:13413ea9a877 1002
ganlikun 0:13413ea9a877 1003 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 1004 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1005
ganlikun 0:13413ea9a877 1006 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 1007 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 1008
ganlikun 0:13413ea9a877 1009 /* Process Unlocked */
ganlikun 0:13413ea9a877 1010 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1011
ganlikun 0:13413ea9a877 1012 return HAL_OK;
ganlikun 0:13413ea9a877 1013 }
ganlikun 0:13413ea9a877 1014 else
ganlikun 0:13413ea9a877 1015 {
ganlikun 0:13413ea9a877 1016 return HAL_BUSY;
ganlikun 0:13413ea9a877 1017 }
ganlikun 0:13413ea9a877 1018 }
ganlikun 0:13413ea9a877 1019
ganlikun 0:13413ea9a877 1020 /**
ganlikun 0:13413ea9a877 1021 * @brief Receive in slave mode an amount of data in blocking mode
ganlikun 0:13413ea9a877 1022 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1023 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1024 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1025 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1026 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 1027 * @retval HAL status
ganlikun 0:13413ea9a877 1028 */
ganlikun 0:13413ea9a877 1029 HAL_StatusTypeDef HAL_FMPI2C_Slave_Receive(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 1030 {
ganlikun 0:13413ea9a877 1031 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 1032
ganlikun 0:13413ea9a877 1033 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1034 {
ganlikun 0:13413ea9a877 1035 if((pData == NULL ) || (Size == 0U))
ganlikun 0:13413ea9a877 1036 {
ganlikun 0:13413ea9a877 1037 return HAL_ERROR;
ganlikun 0:13413ea9a877 1038 }
ganlikun 0:13413ea9a877 1039 /* Process Locked */
ganlikun 0:13413ea9a877 1040 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1041
ganlikun 0:13413ea9a877 1042 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 1043 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 1044
ganlikun 0:13413ea9a877 1045 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 1046 hfmpi2c->Mode = HAL_FMPI2C_MODE_SLAVE;
ganlikun 0:13413ea9a877 1047 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1048
ganlikun 0:13413ea9a877 1049 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1050 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1051 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1052 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 1053
ganlikun 0:13413ea9a877 1054 /* Enable Address Acknowledge */
ganlikun 0:13413ea9a877 1055 hfmpi2c->Instance->CR2 &= ~FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1056
ganlikun 0:13413ea9a877 1057 /* Wait until ADDR flag is set */
ganlikun 0:13413ea9a877 1058 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_ADDR, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1059 {
ganlikun 0:13413ea9a877 1060 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 1061 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1062 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1063 }
ganlikun 0:13413ea9a877 1064
ganlikun 0:13413ea9a877 1065 /* Clear ADDR flag */
ganlikun 0:13413ea9a877 1066 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 1067
ganlikun 0:13413ea9a877 1068 /* Wait until DIR flag is reset Receiver mode */
ganlikun 0:13413ea9a877 1069 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_DIR, SET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1070 {
ganlikun 0:13413ea9a877 1071 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 1072 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1073 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1074 }
ganlikun 0:13413ea9a877 1075
ganlikun 0:13413ea9a877 1076 while(hfmpi2c->XferCount > 0U)
ganlikun 0:13413ea9a877 1077 {
ganlikun 0:13413ea9a877 1078 /* Wait until RXNE flag is set */
ganlikun 0:13413ea9a877 1079 if(FMPI2C_WaitOnRXNEFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1080 {
ganlikun 0:13413ea9a877 1081 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 1082 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1083
ganlikun 0:13413ea9a877 1084 /* Store Last receive data if any */
ganlikun 0:13413ea9a877 1085 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_RXNE) == SET)
ganlikun 0:13413ea9a877 1086 {
ganlikun 0:13413ea9a877 1087 /* Read data from RXDR */
ganlikun 0:13413ea9a877 1088 (*hfmpi2c->pBuffPtr++) = hfmpi2c->Instance->RXDR;
ganlikun 0:13413ea9a877 1089 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 1090 }
ganlikun 0:13413ea9a877 1091
ganlikun 0:13413ea9a877 1092 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_TIMEOUT)
ganlikun 0:13413ea9a877 1093 {
ganlikun 0:13413ea9a877 1094 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1095 }
ganlikun 0:13413ea9a877 1096 else
ganlikun 0:13413ea9a877 1097 {
ganlikun 0:13413ea9a877 1098 return HAL_ERROR;
ganlikun 0:13413ea9a877 1099 }
ganlikun 0:13413ea9a877 1100 }
ganlikun 0:13413ea9a877 1101
ganlikun 0:13413ea9a877 1102 /* Read data from RXDR */
ganlikun 0:13413ea9a877 1103 (*hfmpi2c->pBuffPtr++) = hfmpi2c->Instance->RXDR;
ganlikun 0:13413ea9a877 1104 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 1105 }
ganlikun 0:13413ea9a877 1106
ganlikun 0:13413ea9a877 1107 /* Wait until STOP flag is set */
ganlikun 0:13413ea9a877 1108 if(FMPI2C_WaitOnSTOPFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1109 {
ganlikun 0:13413ea9a877 1110 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 1111 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1112
ganlikun 0:13413ea9a877 1113 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 1114 {
ganlikun 0:13413ea9a877 1115 return HAL_ERROR;
ganlikun 0:13413ea9a877 1116 }
ganlikun 0:13413ea9a877 1117 else
ganlikun 0:13413ea9a877 1118 {
ganlikun 0:13413ea9a877 1119 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1120 }
ganlikun 0:13413ea9a877 1121 }
ganlikun 0:13413ea9a877 1122
ganlikun 0:13413ea9a877 1123 /* Clear STOP flag */
ganlikun 0:13413ea9a877 1124 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 1125
ganlikun 0:13413ea9a877 1126 /* Wait until BUSY flag is reset */
ganlikun 0:13413ea9a877 1127 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_BUSY, SET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1128 {
ganlikun 0:13413ea9a877 1129 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 1130 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1131 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1132 }
ganlikun 0:13413ea9a877 1133
ganlikun 0:13413ea9a877 1134 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 1135 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1136
ganlikun 0:13413ea9a877 1137 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 1138 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 1139
ganlikun 0:13413ea9a877 1140 /* Process Unlocked */
ganlikun 0:13413ea9a877 1141 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1142
ganlikun 0:13413ea9a877 1143 return HAL_OK;
ganlikun 0:13413ea9a877 1144 }
ganlikun 0:13413ea9a877 1145 else
ganlikun 0:13413ea9a877 1146 {
ganlikun 0:13413ea9a877 1147 return HAL_BUSY;
ganlikun 0:13413ea9a877 1148 }
ganlikun 0:13413ea9a877 1149 }
ganlikun 0:13413ea9a877 1150
ganlikun 0:13413ea9a877 1151 /**
ganlikun 0:13413ea9a877 1152 * @brief Transmit in master mode an amount of data in non-blocking mode with Interrupt
ganlikun 0:13413ea9a877 1153 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1154 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1155 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 1156 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 1157 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1158 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1159 * @retval HAL status
ganlikun 0:13413ea9a877 1160 */
ganlikun 0:13413ea9a877 1161 HAL_StatusTypeDef HAL_FMPI2C_Master_Transmit_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 1162 {
ganlikun 0:13413ea9a877 1163 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 1164
ganlikun 0:13413ea9a877 1165 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1166 {
ganlikun 0:13413ea9a877 1167 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 1168 {
ganlikun 0:13413ea9a877 1169 return HAL_BUSY;
ganlikun 0:13413ea9a877 1170 }
ganlikun 0:13413ea9a877 1171
ganlikun 0:13413ea9a877 1172 /* Process Locked */
ganlikun 0:13413ea9a877 1173 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1174
ganlikun 0:13413ea9a877 1175 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 1176 hfmpi2c->Mode = HAL_FMPI2C_MODE_MASTER;
ganlikun 0:13413ea9a877 1177 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1178
ganlikun 0:13413ea9a877 1179 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1180 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1181 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1182 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 1183 hfmpi2c->XferISR = FMPI2C_Master_ISR_IT;
ganlikun 0:13413ea9a877 1184
ganlikun 0:13413ea9a877 1185 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 1186 {
ganlikun 0:13413ea9a877 1187 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 1188 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 1189 }
ganlikun 0:13413ea9a877 1190 else
ganlikun 0:13413ea9a877 1191 {
ganlikun 0:13413ea9a877 1192 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1193 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 1194 }
ganlikun 0:13413ea9a877 1195
ganlikun 0:13413ea9a877 1196 /* Send Slave Address */
ganlikun 0:13413ea9a877 1197 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE */
ganlikun 0:13413ea9a877 1198 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, xfermode, FMPI2C_GENERATE_START_WRITE);
ganlikun 0:13413ea9a877 1199
ganlikun 0:13413ea9a877 1200 /* Process Unlocked */
ganlikun 0:13413ea9a877 1201 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1202
ganlikun 0:13413ea9a877 1203 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 1204 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 1205 process unlock */
ganlikun 0:13413ea9a877 1206
ganlikun 0:13413ea9a877 1207 /* Enable ERR, TC, STOP, NACK, TXI interrupt */
ganlikun 0:13413ea9a877 1208 /* possible to enable all of these */
ganlikun 0:13413ea9a877 1209 /* FMPI2C_IT_ERRI | FMPI2C_IT_TCI| FMPI2C_IT_STOPI| FMPI2C_IT_NACKI | FMPI2C_IT_ADDRI | FMPI2C_IT_RXI | FMPI2C_IT_TXI */
ganlikun 0:13413ea9a877 1210 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 1211
ganlikun 0:13413ea9a877 1212 return HAL_OK;
ganlikun 0:13413ea9a877 1213 }
ganlikun 0:13413ea9a877 1214 else
ganlikun 0:13413ea9a877 1215 {
ganlikun 0:13413ea9a877 1216 return HAL_BUSY;
ganlikun 0:13413ea9a877 1217 }
ganlikun 0:13413ea9a877 1218 }
ganlikun 0:13413ea9a877 1219
ganlikun 0:13413ea9a877 1220 /**
ganlikun 0:13413ea9a877 1221 * @brief Receive in master mode an amount of data in non-blocking mode with Interrupt
ganlikun 0:13413ea9a877 1222 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1223 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1224 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 1225 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 1226 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1227 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1228 * @retval HAL status
ganlikun 0:13413ea9a877 1229 */
ganlikun 0:13413ea9a877 1230 HAL_StatusTypeDef HAL_FMPI2C_Master_Receive_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 1231 {
ganlikun 0:13413ea9a877 1232 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 1233
ganlikun 0:13413ea9a877 1234 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1235 {
ganlikun 0:13413ea9a877 1236 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 1237 {
ganlikun 0:13413ea9a877 1238 return HAL_BUSY;
ganlikun 0:13413ea9a877 1239 }
ganlikun 0:13413ea9a877 1240
ganlikun 0:13413ea9a877 1241 /* Process Locked */
ganlikun 0:13413ea9a877 1242 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1243
ganlikun 0:13413ea9a877 1244 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 1245 hfmpi2c->Mode = HAL_FMPI2C_MODE_MASTER;
ganlikun 0:13413ea9a877 1246 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1247
ganlikun 0:13413ea9a877 1248 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1249 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1250 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1251 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 1252 hfmpi2c->XferISR = FMPI2C_Master_ISR_IT;
ganlikun 0:13413ea9a877 1253
ganlikun 0:13413ea9a877 1254 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 1255 {
ganlikun 0:13413ea9a877 1256 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 1257 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 1258 }
ganlikun 0:13413ea9a877 1259 else
ganlikun 0:13413ea9a877 1260 {
ganlikun 0:13413ea9a877 1261 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1262 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 1263 }
ganlikun 0:13413ea9a877 1264
ganlikun 0:13413ea9a877 1265 /* Send Slave Address */
ganlikun 0:13413ea9a877 1266 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE */
ganlikun 0:13413ea9a877 1267 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, xfermode, FMPI2C_GENERATE_START_READ);
ganlikun 0:13413ea9a877 1268
ganlikun 0:13413ea9a877 1269 /* Process Unlocked */
ganlikun 0:13413ea9a877 1270 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1271
ganlikun 0:13413ea9a877 1272 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 1273 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 1274 process unlock */
ganlikun 0:13413ea9a877 1275
ganlikun 0:13413ea9a877 1276 /* Enable ERR, TC, STOP, NACK, RXI interrupt */
ganlikun 0:13413ea9a877 1277 /* possible to enable all of these */
ganlikun 0:13413ea9a877 1278 /* FMPI2C_IT_ERRI | FMPI2C_IT_TCI| FMPI2C_IT_STOPI| FMPI2C_IT_NACKI | FMPI2C_IT_ADDRI | FMPI2C_IT_RXI | FMPI2C_IT_TXI */
ganlikun 0:13413ea9a877 1279 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 1280
ganlikun 0:13413ea9a877 1281 return HAL_OK;
ganlikun 0:13413ea9a877 1282 }
ganlikun 0:13413ea9a877 1283 else
ganlikun 0:13413ea9a877 1284 {
ganlikun 0:13413ea9a877 1285 return HAL_BUSY;
ganlikun 0:13413ea9a877 1286 }
ganlikun 0:13413ea9a877 1287 }
ganlikun 0:13413ea9a877 1288
ganlikun 0:13413ea9a877 1289 /**
ganlikun 0:13413ea9a877 1290 * @brief Transmit in slave mode an amount of data in non-blocking mode with Interrupt
ganlikun 0:13413ea9a877 1291 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1292 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1293 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1294 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1295 * @retval HAL status
ganlikun 0:13413ea9a877 1296 */
ganlikun 0:13413ea9a877 1297 HAL_StatusTypeDef HAL_FMPI2C_Slave_Transmit_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 1298 {
ganlikun 0:13413ea9a877 1299 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1300 {
ganlikun 0:13413ea9a877 1301 /* Process Locked */
ganlikun 0:13413ea9a877 1302 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1303
ganlikun 0:13413ea9a877 1304 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 1305 hfmpi2c->Mode = HAL_FMPI2C_MODE_SLAVE;
ganlikun 0:13413ea9a877 1306 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1307
ganlikun 0:13413ea9a877 1308 /* Enable Address Acknowledge */
ganlikun 0:13413ea9a877 1309 hfmpi2c->Instance->CR2 &= ~FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1310
ganlikun 0:13413ea9a877 1311 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1312 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1313 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1314 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1315 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 1316 hfmpi2c->XferISR = FMPI2C_Slave_ISR_IT;
ganlikun 0:13413ea9a877 1317
ganlikun 0:13413ea9a877 1318 /* Process Unlocked */
ganlikun 0:13413ea9a877 1319 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1320
ganlikun 0:13413ea9a877 1321 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 1322 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 1323 process unlock */
ganlikun 0:13413ea9a877 1324
ganlikun 0:13413ea9a877 1325 /* Enable ERR, TC, STOP, NACK, TXI interrupt */
ganlikun 0:13413ea9a877 1326 /* possible to enable all of these */
ganlikun 0:13413ea9a877 1327 /* FMPI2C_IT_ERRI | FMPI2C_IT_TCI| FMPI2C_IT_STOPI| FMPI2C_IT_NACKI | FMPI2C_IT_ADDRI | FMPI2C_IT_RXI | FMPI2C_IT_TXI */
ganlikun 0:13413ea9a877 1328 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT | FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 1329
ganlikun 0:13413ea9a877 1330 return HAL_OK;
ganlikun 0:13413ea9a877 1331 }
ganlikun 0:13413ea9a877 1332 else
ganlikun 0:13413ea9a877 1333 {
ganlikun 0:13413ea9a877 1334 return HAL_BUSY;
ganlikun 0:13413ea9a877 1335 }
ganlikun 0:13413ea9a877 1336 }
ganlikun 0:13413ea9a877 1337
ganlikun 0:13413ea9a877 1338 /**
ganlikun 0:13413ea9a877 1339 * @brief Receive in slave mode an amount of data in non-blocking mode with Interrupt
ganlikun 0:13413ea9a877 1340 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1341 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1342 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1343 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1344 * @retval HAL status
ganlikun 0:13413ea9a877 1345 */
ganlikun 0:13413ea9a877 1346 HAL_StatusTypeDef HAL_FMPI2C_Slave_Receive_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 1347 {
ganlikun 0:13413ea9a877 1348 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1349 {
ganlikun 0:13413ea9a877 1350 /* Process Locked */
ganlikun 0:13413ea9a877 1351 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1352
ganlikun 0:13413ea9a877 1353 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 1354 hfmpi2c->Mode = HAL_FMPI2C_MODE_SLAVE;
ganlikun 0:13413ea9a877 1355 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1356
ganlikun 0:13413ea9a877 1357 /* Enable Address Acknowledge */
ganlikun 0:13413ea9a877 1358 hfmpi2c->Instance->CR2 &= ~FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1359
ganlikun 0:13413ea9a877 1360 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1361 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1362 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1363 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1364 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 1365 hfmpi2c->XferISR = FMPI2C_Slave_ISR_IT;
ganlikun 0:13413ea9a877 1366
ganlikun 0:13413ea9a877 1367 /* Process Unlocked */
ganlikun 0:13413ea9a877 1368 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1369
ganlikun 0:13413ea9a877 1370 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 1371 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 1372 process unlock */
ganlikun 0:13413ea9a877 1373
ganlikun 0:13413ea9a877 1374 /* Enable ERR, TC, STOP, NACK, RXI interrupt */
ganlikun 0:13413ea9a877 1375 /* possible to enable all of these */
ganlikun 0:13413ea9a877 1376 /* FMPI2C_IT_ERRI | FMPI2C_IT_TCI| FMPI2C_IT_STOPI| FMPI2C_IT_NACKI | FMPI2C_IT_ADDRI | FMPI2C_IT_RXI | FMPI2C_IT_TXI */
ganlikun 0:13413ea9a877 1377 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT | FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 1378
ganlikun 0:13413ea9a877 1379 return HAL_OK;
ganlikun 0:13413ea9a877 1380 }
ganlikun 0:13413ea9a877 1381 else
ganlikun 0:13413ea9a877 1382 {
ganlikun 0:13413ea9a877 1383 return HAL_BUSY;
ganlikun 0:13413ea9a877 1384 }
ganlikun 0:13413ea9a877 1385 }
ganlikun 0:13413ea9a877 1386
ganlikun 0:13413ea9a877 1387 /**
ganlikun 0:13413ea9a877 1388 * @brief Transmit in master mode an amount of data in non-blocking mode with DMA
ganlikun 0:13413ea9a877 1389 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1390 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1391 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 1392 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 1393 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1394 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1395 * @retval HAL status
ganlikun 0:13413ea9a877 1396 */
ganlikun 0:13413ea9a877 1397 HAL_StatusTypeDef HAL_FMPI2C_Master_Transmit_DMA(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 1398 {
ganlikun 0:13413ea9a877 1399 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 1400
ganlikun 0:13413ea9a877 1401 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1402 {
ganlikun 0:13413ea9a877 1403 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 1404 {
ganlikun 0:13413ea9a877 1405 return HAL_BUSY;
ganlikun 0:13413ea9a877 1406 }
ganlikun 0:13413ea9a877 1407
ganlikun 0:13413ea9a877 1408 /* Process Locked */
ganlikun 0:13413ea9a877 1409 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1410
ganlikun 0:13413ea9a877 1411 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 1412 hfmpi2c->Mode = HAL_FMPI2C_MODE_MASTER;
ganlikun 0:13413ea9a877 1413 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1414
ganlikun 0:13413ea9a877 1415 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1416 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1417 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1418 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 1419 hfmpi2c->XferISR = FMPI2C_Master_ISR_DMA;
ganlikun 0:13413ea9a877 1420
ganlikun 0:13413ea9a877 1421 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 1422 {
ganlikun 0:13413ea9a877 1423 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 1424 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 1425 }
ganlikun 0:13413ea9a877 1426 else
ganlikun 0:13413ea9a877 1427 {
ganlikun 0:13413ea9a877 1428 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1429 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 1430 }
ganlikun 0:13413ea9a877 1431
ganlikun 0:13413ea9a877 1432 /* Set the FMPI2C DMA transfer complete callback */
ganlikun 0:13413ea9a877 1433 hfmpi2c->hdmatx->XferCpltCallback = FMPI2C_DMAMasterTransmitCplt;
ganlikun 0:13413ea9a877 1434
ganlikun 0:13413ea9a877 1435 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1436 hfmpi2c->hdmatx->XferErrorCallback = FMPI2C_DMAError;
ganlikun 0:13413ea9a877 1437
ganlikun 0:13413ea9a877 1438 /* Set the unused DMA callbacks to NULL */
ganlikun 0:13413ea9a877 1439 hfmpi2c->hdmatx->XferHalfCpltCallback = NULL;
ganlikun 0:13413ea9a877 1440 hfmpi2c->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1441
ganlikun 0:13413ea9a877 1442 /* Enable the DMA channel */
ganlikun 0:13413ea9a877 1443 HAL_DMA_Start_IT(hfmpi2c->hdmatx, (uint32_t)pData, (uint32_t)&hfmpi2c->Instance->TXDR, hfmpi2c->XferSize);
ganlikun 0:13413ea9a877 1444
ganlikun 0:13413ea9a877 1445 /* Send Slave Address */
ganlikun 0:13413ea9a877 1446 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 1447 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, xfermode, FMPI2C_GENERATE_START_WRITE);
ganlikun 0:13413ea9a877 1448
ganlikun 0:13413ea9a877 1449 /* Update XferCount value */
ganlikun 0:13413ea9a877 1450 hfmpi2c->XferCount -= hfmpi2c->XferSize;
ganlikun 0:13413ea9a877 1451
ganlikun 0:13413ea9a877 1452 /* Process Unlocked */
ganlikun 0:13413ea9a877 1453 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1454
ganlikun 0:13413ea9a877 1455 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 1456 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 1457 process unlock */
ganlikun 0:13413ea9a877 1458 /* Enable ERR and NACK interrupts */
ganlikun 0:13413ea9a877 1459 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_ERROR_IT);
ganlikun 0:13413ea9a877 1460
ganlikun 0:13413ea9a877 1461 /* Enable DMA Request */
ganlikun 0:13413ea9a877 1462 hfmpi2c->Instance->CR1 |= FMPI2C_CR1_TXDMAEN;
ganlikun 0:13413ea9a877 1463
ganlikun 0:13413ea9a877 1464 return HAL_OK;
ganlikun 0:13413ea9a877 1465 }
ganlikun 0:13413ea9a877 1466 else
ganlikun 0:13413ea9a877 1467 {
ganlikun 0:13413ea9a877 1468 return HAL_BUSY;
ganlikun 0:13413ea9a877 1469 }
ganlikun 0:13413ea9a877 1470 }
ganlikun 0:13413ea9a877 1471
ganlikun 0:13413ea9a877 1472 /**
ganlikun 0:13413ea9a877 1473 * @brief Receive in master mode an amount of data in non-blocking mode with DMA
ganlikun 0:13413ea9a877 1474 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1475 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1476 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 1477 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 1478 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1479 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1480 * @retval HAL status
ganlikun 0:13413ea9a877 1481 */
ganlikun 0:13413ea9a877 1482 HAL_StatusTypeDef HAL_FMPI2C_Master_Receive_DMA(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 1483 {
ganlikun 0:13413ea9a877 1484 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 1485
ganlikun 0:13413ea9a877 1486 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1487 {
ganlikun 0:13413ea9a877 1488 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 1489 {
ganlikun 0:13413ea9a877 1490 return HAL_BUSY;
ganlikun 0:13413ea9a877 1491 }
ganlikun 0:13413ea9a877 1492
ganlikun 0:13413ea9a877 1493 /* Process Locked */
ganlikun 0:13413ea9a877 1494 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1495
ganlikun 0:13413ea9a877 1496 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 1497 hfmpi2c->Mode = HAL_FMPI2C_MODE_MASTER;
ganlikun 0:13413ea9a877 1498 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1499
ganlikun 0:13413ea9a877 1500 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1501 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1502 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1503 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 1504 hfmpi2c->XferISR = FMPI2C_Master_ISR_DMA;
ganlikun 0:13413ea9a877 1505
ganlikun 0:13413ea9a877 1506 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 1507 {
ganlikun 0:13413ea9a877 1508 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 1509 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 1510 }
ganlikun 0:13413ea9a877 1511 else
ganlikun 0:13413ea9a877 1512 {
ganlikun 0:13413ea9a877 1513 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1514 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 1515 }
ganlikun 0:13413ea9a877 1516
ganlikun 0:13413ea9a877 1517 if(hfmpi2c->XferSize > 0U)
ganlikun 0:13413ea9a877 1518 {
ganlikun 0:13413ea9a877 1519 /* Set the FMPI2C DMA transfer complete callback */
ganlikun 0:13413ea9a877 1520 hfmpi2c->hdmarx->XferCpltCallback = FMPI2C_DMAMasterReceiveCplt;
ganlikun 0:13413ea9a877 1521
ganlikun 0:13413ea9a877 1522 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1523 hfmpi2c->hdmarx->XferErrorCallback = FMPI2C_DMAError;
ganlikun 0:13413ea9a877 1524
ganlikun 0:13413ea9a877 1525 /* Set the unused DMA callbacks to NULL */
ganlikun 0:13413ea9a877 1526 hfmpi2c->hdmarx->XferHalfCpltCallback = NULL;
ganlikun 0:13413ea9a877 1527 hfmpi2c->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1528
ganlikun 0:13413ea9a877 1529 /* Enable the DMA channel */
ganlikun 0:13413ea9a877 1530 HAL_DMA_Start_IT(hfmpi2c->hdmarx, (uint32_t)&hfmpi2c->Instance->RXDR, (uint32_t)pData, hfmpi2c->XferSize);
ganlikun 0:13413ea9a877 1531
ganlikun 0:13413ea9a877 1532 /* Send Slave Address */
ganlikun 0:13413ea9a877 1533 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 1534 FMPI2C_TransferConfig(hfmpi2c,DevAddress,hfmpi2c->XferSize, xfermode, FMPI2C_GENERATE_START_READ);
ganlikun 0:13413ea9a877 1535
ganlikun 0:13413ea9a877 1536 /* Update XferCount value */
ganlikun 0:13413ea9a877 1537 hfmpi2c->XferCount -= hfmpi2c->XferSize;
ganlikun 0:13413ea9a877 1538
ganlikun 0:13413ea9a877 1539 /* Process Unlocked */
ganlikun 0:13413ea9a877 1540 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1541
ganlikun 0:13413ea9a877 1542 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 1543 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 1544 process unlock */
ganlikun 0:13413ea9a877 1545 /* Enable ERR and NACK interrupts */
ganlikun 0:13413ea9a877 1546 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_ERROR_IT);
ganlikun 0:13413ea9a877 1547
ganlikun 0:13413ea9a877 1548 /* Enable DMA Request */
ganlikun 0:13413ea9a877 1549 hfmpi2c->Instance->CR1 |= FMPI2C_CR1_RXDMAEN;
ganlikun 0:13413ea9a877 1550 }
ganlikun 0:13413ea9a877 1551 else
ganlikun 0:13413ea9a877 1552 {
ganlikun 0:13413ea9a877 1553 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 1554 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 1555
ganlikun 0:13413ea9a877 1556 /* Process Unlocked */
ganlikun 0:13413ea9a877 1557 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1558 }
ganlikun 0:13413ea9a877 1559 return HAL_OK;
ganlikun 0:13413ea9a877 1560 }
ganlikun 0:13413ea9a877 1561 else
ganlikun 0:13413ea9a877 1562 {
ganlikun 0:13413ea9a877 1563 return HAL_BUSY;
ganlikun 0:13413ea9a877 1564 }
ganlikun 0:13413ea9a877 1565 }
ganlikun 0:13413ea9a877 1566
ganlikun 0:13413ea9a877 1567 /**
ganlikun 0:13413ea9a877 1568 * @brief Transmit in slave mode an amount of data in non-blocking mode with DMA
ganlikun 0:13413ea9a877 1569 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1570 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1571 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1572 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1573 * @retval HAL status
ganlikun 0:13413ea9a877 1574 */
ganlikun 0:13413ea9a877 1575 HAL_StatusTypeDef HAL_FMPI2C_Slave_Transmit_DMA(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 1576 {
ganlikun 0:13413ea9a877 1577 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1578 {
ganlikun 0:13413ea9a877 1579 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 1580 {
ganlikun 0:13413ea9a877 1581 return HAL_ERROR;
ganlikun 0:13413ea9a877 1582 }
ganlikun 0:13413ea9a877 1583 /* Process Locked */
ganlikun 0:13413ea9a877 1584 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1585
ganlikun 0:13413ea9a877 1586 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 1587 hfmpi2c->Mode = HAL_FMPI2C_MODE_SLAVE;
ganlikun 0:13413ea9a877 1588 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1589
ganlikun 0:13413ea9a877 1590 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1591 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1592 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1593 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1594 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 1595 hfmpi2c->XferISR = FMPI2C_Slave_ISR_DMA;
ganlikun 0:13413ea9a877 1596
ganlikun 0:13413ea9a877 1597 /* Set the FMPI2C DMA transfer complete callback */
ganlikun 0:13413ea9a877 1598 hfmpi2c->hdmatx->XferCpltCallback = FMPI2C_DMASlaveTransmitCplt;
ganlikun 0:13413ea9a877 1599
ganlikun 0:13413ea9a877 1600 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1601 hfmpi2c->hdmatx->XferErrorCallback = FMPI2C_DMAError;
ganlikun 0:13413ea9a877 1602
ganlikun 0:13413ea9a877 1603 /* Set the unused DMA callbacks to NULL */
ganlikun 0:13413ea9a877 1604 hfmpi2c->hdmatx->XferHalfCpltCallback = NULL;
ganlikun 0:13413ea9a877 1605 hfmpi2c->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1606
ganlikun 0:13413ea9a877 1607 /* Enable the DMA channel */
ganlikun 0:13413ea9a877 1608 HAL_DMA_Start_IT(hfmpi2c->hdmatx, (uint32_t)pData, (uint32_t)&hfmpi2c->Instance->TXDR, hfmpi2c->XferSize);
ganlikun 0:13413ea9a877 1609
ganlikun 0:13413ea9a877 1610 /* Enable Address Acknowledge */
ganlikun 0:13413ea9a877 1611 hfmpi2c->Instance->CR2 &= ~FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1612
ganlikun 0:13413ea9a877 1613 /* Process Unlocked */
ganlikun 0:13413ea9a877 1614 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1615
ganlikun 0:13413ea9a877 1616 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 1617 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 1618 process unlock */
ganlikun 0:13413ea9a877 1619 /* Enable ERR, STOP, NACK, ADDR interrupts */
ganlikun 0:13413ea9a877 1620 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 1621
ganlikun 0:13413ea9a877 1622 /* Enable DMA Request */
ganlikun 0:13413ea9a877 1623 hfmpi2c->Instance->CR1 |= FMPI2C_CR1_TXDMAEN;
ganlikun 0:13413ea9a877 1624
ganlikun 0:13413ea9a877 1625 return HAL_OK;
ganlikun 0:13413ea9a877 1626 }
ganlikun 0:13413ea9a877 1627 else
ganlikun 0:13413ea9a877 1628 {
ganlikun 0:13413ea9a877 1629 return HAL_BUSY;
ganlikun 0:13413ea9a877 1630 }
ganlikun 0:13413ea9a877 1631 }
ganlikun 0:13413ea9a877 1632
ganlikun 0:13413ea9a877 1633 /**
ganlikun 0:13413ea9a877 1634 * @brief Receive in slave mode an amount of data in non-blocking mode with DMA
ganlikun 0:13413ea9a877 1635 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1636 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1637 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1638 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1639 * @retval HAL status
ganlikun 0:13413ea9a877 1640 */
ganlikun 0:13413ea9a877 1641 HAL_StatusTypeDef HAL_FMPI2C_Slave_Receive_DMA(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 1642 {
ganlikun 0:13413ea9a877 1643 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1644 {
ganlikun 0:13413ea9a877 1645 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 1646 {
ganlikun 0:13413ea9a877 1647 return HAL_ERROR;
ganlikun 0:13413ea9a877 1648 }
ganlikun 0:13413ea9a877 1649 /* Process Locked */
ganlikun 0:13413ea9a877 1650 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1651
ganlikun 0:13413ea9a877 1652 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 1653 hfmpi2c->Mode = HAL_FMPI2C_MODE_SLAVE;
ganlikun 0:13413ea9a877 1654 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1655
ganlikun 0:13413ea9a877 1656 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1657 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1658 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1659 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1660 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 1661 hfmpi2c->XferISR = FMPI2C_Slave_ISR_DMA;
ganlikun 0:13413ea9a877 1662
ganlikun 0:13413ea9a877 1663 /* Set the FMPI2C DMA transfer complete callback */
ganlikun 0:13413ea9a877 1664 hfmpi2c->hdmarx->XferCpltCallback = FMPI2C_DMASlaveReceiveCplt;
ganlikun 0:13413ea9a877 1665
ganlikun 0:13413ea9a877 1666 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1667 hfmpi2c->hdmarx->XferErrorCallback = FMPI2C_DMAError;
ganlikun 0:13413ea9a877 1668
ganlikun 0:13413ea9a877 1669 /* Set the unused DMA callbacks to NULL */
ganlikun 0:13413ea9a877 1670 hfmpi2c->hdmarx->XferHalfCpltCallback = NULL;
ganlikun 0:13413ea9a877 1671 hfmpi2c->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 1672
ganlikun 0:13413ea9a877 1673 /* Enable the DMA channel */
ganlikun 0:13413ea9a877 1674 HAL_DMA_Start_IT(hfmpi2c->hdmarx, (uint32_t)&hfmpi2c->Instance->RXDR, (uint32_t)pData, hfmpi2c->XferSize);
ganlikun 0:13413ea9a877 1675
ganlikun 0:13413ea9a877 1676 /* Enable Address Acknowledge */
ganlikun 0:13413ea9a877 1677 hfmpi2c->Instance->CR2 &= ~FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 1678
ganlikun 0:13413ea9a877 1679 /* Process Unlocked */
ganlikun 0:13413ea9a877 1680 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1681
ganlikun 0:13413ea9a877 1682 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 1683 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 1684 process unlock */
ganlikun 0:13413ea9a877 1685 /* Enable ERR, STOP, NACK, ADDR interrupts */
ganlikun 0:13413ea9a877 1686 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 1687
ganlikun 0:13413ea9a877 1688 /* Enable DMA Request */
ganlikun 0:13413ea9a877 1689 hfmpi2c->Instance->CR1 |= FMPI2C_CR1_RXDMAEN;
ganlikun 0:13413ea9a877 1690
ganlikun 0:13413ea9a877 1691 return HAL_OK;
ganlikun 0:13413ea9a877 1692 }
ganlikun 0:13413ea9a877 1693 else
ganlikun 0:13413ea9a877 1694 {
ganlikun 0:13413ea9a877 1695 return HAL_BUSY;
ganlikun 0:13413ea9a877 1696 }
ganlikun 0:13413ea9a877 1697 }
ganlikun 0:13413ea9a877 1698 /**
ganlikun 0:13413ea9a877 1699 * @brief Write an amount of data in blocking mode to a specific memory address
ganlikun 0:13413ea9a877 1700 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1701 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1702 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 1703 * @param MemAddress Internal memory address
ganlikun 0:13413ea9a877 1704 * @param MemAddSize Size of internal memory address
ganlikun 0:13413ea9a877 1705 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1706 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1707 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 1708 * @retval HAL status
ganlikun 0:13413ea9a877 1709 */
ganlikun 0:13413ea9a877 1710 HAL_StatusTypeDef HAL_FMPI2C_Mem_Write(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 1711 {
ganlikun 0:13413ea9a877 1712 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 1713
ganlikun 0:13413ea9a877 1714 /* Check the parameters */
ganlikun 0:13413ea9a877 1715 assert_param(IS_FMPI2C_MEMADD_SIZE(MemAddSize));
ganlikun 0:13413ea9a877 1716
ganlikun 0:13413ea9a877 1717 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1718 {
ganlikun 0:13413ea9a877 1719 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 1720 {
ganlikun 0:13413ea9a877 1721 return HAL_ERROR;
ganlikun 0:13413ea9a877 1722 }
ganlikun 0:13413ea9a877 1723
ganlikun 0:13413ea9a877 1724 /* Process Locked */
ganlikun 0:13413ea9a877 1725 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1726
ganlikun 0:13413ea9a877 1727 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 1728 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 1729
ganlikun 0:13413ea9a877 1730 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_BUSY, SET, FMPI2C_TIMEOUT_BUSY, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1731 {
ganlikun 0:13413ea9a877 1732 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1733 }
ganlikun 0:13413ea9a877 1734
ganlikun 0:13413ea9a877 1735 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 1736 hfmpi2c->Mode = HAL_FMPI2C_MODE_MEM;
ganlikun 0:13413ea9a877 1737 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1738
ganlikun 0:13413ea9a877 1739 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1740 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1741 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1742 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 1743
ganlikun 0:13413ea9a877 1744 /* Send Slave Address and Memory Address */
ganlikun 0:13413ea9a877 1745 if(FMPI2C_RequestMemoryWrite(hfmpi2c, DevAddress, MemAddress, MemAddSize, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1746 {
ganlikun 0:13413ea9a877 1747 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 1748 {
ganlikun 0:13413ea9a877 1749 /* Process Unlocked */
ganlikun 0:13413ea9a877 1750 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1751 return HAL_ERROR;
ganlikun 0:13413ea9a877 1752 }
ganlikun 0:13413ea9a877 1753 else
ganlikun 0:13413ea9a877 1754 {
ganlikun 0:13413ea9a877 1755 /* Process Unlocked */
ganlikun 0:13413ea9a877 1756 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1757 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1758 }
ganlikun 0:13413ea9a877 1759 }
ganlikun 0:13413ea9a877 1760
ganlikun 0:13413ea9a877 1761 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE */
ganlikun 0:13413ea9a877 1762 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 1763 {
ganlikun 0:13413ea9a877 1764 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 1765 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 1766 }
ganlikun 0:13413ea9a877 1767 else
ganlikun 0:13413ea9a877 1768 {
ganlikun 0:13413ea9a877 1769 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1770 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 1771 }
ganlikun 0:13413ea9a877 1772
ganlikun 0:13413ea9a877 1773 do
ganlikun 0:13413ea9a877 1774 {
ganlikun 0:13413ea9a877 1775 /* Wait until TXIS flag is set */
ganlikun 0:13413ea9a877 1776 if(FMPI2C_WaitOnTXISFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1777 {
ganlikun 0:13413ea9a877 1778 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 1779 {
ganlikun 0:13413ea9a877 1780 return HAL_ERROR;
ganlikun 0:13413ea9a877 1781 }
ganlikun 0:13413ea9a877 1782 else
ganlikun 0:13413ea9a877 1783 {
ganlikun 0:13413ea9a877 1784 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1785 }
ganlikun 0:13413ea9a877 1786 }
ganlikun 0:13413ea9a877 1787
ganlikun 0:13413ea9a877 1788 /* Write data to TXDR */
ganlikun 0:13413ea9a877 1789 hfmpi2c->Instance->TXDR = (*hfmpi2c->pBuffPtr++);
ganlikun 0:13413ea9a877 1790 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 1791 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 1792
ganlikun 0:13413ea9a877 1793 if((hfmpi2c->XferSize == 0U) && (hfmpi2c->XferCount!=0U))
ganlikun 0:13413ea9a877 1794 {
ganlikun 0:13413ea9a877 1795 /* Wait until TCR flag is set */
ganlikun 0:13413ea9a877 1796 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_TCR, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1797 {
ganlikun 0:13413ea9a877 1798 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1799 }
ganlikun 0:13413ea9a877 1800
ganlikun 0:13413ea9a877 1801 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 1802 {
ganlikun 0:13413ea9a877 1803 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 1804 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 1805 }
ganlikun 0:13413ea9a877 1806 else
ganlikun 0:13413ea9a877 1807 {
ganlikun 0:13413ea9a877 1808 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1809 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 1810 }
ganlikun 0:13413ea9a877 1811 }
ganlikun 0:13413ea9a877 1812
ganlikun 0:13413ea9a877 1813 }while(hfmpi2c->XferCount > 0U);
ganlikun 0:13413ea9a877 1814
ganlikun 0:13413ea9a877 1815 /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */
ganlikun 0:13413ea9a877 1816 /* Wait until STOPF flag is reset */
ganlikun 0:13413ea9a877 1817 if(FMPI2C_WaitOnSTOPFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1818 {
ganlikun 0:13413ea9a877 1819 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 1820 {
ganlikun 0:13413ea9a877 1821 return HAL_ERROR;
ganlikun 0:13413ea9a877 1822 }
ganlikun 0:13413ea9a877 1823 else
ganlikun 0:13413ea9a877 1824 {
ganlikun 0:13413ea9a877 1825 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1826 }
ganlikun 0:13413ea9a877 1827 }
ganlikun 0:13413ea9a877 1828
ganlikun 0:13413ea9a877 1829 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 1830 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 1831
ganlikun 0:13413ea9a877 1832 /* Clear Configuration Register 2 */
ganlikun 0:13413ea9a877 1833 FMPI2C_RESET_CR2(hfmpi2c);
ganlikun 0:13413ea9a877 1834
ganlikun 0:13413ea9a877 1835 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 1836 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 1837
ganlikun 0:13413ea9a877 1838 /* Process Unlocked */
ganlikun 0:13413ea9a877 1839 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1840
ganlikun 0:13413ea9a877 1841 return HAL_OK;
ganlikun 0:13413ea9a877 1842 }
ganlikun 0:13413ea9a877 1843 else
ganlikun 0:13413ea9a877 1844 {
ganlikun 0:13413ea9a877 1845 return HAL_BUSY;
ganlikun 0:13413ea9a877 1846 }
ganlikun 0:13413ea9a877 1847 }
ganlikun 0:13413ea9a877 1848
ganlikun 0:13413ea9a877 1849 /**
ganlikun 0:13413ea9a877 1850 * @brief Read an amount of data in blocking mode from a specific memory address
ganlikun 0:13413ea9a877 1851 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1852 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1853 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 1854 * @param MemAddress Internal memory address
ganlikun 0:13413ea9a877 1855 * @param MemAddSize Size of internal memory address
ganlikun 0:13413ea9a877 1856 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 1857 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 1858 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 1859 * @retval HAL status
ganlikun 0:13413ea9a877 1860 */
ganlikun 0:13413ea9a877 1861 HAL_StatusTypeDef HAL_FMPI2C_Mem_Read(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
ganlikun 0:13413ea9a877 1862 {
ganlikun 0:13413ea9a877 1863 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 1864
ganlikun 0:13413ea9a877 1865 /* Check the parameters */
ganlikun 0:13413ea9a877 1866 assert_param(IS_FMPI2C_MEMADD_SIZE(MemAddSize));
ganlikun 0:13413ea9a877 1867
ganlikun 0:13413ea9a877 1868 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 1869 {
ganlikun 0:13413ea9a877 1870 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 1871 {
ganlikun 0:13413ea9a877 1872 return HAL_ERROR;
ganlikun 0:13413ea9a877 1873 }
ganlikun 0:13413ea9a877 1874
ganlikun 0:13413ea9a877 1875 /* Process Locked */
ganlikun 0:13413ea9a877 1876 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1877
ganlikun 0:13413ea9a877 1878 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 1879 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 1880
ganlikun 0:13413ea9a877 1881 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_BUSY, SET, FMPI2C_TIMEOUT_BUSY, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1882 {
ganlikun 0:13413ea9a877 1883 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1884 }
ganlikun 0:13413ea9a877 1885
ganlikun 0:13413ea9a877 1886 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 1887 hfmpi2c->Mode = HAL_FMPI2C_MODE_MEM;
ganlikun 0:13413ea9a877 1888 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 1889
ganlikun 0:13413ea9a877 1890 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 1891 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 1892 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 1893 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 1894
ganlikun 0:13413ea9a877 1895 /* Send Slave Address and Memory Address */
ganlikun 0:13413ea9a877 1896 if(FMPI2C_RequestMemoryRead(hfmpi2c, DevAddress, MemAddress, MemAddSize, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1897 {
ganlikun 0:13413ea9a877 1898 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 1899 {
ganlikun 0:13413ea9a877 1900 /* Process Unlocked */
ganlikun 0:13413ea9a877 1901 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1902 return HAL_ERROR;
ganlikun 0:13413ea9a877 1903 }
ganlikun 0:13413ea9a877 1904 else
ganlikun 0:13413ea9a877 1905 {
ganlikun 0:13413ea9a877 1906 /* Process Unlocked */
ganlikun 0:13413ea9a877 1907 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1908 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1909 }
ganlikun 0:13413ea9a877 1910 }
ganlikun 0:13413ea9a877 1911
ganlikun 0:13413ea9a877 1912 /* Send Slave Address */
ganlikun 0:13413ea9a877 1913 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 1914 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 1915 {
ganlikun 0:13413ea9a877 1916 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 1917 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_GENERATE_START_READ);
ganlikun 0:13413ea9a877 1918 }
ganlikun 0:13413ea9a877 1919 else
ganlikun 0:13413ea9a877 1920 {
ganlikun 0:13413ea9a877 1921 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1922 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_GENERATE_START_READ);
ganlikun 0:13413ea9a877 1923 }
ganlikun 0:13413ea9a877 1924
ganlikun 0:13413ea9a877 1925 do
ganlikun 0:13413ea9a877 1926 {
ganlikun 0:13413ea9a877 1927 /* Wait until RXNE flag is set */
ganlikun 0:13413ea9a877 1928 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_RXNE, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1929 {
ganlikun 0:13413ea9a877 1930 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1931 }
ganlikun 0:13413ea9a877 1932
ganlikun 0:13413ea9a877 1933 /* Read data from RXDR */
ganlikun 0:13413ea9a877 1934 (*hfmpi2c->pBuffPtr++) = hfmpi2c->Instance->RXDR;
ganlikun 0:13413ea9a877 1935 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 1936 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 1937
ganlikun 0:13413ea9a877 1938 if((hfmpi2c->XferSize == 0U) && (hfmpi2c->XferCount != 0U))
ganlikun 0:13413ea9a877 1939 {
ganlikun 0:13413ea9a877 1940 /* Wait until TCR flag is set */
ganlikun 0:13413ea9a877 1941 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_TCR, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1942 {
ganlikun 0:13413ea9a877 1943 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1944 }
ganlikun 0:13413ea9a877 1945
ganlikun 0:13413ea9a877 1946 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 1947 {
ganlikun 0:13413ea9a877 1948 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 1949 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 1950 }
ganlikun 0:13413ea9a877 1951 else
ganlikun 0:13413ea9a877 1952 {
ganlikun 0:13413ea9a877 1953 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 1954 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 1955 }
ganlikun 0:13413ea9a877 1956 }
ganlikun 0:13413ea9a877 1957 }while(hfmpi2c->XferCount > 0U);
ganlikun 0:13413ea9a877 1958
ganlikun 0:13413ea9a877 1959 /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */
ganlikun 0:13413ea9a877 1960 /* Wait until STOPF flag is reset */
ganlikun 0:13413ea9a877 1961 if(FMPI2C_WaitOnSTOPFlagUntilTimeout(hfmpi2c, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 1962 {
ganlikun 0:13413ea9a877 1963 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 1964 {
ganlikun 0:13413ea9a877 1965 return HAL_ERROR;
ganlikun 0:13413ea9a877 1966 }
ganlikun 0:13413ea9a877 1967 else
ganlikun 0:13413ea9a877 1968 {
ganlikun 0:13413ea9a877 1969 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 1970 }
ganlikun 0:13413ea9a877 1971 }
ganlikun 0:13413ea9a877 1972
ganlikun 0:13413ea9a877 1973 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 1974 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 1975
ganlikun 0:13413ea9a877 1976 /* Clear Configuration Register 2 */
ganlikun 0:13413ea9a877 1977 FMPI2C_RESET_CR2(hfmpi2c);
ganlikun 0:13413ea9a877 1978
ganlikun 0:13413ea9a877 1979 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 1980 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 1981
ganlikun 0:13413ea9a877 1982 /* Process Unlocked */
ganlikun 0:13413ea9a877 1983 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 1984
ganlikun 0:13413ea9a877 1985 return HAL_OK;
ganlikun 0:13413ea9a877 1986 }
ganlikun 0:13413ea9a877 1987 else
ganlikun 0:13413ea9a877 1988 {
ganlikun 0:13413ea9a877 1989 return HAL_BUSY;
ganlikun 0:13413ea9a877 1990 }
ganlikun 0:13413ea9a877 1991 }
ganlikun 0:13413ea9a877 1992 /**
ganlikun 0:13413ea9a877 1993 * @brief Write an amount of data in non-blocking mode with Interrupt to a specific memory address
ganlikun 0:13413ea9a877 1994 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1995 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 1996 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 1997 * @param MemAddress Internal memory address
ganlikun 0:13413ea9a877 1998 * @param MemAddSize Size of internal memory address
ganlikun 0:13413ea9a877 1999 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 2000 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 2001 * @retval HAL status
ganlikun 0:13413ea9a877 2002 */
ganlikun 0:13413ea9a877 2003 HAL_StatusTypeDef HAL_FMPI2C_Mem_Write_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 2004 {
ganlikun 0:13413ea9a877 2005 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 2006 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 2007
ganlikun 0:13413ea9a877 2008 /* Check the parameters */
ganlikun 0:13413ea9a877 2009 assert_param(IS_FMPI2C_MEMADD_SIZE(MemAddSize));
ganlikun 0:13413ea9a877 2010
ganlikun 0:13413ea9a877 2011 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 2012 {
ganlikun 0:13413ea9a877 2013 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 2014 {
ganlikun 0:13413ea9a877 2015 return HAL_ERROR;
ganlikun 0:13413ea9a877 2016 }
ganlikun 0:13413ea9a877 2017
ganlikun 0:13413ea9a877 2018 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 2019 {
ganlikun 0:13413ea9a877 2020 return HAL_BUSY;
ganlikun 0:13413ea9a877 2021 }
ganlikun 0:13413ea9a877 2022
ganlikun 0:13413ea9a877 2023 /* Process Locked */
ganlikun 0:13413ea9a877 2024 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2025
ganlikun 0:13413ea9a877 2026 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 2027 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 2028
ganlikun 0:13413ea9a877 2029 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 2030 hfmpi2c->Mode = HAL_FMPI2C_MODE_MEM;
ganlikun 0:13413ea9a877 2031 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2032
ganlikun 0:13413ea9a877 2033 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 2034 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 2035 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 2036 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 2037 hfmpi2c->XferISR = FMPI2C_Master_ISR_IT;
ganlikun 0:13413ea9a877 2038
ganlikun 0:13413ea9a877 2039 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 2040 {
ganlikun 0:13413ea9a877 2041 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 2042 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 2043 }
ganlikun 0:13413ea9a877 2044 else
ganlikun 0:13413ea9a877 2045 {
ganlikun 0:13413ea9a877 2046 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 2047 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 2048 }
ganlikun 0:13413ea9a877 2049
ganlikun 0:13413ea9a877 2050 /* Send Slave Address and Memory Address */
ganlikun 0:13413ea9a877 2051 if(FMPI2C_RequestMemoryWrite(hfmpi2c, DevAddress, MemAddress, MemAddSize, FMPI2C_TIMEOUT_FLAG, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 2052 {
ganlikun 0:13413ea9a877 2053 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 2054 {
ganlikun 0:13413ea9a877 2055 /* Process Unlocked */
ganlikun 0:13413ea9a877 2056 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2057 return HAL_ERROR;
ganlikun 0:13413ea9a877 2058 }
ganlikun 0:13413ea9a877 2059 else
ganlikun 0:13413ea9a877 2060 {
ganlikun 0:13413ea9a877 2061 /* Process Unlocked */
ganlikun 0:13413ea9a877 2062 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2063 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2064 }
ganlikun 0:13413ea9a877 2065 }
ganlikun 0:13413ea9a877 2066
ganlikun 0:13413ea9a877 2067 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 2068 FMPI2C_TransferConfig(hfmpi2c,DevAddress, hfmpi2c->XferSize, xfermode, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 2069
ganlikun 0:13413ea9a877 2070 /* Process Unlocked */
ganlikun 0:13413ea9a877 2071 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2072
ganlikun 0:13413ea9a877 2073 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2074 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2075 process unlock */
ganlikun 0:13413ea9a877 2076
ganlikun 0:13413ea9a877 2077 /* Enable ERR, TC, STOP, NACK, TXI interrupt */
ganlikun 0:13413ea9a877 2078 /* possible to enable all of these */
ganlikun 0:13413ea9a877 2079 /* FMPI2C_IT_ERRI | FMPI2C_IT_TCI| FMPI2C_IT_STOPI| FMPI2C_IT_NACKI | FMPI2C_IT_ADDRI | FMPI2C_IT_RXI | FMPI2C_IT_TXI */
ganlikun 0:13413ea9a877 2080 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 2081
ganlikun 0:13413ea9a877 2082 return HAL_OK;
ganlikun 0:13413ea9a877 2083 }
ganlikun 0:13413ea9a877 2084 else
ganlikun 0:13413ea9a877 2085 {
ganlikun 0:13413ea9a877 2086 return HAL_BUSY;
ganlikun 0:13413ea9a877 2087 }
ganlikun 0:13413ea9a877 2088 }
ganlikun 0:13413ea9a877 2089
ganlikun 0:13413ea9a877 2090 /**
ganlikun 0:13413ea9a877 2091 * @brief Read an amount of data in non-blocking mode with Interrupt from a specific memory address
ganlikun 0:13413ea9a877 2092 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2093 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2094 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 2095 * @param MemAddress Internal memory address
ganlikun 0:13413ea9a877 2096 * @param MemAddSize Size of internal memory address
ganlikun 0:13413ea9a877 2097 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 2098 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 2099 * @retval HAL status
ganlikun 0:13413ea9a877 2100 */
ganlikun 0:13413ea9a877 2101 HAL_StatusTypeDef HAL_FMPI2C_Mem_Read_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 2102 {
ganlikun 0:13413ea9a877 2103 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 2104 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 2105
ganlikun 0:13413ea9a877 2106 /* Check the parameters */
ganlikun 0:13413ea9a877 2107 assert_param(IS_FMPI2C_MEMADD_SIZE(MemAddSize));
ganlikun 0:13413ea9a877 2108
ganlikun 0:13413ea9a877 2109 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 2110 {
ganlikun 0:13413ea9a877 2111 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 2112 {
ganlikun 0:13413ea9a877 2113 return HAL_ERROR;
ganlikun 0:13413ea9a877 2114 }
ganlikun 0:13413ea9a877 2115
ganlikun 0:13413ea9a877 2116 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 2117 {
ganlikun 0:13413ea9a877 2118 return HAL_BUSY;
ganlikun 0:13413ea9a877 2119 }
ganlikun 0:13413ea9a877 2120
ganlikun 0:13413ea9a877 2121 /* Process Locked */
ganlikun 0:13413ea9a877 2122 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2123
ganlikun 0:13413ea9a877 2124 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 2125 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 2126
ganlikun 0:13413ea9a877 2127 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 2128 hfmpi2c->Mode = HAL_FMPI2C_MODE_MEM;
ganlikun 0:13413ea9a877 2129 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2130
ganlikun 0:13413ea9a877 2131 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 2132 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 2133 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 2134 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 2135 hfmpi2c->XferISR = FMPI2C_Master_ISR_IT;
ganlikun 0:13413ea9a877 2136
ganlikun 0:13413ea9a877 2137 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 2138 {
ganlikun 0:13413ea9a877 2139 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 2140 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 2141 }
ganlikun 0:13413ea9a877 2142 else
ganlikun 0:13413ea9a877 2143 {
ganlikun 0:13413ea9a877 2144 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 2145 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 2146 }
ganlikun 0:13413ea9a877 2147
ganlikun 0:13413ea9a877 2148 /* Send Slave Address and Memory Address */
ganlikun 0:13413ea9a877 2149 if(FMPI2C_RequestMemoryRead(hfmpi2c, DevAddress, MemAddress, MemAddSize, FMPI2C_TIMEOUT_FLAG, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 2150 {
ganlikun 0:13413ea9a877 2151 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 2152 {
ganlikun 0:13413ea9a877 2153 /* Process Unlocked */
ganlikun 0:13413ea9a877 2154 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2155 return HAL_ERROR;
ganlikun 0:13413ea9a877 2156 }
ganlikun 0:13413ea9a877 2157 else
ganlikun 0:13413ea9a877 2158 {
ganlikun 0:13413ea9a877 2159 /* Process Unlocked */
ganlikun 0:13413ea9a877 2160 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2161 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2162 }
ganlikun 0:13413ea9a877 2163 }
ganlikun 0:13413ea9a877 2164
ganlikun 0:13413ea9a877 2165 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 2166 FMPI2C_TransferConfig(hfmpi2c,DevAddress,hfmpi2c->XferSize, xfermode, FMPI2C_GENERATE_START_READ);
ganlikun 0:13413ea9a877 2167
ganlikun 0:13413ea9a877 2168 /* Process Unlocked */
ganlikun 0:13413ea9a877 2169 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2170
ganlikun 0:13413ea9a877 2171 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2172 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2173 process unlock */
ganlikun 0:13413ea9a877 2174
ganlikun 0:13413ea9a877 2175 /* Enable ERR, TC, STOP, NACK, RXI interrupt */
ganlikun 0:13413ea9a877 2176 /* possible to enable all of these */
ganlikun 0:13413ea9a877 2177 /* FMPI2C_IT_ERRI | FMPI2C_IT_TCI| FMPI2C_IT_STOPI| FMPI2C_IT_NACKI | FMPI2C_IT_ADDRI | FMPI2C_IT_RXI | FMPI2C_IT_TXI */
ganlikun 0:13413ea9a877 2178 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 2179
ganlikun 0:13413ea9a877 2180 return HAL_OK;
ganlikun 0:13413ea9a877 2181 }
ganlikun 0:13413ea9a877 2182 else
ganlikun 0:13413ea9a877 2183 {
ganlikun 0:13413ea9a877 2184 return HAL_BUSY;
ganlikun 0:13413ea9a877 2185 }
ganlikun 0:13413ea9a877 2186 }
ganlikun 0:13413ea9a877 2187 /**
ganlikun 0:13413ea9a877 2188 * @brief Write an amount of data in non-blocking mode with DMA to a specific memory address
ganlikun 0:13413ea9a877 2189 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2190 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2191 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 2192 * @param MemAddress Internal memory address
ganlikun 0:13413ea9a877 2193 * @param MemAddSize Size of internal memory address
ganlikun 0:13413ea9a877 2194 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 2195 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 2196 * @retval HAL status
ganlikun 0:13413ea9a877 2197 */
ganlikun 0:13413ea9a877 2198 HAL_StatusTypeDef HAL_FMPI2C_Mem_Write_DMA(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 2199 {
ganlikun 0:13413ea9a877 2200 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 2201 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 2202
ganlikun 0:13413ea9a877 2203 /* Check the parameters */
ganlikun 0:13413ea9a877 2204 assert_param(IS_FMPI2C_MEMADD_SIZE(MemAddSize));
ganlikun 0:13413ea9a877 2205
ganlikun 0:13413ea9a877 2206 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 2207 {
ganlikun 0:13413ea9a877 2208 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 2209 {
ganlikun 0:13413ea9a877 2210 return HAL_ERROR;
ganlikun 0:13413ea9a877 2211 }
ganlikun 0:13413ea9a877 2212
ganlikun 0:13413ea9a877 2213 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 2214 {
ganlikun 0:13413ea9a877 2215 return HAL_BUSY;
ganlikun 0:13413ea9a877 2216 }
ganlikun 0:13413ea9a877 2217
ganlikun 0:13413ea9a877 2218 /* Process Locked */
ganlikun 0:13413ea9a877 2219 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2220
ganlikun 0:13413ea9a877 2221 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 2222 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 2223
ganlikun 0:13413ea9a877 2224 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 2225 hfmpi2c->Mode = HAL_FMPI2C_MODE_MEM;
ganlikun 0:13413ea9a877 2226 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2227
ganlikun 0:13413ea9a877 2228 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 2229 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 2230 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 2231 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 2232 hfmpi2c->XferISR = FMPI2C_Master_ISR_DMA;
ganlikun 0:13413ea9a877 2233
ganlikun 0:13413ea9a877 2234 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 2235 {
ganlikun 0:13413ea9a877 2236 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 2237 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 2238 }
ganlikun 0:13413ea9a877 2239 else
ganlikun 0:13413ea9a877 2240 {
ganlikun 0:13413ea9a877 2241 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 2242 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 2243 }
ganlikun 0:13413ea9a877 2244
ganlikun 0:13413ea9a877 2245 /* Send Slave Address and Memory Address */
ganlikun 0:13413ea9a877 2246 if(FMPI2C_RequestMemoryWrite(hfmpi2c, DevAddress, MemAddress, MemAddSize, FMPI2C_TIMEOUT_FLAG, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 2247 {
ganlikun 0:13413ea9a877 2248 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 2249 {
ganlikun 0:13413ea9a877 2250 /* Process Unlocked */
ganlikun 0:13413ea9a877 2251 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2252 return HAL_ERROR;
ganlikun 0:13413ea9a877 2253 }
ganlikun 0:13413ea9a877 2254 else
ganlikun 0:13413ea9a877 2255 {
ganlikun 0:13413ea9a877 2256 /* Process Unlocked */
ganlikun 0:13413ea9a877 2257 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2258 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2259 }
ganlikun 0:13413ea9a877 2260 }
ganlikun 0:13413ea9a877 2261
ganlikun 0:13413ea9a877 2262 /* Set the FMPI2C DMA transfer complete callback */
ganlikun 0:13413ea9a877 2263 hfmpi2c->hdmatx->XferCpltCallback = FMPI2C_DMAMasterTransmitCplt;
ganlikun 0:13413ea9a877 2264
ganlikun 0:13413ea9a877 2265 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 2266 hfmpi2c->hdmatx->XferErrorCallback = FMPI2C_DMAError;
ganlikun 0:13413ea9a877 2267
ganlikun 0:13413ea9a877 2268 /* Set the unused DMA callbacks to NULL */
ganlikun 0:13413ea9a877 2269 hfmpi2c->hdmatx->XferHalfCpltCallback = NULL;
ganlikun 0:13413ea9a877 2270 hfmpi2c->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 2271
ganlikun 0:13413ea9a877 2272 /* Enable the DMA channel */
ganlikun 0:13413ea9a877 2273 HAL_DMA_Start_IT(hfmpi2c->hdmatx, (uint32_t)pData, (uint32_t)&hfmpi2c->Instance->TXDR, hfmpi2c->XferSize);
ganlikun 0:13413ea9a877 2274
ganlikun 0:13413ea9a877 2275 /* Send Slave Address */
ganlikun 0:13413ea9a877 2276 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 2277 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, xfermode, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 2278
ganlikun 0:13413ea9a877 2279 /* Update XferCount value */
ganlikun 0:13413ea9a877 2280 hfmpi2c->XferCount -= hfmpi2c->XferSize;
ganlikun 0:13413ea9a877 2281
ganlikun 0:13413ea9a877 2282 /* Process Unlocked */
ganlikun 0:13413ea9a877 2283 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2284
ganlikun 0:13413ea9a877 2285 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2286 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2287 process unlock */
ganlikun 0:13413ea9a877 2288 /* Enable ERR and NACK interrupts */
ganlikun 0:13413ea9a877 2289 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_ERROR_IT);
ganlikun 0:13413ea9a877 2290
ganlikun 0:13413ea9a877 2291 /* Enable DMA Request */
ganlikun 0:13413ea9a877 2292 hfmpi2c->Instance->CR1 |= FMPI2C_CR1_TXDMAEN;
ganlikun 0:13413ea9a877 2293
ganlikun 0:13413ea9a877 2294 return HAL_OK;
ganlikun 0:13413ea9a877 2295 }
ganlikun 0:13413ea9a877 2296 else
ganlikun 0:13413ea9a877 2297 {
ganlikun 0:13413ea9a877 2298 return HAL_BUSY;
ganlikun 0:13413ea9a877 2299 }
ganlikun 0:13413ea9a877 2300 }
ganlikun 0:13413ea9a877 2301
ganlikun 0:13413ea9a877 2302 /**
ganlikun 0:13413ea9a877 2303 * @brief Reads an amount of data in non-blocking mode with DMA from a specific memory address.
ganlikun 0:13413ea9a877 2304 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2305 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2306 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 2307 * @param MemAddress Internal memory address
ganlikun 0:13413ea9a877 2308 * @param MemAddSize Size of internal memory address
ganlikun 0:13413ea9a877 2309 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 2310 * @param Size Amount of data to be read
ganlikun 0:13413ea9a877 2311 * @retval HAL status
ganlikun 0:13413ea9a877 2312 */
ganlikun 0:13413ea9a877 2313 HAL_StatusTypeDef HAL_FMPI2C_Mem_Read_DMA(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size)
ganlikun 0:13413ea9a877 2314 {
ganlikun 0:13413ea9a877 2315 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 2316 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 2317
ganlikun 0:13413ea9a877 2318 /* Check the parameters */
ganlikun 0:13413ea9a877 2319 assert_param(IS_FMPI2C_MEMADD_SIZE(MemAddSize));
ganlikun 0:13413ea9a877 2320
ganlikun 0:13413ea9a877 2321 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 2322 {
ganlikun 0:13413ea9a877 2323 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 2324 {
ganlikun 0:13413ea9a877 2325 return HAL_ERROR;
ganlikun 0:13413ea9a877 2326 }
ganlikun 0:13413ea9a877 2327
ganlikun 0:13413ea9a877 2328 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 2329 {
ganlikun 0:13413ea9a877 2330 return HAL_BUSY;
ganlikun 0:13413ea9a877 2331 }
ganlikun 0:13413ea9a877 2332
ganlikun 0:13413ea9a877 2333 /* Process Locked */
ganlikun 0:13413ea9a877 2334 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2335
ganlikun 0:13413ea9a877 2336 /* Init tickstart for timeout management*/
ganlikun 0:13413ea9a877 2337 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 2338
ganlikun 0:13413ea9a877 2339 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 2340 hfmpi2c->Mode = HAL_FMPI2C_MODE_MEM;
ganlikun 0:13413ea9a877 2341 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2342
ganlikun 0:13413ea9a877 2343 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 2344 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 2345 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 2346 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 2347 hfmpi2c->XferISR = FMPI2C_Master_ISR_DMA;
ganlikun 0:13413ea9a877 2348
ganlikun 0:13413ea9a877 2349 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 2350 {
ganlikun 0:13413ea9a877 2351 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 2352 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 2353 }
ganlikun 0:13413ea9a877 2354 else
ganlikun 0:13413ea9a877 2355 {
ganlikun 0:13413ea9a877 2356 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 2357 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 2358 }
ganlikun 0:13413ea9a877 2359
ganlikun 0:13413ea9a877 2360 /* Send Slave Address and Memory Address */
ganlikun 0:13413ea9a877 2361 if(FMPI2C_RequestMemoryRead(hfmpi2c, DevAddress, MemAddress, MemAddSize, FMPI2C_TIMEOUT_FLAG, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 2362 {
ganlikun 0:13413ea9a877 2363 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 2364 {
ganlikun 0:13413ea9a877 2365 /* Process Unlocked */
ganlikun 0:13413ea9a877 2366 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2367 return HAL_ERROR;
ganlikun 0:13413ea9a877 2368 }
ganlikun 0:13413ea9a877 2369 else
ganlikun 0:13413ea9a877 2370 {
ganlikun 0:13413ea9a877 2371 /* Process Unlocked */
ganlikun 0:13413ea9a877 2372 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2373 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2374 }
ganlikun 0:13413ea9a877 2375 }
ganlikun 0:13413ea9a877 2376
ganlikun 0:13413ea9a877 2377 /* Set the FMPI2C DMA transfer complete callback */
ganlikun 0:13413ea9a877 2378 hfmpi2c->hdmarx->XferCpltCallback = FMPI2C_DMAMasterReceiveCplt;
ganlikun 0:13413ea9a877 2379
ganlikun 0:13413ea9a877 2380 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 2381 hfmpi2c->hdmarx->XferErrorCallback = FMPI2C_DMAError;
ganlikun 0:13413ea9a877 2382
ganlikun 0:13413ea9a877 2383 /* Set the unused DMA callbacks to NULL */
ganlikun 0:13413ea9a877 2384 hfmpi2c->hdmarx->XferHalfCpltCallback = NULL;
ganlikun 0:13413ea9a877 2385 hfmpi2c->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 2386
ganlikun 0:13413ea9a877 2387 /* Enable the DMA channel */
ganlikun 0:13413ea9a877 2388 HAL_DMA_Start_IT(hfmpi2c->hdmarx, (uint32_t)&hfmpi2c->Instance->RXDR, (uint32_t)pData, hfmpi2c->XferSize);
ganlikun 0:13413ea9a877 2389
ganlikun 0:13413ea9a877 2390 /* Set NBYTES to write and reload if hfmpi2c->XferCount > MAX_NBYTE_SIZE and generate RESTART */
ganlikun 0:13413ea9a877 2391 FMPI2C_TransferConfig(hfmpi2c,DevAddress, hfmpi2c->XferSize, xfermode, FMPI2C_GENERATE_START_READ);
ganlikun 0:13413ea9a877 2392
ganlikun 0:13413ea9a877 2393 /* Update XferCount value */
ganlikun 0:13413ea9a877 2394 hfmpi2c->XferCount -= hfmpi2c->XferSize;
ganlikun 0:13413ea9a877 2395
ganlikun 0:13413ea9a877 2396 /* Process Unlocked */
ganlikun 0:13413ea9a877 2397 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2398
ganlikun 0:13413ea9a877 2399 /* Enable DMA Request */
ganlikun 0:13413ea9a877 2400 hfmpi2c->Instance->CR1 |= FMPI2C_CR1_RXDMAEN;
ganlikun 0:13413ea9a877 2401
ganlikun 0:13413ea9a877 2402 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2403 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2404 process unlock */
ganlikun 0:13413ea9a877 2405 /* Enable ERR and NACK interrupts */
ganlikun 0:13413ea9a877 2406 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_ERROR_IT);
ganlikun 0:13413ea9a877 2407
ganlikun 0:13413ea9a877 2408 return HAL_OK;
ganlikun 0:13413ea9a877 2409 }
ganlikun 0:13413ea9a877 2410 else
ganlikun 0:13413ea9a877 2411 {
ganlikun 0:13413ea9a877 2412 return HAL_BUSY;
ganlikun 0:13413ea9a877 2413 }
ganlikun 0:13413ea9a877 2414 }
ganlikun 0:13413ea9a877 2415
ganlikun 0:13413ea9a877 2416 /**
ganlikun 0:13413ea9a877 2417 * @brief Checks if target device is ready for communication.
ganlikun 0:13413ea9a877 2418 * @note This function is used with Memory devices
ganlikun 0:13413ea9a877 2419 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2420 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2421 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 2422 * @param Trials Number of trials
ganlikun 0:13413ea9a877 2423 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 2424 * @retval HAL status
ganlikun 0:13413ea9a877 2425 */
ganlikun 0:13413ea9a877 2426 HAL_StatusTypeDef HAL_FMPI2C_IsDeviceReady(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout)
ganlikun 0:13413ea9a877 2427 {
ganlikun 0:13413ea9a877 2428 uint32_t tickstart = 0U;
ganlikun 0:13413ea9a877 2429
ganlikun 0:13413ea9a877 2430 __IO uint32_t FMPI2C_Trials = 0U;
ganlikun 0:13413ea9a877 2431
ganlikun 0:13413ea9a877 2432 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 2433 {
ganlikun 0:13413ea9a877 2434 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_BUSY) == SET)
ganlikun 0:13413ea9a877 2435 {
ganlikun 0:13413ea9a877 2436 return HAL_BUSY;
ganlikun 0:13413ea9a877 2437 }
ganlikun 0:13413ea9a877 2438
ganlikun 0:13413ea9a877 2439 /* Process Locked */
ganlikun 0:13413ea9a877 2440 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2441
ganlikun 0:13413ea9a877 2442 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY;
ganlikun 0:13413ea9a877 2443 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2444
ganlikun 0:13413ea9a877 2445 do
ganlikun 0:13413ea9a877 2446 {
ganlikun 0:13413ea9a877 2447 /* Generate Start */
ganlikun 0:13413ea9a877 2448 hfmpi2c->Instance->CR2 = FMPI2C_GENERATE_START(hfmpi2c->Init.AddressingMode,DevAddress);
ganlikun 0:13413ea9a877 2449
ganlikun 0:13413ea9a877 2450 /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */
ganlikun 0:13413ea9a877 2451 /* Wait until STOPF flag is set or a NACK flag is set*/
ganlikun 0:13413ea9a877 2452 tickstart = HAL_GetTick();
ganlikun 0:13413ea9a877 2453 while((__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF) == RESET) && (__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_AF) == RESET) && (hfmpi2c->State != HAL_FMPI2C_STATE_TIMEOUT))
ganlikun 0:13413ea9a877 2454 {
ganlikun 0:13413ea9a877 2455 if(Timeout != HAL_MAX_DELAY)
ganlikun 0:13413ea9a877 2456 {
ganlikun 0:13413ea9a877 2457 if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
ganlikun 0:13413ea9a877 2458 {
ganlikun 0:13413ea9a877 2459 /* Device is ready */
ganlikun 0:13413ea9a877 2460 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 2461 /* Process Unlocked */
ganlikun 0:13413ea9a877 2462 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2463 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2464 }
ganlikun 0:13413ea9a877 2465 }
ganlikun 0:13413ea9a877 2466 }
ganlikun 0:13413ea9a877 2467
ganlikun 0:13413ea9a877 2468 /* Check if the NACKF flag has not been set */
ganlikun 0:13413ea9a877 2469 if (__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_AF) == RESET)
ganlikun 0:13413ea9a877 2470 {
ganlikun 0:13413ea9a877 2471 /* Wait until STOPF flag is reset */
ganlikun 0:13413ea9a877 2472 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_STOPF, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 2473 {
ganlikun 0:13413ea9a877 2474 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2475 }
ganlikun 0:13413ea9a877 2476
ganlikun 0:13413ea9a877 2477 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 2478 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 2479
ganlikun 0:13413ea9a877 2480 /* Device is ready */
ganlikun 0:13413ea9a877 2481 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 2482
ganlikun 0:13413ea9a877 2483 /* Process Unlocked */
ganlikun 0:13413ea9a877 2484 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2485
ganlikun 0:13413ea9a877 2486 return HAL_OK;
ganlikun 0:13413ea9a877 2487 }
ganlikun 0:13413ea9a877 2488 else
ganlikun 0:13413ea9a877 2489 {
ganlikun 0:13413ea9a877 2490 /* Wait until STOPF flag is reset */
ganlikun 0:13413ea9a877 2491 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_STOPF, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 2492 {
ganlikun 0:13413ea9a877 2493 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2494 }
ganlikun 0:13413ea9a877 2495
ganlikun 0:13413ea9a877 2496 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 2497 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 2498
ganlikun 0:13413ea9a877 2499 /* Clear STOP Flag, auto generated with autoend*/
ganlikun 0:13413ea9a877 2500 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 2501 }
ganlikun 0:13413ea9a877 2502
ganlikun 0:13413ea9a877 2503 /* Check if the maximum allowed number of trials has been reached */
ganlikun 0:13413ea9a877 2504 if (FMPI2C_Trials++ == Trials)
ganlikun 0:13413ea9a877 2505 {
ganlikun 0:13413ea9a877 2506 /* Generate Stop */
ganlikun 0:13413ea9a877 2507 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_STOP;
ganlikun 0:13413ea9a877 2508
ganlikun 0:13413ea9a877 2509 /* Wait until STOPF flag is reset */
ganlikun 0:13413ea9a877 2510 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_STOPF, RESET, Timeout, tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 2511 {
ganlikun 0:13413ea9a877 2512 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2513 }
ganlikun 0:13413ea9a877 2514
ganlikun 0:13413ea9a877 2515 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 2516 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 2517 }
ganlikun 0:13413ea9a877 2518 }while(FMPI2C_Trials < Trials);
ganlikun 0:13413ea9a877 2519
ganlikun 0:13413ea9a877 2520 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 2521
ganlikun 0:13413ea9a877 2522 /* Process Unlocked */
ganlikun 0:13413ea9a877 2523 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2524
ganlikun 0:13413ea9a877 2525 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 2526 }
ganlikun 0:13413ea9a877 2527 else
ganlikun 0:13413ea9a877 2528 {
ganlikun 0:13413ea9a877 2529 return HAL_BUSY;
ganlikun 0:13413ea9a877 2530 }
ganlikun 0:13413ea9a877 2531 }
ganlikun 0:13413ea9a877 2532
ganlikun 0:13413ea9a877 2533 /**
ganlikun 0:13413ea9a877 2534 * @brief Sequential transmit in master FMPI2C mode an amount of data in non-blocking mode with Interrupt.
ganlikun 0:13413ea9a877 2535 * @note This interface allow to manage repeated start condition when a direction change during transfer
ganlikun 0:13413ea9a877 2536 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2537 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2538 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 2539 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 2540 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 2541 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 2542 * @param XferOptions Options of Transfer, value of @ref FMPI2C_XFEROPTIONS
ganlikun 0:13413ea9a877 2543 * @retval HAL status
ganlikun 0:13413ea9a877 2544 */
ganlikun 0:13413ea9a877 2545 HAL_StatusTypeDef HAL_FMPI2C_Master_Sequential_Transmit_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions)
ganlikun 0:13413ea9a877 2546 {
ganlikun 0:13413ea9a877 2547 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 2548 uint32_t xferrequest = FMPI2C_GENERATE_START_WRITE;
ganlikun 0:13413ea9a877 2549
ganlikun 0:13413ea9a877 2550 /* Check the parameters */
ganlikun 0:13413ea9a877 2551 assert_param(IS_FMPI2C_TRANSFER_OPTIONS_REQUEST(XferOptions));
ganlikun 0:13413ea9a877 2552
ganlikun 0:13413ea9a877 2553 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 2554 {
ganlikun 0:13413ea9a877 2555 /* Process Locked */
ganlikun 0:13413ea9a877 2556 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2557
ganlikun 0:13413ea9a877 2558 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX;
ganlikun 0:13413ea9a877 2559 hfmpi2c->Mode = HAL_FMPI2C_MODE_MASTER;
ganlikun 0:13413ea9a877 2560 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2561
ganlikun 0:13413ea9a877 2562 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 2563 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 2564 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 2565 hfmpi2c->XferOptions = XferOptions;
ganlikun 0:13413ea9a877 2566 hfmpi2c->XferISR = FMPI2C_Master_ISR_IT;
ganlikun 0:13413ea9a877 2567
ganlikun 0:13413ea9a877 2568 /* If size > MAX_NBYTE_SIZE, use reload mode */
ganlikun 0:13413ea9a877 2569 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 2570 {
ganlikun 0:13413ea9a877 2571 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 2572 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 2573 }
ganlikun 0:13413ea9a877 2574 else
ganlikun 0:13413ea9a877 2575 {
ganlikun 0:13413ea9a877 2576 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 2577 xfermode = hfmpi2c->XferOptions;
ganlikun 0:13413ea9a877 2578 }
ganlikun 0:13413ea9a877 2579
ganlikun 0:13413ea9a877 2580 /* If transfer direction not change, do not generate Restart Condition */
ganlikun 0:13413ea9a877 2581 /* Mean Previous state is same as current state */
ganlikun 0:13413ea9a877 2582 if(hfmpi2c->PreviousState == FMPI2C_STATE_SLAVE_BUSY_TX)
ganlikun 0:13413ea9a877 2583 {
ganlikun 0:13413ea9a877 2584 xferrequest = FMPI2C_NO_STARTSTOP;
ganlikun 0:13413ea9a877 2585 }
ganlikun 0:13413ea9a877 2586
ganlikun 0:13413ea9a877 2587 /* Send Slave Address and set NBYTES to write */
ganlikun 0:13413ea9a877 2588 FMPI2C_TransferConfig(hfmpi2c, DevAddress, hfmpi2c->XferSize, xfermode, xferrequest);
ganlikun 0:13413ea9a877 2589
ganlikun 0:13413ea9a877 2590 /* Process Unlocked */
ganlikun 0:13413ea9a877 2591 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2592
ganlikun 0:13413ea9a877 2593 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2594 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2595 process unlock */
ganlikun 0:13413ea9a877 2596 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 2597
ganlikun 0:13413ea9a877 2598 return HAL_OK;
ganlikun 0:13413ea9a877 2599 }
ganlikun 0:13413ea9a877 2600 else
ganlikun 0:13413ea9a877 2601 {
ganlikun 0:13413ea9a877 2602 return HAL_BUSY;
ganlikun 0:13413ea9a877 2603 }
ganlikun 0:13413ea9a877 2604 }
ganlikun 0:13413ea9a877 2605
ganlikun 0:13413ea9a877 2606 /**
ganlikun 0:13413ea9a877 2607 * @brief Sequential receive in master FMPI2C mode an amount of data in non-blocking mode with Interrupt
ganlikun 0:13413ea9a877 2608 * @note This interface allow to manage repeated start condition when a direction change during transfer
ganlikun 0:13413ea9a877 2609 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2610 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2611 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 2612 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 2613 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 2614 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 2615 * @param XferOptions Options of Transfer, value of @ref FMPI2C_XFEROPTIONS
ganlikun 0:13413ea9a877 2616 * @retval HAL status
ganlikun 0:13413ea9a877 2617 */
ganlikun 0:13413ea9a877 2618 HAL_StatusTypeDef HAL_FMPI2C_Master_Sequential_Receive_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions)
ganlikun 0:13413ea9a877 2619 {
ganlikun 0:13413ea9a877 2620 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 2621 uint32_t xferrequest = FMPI2C_GENERATE_START_READ;
ganlikun 0:13413ea9a877 2622
ganlikun 0:13413ea9a877 2623 /* Check the parameters */
ganlikun 0:13413ea9a877 2624 assert_param(IS_FMPI2C_TRANSFER_OPTIONS_REQUEST(XferOptions));
ganlikun 0:13413ea9a877 2625
ganlikun 0:13413ea9a877 2626 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 2627 {
ganlikun 0:13413ea9a877 2628 /* Process Locked */
ganlikun 0:13413ea9a877 2629 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2630
ganlikun 0:13413ea9a877 2631 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX;
ganlikun 0:13413ea9a877 2632 hfmpi2c->Mode = HAL_FMPI2C_MODE_MASTER;
ganlikun 0:13413ea9a877 2633 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2634
ganlikun 0:13413ea9a877 2635 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 2636 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 2637 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 2638 hfmpi2c->XferOptions = XferOptions;
ganlikun 0:13413ea9a877 2639 hfmpi2c->XferISR = FMPI2C_Master_ISR_IT;
ganlikun 0:13413ea9a877 2640
ganlikun 0:13413ea9a877 2641 /* If hfmpi2c->XferCount > MAX_NBYTE_SIZE, use reload mode */
ganlikun 0:13413ea9a877 2642 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 2643 {
ganlikun 0:13413ea9a877 2644 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 2645 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 2646 }
ganlikun 0:13413ea9a877 2647 else
ganlikun 0:13413ea9a877 2648 {
ganlikun 0:13413ea9a877 2649 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 2650 xfermode = hfmpi2c->XferOptions;
ganlikun 0:13413ea9a877 2651 }
ganlikun 0:13413ea9a877 2652
ganlikun 0:13413ea9a877 2653 /* If transfer direction not change, do not generate Restart Condition */
ganlikun 0:13413ea9a877 2654 /* Mean Previous state is same as current state */
ganlikun 0:13413ea9a877 2655 if(hfmpi2c->PreviousState == FMPI2C_STATE_MASTER_BUSY_RX)
ganlikun 0:13413ea9a877 2656 {
ganlikun 0:13413ea9a877 2657 xferrequest = FMPI2C_NO_STARTSTOP;
ganlikun 0:13413ea9a877 2658 }
ganlikun 0:13413ea9a877 2659
ganlikun 0:13413ea9a877 2660 /* Send Slave Address and set NBYTES to read */
ganlikun 0:13413ea9a877 2661 FMPI2C_TransferConfig(hfmpi2c,DevAddress, hfmpi2c->XferSize, xfermode, xferrequest);
ganlikun 0:13413ea9a877 2662
ganlikun 0:13413ea9a877 2663 /* Process Unlocked */
ganlikun 0:13413ea9a877 2664 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2665
ganlikun 0:13413ea9a877 2666 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2667 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2668 process unlock */
ganlikun 0:13413ea9a877 2669 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 2670
ganlikun 0:13413ea9a877 2671 return HAL_OK;
ganlikun 0:13413ea9a877 2672 }
ganlikun 0:13413ea9a877 2673 else
ganlikun 0:13413ea9a877 2674 {
ganlikun 0:13413ea9a877 2675 return HAL_BUSY;
ganlikun 0:13413ea9a877 2676 }
ganlikun 0:13413ea9a877 2677 }
ganlikun 0:13413ea9a877 2678
ganlikun 0:13413ea9a877 2679 /**
ganlikun 0:13413ea9a877 2680 * @brief Sequential transmit in slave/device FMPI2C mode an amount of data in non-blocking mode with Interrupt
ganlikun 0:13413ea9a877 2681 * @note This interface allow to manage repeated start condition when a direction change during transfer
ganlikun 0:13413ea9a877 2682 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2683 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2684 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 2685 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 2686 * @param XferOptions Options of Transfer, value of @ref FMPI2C_XFEROPTIONS
ganlikun 0:13413ea9a877 2687 * @retval HAL status
ganlikun 0:13413ea9a877 2688 */
ganlikun 0:13413ea9a877 2689 HAL_StatusTypeDef HAL_FMPI2C_Slave_Sequential_Transmit_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions)
ganlikun 0:13413ea9a877 2690 {
ganlikun 0:13413ea9a877 2691 /* Check the parameters */
ganlikun 0:13413ea9a877 2692 assert_param(IS_FMPI2C_TRANSFER_OPTIONS_REQUEST(XferOptions));
ganlikun 0:13413ea9a877 2693
ganlikun 0:13413ea9a877 2694 if((hfmpi2c->State & HAL_FMPI2C_STATE_LISTEN) == HAL_FMPI2C_STATE_LISTEN)
ganlikun 0:13413ea9a877 2695 {
ganlikun 0:13413ea9a877 2696 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 2697 {
ganlikun 0:13413ea9a877 2698 return HAL_ERROR;
ganlikun 0:13413ea9a877 2699 }
ganlikun 0:13413ea9a877 2700
ganlikun 0:13413ea9a877 2701 /* Disable Interrupts, to prevent preemption during treatment in case of multicall */
ganlikun 0:13413ea9a877 2702 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT | FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 2703
ganlikun 0:13413ea9a877 2704 /* Process Locked */
ganlikun 0:13413ea9a877 2705 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2706
ganlikun 0:13413ea9a877 2707 /* FMPI2C cannot manage full duplex exchange so disable previous IT enabled if any */
ganlikun 0:13413ea9a877 2708 /* and then toggle the HAL slave RX state to TX state */
ganlikun 0:13413ea9a877 2709 if(hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_RX_LISTEN)
ganlikun 0:13413ea9a877 2710 {
ganlikun 0:13413ea9a877 2711 /* Disable associated Interrupts */
ganlikun 0:13413ea9a877 2712 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 2713 }
ganlikun 0:13413ea9a877 2714
ganlikun 0:13413ea9a877 2715 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_TX_LISTEN;
ganlikun 0:13413ea9a877 2716 hfmpi2c->Mode = HAL_FMPI2C_MODE_SLAVE;
ganlikun 0:13413ea9a877 2717 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2718
ganlikun 0:13413ea9a877 2719 /* Enable Address Acknowledge */
ganlikun 0:13413ea9a877 2720 hfmpi2c->Instance->CR2 &= ~FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 2721
ganlikun 0:13413ea9a877 2722 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 2723 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 2724 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 2725 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 2726 hfmpi2c->XferOptions = XferOptions;
ganlikun 0:13413ea9a877 2727 hfmpi2c->XferISR = FMPI2C_Slave_ISR_IT;
ganlikun 0:13413ea9a877 2728
ganlikun 0:13413ea9a877 2729 if(FMPI2C_GET_DIR(hfmpi2c) == FMPI2C_DIRECTION_RECEIVE)
ganlikun 0:13413ea9a877 2730 {
ganlikun 0:13413ea9a877 2731 /* Clear ADDR flag after prepare the transfer parameters */
ganlikun 0:13413ea9a877 2732 /* This action will generate an acknowledge to the Master */
ganlikun 0:13413ea9a877 2733 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 2734 }
ganlikun 0:13413ea9a877 2735
ganlikun 0:13413ea9a877 2736 /* Process Unlocked */
ganlikun 0:13413ea9a877 2737 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2738
ganlikun 0:13413ea9a877 2739 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2740 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2741 process unlock */
ganlikun 0:13413ea9a877 2742 /* REnable ADDR interrupt */
ganlikun 0:13413ea9a877 2743 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT | FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 2744
ganlikun 0:13413ea9a877 2745 return HAL_OK;
ganlikun 0:13413ea9a877 2746 }
ganlikun 0:13413ea9a877 2747 else
ganlikun 0:13413ea9a877 2748 {
ganlikun 0:13413ea9a877 2749 return HAL_ERROR;
ganlikun 0:13413ea9a877 2750 }
ganlikun 0:13413ea9a877 2751 }
ganlikun 0:13413ea9a877 2752
ganlikun 0:13413ea9a877 2753 /**
ganlikun 0:13413ea9a877 2754 * @brief Sequential receive in slave/device FMPI2C mode an amount of data in non-blocking mode with Interrupt
ganlikun 0:13413ea9a877 2755 * @note This interface allow to manage repeated start condition when a direction change during transfer
ganlikun 0:13413ea9a877 2756 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2757 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2758 * @param pData Pointer to data buffer
ganlikun 0:13413ea9a877 2759 * @param Size Amount of data to be sent
ganlikun 0:13413ea9a877 2760 * @param XferOptions Options of Transfer, value of @ref FMPI2C_XFEROPTIONS
ganlikun 0:13413ea9a877 2761 * @retval HAL status
ganlikun 0:13413ea9a877 2762 */
ganlikun 0:13413ea9a877 2763 HAL_StatusTypeDef HAL_FMPI2C_Slave_Sequential_Receive_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t *pData, uint16_t Size, uint32_t XferOptions)
ganlikun 0:13413ea9a877 2764 {
ganlikun 0:13413ea9a877 2765 /* Check the parameters */
ganlikun 0:13413ea9a877 2766 assert_param(IS_FMPI2C_TRANSFER_OPTIONS_REQUEST(XferOptions));
ganlikun 0:13413ea9a877 2767
ganlikun 0:13413ea9a877 2768 if((hfmpi2c->State & HAL_FMPI2C_STATE_LISTEN) == HAL_FMPI2C_STATE_LISTEN)
ganlikun 0:13413ea9a877 2769 {
ganlikun 0:13413ea9a877 2770 if((pData == NULL) || (Size == 0))
ganlikun 0:13413ea9a877 2771 {
ganlikun 0:13413ea9a877 2772 return HAL_ERROR;
ganlikun 0:13413ea9a877 2773 }
ganlikun 0:13413ea9a877 2774
ganlikun 0:13413ea9a877 2775 /* Disable Interrupts, to prevent preemption during treatment in case of multicall */
ganlikun 0:13413ea9a877 2776 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT | FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 2777
ganlikun 0:13413ea9a877 2778 /* Process Locked */
ganlikun 0:13413ea9a877 2779 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2780
ganlikun 0:13413ea9a877 2781 /* FMPI2C cannot manage full duplex exchange so disable previous IT enabled if any */
ganlikun 0:13413ea9a877 2782 /* and then toggle the HAL slave TX state to RX state */
ganlikun 0:13413ea9a877 2783 if(hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_TX_LISTEN)
ganlikun 0:13413ea9a877 2784 {
ganlikun 0:13413ea9a877 2785 /* Disable associated Interrupts */
ganlikun 0:13413ea9a877 2786 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 2787 }
ganlikun 0:13413ea9a877 2788
ganlikun 0:13413ea9a877 2789 hfmpi2c->State = HAL_FMPI2C_STATE_BUSY_RX_LISTEN;
ganlikun 0:13413ea9a877 2790 hfmpi2c->Mode = HAL_FMPI2C_MODE_SLAVE;
ganlikun 0:13413ea9a877 2791 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 2792
ganlikun 0:13413ea9a877 2793 /* Enable Address Acknowledge */
ganlikun 0:13413ea9a877 2794 hfmpi2c->Instance->CR2 &= ~FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 2795
ganlikun 0:13413ea9a877 2796 /* Prepare transfer parameters */
ganlikun 0:13413ea9a877 2797 hfmpi2c->pBuffPtr = pData;
ganlikun 0:13413ea9a877 2798 hfmpi2c->XferCount = Size;
ganlikun 0:13413ea9a877 2799 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 2800 hfmpi2c->XferOptions = XferOptions;
ganlikun 0:13413ea9a877 2801 hfmpi2c->XferISR = FMPI2C_Slave_ISR_IT;
ganlikun 0:13413ea9a877 2802
ganlikun 0:13413ea9a877 2803 if(FMPI2C_GET_DIR(hfmpi2c) == FMPI2C_DIRECTION_TRANSMIT)
ganlikun 0:13413ea9a877 2804 {
ganlikun 0:13413ea9a877 2805 /* Clear ADDR flag after prepare the transfer parameters */
ganlikun 0:13413ea9a877 2806 /* This action will generate an acknowledge to the Master */
ganlikun 0:13413ea9a877 2807 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 2808 }
ganlikun 0:13413ea9a877 2809
ganlikun 0:13413ea9a877 2810 /* Process Unlocked */
ganlikun 0:13413ea9a877 2811 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2812
ganlikun 0:13413ea9a877 2813 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2814 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2815 process unlock */
ganlikun 0:13413ea9a877 2816 /* REnable ADDR interrupt */
ganlikun 0:13413ea9a877 2817 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT | FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 2818
ganlikun 0:13413ea9a877 2819 return HAL_OK;
ganlikun 0:13413ea9a877 2820 }
ganlikun 0:13413ea9a877 2821 else
ganlikun 0:13413ea9a877 2822 {
ganlikun 0:13413ea9a877 2823 return HAL_ERROR;
ganlikun 0:13413ea9a877 2824 }
ganlikun 0:13413ea9a877 2825 }
ganlikun 0:13413ea9a877 2826
ganlikun 0:13413ea9a877 2827 /**
ganlikun 0:13413ea9a877 2828 * @brief Enable the Address listen mode with Interrupt.
ganlikun 0:13413ea9a877 2829 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2830 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2831 * @retval HAL status
ganlikun 0:13413ea9a877 2832 */
ganlikun 0:13413ea9a877 2833 HAL_StatusTypeDef HAL_FMPI2C_EnableListen_IT(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 2834 {
ganlikun 0:13413ea9a877 2835 if(hfmpi2c->State == HAL_FMPI2C_STATE_READY)
ganlikun 0:13413ea9a877 2836 {
ganlikun 0:13413ea9a877 2837 hfmpi2c->State = HAL_FMPI2C_STATE_LISTEN;
ganlikun 0:13413ea9a877 2838 hfmpi2c->XferISR = FMPI2C_Slave_ISR_IT;
ganlikun 0:13413ea9a877 2839
ganlikun 0:13413ea9a877 2840 /* Enable the Address Match interrupt */
ganlikun 0:13413ea9a877 2841 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 2842
ganlikun 0:13413ea9a877 2843 return HAL_OK;
ganlikun 0:13413ea9a877 2844 }
ganlikun 0:13413ea9a877 2845 else
ganlikun 0:13413ea9a877 2846 {
ganlikun 0:13413ea9a877 2847 return HAL_BUSY;
ganlikun 0:13413ea9a877 2848 }
ganlikun 0:13413ea9a877 2849 }
ganlikun 0:13413ea9a877 2850
ganlikun 0:13413ea9a877 2851 /**
ganlikun 0:13413ea9a877 2852 * @brief Disable the Address listen mode with Interrupt.
ganlikun 0:13413ea9a877 2853 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2854 * the configuration information for the specified FMPI2C
ganlikun 0:13413ea9a877 2855 * @retval HAL status
ganlikun 0:13413ea9a877 2856 */
ganlikun 0:13413ea9a877 2857 HAL_StatusTypeDef HAL_FMPI2C_DisableListen_IT(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 2858 {
ganlikun 0:13413ea9a877 2859 /* Declaration of tmp to prevent undefined behavior of volatile usage */
ganlikun 0:13413ea9a877 2860 uint32_t tmp;
ganlikun 0:13413ea9a877 2861
ganlikun 0:13413ea9a877 2862 /* Disable Address listen mode only if a transfer is not ongoing */
ganlikun 0:13413ea9a877 2863 if(hfmpi2c->State == HAL_FMPI2C_STATE_LISTEN)
ganlikun 0:13413ea9a877 2864 {
ganlikun 0:13413ea9a877 2865 tmp = (uint32_t)(hfmpi2c->State) & FMPI2C_STATE_MSK;
ganlikun 0:13413ea9a877 2866 hfmpi2c->PreviousState = tmp | (uint32_t)(hfmpi2c->Mode);
ganlikun 0:13413ea9a877 2867 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 2868 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 2869 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 2870
ganlikun 0:13413ea9a877 2871 /* Disable the Address Match interrupt */
ganlikun 0:13413ea9a877 2872 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 2873
ganlikun 0:13413ea9a877 2874 return HAL_OK;
ganlikun 0:13413ea9a877 2875 }
ganlikun 0:13413ea9a877 2876 else
ganlikun 0:13413ea9a877 2877 {
ganlikun 0:13413ea9a877 2878 return HAL_BUSY;
ganlikun 0:13413ea9a877 2879 }
ganlikun 0:13413ea9a877 2880 }
ganlikun 0:13413ea9a877 2881
ganlikun 0:13413ea9a877 2882 /**
ganlikun 0:13413ea9a877 2883 * @brief Abort a master FMPI2C IT or DMA process communication with Interrupt.
ganlikun 0:13413ea9a877 2884 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2885 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2886 * @param DevAddress Target device address: The device 7 bits address value
ganlikun 0:13413ea9a877 2887 * in datasheet must be shift at right before call interface
ganlikun 0:13413ea9a877 2888 * @retval HAL status
ganlikun 0:13413ea9a877 2889 */
ganlikun 0:13413ea9a877 2890 HAL_StatusTypeDef HAL_FMPI2C_Master_Abort_IT(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress)
ganlikun 0:13413ea9a877 2891 {
ganlikun 0:13413ea9a877 2892 if(hfmpi2c->Mode == HAL_FMPI2C_MODE_MASTER)
ganlikun 0:13413ea9a877 2893 {
ganlikun 0:13413ea9a877 2894 /* Process Locked */
ganlikun 0:13413ea9a877 2895 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2896
ganlikun 0:13413ea9a877 2897 /* Disable Interrupts */
ganlikun 0:13413ea9a877 2898 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 2899 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 2900
ganlikun 0:13413ea9a877 2901 /* Set State at HAL_FMPI2C_STATE_ABORT */
ganlikun 0:13413ea9a877 2902 hfmpi2c->State = HAL_FMPI2C_STATE_ABORT;
ganlikun 0:13413ea9a877 2903
ganlikun 0:13413ea9a877 2904 /* Set NBYTES to 1 to generate a dummy read on FMPI2C peripheral */
ganlikun 0:13413ea9a877 2905 /* Set AUTOEND mode, this will generate a NACK then STOP condition to abort the current transfer */
ganlikun 0:13413ea9a877 2906 FMPI2C_TransferConfig(hfmpi2c, DevAddress, 1, FMPI2C_AUTOEND_MODE, FMPI2C_GENERATE_STOP);
ganlikun 0:13413ea9a877 2907
ganlikun 0:13413ea9a877 2908 /* Process Unlocked */
ganlikun 0:13413ea9a877 2909 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 2910
ganlikun 0:13413ea9a877 2911 /* Note : The FMPI2C interrupts must be enabled after unlocking current process
ganlikun 0:13413ea9a877 2912 to avoid the risk of FMPI2C interrupt handle execution before current
ganlikun 0:13413ea9a877 2913 process unlock */
ganlikun 0:13413ea9a877 2914 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_CPLT_IT);
ganlikun 0:13413ea9a877 2915
ganlikun 0:13413ea9a877 2916 return HAL_OK;
ganlikun 0:13413ea9a877 2917 }
ganlikun 0:13413ea9a877 2918 else
ganlikun 0:13413ea9a877 2919 {
ganlikun 0:13413ea9a877 2920 /* Wrong usage of abort function */
ganlikun 0:13413ea9a877 2921 /* This function should be used only in case of abort monitored by master device */
ganlikun 0:13413ea9a877 2922 return HAL_ERROR;
ganlikun 0:13413ea9a877 2923 }
ganlikun 0:13413ea9a877 2924 }
ganlikun 0:13413ea9a877 2925
ganlikun 0:13413ea9a877 2926 /**
ganlikun 0:13413ea9a877 2927 * @}
ganlikun 0:13413ea9a877 2928 */
ganlikun 0:13413ea9a877 2929
ganlikun 0:13413ea9a877 2930 /** @defgroup FMPI2C_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
ganlikun 0:13413ea9a877 2931 * @{
ganlikun 0:13413ea9a877 2932 */
ganlikun 0:13413ea9a877 2933
ganlikun 0:13413ea9a877 2934 /**
ganlikun 0:13413ea9a877 2935 * @brief This function handles FMPI2C event interrupt request.
ganlikun 0:13413ea9a877 2936 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2937 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2938 * @retval None
ganlikun 0:13413ea9a877 2939 */
ganlikun 0:13413ea9a877 2940 void HAL_FMPI2C_EV_IRQHandler(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 2941 {
ganlikun 0:13413ea9a877 2942 /* Get current IT Flags and IT sources value */
ganlikun 0:13413ea9a877 2943 uint32_t itflags = READ_REG(hfmpi2c->Instance->ISR);
ganlikun 0:13413ea9a877 2944 uint32_t itsources = READ_REG(hfmpi2c->Instance->CR1);
ganlikun 0:13413ea9a877 2945
ganlikun 0:13413ea9a877 2946 /* FMPI2C events treatment -------------------------------------*/
ganlikun 0:13413ea9a877 2947 if(hfmpi2c->XferISR != NULL)
ganlikun 0:13413ea9a877 2948 {
ganlikun 0:13413ea9a877 2949 hfmpi2c->XferISR(hfmpi2c, itflags, itsources);
ganlikun 0:13413ea9a877 2950 }
ganlikun 0:13413ea9a877 2951 }
ganlikun 0:13413ea9a877 2952
ganlikun 0:13413ea9a877 2953 /**
ganlikun 0:13413ea9a877 2954 * @brief This function handles FMPI2C error interrupt request.
ganlikun 0:13413ea9a877 2955 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 2956 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 2957 * @retval None
ganlikun 0:13413ea9a877 2958 */
ganlikun 0:13413ea9a877 2959 void HAL_FMPI2C_ER_IRQHandler(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 2960 {
ganlikun 0:13413ea9a877 2961 uint32_t itflags = READ_REG(hfmpi2c->Instance->ISR);
ganlikun 0:13413ea9a877 2962 uint32_t itsources = READ_REG(hfmpi2c->Instance->CR1);
ganlikun 0:13413ea9a877 2963
ganlikun 0:13413ea9a877 2964 /* FMPI2C Bus error interrupt occurred ------------------------------------*/
ganlikun 0:13413ea9a877 2965 if(((itflags & FMPI2C_FLAG_BERR) != RESET) && ((itsources & FMPI2C_IT_ERRI) != RESET))
ganlikun 0:13413ea9a877 2966 {
ganlikun 0:13413ea9a877 2967 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_BERR;
ganlikun 0:13413ea9a877 2968
ganlikun 0:13413ea9a877 2969 /* Clear BERR flag */
ganlikun 0:13413ea9a877 2970 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_BERR);
ganlikun 0:13413ea9a877 2971 }
ganlikun 0:13413ea9a877 2972
ganlikun 0:13413ea9a877 2973 /* FMPI2C Over-Run/Under-Run interrupt occurred ----------------------------------------*/
ganlikun 0:13413ea9a877 2974 if(((itflags & FMPI2C_FLAG_OVR) != RESET) && ((itsources & FMPI2C_IT_ERRI) != RESET))
ganlikun 0:13413ea9a877 2975 {
ganlikun 0:13413ea9a877 2976 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_OVR;
ganlikun 0:13413ea9a877 2977
ganlikun 0:13413ea9a877 2978 /* Clear OVR flag */
ganlikun 0:13413ea9a877 2979 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_OVR);
ganlikun 0:13413ea9a877 2980 }
ganlikun 0:13413ea9a877 2981
ganlikun 0:13413ea9a877 2982 /* FMPI2C Arbitration Loss error interrupt occurred -------------------------------------*/
ganlikun 0:13413ea9a877 2983 if(((itflags & FMPI2C_FLAG_ARLO) != RESET) && ((itsources & FMPI2C_IT_ERRI) != RESET))
ganlikun 0:13413ea9a877 2984 {
ganlikun 0:13413ea9a877 2985 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_ARLO;
ganlikun 0:13413ea9a877 2986
ganlikun 0:13413ea9a877 2987 /* Clear ARLO flag */
ganlikun 0:13413ea9a877 2988 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_ARLO);
ganlikun 0:13413ea9a877 2989 }
ganlikun 0:13413ea9a877 2990
ganlikun 0:13413ea9a877 2991 /* Call the Error Callback in case of Error detected */
ganlikun 0:13413ea9a877 2992 if((hfmpi2c->ErrorCode & (HAL_FMPI2C_ERROR_BERR | HAL_FMPI2C_ERROR_OVR | HAL_FMPI2C_ERROR_ARLO)) != HAL_FMPI2C_ERROR_NONE)
ganlikun 0:13413ea9a877 2993 {
ganlikun 0:13413ea9a877 2994 FMPI2C_ITError(hfmpi2c, hfmpi2c->ErrorCode);
ganlikun 0:13413ea9a877 2995 }
ganlikun 0:13413ea9a877 2996 }
ganlikun 0:13413ea9a877 2997
ganlikun 0:13413ea9a877 2998 /**
ganlikun 0:13413ea9a877 2999 * @brief Master Tx Transfer completed callback.
ganlikun 0:13413ea9a877 3000 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3001 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3002 * @retval None
ganlikun 0:13413ea9a877 3003 */
ganlikun 0:13413ea9a877 3004 __weak void HAL_FMPI2C_MasterTxCpltCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3005 {
ganlikun 0:13413ea9a877 3006 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3007 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3008
ganlikun 0:13413ea9a877 3009 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3010 the HAL_FMPI2C_MasterTxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 3011 */
ganlikun 0:13413ea9a877 3012 }
ganlikun 0:13413ea9a877 3013
ganlikun 0:13413ea9a877 3014 /**
ganlikun 0:13413ea9a877 3015 * @brief Master Rx Transfer completed callback.
ganlikun 0:13413ea9a877 3016 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3017 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3018 * @retval None
ganlikun 0:13413ea9a877 3019 */
ganlikun 0:13413ea9a877 3020 __weak void HAL_FMPI2C_MasterRxCpltCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3021 {
ganlikun 0:13413ea9a877 3022 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3023 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3024
ganlikun 0:13413ea9a877 3025 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3026 the HAL_FMPI2C_MasterRxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 3027 */
ganlikun 0:13413ea9a877 3028 }
ganlikun 0:13413ea9a877 3029
ganlikun 0:13413ea9a877 3030 /** @brief Slave Tx Transfer completed callback.
ganlikun 0:13413ea9a877 3031 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3032 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3033 * @retval None
ganlikun 0:13413ea9a877 3034 */
ganlikun 0:13413ea9a877 3035 __weak void HAL_FMPI2C_SlaveTxCpltCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3036 {
ganlikun 0:13413ea9a877 3037 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3038 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3039
ganlikun 0:13413ea9a877 3040 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3041 the HAL_FMPI2C_SlaveTxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 3042 */
ganlikun 0:13413ea9a877 3043 }
ganlikun 0:13413ea9a877 3044
ganlikun 0:13413ea9a877 3045 /**
ganlikun 0:13413ea9a877 3046 * @brief Slave Rx Transfer completed callback.
ganlikun 0:13413ea9a877 3047 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3048 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3049 * @retval None
ganlikun 0:13413ea9a877 3050 */
ganlikun 0:13413ea9a877 3051 __weak void HAL_FMPI2C_SlaveRxCpltCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3052 {
ganlikun 0:13413ea9a877 3053 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3054 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3055
ganlikun 0:13413ea9a877 3056 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3057 the HAL_FMPI2C_SlaveRxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 3058 */
ganlikun 0:13413ea9a877 3059 }
ganlikun 0:13413ea9a877 3060
ganlikun 0:13413ea9a877 3061 /**
ganlikun 0:13413ea9a877 3062 * @brief Slave Address Match callback.
ganlikun 0:13413ea9a877 3063 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3064 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3065 * @param TransferDirection: Master request Transfer Direction (Write/Read), value of @ref FMPI2C_XFEROPTIONS
ganlikun 0:13413ea9a877 3066 * @param AddrMatchCode: Address Match Code
ganlikun 0:13413ea9a877 3067 * @retval None
ganlikun 0:13413ea9a877 3068 */
ganlikun 0:13413ea9a877 3069 __weak void HAL_FMPI2C_AddrCallback(FMPI2C_HandleTypeDef *hfmpi2c, uint8_t TransferDirection, uint16_t AddrMatchCode)
ganlikun 0:13413ea9a877 3070 {
ganlikun 0:13413ea9a877 3071 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3072 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3073 UNUSED(TransferDirection);
ganlikun 0:13413ea9a877 3074 UNUSED(AddrMatchCode);
ganlikun 0:13413ea9a877 3075
ganlikun 0:13413ea9a877 3076 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3077 the HAL_FMPI2C_AddrCallback() could be implemented in the user file
ganlikun 0:13413ea9a877 3078 */
ganlikun 0:13413ea9a877 3079 }
ganlikun 0:13413ea9a877 3080
ganlikun 0:13413ea9a877 3081 /**
ganlikun 0:13413ea9a877 3082 * @brief Listen Complete callback.
ganlikun 0:13413ea9a877 3083 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3084 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3085 * @retval None
ganlikun 0:13413ea9a877 3086 */
ganlikun 0:13413ea9a877 3087 __weak void HAL_FMPI2C_ListenCpltCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3088 {
ganlikun 0:13413ea9a877 3089 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3090 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3091
ganlikun 0:13413ea9a877 3092 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3093 the HAL_FMPI2C_ListenCpltCallback() could be implemented in the user file
ganlikun 0:13413ea9a877 3094 */
ganlikun 0:13413ea9a877 3095 }
ganlikun 0:13413ea9a877 3096
ganlikun 0:13413ea9a877 3097 /**
ganlikun 0:13413ea9a877 3098 * @brief Memory Tx Transfer completed callback.
ganlikun 0:13413ea9a877 3099 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3100 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3101 * @retval None
ganlikun 0:13413ea9a877 3102 */
ganlikun 0:13413ea9a877 3103 __weak void HAL_FMPI2C_MemTxCpltCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3104 {
ganlikun 0:13413ea9a877 3105 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3106 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3107
ganlikun 0:13413ea9a877 3108 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3109 the HAL_FMPI2C_MemTxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 3110 */
ganlikun 0:13413ea9a877 3111 }
ganlikun 0:13413ea9a877 3112
ganlikun 0:13413ea9a877 3113 /**
ganlikun 0:13413ea9a877 3114 * @brief Memory Rx Transfer completed callback.
ganlikun 0:13413ea9a877 3115 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3116 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3117 * @retval None
ganlikun 0:13413ea9a877 3118 */
ganlikun 0:13413ea9a877 3119 __weak void HAL_FMPI2C_MemRxCpltCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3120 {
ganlikun 0:13413ea9a877 3121 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3122 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3123
ganlikun 0:13413ea9a877 3124 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3125 the HAL_FMPI2C_MemRxCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 3126 */
ganlikun 0:13413ea9a877 3127 }
ganlikun 0:13413ea9a877 3128
ganlikun 0:13413ea9a877 3129 /**
ganlikun 0:13413ea9a877 3130 * @brief FMPI2C error callback.
ganlikun 0:13413ea9a877 3131 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3132 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3133 * @retval None
ganlikun 0:13413ea9a877 3134 */
ganlikun 0:13413ea9a877 3135 __weak void HAL_FMPI2C_ErrorCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3136 {
ganlikun 0:13413ea9a877 3137 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3138 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3139
ganlikun 0:13413ea9a877 3140 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3141 the HAL_FMPI2C_ErrorCallback could be implemented in the user file
ganlikun 0:13413ea9a877 3142 */
ganlikun 0:13413ea9a877 3143 }
ganlikun 0:13413ea9a877 3144
ganlikun 0:13413ea9a877 3145 /**
ganlikun 0:13413ea9a877 3146 * @brief FMPI2C abort callback.
ganlikun 0:13413ea9a877 3147 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3148 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3149 * @retval None
ganlikun 0:13413ea9a877 3150 */
ganlikun 0:13413ea9a877 3151 __weak void HAL_FMPI2C_AbortCpltCallback(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3152 {
ganlikun 0:13413ea9a877 3153 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 3154 UNUSED(hfmpi2c);
ganlikun 0:13413ea9a877 3155
ganlikun 0:13413ea9a877 3156 /* NOTE : This function should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 3157 the HAL_FMPI2C_AbortCpltCallback could be implemented in the user file
ganlikun 0:13413ea9a877 3158 */
ganlikun 0:13413ea9a877 3159 }
ganlikun 0:13413ea9a877 3160
ganlikun 0:13413ea9a877 3161 /**
ganlikun 0:13413ea9a877 3162 * @}
ganlikun 0:13413ea9a877 3163 */
ganlikun 0:13413ea9a877 3164
ganlikun 0:13413ea9a877 3165 /** @defgroup FMPI2C_Exported_Functions_Group3 Peripheral State, Mode and Error functions
ganlikun 0:13413ea9a877 3166 * @brief Peripheral State, Mode and Error functions
ganlikun 0:13413ea9a877 3167 *
ganlikun 0:13413ea9a877 3168 @verbatim
ganlikun 0:13413ea9a877 3169 ===============================================================================
ganlikun 0:13413ea9a877 3170 ##### Peripheral State, Mode and Error functions #####
ganlikun 0:13413ea9a877 3171 ===============================================================================
ganlikun 0:13413ea9a877 3172 [..]
ganlikun 0:13413ea9a877 3173 This subsection permit to get in run-time the status of the peripheral
ganlikun 0:13413ea9a877 3174 and the data flow.
ganlikun 0:13413ea9a877 3175
ganlikun 0:13413ea9a877 3176 @endverbatim
ganlikun 0:13413ea9a877 3177 * @{
ganlikun 0:13413ea9a877 3178 */
ganlikun 0:13413ea9a877 3179
ganlikun 0:13413ea9a877 3180 /**
ganlikun 0:13413ea9a877 3181 * @brief Return the FMPI2C handle state.
ganlikun 0:13413ea9a877 3182 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3183 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3184 * @retval HAL state
ganlikun 0:13413ea9a877 3185 */
ganlikun 0:13413ea9a877 3186 HAL_FMPI2C_StateTypeDef HAL_FMPI2C_GetState(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3187 {
ganlikun 0:13413ea9a877 3188 /* Return FMPI2C handle state */
ganlikun 0:13413ea9a877 3189 return hfmpi2c->State;
ganlikun 0:13413ea9a877 3190 }
ganlikun 0:13413ea9a877 3191
ganlikun 0:13413ea9a877 3192 /**
ganlikun 0:13413ea9a877 3193 * @brief Returns the FMPI2C Master, Slave, Memory or no mode.
ganlikun 0:13413ea9a877 3194 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3195 * the configuration information for FMPI2C module
ganlikun 0:13413ea9a877 3196 * @retval HAL mode
ganlikun 0:13413ea9a877 3197 */
ganlikun 0:13413ea9a877 3198 HAL_FMPI2C_ModeTypeDef HAL_FMPI2C_GetMode(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3199 {
ganlikun 0:13413ea9a877 3200 return hfmpi2c->Mode;
ganlikun 0:13413ea9a877 3201 }
ganlikun 0:13413ea9a877 3202
ganlikun 0:13413ea9a877 3203 /**
ganlikun 0:13413ea9a877 3204 * @brief Return the FMPI2C error code.
ganlikun 0:13413ea9a877 3205 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3206 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3207 * @retval FMPI2C Error Code
ganlikun 0:13413ea9a877 3208 */
ganlikun 0:13413ea9a877 3209 uint32_t HAL_FMPI2C_GetError(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3210 {
ganlikun 0:13413ea9a877 3211 return hfmpi2c->ErrorCode;
ganlikun 0:13413ea9a877 3212 }
ganlikun 0:13413ea9a877 3213
ganlikun 0:13413ea9a877 3214 /**
ganlikun 0:13413ea9a877 3215 * @}
ganlikun 0:13413ea9a877 3216 */
ganlikun 0:13413ea9a877 3217
ganlikun 0:13413ea9a877 3218 /**
ganlikun 0:13413ea9a877 3219 * @}
ganlikun 0:13413ea9a877 3220 */
ganlikun 0:13413ea9a877 3221
ganlikun 0:13413ea9a877 3222 /** @addtogroup FMPI2C_Private_Functions
ganlikun 0:13413ea9a877 3223 * @{
ganlikun 0:13413ea9a877 3224 */
ganlikun 0:13413ea9a877 3225
ganlikun 0:13413ea9a877 3226 /**
ganlikun 0:13413ea9a877 3227 * @brief Interrupt Sub-Routine which handle the Interrupt Flags Master Mode with Interrupt.
ganlikun 0:13413ea9a877 3228 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3229 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3230 * @param ITFlags Interrupt flags to handle.
ganlikun 0:13413ea9a877 3231 * @param ITSources Interrupt sources enabled.
ganlikun 0:13413ea9a877 3232 * @retval HAL status
ganlikun 0:13413ea9a877 3233 */
ganlikun 0:13413ea9a877 3234 static HAL_StatusTypeDef FMPI2C_Master_ISR_IT(struct __FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags, uint32_t ITSources)
ganlikun 0:13413ea9a877 3235 {
ganlikun 0:13413ea9a877 3236 uint16_t devaddress = 0;
ganlikun 0:13413ea9a877 3237
ganlikun 0:13413ea9a877 3238 /* Process Locked */
ganlikun 0:13413ea9a877 3239 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3240
ganlikun 0:13413ea9a877 3241 if(((ITFlags & FMPI2C_FLAG_AF) != RESET) && ((ITSources & FMPI2C_IT_NACKI) != RESET))
ganlikun 0:13413ea9a877 3242 {
ganlikun 0:13413ea9a877 3243 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 3244 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 3245
ganlikun 0:13413ea9a877 3246 /* Set corresponding Error Code */
ganlikun 0:13413ea9a877 3247 /* No need to generate STOP, it is automatically done */
ganlikun 0:13413ea9a877 3248 /* Error callback will be send during stop flag treatment */
ganlikun 0:13413ea9a877 3249 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 3250
ganlikun 0:13413ea9a877 3251 /* Flush TX register */
ganlikun 0:13413ea9a877 3252 FMPI2C_Flush_TXDR(hfmpi2c);
ganlikun 0:13413ea9a877 3253 }
ganlikun 0:13413ea9a877 3254 else if(((ITFlags & FMPI2C_FLAG_RXNE) != RESET) && ((ITSources & FMPI2C_IT_RXI) != RESET))
ganlikun 0:13413ea9a877 3255 {
ganlikun 0:13413ea9a877 3256 /* Read data from RXDR */
ganlikun 0:13413ea9a877 3257 (*hfmpi2c->pBuffPtr++) = hfmpi2c->Instance->RXDR;
ganlikun 0:13413ea9a877 3258 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 3259 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 3260 }
ganlikun 0:13413ea9a877 3261 else if(((ITFlags & FMPI2C_FLAG_TXIS) != RESET) && ((ITSources & FMPI2C_IT_TXI) != RESET))
ganlikun 0:13413ea9a877 3262 {
ganlikun 0:13413ea9a877 3263 /* Write data to TXDR */
ganlikun 0:13413ea9a877 3264 hfmpi2c->Instance->TXDR = (*hfmpi2c->pBuffPtr++);
ganlikun 0:13413ea9a877 3265 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 3266 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 3267 }
ganlikun 0:13413ea9a877 3268 else if(((ITFlags & FMPI2C_FLAG_TCR) != RESET) && ((ITSources & FMPI2C_IT_TCI) != RESET))
ganlikun 0:13413ea9a877 3269 {
ganlikun 0:13413ea9a877 3270 if((hfmpi2c->XferSize == 0U) && (hfmpi2c->XferCount != 0U))
ganlikun 0:13413ea9a877 3271 {
ganlikun 0:13413ea9a877 3272 devaddress = (hfmpi2c->Instance->CR2 & FMPI2C_CR2_SADD);
ganlikun 0:13413ea9a877 3273
ganlikun 0:13413ea9a877 3274 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 3275 {
ganlikun 0:13413ea9a877 3276 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 3277 FMPI2C_TransferConfig(hfmpi2c, devaddress, hfmpi2c->XferSize, FMPI2C_RELOAD_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 3278 }
ganlikun 0:13413ea9a877 3279 else
ganlikun 0:13413ea9a877 3280 {
ganlikun 0:13413ea9a877 3281 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 3282 if(hfmpi2c->XferOptions != FMPI2C_NO_OPTION_FRAME)
ganlikun 0:13413ea9a877 3283 {
ganlikun 0:13413ea9a877 3284 FMPI2C_TransferConfig(hfmpi2c, devaddress, hfmpi2c->XferSize, hfmpi2c->XferOptions, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 3285 }
ganlikun 0:13413ea9a877 3286 else
ganlikun 0:13413ea9a877 3287 {
ganlikun 0:13413ea9a877 3288 FMPI2C_TransferConfig(hfmpi2c, devaddress, hfmpi2c->XferSize, FMPI2C_AUTOEND_MODE, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 3289 }
ganlikun 0:13413ea9a877 3290 }
ganlikun 0:13413ea9a877 3291 }
ganlikun 0:13413ea9a877 3292 else
ganlikun 0:13413ea9a877 3293 {
ganlikun 0:13413ea9a877 3294 /* Call TxCpltCallback() if no stop mode is set */
ganlikun 0:13413ea9a877 3295 if((FMPI2C_GET_STOP_MODE(hfmpi2c) != FMPI2C_AUTOEND_MODE)&&(hfmpi2c->Mode == HAL_FMPI2C_MODE_MASTER))
ganlikun 0:13413ea9a877 3296 {
ganlikun 0:13413ea9a877 3297 /* Call FMPI2C Master Sequential complete process */
ganlikun 0:13413ea9a877 3298 FMPI2C_ITMasterSequentialCplt(hfmpi2c);
ganlikun 0:13413ea9a877 3299 }
ganlikun 0:13413ea9a877 3300 else
ganlikun 0:13413ea9a877 3301 {
ganlikun 0:13413ea9a877 3302 /* Wrong size Status regarding TCR flag event */
ganlikun 0:13413ea9a877 3303 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3304 FMPI2C_ITError(hfmpi2c, HAL_FMPI2C_ERROR_SIZE);
ganlikun 0:13413ea9a877 3305 }
ganlikun 0:13413ea9a877 3306 }
ganlikun 0:13413ea9a877 3307 }
ganlikun 0:13413ea9a877 3308 else if(((ITFlags & FMPI2C_FLAG_TC) != RESET) && ((ITSources & FMPI2C_IT_TCI) != RESET))
ganlikun 0:13413ea9a877 3309 {
ganlikun 0:13413ea9a877 3310 if(hfmpi2c->XferCount == 0U)
ganlikun 0:13413ea9a877 3311 {
ganlikun 0:13413ea9a877 3312 if((FMPI2C_GET_STOP_MODE(hfmpi2c) != FMPI2C_AUTOEND_MODE)&&(hfmpi2c->Mode == HAL_FMPI2C_MODE_MASTER))
ganlikun 0:13413ea9a877 3313 {
ganlikun 0:13413ea9a877 3314 /* Call FMPI2C Master Sequential complete process */
ganlikun 0:13413ea9a877 3315 FMPI2C_ITMasterSequentialCplt(hfmpi2c);
ganlikun 0:13413ea9a877 3316 }
ganlikun 0:13413ea9a877 3317 }
ganlikun 0:13413ea9a877 3318 else
ganlikun 0:13413ea9a877 3319 {
ganlikun 0:13413ea9a877 3320 /* Wrong size Status regarding TC flag event */
ganlikun 0:13413ea9a877 3321 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3322 FMPI2C_ITError(hfmpi2c, HAL_FMPI2C_ERROR_SIZE);
ganlikun 0:13413ea9a877 3323 }
ganlikun 0:13413ea9a877 3324 }
ganlikun 0:13413ea9a877 3325
ganlikun 0:13413ea9a877 3326 if(((ITFlags & FMPI2C_FLAG_STOPF) != RESET) && ((ITSources & FMPI2C_IT_STOPI) != RESET))
ganlikun 0:13413ea9a877 3327 {
ganlikun 0:13413ea9a877 3328 /* Call FMPI2C Master complete process */
ganlikun 0:13413ea9a877 3329 FMPI2C_ITMasterCplt(hfmpi2c, ITFlags);
ganlikun 0:13413ea9a877 3330 }
ganlikun 0:13413ea9a877 3331
ganlikun 0:13413ea9a877 3332 /* Process Unlocked */
ganlikun 0:13413ea9a877 3333 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3334
ganlikun 0:13413ea9a877 3335 return HAL_OK;
ganlikun 0:13413ea9a877 3336 }
ganlikun 0:13413ea9a877 3337
ganlikun 0:13413ea9a877 3338 /**
ganlikun 0:13413ea9a877 3339 * @brief Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode with Interrupt.
ganlikun 0:13413ea9a877 3340 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3341 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3342 * @param ITFlags Interrupt flags to handle.
ganlikun 0:13413ea9a877 3343 * @param ITSources Interrupt sources enabled.
ganlikun 0:13413ea9a877 3344 * @retval HAL status
ganlikun 0:13413ea9a877 3345 */
ganlikun 0:13413ea9a877 3346 static HAL_StatusTypeDef FMPI2C_Slave_ISR_IT(struct __FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags, uint32_t ITSources)
ganlikun 0:13413ea9a877 3347 {
ganlikun 0:13413ea9a877 3348 /* Process locked */
ganlikun 0:13413ea9a877 3349 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3350
ganlikun 0:13413ea9a877 3351 if(((ITFlags & FMPI2C_FLAG_AF) != RESET) && ((ITSources & FMPI2C_IT_NACKI) != RESET))
ganlikun 0:13413ea9a877 3352 {
ganlikun 0:13413ea9a877 3353 /* Check that FMPI2C transfer finished */
ganlikun 0:13413ea9a877 3354 /* if yes, normal use case, a NACK is sent by the MASTER when Transfer is finished */
ganlikun 0:13413ea9a877 3355 /* Mean XferCount == 0*/
ganlikun 0:13413ea9a877 3356 /* So clear Flag NACKF only */
ganlikun 0:13413ea9a877 3357 if(hfmpi2c->XferCount == 0U)
ganlikun 0:13413ea9a877 3358 {
ganlikun 0:13413ea9a877 3359 if(((hfmpi2c->XferOptions == FMPI2C_FIRST_AND_LAST_FRAME) || (hfmpi2c->XferOptions == FMPI2C_LAST_FRAME)) && \
ganlikun 0:13413ea9a877 3360 (hfmpi2c->State == HAL_FMPI2C_STATE_LISTEN))
ganlikun 0:13413ea9a877 3361 {
ganlikun 0:13413ea9a877 3362 /* Call FMPI2C Listen complete process */
ganlikun 0:13413ea9a877 3363 FMPI2C_ITListenCplt(hfmpi2c, ITFlags);
ganlikun 0:13413ea9a877 3364 }
ganlikun 0:13413ea9a877 3365 else if((hfmpi2c->XferOptions != FMPI2C_NO_OPTION_FRAME) && (hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_TX_LISTEN))
ganlikun 0:13413ea9a877 3366 {
ganlikun 0:13413ea9a877 3367 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 3368 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 3369
ganlikun 0:13413ea9a877 3370 /* Flush TX register */
ganlikun 0:13413ea9a877 3371 FMPI2C_Flush_TXDR(hfmpi2c);
ganlikun 0:13413ea9a877 3372
ganlikun 0:13413ea9a877 3373 /* Last Byte is Transmitted */
ganlikun 0:13413ea9a877 3374 /* Call FMPI2C Slave Sequential complete process */
ganlikun 0:13413ea9a877 3375 FMPI2C_ITSlaveSequentialCplt(hfmpi2c);
ganlikun 0:13413ea9a877 3376 }
ganlikun 0:13413ea9a877 3377 else
ganlikun 0:13413ea9a877 3378 {
ganlikun 0:13413ea9a877 3379 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 3380 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 3381 }
ganlikun 0:13413ea9a877 3382 }
ganlikun 0:13413ea9a877 3383 else
ganlikun 0:13413ea9a877 3384 {
ganlikun 0:13413ea9a877 3385 /* if no, error use case, a Non-Acknowledge of last Data is generated by the MASTER*/
ganlikun 0:13413ea9a877 3386 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 3387 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 3388
ganlikun 0:13413ea9a877 3389 /* Set ErrorCode corresponding to a Non-Acknowledge */
ganlikun 0:13413ea9a877 3390 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 3391 }
ganlikun 0:13413ea9a877 3392 }
ganlikun 0:13413ea9a877 3393 else if(((ITFlags & FMPI2C_FLAG_RXNE) != RESET) && ((ITSources & FMPI2C_IT_RXI) != RESET))
ganlikun 0:13413ea9a877 3394 {
ganlikun 0:13413ea9a877 3395 if(hfmpi2c->XferCount > 0U)
ganlikun 0:13413ea9a877 3396 {
ganlikun 0:13413ea9a877 3397 /* Read data from RXDR */
ganlikun 0:13413ea9a877 3398 (*hfmpi2c->pBuffPtr++) = hfmpi2c->Instance->RXDR;
ganlikun 0:13413ea9a877 3399 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 3400 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 3401 }
ganlikun 0:13413ea9a877 3402
ganlikun 0:13413ea9a877 3403 if((hfmpi2c->XferCount == 0U) && \
ganlikun 0:13413ea9a877 3404 (hfmpi2c->XferOptions != FMPI2C_NO_OPTION_FRAME))
ganlikun 0:13413ea9a877 3405 {
ganlikun 0:13413ea9a877 3406 /* Call FMPI2C Slave Sequential complete process */
ganlikun 0:13413ea9a877 3407 FMPI2C_ITSlaveSequentialCplt(hfmpi2c);
ganlikun 0:13413ea9a877 3408 }
ganlikun 0:13413ea9a877 3409 }
ganlikun 0:13413ea9a877 3410 else if(((ITFlags & FMPI2C_FLAG_ADDR) != RESET) && ((ITSources & FMPI2C_IT_ADDRI) != RESET))
ganlikun 0:13413ea9a877 3411 {
ganlikun 0:13413ea9a877 3412 FMPI2C_ITAddrCplt(hfmpi2c, ITFlags);
ganlikun 0:13413ea9a877 3413 }
ganlikun 0:13413ea9a877 3414 else if(((ITFlags & FMPI2C_FLAG_TXIS) != RESET) && ((ITSources & FMPI2C_IT_TXI) != RESET))
ganlikun 0:13413ea9a877 3415 {
ganlikun 0:13413ea9a877 3416 /* Write data to TXDR only if XferCount not reach "0" */
ganlikun 0:13413ea9a877 3417 /* A TXIS flag can be set, during STOP treatment */
ganlikun 0:13413ea9a877 3418 /* Check if all Datas have already been sent */
ganlikun 0:13413ea9a877 3419 /* If it is the case, this last write in TXDR is not sent, correspond to a dummy TXIS event */
ganlikun 0:13413ea9a877 3420 if(hfmpi2c->XferCount > 0U)
ganlikun 0:13413ea9a877 3421 {
ganlikun 0:13413ea9a877 3422 /* Write data to TXDR */
ganlikun 0:13413ea9a877 3423 hfmpi2c->Instance->TXDR = (*hfmpi2c->pBuffPtr++);
ganlikun 0:13413ea9a877 3424 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 3425 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 3426 }
ganlikun 0:13413ea9a877 3427 else
ganlikun 0:13413ea9a877 3428 {
ganlikun 0:13413ea9a877 3429 if((hfmpi2c->XferOptions == FMPI2C_NEXT_FRAME) || (hfmpi2c->XferOptions == FMPI2C_FIRST_FRAME))
ganlikun 0:13413ea9a877 3430 {
ganlikun 0:13413ea9a877 3431 /* Last Byte is Transmitted */
ganlikun 0:13413ea9a877 3432 /* Call FMPI2C Slave Sequential complete process */
ganlikun 0:13413ea9a877 3433 FMPI2C_ITSlaveSequentialCplt(hfmpi2c);
ganlikun 0:13413ea9a877 3434 }
ganlikun 0:13413ea9a877 3435 }
ganlikun 0:13413ea9a877 3436 }
ganlikun 0:13413ea9a877 3437
ganlikun 0:13413ea9a877 3438 /* Check if STOPF is set */
ganlikun 0:13413ea9a877 3439 if(((ITFlags & FMPI2C_FLAG_STOPF) != RESET) && ((ITSources & FMPI2C_IT_STOPI) != RESET))
ganlikun 0:13413ea9a877 3440 {
ganlikun 0:13413ea9a877 3441 /* Call FMPI2C Slave complete process */
ganlikun 0:13413ea9a877 3442 FMPI2C_ITSlaveCplt(hfmpi2c, ITFlags);
ganlikun 0:13413ea9a877 3443 }
ganlikun 0:13413ea9a877 3444
ganlikun 0:13413ea9a877 3445 /* Process Unlocked */
ganlikun 0:13413ea9a877 3446 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3447
ganlikun 0:13413ea9a877 3448 return HAL_OK;
ganlikun 0:13413ea9a877 3449 }
ganlikun 0:13413ea9a877 3450
ganlikun 0:13413ea9a877 3451 /**
ganlikun 0:13413ea9a877 3452 * @brief Interrupt Sub-Routine which handle the Interrupt Flags Master Mode with DMA.
ganlikun 0:13413ea9a877 3453 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3454 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3455 * @param ITFlags Interrupt flags to handle.
ganlikun 0:13413ea9a877 3456 * @param ITSources Interrupt sources enabled.
ganlikun 0:13413ea9a877 3457 * @retval HAL status
ganlikun 0:13413ea9a877 3458 */
ganlikun 0:13413ea9a877 3459 static HAL_StatusTypeDef FMPI2C_Master_ISR_DMA(struct __FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags, uint32_t ITSources)
ganlikun 0:13413ea9a877 3460 {
ganlikun 0:13413ea9a877 3461 uint16_t devaddress = 0;
ganlikun 0:13413ea9a877 3462 uint32_t xfermode = 0U;
ganlikun 0:13413ea9a877 3463
ganlikun 0:13413ea9a877 3464 /* Process Locked */
ganlikun 0:13413ea9a877 3465 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3466
ganlikun 0:13413ea9a877 3467 if(((ITFlags & FMPI2C_FLAG_AF) != RESET) && ((ITSources & FMPI2C_IT_NACKI) != RESET))
ganlikun 0:13413ea9a877 3468 {
ganlikun 0:13413ea9a877 3469 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 3470 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 3471
ganlikun 0:13413ea9a877 3472 /* Set corresponding Error Code */
ganlikun 0:13413ea9a877 3473 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 3474
ganlikun 0:13413ea9a877 3475 /* No need to generate STOP, it is automatically done */
ganlikun 0:13413ea9a877 3476 /* But enable STOP interrupt, to treat it */
ganlikun 0:13413ea9a877 3477 /* Error callback will be send during stop flag treatment */
ganlikun 0:13413ea9a877 3478 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_CPLT_IT);
ganlikun 0:13413ea9a877 3479
ganlikun 0:13413ea9a877 3480 /* Flush TX register */
ganlikun 0:13413ea9a877 3481 FMPI2C_Flush_TXDR(hfmpi2c);
ganlikun 0:13413ea9a877 3482 }
ganlikun 0:13413ea9a877 3483 else if(((ITFlags & FMPI2C_FLAG_TCR) != RESET) && ((ITSources & FMPI2C_IT_TCI) != RESET))
ganlikun 0:13413ea9a877 3484 {
ganlikun 0:13413ea9a877 3485 /* Disable TC interrupt */
ganlikun 0:13413ea9a877 3486 __HAL_FMPI2C_DISABLE_IT(hfmpi2c, FMPI2C_IT_TCI);
ganlikun 0:13413ea9a877 3487
ganlikun 0:13413ea9a877 3488 if(hfmpi2c->XferCount != 0U)
ganlikun 0:13413ea9a877 3489 {
ganlikun 0:13413ea9a877 3490 /* Recover Slave address */
ganlikun 0:13413ea9a877 3491 devaddress = (hfmpi2c->Instance->CR2 & FMPI2C_CR2_SADD);
ganlikun 0:13413ea9a877 3492
ganlikun 0:13413ea9a877 3493 /* Prepare the new XferSize to transfer */
ganlikun 0:13413ea9a877 3494 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 3495 {
ganlikun 0:13413ea9a877 3496 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 3497 xfermode = FMPI2C_RELOAD_MODE;
ganlikun 0:13413ea9a877 3498 }
ganlikun 0:13413ea9a877 3499 else
ganlikun 0:13413ea9a877 3500 {
ganlikun 0:13413ea9a877 3501 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 3502 xfermode = FMPI2C_AUTOEND_MODE;
ganlikun 0:13413ea9a877 3503 }
ganlikun 0:13413ea9a877 3504
ganlikun 0:13413ea9a877 3505 /* Set the new XferSize in Nbytes register */
ganlikun 0:13413ea9a877 3506 FMPI2C_TransferConfig(hfmpi2c, devaddress, hfmpi2c->XferSize, xfermode, FMPI2C_NO_STARTSTOP);
ganlikun 0:13413ea9a877 3507
ganlikun 0:13413ea9a877 3508 /* Update XferCount value */
ganlikun 0:13413ea9a877 3509 hfmpi2c->XferCount -= hfmpi2c->XferSize;
ganlikun 0:13413ea9a877 3510
ganlikun 0:13413ea9a877 3511 /* Enable DMA Request */
ganlikun 0:13413ea9a877 3512 if(hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_RX)
ganlikun 0:13413ea9a877 3513 {
ganlikun 0:13413ea9a877 3514 hfmpi2c->Instance->CR1 |= FMPI2C_CR1_RXDMAEN;
ganlikun 0:13413ea9a877 3515 }
ganlikun 0:13413ea9a877 3516 else
ganlikun 0:13413ea9a877 3517 {
ganlikun 0:13413ea9a877 3518 hfmpi2c->Instance->CR1 |= FMPI2C_CR1_TXDMAEN;
ganlikun 0:13413ea9a877 3519 }
ganlikun 0:13413ea9a877 3520 }
ganlikun 0:13413ea9a877 3521 else
ganlikun 0:13413ea9a877 3522 {
ganlikun 0:13413ea9a877 3523 /* Wrong size Status regarding TCR flag event */
ganlikun 0:13413ea9a877 3524 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3525 FMPI2C_ITError(hfmpi2c, HAL_FMPI2C_ERROR_SIZE);
ganlikun 0:13413ea9a877 3526 }
ganlikun 0:13413ea9a877 3527 }
ganlikun 0:13413ea9a877 3528 else if(((ITFlags & FMPI2C_FLAG_STOPF) != RESET) && ((ITSources & FMPI2C_IT_STOPI) != RESET))
ganlikun 0:13413ea9a877 3529 {
ganlikun 0:13413ea9a877 3530 /* Call FMPI2C Master complete process */
ganlikun 0:13413ea9a877 3531 FMPI2C_ITMasterCplt(hfmpi2c, ITFlags);
ganlikun 0:13413ea9a877 3532 }
ganlikun 0:13413ea9a877 3533
ganlikun 0:13413ea9a877 3534 /* Process Unlocked */
ganlikun 0:13413ea9a877 3535 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3536
ganlikun 0:13413ea9a877 3537 return HAL_OK;
ganlikun 0:13413ea9a877 3538 }
ganlikun 0:13413ea9a877 3539
ganlikun 0:13413ea9a877 3540 /**
ganlikun 0:13413ea9a877 3541 * @brief Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode with DMA.
ganlikun 0:13413ea9a877 3542 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3543 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3544 * @param ITFlags Interrupt flags to handle.
ganlikun 0:13413ea9a877 3545 * @param ITSources Interrupt sources enabled.
ganlikun 0:13413ea9a877 3546 * @retval HAL status
ganlikun 0:13413ea9a877 3547 */
ganlikun 0:13413ea9a877 3548 static HAL_StatusTypeDef FMPI2C_Slave_ISR_DMA(struct __FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags, uint32_t ITSources)
ganlikun 0:13413ea9a877 3549 {
ganlikun 0:13413ea9a877 3550 /* Process locked */
ganlikun 0:13413ea9a877 3551 __HAL_LOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3552
ganlikun 0:13413ea9a877 3553 if(((ITFlags & FMPI2C_FLAG_AF) != RESET) && ((ITSources & FMPI2C_IT_NACKI) != RESET))
ganlikun 0:13413ea9a877 3554 {
ganlikun 0:13413ea9a877 3555 /* Check that FMPI2C transfer finished */
ganlikun 0:13413ea9a877 3556 /* if yes, normal use case, a NACK is sent by the MASTER when Transfer is finished */
ganlikun 0:13413ea9a877 3557 /* Mean XferCount == 0 */
ganlikun 0:13413ea9a877 3558 /* So clear Flag NACKF only */
ganlikun 0:13413ea9a877 3559 if(FMPI2C_GET_DMA_REMAIN_DATA(hfmpi2c) == 0U)
ganlikun 0:13413ea9a877 3560 {
ganlikun 0:13413ea9a877 3561 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 3562 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 3563 }
ganlikun 0:13413ea9a877 3564 else
ganlikun 0:13413ea9a877 3565 {
ganlikun 0:13413ea9a877 3566 /* if no, error use case, a Non-Acknowledge of last Data is generated by the MASTER*/
ganlikun 0:13413ea9a877 3567 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 3568 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 3569
ganlikun 0:13413ea9a877 3570 /* Set ErrorCode corresponding to a Non-Acknowledge */
ganlikun 0:13413ea9a877 3571 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 3572 }
ganlikun 0:13413ea9a877 3573 }
ganlikun 0:13413ea9a877 3574 else if(((ITFlags & FMPI2C_FLAG_ADDR) != RESET) && ((ITSources & FMPI2C_IT_ADDRI) != RESET))
ganlikun 0:13413ea9a877 3575 {
ganlikun 0:13413ea9a877 3576 /* Clear ADDR flag */
ganlikun 0:13413ea9a877 3577 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 3578 }
ganlikun 0:13413ea9a877 3579 else if(((ITFlags & FMPI2C_FLAG_STOPF) != RESET) && ((ITSources & FMPI2C_IT_STOPI) != RESET))
ganlikun 0:13413ea9a877 3580 {
ganlikun 0:13413ea9a877 3581 /* Call FMPI2C Slave complete process */
ganlikun 0:13413ea9a877 3582 FMPI2C_ITSlaveCplt(hfmpi2c, ITFlags);
ganlikun 0:13413ea9a877 3583 }
ganlikun 0:13413ea9a877 3584
ganlikun 0:13413ea9a877 3585 /* Process Unlocked */
ganlikun 0:13413ea9a877 3586 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3587
ganlikun 0:13413ea9a877 3588 return HAL_OK;
ganlikun 0:13413ea9a877 3589 }
ganlikun 0:13413ea9a877 3590
ganlikun 0:13413ea9a877 3591 /**
ganlikun 0:13413ea9a877 3592 * @brief Master sends target device address followed by internal memory address for write request.
ganlikun 0:13413ea9a877 3593 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3594 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3595 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 3596 * @param MemAddress Internal memory address
ganlikun 0:13413ea9a877 3597 * @param MemAddSize Size of internal memory address
ganlikun 0:13413ea9a877 3598 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 3599 * @param Tickstart Tick start value
ganlikun 0:13413ea9a877 3600 * @retval HAL status
ganlikun 0:13413ea9a877 3601 */
ganlikun 0:13413ea9a877 3602 static HAL_StatusTypeDef FMPI2C_RequestMemoryWrite(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout, uint32_t Tickstart)
ganlikun 0:13413ea9a877 3603 {
ganlikun 0:13413ea9a877 3604 FMPI2C_TransferConfig(hfmpi2c,DevAddress,MemAddSize, FMPI2C_RELOAD_MODE, FMPI2C_GENERATE_START_WRITE);
ganlikun 0:13413ea9a877 3605
ganlikun 0:13413ea9a877 3606 /* Wait until TXIS flag is set */
ganlikun 0:13413ea9a877 3607 if(FMPI2C_WaitOnTXISFlagUntilTimeout(hfmpi2c, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 3608 {
ganlikun 0:13413ea9a877 3609 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 3610 {
ganlikun 0:13413ea9a877 3611 return HAL_ERROR;
ganlikun 0:13413ea9a877 3612 }
ganlikun 0:13413ea9a877 3613 else
ganlikun 0:13413ea9a877 3614 {
ganlikun 0:13413ea9a877 3615 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 3616 }
ganlikun 0:13413ea9a877 3617 }
ganlikun 0:13413ea9a877 3618
ganlikun 0:13413ea9a877 3619 /* If Memory address size is 8Bit */
ganlikun 0:13413ea9a877 3620 if(MemAddSize == FMPI2C_MEMADD_SIZE_8BIT)
ganlikun 0:13413ea9a877 3621 {
ganlikun 0:13413ea9a877 3622 /* Send Memory Address */
ganlikun 0:13413ea9a877 3623 hfmpi2c->Instance->TXDR = FMPI2C_MEM_ADD_LSB(MemAddress);
ganlikun 0:13413ea9a877 3624 }
ganlikun 0:13413ea9a877 3625 /* If Memory address size is 16Bit */
ganlikun 0:13413ea9a877 3626 else
ganlikun 0:13413ea9a877 3627 {
ganlikun 0:13413ea9a877 3628 /* Send MSB of Memory Address */
ganlikun 0:13413ea9a877 3629 hfmpi2c->Instance->TXDR = FMPI2C_MEM_ADD_MSB(MemAddress);
ganlikun 0:13413ea9a877 3630
ganlikun 0:13413ea9a877 3631 /* Wait until TXIS flag is set */
ganlikun 0:13413ea9a877 3632 if(FMPI2C_WaitOnTXISFlagUntilTimeout(hfmpi2c, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 3633 {
ganlikun 0:13413ea9a877 3634 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 3635 {
ganlikun 0:13413ea9a877 3636 return HAL_ERROR;
ganlikun 0:13413ea9a877 3637 }
ganlikun 0:13413ea9a877 3638 else
ganlikun 0:13413ea9a877 3639 {
ganlikun 0:13413ea9a877 3640 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 3641 }
ganlikun 0:13413ea9a877 3642 }
ganlikun 0:13413ea9a877 3643
ganlikun 0:13413ea9a877 3644 /* Send LSB of Memory Address */
ganlikun 0:13413ea9a877 3645 hfmpi2c->Instance->TXDR = FMPI2C_MEM_ADD_LSB(MemAddress);
ganlikun 0:13413ea9a877 3646 }
ganlikun 0:13413ea9a877 3647
ganlikun 0:13413ea9a877 3648 /* Wait until TCR flag is set */
ganlikun 0:13413ea9a877 3649 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_TCR, RESET, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 3650 {
ganlikun 0:13413ea9a877 3651 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 3652 }
ganlikun 0:13413ea9a877 3653
ganlikun 0:13413ea9a877 3654 return HAL_OK;
ganlikun 0:13413ea9a877 3655 }
ganlikun 0:13413ea9a877 3656
ganlikun 0:13413ea9a877 3657 /**
ganlikun 0:13413ea9a877 3658 * @brief Master sends target device address followed by internal memory address for read request.
ganlikun 0:13413ea9a877 3659 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 3660 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 3661 * @param DevAddress Target device address
ganlikun 0:13413ea9a877 3662 * @param MemAddress Internal memory address
ganlikun 0:13413ea9a877 3663 * @param MemAddSize Size of internal memory address
ganlikun 0:13413ea9a877 3664 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 3665 * @param Tickstart Tick start value
ganlikun 0:13413ea9a877 3666 * @retval HAL status
ganlikun 0:13413ea9a877 3667 */
ganlikun 0:13413ea9a877 3668 static HAL_StatusTypeDef FMPI2C_RequestMemoryRead(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout, uint32_t Tickstart)
ganlikun 0:13413ea9a877 3669 {
ganlikun 0:13413ea9a877 3670 FMPI2C_TransferConfig(hfmpi2c,DevAddress,MemAddSize, FMPI2C_SOFTEND_MODE, FMPI2C_GENERATE_START_WRITE);
ganlikun 0:13413ea9a877 3671
ganlikun 0:13413ea9a877 3672 /* Wait until TXIS flag is set */
ganlikun 0:13413ea9a877 3673 if(FMPI2C_WaitOnTXISFlagUntilTimeout(hfmpi2c, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 3674 {
ganlikun 0:13413ea9a877 3675 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 3676 {
ganlikun 0:13413ea9a877 3677 return HAL_ERROR;
ganlikun 0:13413ea9a877 3678 }
ganlikun 0:13413ea9a877 3679 else
ganlikun 0:13413ea9a877 3680 {
ganlikun 0:13413ea9a877 3681 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 3682 }
ganlikun 0:13413ea9a877 3683 }
ganlikun 0:13413ea9a877 3684
ganlikun 0:13413ea9a877 3685 /* If Memory address size is 8Bit */
ganlikun 0:13413ea9a877 3686 if(MemAddSize == FMPI2C_MEMADD_SIZE_8BIT)
ganlikun 0:13413ea9a877 3687 {
ganlikun 0:13413ea9a877 3688 /* Send Memory Address */
ganlikun 0:13413ea9a877 3689 hfmpi2c->Instance->TXDR = FMPI2C_MEM_ADD_LSB(MemAddress);
ganlikun 0:13413ea9a877 3690 }
ganlikun 0:13413ea9a877 3691 /* If Memory address size is 16Bit */
ganlikun 0:13413ea9a877 3692 else
ganlikun 0:13413ea9a877 3693 {
ganlikun 0:13413ea9a877 3694 /* Send MSB of Memory Address */
ganlikun 0:13413ea9a877 3695 hfmpi2c->Instance->TXDR = FMPI2C_MEM_ADD_MSB(MemAddress);
ganlikun 0:13413ea9a877 3696
ganlikun 0:13413ea9a877 3697 /* Wait until TXIS flag is set */
ganlikun 0:13413ea9a877 3698 if(FMPI2C_WaitOnTXISFlagUntilTimeout(hfmpi2c, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 3699 {
ganlikun 0:13413ea9a877 3700 if(hfmpi2c->ErrorCode == HAL_FMPI2C_ERROR_AF)
ganlikun 0:13413ea9a877 3701 {
ganlikun 0:13413ea9a877 3702 return HAL_ERROR;
ganlikun 0:13413ea9a877 3703 }
ganlikun 0:13413ea9a877 3704 else
ganlikun 0:13413ea9a877 3705 {
ganlikun 0:13413ea9a877 3706 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 3707 }
ganlikun 0:13413ea9a877 3708 }
ganlikun 0:13413ea9a877 3709
ganlikun 0:13413ea9a877 3710 /* Send LSB of Memory Address */
ganlikun 0:13413ea9a877 3711 hfmpi2c->Instance->TXDR = FMPI2C_MEM_ADD_LSB(MemAddress);
ganlikun 0:13413ea9a877 3712 }
ganlikun 0:13413ea9a877 3713
ganlikun 0:13413ea9a877 3714 /* Wait until TC flag is set */
ganlikun 0:13413ea9a877 3715 if(FMPI2C_WaitOnFlagUntilTimeout(hfmpi2c, FMPI2C_FLAG_TC, RESET, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 3716 {
ganlikun 0:13413ea9a877 3717 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 3718 }
ganlikun 0:13413ea9a877 3719
ganlikun 0:13413ea9a877 3720 return HAL_OK;
ganlikun 0:13413ea9a877 3721 }
ganlikun 0:13413ea9a877 3722
ganlikun 0:13413ea9a877 3723 /**
ganlikun 0:13413ea9a877 3724 * @brief FMPI2C Address complete process callback.
ganlikun 0:13413ea9a877 3725 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 3726 * @param ITFlags Interrupt flags to handle.
ganlikun 0:13413ea9a877 3727 * @retval None
ganlikun 0:13413ea9a877 3728 */
ganlikun 0:13413ea9a877 3729 static void FMPI2C_ITAddrCplt(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags)
ganlikun 0:13413ea9a877 3730 {
ganlikun 0:13413ea9a877 3731 uint8_t transferdirection = 0;
ganlikun 0:13413ea9a877 3732 uint16_t slaveaddrcode = 0;
ganlikun 0:13413ea9a877 3733 uint16_t ownadd1code = 0;
ganlikun 0:13413ea9a877 3734 uint16_t ownadd2code = 0;
ganlikun 0:13413ea9a877 3735
ganlikun 0:13413ea9a877 3736 /* In case of Listen state, need to inform upper layer of address match code event */
ganlikun 0:13413ea9a877 3737 if((hfmpi2c->State & HAL_FMPI2C_STATE_LISTEN) == HAL_FMPI2C_STATE_LISTEN)
ganlikun 0:13413ea9a877 3738 {
ganlikun 0:13413ea9a877 3739 transferdirection = FMPI2C_GET_DIR(hfmpi2c);
ganlikun 0:13413ea9a877 3740 slaveaddrcode = FMPI2C_GET_ADDR_MATCH(hfmpi2c);
ganlikun 0:13413ea9a877 3741 ownadd1code = FMPI2C_GET_OWN_ADDRESS1(hfmpi2c);
ganlikun 0:13413ea9a877 3742 ownadd2code = FMPI2C_GET_OWN_ADDRESS2(hfmpi2c);
ganlikun 0:13413ea9a877 3743
ganlikun 0:13413ea9a877 3744 /* If 10bits addressing mode is selected */
ganlikun 0:13413ea9a877 3745 if(hfmpi2c->Init.AddressingMode == FMPI2C_ADDRESSINGMODE_10BIT)
ganlikun 0:13413ea9a877 3746 {
ganlikun 0:13413ea9a877 3747 if((slaveaddrcode & SlaveAddr_MSK) == ((ownadd1code >> SlaveAddr_SHIFT) & SlaveAddr_MSK))
ganlikun 0:13413ea9a877 3748 {
ganlikun 0:13413ea9a877 3749 slaveaddrcode = ownadd1code;
ganlikun 0:13413ea9a877 3750 hfmpi2c->AddrEventCount++;
ganlikun 0:13413ea9a877 3751 if(hfmpi2c->AddrEventCount == 2U)
ganlikun 0:13413ea9a877 3752 {
ganlikun 0:13413ea9a877 3753 /* Reset Address Event counter */
ganlikun 0:13413ea9a877 3754 hfmpi2c->AddrEventCount = 0U;
ganlikun 0:13413ea9a877 3755
ganlikun 0:13413ea9a877 3756 /* Clear ADDR flag */
ganlikun 0:13413ea9a877 3757 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 3758
ganlikun 0:13413ea9a877 3759 /* Process Unlocked */
ganlikun 0:13413ea9a877 3760 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3761
ganlikun 0:13413ea9a877 3762 /* Call Slave Addr callback */
ganlikun 0:13413ea9a877 3763 HAL_FMPI2C_AddrCallback(hfmpi2c, transferdirection, slaveaddrcode);
ganlikun 0:13413ea9a877 3764 }
ganlikun 0:13413ea9a877 3765 }
ganlikun 0:13413ea9a877 3766 else
ganlikun 0:13413ea9a877 3767 {
ganlikun 0:13413ea9a877 3768 slaveaddrcode = ownadd2code;
ganlikun 0:13413ea9a877 3769
ganlikun 0:13413ea9a877 3770 /* Disable ADDR Interrupts */
ganlikun 0:13413ea9a877 3771 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 3772
ganlikun 0:13413ea9a877 3773 /* Process Unlocked */
ganlikun 0:13413ea9a877 3774 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3775
ganlikun 0:13413ea9a877 3776 /* Call Slave Addr callback */
ganlikun 0:13413ea9a877 3777 HAL_FMPI2C_AddrCallback(hfmpi2c, transferdirection, slaveaddrcode);
ganlikun 0:13413ea9a877 3778 }
ganlikun 0:13413ea9a877 3779 }
ganlikun 0:13413ea9a877 3780 /* else 7 bits addressing mode is selected */
ganlikun 0:13413ea9a877 3781 else
ganlikun 0:13413ea9a877 3782 {
ganlikun 0:13413ea9a877 3783 /* Disable ADDR Interrupts */
ganlikun 0:13413ea9a877 3784 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT);
ganlikun 0:13413ea9a877 3785
ganlikun 0:13413ea9a877 3786 /* Process Unlocked */
ganlikun 0:13413ea9a877 3787 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3788
ganlikun 0:13413ea9a877 3789 /* Call Slave Addr callback */
ganlikun 0:13413ea9a877 3790 HAL_FMPI2C_AddrCallback(hfmpi2c, transferdirection, slaveaddrcode);
ganlikun 0:13413ea9a877 3791 }
ganlikun 0:13413ea9a877 3792 }
ganlikun 0:13413ea9a877 3793 /* Else clear address flag only */
ganlikun 0:13413ea9a877 3794 else
ganlikun 0:13413ea9a877 3795 {
ganlikun 0:13413ea9a877 3796 /* Clear ADDR flag */
ganlikun 0:13413ea9a877 3797 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 3798
ganlikun 0:13413ea9a877 3799 /* Process Unlocked */
ganlikun 0:13413ea9a877 3800 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3801 }
ganlikun 0:13413ea9a877 3802 }
ganlikun 0:13413ea9a877 3803
ganlikun 0:13413ea9a877 3804 /**
ganlikun 0:13413ea9a877 3805 * @brief FMPI2C Master sequential complete process.
ganlikun 0:13413ea9a877 3806 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 3807 * @retval None
ganlikun 0:13413ea9a877 3808 */
ganlikun 0:13413ea9a877 3809 static void FMPI2C_ITMasterSequentialCplt(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3810 {
ganlikun 0:13413ea9a877 3811 /* Reset FMPI2C handle mode */
ganlikun 0:13413ea9a877 3812 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 3813
ganlikun 0:13413ea9a877 3814 /* No Generate Stop, to permit restart mode */
ganlikun 0:13413ea9a877 3815 /* The stop will be done at the end of transfer, when FMPI2C_AUTOEND_MODE enable */
ganlikun 0:13413ea9a877 3816 if (hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_TX)
ganlikun 0:13413ea9a877 3817 {
ganlikun 0:13413ea9a877 3818 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 3819 hfmpi2c->PreviousState = FMPI2C_STATE_MASTER_BUSY_TX;
ganlikun 0:13413ea9a877 3820 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 3821
ganlikun 0:13413ea9a877 3822 /* Disable Interrupts */
ganlikun 0:13413ea9a877 3823 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 3824
ganlikun 0:13413ea9a877 3825 /* Process Unlocked */
ganlikun 0:13413ea9a877 3826 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3827
ganlikun 0:13413ea9a877 3828 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3829 HAL_FMPI2C_MasterTxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 3830 }
ganlikun 0:13413ea9a877 3831 /* hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_RX */
ganlikun 0:13413ea9a877 3832 else
ganlikun 0:13413ea9a877 3833 {
ganlikun 0:13413ea9a877 3834 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 3835 hfmpi2c->PreviousState = FMPI2C_STATE_MASTER_BUSY_RX;
ganlikun 0:13413ea9a877 3836 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 3837
ganlikun 0:13413ea9a877 3838 /* Disable Interrupts */
ganlikun 0:13413ea9a877 3839 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 3840
ganlikun 0:13413ea9a877 3841 /* Process Unlocked */
ganlikun 0:13413ea9a877 3842 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3843
ganlikun 0:13413ea9a877 3844 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3845 HAL_FMPI2C_MasterRxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 3846 }
ganlikun 0:13413ea9a877 3847 }
ganlikun 0:13413ea9a877 3848
ganlikun 0:13413ea9a877 3849 /**
ganlikun 0:13413ea9a877 3850 * @brief FMPI2C Slave sequential complete process.
ganlikun 0:13413ea9a877 3851 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 3852 * @retval None
ganlikun 0:13413ea9a877 3853 */
ganlikun 0:13413ea9a877 3854 static void FMPI2C_ITSlaveSequentialCplt(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 3855 {
ganlikun 0:13413ea9a877 3856 /* Reset FMPI2C handle mode */
ganlikun 0:13413ea9a877 3857 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 3858
ganlikun 0:13413ea9a877 3859 if(hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_TX_LISTEN)
ganlikun 0:13413ea9a877 3860 {
ganlikun 0:13413ea9a877 3861 /* Remove HAL_FMPI2C_STATE_SLAVE_BUSY_TX, keep only HAL_FMPI2C_STATE_LISTEN */
ganlikun 0:13413ea9a877 3862 hfmpi2c->State = HAL_FMPI2C_STATE_LISTEN;
ganlikun 0:13413ea9a877 3863 hfmpi2c->PreviousState = FMPI2C_STATE_SLAVE_BUSY_TX;
ganlikun 0:13413ea9a877 3864
ganlikun 0:13413ea9a877 3865 /* Disable Interrupts */
ganlikun 0:13413ea9a877 3866 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 3867
ganlikun 0:13413ea9a877 3868 /* Process Unlocked */
ganlikun 0:13413ea9a877 3869 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3870
ganlikun 0:13413ea9a877 3871 /* Call the Tx complete callback to inform upper layer of the end of transmit process */
ganlikun 0:13413ea9a877 3872 HAL_FMPI2C_SlaveTxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 3873 }
ganlikun 0:13413ea9a877 3874
ganlikun 0:13413ea9a877 3875 else if(hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_RX_LISTEN)
ganlikun 0:13413ea9a877 3876 {
ganlikun 0:13413ea9a877 3877 /* Remove HAL_FMPI2C_STATE_SLAVE_BUSY_RX, keep only HAL_FMPI2C_STATE_LISTEN */
ganlikun 0:13413ea9a877 3878 hfmpi2c->State = HAL_FMPI2C_STATE_LISTEN;
ganlikun 0:13413ea9a877 3879 hfmpi2c->PreviousState = FMPI2C_STATE_SLAVE_BUSY_RX;
ganlikun 0:13413ea9a877 3880
ganlikun 0:13413ea9a877 3881 /* Disable Interrupts */
ganlikun 0:13413ea9a877 3882 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 3883
ganlikun 0:13413ea9a877 3884 /* Process Unlocked */
ganlikun 0:13413ea9a877 3885 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3886
ganlikun 0:13413ea9a877 3887 /* Call the Rx complete callback to inform upper layer of the end of receive process */
ganlikun 0:13413ea9a877 3888 HAL_FMPI2C_SlaveRxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 3889 }
ganlikun 0:13413ea9a877 3890 }
ganlikun 0:13413ea9a877 3891
ganlikun 0:13413ea9a877 3892 /**
ganlikun 0:13413ea9a877 3893 * @brief FMPI2C Master complete process.
ganlikun 0:13413ea9a877 3894 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 3895 * @param ITFlags Interrupt flags to handle.
ganlikun 0:13413ea9a877 3896 * @retval None
ganlikun 0:13413ea9a877 3897 */
ganlikun 0:13413ea9a877 3898 static void FMPI2C_ITMasterCplt(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags)
ganlikun 0:13413ea9a877 3899 {
ganlikun 0:13413ea9a877 3900 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 3901 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 3902
ganlikun 0:13413ea9a877 3903 /* Clear Configuration Register 2 */
ganlikun 0:13413ea9a877 3904 FMPI2C_RESET_CR2(hfmpi2c);
ganlikun 0:13413ea9a877 3905
ganlikun 0:13413ea9a877 3906 /* Reset handle parameters */
ganlikun 0:13413ea9a877 3907 hfmpi2c->PreviousState = FMPI2C_STATE_NONE;
ganlikun 0:13413ea9a877 3908 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 3909 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 3910
ganlikun 0:13413ea9a877 3911 if((ITFlags & FMPI2C_FLAG_AF) != RESET)
ganlikun 0:13413ea9a877 3912 {
ganlikun 0:13413ea9a877 3913 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 3914 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 3915
ganlikun 0:13413ea9a877 3916 /* Set acknowledge error code */
ganlikun 0:13413ea9a877 3917 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 3918 }
ganlikun 0:13413ea9a877 3919
ganlikun 0:13413ea9a877 3920 /* Flush TX register */
ganlikun 0:13413ea9a877 3921 FMPI2C_Flush_TXDR(hfmpi2c);
ganlikun 0:13413ea9a877 3922
ganlikun 0:13413ea9a877 3923 /* Disable Interrupts */
ganlikun 0:13413ea9a877 3924 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_TX_IT| FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 3925
ganlikun 0:13413ea9a877 3926 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3927 if((hfmpi2c->ErrorCode != HAL_FMPI2C_ERROR_NONE) || (hfmpi2c->State == HAL_FMPI2C_STATE_ABORT))
ganlikun 0:13413ea9a877 3928 {
ganlikun 0:13413ea9a877 3929 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3930 FMPI2C_ITError(hfmpi2c, hfmpi2c->ErrorCode);
ganlikun 0:13413ea9a877 3931 }
ganlikun 0:13413ea9a877 3932 /* hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_TX */
ganlikun 0:13413ea9a877 3933 else if(hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_TX)
ganlikun 0:13413ea9a877 3934 {
ganlikun 0:13413ea9a877 3935 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 3936
ganlikun 0:13413ea9a877 3937 if (hfmpi2c->Mode == HAL_FMPI2C_MODE_MEM)
ganlikun 0:13413ea9a877 3938 {
ganlikun 0:13413ea9a877 3939 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 3940
ganlikun 0:13413ea9a877 3941 /* Process Unlocked */
ganlikun 0:13413ea9a877 3942 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3943
ganlikun 0:13413ea9a877 3944 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3945 HAL_FMPI2C_MemTxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 3946 }
ganlikun 0:13413ea9a877 3947 else
ganlikun 0:13413ea9a877 3948 {
ganlikun 0:13413ea9a877 3949 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 3950
ganlikun 0:13413ea9a877 3951 /* Process Unlocked */
ganlikun 0:13413ea9a877 3952 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3953
ganlikun 0:13413ea9a877 3954 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 3955 HAL_FMPI2C_MasterTxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 3956 }
ganlikun 0:13413ea9a877 3957 }
ganlikun 0:13413ea9a877 3958 /* hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_RX */
ganlikun 0:13413ea9a877 3959 else if(hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_RX)
ganlikun 0:13413ea9a877 3960 {
ganlikun 0:13413ea9a877 3961 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 3962
ganlikun 0:13413ea9a877 3963 if (hfmpi2c->Mode == HAL_FMPI2C_MODE_MEM)
ganlikun 0:13413ea9a877 3964 {
ganlikun 0:13413ea9a877 3965 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 3966
ganlikun 0:13413ea9a877 3967 /* Process Unlocked */
ganlikun 0:13413ea9a877 3968 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3969
ganlikun 0:13413ea9a877 3970 HAL_FMPI2C_MemRxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 3971 }
ganlikun 0:13413ea9a877 3972 else
ganlikun 0:13413ea9a877 3973 {
ganlikun 0:13413ea9a877 3974 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 3975
ganlikun 0:13413ea9a877 3976 /* Process Unlocked */
ganlikun 0:13413ea9a877 3977 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 3978
ganlikun 0:13413ea9a877 3979 HAL_FMPI2C_MasterRxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 3980 }
ganlikun 0:13413ea9a877 3981 }
ganlikun 0:13413ea9a877 3982 }
ganlikun 0:13413ea9a877 3983
ganlikun 0:13413ea9a877 3984 /**
ganlikun 0:13413ea9a877 3985 * @brief FMPI2C Slave complete process.
ganlikun 0:13413ea9a877 3986 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 3987 * @param ITFlags Interrupt flags to handle.
ganlikun 0:13413ea9a877 3988 * @retval None
ganlikun 0:13413ea9a877 3989 */
ganlikun 0:13413ea9a877 3990 static void FMPI2C_ITSlaveCplt(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags)
ganlikun 0:13413ea9a877 3991 {
ganlikun 0:13413ea9a877 3992 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 3993 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 3994
ganlikun 0:13413ea9a877 3995 /* Clear ADDR flag */
ganlikun 0:13413ea9a877 3996 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c,FMPI2C_FLAG_ADDR);
ganlikun 0:13413ea9a877 3997
ganlikun 0:13413ea9a877 3998 /* Disable all interrupts */
ganlikun 0:13413ea9a877 3999 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT | FMPI2C_XFER_TX_IT | FMPI2C_XFER_RX_IT);
ganlikun 0:13413ea9a877 4000
ganlikun 0:13413ea9a877 4001 /* Disable Address Acknowledge */
ganlikun 0:13413ea9a877 4002 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 4003
ganlikun 0:13413ea9a877 4004 /* Clear Configuration Register 2 */
ganlikun 0:13413ea9a877 4005 FMPI2C_RESET_CR2(hfmpi2c);
ganlikun 0:13413ea9a877 4006
ganlikun 0:13413ea9a877 4007 /* Flush TX register */
ganlikun 0:13413ea9a877 4008 FMPI2C_Flush_TXDR(hfmpi2c);
ganlikun 0:13413ea9a877 4009
ganlikun 0:13413ea9a877 4010 /* If a DMA is ongoing, Update handle size context */
ganlikun 0:13413ea9a877 4011 if(((hfmpi2c->Instance->CR1 & FMPI2C_CR1_TXDMAEN) == FMPI2C_CR1_TXDMAEN) ||
ganlikun 0:13413ea9a877 4012 ((hfmpi2c->Instance->CR1 & FMPI2C_CR1_RXDMAEN) == FMPI2C_CR1_RXDMAEN))
ganlikun 0:13413ea9a877 4013 {
ganlikun 0:13413ea9a877 4014 hfmpi2c->XferCount = FMPI2C_GET_DMA_REMAIN_DATA(hfmpi2c);
ganlikun 0:13413ea9a877 4015 }
ganlikun 0:13413ea9a877 4016
ganlikun 0:13413ea9a877 4017 /* All data are not transferred, so set error code accordingly */
ganlikun 0:13413ea9a877 4018 if(hfmpi2c->XferCount != 0U)
ganlikun 0:13413ea9a877 4019 {
ganlikun 0:13413ea9a877 4020 /* Set ErrorCode corresponding to a Non-Acknowledge */
ganlikun 0:13413ea9a877 4021 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 4022 }
ganlikun 0:13413ea9a877 4023
ganlikun 0:13413ea9a877 4024 /* Store Last receive data if any */
ganlikun 0:13413ea9a877 4025 if(((ITFlags & FMPI2C_FLAG_RXNE) != RESET))
ganlikun 0:13413ea9a877 4026 {
ganlikun 0:13413ea9a877 4027 /* Read data from RXDR */
ganlikun 0:13413ea9a877 4028 (*hfmpi2c->pBuffPtr++) = hfmpi2c->Instance->RXDR;
ganlikun 0:13413ea9a877 4029
ganlikun 0:13413ea9a877 4030 if((hfmpi2c->XferSize > 0U))
ganlikun 0:13413ea9a877 4031 {
ganlikun 0:13413ea9a877 4032 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 4033 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 4034
ganlikun 0:13413ea9a877 4035 /* Set ErrorCode corresponding to a Non-Acknowledge */
ganlikun 0:13413ea9a877 4036 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 4037 }
ganlikun 0:13413ea9a877 4038 }
ganlikun 0:13413ea9a877 4039
ganlikun 0:13413ea9a877 4040 hfmpi2c->PreviousState = FMPI2C_STATE_NONE;
ganlikun 0:13413ea9a877 4041 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4042 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 4043
ganlikun 0:13413ea9a877 4044 if(hfmpi2c->ErrorCode != HAL_FMPI2C_ERROR_NONE)
ganlikun 0:13413ea9a877 4045 {
ganlikun 0:13413ea9a877 4046 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 4047 FMPI2C_ITError(hfmpi2c, hfmpi2c->ErrorCode);
ganlikun 0:13413ea9a877 4048
ganlikun 0:13413ea9a877 4049 /* Call the Listen Complete callback, to inform upper layer of the end of Listen usecase */
ganlikun 0:13413ea9a877 4050 if(hfmpi2c->State == HAL_FMPI2C_STATE_LISTEN)
ganlikun 0:13413ea9a877 4051 {
ganlikun 0:13413ea9a877 4052 /* Call FMPI2C Listen complete process */
ganlikun 0:13413ea9a877 4053 FMPI2C_ITListenCplt(hfmpi2c, ITFlags);
ganlikun 0:13413ea9a877 4054 }
ganlikun 0:13413ea9a877 4055 }
ganlikun 0:13413ea9a877 4056 else if(hfmpi2c->XferOptions != FMPI2C_NO_OPTION_FRAME)
ganlikun 0:13413ea9a877 4057 {
ganlikun 0:13413ea9a877 4058 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 4059 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4060
ganlikun 0:13413ea9a877 4061 /* Process Unlocked */
ganlikun 0:13413ea9a877 4062 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4063
ganlikun 0:13413ea9a877 4064 /* Call the Listen Complete callback, to inform upper layer of the end of Listen usecase */
ganlikun 0:13413ea9a877 4065 HAL_FMPI2C_ListenCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 4066 }
ganlikun 0:13413ea9a877 4067 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 4068 else if(hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_RX)
ganlikun 0:13413ea9a877 4069 {
ganlikun 0:13413ea9a877 4070 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4071
ganlikun 0:13413ea9a877 4072 /* Process Unlocked */
ganlikun 0:13413ea9a877 4073 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4074
ganlikun 0:13413ea9a877 4075 /* Call the Slave Rx Complete callback */
ganlikun 0:13413ea9a877 4076 HAL_FMPI2C_SlaveRxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 4077 }
ganlikun 0:13413ea9a877 4078 else
ganlikun 0:13413ea9a877 4079 {
ganlikun 0:13413ea9a877 4080 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4081
ganlikun 0:13413ea9a877 4082 /* Process Unlocked */
ganlikun 0:13413ea9a877 4083 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4084
ganlikun 0:13413ea9a877 4085 /* Call the Slave Tx Complete callback */
ganlikun 0:13413ea9a877 4086 HAL_FMPI2C_SlaveTxCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 4087 }
ganlikun 0:13413ea9a877 4088 }
ganlikun 0:13413ea9a877 4089
ganlikun 0:13413ea9a877 4090 /**
ganlikun 0:13413ea9a877 4091 * @brief FMPI2C Listen complete process.
ganlikun 0:13413ea9a877 4092 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 4093 * @param ITFlags Interrupt flags to handle.
ganlikun 0:13413ea9a877 4094 * @retval None
ganlikun 0:13413ea9a877 4095 */
ganlikun 0:13413ea9a877 4096 static void FMPI2C_ITListenCplt(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ITFlags)
ganlikun 0:13413ea9a877 4097 {
ganlikun 0:13413ea9a877 4098 /* Reset handle parameters */
ganlikun 0:13413ea9a877 4099 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 4100 hfmpi2c->PreviousState = FMPI2C_STATE_NONE;
ganlikun 0:13413ea9a877 4101 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4102 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4103 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 4104
ganlikun 0:13413ea9a877 4105 /* Store Last receive data if any */
ganlikun 0:13413ea9a877 4106 if(((ITFlags & FMPI2C_FLAG_RXNE) != RESET))
ganlikun 0:13413ea9a877 4107 {
ganlikun 0:13413ea9a877 4108 /* Read data from RXDR */
ganlikun 0:13413ea9a877 4109 (*hfmpi2c->pBuffPtr++) = hfmpi2c->Instance->RXDR;
ganlikun 0:13413ea9a877 4110
ganlikun 0:13413ea9a877 4111 if((hfmpi2c->XferSize > 0U))
ganlikun 0:13413ea9a877 4112 {
ganlikun 0:13413ea9a877 4113 hfmpi2c->XferSize--;
ganlikun 0:13413ea9a877 4114 hfmpi2c->XferCount--;
ganlikun 0:13413ea9a877 4115
ganlikun 0:13413ea9a877 4116 /* Set ErrorCode corresponding to a Non-Acknowledge */
ganlikun 0:13413ea9a877 4117 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 4118 }
ganlikun 0:13413ea9a877 4119 }
ganlikun 0:13413ea9a877 4120
ganlikun 0:13413ea9a877 4121 /* Disable all Interrupts*/
ganlikun 0:13413ea9a877 4122 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT | FMPI2C_XFER_RX_IT | FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 4123
ganlikun 0:13413ea9a877 4124 /* Clear NACK Flag */
ganlikun 0:13413ea9a877 4125 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 4126
ganlikun 0:13413ea9a877 4127 /* Process Unlocked */
ganlikun 0:13413ea9a877 4128 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4129
ganlikun 0:13413ea9a877 4130 /* Call the Listen Complete callback, to inform upper layer of the end of Listen usecase */
ganlikun 0:13413ea9a877 4131 HAL_FMPI2C_ListenCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 4132 }
ganlikun 0:13413ea9a877 4133
ganlikun 0:13413ea9a877 4134 /**
ganlikun 0:13413ea9a877 4135 * @brief FMPI2C interrupts error process.
ganlikun 0:13413ea9a877 4136 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 4137 * @param ErrorCode Error code to handle.
ganlikun 0:13413ea9a877 4138 * @retval None
ganlikun 0:13413ea9a877 4139 */
ganlikun 0:13413ea9a877 4140 static void FMPI2C_ITError(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t ErrorCode)
ganlikun 0:13413ea9a877 4141 {
ganlikun 0:13413ea9a877 4142 /* Reset handle parameters */
ganlikun 0:13413ea9a877 4143 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4144 hfmpi2c->XferOptions = FMPI2C_NO_OPTION_FRAME;
ganlikun 0:13413ea9a877 4145 hfmpi2c->XferCount = 0U;
ganlikun 0:13413ea9a877 4146
ganlikun 0:13413ea9a877 4147 /* Set new error code */
ganlikun 0:13413ea9a877 4148 hfmpi2c->ErrorCode |= ErrorCode;
ganlikun 0:13413ea9a877 4149
ganlikun 0:13413ea9a877 4150 /* Disable Interrupts */
ganlikun 0:13413ea9a877 4151 if((hfmpi2c->State == HAL_FMPI2C_STATE_LISTEN) ||
ganlikun 0:13413ea9a877 4152 (hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_TX_LISTEN) ||
ganlikun 0:13413ea9a877 4153 (hfmpi2c->State == HAL_FMPI2C_STATE_BUSY_RX_LISTEN))
ganlikun 0:13413ea9a877 4154 {
ganlikun 0:13413ea9a877 4155 /* Disable all interrupts, except interrupts related to LISTEN state */
ganlikun 0:13413ea9a877 4156 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_RX_IT | FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 4157
ganlikun 0:13413ea9a877 4158 /* keep HAL_FMPI2C_STATE_LISTEN if set */
ganlikun 0:13413ea9a877 4159 hfmpi2c->State = HAL_FMPI2C_STATE_LISTEN;
ganlikun 0:13413ea9a877 4160 hfmpi2c->PreviousState = FMPI2C_STATE_NONE;
ganlikun 0:13413ea9a877 4161 hfmpi2c->XferISR = FMPI2C_Slave_ISR_IT;
ganlikun 0:13413ea9a877 4162 }
ganlikun 0:13413ea9a877 4163 else
ganlikun 0:13413ea9a877 4164 {
ganlikun 0:13413ea9a877 4165 /* Disable all interrupts */
ganlikun 0:13413ea9a877 4166 FMPI2C_Disable_IRQ(hfmpi2c, FMPI2C_XFER_LISTEN_IT | FMPI2C_XFER_RX_IT | FMPI2C_XFER_TX_IT);
ganlikun 0:13413ea9a877 4167
ganlikun 0:13413ea9a877 4168 /* If state is an abort treatment on goind, don't change state */
ganlikun 0:13413ea9a877 4169 /* This change will be do later */
ganlikun 0:13413ea9a877 4170 if(hfmpi2c->State != HAL_FMPI2C_STATE_ABORT)
ganlikun 0:13413ea9a877 4171 {
ganlikun 0:13413ea9a877 4172 /* Set HAL_FMPI2C_STATE_READY */
ganlikun 0:13413ea9a877 4173 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4174 }
ganlikun 0:13413ea9a877 4175 hfmpi2c->PreviousState = FMPI2C_STATE_NONE;
ganlikun 0:13413ea9a877 4176 hfmpi2c->XferISR = NULL;
ganlikun 0:13413ea9a877 4177 }
ganlikun 0:13413ea9a877 4178
ganlikun 0:13413ea9a877 4179 /* Abort DMA TX transfer if any */
ganlikun 0:13413ea9a877 4180 if((hfmpi2c->Instance->CR1 & FMPI2C_CR1_TXDMAEN) == FMPI2C_CR1_TXDMAEN)
ganlikun 0:13413ea9a877 4181 {
ganlikun 0:13413ea9a877 4182 hfmpi2c->Instance->CR1 &= ~FMPI2C_CR1_TXDMAEN;
ganlikun 0:13413ea9a877 4183
ganlikun 0:13413ea9a877 4184 /* Set the FMPI2C DMA Abort callback :
ganlikun 0:13413ea9a877 4185 will lead to call HAL_FMPI2C_ErrorCallback() at end of DMA abort procedure */
ganlikun 0:13413ea9a877 4186 hfmpi2c->hdmatx->XferAbortCallback = FMPI2C_DMAAbort;
ganlikun 0:13413ea9a877 4187
ganlikun 0:13413ea9a877 4188 /* Process Unlocked */
ganlikun 0:13413ea9a877 4189 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4190
ganlikun 0:13413ea9a877 4191 if(HAL_DMA_Abort_IT(hfmpi2c->hdmatx) != HAL_OK)
ganlikun 0:13413ea9a877 4192 {
ganlikun 0:13413ea9a877 4193 /* Call Directly XferAbortCallback function in case of error */
ganlikun 0:13413ea9a877 4194 hfmpi2c->hdmatx->XferAbortCallback(hfmpi2c->hdmatx);
ganlikun 0:13413ea9a877 4195 }
ganlikun 0:13413ea9a877 4196 }
ganlikun 0:13413ea9a877 4197 /* Abort DMA RX transfer if any */
ganlikun 0:13413ea9a877 4198 else if((hfmpi2c->Instance->CR1 & FMPI2C_CR1_RXDMAEN) == FMPI2C_CR1_RXDMAEN)
ganlikun 0:13413ea9a877 4199 {
ganlikun 0:13413ea9a877 4200 hfmpi2c->Instance->CR1 &= ~FMPI2C_CR1_RXDMAEN;
ganlikun 0:13413ea9a877 4201
ganlikun 0:13413ea9a877 4202 /* Set the FMPI2C DMA Abort callback :
ganlikun 0:13413ea9a877 4203 will lead to call HAL_FMPI2C_ErrorCallback() at end of DMA abort procedure */
ganlikun 0:13413ea9a877 4204 hfmpi2c->hdmarx->XferAbortCallback = FMPI2C_DMAAbort;
ganlikun 0:13413ea9a877 4205
ganlikun 0:13413ea9a877 4206 /* Process Unlocked */
ganlikun 0:13413ea9a877 4207 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4208
ganlikun 0:13413ea9a877 4209 if(HAL_DMA_Abort_IT(hfmpi2c->hdmarx) != HAL_OK)
ganlikun 0:13413ea9a877 4210 {
ganlikun 0:13413ea9a877 4211 /* Call Directly XferAbortCallback function in case of error */
ganlikun 0:13413ea9a877 4212 hfmpi2c->hdmarx->XferAbortCallback(hfmpi2c->hdmarx);
ganlikun 0:13413ea9a877 4213 }
ganlikun 0:13413ea9a877 4214 }
ganlikun 0:13413ea9a877 4215 else if(hfmpi2c->State == HAL_FMPI2C_STATE_ABORT)
ganlikun 0:13413ea9a877 4216 {
ganlikun 0:13413ea9a877 4217 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4218
ganlikun 0:13413ea9a877 4219 /* Process Unlocked */
ganlikun 0:13413ea9a877 4220 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4221
ganlikun 0:13413ea9a877 4222 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 4223 HAL_FMPI2C_AbortCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 4224 }
ganlikun 0:13413ea9a877 4225 else
ganlikun 0:13413ea9a877 4226 {
ganlikun 0:13413ea9a877 4227 /* Process Unlocked */
ganlikun 0:13413ea9a877 4228 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4229
ganlikun 0:13413ea9a877 4230 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 4231 HAL_FMPI2C_ErrorCallback(hfmpi2c);
ganlikun 0:13413ea9a877 4232 }
ganlikun 0:13413ea9a877 4233 }
ganlikun 0:13413ea9a877 4234
ganlikun 0:13413ea9a877 4235 /**
ganlikun 0:13413ea9a877 4236 * @brief FMPI2C Tx data register flush process.
ganlikun 0:13413ea9a877 4237 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 4238 * @retval None
ganlikun 0:13413ea9a877 4239 */
ganlikun 0:13413ea9a877 4240 static void FMPI2C_Flush_TXDR(FMPI2C_HandleTypeDef *hfmpi2c)
ganlikun 0:13413ea9a877 4241 {
ganlikun 0:13413ea9a877 4242 /* If a pending TXIS flag is set */
ganlikun 0:13413ea9a877 4243 /* Write a dummy data in TXDR to clear it */
ganlikun 0:13413ea9a877 4244 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_TXIS) != RESET)
ganlikun 0:13413ea9a877 4245 {
ganlikun 0:13413ea9a877 4246 hfmpi2c->Instance->TXDR = 0x00U;
ganlikun 0:13413ea9a877 4247 }
ganlikun 0:13413ea9a877 4248
ganlikun 0:13413ea9a877 4249 /* Flush TX register if not empty */
ganlikun 0:13413ea9a877 4250 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_TXE) == RESET)
ganlikun 0:13413ea9a877 4251 {
ganlikun 0:13413ea9a877 4252 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_TXE);
ganlikun 0:13413ea9a877 4253 }
ganlikun 0:13413ea9a877 4254 }
ganlikun 0:13413ea9a877 4255
ganlikun 0:13413ea9a877 4256 /**
ganlikun 0:13413ea9a877 4257 * @brief DMA FMPI2C master transmit process complete callback.
ganlikun 0:13413ea9a877 4258 * @param hdma DMA handle
ganlikun 0:13413ea9a877 4259 * @retval None
ganlikun 0:13413ea9a877 4260 */
ganlikun 0:13413ea9a877 4261 static void FMPI2C_DMAMasterTransmitCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 4262 {
ganlikun 0:13413ea9a877 4263 FMPI2C_HandleTypeDef* hfmpi2c = (FMPI2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
ganlikun 0:13413ea9a877 4264
ganlikun 0:13413ea9a877 4265 /* Disable DMA Request */
ganlikun 0:13413ea9a877 4266 hfmpi2c->Instance->CR1 &= ~FMPI2C_CR1_TXDMAEN;
ganlikun 0:13413ea9a877 4267
ganlikun 0:13413ea9a877 4268 /* If last transfer, enable STOP interrupt */
ganlikun 0:13413ea9a877 4269 if(hfmpi2c->XferCount == 0U)
ganlikun 0:13413ea9a877 4270 {
ganlikun 0:13413ea9a877 4271 /* Enable STOP interrupt */
ganlikun 0:13413ea9a877 4272 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_CPLT_IT);
ganlikun 0:13413ea9a877 4273 }
ganlikun 0:13413ea9a877 4274 /* else prepare a new DMA transfer and enable TCReload interrupt */
ganlikun 0:13413ea9a877 4275 else
ganlikun 0:13413ea9a877 4276 {
ganlikun 0:13413ea9a877 4277 /* Update Buffer pointer */
ganlikun 0:13413ea9a877 4278 hfmpi2c->pBuffPtr += hfmpi2c->XferSize;
ganlikun 0:13413ea9a877 4279
ganlikun 0:13413ea9a877 4280 /* Set the XferSize to transfer */
ganlikun 0:13413ea9a877 4281 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 4282 {
ganlikun 0:13413ea9a877 4283 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 4284 }
ganlikun 0:13413ea9a877 4285 else
ganlikun 0:13413ea9a877 4286 {
ganlikun 0:13413ea9a877 4287 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 4288 }
ganlikun 0:13413ea9a877 4289
ganlikun 0:13413ea9a877 4290 /* Enable the DMA channel */
ganlikun 0:13413ea9a877 4291 HAL_DMA_Start_IT(hfmpi2c->hdmatx, (uint32_t)hfmpi2c->pBuffPtr, (uint32_t)&hfmpi2c->Instance->TXDR, hfmpi2c->XferSize);
ganlikun 0:13413ea9a877 4292
ganlikun 0:13413ea9a877 4293 /* Enable TC interrupts */
ganlikun 0:13413ea9a877 4294 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_RELOAD_IT);
ganlikun 0:13413ea9a877 4295 }
ganlikun 0:13413ea9a877 4296 }
ganlikun 0:13413ea9a877 4297
ganlikun 0:13413ea9a877 4298 /**
ganlikun 0:13413ea9a877 4299 * @brief DMA FMPI2C slave transmit process complete callback.
ganlikun 0:13413ea9a877 4300 * @param hdma DMA handle
ganlikun 0:13413ea9a877 4301 * @retval None
ganlikun 0:13413ea9a877 4302 */
ganlikun 0:13413ea9a877 4303 static void FMPI2C_DMASlaveTransmitCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 4304 {
ganlikun 0:13413ea9a877 4305 /* No specific action, Master fully manage the generation of STOP condition */
ganlikun 0:13413ea9a877 4306 /* Mean that this generation can arrive at any time, at the end or during DMA process */
ganlikun 0:13413ea9a877 4307 /* So STOP condition should be manage through Interrupt treatment */
ganlikun 0:13413ea9a877 4308 }
ganlikun 0:13413ea9a877 4309
ganlikun 0:13413ea9a877 4310 /**
ganlikun 0:13413ea9a877 4311 * @brief DMA FMPI2C master receive process complete callback.
ganlikun 0:13413ea9a877 4312 * @param hdma DMA handle
ganlikun 0:13413ea9a877 4313 * @retval None
ganlikun 0:13413ea9a877 4314 */
ganlikun 0:13413ea9a877 4315 static void FMPI2C_DMAMasterReceiveCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 4316 {
ganlikun 0:13413ea9a877 4317 FMPI2C_HandleTypeDef* hfmpi2c = (FMPI2C_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
ganlikun 0:13413ea9a877 4318
ganlikun 0:13413ea9a877 4319 /* Disable DMA Request */
ganlikun 0:13413ea9a877 4320 hfmpi2c->Instance->CR1 &= ~FMPI2C_CR1_RXDMAEN;
ganlikun 0:13413ea9a877 4321
ganlikun 0:13413ea9a877 4322 /* If last transfer, enable STOP interrupt */
ganlikun 0:13413ea9a877 4323 if(hfmpi2c->XferCount == 0U)
ganlikun 0:13413ea9a877 4324 {
ganlikun 0:13413ea9a877 4325 /* Enable STOP interrupt */
ganlikun 0:13413ea9a877 4326 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_CPLT_IT);
ganlikun 0:13413ea9a877 4327 }
ganlikun 0:13413ea9a877 4328 /* else prepare a new DMA transfer and enable TCReload interrupt */
ganlikun 0:13413ea9a877 4329 else
ganlikun 0:13413ea9a877 4330 {
ganlikun 0:13413ea9a877 4331 /* Update Buffer pointer */
ganlikun 0:13413ea9a877 4332 hfmpi2c->pBuffPtr += hfmpi2c->XferSize;
ganlikun 0:13413ea9a877 4333
ganlikun 0:13413ea9a877 4334 /* Set the XferSize to transfer */
ganlikun 0:13413ea9a877 4335 if(hfmpi2c->XferCount > MAX_NBYTE_SIZE)
ganlikun 0:13413ea9a877 4336 {
ganlikun 0:13413ea9a877 4337 hfmpi2c->XferSize = MAX_NBYTE_SIZE;
ganlikun 0:13413ea9a877 4338 }
ganlikun 0:13413ea9a877 4339 else
ganlikun 0:13413ea9a877 4340 {
ganlikun 0:13413ea9a877 4341 hfmpi2c->XferSize = hfmpi2c->XferCount;
ganlikun 0:13413ea9a877 4342 }
ganlikun 0:13413ea9a877 4343
ganlikun 0:13413ea9a877 4344 /* Enable the DMA channel */
ganlikun 0:13413ea9a877 4345 HAL_DMA_Start_IT(hfmpi2c->hdmarx, (uint32_t)&hfmpi2c->Instance->RXDR, (uint32_t)hfmpi2c->pBuffPtr, hfmpi2c->XferSize);
ganlikun 0:13413ea9a877 4346
ganlikun 0:13413ea9a877 4347 /* Enable TC interrupts */
ganlikun 0:13413ea9a877 4348 FMPI2C_Enable_IRQ(hfmpi2c, FMPI2C_XFER_RELOAD_IT);
ganlikun 0:13413ea9a877 4349 }
ganlikun 0:13413ea9a877 4350 }
ganlikun 0:13413ea9a877 4351
ganlikun 0:13413ea9a877 4352 /**
ganlikun 0:13413ea9a877 4353 * @brief DMA FMPI2C slave receive process complete callback.
ganlikun 0:13413ea9a877 4354 * @param hdma DMA handle
ganlikun 0:13413ea9a877 4355 * @retval None
ganlikun 0:13413ea9a877 4356 */
ganlikun 0:13413ea9a877 4357 static void FMPI2C_DMASlaveReceiveCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 4358 {
ganlikun 0:13413ea9a877 4359 /* No specific action, Master fully manage the generation of STOP condition */
ganlikun 0:13413ea9a877 4360 /* Mean that this generation can arrive at any time, at the end or during DMA process */
ganlikun 0:13413ea9a877 4361 /* So STOP condition should be manage through Interrupt treatment */
ganlikun 0:13413ea9a877 4362 }
ganlikun 0:13413ea9a877 4363
ganlikun 0:13413ea9a877 4364 /**
ganlikun 0:13413ea9a877 4365 * @brief DMA FMPI2C communication error callback.
ganlikun 0:13413ea9a877 4366 * @param hdma DMA handle
ganlikun 0:13413ea9a877 4367 * @retval None
ganlikun 0:13413ea9a877 4368 */
ganlikun 0:13413ea9a877 4369 static void FMPI2C_DMAError(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 4370 {
ganlikun 0:13413ea9a877 4371 FMPI2C_HandleTypeDef* hfmpi2c = ( FMPI2C_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 4372
ganlikun 0:13413ea9a877 4373 /* Disable Acknowledge */
ganlikun 0:13413ea9a877 4374 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 4375
ganlikun 0:13413ea9a877 4376 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 4377 FMPI2C_ITError(hfmpi2c, HAL_FMPI2C_ERROR_DMA);
ganlikun 0:13413ea9a877 4378 }
ganlikun 0:13413ea9a877 4379
ganlikun 0:13413ea9a877 4380 /**
ganlikun 0:13413ea9a877 4381 * @brief DMA FMPI2C communication abort callback
ganlikun 0:13413ea9a877 4382 * (To be called at end of DMA Abort procedure).
ganlikun 0:13413ea9a877 4383 * @param hdma: DMA handle.
ganlikun 0:13413ea9a877 4384 * @retval None
ganlikun 0:13413ea9a877 4385 */
ganlikun 0:13413ea9a877 4386 static void FMPI2C_DMAAbort(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 4387 {
ganlikun 0:13413ea9a877 4388 FMPI2C_HandleTypeDef* hfmpi2c = ( FMPI2C_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 4389
ganlikun 0:13413ea9a877 4390 /* Disable Acknowledge */
ganlikun 0:13413ea9a877 4391 hfmpi2c->Instance->CR2 |= FMPI2C_CR2_NACK;
ganlikun 0:13413ea9a877 4392
ganlikun 0:13413ea9a877 4393 /* Reset AbortCpltCallback */
ganlikun 0:13413ea9a877 4394 hfmpi2c->hdmatx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 4395 hfmpi2c->hdmarx->XferAbortCallback = NULL;
ganlikun 0:13413ea9a877 4396
ganlikun 0:13413ea9a877 4397 /* Check if come from abort from user */
ganlikun 0:13413ea9a877 4398 if(hfmpi2c->State == HAL_FMPI2C_STATE_ABORT)
ganlikun 0:13413ea9a877 4399 {
ganlikun 0:13413ea9a877 4400 hfmpi2c->State = HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4401
ganlikun 0:13413ea9a877 4402 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 4403 HAL_FMPI2C_AbortCpltCallback(hfmpi2c);
ganlikun 0:13413ea9a877 4404 }
ganlikun 0:13413ea9a877 4405 else
ganlikun 0:13413ea9a877 4406 {
ganlikun 0:13413ea9a877 4407 /* Call the corresponding callback to inform upper layer of End of Transfer */
ganlikun 0:13413ea9a877 4408 HAL_FMPI2C_ErrorCallback(hfmpi2c);
ganlikun 0:13413ea9a877 4409 }
ganlikun 0:13413ea9a877 4410 }
ganlikun 0:13413ea9a877 4411
ganlikun 0:13413ea9a877 4412 /**
ganlikun 0:13413ea9a877 4413 * @brief This function handles FMPI2C Communication Timeout.
ganlikun 0:13413ea9a877 4414 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 4415 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 4416 * @param Flag Specifies the FMPI2C flag to check.
ganlikun 0:13413ea9a877 4417 * @param Status The new Flag status (SET or RESET).
ganlikun 0:13413ea9a877 4418 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 4419 * @param Tickstart Tick start value
ganlikun 0:13413ea9a877 4420 * @retval HAL status
ganlikun 0:13413ea9a877 4421 */
ganlikun 0:13413ea9a877 4422 static HAL_StatusTypeDef FMPI2C_WaitOnFlagUntilTimeout(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
ganlikun 0:13413ea9a877 4423 {
ganlikun 0:13413ea9a877 4424 while(__HAL_FMPI2C_GET_FLAG(hfmpi2c, Flag) == Status)
ganlikun 0:13413ea9a877 4425 {
ganlikun 0:13413ea9a877 4426 /* Check for the Timeout */
ganlikun 0:13413ea9a877 4427 if(Timeout != HAL_MAX_DELAY)
ganlikun 0:13413ea9a877 4428 {
ganlikun 0:13413ea9a877 4429 if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))
ganlikun 0:13413ea9a877 4430 {
ganlikun 0:13413ea9a877 4431 hfmpi2c->State= HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4432 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4433
ganlikun 0:13413ea9a877 4434 /* Process Unlocked */
ganlikun 0:13413ea9a877 4435 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4436 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 4437 }
ganlikun 0:13413ea9a877 4438 }
ganlikun 0:13413ea9a877 4439 }
ganlikun 0:13413ea9a877 4440 return HAL_OK;
ganlikun 0:13413ea9a877 4441 }
ganlikun 0:13413ea9a877 4442
ganlikun 0:13413ea9a877 4443 /**
ganlikun 0:13413ea9a877 4444 * @brief This function handles FMPI2C Communication Timeout for specific usage of TXIS flag.
ganlikun 0:13413ea9a877 4445 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 4446 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 4447 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 4448 * @param Tickstart Tick start value
ganlikun 0:13413ea9a877 4449 * @retval HAL status
ganlikun 0:13413ea9a877 4450 */
ganlikun 0:13413ea9a877 4451 static HAL_StatusTypeDef FMPI2C_WaitOnTXISFlagUntilTimeout(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Timeout, uint32_t Tickstart)
ganlikun 0:13413ea9a877 4452 {
ganlikun 0:13413ea9a877 4453 while(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_TXIS) == RESET)
ganlikun 0:13413ea9a877 4454 {
ganlikun 0:13413ea9a877 4455 /* Check if a NACK is detected */
ganlikun 0:13413ea9a877 4456 if(FMPI2C_IsAcknowledgeFailed(hfmpi2c, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 4457 {
ganlikun 0:13413ea9a877 4458 return HAL_ERROR;
ganlikun 0:13413ea9a877 4459 }
ganlikun 0:13413ea9a877 4460
ganlikun 0:13413ea9a877 4461 /* Check for the Timeout */
ganlikun 0:13413ea9a877 4462 if(Timeout != HAL_MAX_DELAY)
ganlikun 0:13413ea9a877 4463 {
ganlikun 0:13413ea9a877 4464 if((Timeout == 0U)||((HAL_GetTick() - Tickstart) > Timeout))
ganlikun 0:13413ea9a877 4465 {
ganlikun 0:13413ea9a877 4466 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_TIMEOUT;
ganlikun 0:13413ea9a877 4467 hfmpi2c->State= HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4468 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4469
ganlikun 0:13413ea9a877 4470 /* Process Unlocked */
ganlikun 0:13413ea9a877 4471 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4472
ganlikun 0:13413ea9a877 4473 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 4474 }
ganlikun 0:13413ea9a877 4475 }
ganlikun 0:13413ea9a877 4476 }
ganlikun 0:13413ea9a877 4477 return HAL_OK;
ganlikun 0:13413ea9a877 4478 }
ganlikun 0:13413ea9a877 4479
ganlikun 0:13413ea9a877 4480 /**
ganlikun 0:13413ea9a877 4481 * @brief This function handles FMPI2C Communication Timeout for specific usage of STOP flag.
ganlikun 0:13413ea9a877 4482 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 4483 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 4484 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 4485 * @param Tickstart Tick start value
ganlikun 0:13413ea9a877 4486 * @retval HAL status
ganlikun 0:13413ea9a877 4487 */
ganlikun 0:13413ea9a877 4488 static HAL_StatusTypeDef FMPI2C_WaitOnSTOPFlagUntilTimeout(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Timeout, uint32_t Tickstart)
ganlikun 0:13413ea9a877 4489 {
ganlikun 0:13413ea9a877 4490 while(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF) == RESET)
ganlikun 0:13413ea9a877 4491 {
ganlikun 0:13413ea9a877 4492 /* Check if a NACK is detected */
ganlikun 0:13413ea9a877 4493 if(FMPI2C_IsAcknowledgeFailed(hfmpi2c, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 4494 {
ganlikun 0:13413ea9a877 4495 return HAL_ERROR;
ganlikun 0:13413ea9a877 4496 }
ganlikun 0:13413ea9a877 4497
ganlikun 0:13413ea9a877 4498 /* Check for the Timeout */
ganlikun 0:13413ea9a877 4499 if((Timeout == 0U)||((HAL_GetTick() - Tickstart) > Timeout))
ganlikun 0:13413ea9a877 4500 {
ganlikun 0:13413ea9a877 4501 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_TIMEOUT;
ganlikun 0:13413ea9a877 4502 hfmpi2c->State= HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4503 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4504
ganlikun 0:13413ea9a877 4505 /* Process Unlocked */
ganlikun 0:13413ea9a877 4506 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4507
ganlikun 0:13413ea9a877 4508 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 4509 }
ganlikun 0:13413ea9a877 4510 }
ganlikun 0:13413ea9a877 4511 return HAL_OK;
ganlikun 0:13413ea9a877 4512 }
ganlikun 0:13413ea9a877 4513
ganlikun 0:13413ea9a877 4514 /**
ganlikun 0:13413ea9a877 4515 * @brief This function handles FMPI2C Communication Timeout for specific usage of RXNE flag.
ganlikun 0:13413ea9a877 4516 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 4517 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 4518 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 4519 * @param Tickstart Tick start value
ganlikun 0:13413ea9a877 4520 * @retval HAL status
ganlikun 0:13413ea9a877 4521 */
ganlikun 0:13413ea9a877 4522 static HAL_StatusTypeDef FMPI2C_WaitOnRXNEFlagUntilTimeout(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Timeout, uint32_t Tickstart)
ganlikun 0:13413ea9a877 4523 {
ganlikun 0:13413ea9a877 4524 while(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_RXNE) == RESET)
ganlikun 0:13413ea9a877 4525 {
ganlikun 0:13413ea9a877 4526 /* Check if a NACK is detected */
ganlikun 0:13413ea9a877 4527 if(FMPI2C_IsAcknowledgeFailed(hfmpi2c, Timeout, Tickstart) != HAL_OK)
ganlikun 0:13413ea9a877 4528 {
ganlikun 0:13413ea9a877 4529 return HAL_ERROR;
ganlikun 0:13413ea9a877 4530 }
ganlikun 0:13413ea9a877 4531
ganlikun 0:13413ea9a877 4532 /* Check if a STOPF is detected */
ganlikun 0:13413ea9a877 4533 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF) == SET)
ganlikun 0:13413ea9a877 4534 {
ganlikun 0:13413ea9a877 4535 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 4536 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 4537
ganlikun 0:13413ea9a877 4538 /* Clear Configuration Register 2 */
ganlikun 0:13413ea9a877 4539 FMPI2C_RESET_CR2(hfmpi2c);
ganlikun 0:13413ea9a877 4540
ganlikun 0:13413ea9a877 4541 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_NONE;
ganlikun 0:13413ea9a877 4542 hfmpi2c->State= HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4543 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4544
ganlikun 0:13413ea9a877 4545 /* Process Unlocked */
ganlikun 0:13413ea9a877 4546 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4547
ganlikun 0:13413ea9a877 4548 return HAL_ERROR;
ganlikun 0:13413ea9a877 4549 }
ganlikun 0:13413ea9a877 4550
ganlikun 0:13413ea9a877 4551 /* Check for the Timeout */
ganlikun 0:13413ea9a877 4552 if((Timeout == 0U)||((HAL_GetTick() - Tickstart) > Timeout))
ganlikun 0:13413ea9a877 4553 {
ganlikun 0:13413ea9a877 4554 hfmpi2c->ErrorCode |= HAL_FMPI2C_ERROR_TIMEOUT;
ganlikun 0:13413ea9a877 4555 hfmpi2c->State= HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4556
ganlikun 0:13413ea9a877 4557 /* Process Unlocked */
ganlikun 0:13413ea9a877 4558 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4559
ganlikun 0:13413ea9a877 4560 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 4561 }
ganlikun 0:13413ea9a877 4562 }
ganlikun 0:13413ea9a877 4563 return HAL_OK;
ganlikun 0:13413ea9a877 4564 }
ganlikun 0:13413ea9a877 4565
ganlikun 0:13413ea9a877 4566 /**
ganlikun 0:13413ea9a877 4567 * @brief This function handles Acknowledge failed detection during an FMPI2C Communication.
ganlikun 0:13413ea9a877 4568 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 4569 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 4570 * @param Timeout Timeout duration
ganlikun 0:13413ea9a877 4571 * @param Tickstart Tick start value
ganlikun 0:13413ea9a877 4572 * @retval HAL status
ganlikun 0:13413ea9a877 4573 */
ganlikun 0:13413ea9a877 4574 static HAL_StatusTypeDef FMPI2C_IsAcknowledgeFailed(FMPI2C_HandleTypeDef *hfmpi2c, uint32_t Timeout, uint32_t Tickstart)
ganlikun 0:13413ea9a877 4575 {
ganlikun 0:13413ea9a877 4576 if(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_AF) == SET)
ganlikun 0:13413ea9a877 4577 {
ganlikun 0:13413ea9a877 4578 /* Wait until STOP Flag is reset */
ganlikun 0:13413ea9a877 4579 /* AutoEnd should be initiate after AF */
ganlikun 0:13413ea9a877 4580 while(__HAL_FMPI2C_GET_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF) == RESET)
ganlikun 0:13413ea9a877 4581 {
ganlikun 0:13413ea9a877 4582 /* Check for the Timeout */
ganlikun 0:13413ea9a877 4583 if(Timeout != HAL_MAX_DELAY)
ganlikun 0:13413ea9a877 4584 {
ganlikun 0:13413ea9a877 4585 if((Timeout == 0U)||((HAL_GetTick() - Tickstart) > Timeout))
ganlikun 0:13413ea9a877 4586 {
ganlikun 0:13413ea9a877 4587 hfmpi2c->State= HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4588 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4589
ganlikun 0:13413ea9a877 4590 /* Process Unlocked */
ganlikun 0:13413ea9a877 4591 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4592 return HAL_TIMEOUT;
ganlikun 0:13413ea9a877 4593 }
ganlikun 0:13413ea9a877 4594 }
ganlikun 0:13413ea9a877 4595 }
ganlikun 0:13413ea9a877 4596
ganlikun 0:13413ea9a877 4597 /* Clear NACKF Flag */
ganlikun 0:13413ea9a877 4598 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_AF);
ganlikun 0:13413ea9a877 4599
ganlikun 0:13413ea9a877 4600 /* Clear STOP Flag */
ganlikun 0:13413ea9a877 4601 __HAL_FMPI2C_CLEAR_FLAG(hfmpi2c, FMPI2C_FLAG_STOPF);
ganlikun 0:13413ea9a877 4602
ganlikun 0:13413ea9a877 4603 /* Flush TX register */
ganlikun 0:13413ea9a877 4604 FMPI2C_Flush_TXDR(hfmpi2c);
ganlikun 0:13413ea9a877 4605
ganlikun 0:13413ea9a877 4606 /* Clear Configuration Register 2 */
ganlikun 0:13413ea9a877 4607 FMPI2C_RESET_CR2(hfmpi2c);
ganlikun 0:13413ea9a877 4608
ganlikun 0:13413ea9a877 4609 hfmpi2c->ErrorCode = HAL_FMPI2C_ERROR_AF;
ganlikun 0:13413ea9a877 4610 hfmpi2c->State= HAL_FMPI2C_STATE_READY;
ganlikun 0:13413ea9a877 4611 hfmpi2c->Mode = HAL_FMPI2C_MODE_NONE;
ganlikun 0:13413ea9a877 4612
ganlikun 0:13413ea9a877 4613 /* Process Unlocked */
ganlikun 0:13413ea9a877 4614 __HAL_UNLOCK(hfmpi2c);
ganlikun 0:13413ea9a877 4615
ganlikun 0:13413ea9a877 4616 return HAL_ERROR;
ganlikun 0:13413ea9a877 4617 }
ganlikun 0:13413ea9a877 4618 return HAL_OK;
ganlikun 0:13413ea9a877 4619 }
ganlikun 0:13413ea9a877 4620
ganlikun 0:13413ea9a877 4621 /**
ganlikun 0:13413ea9a877 4622 * @brief Handles FMPI2Cx communication when starting transfer or during transfer (TC or TCR flag are set).
ganlikun 0:13413ea9a877 4623 * @param hfmpi2c FMPI2C handle.
ganlikun 0:13413ea9a877 4624 * @param DevAddress Specifies the slave address to be programmed.
ganlikun 0:13413ea9a877 4625 * @param Size Specifies the number of bytes to be programmed.
ganlikun 0:13413ea9a877 4626 * This parameter must be a value between 0 and 255.
ganlikun 0:13413ea9a877 4627 * @param Mode New state of the FMPI2C START condition generation.
ganlikun 0:13413ea9a877 4628 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 4629 * @arg @ref FMPI2C_RELOAD_MODE Enable Reload mode .
ganlikun 0:13413ea9a877 4630 * @arg @ref FMPI2C_AUTOEND_MODE Enable Automatic end mode.
ganlikun 0:13413ea9a877 4631 * @arg @ref FMPI2C_SOFTEND_MODE Enable Software end mode.
ganlikun 0:13413ea9a877 4632 * @param Request New state of the FMPI2C START condition generation.
ganlikun 0:13413ea9a877 4633 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 4634 * @arg @ref FMPI2C_NO_STARTSTOP Don't Generate stop and start condition.
ganlikun 0:13413ea9a877 4635 * @arg @ref FMPI2C_GENERATE_STOP Generate stop condition (Size should be set to 0).
ganlikun 0:13413ea9a877 4636 * @arg @ref FMPI2C_GENERATE_START_READ Generate Restart for read request.
ganlikun 0:13413ea9a877 4637 * @arg @ref FMPI2C_GENERATE_START_WRITE Generate Restart for write request.
ganlikun 0:13413ea9a877 4638 * @retval None
ganlikun 0:13413ea9a877 4639 */
ganlikun 0:13413ea9a877 4640 static void FMPI2C_TransferConfig(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
ganlikun 0:13413ea9a877 4641 {
ganlikun 0:13413ea9a877 4642 uint32_t tmpreg = 0U;
ganlikun 0:13413ea9a877 4643
ganlikun 0:13413ea9a877 4644 /* Check the parameters */
ganlikun 0:13413ea9a877 4645 assert_param(IS_FMPI2C_ALL_INSTANCE(hfmpi2c->Instance));
ganlikun 0:13413ea9a877 4646 assert_param(IS_TRANSFER_MODE(Mode));
ganlikun 0:13413ea9a877 4647 assert_param(IS_TRANSFER_REQUEST(Request));
ganlikun 0:13413ea9a877 4648
ganlikun 0:13413ea9a877 4649 /* Get the CR2 register value */
ganlikun 0:13413ea9a877 4650 tmpreg = hfmpi2c->Instance->CR2;
ganlikun 0:13413ea9a877 4651
ganlikun 0:13413ea9a877 4652 /* clear tmpreg specific bits */
ganlikun 0:13413ea9a877 4653 tmpreg &= (uint32_t)~((uint32_t)(FMPI2C_CR2_SADD | FMPI2C_CR2_NBYTES | FMPI2C_CR2_RELOAD | FMPI2C_CR2_AUTOEND | FMPI2C_CR2_RD_WRN | FMPI2C_CR2_START | FMPI2C_CR2_STOP));
ganlikun 0:13413ea9a877 4654
ganlikun 0:13413ea9a877 4655 /* update tmpreg */
ganlikun 0:13413ea9a877 4656 tmpreg |= (uint32_t)(((uint32_t)DevAddress & FMPI2C_CR2_SADD) | (((uint32_t)Size << 16U) & FMPI2C_CR2_NBYTES) | \
ganlikun 0:13413ea9a877 4657 (uint32_t)Mode | (uint32_t)Request);
ganlikun 0:13413ea9a877 4658
ganlikun 0:13413ea9a877 4659 /* update CR2 register */
ganlikun 0:13413ea9a877 4660 hfmpi2c->Instance->CR2 = tmpreg;
ganlikun 0:13413ea9a877 4661 }
ganlikun 0:13413ea9a877 4662
ganlikun 0:13413ea9a877 4663 /**
ganlikun 0:13413ea9a877 4664 * @brief Manage the enabling of Interrupts.
ganlikun 0:13413ea9a877 4665 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 4666 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 4667 * @param InterruptRequest Value of @ref FMPI2C_Interrupt_configuration_definition.
ganlikun 0:13413ea9a877 4668 * @retval HAL status
ganlikun 0:13413ea9a877 4669 */
ganlikun 0:13413ea9a877 4670 static HAL_StatusTypeDef FMPI2C_Enable_IRQ(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t InterruptRequest)
ganlikun 0:13413ea9a877 4671 {
ganlikun 0:13413ea9a877 4672 uint32_t tmpisr = 0U;
ganlikun 0:13413ea9a877 4673
ganlikun 0:13413ea9a877 4674 if((hfmpi2c->XferISR == FMPI2C_Master_ISR_DMA) || \
ganlikun 0:13413ea9a877 4675 (hfmpi2c->XferISR == FMPI2C_Slave_ISR_DMA))
ganlikun 0:13413ea9a877 4676 {
ganlikun 0:13413ea9a877 4677 if((InterruptRequest & FMPI2C_XFER_LISTEN_IT) == FMPI2C_XFER_LISTEN_IT)
ganlikun 0:13413ea9a877 4678 {
ganlikun 0:13413ea9a877 4679 /* Enable ERR, STOP, NACK and ADDR interrupts */
ganlikun 0:13413ea9a877 4680 tmpisr |= FMPI2C_IT_ADDRI | FMPI2C_IT_STOPI | FMPI2C_IT_NACKI | FMPI2C_IT_ERRI;
ganlikun 0:13413ea9a877 4681 }
ganlikun 0:13413ea9a877 4682
ganlikun 0:13413ea9a877 4683 if((InterruptRequest & FMPI2C_XFER_ERROR_IT) == FMPI2C_XFER_ERROR_IT)
ganlikun 0:13413ea9a877 4684 {
ganlikun 0:13413ea9a877 4685 /* Enable ERR and NACK interrupts */
ganlikun 0:13413ea9a877 4686 tmpisr |= FMPI2C_IT_ERRI | FMPI2C_IT_NACKI;
ganlikun 0:13413ea9a877 4687 }
ganlikun 0:13413ea9a877 4688
ganlikun 0:13413ea9a877 4689 if((InterruptRequest & FMPI2C_XFER_CPLT_IT) == FMPI2C_XFER_CPLT_IT)
ganlikun 0:13413ea9a877 4690 {
ganlikun 0:13413ea9a877 4691 /* Enable STOP interrupts */
ganlikun 0:13413ea9a877 4692 tmpisr |= FMPI2C_IT_STOPI;
ganlikun 0:13413ea9a877 4693 }
ganlikun 0:13413ea9a877 4694
ganlikun 0:13413ea9a877 4695 if((InterruptRequest & FMPI2C_XFER_RELOAD_IT) == FMPI2C_XFER_RELOAD_IT)
ganlikun 0:13413ea9a877 4696 {
ganlikun 0:13413ea9a877 4697 /* Enable TC interrupts */
ganlikun 0:13413ea9a877 4698 tmpisr |= FMPI2C_IT_TCI;
ganlikun 0:13413ea9a877 4699 }
ganlikun 0:13413ea9a877 4700 }
ganlikun 0:13413ea9a877 4701 else
ganlikun 0:13413ea9a877 4702 {
ganlikun 0:13413ea9a877 4703 if((InterruptRequest & FMPI2C_XFER_LISTEN_IT) == FMPI2C_XFER_LISTEN_IT)
ganlikun 0:13413ea9a877 4704 {
ganlikun 0:13413ea9a877 4705 /* Enable ERR, STOP, NACK, and ADDR interrupts */
ganlikun 0:13413ea9a877 4706 tmpisr |= FMPI2C_IT_ADDRI | FMPI2C_IT_STOPI | FMPI2C_IT_NACKI | FMPI2C_IT_ERRI;
ganlikun 0:13413ea9a877 4707 }
ganlikun 0:13413ea9a877 4708
ganlikun 0:13413ea9a877 4709 if((InterruptRequest & FMPI2C_XFER_TX_IT) == FMPI2C_XFER_TX_IT)
ganlikun 0:13413ea9a877 4710 {
ganlikun 0:13413ea9a877 4711 /* Enable ERR, TC, STOP, NACK and RXI interrupts */
ganlikun 0:13413ea9a877 4712 tmpisr |= FMPI2C_IT_ERRI | FMPI2C_IT_TCI | FMPI2C_IT_STOPI | FMPI2C_IT_NACKI | FMPI2C_IT_TXI;
ganlikun 0:13413ea9a877 4713 }
ganlikun 0:13413ea9a877 4714
ganlikun 0:13413ea9a877 4715 if((InterruptRequest & FMPI2C_XFER_RX_IT) == FMPI2C_XFER_RX_IT)
ganlikun 0:13413ea9a877 4716 {
ganlikun 0:13413ea9a877 4717 /* Enable ERR, TC, STOP, NACK and TXI interrupts */
ganlikun 0:13413ea9a877 4718 tmpisr |= FMPI2C_IT_ERRI | FMPI2C_IT_TCI | FMPI2C_IT_STOPI | FMPI2C_IT_NACKI | FMPI2C_IT_RXI;
ganlikun 0:13413ea9a877 4719 }
ganlikun 0:13413ea9a877 4720
ganlikun 0:13413ea9a877 4721 if((InterruptRequest & FMPI2C_XFER_CPLT_IT) == FMPI2C_XFER_CPLT_IT)
ganlikun 0:13413ea9a877 4722 {
ganlikun 0:13413ea9a877 4723 /* Enable STOP interrupts */
ganlikun 0:13413ea9a877 4724 tmpisr |= FMPI2C_IT_STOPI;
ganlikun 0:13413ea9a877 4725 }
ganlikun 0:13413ea9a877 4726 }
ganlikun 0:13413ea9a877 4727
ganlikun 0:13413ea9a877 4728 /* Enable interrupts only at the end */
ganlikun 0:13413ea9a877 4729 /* to avoid the risk of FMPI2C interrupt handle execution before */
ganlikun 0:13413ea9a877 4730 /* all interrupts requested done */
ganlikun 0:13413ea9a877 4731 __HAL_FMPI2C_ENABLE_IT(hfmpi2c, tmpisr);
ganlikun 0:13413ea9a877 4732
ganlikun 0:13413ea9a877 4733 return HAL_OK;
ganlikun 0:13413ea9a877 4734 }
ganlikun 0:13413ea9a877 4735
ganlikun 0:13413ea9a877 4736 /**
ganlikun 0:13413ea9a877 4737 * @brief Manage the disabling of Interrupts.
ganlikun 0:13413ea9a877 4738 * @param hfmpi2c Pointer to a FMPI2C_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 4739 * the configuration information for the specified FMPI2C.
ganlikun 0:13413ea9a877 4740 * @param InterruptRequest Value of @ref FMPI2C_Interrupt_configuration_definition.
ganlikun 0:13413ea9a877 4741 * @retval HAL status
ganlikun 0:13413ea9a877 4742 */
ganlikun 0:13413ea9a877 4743 static HAL_StatusTypeDef FMPI2C_Disable_IRQ(FMPI2C_HandleTypeDef *hfmpi2c, uint16_t InterruptRequest)
ganlikun 0:13413ea9a877 4744 {
ganlikun 0:13413ea9a877 4745 uint32_t tmpisr = 0U;
ganlikun 0:13413ea9a877 4746
ganlikun 0:13413ea9a877 4747 if((InterruptRequest & FMPI2C_XFER_TX_IT) == FMPI2C_XFER_TX_IT)
ganlikun 0:13413ea9a877 4748 {
ganlikun 0:13413ea9a877 4749 /* Disable TC and TXI interrupts */
ganlikun 0:13413ea9a877 4750 tmpisr |= FMPI2C_IT_TCI | FMPI2C_IT_TXI;
ganlikun 0:13413ea9a877 4751
ganlikun 0:13413ea9a877 4752 if((hfmpi2c->State & HAL_FMPI2C_STATE_LISTEN) != HAL_FMPI2C_STATE_LISTEN)
ganlikun 0:13413ea9a877 4753 {
ganlikun 0:13413ea9a877 4754 /* Disable NACK and STOP interrupts */
ganlikun 0:13413ea9a877 4755 tmpisr |= FMPI2C_IT_STOPI | FMPI2C_IT_NACKI | FMPI2C_IT_ERRI;
ganlikun 0:13413ea9a877 4756 }
ganlikun 0:13413ea9a877 4757 }
ganlikun 0:13413ea9a877 4758
ganlikun 0:13413ea9a877 4759 if((InterruptRequest & FMPI2C_XFER_RX_IT) == FMPI2C_XFER_RX_IT)
ganlikun 0:13413ea9a877 4760 {
ganlikun 0:13413ea9a877 4761 /* Disable TC and RXI interrupts */
ganlikun 0:13413ea9a877 4762 tmpisr |= FMPI2C_IT_TCI | FMPI2C_IT_RXI;
ganlikun 0:13413ea9a877 4763
ganlikun 0:13413ea9a877 4764 if((hfmpi2c->State & HAL_FMPI2C_STATE_LISTEN) != HAL_FMPI2C_STATE_LISTEN)
ganlikun 0:13413ea9a877 4765 {
ganlikun 0:13413ea9a877 4766 /* Disable NACK and STOP interrupts */
ganlikun 0:13413ea9a877 4767 tmpisr |= FMPI2C_IT_STOPI | FMPI2C_IT_NACKI | FMPI2C_IT_ERRI;
ganlikun 0:13413ea9a877 4768 }
ganlikun 0:13413ea9a877 4769 }
ganlikun 0:13413ea9a877 4770
ganlikun 0:13413ea9a877 4771 if((InterruptRequest & FMPI2C_XFER_LISTEN_IT) == FMPI2C_XFER_LISTEN_IT)
ganlikun 0:13413ea9a877 4772 {
ganlikun 0:13413ea9a877 4773 /* Disable ADDR, NACK and STOP interrupts */
ganlikun 0:13413ea9a877 4774 tmpisr |= FMPI2C_IT_ADDRI | FMPI2C_IT_STOPI | FMPI2C_IT_NACKI | FMPI2C_IT_ERRI;
ganlikun 0:13413ea9a877 4775 }
ganlikun 0:13413ea9a877 4776
ganlikun 0:13413ea9a877 4777 if((InterruptRequest & FMPI2C_XFER_ERROR_IT) == FMPI2C_XFER_ERROR_IT)
ganlikun 0:13413ea9a877 4778 {
ganlikun 0:13413ea9a877 4779 /* Enable ERR and NACK interrupts */
ganlikun 0:13413ea9a877 4780 tmpisr |= FMPI2C_IT_ERRI | FMPI2C_IT_NACKI;
ganlikun 0:13413ea9a877 4781 }
ganlikun 0:13413ea9a877 4782
ganlikun 0:13413ea9a877 4783 if((InterruptRequest & FMPI2C_XFER_CPLT_IT) == FMPI2C_XFER_CPLT_IT)
ganlikun 0:13413ea9a877 4784 {
ganlikun 0:13413ea9a877 4785 /* Enable STOP interrupts */
ganlikun 0:13413ea9a877 4786 tmpisr |= FMPI2C_IT_STOPI;
ganlikun 0:13413ea9a877 4787 }
ganlikun 0:13413ea9a877 4788
ganlikun 0:13413ea9a877 4789 if((InterruptRequest & FMPI2C_XFER_RELOAD_IT) == FMPI2C_XFER_RELOAD_IT)
ganlikun 0:13413ea9a877 4790 {
ganlikun 0:13413ea9a877 4791 /* Enable TC interrupts */
ganlikun 0:13413ea9a877 4792 tmpisr |= FMPI2C_IT_TCI;
ganlikun 0:13413ea9a877 4793 }
ganlikun 0:13413ea9a877 4794
ganlikun 0:13413ea9a877 4795 /* Disable interrupts only at the end */
ganlikun 0:13413ea9a877 4796 /* to avoid a breaking situation like at "t" time */
ganlikun 0:13413ea9a877 4797 /* all disable interrupts request are not done */
ganlikun 0:13413ea9a877 4798 __HAL_FMPI2C_DISABLE_IT(hfmpi2c, tmpisr);
ganlikun 0:13413ea9a877 4799
ganlikun 0:13413ea9a877 4800 return HAL_OK;
ganlikun 0:13413ea9a877 4801 }
ganlikun 0:13413ea9a877 4802
ganlikun 0:13413ea9a877 4803 /**
ganlikun 0:13413ea9a877 4804 * @}
ganlikun 0:13413ea9a877 4805 */
ganlikun 0:13413ea9a877 4806 #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
ganlikun 0:13413ea9a877 4807 #endif /* HAL_FMPI2C_MODULE_ENABLED */
ganlikun 0:13413ea9a877 4808 /**
ganlikun 0:13413ea9a877 4809 * @}
ganlikun 0:13413ea9a877 4810 */
ganlikun 0:13413ea9a877 4811
ganlikun 0:13413ea9a877 4812 /**
ganlikun 0:13413ea9a877 4813 * @}
ganlikun 0:13413ea9a877 4814 */
ganlikun 0:13413ea9a877 4815
ganlikun 0:13413ea9a877 4816 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:13413ea9a877 4817