inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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