Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 9 | ||
|---|---|---|---|
| Line 238... | Line 238... | ||
| 238 | using function HAL_DMA_Init(). |
238 | using function HAL_DMA_Init(). |
| 239 | (++) Disable the NVIC for DMA |
239 | (++) Disable the NVIC for DMA |
| 240 | using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn) |
240 | using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn) |
| 241 | 241 | ||
| 242 | [..] |
242 | [..] |
| - | 243 | |
|
| - | 244 | *** Callback registration *** |
|
| - | 245 | ============================================= |
|
| - | 246 | [..] |
|
| - | 247 | ||
| - | 248 | The compilation flag USE_HAL_ADC_REGISTER_CALLBACKS, when set to 1, |
|
| - | 249 | allows the user to configure dynamically the driver callbacks. |
|
| - | 250 | Use Functions @ref HAL_ADC_RegisterCallback() |
|
| - | 251 | to register an interrupt callback. |
|
| - | 252 | [..] |
|
| - | 253 | ||
| - | 254 | Function @ref HAL_ADC_RegisterCallback() allows to register following callbacks: |
|
| - | 255 | (+) ConvCpltCallback : ADC conversion complete callback |
|
| - | 256 | (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback |
|
| - | 257 | (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback |
|
| - | 258 | (+) ErrorCallback : ADC error callback |
|
| - | 259 | (+) InjectedConvCpltCallback : ADC group injected conversion complete callback |
|
| - | 260 | (+) MspInitCallback : ADC Msp Init callback |
|
| - | 261 | (+) MspDeInitCallback : ADC Msp DeInit callback |
|
| - | 262 | This function takes as parameters the HAL peripheral handle, the Callback ID |
|
| - | 263 | and a pointer to the user callback function. |
|
| - | 264 | [..] |
|
| - | 265 | ||
| - | 266 | Use function @ref HAL_ADC_UnRegisterCallback to reset a callback to the default |
|
| - | 267 | weak function. |
|
| - | 268 | [..] |
|
| - | 269 | ||
| - | 270 | @ref HAL_ADC_UnRegisterCallback takes as parameters the HAL peripheral handle, |
|
| - | 271 | and the Callback ID. |
|
| - | 272 | This function allows to reset following callbacks: |
|
| - | 273 | (+) ConvCpltCallback : ADC conversion complete callback |
|
| - | 274 | (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback |
|
| - | 275 | (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback |
|
| - | 276 | (+) ErrorCallback : ADC error callback |
|
| - | 277 | (+) InjectedConvCpltCallback : ADC group injected conversion complete callback |
|
| - | 278 | (+) MspInitCallback : ADC Msp Init callback |
|
| - | 279 | (+) MspDeInitCallback : ADC Msp DeInit callback |
|
| - | 280 | [..] |
|
| - | 281 | ||
| - | 282 | By default, after the @ref HAL_ADC_Init() and when the state is @ref HAL_ADC_STATE_RESET |
|
| - | 283 | all callbacks are set to the corresponding weak functions: |
|
| - | 284 | examples @ref HAL_ADC_ConvCpltCallback(), @ref HAL_ADC_ErrorCallback(). |
|
| - | 285 | Exception done for MspInit and MspDeInit functions that are |
|
| - | 286 | reset to the legacy weak functions in the @ref HAL_ADC_Init()/ @ref HAL_ADC_DeInit() only when |
|
| - | 287 | these callbacks are null (not registered beforehand). |
|
| - | 288 | [..] |
|
| - | 289 | ||
| - | 290 | If MspInit or MspDeInit are not null, the @ref HAL_ADC_Init()/ @ref HAL_ADC_DeInit() |
|
| - | 291 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state. |
|
| - | 292 | [..] |
|
| - | 293 | ||
| - | 294 | Callbacks can be registered/unregistered in @ref HAL_ADC_STATE_READY state only. |
|
| - | 295 | Exception done MspInit/MspDeInit functions that can be registered/unregistered |
|
| - | 296 | in @ref HAL_ADC_STATE_READY or @ref HAL_ADC_STATE_RESET state, |
|
| - | 297 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
|
| - | 298 | [..] |
|
| - | 299 | ||
| - | 300 | Then, the user first registers the MspInit/MspDeInit user callbacks |
|
| - | 301 | using @ref HAL_ADC_RegisterCallback() before calling @ref HAL_ADC_DeInit() |
|
| - | 302 | or @ref HAL_ADC_Init() function. |
|
| - | 303 | [..] |
|
| - | 304 | ||
| - | 305 | When the compilation flag USE_HAL_ADC_REGISTER_CALLBACKS is set to 0 or |
|
| - | 306 | not defined, the callback registration feature is not available and all callbacks |
|
| - | 307 | are set to the corresponding weak functions. |
|
| 243 | |
308 | |
| 244 | @endverbatim |
309 | @endverbatim |
| 245 | ****************************************************************************** |
310 | ****************************************************************************** |
| 246 | * @attention |
311 | * @attention |
| 247 | * |
312 | * |
| 248 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
313 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
| 249 | * |
- | |
| 250 | * Redistribution and use in source and binary forms, with or without modification, |
- | |
| 251 | * are permitted provided that the following conditions are met: |
- | |
| 252 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
| 253 | * this list of conditions and the following disclaimer. |
- | |
| 254 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
| 255 | * this list of conditions and the following disclaimer in the documentation |
- | |
| 256 | * and/or other materials provided with the distribution. |
- | |
| 257 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
| 258 | * may be used to endorse or promote products derived from this software |
- | |
| 259 | * without specific prior written permission. |
314 | * All rights reserved.</center></h2> |
| 260 | * |
315 | * |
| 261 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
316 | * This software component is licensed by ST under BSD 3-Clause license, |
| 262 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
| 263 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
| 264 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
| 265 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
| 266 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
317 | * the "License"; You may not use this file except in compliance with the |
| 267 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
318 | * License. You may obtain a copy of the License at: |
| 268 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
| 269 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
| 270 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
319 | * opensource.org/licenses/BSD-3-Clause |
| 271 | * |
320 | * |
| 272 | ****************************************************************************** |
321 | ****************************************************************************** |
| 273 | */ |
322 | */ |
| 274 | 323 | ||
| 275 | /* Includes ------------------------------------------------------------------*/ |
324 | /* Includes ------------------------------------------------------------------*/ |
| 276 | #include "stm32f1xx_hal.h" |
325 | #include "stm32f1xx_hal.h" |
| 277 | 326 | ||
| Line 412... | Line 461... | ||
| 412 | ADC_CLEAR_ERRORCODE(hadc); |
461 | ADC_CLEAR_ERRORCODE(hadc); |
| 413 | 462 | ||
| 414 | /* Allocate lock resource and initialize it */ |
463 | /* Allocate lock resource and initialize it */ |
| 415 | hadc->Lock = HAL_UNLOCKED; |
464 | hadc->Lock = HAL_UNLOCKED; |
| 416 | 465 | ||
| - | 466 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 467 | /* Init the ADC Callback settings */ |
|
| - | 468 | hadc->ConvCpltCallback = HAL_ADC_ConvCpltCallback; /* Legacy weak callback */ |
|
| - | 469 | hadc->ConvHalfCpltCallback = HAL_ADC_ConvHalfCpltCallback; /* Legacy weak callback */ |
|
| - | 470 | hadc->LevelOutOfWindowCallback = HAL_ADC_LevelOutOfWindowCallback; /* Legacy weak callback */ |
|
| - | 471 | hadc->ErrorCallback = HAL_ADC_ErrorCallback; /* Legacy weak callback */ |
|
| - | 472 | hadc->InjectedConvCpltCallback = HAL_ADCEx_InjectedConvCpltCallback; /* Legacy weak callback */ |
|
| - | 473 | ||
| - | 474 | if (hadc->MspInitCallback == NULL) |
|
| - | 475 | { |
|
| - | 476 | hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ |
|
| - | 477 | } |
|
| - | 478 | ||
| - | 479 | /* Init the low level hardware */ |
|
| - | 480 | hadc->MspInitCallback(hadc); |
|
| - | 481 | #else |
|
| 417 | /* Init the low level hardware */ |
482 | /* Init the low level hardware */ |
| 418 | HAL_ADC_MspInit(hadc); |
483 | HAL_ADC_MspInit(hadc); |
| - | 484 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| 419 | } |
485 | } |
| 420 | 486 | ||
| 421 | /* Stop potential conversion on going, on regular and injected groups */ |
487 | /* Stop potential conversion on going, on regular and injected groups */ |
| 422 | /* Disable ADC peripheral */ |
488 | /* Disable ADC peripheral */ |
| 423 | /* Note: In case of ADC already enabled, precaution to not launch an */ |
489 | /* Note: In case of ADC already enabled, precaution to not launch an */ |
| Line 446... | Line 512... | ||
| 446 | /* - continuous conversion mode */ |
512 | /* - continuous conversion mode */ |
| 447 | /* Note: External trigger polarity (ADC_CR2_EXTTRIG) is set into */ |
513 | /* Note: External trigger polarity (ADC_CR2_EXTTRIG) is set into */ |
| 448 | /* HAL_ADC_Start_xxx functions because if set in this function, */ |
514 | /* HAL_ADC_Start_xxx functions because if set in this function, */ |
| 449 | /* a conversion on injected group would start a conversion also on */ |
515 | /* a conversion on injected group would start a conversion also on */ |
| 450 | /* regular group after ADC enabling. */ |
516 | /* regular group after ADC enabling. */ |
| 451 | tmp_cr2 |= (hadc->Init.DataAlign | |
517 | tmp_cr2 |= (hadc->Init.DataAlign | |
| 452 | ADC_CFGR_EXTSEL(hadc, hadc->Init.ExternalTrigConv) | |
518 | ADC_CFGR_EXTSEL(hadc, hadc->Init.ExternalTrigConv) | |
| 453 | ADC_CR2_CONTINUOUS(hadc->Init.ContinuousConvMode) ); |
519 | ADC_CR2_CONTINUOUS((uint32_t)hadc->Init.ContinuousConvMode) ); |
| 454 | 520 | ||
| 455 | /* Configuration of ADC: */ |
521 | /* Configuration of ADC: */ |
| 456 | /* - scan mode */ |
522 | /* - scan mode */ |
| 457 | /* - discontinuous mode disable/enable */ |
523 | /* - discontinuous mode disable/enable */ |
| 458 | /* - discontinuous mode number of conversions */ |
524 | /* - discontinuous mode number of conversions */ |
| 459 | tmp_cr1 |= (ADC_CR1_SCAN_SET(hadc->Init.ScanConvMode)); |
525 | tmp_cr1 |= (ADC_CR1_SCAN_SET(hadc->Init.ScanConvMode)); |
| Line 683... | Line 749... | ||
| 683 | /* function "void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)": */ |
749 | /* function "void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)": */ |
| 684 | /* */ |
750 | /* */ |
| 685 | /* __HAL_RCC_ADC1_FORCE_RESET() */ |
751 | /* __HAL_RCC_ADC1_FORCE_RESET() */ |
| 686 | /* __HAL_RCC_ADC1_RELEASE_RESET() */ |
752 | /* __HAL_RCC_ADC1_RELEASE_RESET() */ |
| 687 | 753 | ||
| - | 754 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 755 | if (hadc->MspDeInitCallback == NULL) |
|
| - | 756 | { |
|
| - | 757 | hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ |
|
| - | 758 | } |
|
| - | 759 | ||
| - | 760 | /* DeInit the low level hardware */ |
|
| - | 761 | hadc->MspDeInitCallback(hadc); |
|
| - | 762 | #else |
|
| 688 | /* DeInit the low level hardware */ |
763 | /* DeInit the low level hardware */ |
| 689 | HAL_ADC_MspDeInit(hadc); |
764 | HAL_ADC_MspDeInit(hadc); |
| - | 765 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| 690 | 766 | ||
| 691 | /* Set ADC error code to none */ |
767 | /* Set ADC error code to none */ |
| 692 | ADC_CLEAR_ERRORCODE(hadc); |
768 | ADC_CLEAR_ERRORCODE(hadc); |
| 693 | 769 | ||
| 694 | /* Set ADC state */ |
770 | /* Set ADC state */ |
| Line 729... | Line 805... | ||
| 729 | /* NOTE : This function should not be modified. When the callback is needed, |
805 | /* NOTE : This function should not be modified. When the callback is needed, |
| 730 | function HAL_ADC_MspDeInit must be implemented in the user file. |
806 | function HAL_ADC_MspDeInit must be implemented in the user file. |
| 731 | */ |
807 | */ |
| 732 | } |
808 | } |
| 733 | 809 | ||
| - | 810 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 811 | /** |
|
| - | 812 | * @brief Register a User ADC Callback |
|
| - | 813 | * To be used instead of the weak predefined callback |
|
| - | 814 | * @param hadc Pointer to a ADC_HandleTypeDef structure that contains |
|
| - | 815 | * the configuration information for the specified ADC. |
|
| - | 816 | * @param CallbackID ID of the callback to be registered |
|
| - | 817 | * This parameter can be one of the following values: |
|
| - | 818 | * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID |
|
| - | 819 | * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion complete callback ID |
|
| - | 820 | * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID |
|
| - | 821 | * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID |
|
| - | 822 | * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID |
|
| - | 823 | * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID |
|
| - | 824 | * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID |
|
| - | 825 | * @arg @ref HAL_ADC_MSPINIT_CB_ID MspInit callback ID |
|
| - | 826 | * @arg @ref HAL_ADC_MSPDEINIT_CB_ID MspDeInit callback ID |
|
| - | 827 | * @param pCallback pointer to the Callback function |
|
| - | 828 | * @retval HAL status |
|
| - | 829 | */ |
|
| - | 830 | HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback) |
|
| - | 831 | { |
|
| - | 832 | HAL_StatusTypeDef status = HAL_OK; |
|
| - | 833 | ||
| - | 834 | if (pCallback == NULL) |
|
| - | 835 | { |
|
| - | 836 | /* Update the error code */ |
|
| - | 837 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
| - | 838 | ||
| - | 839 | return HAL_ERROR; |
|
| - | 840 | } |
|
| - | 841 | ||
| - | 842 | if ((hadc->State & HAL_ADC_STATE_READY) != 0) |
|
| - | 843 | { |
|
| - | 844 | switch (CallbackID) |
|
| - | 845 | { |
|
| - | 846 | case HAL_ADC_CONVERSION_COMPLETE_CB_ID : |
|
| - | 847 | hadc->ConvCpltCallback = pCallback; |
|
| - | 848 | break; |
|
| - | 849 | ||
| - | 850 | case HAL_ADC_CONVERSION_HALF_CB_ID : |
|
| - | 851 | hadc->ConvHalfCpltCallback = pCallback; |
|
| - | 852 | break; |
|
| - | 853 | ||
| - | 854 | case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID : |
|
| - | 855 | hadc->LevelOutOfWindowCallback = pCallback; |
|
| - | 856 | break; |
|
| - | 857 | ||
| - | 858 | case HAL_ADC_ERROR_CB_ID : |
|
| - | 859 | hadc->ErrorCallback = pCallback; |
|
| - | 860 | break; |
|
| - | 861 | ||
| - | 862 | case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID : |
|
| - | 863 | hadc->InjectedConvCpltCallback = pCallback; |
|
| - | 864 | break; |
|
| - | 865 | ||
| - | 866 | case HAL_ADC_MSPINIT_CB_ID : |
|
| - | 867 | hadc->MspInitCallback = pCallback; |
|
| - | 868 | break; |
|
| - | 869 | ||
| - | 870 | case HAL_ADC_MSPDEINIT_CB_ID : |
|
| - | 871 | hadc->MspDeInitCallback = pCallback; |
|
| - | 872 | break; |
|
| - | 873 | ||
| - | 874 | default : |
|
| - | 875 | /* Update the error code */ |
|
| - | 876 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
| - | 877 | ||
| - | 878 | /* Return error status */ |
|
| - | 879 | status = HAL_ERROR; |
|
| - | 880 | break; |
|
| - | 881 | } |
|
| - | 882 | } |
|
| - | 883 | else if (HAL_ADC_STATE_RESET == hadc->State) |
|
| - | 884 | { |
|
| - | 885 | switch (CallbackID) |
|
| - | 886 | { |
|
| - | 887 | case HAL_ADC_MSPINIT_CB_ID : |
|
| - | 888 | hadc->MspInitCallback = pCallback; |
|
| - | 889 | break; |
|
| - | 890 | ||
| - | 891 | case HAL_ADC_MSPDEINIT_CB_ID : |
|
| - | 892 | hadc->MspDeInitCallback = pCallback; |
|
| - | 893 | break; |
|
| - | 894 | ||
| - | 895 | default : |
|
| - | 896 | /* Update the error code */ |
|
| - | 897 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
| - | 898 | ||
| - | 899 | /* Return error status */ |
|
| - | 900 | status = HAL_ERROR; |
|
| - | 901 | break; |
|
| - | 902 | } |
|
| - | 903 | } |
|
| - | 904 | else |
|
| - | 905 | { |
|
| - | 906 | /* Update the error code */ |
|
| - | 907 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
| - | 908 | ||
| - | 909 | /* Return error status */ |
|
| - | 910 | status = HAL_ERROR; |
|
| - | 911 | } |
|
| - | 912 | ||
| - | 913 | return status; |
|
| - | 914 | } |
|
| - | 915 | ||
| - | 916 | /** |
|
| - | 917 | * @brief Unregister a ADC Callback |
|
| - | 918 | * ADC callback is redirected to the weak predefined callback |
|
| - | 919 | * @param hadc Pointer to a ADC_HandleTypeDef structure that contains |
|
| - | 920 | * the configuration information for the specified ADC. |
|
| - | 921 | * @param CallbackID ID of the callback to be unregistered |
|
| - | 922 | * This parameter can be one of the following values: |
|
| - | 923 | * @arg @ref HAL_ADC_CONVERSION_COMPLETE_CB_ID ADC conversion complete callback ID |
|
| - | 924 | * @arg @ref HAL_ADC_CONVERSION_HALF_CB_ID ADC conversion complete callback ID |
|
| - | 925 | * @arg @ref HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID ADC analog watchdog 1 callback ID |
|
| - | 926 | * @arg @ref HAL_ADC_ERROR_CB_ID ADC error callback ID |
|
| - | 927 | * @arg @ref HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID ADC group injected conversion complete callback ID |
|
| - | 928 | * @arg @ref HAL_ADC_MSPINIT_CB_ID ADC Msp Init callback ID |
|
| - | 929 | * @arg @ref HAL_ADC_MSPDEINIT_CB_ID ADC Msp DeInit callback ID |
|
| - | 930 | * @arg @ref HAL_ADC_MSPINIT_CB_ID MspInit callback ID |
|
| - | 931 | * @arg @ref HAL_ADC_MSPDEINIT_CB_ID MspDeInit callback ID |
|
| - | 932 | * @retval HAL status |
|
| - | 933 | */ |
|
| - | 934 | HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID) |
|
| - | 935 | { |
|
| - | 936 | HAL_StatusTypeDef status = HAL_OK; |
|
| - | 937 | ||
| - | 938 | if ((hadc->State & HAL_ADC_STATE_READY) != 0) |
|
| - | 939 | { |
|
| - | 940 | switch (CallbackID) |
|
| - | 941 | { |
|
| - | 942 | case HAL_ADC_CONVERSION_COMPLETE_CB_ID : |
|
| - | 943 | hadc->ConvCpltCallback = HAL_ADC_ConvCpltCallback; |
|
| - | 944 | break; |
|
| - | 945 | ||
| - | 946 | case HAL_ADC_CONVERSION_HALF_CB_ID : |
|
| - | 947 | hadc->ConvHalfCpltCallback = HAL_ADC_ConvHalfCpltCallback; |
|
| - | 948 | break; |
|
| - | 949 | ||
| - | 950 | case HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID : |
|
| - | 951 | hadc->LevelOutOfWindowCallback = HAL_ADC_LevelOutOfWindowCallback; |
|
| - | 952 | break; |
|
| - | 953 | ||
| - | 954 | case HAL_ADC_ERROR_CB_ID : |
|
| - | 955 | hadc->ErrorCallback = HAL_ADC_ErrorCallback; |
|
| - | 956 | break; |
|
| - | 957 | ||
| - | 958 | case HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID : |
|
| - | 959 | hadc->InjectedConvCpltCallback = HAL_ADCEx_InjectedConvCpltCallback; |
|
| - | 960 | break; |
|
| - | 961 | ||
| - | 962 | case HAL_ADC_MSPINIT_CB_ID : |
|
| - | 963 | hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ |
|
| - | 964 | break; |
|
| - | 965 | ||
| - | 966 | case HAL_ADC_MSPDEINIT_CB_ID : |
|
| - | 967 | hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ |
|
| - | 968 | break; |
|
| - | 969 | ||
| - | 970 | default : |
|
| - | 971 | /* Update the error code */ |
|
| - | 972 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
| - | 973 | ||
| - | 974 | /* Return error status */ |
|
| - | 975 | status = HAL_ERROR; |
|
| - | 976 | break; |
|
| - | 977 | } |
|
| - | 978 | } |
|
| - | 979 | else if (HAL_ADC_STATE_RESET == hadc->State) |
|
| - | 980 | { |
|
| - | 981 | switch (CallbackID) |
|
| - | 982 | { |
|
| - | 983 | case HAL_ADC_MSPINIT_CB_ID : |
|
| - | 984 | hadc->MspInitCallback = HAL_ADC_MspInit; /* Legacy weak MspInit */ |
|
| - | 985 | break; |
|
| - | 986 | ||
| - | 987 | case HAL_ADC_MSPDEINIT_CB_ID : |
|
| - | 988 | hadc->MspDeInitCallback = HAL_ADC_MspDeInit; /* Legacy weak MspDeInit */ |
|
| - | 989 | break; |
|
| - | 990 | ||
| - | 991 | default : |
|
| - | 992 | /* Update the error code */ |
|
| - | 993 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
| - | 994 | ||
| - | 995 | /* Return error status */ |
|
| - | 996 | status = HAL_ERROR; |
|
| - | 997 | break; |
|
| - | 998 | } |
|
| - | 999 | } |
|
| - | 1000 | else |
|
| - | 1001 | { |
|
| - | 1002 | /* Update the error code */ |
|
| - | 1003 | hadc->ErrorCode |= HAL_ADC_ERROR_INVALID_CALLBACK; |
|
| - | 1004 | ||
| - | 1005 | /* Return error status */ |
|
| - | 1006 | status = HAL_ERROR; |
|
| - | 1007 | } |
|
| - | 1008 | ||
| - | 1009 | return status; |
|
| - | 1010 | } |
|
| - | 1011 | ||
| - | 1012 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| - | 1013 | ||
| 734 | /** |
1014 | /** |
| 735 | * @} |
1015 | * @} |
| 736 | */ |
1016 | */ |
| 737 | 1017 | ||
| 738 | /** @defgroup ADC_Exported_Functions_Group2 IO operation functions |
1018 | /** @defgroup ADC_Exported_Functions_Group2 IO operation functions |
| Line 1429... | Line 1709... | ||
| 1429 | /* Disable ADC DMA mode */ |
1709 | /* Disable ADC DMA mode */ |
| 1430 | CLEAR_BIT(hadc->Instance->CR2, ADC_CR2_DMA); |
1710 | CLEAR_BIT(hadc->Instance->CR2, ADC_CR2_DMA); |
| 1431 | 1711 | ||
| 1432 | /* Disable the DMA channel (in case of DMA in circular mode or stop while */ |
1712 | /* Disable the DMA channel (in case of DMA in circular mode or stop while */ |
| 1433 | /* DMA transfer is on going) */ |
1713 | /* DMA transfer is on going) */ |
| 1434 | tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); |
- | |
| 1435 | - | ||
| 1436 | /* Check if DMA channel effectively disabled */ |
- | |
| 1437 | if (tmp_hal_status == HAL_OK) |
- | |
| 1438 | { |
- | |
| 1439 | /* Set ADC state */ |
- | |
| 1440 | ADC_STATE_CLR_SET(hadc->State, |
- | |
| 1441 | HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, |
- | |
| 1442 | HAL_ADC_STATE_READY); |
1714 | if (hadc->DMA_Handle->State == HAL_DMA_STATE_BUSY) |
| 1443 | } |
- | |
| 1444 | else |
- | |
| 1445 | { |
1715 | { |
| - | 1716 | tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); |
|
| - | 1717 | ||
| - | 1718 | /* Check if DMA channel effectively disabled */ |
|
| - | 1719 | if (tmp_hal_status == HAL_OK) |
|
| - | 1720 | { |
|
| - | 1721 | /* Set ADC state */ |
|
| - | 1722 | ADC_STATE_CLR_SET(hadc->State, |
|
| - | 1723 | HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, |
|
| - | 1724 | HAL_ADC_STATE_READY); |
|
| - | 1725 | } |
|
| - | 1726 | else |
|
| - | 1727 | { |
|
| 1446 | /* Update ADC state machine to error */ |
1728 | /* Update ADC state machine to error */ |
| 1447 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); |
1729 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); |
| - | 1730 | } |
|
| 1448 | } |
1731 | } |
| 1449 | } |
1732 | } |
| 1450 | 1733 | ||
| 1451 | /* Process unlocked */ |
1734 | /* Process unlocked */ |
| 1452 | __HAL_UNLOCK(hadc); |
1735 | __HAL_UNLOCK(hadc); |
| 1453 | 1736 | ||
| 1454 | /* Return function status */ |
1737 | /* Return function status */ |
| 1455 | return tmp_hal_status; |
1738 | return tmp_hal_status; |
| Line 1530... | Line 1813... | ||
| 1530 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
1813 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
| 1531 | } |
1814 | } |
| 1532 | } |
1815 | } |
| 1533 | 1816 | ||
| 1534 | /* Conversion complete callback */ |
1817 | /* Conversion complete callback */ |
| - | 1818 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 1819 | hadc->ConvCpltCallback(hadc); |
|
| - | 1820 | #else |
|
| 1535 | HAL_ADC_ConvCpltCallback(hadc); |
1821 | HAL_ADC_ConvCpltCallback(hadc); |
| - | 1822 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| 1536 | 1823 | ||
| 1537 | /* Clear regular group conversion flag */ |
1824 | /* Clear regular group conversion flag */ |
| 1538 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_STRT | ADC_FLAG_EOC); |
1825 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_STRT | ADC_FLAG_EOC); |
| 1539 | } |
1826 | } |
| 1540 | } |
1827 | } |
| Line 1574... | Line 1861... | ||
| 1574 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
1861 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
| 1575 | } |
1862 | } |
| 1576 | } |
1863 | } |
| 1577 | 1864 | ||
| 1578 | /* Conversion complete callback */ |
1865 | /* Conversion complete callback */ |
| - | 1866 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 1867 | hadc->InjectedConvCpltCallback(hadc); |
|
| - | 1868 | #else |
|
| 1579 | HAL_ADCEx_InjectedConvCpltCallback(hadc); |
1869 | HAL_ADCEx_InjectedConvCpltCallback(hadc); |
| - | 1870 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| 1580 | 1871 | ||
| 1581 | /* Clear injected group conversion flag */ |
1872 | /* Clear injected group conversion flag */ |
| 1582 | __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JSTRT | ADC_FLAG_JEOC)); |
1873 | __HAL_ADC_CLEAR_FLAG(hadc, (ADC_FLAG_JSTRT | ADC_FLAG_JEOC)); |
| 1583 | } |
1874 | } |
| 1584 | } |
1875 | } |
| Line 1590... | Line 1881... | ||
| 1590 | { |
1881 | { |
| 1591 | /* Set ADC state */ |
1882 | /* Set ADC state */ |
| 1592 | SET_BIT(hadc->State, HAL_ADC_STATE_AWD1); |
1883 | SET_BIT(hadc->State, HAL_ADC_STATE_AWD1); |
| 1593 | 1884 | ||
| 1594 | /* Level out of window callback */ |
1885 | /* Level out of window callback */ |
| - | 1886 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 1887 | hadc->LevelOutOfWindowCallback(hadc); |
|
| - | 1888 | #else |
|
| 1595 | HAL_ADC_LevelOutOfWindowCallback(hadc); |
1889 | HAL_ADC_LevelOutOfWindowCallback(hadc); |
| - | 1890 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| 1596 | 1891 | ||
| 1597 | /* Clear the ADC analog watchdog flag */ |
1892 | /* Clear the ADC analog watchdog flag */ |
| 1598 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD); |
1893 | __HAL_ADC_CLEAR_FLAG(hadc, ADC_FLAG_AWD); |
| 1599 | } |
1894 | } |
| 1600 | } |
1895 | } |
| Line 2049... | Line 2344... | ||
| 2049 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
2344 | SET_BIT(hadc->State, HAL_ADC_STATE_READY); |
| 2050 | } |
2345 | } |
| 2051 | } |
2346 | } |
| 2052 | 2347 | ||
| 2053 | /* Conversion complete callback */ |
2348 | /* Conversion complete callback */ |
| - | 2349 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 2350 | hadc->ConvCpltCallback(hadc); |
|
| - | 2351 | #else |
|
| 2054 | HAL_ADC_ConvCpltCallback(hadc); |
2352 | HAL_ADC_ConvCpltCallback(hadc); |
| - | 2353 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| 2055 | } |
2354 | } |
| 2056 | else |
2355 | else |
| 2057 | { |
2356 | { |
| 2058 | /* Call DMA error callback */ |
2357 | /* Call DMA error callback */ |
| 2059 | hadc->DMA_Handle->XferErrorCallback(hdma); |
2358 | hadc->DMA_Handle->XferErrorCallback(hdma); |
| Line 2069... | Line 2368... | ||
| 2069 | { |
2368 | { |
| 2070 | /* Retrieve ADC handle corresponding to current DMA handle */ |
2369 | /* Retrieve ADC handle corresponding to current DMA handle */ |
| 2071 | ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
2370 | ADC_HandleTypeDef* hadc = ( ADC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
| 2072 | 2371 | ||
| 2073 | /* Half conversion callback */ |
2372 | /* Half conversion callback */ |
| - | 2373 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 2374 | hadc->ConvHalfCpltCallback(hadc); |
|
| - | 2375 | #else |
|
| 2074 | HAL_ADC_ConvHalfCpltCallback(hadc); |
2376 | HAL_ADC_ConvHalfCpltCallback(hadc); |
| - | 2377 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| 2075 | } |
2378 | } |
| 2076 | 2379 | ||
| 2077 | /** |
2380 | /** |
| 2078 | * @brief DMA error callback |
2381 | * @brief DMA error callback |
| 2079 | * @param hdma: pointer to DMA handle. |
2382 | * @param hdma: pointer to DMA handle. |
| Line 2089... | Line 2392... | ||
| 2089 | 2392 | ||
| 2090 | /* Set ADC error code to DMA error */ |
2393 | /* Set ADC error code to DMA error */ |
| 2091 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_DMA); |
2394 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_DMA); |
| 2092 | 2395 | ||
| 2093 | /* Error callback */ |
2396 | /* Error callback */ |
| - | 2397 | #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) |
|
| - | 2398 | hadc->ErrorCallback(hadc); |
|
| - | 2399 | #else |
|
| 2094 | HAL_ADC_ErrorCallback(hadc); |
2400 | HAL_ADC_ErrorCallback(hadc); |
| - | 2401 | #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ |
|
| 2095 | } |
2402 | } |
| 2096 | 2403 | ||
| 2097 | /** |
2404 | /** |
| 2098 | * @} |
2405 | * @} |
| 2099 | */ |
2406 | */ |