66 ******************************************************************************
77 * @attention
88 *
9- * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
9+ * <h2><center>© Copyright (c) 2016 STMicroelectronics.
10+ * All rights reserved.</center></h2>
1011 *
11- * Redistribution and use in source and binary forms, with or without modification,
12- * are permitted provided that the following conditions are met:
13- * 1. Redistributions of source code must retain the above copyright notice,
14- * this list of conditions and the following disclaimer.
15- * 2. Redistributions in binary form must reproduce the above copyright notice,
16- * this list of conditions and the following disclaimer in the documentation
17- * and/or other materials provided with the distribution.
18- * 3. Neither the name of STMicroelectronics nor the names of its contributors
19- * may be used to endorse or promote products derived from this software
20- * without specific prior written permission.
21- *
22- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12+ * This software component is licensed by ST under BSD 3-Clause license,
13+ * the "License"; You may not use this file except in compliance with the
14+ * License. You may obtain a copy of the License at:
15+ * opensource.org/licenses/BSD-3-Clause
3216 *
3317 ******************************************************************************
3418 */
@@ -197,7 +181,11 @@ typedef struct
197181/**
198182 * @brief ADC handle Structure definition
199183 */
184+ #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1 )
185+ typedef struct __ADC_HandleTypeDef
186+ #else
200187typedef struct
188+ #endif
201189{
202190 ADC_TypeDef * Instance ; /*!< Register base address */
203191
@@ -212,7 +200,39 @@ typedef struct
212200 __IO uint32_t State ; /*!< ADC communication state */
213201
214202 __IO uint32_t ErrorCode ; /*!< ADC Error code */
203+ #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1 )
204+ void (* ConvCpltCallback )(struct __ADC_HandleTypeDef * hadc ); /*!< ADC conversion complete callback */
205+ void (* ConvHalfCpltCallback )(struct __ADC_HandleTypeDef * hadc ); /*!< ADC conversion DMA half-transfer callback */
206+ void (* LevelOutOfWindowCallback )(struct __ADC_HandleTypeDef * hadc ); /*!< ADC analog watchdog 1 callback */
207+ void (* ErrorCallback )(struct __ADC_HandleTypeDef * hadc ); /*!< ADC error callback */
208+ void (* InjectedConvCpltCallback )(struct __ADC_HandleTypeDef * hadc ); /*!< ADC group injected conversion complete callback */
209+ void (* MspInitCallback )(struct __ADC_HandleTypeDef * hadc ); /*!< ADC Msp Init callback */
210+ void (* MspDeInitCallback )(struct __ADC_HandleTypeDef * hadc ); /*!< ADC Msp DeInit callback */
211+ #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
215212}ADC_HandleTypeDef ;
213+
214+ #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1 )
215+ /**
216+ * @brief HAL ADC Callback ID enumeration definition
217+ */
218+ typedef enum
219+ {
220+ HAL_ADC_CONVERSION_COMPLETE_CB_ID = 0x00U , /*!< ADC conversion complete callback ID */
221+ HAL_ADC_CONVERSION_HALF_CB_ID = 0x01U , /*!< ADC conversion DMA half-transfer callback ID */
222+ HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID = 0x02U , /*!< ADC analog watchdog 1 callback ID */
223+ HAL_ADC_ERROR_CB_ID = 0x03U , /*!< ADC error callback ID */
224+ HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U , /*!< ADC group injected conversion complete callback ID */
225+ HAL_ADC_MSPINIT_CB_ID = 0x05U , /*!< ADC Msp Init callback ID */
226+ HAL_ADC_MSPDEINIT_CB_ID = 0x06U /*!< ADC Msp DeInit callback ID */
227+ } HAL_ADC_CallbackIDTypeDef ;
228+
229+ /**
230+ * @brief HAL ADC Callback pointer definition
231+ */
232+ typedef void (* pADC_CallbackTypeDef )(ADC_HandleTypeDef * hadc ); /*!< pointer to a ADC callback function */
233+
234+ #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
235+
216236/**
217237 * @}
218238 */
@@ -230,6 +250,9 @@ typedef struct
230250 enable/disable, erroneous state */
231251#define HAL_ADC_ERROR_OVR 0x02U /*!< Overrun error */
232252#define HAL_ADC_ERROR_DMA 0x04U /*!< DMA transfer error */
253+ #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1 )
254+ #define HAL_ADC_ERROR_INVALID_CALLBACK (0x10U) /*!< Invalid Callback error */
255+ #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
233256/**
234257 * @}
235258 */
@@ -450,7 +473,17 @@ typedef struct
450473 * @param __HANDLE__ ADC handle
451474 * @retval None
452475 */
453- #define __HAL_ADC_RESET_HANDLE_STATE (__HANDLE__ ) ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
476+ #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1 )
477+ #define __HAL_ADC_RESET_HANDLE_STATE (__HANDLE__ ) \
478+ do{ \
479+ (__HANDLE__)->State = HAL_ADC_STATE_RESET; \
480+ (__HANDLE__)->MspInitCallback = NULL; \
481+ (__HANDLE__)->MspDeInitCallback = NULL; \
482+ } while(0)
483+ #else
484+ #define __HAL_ADC_RESET_HANDLE_STATE (__HANDLE__ ) \
485+ ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
486+ #endif
454487
455488/**
456489 * @brief Enable the ADC peripheral.
@@ -525,6 +558,12 @@ HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
525558HAL_StatusTypeDef HAL_ADC_DeInit (ADC_HandleTypeDef * hadc );
526559void HAL_ADC_MspInit (ADC_HandleTypeDef * hadc );
527560void HAL_ADC_MspDeInit (ADC_HandleTypeDef * hadc );
561+
562+ #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1 )
563+ /* Callbacks Register/UnRegister functions ***********************************/
564+ HAL_StatusTypeDef HAL_ADC_RegisterCallback (ADC_HandleTypeDef * hadc , HAL_ADC_CallbackIDTypeDef CallbackID , pADC_CallbackTypeDef pCallback );
565+ HAL_StatusTypeDef HAL_ADC_UnRegisterCallback (ADC_HandleTypeDef * hadc , HAL_ADC_CallbackIDTypeDef CallbackID );
566+ #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
528567/**
529568 * @}
530569 */
0 commit comments