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