Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 28 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32l1xx_hal_adc.c |
3 | * @file stm32l1xx_hal_adc.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @version V1.2.0 |
- | |
6 | * @date 01-July-2016 |
- | |
7 | * @brief This file provides firmware functions to manage the following |
5 | * @brief This file provides firmware functions to manage the following |
8 | * functionalities of the Analog to Digital Convertor (ADC) |
6 | * functionalities of the Analog to Digital Convertor (ADC) |
9 | * peripheral: |
7 | * peripheral: |
10 | * + Initialization and de-initialization functions |
8 | * + Initialization and de-initialization functions |
11 | * ++ Initialization and Configuration of ADC |
9 | * ++ Initialization and Configuration of ADC |
Line 249... | Line 247... | ||
249 | using function HAL_DMA_Init(). |
247 | using function HAL_DMA_Init(). |
250 | (++) Disable the NVIC for DMA |
248 | (++) Disable the NVIC for DMA |
251 | using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn) |
249 | using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn) |
252 | 250 | ||
253 | [..] |
251 | [..] |
- | 252 | |
|
- | 253 | *** Callback registration *** |
|
- | 254 | ============================================= |
|
- | 255 | [..] |
|
- | 256 | ||
- | 257 | The compilation flag USE_HAL_ADC_REGISTER_CALLBACKS, when set to 1, |
|
- | 258 | allows the user to configure dynamically the driver callbacks. |
|
- | 259 | Use Functions @ref HAL_ADC_RegisterCallback() |
|
- | 260 | to register an interrupt callback. |
|
- | 261 | [..] |
|
- | 262 | ||
- | 263 | Function @ref HAL_ADC_RegisterCallback() allows to register following callbacks: |
|
- | 264 | (+) ConvCpltCallback : ADC conversion complete callback |
|
- | 265 | (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback |
|
- | 266 | (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback |
|
- | 267 | (+) ErrorCallback : ADC error callback |
|
- | 268 | (+) InjectedConvCpltCallback : ADC group injected conversion complete callback |
|
- | 269 | (+) MspInitCallback : ADC Msp Init callback |
|
- | 270 | (+) MspDeInitCallback : ADC Msp DeInit callback |
|
- | 271 | This function takes as parameters the HAL peripheral handle, the Callback ID |
|
- | 272 | and a pointer to the user callback function. |
|
- | 273 | [..] |
|
- | 274 | ||
- | 275 | Use function @ref HAL_ADC_UnRegisterCallback to reset a callback to the default |
|
- | 276 | weak function. |
|
- | 277 | [..] |
|
- | 278 | ||
- | 279 | @ref HAL_ADC_UnRegisterCallback takes as parameters the HAL peripheral handle, |
|
- | 280 | and the Callback ID. |
|
- | 281 | This function allows to reset following callbacks: |
|
- | 282 | (+) ConvCpltCallback : ADC conversion complete callback |
|
- | 283 | (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback |
|
- | 284 | (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback |
|
- | 285 | (+) ErrorCallback : ADC error callback |
|
- | 286 | (+) InjectedConvCpltCallback : ADC group injected conversion complete callback |
|
- | 287 | (+) MspInitCallback : ADC Msp Init callback |
|
- | 288 | (+) MspDeInitCallback : ADC Msp DeInit callback |
|
- | 289 | [..] |
|
- | 290 | ||
- | 291 | By default, after the @ref HAL_ADC_Init() and when the state is @ref HAL_ADC_STATE_RESET |
|
- | 292 | all callbacks are set to the corresponding weak functions: |
|
- | 293 | examples @ref HAL_ADC_ConvCpltCallback(), @ref HAL_ADC_ErrorCallback(). |
|
- | 294 | Exception done for MspInit and MspDeInit functions that are |
|
- | 295 | reset to the legacy weak functions in the @ref HAL_ADC_Init()/ @ref HAL_ADC_DeInit() only when |
|
- | 296 | these callbacks are null (not registered beforehand). |
|
- | 297 | [..] |
|
- | 298 | ||
- | 299 | If MspInit or MspDeInit are not null, the @ref HAL_ADC_Init()/ @ref HAL_ADC_DeInit() |
|
- | 300 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state. |
|
- | 301 | [..] |
|
- | 302 | ||
- | 303 | Callbacks can be registered/unregistered in @ref HAL_ADC_STATE_READY state only. |
|
- | 304 | Exception done MspInit/MspDeInit functions that can be registered/unregistered |
|
- | 305 | in @ref HAL_ADC_STATE_READY or @ref HAL_ADC_STATE_RESET state, |
|
- | 306 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
|
- | 307 | [..] |
|
- | 308 | ||
- | 309 | Then, the user first registers the MspInit/MspDeInit user callbacks |
|
- | 310 | using @ref HAL_ADC_RegisterCallback() before calling @ref HAL_ADC_DeInit() |
|
- | 311 | or @ref HAL_ADC_Init() function. |
|
- | 312 | [..] |
|
- | 313 | ||
- | 314 | When the compilation flag USE_HAL_ADC_REGISTER_CALLBACKS is set to 0 or |
|
- | 315 | not defined, the callback registration feature is not available and all callbacks |
|
- | 316 | are set to the corresponding weak functions. |
|
254 | |
317 | |
255 | @endverbatim |
318 | @endverbatim |
256 | ****************************************************************************** |
319 | ****************************************************************************** |
257 | * @attention |
320 | * @attention |
258 | * |
321 | * |
259 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
322 | * <h2><center>© Copyright (c) 2017 STMicroelectronics. |
260 | * |
- | |
261 | * Redistribution and use in source and binary forms, with or without modification, |
- | |
262 | * are permitted provided that the following conditions are met: |
- | |
263 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
264 | * this list of conditions and the following disclaimer. |
- | |
265 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
266 | * this list of conditions and the following disclaimer in the documentation |
- | |
267 | * and/or other materials provided with the distribution. |
- | |
268 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
269 | * may be used to endorse or promote products derived from this software |
- | |
270 | * without specific prior written permission. |
323 | * All rights reserved.</center></h2> |
271 | * |
324 | * |
272 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
325 | * This software component is licensed by ST under BSD 3-Clause license, |
273 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
274 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
275 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
276 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
277 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
326 | * the "License"; You may not use this file except in compliance with the |
278 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
327 | * License. You may obtain a copy of the License at: |
279 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
280 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
281 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
328 | * opensource.org/licenses/BSD-3-Clause |
282 | * |
329 | * |
283 | ****************************************************************************** |
330 | ****************************************************************************** |
284 | */ |
331 | */ |
285 | 332 | ||
286 | /* Includes ------------------------------------------------------------------*/ |
333 | /* Includes ------------------------------------------------------------------*/ |
Line 307... | Line 354... | ||
307 | /* Values defined to be higher than worst cases: low clocks freq, */ |
354 | /* Values defined to be higher than worst cases: low clocks freq, */ |
308 | /* maximum prescaler. */ |
355 | /* maximum prescaler. */ |
309 | /* Ex of profile low frequency : Clock source at 0.1 MHz, ADC clock */ |
356 | /* Ex of profile low frequency : Clock source at 0.1 MHz, ADC clock */ |
310 | /* prescaler 4, sampling time 7.5 ADC clock cycles, resolution 12 bits. */ |
357 | /* prescaler 4, sampling time 7.5 ADC clock cycles, resolution 12 bits. */ |
311 | /* Unit: ms */ |
358 | /* Unit: ms */ |
312 | #define ADC_ENABLE_TIMEOUT ((uint32_t) 2) |
359 | #define ADC_ENABLE_TIMEOUT (2U) |
313 | #define ADC_DISABLE_TIMEOUT ((uint32_t) 2) |
360 | #define ADC_DISABLE_TIMEOUT (2U) |
314 | 361 | ||
315 | /* Delay for ADC stabilization time. */ |
362 | /* Delay for ADC stabilization time. */ |
316 | /* Maximum delay is 1us (refer to device datasheet, parameter tSTAB). */ |
363 | /* Maximum delay is 1us (refer to device datasheet, parameter tSTAB). */ |
317 | /* Unit: us */ |
364 | /* Unit: us */ |
318 | #define ADC_STAB_DELAY_US ((uint32_t) 3) |
365 | #define ADC_STAB_DELAY_US (3U) |
319 | 366 | ||
320 | /* Delay for temperature sensor stabilization time. */ |
367 | /* Delay for temperature sensor stabilization time. */ |
321 | /* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */ |
368 | /* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */ |
322 | /* Unit: us */ |
369 | /* Unit: us */ |
323 | #define ADC_TEMPSENSOR_DELAY_US ((uint32_t) 10) |
370 | #define ADC_TEMPSENSOR_DELAY_US (10U) |
324 | 371 | ||
325 | /** |
372 | /** |
326 | * @} |
373 | * @} |
327 | */ |
374 | */ |
328 | 375 | ||
Line 377... | Line 424... | ||
377 | * For parameters constraints, see comments of structure |
424 | * For parameters constraints, see comments of structure |
378 | * "ADC_InitTypeDef". |
425 | * "ADC_InitTypeDef". |
379 | * @note This function configures the ADC within 2 scopes: scope of entire |
426 | * @note This function configures the ADC within 2 scopes: scope of entire |
380 | * ADC and scope of regular group. For parameters details, see comments |
427 | * ADC and scope of regular group. For parameters details, see comments |
381 | * of structure "ADC_InitTypeDef". |
428 | * of structure "ADC_InitTypeDef". |
382 | * @param hadc: ADC handle |
429 | * @param hadc ADC handle |
383 | * @retval HAL status |
430 | * @retval HAL status |
384 | */ |
431 | */ |
385 | HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc) |
432 | HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc) |
386 | { |
433 | { |
387 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
434 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 439... | Line 486... | ||
439 | /* Allocate lock resource and initialize it */ |
486 | /* Allocate lock resource and initialize it */ |
440 | hadc->Lock = HAL_UNLOCKED; |
487 | hadc->Lock = HAL_UNLOCKED; |
441 | 488 | ||
442 | /* Enable SYSCFG clock to control the routing Interface (RI) */ |
489 | /* Enable SYSCFG clock to control the routing Interface (RI) */ |
443 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
490 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
- | 491 | ||
- | 492 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
- | 493 | /* Init the ADC Callback settings */ |
|
- | 494 | hadc->ConvCpltCallback = HAL_ADC_ConvCpltCallback; /* Legacy weak callback */ |
|
- | 495 | hadc->ConvHalfCpltCallback = HAL_ADC_ConvHalfCpltCallback; /* Legacy weak callback */ |
|
- | 496 | hadc->LevelOutOfWindowCallback = HAL_ADC_LevelOutOfWindowCallback; /* Legacy weak callback */ |
|
- | 497 | hadc->ErrorCallback = HAL_ADC_ErrorCallback; /* Legacy weak callback */ |
|
- | 498 | hadc->InjectedConvCpltCallback = HAL_ADCEx_InjectedConvCpltCallback; /* Legacy weak callback */ |
|
444 | 499 | ||
- | 500 | if (hadc->MspInitCallback == NULL) |
|
- | 501 | { |
|
- | 502 | hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ |
|
- | 503 | } |
|
- | 504 | ||
- | 505 | /* Init the low level hardware */ |
|
- | 506 | hadc->MspInitCallback(hadc); |
|
- | 507 | #else |
|
445 | /* Init the low level hardware */ |
508 | /* Init the low level hardware */ |
446 | HAL_ADC_MspInit(hadc); |
509 | HAL_ADC_MspInit(hadc); |
- | 510 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
447 | } |
511 | } |
448 | 512 | ||
449 | /* Configuration of ADC parameters if previous preliminary actions are */ |
513 | /* Configuration of ADC parameters if previous preliminary actions are */ |
450 | /* correctly completed. */ |
514 | /* correctly completed. */ |
451 | if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL)) |
515 | if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL)) |
Line 467... | Line 531... | ||
467 | /* - external trigger polarity */ |
531 | /* - external trigger polarity */ |
468 | /* - End of conversion selection */ |
532 | /* - End of conversion selection */ |
469 | /* - DMA continuous request */ |
533 | /* - DMA continuous request */ |
470 | /* - Channels bank (Banks availability depends on devices categories) */ |
534 | /* - Channels bank (Banks availability depends on devices categories) */ |
471 | /* - continuous conversion mode */ |
535 | /* - continuous conversion mode */ |
472 | tmp_cr2 |= (hadc->Init.DataAlign | |
536 | tmp_cr2 |= (hadc->Init.DataAlign | |
473 | hadc->Init.EOCSelection | |
537 | hadc->Init.EOCSelection | |
474 | ADC_CR2_DMACONTREQ(hadc->Init.DMAContinuousRequests) | |
538 | ADC_CR2_DMACONTREQ((uint32_t)hadc->Init.DMAContinuousRequests) | |
475 | hadc->Init.ChannelsBank | |
539 | hadc->Init.ChannelsBank | |
476 | ADC_CR2_CONTINUOUS(hadc->Init.ContinuousConvMode) ); |
540 | ADC_CR2_CONTINUOUS((uint32_t)hadc->Init.ContinuousConvMode) ); |
477 | 541 | ||
478 | /* Enable external trigger if trigger selection is different of software */ |
542 | /* Enable external trigger if trigger selection is different of software */ |
479 | /* start. */ |
543 | /* start. */ |
480 | /* Note: This configuration keeps the hardware feature of parameter */ |
544 | /* Note: This configuration keeps the hardware feature of parameter */ |
481 | /* ExternalTrigConvEdge "trigger edge none" equivalent to */ |
545 | /* ExternalTrigConvEdge "trigger edge none" equivalent to */ |
Line 609... | Line 673... | ||
609 | * @brief Deinitialize the ADC peripheral registers to its default reset values. |
673 | * @brief Deinitialize the ADC peripheral registers to its default reset values. |
610 | * @note To not impact other ADCs, reset of common ADC registers have been |
674 | * @note To not impact other ADCs, reset of common ADC registers have been |
611 | * left commented below. |
675 | * left commented below. |
612 | * If needed, the example code can be copied and uncommented into |
676 | * If needed, the example code can be copied and uncommented into |
613 | * function HAL_ADC_MspDeInit(). |
677 | * function HAL_ADC_MspDeInit(). |
614 | * @param hadc: ADC handle |
678 | * @param hadc ADC handle |
615 | * @retval HAL status |
679 | * @retval HAL status |
616 | */ |
680 | */ |
617 | HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc) |
681 | HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef* hadc) |
618 | { |
682 | { |
619 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
683 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 728... | Line 792... | ||
728 | /* function "void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)": */ |
792 | /* function "void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)": */ |
729 | /* */ |
793 | /* */ |
730 | /* __HAL_RCC_ADC1_FORCE_RESET() */ |
794 | /* __HAL_RCC_ADC1_FORCE_RESET() */ |
731 | /* __HAL_RCC_ADC1_RELEASE_RESET() */ |
795 | /* __HAL_RCC_ADC1_RELEASE_RESET() */ |
732 | 796 | ||
- | 797 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
- | 798 | if (hadc->MspDeInitCallback == NULL) |
|
- | 799 | { |
|
- | 800 | hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ |
|
- | 801 | } |
|
- | 802 | ||
- | 803 | /* DeInit the low level hardware */ |
|
- | 804 | hadc->MspDeInitCallback(hadc); |
|
- | 805 | #else |
|
733 | /* DeInit the low level hardware */ |
806 | /* DeInit the low level hardware */ |
734 | HAL_ADC_MspDeInit(hadc); |
807 | HAL_ADC_MspDeInit(hadc); |
- | 808 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
735 | 809 | ||
736 | /* Set ADC error code to none */ |
810 | /* Set ADC error code to none */ |
737 | ADC_CLEAR_ERRORCODE(hadc); |
811 | ADC_CLEAR_ERRORCODE(hadc); |
738 | 812 | ||
739 | /* Set ADC state */ |
813 | /* Set ADC state */ |
Line 748... | Line 822... | ||
748 | return tmp_hal_status; |
822 | return tmp_hal_status; |
749 | } |
823 | } |
750 | 824 | ||
751 | /** |
825 | /** |
752 | * @brief Initializes the ADC MSP. |
826 | * @brief Initializes the ADC MSP. |
753 | * @param hadc: ADC handle |
827 | * @param hadc ADC handle |
754 | * @retval None |
828 | * @retval None |
755 | */ |
829 | */ |
756 | __weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) |
830 | __weak void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) |
757 | { |
831 | { |
758 | /* Prevent unused argument(s) compilation warning */ |
832 | /* Prevent unused argument(s) compilation warning */ |
Line 763... | Line 837... | ||
763 | */ |
837 | */ |
764 | } |
838 | } |
765 | 839 | ||
766 | /** |
840 | /** |
767 | * @brief DeInitializes the ADC MSP. |
841 | * @brief DeInitializes the ADC MSP. |
768 | * @param hadc: ADC handle |
842 | * @param hadc ADC handle |
769 | * @retval None |
843 | * @retval None |
770 | */ |
844 | */ |
771 | __weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) |
845 | __weak void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) |
772 | { |
846 | { |
773 | /* Prevent unused argument(s) compilation warning */ |
847 | /* Prevent unused argument(s) compilation warning */ |
Line 776... | Line 850... | ||
776 | /* NOTE : This function should not be modified. When the callback is needed, |
850 | /* NOTE : This function should not be modified. When the callback is needed, |
777 | function HAL_ADC_MspDeInit must be implemented in the user file. |
851 | function HAL_ADC_MspDeInit must be implemented in the user file. |
778 | */ |
852 | */ |
779 | } |
853 | } |
780 | 854 | ||
- | 855 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
- | 856 | /** |
|
- | 857 | * @brief Register a User ADC Callback |
|
- | 858 | * To be used instead of the weak predefined callback |
|
- | 859 | * @param hadc Pointer to a ADC_HandleTypeDef structure that contains |
|
- | 860 | * the configuration information for the specified ADC. |
|
- | 861 | * @param CallbackID ID of the callback to be registered |
|
- | 862 | * This parameter can be one of the following values: |
|
- | 863 | * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID |
|
- | 864 | * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion complete callback ID |
|
- | 865 | * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID |
|
- | 866 | * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID |
|
- | 867 | * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID |
|
- | 868 | * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID |
|
- | 869 | * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID |
|
- | 870 | * @arg @ref HAL_ADC_MSPINIT_CB_ID MspInit callback ID |
|
- | 871 | * @arg @ref HAL_ADC_MSPDEINIT_CB_ID MspDeInit callback ID |
|
- | 872 | * @param pCallback pointer to the Callback function |
|
- | 873 | * @retval HAL status |
|
- | 874 | */ |
|
- | 875 | HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback) |
|
- | 876 | { |
|
- | 877 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 878 | ||
- | 879 | if (pCallback == NULL) |
|
- | 880 | { |
|
- | 881 | /* Update the error code */ |
|
- | 882 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
- | 883 | ||
- | 884 | return HAL_ERROR; |
|
- | 885 | } |
|
- | 886 | ||
- | 887 | if ((hadc->State & HAL_ADC_STATE_READY) != 0) |
|
- | 888 | { |
|
- | 889 | switch (CallbackID) |
|
- | 890 | { |
|
- | 891 | case HAL_ADC_CONVERSION_COMPLETE_CB_ID : |
|
- | 892 | hadc->ConvCpltCallback = pCallback; |
|
- | 893 | break; |
|
- | 894 | ||
- | 895 | case HAL_ADC_CONVERSION_HALF_CB_ID : |
|
- | 896 | hadc->ConvHalfCpltCallback = pCallback; |
|
- | 897 | break; |
|
- | 898 | ||
- | 899 | case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID : |
|
- | 900 | hadc->LevelOutOfWindowCallback = pCallback; |
|
- | 901 | break; |
|
- | 902 | ||
- | 903 | case HAL_ADC_ERROR_CB_ID : |
|
- | 904 | hadc->ErrorCallback = pCallback; |
|
- | 905 | break; |
|
- | 906 | ||
- | 907 | case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID : |
|
- | 908 | hadc->InjectedConvCpltCallback = pCallback; |
|
- | 909 | break; |
|
- | 910 | ||
- | 911 | case HAL_ADC_MSPINIT_CB_ID : |
|
- | 912 | hadc->MspInitCallback = pCallback; |
|
- | 913 | break; |
|
- | 914 | ||
- | 915 | case HAL_ADC_MSPDEINIT_CB_ID : |
|
- | 916 | hadc->MspDeInitCallback = pCallback; |
|
- | 917 | break; |
|
- | 918 | ||
- | 919 | default : |
|
- | 920 | /* Update the error code */ |
|
- | 921 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
- | 922 | ||
- | 923 | /* Return error status */ |
|
- | 924 | status = HAL_ERROR; |
|
- | 925 | break; |
|
- | 926 | } |
|
- | 927 | } |
|
- | 928 | else if (HAL_ADC_STATE_RESET == hadc->State) |
|
- | 929 | { |
|
- | 930 | switch (CallbackID) |
|
- | 931 | { |
|
- | 932 | case HAL_ADC_MSPINIT_CB_ID : |
|
- | 933 | hadc->MspInitCallback = pCallback; |
|
- | 934 | break; |
|
- | 935 | ||
- | 936 | case HAL_ADC_MSPDEINIT_CB_ID : |
|
- | 937 | hadc->MspDeInitCallback = pCallback; |
|
- | 938 | break; |
|
- | 939 | ||
- | 940 | default : |
|
- | 941 | /* Update the error code */ |
|
- | 942 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
- | 943 | ||
- | 944 | /* Return error status */ |
|
- | 945 | status = HAL_ERROR; |
|
- | 946 | break; |
|
- | 947 | } |
|
- | 948 | } |
|
- | 949 | else |
|
- | 950 | { |
|
- | 951 | /* Update the error code */ |
|
- | 952 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
- | 953 | ||
- | 954 | /* Return error status */ |
|
- | 955 | status = HAL_ERROR; |
|
- | 956 | } |
|
- | 957 | ||
- | 958 | return status; |
|
- | 959 | } |
|
- | 960 | ||
- | 961 | /** |
|
- | 962 | * @brief Unregister a ADC Callback |
|
- | 963 | * ADC callback is redirected to the weak predefined callback |
|
- | 964 | * @param hadc Pointer to a ADC_HandleTypeDef structure that contains |
|
- | 965 | * the configuration information for the specified ADC. |
|
- | 966 | * @param CallbackID ID of the callback to be unregistered |
|
- | 967 | * This parameter can be one of the following values: |
|
- | 968 | * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID |
|
- | 969 | * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion complete callback ID |
|
- | 970 | * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID |
|
- | 971 | * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID |
|
- | 972 | * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID |
|
- | 973 | * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID |
|
- | 974 | * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID |
|
- | 975 | * @arg @ref HAL_ADC_MSPINIT_CB_ID MspInit callback ID |
|
- | 976 | * @arg @ref HAL_ADC_MSPDEINIT_CB_ID MspDeInit callback ID |
|
- | 977 | * @retval HAL status |
|
- | 978 | */ |
|
- | 979 | HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID) |
|
- | 980 | { |
|
- | 981 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 982 | ||
- | 983 | if ((hadc->State & HAL_ADC_STATE_READY) != 0) |
|
- | 984 | { |
|
- | 985 | switch (CallbackID) |
|
- | 986 | { |
|
- | 987 | case HAL_ADC_CONVERSION_COMPLETE_CB_ID : |
|
- | 988 | hadc->ConvCpltCallback = HAL_ADC_ConvCpltCallback; |
|
- | 989 | break; |
|
- | 990 | ||
- | 991 | case HAL_ADC_CONVERSION_HALF_CB_ID : |
|
- | 992 | hadc->ConvHalfCpltCallback = HAL_ADC_ConvHalfCpltCallback; |
|
- | 993 | break; |
|
- | 994 | ||
- | 995 | case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID : |
|
- | 996 | hadc->LevelOutOfWindowCallback = HAL_ADC_LevelOutOfWindowCallback; |
|
- | 997 | break; |
|
- | 998 | ||
- | 999 | case HAL_ADC_ERROR_CB_ID : |
|
- | 1000 | hadc->ErrorCallback = HAL_ADC_ErrorCallback; |
|
- | 1001 | break; |
|
- | 1002 | ||
- | 1003 | case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID : |
|
- | 1004 | hadc->InjectedConvCpltCallback = HAL_ADCEx_InjectedConvCpltCallback; |
|
- | 1005 | break; |
|
- | 1006 | ||
- | 1007 | case HAL_ADC_MSPINIT_CB_ID : |
|
- | 1008 | hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ |
|
- | 1009 | break; |
|
- | 1010 | ||
- | 1011 | case HAL_ADC_MSPDEINIT_CB_ID : |
|
- | 1012 | hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ |
|
- | 1013 | break; |
|
- | 1014 | ||
- | 1015 | default : |
|
- | 1016 | /* Update the error code */ |
|
- | 1017 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
- | 1018 | ||
- | 1019 | /* Return error status */ |
|
- | 1020 | status = HAL_ERROR; |
|
- | 1021 | break; |
|
- | 1022 | } |
|
- | 1023 | } |
|
- | 1024 | else if (HAL_ADC_STATE_RESET == hadc->State) |
|
- | 1025 | { |
|
- | 1026 | switch (CallbackID) |
|
- | 1027 | { |
|
- | 1028 | case HAL_ADC_MSPINIT_CB_ID : |
|
- | 1029 | hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ |
|
- | 1030 | break; |
|
- | 1031 | ||
- | 1032 | case HAL_ADC_MSPDEINIT_CB_ID : |
|
- | 1033 | hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ |
|
- | 1034 | break; |
|
- | 1035 | ||
- | 1036 | default : |
|
- | 1037 | /* Update the error code */ |
|
- | 1038 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
- | 1039 | ||
- | 1040 | /* Return error status */ |
|
- | 1041 | status = HAL_ERROR; |
|
- | 1042 | break; |
|
- | 1043 | } |
|
- | 1044 | } |
|
- | 1045 | else |
|
- | 1046 | { |
|
- | 1047 | /* Update the error code */ |
|
- | 1048 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
- | 1049 | ||
- | 1050 | /* Return error status */ |
|
- | 1051 | status = HAL_ERROR; |
|
- | 1052 | } |
|
- | 1053 | ||
- | 1054 | return status; |
|
- | 1055 | } |
|
- | 1056 | ||
- | 1057 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
- | 1058 | ||
781 | /** |
1059 | /** |
782 | * @} |
1060 | * @} |
783 | */ |
1061 | */ |
784 | 1062 | ||
785 | /** @defgroup ADC_Exported_Functions_Group2 ADC Input and Output operation functions |
1063 | /** @defgroup ADC_Exported_Functions_Group2 ADC Input and Output operation functions |
Line 805... | Line 1083... | ||
805 | */ |
1083 | */ |
806 | 1084 | ||
807 | /** |
1085 | /** |
808 | * @brief Enables ADC, starts conversion of regular group. |
1086 | * @brief Enables ADC, starts conversion of regular group. |
809 | * Interruptions enabled in this function: None. |
1087 | * Interruptions enabled in this function: None. |
810 | * @param hadc: ADC handle |
1088 | * @param hadc ADC handle |
811 | * @retval HAL status |
1089 | * @retval HAL status |
812 | */ |
1090 | */ |
813 | HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc) |
1091 | HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc) |
814 | { |
1092 | { |
815 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
1093 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 880... | Line 1158... | ||
880 | * @brief Stop ADC conversion of regular group (and injected channels in |
1158 | * @brief Stop ADC conversion of regular group (and injected channels in |
881 | * case of auto_injection mode), disable ADC peripheral. |
1159 | * case of auto_injection mode), disable ADC peripheral. |
882 | * @note: ADC peripheral disable is forcing stop of potential |
1160 | * @note: ADC peripheral disable is forcing stop of potential |
883 | * conversion on injected group. If injected group is under use, it |
1161 | * conversion on injected group. If injected group is under use, it |
884 | * should be preliminarily stopped using HAL_ADCEx_InjectedStop function. |
1162 | * should be preliminarily stopped using HAL_ADCEx_InjectedStop function. |
885 | * @param hadc: ADC handle |
1163 | * @param hadc ADC handle |
886 | * @retval HAL status. |
1164 | * @retval HAL status. |
887 | */ |
1165 | */ |
888 | HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc) |
1166 | HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc) |
889 | { |
1167 | { |
890 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
1168 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 927... | Line 1205... | ||
927 | * parameter "EOCSelection" set to ADC_EOC_SINGLE_CONV). |
1205 | * parameter "EOCSelection" set to ADC_EOC_SINGLE_CONV). |
928 | * In this case, DMA resets the flag EOC and polling cannot be |
1206 | * In this case, DMA resets the flag EOC and polling cannot be |
929 | * performed on each conversion. Nevertheless, polling can still |
1207 | * performed on each conversion. Nevertheless, polling can still |
930 | * be performed on the complete sequence (ADC init |
1208 | * be performed on the complete sequence (ADC init |
931 | * parameter "EOCSelection" set to ADC_EOC_SEQ_CONV). |
1209 | * parameter "EOCSelection" set to ADC_EOC_SEQ_CONV). |
932 | * @param hadc: ADC handle |
1210 | * @param hadc ADC handle |
933 | * @param Timeout: Timeout value in millisecond. |
1211 | * @param Timeout Timeout value in millisecond. |
934 | * @retval HAL status |
1212 | * @retval HAL status |
935 | */ |
1213 | */ |
936 | HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout) |
1214 | HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout) |
937 | { |
1215 | { |
938 | uint32_t tickstart = 0; |
1216 | uint32_t tickstart = 0; |
Line 1016... | Line 1294... | ||
1016 | return HAL_OK; |
1294 | return HAL_OK; |
1017 | } |
1295 | } |
1018 | 1296 | ||
1019 | /** |
1297 | /** |
1020 | * @brief Poll for conversion event. |
1298 | * @brief Poll for conversion event. |
1021 | * @param hadc: ADC handle |
1299 | * @param hadc ADC handle |
1022 | * @param EventType: the ADC event type. |
1300 | * @param EventType the ADC event type. |
1023 | * This parameter can be one of the following values: |
1301 | * This parameter can be one of the following values: |
1024 | * @arg ADC_AWD_EVENT: ADC Analog watchdog event. |
1302 | * @arg ADC_AWD_EVENT: ADC Analog watchdog event. |
1025 | * @arg ADC_OVR_EVENT: ADC Overrun event. |
1303 | * @arg ADC_OVR_EVENT: ADC Overrun event. |
1026 | * @param Timeout: Timeout value in millisecond. |
1304 | * @param Timeout Timeout value in millisecond. |
1027 | * @retval HAL status |
1305 | * @retval HAL status |
1028 | */ |
1306 | */ |
1029 | HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout) |
1307 | HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout) |
1030 | { |
1308 | { |
1031 | uint32_t tickstart = 0; |
1309 | uint32_t tickstart = 0; |
Line 1091... | Line 1369... | ||
1091 | * @brief Enables ADC, starts conversion of regular group with interruption. |
1369 | * @brief Enables ADC, starts conversion of regular group with interruption. |
1092 | * Interruptions enabled in this function: |
1370 | * Interruptions enabled in this function: |
1093 | * - EOC (end of conversion of regular group) |
1371 | * - EOC (end of conversion of regular group) |
1094 | * - overrun |
1372 | * - overrun |
1095 | * Each of these interruptions has its dedicated callback function. |
1373 | * Each of these interruptions has its dedicated callback function. |
1096 | * @param hadc: ADC handle |
1374 | * @param hadc ADC handle |
1097 | * @retval HAL status |
1375 | * @retval HAL status |
1098 | */ |
1376 | */ |
1099 | HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc) |
1377 | HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc) |
1100 | { |
1378 | { |
1101 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
1379 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 1167... | Line 1445... | ||
1167 | 1445 | ||
1168 | /** |
1446 | /** |
1169 | * @brief Stop ADC conversion of regular group (and injected group in |
1447 | * @brief Stop ADC conversion of regular group (and injected group in |
1170 | * case of auto_injection mode), disable interrution of |
1448 | * case of auto_injection mode), disable interrution of |
1171 | * end-of-conversion, disable ADC peripheral. |
1449 | * end-of-conversion, disable ADC peripheral. |
1172 | * @param hadc: ADC handle |
1450 | * @param hadc ADC handle |
1173 | * @retval None |
1451 | * @retval None |
1174 | */ |
1452 | */ |
1175 | HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc) |
1453 | HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc) |
1176 | { |
1454 | { |
1177 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
1455 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 1211... | Line 1489... | ||
1211 | * Interruptions enabled in this function: |
1489 | * Interruptions enabled in this function: |
1212 | * - DMA transfer complete |
1490 | * - DMA transfer complete |
1213 | * - DMA half transfer |
1491 | * - DMA half transfer |
1214 | * - overrun |
1492 | * - overrun |
1215 | * Each of these interruptions has its dedicated callback function. |
1493 | * Each of these interruptions has its dedicated callback function. |
1216 | * @param hadc: ADC handle |
1494 | * @param hadc ADC handle |
1217 | * @param pData: The destination Buffer address. |
1495 | * @param pData The destination Buffer address. |
1218 | * @param Length: The length of data to be transferred from ADC peripheral to memory. |
1496 | * @param Length The length of data to be transferred from ADC peripheral to memory. |
1219 | * @retval None |
1497 | * @retval None |
1220 | */ |
1498 | */ |
1221 | HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length) |
1499 | HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length) |
1222 | { |
1500 | { |
1223 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
1501 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 1313... | Line 1591... | ||
1313 | * case of auto_injection mode), disable ADC DMA transfer, disable |
1591 | * case of auto_injection mode), disable ADC DMA transfer, disable |
1314 | * ADC peripheral. |
1592 | * ADC peripheral. |
1315 | * @note: ADC peripheral disable is forcing stop of potential |
1593 | * @note: ADC peripheral disable is forcing stop of potential |
1316 | * conversion on injected group. If injected group is under use, it |
1594 | * conversion on injected group. If injected group is under use, it |
1317 | * should be preliminarily stopped using HAL_ADCEx_InjectedStop function. |
1595 | * should be preliminarily stopped using HAL_ADCEx_InjectedStop function. |
1318 | * @param hadc: ADC handle |
1596 | * @param hadc ADC handle |
1319 | * @retval HAL status. |
1597 | * @retval HAL status. |
1320 | */ |
1598 | */ |
1321 | HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc) |
1599 | HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc) |
1322 | { |
1600 | { |
1323 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
1601 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 1338... | Line 1616... | ||
1338 | /* Disable ADC DMA mode */ |
1616 | /* Disable ADC DMA mode */ |
1339 | hadc->Instance->CR2 &= ~ADC_CR2_DMA; |
1617 | hadc->Instance->CR2 &= ~ADC_CR2_DMA; |
1340 | 1618 | ||
1341 | /* Disable the DMA channel (in case of DMA in circular mode or stop while */ |
1619 | /* Disable the DMA channel (in case of DMA in circular mode or stop while */ |
1342 | /* DMA transfer is on going) */ |
1620 | /* DMA transfer is on going) */ |
1343 | tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); |
1621 | HAL_DMA_Abort(hadc->DMA_Handle); |
1344 | 1622 | ||
1345 | /* Check if DMA channel effectively disabled */ |
- | |
1346 | if (tmp_hal_status == HAL_OK) |
- | |
1347 | { |
- | |
1348 | /* Set ADC state */ |
1623 | /* Set ADC state */ |
1349 | ADC_STATE_CLR_SET(hadc->State, |
1624 | ADC_STATE_CLR_SET(hadc->State, |
1350 | HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, |
1625 | HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, |
1351 | HAL_ADC_STATE_READY); |
1626 | HAL_ADC_STATE_READY); |
1352 | } |
- | |
1353 | else |
- | |
1354 | { |
- | |
1355 | /* Update ADC state machine to error */ |
- | |
1356 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); |
- | |
1357 | } |
- | |
1358 | 1627 | ||
1359 | /* Disable ADC overrun interrupt */ |
1628 | /* Disable ADC overrun interrupt */ |
1360 | __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); |
1629 | __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); |
1361 | } |
1630 | } |
1362 | 1631 | ||
Line 1381... | Line 1650... | ||
1381 | * both flags EOC and EOS are raised. |
1650 | * both flags EOC and EOS are raised. |
1382 | * To clear this flag, either use function: |
1651 | * To clear this flag, either use function: |
1383 | * in programming model IT: @ref HAL_ADC_IRQHandler(), in programming |
1652 | * in programming model IT: @ref HAL_ADC_IRQHandler(), in programming |
1384 | * model polling: @ref HAL_ADC_PollForConversion() |
1653 | * model polling: @ref HAL_ADC_PollForConversion() |
1385 | * or @ref __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_EOS). |
1654 | * or @ref __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_EOS). |
1386 | * @param hadc: ADC handle |
1655 | * @param hadc ADC handle |
1387 | * @retval ADC group regular conversion data |
1656 | * @retval ADC group regular conversion data |
1388 | */ |
1657 | */ |
1389 | uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc) |
1658 | uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc) |
1390 | { |
1659 | { |
1391 | /* Check the parameters */ |
1660 | /* Check the parameters */ |
Line 1398... | Line 1667... | ||
1398 | return hadc->Instance->DR; |
1667 | return hadc->Instance->DR; |
1399 | } |
1668 | } |
1400 | 1669 | ||
1401 | /** |
1670 | /** |
1402 | * @brief Handles ADC interrupt request |
1671 | * @brief Handles ADC interrupt request |
1403 | * @param hadc: ADC handle |
1672 | * @param hadc ADC handle |
1404 | * @retval None |
1673 | * @retval None |
1405 | */ |
1674 | */ |
1406 | void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc) |
1675 | void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc) |
1407 | { |
1676 | { |
1408 | /* Check the parameters */ |
1677 | /* Check the parameters */ |
Line 1447... | Line 1716... | ||
1447 | { |
1716 | { |
1448 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
1717 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
1449 | } |
1718 | } |
1450 | } |
1719 | } |
1451 | 1720 | ||
- | 1721 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
1452 | /* Conversion complete callback */ |
1722 | hadc->ConvCpltCallback(hadc); |
- | 1723 | #else |
|
1453 | HAL_ADC_ConvCpltCallback(hadc); |
1724 | HAL_ADC_ConvCpltCallback(hadc); |
- | 1725 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
1454 | 1726 | ||
1455 | /* Clear regular group conversion flag */ |
1727 | /* Clear regular group conversion flag */ |
1456 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_STRT | ADC_FLAG_EOC); |
1728 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_STRT | ADC_FLAG_EOC); |
1457 | } |
1729 | } |
1458 | } |
1730 | } |
Line 1490... | Line 1762... | ||
1490 | { |
1762 | { |
1491 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
1763 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
1492 | } |
1764 | } |
1493 | } |
1765 | } |
1494 | 1766 | ||
- | 1767 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
1495 | /* Conversion complete callback */ |
1768 | hadc->InjectedConvCpltCallback(hadc); |
- | 1769 | #else |
|
1496 | HAL_ADCEx_InjectedConvCpltCallback(hadc); |
1770 | HAL_ADCEx_InjectedConvCpltCallback(hadc); |
- | 1771 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
1497 | 1772 | ||
1498 | /* Clear injected group conversion flag */ |
1773 | /* Clear injected group conversion flag */ |
1499 | __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JSTRT | ADC_FLAG_JEOC)); |
1774 | __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JSTRT | ADC_FLAG_JEOC)); |
1500 | } |
1775 | } |
1501 | } |
1776 | } |
Line 1506... | Line 1781... | ||
1506 | if(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_AWD)) |
1781 | if(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_AWD)) |
1507 | { |
1782 | { |
1508 | /* Set ADC state */ |
1783 | /* Set ADC state */ |
1509 | SET_BIT(hadc->State, HAL_ADC_STATE_AWD1); |
1784 | SET_BIT(hadc->State, HAL_ADC_STATE_AWD1); |
1510 | 1785 | ||
- | 1786 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
1511 | /* Level out of window callback */ |
1787 | hadc->LevelOutOfWindowCallback(hadc); |
- | 1788 | #else |
|
1512 | HAL_ADC_LevelOutOfWindowCallback(hadc); |
1789 | HAL_ADC_LevelOutOfWindowCallback(hadc); |
- | 1790 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
1513 | 1791 | ||
1514 | /* Clear the ADC analog watchdog flag */ |
1792 | /* Clear the ADC analog watchdog flag */ |
1515 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD); |
1793 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD); |
1516 | } |
1794 | } |
1517 | } |
1795 | } |
Line 1529... | Line 1807... | ||
1529 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_OVR); |
1807 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_OVR); |
1530 | 1808 | ||
1531 | /* Clear ADC overrun flag */ |
1809 | /* Clear ADC overrun flag */ |
1532 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR); |
1810 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR); |
1533 | 1811 | ||
- | 1812 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
1534 | /* Error callback */ |
1813 | hadc->ErrorCallback(hadc); |
- | 1814 | #else |
|
1535 | HAL_ADC_ErrorCallback(hadc); |
1815 | HAL_ADC_ErrorCallback(hadc); |
- | 1816 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
1536 | 1817 | ||
1537 | /* Clear the Overrun flag */ |
1818 | /* Clear the Overrun flag */ |
1538 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR); |
1819 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_OVR); |
1539 | } |
1820 | } |
1540 | } |
1821 | } |
1541 | 1822 | ||
1542 | } |
1823 | } |
1543 | 1824 | ||
1544 | /** |
1825 | /** |
1545 | * @brief Conversion complete callback in non blocking mode |
1826 | * @brief Conversion complete callback in non blocking mode |
1546 | * @param hadc: ADC handle |
1827 | * @param hadc ADC handle |
1547 | * @retval None |
1828 | * @retval None |
1548 | */ |
1829 | */ |
1549 | __weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) |
1830 | __weak void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) |
1550 | { |
1831 | { |
1551 | /* Prevent unused argument(s) compilation warning */ |
1832 | /* Prevent unused argument(s) compilation warning */ |
Line 1556... | Line 1837... | ||
1556 | */ |
1837 | */ |
1557 | } |
1838 | } |
1558 | 1839 | ||
1559 | /** |
1840 | /** |
1560 | * @brief Conversion DMA half-transfer callback in non blocking mode |
1841 | * @brief Conversion DMA half-transfer callback in non blocking mode |
1561 | * @param hadc: ADC handle |
1842 | * @param hadc ADC handle |
1562 | * @retval None |
1843 | * @retval None |
1563 | */ |
1844 | */ |
1564 | __weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc) |
1845 | __weak void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc) |
1565 | { |
1846 | { |
1566 | /* Prevent unused argument(s) compilation warning */ |
1847 | /* Prevent unused argument(s) compilation warning */ |
Line 1571... | Line 1852... | ||
1571 | */ |
1852 | */ |
1572 | } |
1853 | } |
1573 | 1854 | ||
1574 | /** |
1855 | /** |
1575 | * @brief Analog watchdog callback in non blocking mode. |
1856 | * @brief Analog watchdog callback in non blocking mode. |
1576 | * @param hadc: ADC handle |
1857 | * @param hadc ADC handle |
1577 | * @retval None |
1858 | * @retval None |
1578 | */ |
1859 | */ |
1579 | __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc) |
1860 | __weak void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc) |
1580 | { |
1861 | { |
1581 | /* Prevent unused argument(s) compilation warning */ |
1862 | /* Prevent unused argument(s) compilation warning */ |
Line 1593... | Line 1874... | ||
1593 | * (HAL ADC handle paramater "ErrorCode" to state "HAL_ADC_ERROR_OVR"): |
1874 | * (HAL ADC handle paramater "ErrorCode" to state "HAL_ADC_ERROR_OVR"): |
1594 | * - Reinitialize the DMA using function "HAL_ADC_Stop_DMA()". |
1875 | * - Reinitialize the DMA using function "HAL_ADC_Stop_DMA()". |
1595 | * - If needed, restart a new ADC conversion using function |
1876 | * - If needed, restart a new ADC conversion using function |
1596 | * "HAL_ADC_Start_DMA()" |
1877 | * "HAL_ADC_Start_DMA()" |
1597 | * (this function is also clearing overrun flag) |
1878 | * (this function is also clearing overrun flag) |
1598 | * @param hadc: ADC handle |
1879 | * @param hadc ADC handle |
1599 | * @retval None |
1880 | * @retval None |
1600 | */ |
1881 | */ |
1601 | __weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc) |
1882 | __weak void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc) |
1602 | { |
1883 | { |
1603 | /* Prevent unused argument(s) compilation warning */ |
1884 | /* Prevent unused argument(s) compilation warning */ |
Line 1641... | Line 1922... | ||
1641 | * of structure "ADC_ChannelConfTypeDef" on the fly, without reseting |
1922 | * of structure "ADC_ChannelConfTypeDef" on the fly, without reseting |
1642 | * the ADC. |
1923 | * the ADC. |
1643 | * The setting of these parameters is conditioned to ADC state. |
1924 | * The setting of these parameters is conditioned to ADC state. |
1644 | * For parameters constraints, see comments of structure |
1925 | * For parameters constraints, see comments of structure |
1645 | * "ADC_ChannelConfTypeDef". |
1926 | * "ADC_ChannelConfTypeDef". |
1646 | * @param hadc: ADC handle |
1927 | * @param hadc ADC handle |
1647 | * @param sConfig: Structure of ADC channel for regular group. |
1928 | * @param sConfig Structure of ADC channel for regular group. |
1648 | * @retval HAL status |
1929 | * @retval HAL status |
1649 | */ |
1930 | */ |
1650 | HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig) |
1931 | HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig) |
1651 | { |
1932 | { |
1652 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
1933 | HAL_StatusTypeDef tmp_hal_status = HAL_OK; |
Line 1766... | Line 2047... | ||
1766 | * the programmed threshold values are effective from the next |
2047 | * the programmed threshold values are effective from the next |
1767 | * ADC EOC (end of unitary conversion). |
2048 | * ADC EOC (end of unitary conversion). |
1768 | * Considering that registers write delay may happen due to |
2049 | * Considering that registers write delay may happen due to |
1769 | * bus activity, this might cause an uncertainty on the |
2050 | * bus activity, this might cause an uncertainty on the |
1770 | * effective timing of the new programmed threshold values. |
2051 | * effective timing of the new programmed threshold values. |
1771 | * @param hadc: ADC handle |
2052 | * @param hadc ADC handle |
1772 | * @param AnalogWDGConfig: Structure of ADC analog watchdog configuration |
2053 | * @param AnalogWDGConfig Structure of ADC analog watchdog configuration |
1773 | * @retval HAL status |
2054 | * @retval HAL status |
1774 | */ |
2055 | */ |
1775 | HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig) |
2056 | HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig) |
1776 | { |
2057 | { |
1777 | /* Check the parameters */ |
2058 | /* Check the parameters */ |
Line 1854... | Line 2135... | ||
1854 | * @{ |
2135 | * @{ |
1855 | */ |
2136 | */ |
1856 | 2137 | ||
1857 | /** |
2138 | /** |
1858 | * @brief return the ADC state |
2139 | * @brief return the ADC state |
1859 | * @param hadc: ADC handle |
2140 | * @param hadc ADC handle |
1860 | * @retval HAL state |
2141 | * @retval HAL state |
1861 | */ |
2142 | */ |
1862 | uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc) |
2143 | uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc) |
1863 | { |
2144 | { |
1864 | /* Return ADC state */ |
2145 | /* Return ADC state */ |
1865 | return hadc->State; |
2146 | return hadc->State; |
1866 | } |
2147 | } |
1867 | 2148 | ||
1868 | /** |
2149 | /** |
1869 | * @brief Return the ADC error code |
2150 | * @brief Return the ADC error code |
1870 | * @param hadc: ADC handle |
2151 | * @param hadc ADC handle |
1871 | * @retval ADC Error Code |
2152 | * @retval ADC Error Code |
1872 | */ |
2153 | */ |
1873 | uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc) |
2154 | uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc) |
1874 | { |
2155 | { |
1875 | return hadc->ErrorCode; |
2156 | return hadc->ErrorCode; |
Line 1895... | Line 2176... | ||
1895 | * performed automatically by hardware. |
2176 | * performed automatically by hardware. |
1896 | * In this mode, this function is useless and must not be called because |
2177 | * In this mode, this function is useless and must not be called because |
1897 | * flag ADC_FLAG_RDY is not usable. |
2178 | * flag ADC_FLAG_RDY is not usable. |
1898 | * Therefore, this function must be called under condition of |
2179 | * Therefore, this function must be called under condition of |
1899 | * "if (hadc->Init.LowPowerAutoPowerOff != ENABLE)". |
2180 | * "if (hadc->Init.LowPowerAutoPowerOff != ENABLE)". |
1900 | * @param hadc: ADC handle |
2181 | * @param hadc ADC handle |
1901 | * @retval HAL status. |
2182 | * @retval HAL status. |
1902 | */ |
2183 | */ |
1903 | HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc) |
2184 | HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc) |
1904 | { |
2185 | { |
1905 | uint32_t tickstart = 0; |
2186 | uint32_t tickstart = 0; |
Line 1950... | Line 2231... | ||
1950 | 2231 | ||
1951 | /** |
2232 | /** |
1952 | * @brief Stop ADC conversion and disable the selected ADC |
2233 | * @brief Stop ADC conversion and disable the selected ADC |
1953 | * @note Prerequisite condition to use this function: ADC conversions must be |
2234 | * @note Prerequisite condition to use this function: ADC conversions must be |
1954 | * stopped to disable the ADC. |
2235 | * stopped to disable the ADC. |
1955 | * @param hadc: ADC handle |
2236 | * @param hadc ADC handle |
1956 | * @retval HAL status. |
2237 | * @retval HAL status. |
1957 | */ |
2238 | */ |
1958 | HAL_StatusTypeDef ADC_ConversionStop_Disable(ADC_HandleTypeDef* hadc) |
2239 | HAL_StatusTypeDef ADC_ConversionStop_Disable(ADC_HandleTypeDef* hadc) |
1959 | { |
2240 | { |
1960 | uint32_t tickstart = 0; |
2241 | uint32_t tickstart = 0; |
Line 1988... | Line 2269... | ||
1988 | return HAL_OK; |
2269 | return HAL_OK; |
1989 | } |
2270 | } |
1990 | 2271 | ||
1991 | /** |
2272 | /** |
1992 | * @brief DMA transfer complete callback. |
2273 | * @brief DMA transfer complete callback. |
1993 | * @param hdma: pointer to DMA handle. |
2274 | * @param hdma pointer to DMA handle. |
1994 | * @retval None |
2275 | * @retval None |
1995 | */ |
2276 | */ |
1996 | static void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma) |
2277 | static void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma) |
1997 | { |
2278 | { |
1998 | /* Retrieve ADC handle corresponding to current DMA handle */ |
2279 | /* Retrieve ADC handle corresponding to current DMA handle */ |
Line 2029... | Line 2310... | ||
2029 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
2310 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
2030 | } |
2311 | } |
2031 | } |
2312 | } |
2032 | 2313 | ||
2033 | /* Conversion complete callback */ |
2314 | /* Conversion complete callback */ |
- | 2315 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
- | 2316 | hadc->ConvCpltCallback(hadc); |
|
- | 2317 | #else |
|
2034 | HAL_ADC_ConvCpltCallback(hadc); |
2318 | HAL_ADC_ConvCpltCallback(hadc); |
- | 2319 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
2035 | } |
2320 | } |
2036 | else |
2321 | else |
2037 | { |
2322 | { |
2038 | /* Call DMA error callback */ |
2323 | /* Call DMA error callback */ |
2039 | hadc->DMA_Handle->XferErrorCallback(hdma); |
2324 | hadc->DMA_Handle->XferErrorCallback(hdma); |
2040 | } |
2325 | } |
2041 | } |
2326 | } |
2042 | 2327 | ||
2043 | /** |
2328 | /** |
2044 | * @brief DMA half transfer complete callback. |
2329 | * @brief DMA half transfer complete callback. |
2045 | * @param hdma: pointer to DMA handle. |
2330 | * @param hdma pointer to DMA handle. |
2046 | * @retval None |
2331 | * @retval None |
2047 | */ |
2332 | */ |
2048 | static void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma) |
2333 | static void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma) |
2049 | { |
2334 | { |
2050 | /* Retrieve ADC handle corresponding to current DMA handle */ |
2335 | /* Retrieve ADC handle corresponding to current DMA handle */ |
2051 | ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
2336 | ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
2052 | 2337 | ||
2053 | /* Half conversion callback */ |
2338 | /* Half conversion callback */ |
- | 2339 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
- | 2340 | hadc->ConvHalfCpltCallback(hadc); |
|
- | 2341 | #else |
|
2054 | HAL_ADC_ConvHalfCpltCallback(hadc); |
2342 | HAL_ADC_ConvHalfCpltCallback(hadc); |
- | 2343 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
2055 | } |
2344 | } |
2056 | 2345 | ||
2057 | /** |
2346 | /** |
2058 | * @brief DMA error callback |
2347 | * @brief DMA error callback |
2059 | * @param hdma: pointer to DMA handle. |
2348 | * @param hdma pointer to DMA handle. |
2060 | * @retval None |
2349 | * @retval None |
2061 | */ |
2350 | */ |
2062 | static void ADC_DMAError(DMA_HandleTypeDef *hdma) |
2351 | static void ADC_DMAError(DMA_HandleTypeDef *hdma) |
2063 | { |
2352 | { |
2064 | /* Retrieve ADC handle corresponding to current DMA handle */ |
2353 | /* Retrieve ADC handle corresponding to current DMA handle */ |
Line 2069... | Line 2358... | ||
2069 | 2358 | ||
2070 | /* Set ADC error code to DMA error */ |
2359 | /* Set ADC error code to DMA error */ |
2071 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_DMA); |
2360 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_DMA); |
2072 | 2361 | ||
2073 | /* Error callback */ |
2362 | /* Error callback */ |
- | 2363 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
- | 2364 | hadc->ErrorCallback(hadc); |
|
- | 2365 | #else |
|
2074 | HAL_ADC_ErrorCallback(hadc); |
2366 | HAL_ADC_ErrorCallback(hadc); |
- | 2367 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
2075 | } |
2368 | } |
2076 | 2369 | ||
2077 | /** |
2370 | /** |
2078 | * @} |
2371 | * @} |
2079 | */ |
2372 | */ |