stm32h7xx_hal_dfsdm.c 128.8 KB
Newer Older
whj123999's avatar
whj123999 已提交
1 2 3 4
/**
  ******************************************************************************
  * @file    stm32h7xx_hal_dfsdm.c
  * @author  MCD Application Team
M
Mr.Tiger 已提交
5
  * @brief   This file provides firmware functions to manage the following
whj123999's avatar
whj123999 已提交
6 7 8 9 10 11 12 13 14 15 16 17
  *          functionalities of the Digital Filter for Sigma-Delta Modulators
  *          (DFSDM) peripherals:
  *           + Initialization and configuration of channels and filters
  *           + Regular channels configuration
  *           + Injected channels configuration
  *           + Regular/Injected Channels DMA Configuration
  *           + Interrupts and flags management
  *           + Analog watchdog feature
  *           + Short-circuit detector feature
  *           + Extremes detector feature
  *           + Clock absence detector feature
  *           + Break generation on analog watchdog or short-circuit event
M
Mr.Tiger 已提交
18
  *
whj123999's avatar
whj123999 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  @verbatim
  ==============================================================================
                     ##### How to use this driver #####
  ==============================================================================
  [..]
    *** Channel initialization ***
    ==============================
    [..]
      (#) User has first to initialize channels (before filters initialization).
      (#) As prerequisite, fill in the HAL_DFSDM_ChannelMspInit() :
        (++) Enable DFSDMz clock interface with __HAL_RCC_DFSDMz_CLK_ENABLE().
        (++) Enable the clocks for the DFSDMz GPIOS with __HAL_RCC_GPIOx_CLK_ENABLE().
        (++) Configure these DFSDMz pins in alternate mode using HAL_GPIO_Init().
        (++) If interrupt mode is used, enable and configure DFSDMz_FLT0 global
            interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
      (#) Configure the output clock, input, serial interface, analog watchdog,
M
Mr.Tiger 已提交
35
          offset and data right bit shift parameters for this channel using the
whj123999's avatar
whj123999 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48
          HAL_DFSDM_ChannelInit() function.

    *** Channel clock absence detector ***
    ======================================
    [..]
      (#) Start clock absence detector using HAL_DFSDM_ChannelCkabStart() or
          HAL_DFSDM_ChannelCkabStart_IT().
      (#) In polling mode, use HAL_DFSDM_ChannelPollForCkab() to detect the clock
          absence.
      (#) In interrupt mode, HAL_DFSDM_ChannelCkabCallback() will be called if
          clock absence is detected.
      (#) Stop clock absence detector using HAL_DFSDM_ChannelCkabStop() or
          HAL_DFSDM_ChannelCkabStop_IT().
M
Mr.Tiger 已提交
49
      (#) Please note that the same mode (polling or interrupt) has to be used
whj123999's avatar
whj123999 已提交
50 51 52 53 54 55
          for all channels because the channels are sharing the same interrupt.
      (#) Please note also that in interrupt mode, if clock absence detector is
          stopped for one channel, interrupt will be disabled for all channels.

    *** Channel short circuit detector ***
    ======================================
M
Mr.Tiger 已提交
56
    [..]
whj123999's avatar
whj123999 已提交
57 58 59 60
      (#) Start short circuit detector using HAL_DFSDM_ChannelScdStart() or
          or HAL_DFSDM_ChannelScdStart_IT().
      (#) In polling mode, use HAL_DFSDM_ChannelPollForScd() to detect short
          circuit.
M
Mr.Tiger 已提交
61
      (#) In interrupt mode, HAL_DFSDM_ChannelScdCallback() will be called if
whj123999's avatar
whj123999 已提交
62 63 64
          short circuit is detected.
      (#) Stop short circuit detector using HAL_DFSDM_ChannelScdStop() or
          or HAL_DFSDM_ChannelScdStop_IT().
M
Mr.Tiger 已提交
65
      (#) Please note that the same mode (polling or interrupt) has to be used
whj123999's avatar
whj123999 已提交
66 67 68 69 70 71
          for all channels because the channels are sharing the same interrupt.
      (#) Please note also that in interrupt mode, if short circuit detector is
          stopped for one channel, interrupt will be disabled for all channels.

    *** Channel analog watchdog value ***
    =====================================
M
Mr.Tiger 已提交
72
    [..]
whj123999's avatar
whj123999 已提交
73 74 75 76 77
      (#) Get analog watchdog filter value of a channel using
          HAL_DFSDM_ChannelGetAwdValue().

    *** Channel offset value ***
    =====================================
M
Mr.Tiger 已提交
78
    [..]
whj123999's avatar
whj123999 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
      (#) Modify offset value of a channel using HAL_DFSDM_ChannelModifyOffset().

    *** Filter initialization ***
    =============================
    [..]
      (#) After channel initialization, user has to init filters.
      (#) As prerequisite, fill in the HAL_DFSDM_FilterMspInit() :
        (++) If interrupt mode is used , enable and configure DFSDMz_FLTx global
            interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
            Please note that DFSDMz_FLT0 global interrupt could be already
            enabled if interrupt is used for channel.
        (++) If DMA mode is used, configure DMA with HAL_DMA_Init() and link it
            with DFSDMz filter handle using __HAL_LINKDMA().
      (#) Configure the regular conversion, injected conversion and filter
          parameters for this filter using the HAL_DFSDM_FilterInit() function.

    *** Filter regular channel conversion ***
    =========================================
M
Mr.Tiger 已提交
97
    [..]
whj123999's avatar
whj123999 已提交
98 99 100 101 102
      (#) Select regular channel and enable/disable continuous mode using
          HAL_DFSDM_FilterConfigRegChannel().
      (#) Start regular conversion using HAL_DFSDM_FilterRegularStart(),
          HAL_DFSDM_FilterRegularStart_IT(), HAL_DFSDM_FilterRegularStart_DMA() or
          HAL_DFSDM_FilterRegularMsbStart_DMA().
M
Mr.Tiger 已提交
103
      (#) In polling mode, use HAL_DFSDM_FilterPollForRegConversion() to detect
whj123999's avatar
whj123999 已提交
104 105 106
          the end of regular conversion.
      (#) In interrupt mode, HAL_DFSDM_FilterRegConvCpltCallback() will be called
          at the end of regular conversion.
M
Mr.Tiger 已提交
107
      (#) Get value of regular conversion and corresponding channel using
whj123999's avatar
whj123999 已提交
108
          HAL_DFSDM_FilterGetRegularValue().
M
Mr.Tiger 已提交
109
      (#) In DMA mode, HAL_DFSDM_FilterRegConvHalfCpltCallback() and
whj123999's avatar
whj123999 已提交
110
          HAL_DFSDM_FilterRegConvCpltCallback() will be called respectively at the
M
Mr.Tiger 已提交
111
          half transfer and at the transfer complete. Please note that
whj123999's avatar
whj123999 已提交
112 113 114 115 116 117 118
          HAL_DFSDM_FilterRegConvHalfCpltCallback() will be called only in DMA
          circular mode.
      (#) Stop regular conversion using HAL_DFSDM_FilterRegularStop(),
          HAL_DFSDM_FilterRegularStop_IT() or HAL_DFSDM_FilterRegularStop_DMA().

    *** Filter injected channels conversion ***
    ===========================================
M
Mr.Tiger 已提交
119
    [..]
whj123999's avatar
whj123999 已提交
120 121 122 123
      (#) Select injected channels using HAL_DFSDM_FilterConfigInjChannel().
      (#) Start injected conversion using HAL_DFSDM_FilterInjectedStart(),
          HAL_DFSDM_FilterInjectedStart_IT(), HAL_DFSDM_FilterInjectedStart_DMA() or
          HAL_DFSDM_FilterInjectedMsbStart_DMA().
M
Mr.Tiger 已提交
124
      (#) In polling mode, use HAL_DFSDM_FilterPollForInjConversion() to detect
whj123999's avatar
whj123999 已提交
125 126 127
          the end of injected conversion.
      (#) In interrupt mode, HAL_DFSDM_FilterInjConvCpltCallback() will be called
          at the end of injected conversion.
M
Mr.Tiger 已提交
128
      (#) Get value of injected conversion and corresponding channel using
whj123999's avatar
whj123999 已提交
129
          HAL_DFSDM_FilterGetInjectedValue().
M
Mr.Tiger 已提交
130
      (#) In DMA mode, HAL_DFSDM_FilterInjConvHalfCpltCallback() and
whj123999's avatar
whj123999 已提交
131
          HAL_DFSDM_FilterInjConvCpltCallback() will be called respectively at the
M
Mr.Tiger 已提交
132
          half transfer and at the transfer complete. Please note that
whj123999's avatar
whj123999 已提交
133 134 135 136 137 138 139
          HAL_DFSDM_FilterInjConvCpltCallback() will be called only in DMA
          circular mode.
      (#) Stop injected conversion using HAL_DFSDM_FilterInjectedStop(),
          HAL_DFSDM_FilterInjectedStop_IT() or HAL_DFSDM_FilterInjectedStop_DMA().

    *** Filter analog watchdog ***
    ==============================
M
Mr.Tiger 已提交
140
    [..]
whj123999's avatar
whj123999 已提交
141 142 143 144 145 146
      (#) Start filter analog watchdog using HAL_DFSDM_FilterAwdStart_IT().
      (#) HAL_DFSDM_FilterAwdCallback() will be called if analog watchdog occurs.
      (#) Stop filter analog watchdog using HAL_DFSDM_FilterAwdStop_IT().

    *** Filter extreme detector ***
    ===============================
M
Mr.Tiger 已提交
147
    [..]
whj123999's avatar
whj123999 已提交
148 149 150 151 152 153 154
      (#) Start filter extreme detector using HAL_DFSDM_FilterExdStart().
      (#) Get extreme detector maximum value using HAL_DFSDM_FilterGetExdMaxValue().
      (#) Get extreme detector minimum value using HAL_DFSDM_FilterGetExdMinValue().
      (#) Start filter extreme detector using HAL_DFSDM_FilterExdStop().

    *** Filter conversion time ***
    ==============================
M
Mr.Tiger 已提交
155
    [..]
whj123999's avatar
whj123999 已提交
156 157
      (#) Get conversion time value using HAL_DFSDM_FilterGetConvTimeValue().

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
    *** Callback registration ***
    =============================
    [..]
    The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS when set to 1
    allows the user to configure dynamically the driver callbacks.
    Use functions HAL_DFSDM_Channel_RegisterCallback(),
    HAL_DFSDM_Filter_RegisterCallback() or
    HAL_DFSDM_Filter_RegisterAwdCallback() to register a user callback.

    [..]
    Function HAL_DFSDM_Channel_RegisterCallback() allows to register
    following callbacks:
      (+) CkabCallback      : DFSDM channel clock absence detection callback.
      (+) ScdCallback       : DFSDM channel short circuit detection callback.
      (+) MspInitCallback   : DFSDM channel MSP init callback.
      (+) MspDeInitCallback : DFSDM channel MSP de-init callback.
    [..]
    This function takes as parameters the HAL peripheral handle, the Callback ID
    and a pointer to the user callback function.

    [..]
    Function HAL_DFSDM_Filter_RegisterCallback() allows to register
    following callbacks:
      (+) RegConvCpltCallback     : DFSDM filter regular conversion complete callback.
      (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback.
      (+) InjConvCpltCallback     : DFSDM filter injected conversion complete callback.
      (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback.
      (+) ErrorCallback           : DFSDM filter error callback.
      (+) MspInitCallback         : DFSDM filter MSP init callback.
      (+) MspDeInitCallback       : DFSDM filter MSP de-init callback.
    [..]
    This function takes as parameters the HAL peripheral handle, the Callback ID
    and a pointer to the user callback function.

    [..]
M
Mr.Tiger 已提交
193
    For specific DFSDM filter analog watchdog callback use dedicated register callback:
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
    HAL_DFSDM_Filter_RegisterAwdCallback().

    [..]
    Use functions HAL_DFSDM_Channel_UnRegisterCallback() or
    HAL_DFSDM_Filter_UnRegisterCallback() to reset a callback to the default
    weak function.

    [..]
    HAL_DFSDM_Channel_UnRegisterCallback() takes as parameters the HAL peripheral handle,
    and the Callback ID.
    [..]
    This function allows to reset following callbacks:
      (+) CkabCallback      : DFSDM channel clock absence detection callback.
      (+) ScdCallback       : DFSDM channel short circuit detection callback.
      (+) MspInitCallback   : DFSDM channel MSP init callback.
      (+) MspDeInitCallback : DFSDM channel MSP de-init callback.

    [..]
    HAL_DFSDM_Filter_UnRegisterCallback() takes as parameters the HAL peripheral handle,
    and the Callback ID.
    [..]
    This function allows to reset following callbacks:
      (+) RegConvCpltCallback     : DFSDM filter regular conversion complete callback.
      (+) RegConvHalfCpltCallback : DFSDM filter half regular conversion complete callback.
      (+) InjConvCpltCallback     : DFSDM filter injected conversion complete callback.
      (+) InjConvHalfCpltCallback : DFSDM filter half injected conversion complete callback.
      (+) ErrorCallback           : DFSDM filter error callback.
      (+) MspInitCallback         : DFSDM filter MSP init callback.
      (+) MspDeInitCallback       : DFSDM filter MSP de-init callback.

    [..]
    For specific DFSDM filter analog watchdog callback use dedicated unregister callback:
    HAL_DFSDM_Filter_UnRegisterAwdCallback().

    [..]
M
Mr.Tiger 已提交
229 230
    By default, after the call of init function and if the state is RESET
    all callbacks are reset to the corresponding legacy weak functions:
231 232
    examples HAL_DFSDM_ChannelScdCallback(), HAL_DFSDM_FilterErrorCallback().
    Exception done for MspInit and MspDeInit callbacks that are respectively
M
Mr.Tiger 已提交
233
    reset to the legacy weak functions in the init and de-init only when these
234 235 236 237 238 239 240 241 242
    callbacks are null (not registered beforehand).
    If not, MspInit or MspDeInit are not null, the init and de-init keep and use
    the user MspInit/MspDeInit callbacks (registered beforehand)

    [..]
    Callbacks can be registered/unregistered in READY state only.
    Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
    in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
    during the init/de-init.
M
Mr.Tiger 已提交
243
    In that case first register the MspInit/MspDeInit user callbacks using
244 245 246 247 248
    HAL_DFSDM_Channel_RegisterCallback() or
    HAL_DFSDM_Filter_RegisterCallback() before calling init or de-init function.

    [..]
    When The compilation define USE_HAL_DFSDM_REGISTER_CALLBACKS is set to 0 or
M
Mr.Tiger 已提交
249
    not defined, the callback registering feature is not available
250 251
    and weak callbacks are used.

whj123999's avatar
whj123999 已提交
252 253 254 255
    @endverbatim
  ******************************************************************************
  * @attention
  *
256 257
  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  * All rights reserved.</center></h2>
whj123999's avatar
whj123999 已提交
258
  *
259 260 261 262
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
whj123999's avatar
whj123999 已提交
263
  *
264 265
  ******************************************************************************
  */
whj123999's avatar
whj123999 已提交
266 267 268 269 270 271 272 273

/* Includes ------------------------------------------------------------------*/
#include "stm32h7xx_hal.h"

/** @addtogroup STM32H7xx_HAL_Driver
  * @{
  */
#ifdef HAL_DFSDM_MODULE_ENABLED
274

whj123999's avatar
whj123999 已提交
275 276 277
/** @defgroup DFSDM DFSDM
  * @brief DFSDM HAL driver module
  * @{
M
Mr.Tiger 已提交
278
  */
whj123999's avatar
whj123999 已提交
279 280 281 282 283 284 285

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/** @defgroup DFSDM_Private_Define DFSDM Private Define
 * @{
 */
#define DFSDM_FLTCR1_MSB_RCH_OFFSET     8
286 287 288 289
#define DFSDM_MSB_MASK                  0xFFFF0000U
#define DFSDM_LSB_MASK                  0x0000FFFFU
#define DFSDM_CKAB_TIMEOUT              5000U
#define DFSDM1_CHANNEL_NUMBER           8U
M
Mr.Tiger 已提交
290 291 292
#if defined(DFSDM2_Channel0)
#define DFSDM2_CHANNEL_NUMBER           2U
#endif /* DFSDM2_Channel0 */
whj123999's avatar
whj123999 已提交
293 294 295 296 297 298 299 300 301
/**
  * @}
  */

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/** @defgroup DFSDM_Private_Variables DFSDM Private Variables
  * @{
  */
302
static __IO uint32_t                v_dfsdm1ChannelCounter = 0;
M
Mr.Tiger 已提交
303 304 305 306 307
static DFSDM_Channel_HandleTypeDef *a_dfsdm1ChannelHandle[DFSDM1_CHANNEL_NUMBER] = {NULL};
#if defined(DFSDM2_Channel0)
static __IO uint32_t                v_dfsdm2ChannelCounter = 0;
static DFSDM_Channel_HandleTypeDef *a_dfsdm2ChannelHandle[DFSDM2_CHANNEL_NUMBER] = {NULL};
#endif /* DFSDM2_Channel0 */
whj123999's avatar
whj123999 已提交
308 309 310 311 312 313 314 315 316
/**
  * @}
  */

/* Private function prototypes -----------------------------------------------*/
/** @defgroup DFSDM_Private_Functions DFSDM Private Functions
  * @{
  */
static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels);
M
Mr.Tiger 已提交
317
static uint32_t DFSDM_GetChannelFromInstance(const DFSDM_Channel_TypeDef *Instance);
whj123999's avatar
whj123999 已提交
318
static void     DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
M
Mr.Tiger 已提交
319 320 321
static void     DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
static void     DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
static void     DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
whj123999's avatar
whj123999 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
static void     DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma);
static void     DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma);
static void     DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma);
static void     DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma);
static void     DFSDM_DMAError(DMA_HandleTypeDef *hdma);
/**
  * @}
  */

/* Exported functions --------------------------------------------------------*/
/** @defgroup DFSDM_Exported_Functions DFSDM Exported Functions
  * @{
  */

/** @defgroup DFSDM_Exported_Functions_Group1_Channel Channel initialization and de-initialization functions
M
Mr.Tiger 已提交
337
 *  @brief    Channel initialization and de-initialization functions
whj123999's avatar
whj123999 已提交
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
 *
@verbatim
  ==============================================================================
        ##### Channel initialization and de-initialization functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Initialize the DFSDM channel.
      (+) De-initialize the DFSDM channel.
@endverbatim
  * @{
  */

/**
  * @brief  Initialize the DFSDM channel according to the specified parameters
  *         in the DFSDM_ChannelInitTypeDef structure and initialize the associated handle.
353
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
354 355 356 357
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
M
Mr.Tiger 已提交
358 359 360 361
  __IO uint32_t               *channelCounterPtr;
  DFSDM_Channel_HandleTypeDef **channelHandleTable;
  DFSDM_Channel_TypeDef       *channel0Instance;

whj123999's avatar
whj123999 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
  /* Check DFSDM Channel handle */
  if(hdfsdm_channel == NULL)
  {
    return HAL_ERROR;
  }

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
  assert_param(IS_FUNCTIONAL_STATE(hdfsdm_channel->Init.OutputClock.Activation));
  assert_param(IS_DFSDM_CHANNEL_INPUT(hdfsdm_channel->Init.Input.Multiplexer));
  assert_param(IS_DFSDM_CHANNEL_DATA_PACKING(hdfsdm_channel->Init.Input.DataPacking));
  assert_param(IS_DFSDM_CHANNEL_INPUT_PINS(hdfsdm_channel->Init.Input.Pins));
  assert_param(IS_DFSDM_CHANNEL_SERIAL_INTERFACE_TYPE(hdfsdm_channel->Init.SerialInterface.Type));
  assert_param(IS_DFSDM_CHANNEL_SPI_CLOCK(hdfsdm_channel->Init.SerialInterface.SpiClock));
  assert_param(IS_DFSDM_CHANNEL_FILTER_ORDER(hdfsdm_channel->Init.Awd.FilterOrder));
  assert_param(IS_DFSDM_CHANNEL_FILTER_OVS_RATIO(hdfsdm_channel->Init.Awd.Oversampling));
  assert_param(IS_DFSDM_CHANNEL_OFFSET(hdfsdm_channel->Init.Offset));
  assert_param(IS_DFSDM_CHANNEL_RIGHT_BIT_SHIFT(hdfsdm_channel->Init.RightBitShift));
M
Mr.Tiger 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    channelCounterPtr  = &v_dfsdm1ChannelCounter;
    channelHandleTable = a_dfsdm1ChannelHandle;
    channel0Instance   = DFSDM1_Channel0;
  }
  else
  {
    channelCounterPtr  = &v_dfsdm2ChannelCounter;
    channelHandleTable = a_dfsdm2ChannelHandle;
    channel0Instance   = DFSDM2_Channel0;
  }
#else /* DFSDM2_Channel0 */
  channelCounterPtr  = &v_dfsdm1ChannelCounter;
  channelHandleTable = a_dfsdm1ChannelHandle;
  channel0Instance   = DFSDM1_Channel0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
400
  /* Check that channel has not been already initialized */
M
Mr.Tiger 已提交
401
  if (channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] != NULL)
whj123999's avatar
whj123999 已提交
402 403 404
  {
    return HAL_ERROR;
  }
M
Mr.Tiger 已提交
405

406 407 408 409 410 411 412 413 414 415 416 417
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  /* Reset callback pointers to the weak predefined callbacks */
  hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback;
  hdfsdm_channel->ScdCallback  = HAL_DFSDM_ChannelScdCallback;

  /* Call MSP init function */
  if(hdfsdm_channel->MspInitCallback == NULL)
  {
    hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
  }
  hdfsdm_channel->MspInitCallback(hdfsdm_channel);
#else
whj123999's avatar
whj123999 已提交
418 419
  /* Call MSP init function */
  HAL_DFSDM_ChannelMspInit(hdfsdm_channel);
420
#endif
M
Mr.Tiger 已提交
421

whj123999's avatar
whj123999 已提交
422
  /* Update the channel counter */
M
Mr.Tiger 已提交
423 424
  (*channelCounterPtr)++;

whj123999's avatar
whj123999 已提交
425
  /* Configure output serial clock and enable global DFSDM interface only for first channel */
M
Mr.Tiger 已提交
426
  if(*channelCounterPtr == 1U)
whj123999's avatar
whj123999 已提交
427 428 429
  {
    assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK(hdfsdm_channel->Init.OutputClock.Selection));
    /* Set the output serial clock source */
M
Mr.Tiger 已提交
430 431 432
    channel0Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTSRC);
    channel0Instance->CHCFGR1 |= hdfsdm_channel->Init.OutputClock.Selection;

whj123999's avatar
whj123999 已提交
433
    /* Reset clock divider */
M
Mr.Tiger 已提交
434
    channel0Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKOUTDIV);
whj123999's avatar
whj123999 已提交
435 436 437 438
    if(hdfsdm_channel->Init.OutputClock.Activation == ENABLE)
    {
      assert_param(IS_DFSDM_CHANNEL_OUTPUT_CLOCK_DIVIDER(hdfsdm_channel->Init.OutputClock.Divider));
      /* Set the output clock divider */
M
Mr.Tiger 已提交
439 440
      channel0Instance->CHCFGR1 |= (uint32_t)((hdfsdm_channel->Init.OutputClock.Divider - 1U) <<
                                              DFSDM_CHCFGR1_CKOUTDIV_Pos);
whj123999's avatar
whj123999 已提交
441
    }
M
Mr.Tiger 已提交
442

whj123999's avatar
whj123999 已提交
443
    /* enable the DFSDM global interface */
M
Mr.Tiger 已提交
444
    channel0Instance->CHCFGR1 |= DFSDM_CHCFGR1_DFSDMEN;
whj123999's avatar
whj123999 已提交
445
  }
M
Mr.Tiger 已提交
446

whj123999's avatar
whj123999 已提交
447
  /* Set channel input parameters */
M
Mr.Tiger 已提交
448
  hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DATPACK | DFSDM_CHCFGR1_DATMPX |
whj123999's avatar
whj123999 已提交
449
                                         DFSDM_CHCFGR1_CHINSEL);
M
Mr.Tiger 已提交
450 451
  hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.Input.Multiplexer |
                                        hdfsdm_channel->Init.Input.DataPacking |
whj123999's avatar
whj123999 已提交
452
                                        hdfsdm_channel->Init.Input.Pins);
M
Mr.Tiger 已提交
453

whj123999's avatar
whj123999 已提交
454 455
  /* Set serial interface parameters */
  hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SITP | DFSDM_CHCFGR1_SPICKSEL);
M
Mr.Tiger 已提交
456
  hdfsdm_channel->Instance->CHCFGR1 |= (hdfsdm_channel->Init.SerialInterface.Type |
whj123999's avatar
whj123999 已提交
457
                                        hdfsdm_channel->Init.SerialInterface.SpiClock);
M
Mr.Tiger 已提交
458

whj123999's avatar
whj123999 已提交
459 460
  /* Set analog watchdog parameters */
  hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_AWFORD | DFSDM_CHAWSCDR_AWFOSR);
M
Mr.Tiger 已提交
461
  hdfsdm_channel->Instance->CHAWSCDR |= (hdfsdm_channel->Init.Awd.FilterOrder |
462
                                       ((hdfsdm_channel->Init.Awd.Oversampling - 1U) << DFSDM_CHAWSCDR_AWFOSR_Pos));
whj123999's avatar
whj123999 已提交
463 464 465

  /* Set channel offset and right bit shift */
  hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET | DFSDM_CHCFGR2_DTRBS);
M
Mr.Tiger 已提交
466
  hdfsdm_channel->Instance->CHCFGR2 |= (((uint32_t) hdfsdm_channel->Init.Offset << DFSDM_CHCFGR2_OFFSET_Pos) |
467
                                        (hdfsdm_channel->Init.RightBitShift << DFSDM_CHCFGR2_DTRBS_Pos));
whj123999's avatar
whj123999 已提交
468 469 470

  /* Enable DFSDM channel */
  hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CHEN;
M
Mr.Tiger 已提交
471

whj123999's avatar
whj123999 已提交
472 473 474 475
  /* Set DFSDM Channel to ready state */
  hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_READY;

  /* Store channel handle in DFSDM channel handle table */
M
Mr.Tiger 已提交
476 477
  channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = hdfsdm_channel;

whj123999's avatar
whj123999 已提交
478 479 480 481 482
  return HAL_OK;
}

/**
  * @brief  De-initialize the DFSDM channel.
483
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
484 485 486 487
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
M
Mr.Tiger 已提交
488 489 490 491
  __IO uint32_t               *channelCounterPtr;
  DFSDM_Channel_HandleTypeDef **channelHandleTable;
  DFSDM_Channel_TypeDef       *channel0Instance;

whj123999's avatar
whj123999 已提交
492 493 494 495 496 497 498 499
  /* Check DFSDM Channel handle */
  if(hdfsdm_channel == NULL)
  {
    return HAL_ERROR;
  }

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
M
Mr.Tiger 已提交
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    channelCounterPtr  = &v_dfsdm1ChannelCounter;
    channelHandleTable = a_dfsdm1ChannelHandle;
    channel0Instance   = DFSDM1_Channel0;
  }
  else
  {
    channelCounterPtr  = &v_dfsdm2ChannelCounter;
    channelHandleTable = a_dfsdm2ChannelHandle;
    channel0Instance   = DFSDM2_Channel0;
  }
#else /* DFSDM2_Channel0 */
  channelCounterPtr  = &v_dfsdm1ChannelCounter;
  channelHandleTable = a_dfsdm1ChannelHandle;
  channel0Instance   = DFSDM1_Channel0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
520
  /* Check that channel has not been already deinitialized */
M
Mr.Tiger 已提交
521
  if (channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] == NULL)
whj123999's avatar
whj123999 已提交
522 523 524 525 526 527
  {
    return HAL_ERROR;
  }

  /* Disable the DFSDM channel */
  hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CHEN);
M
Mr.Tiger 已提交
528

whj123999's avatar
whj123999 已提交
529
  /* Update the channel counter */
M
Mr.Tiger 已提交
530 531
  (*channelCounterPtr)--;

whj123999's avatar
whj123999 已提交
532
  /* Disable global DFSDM at deinit of last channel */
M
Mr.Tiger 已提交
533
  if (*channelCounterPtr == 0U)
whj123999's avatar
whj123999 已提交
534
  {
M
Mr.Tiger 已提交
535
    channel0Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_DFSDMEN);
whj123999's avatar
whj123999 已提交
536 537 538
  }

  /* Call MSP deinit function */
539 540 541 542 543 544 545
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  if(hdfsdm_channel->MspDeInitCallback == NULL)
  {
    hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
  }
  hdfsdm_channel->MspDeInitCallback(hdfsdm_channel);
#else
whj123999's avatar
whj123999 已提交
546
  HAL_DFSDM_ChannelMspDeInit(hdfsdm_channel);
547
#endif
whj123999's avatar
whj123999 已提交
548 549 550 551 552

  /* Set DFSDM Channel in reset state */
  hdfsdm_channel->State = HAL_DFSDM_CHANNEL_STATE_RESET;

  /* Reset channel handle in DFSDM channel handle table */
M
Mr.Tiger 已提交
553
  channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance)] = (DFSDM_Channel_HandleTypeDef *) NULL;
whj123999's avatar
whj123999 已提交
554 555 556 557 558 559

  return HAL_OK;
}

/**
  * @brief  Initialize the DFSDM channel MSP.
560
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
561 562 563 564 565 566
  * @retval None
  */
__weak void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_channel);
M
Mr.Tiger 已提交
567

whj123999's avatar
whj123999 已提交
568 569 570 571 572 573 574
  /* NOTE : This function should not be modified, when the function is needed,
            the HAL_DFSDM_ChannelMspInit could be implemented in the user file.
   */
}

/**
  * @brief  De-initialize the DFSDM channel MSP.
575
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
576 577 578 579 580 581
  * @retval None
  */
__weak void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_channel);
M
Mr.Tiger 已提交
582

whj123999's avatar
whj123999 已提交
583 584 585 586 587
  /* NOTE : This function should not be modified, when the function is needed,
            the HAL_DFSDM_ChannelMspDeInit could be implemented in the user file.
   */
}

588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
/**
  * @brief  Register a user DFSDM channel callback
  *         to be used instead of the weak predefined callback.
  * @param  hdfsdm_channel DFSDM channel handle.
  * @param  CallbackID ID of the callback to be registered.
  *         This parameter can be one of the following values:
  *           @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID.
  *           @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID.
  *           @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID.
  *           @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID.
  * @param  pCallback pointer to the callback function.
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_Channel_RegisterCallback(DFSDM_Channel_HandleTypeDef        *hdfsdm_channel,
                                                     HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID,
                                                     pDFSDM_Channel_CallbackTypeDef      pCallback)
{
  HAL_StatusTypeDef status = HAL_OK;

  if(pCallback == NULL)
  {
    /* update return status */
    status = HAL_ERROR;
  }
  else
  {
    if(HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State)
    {
      switch (CallbackID)
      {
M
Mr.Tiger 已提交
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
        case HAL_DFSDM_CHANNEL_CKAB_CB_ID :
          hdfsdm_channel->CkabCallback = pCallback;
          break;
        case HAL_DFSDM_CHANNEL_SCD_CB_ID :
          hdfsdm_channel->ScdCallback = pCallback;
          break;
        case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
          hdfsdm_channel->MspInitCallback = pCallback;
          break;
        case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
          hdfsdm_channel->MspDeInitCallback = pCallback;
          break;
        default :
          /* update return status */
          status = HAL_ERROR;
          break;
635 636 637 638 639 640
      }
    }
    else if(HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State)
    {
      switch (CallbackID)
      {
M
Mr.Tiger 已提交
641 642 643 644 645 646 647 648 649 650
        case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
          hdfsdm_channel->MspInitCallback = pCallback;
          break;
        case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
          hdfsdm_channel->MspDeInitCallback = pCallback;
          break;
        default :
          /* update return status */
          status = HAL_ERROR;
          break;
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
      }
    }
    else
    {
      /* update return status */
      status = HAL_ERROR;
    }
  }
  return status;
}

/**
  * @brief  Unregister a user DFSDM channel callback.
  *         DFSDM channel callback is redirected to the weak predefined callback.
  * @param  hdfsdm_channel DFSDM channel handle.
  * @param  CallbackID ID of the callback to be unregistered.
  *         This parameter can be one of the following values:
  *           @arg @ref HAL_DFSDM_CHANNEL_CKAB_CB_ID clock absence detection callback ID.
  *           @arg @ref HAL_DFSDM_CHANNEL_SCD_CB_ID short circuit detection callback ID.
  *           @arg @ref HAL_DFSDM_CHANNEL_MSPINIT_CB_ID MSP init callback ID.
  *           @arg @ref HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID MSP de-init callback ID.
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_Channel_UnRegisterCallback(DFSDM_Channel_HandleTypeDef        *hdfsdm_channel,
                                                       HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID)
{
  HAL_StatusTypeDef status = HAL_OK;

  if(HAL_DFSDM_CHANNEL_STATE_READY == hdfsdm_channel->State)
  {
    switch (CallbackID)
    {
    case HAL_DFSDM_CHANNEL_CKAB_CB_ID :
      hdfsdm_channel->CkabCallback = HAL_DFSDM_ChannelCkabCallback;
      break;
    case HAL_DFSDM_CHANNEL_SCD_CB_ID :
      hdfsdm_channel->ScdCallback = HAL_DFSDM_ChannelScdCallback;
      break;
    case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
      hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
      break;
    case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
      hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
      break;
    default :
      /* update return status */
      status = HAL_ERROR;
      break;
    }
  }
  else if(HAL_DFSDM_CHANNEL_STATE_RESET == hdfsdm_channel->State)
  {
    switch (CallbackID)
    {
    case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
      hdfsdm_channel->MspInitCallback = HAL_DFSDM_ChannelMspInit;
      break;
    case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
      hdfsdm_channel->MspDeInitCallback = HAL_DFSDM_ChannelMspDeInit;
      break;
    default :
      /* update return status */
      status = HAL_ERROR;
      break;
    }
  }
  else
  {
    /* update return status */
    status = HAL_ERROR;
  }
  return status;
}
#endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */

whj123999's avatar
whj123999 已提交
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
/**
  * @}
  */

/** @defgroup DFSDM_Exported_Functions_Group2_Channel Channel operation functions
 *  @brief    Channel operation functions
 *
@verbatim
  ==============================================================================
                   ##### Channel operation functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Manage clock absence detector feature.
      (+) Manage short circuit detector feature.
      (+) Get analog watchdog value.
      (+) Modify offset value.
@endverbatim
  * @{
  */

/**
  * @brief  This function allows to start clock absence detection in polling mode.
  * @note   Same mode has to be used for all channels.
  * @note   If clock is not available on this channel during 5 seconds,
  *         clock absence detection will not be activated and function
  *         will return HAL_TIMEOUT error.
752
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
753 754 755 756 757 758 759
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  HAL_StatusTypeDef status = HAL_OK;
  uint32_t channel;
  uint32_t tickstart;
M
Mr.Tiger 已提交
760
  DFSDM_Filter_TypeDef *filter0Instance;
whj123999's avatar
whj123999 已提交
761 762 763

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
M
Mr.Tiger 已提交
764 765 766 767 768 769 770 771 772 773 774 775 776 777

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Get channel number from channel instance */
    channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);

    /* Get timeout */
    tickstart = HAL_GetTick();

    /* Clear clock absence flag */
M
Mr.Tiger 已提交
793
    while ((((filter0Instance->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) != 0U)
whj123999's avatar
whj123999 已提交
794
    {
M
Mr.Tiger 已提交
795
      filter0Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
whj123999's avatar
whj123999 已提交
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817

      /* Check the Timeout */
      if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT)
      {
        /* Set timeout status */
        status = HAL_TIMEOUT;
        break;
      }
    }

    if(status == HAL_OK)
    {
      /* Start clock absence detection */
      hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN;
    }
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to poll for the clock absence detection.
818 819
  * @param  hdfsdm_channel DFSDM channel handle.
  * @param  Timeout Timeout value in milliseconds.
whj123999's avatar
whj123999 已提交
820 821
  * @retval HAL status
  */
M
Mr.Tiger 已提交
822
HAL_StatusTypeDef HAL_DFSDM_ChannelPollForCkab(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
whj123999's avatar
whj123999 已提交
823 824 825 826
                                               uint32_t Timeout)
{
  uint32_t tickstart;
  uint32_t channel;
M
Mr.Tiger 已提交
827 828
  DFSDM_Filter_TypeDef *filter0Instance;

whj123999's avatar
whj123999 已提交
829 830 831
  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));

M
Mr.Tiger 已提交
832 833 834 835 836 837 838 839 840 841 842 843 844
#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
845 846 847 848 849 850 851 852 853 854
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    return HAL_ERROR;
  }
  else
  {
    /* Get channel number from channel instance */
    channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
M
Mr.Tiger 已提交
855

whj123999's avatar
whj123999 已提交
856 857 858 859
    /* Get timeout */
    tickstart = HAL_GetTick();

    /* Wait clock absence detection */
M
Mr.Tiger 已提交
860
    while ((((filter0Instance->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) == 0U)
whj123999's avatar
whj123999 已提交
861 862 863 864
    {
      /* Check the Timeout */
      if(Timeout != HAL_MAX_DELAY)
      {
865
        if(((HAL_GetTick()-tickstart) > Timeout) || (Timeout == 0U))
whj123999's avatar
whj123999 已提交
866 867 868 869 870 871
        {
          /* Return timeout status */
          return HAL_TIMEOUT;
        }
      }
    }
M
Mr.Tiger 已提交
872

whj123999's avatar
whj123999 已提交
873
    /* Clear clock absence detection flag */
M
Mr.Tiger 已提交
874 875
    filter0Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));

whj123999's avatar
whj123999 已提交
876 877 878 879 880 881 882
    /* Return function status */
    return HAL_OK;
  }
}

/**
  * @brief  This function allows to stop clock absence detection in polling mode.
883
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
884 885 886 887 888 889
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  HAL_StatusTypeDef status = HAL_OK;
  uint32_t channel;
M
Mr.Tiger 已提交
890
  DFSDM_Filter_TypeDef *filter0Instance;
whj123999's avatar
whj123999 已提交
891 892 893

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
M
Mr.Tiger 已提交
894 895 896 897 898 899 900 901 902 903 904 905 906 907

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
908 909 910 911 912 913 914 915 916 917
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Stop clock absence detection */
    hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN);
M
Mr.Tiger 已提交
918

whj123999's avatar
whj123999 已提交
919 920
    /* Clear clock absence flag */
    channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
M
Mr.Tiger 已提交
921
    filter0Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
whj123999's avatar
whj123999 已提交
922 923 924 925 926 927 928 929 930 931 932
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start clock absence detection in interrupt mode.
  * @note   Same mode has to be used for all channels.
  * @note   If clock is not available on this channel during 5 seconds,
  *         clock absence detection will not be activated and function
  *         will return HAL_TIMEOUT error.
933
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
934 935 936 937 938 939 940
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  HAL_StatusTypeDef status = HAL_OK;
  uint32_t channel;
  uint32_t tickstart;
M
Mr.Tiger 已提交
941
  DFSDM_Filter_TypeDef *filter0Instance;
whj123999's avatar
whj123999 已提交
942 943 944

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
M
Mr.Tiger 已提交
945 946 947 948 949 950 951 952 953 954 955 956 957 958

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Get channel number from channel instance */
    channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);

    /* Get timeout */
    tickstart = HAL_GetTick();

    /* Clear clock absence flag */
M
Mr.Tiger 已提交
974
    while ((((filter0Instance->FLTISR & DFSDM_FLTISR_CKABF) >> (DFSDM_FLTISR_CKABF_Pos + channel)) & 1U) != 0U)
whj123999's avatar
whj123999 已提交
975
    {
M
Mr.Tiger 已提交
976
      filter0Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
whj123999's avatar
whj123999 已提交
977 978 979 980 981 982 983 984 985 986 987 988 989

      /* Check the Timeout */
      if((HAL_GetTick()-tickstart) > DFSDM_CKAB_TIMEOUT)
      {
        /* Set timeout status */
        status = HAL_TIMEOUT;
        break;
      }
    }

    if(status == HAL_OK)
    {
      /* Activate clock absence detection interrupt */
M
Mr.Tiger 已提交
990
      filter0Instance->FLTCR2 |= DFSDM_FLTCR2_CKABIE;
whj123999's avatar
whj123999 已提交
991 992 993 994 995 996 997 998 999 1000

      /* Start clock absence detection */
      hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_CKABEN;
    }
  }
  /* Return function status */
  return status;
}

/**
M
Mr.Tiger 已提交
1001
  * @brief  Clock absence detection callback.
1002
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
1003 1004 1005 1006 1007 1008
  * @retval None
  */
__weak void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_channel);
M
Mr.Tiger 已提交
1009

whj123999's avatar
whj123999 已提交
1010 1011 1012 1013 1014 1015 1016 1017
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_DFSDM_ChannelCkabCallback could be implemented in the user file
   */
}

/**
  * @brief  This function allows to stop clock absence detection in interrupt mode.
  * @note   Interrupt will be disabled for all channels
1018
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
1019 1020 1021 1022 1023 1024
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  HAL_StatusTypeDef status = HAL_OK;
  uint32_t channel;
M
Mr.Tiger 已提交
1025
  DFSDM_Filter_TypeDef *filter0Instance;
whj123999's avatar
whj123999 已提交
1026 1027 1028

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
M
Mr.Tiger 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Stop clock absence detection */
    hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_CKABEN);
M
Mr.Tiger 已提交
1053

whj123999's avatar
whj123999 已提交
1054 1055
    /* Clear clock absence flag */
    channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
M
Mr.Tiger 已提交
1056
    filter0Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
whj123999's avatar
whj123999 已提交
1057 1058

    /* Disable clock absence detection interrupt */
M
Mr.Tiger 已提交
1059
    filter0Instance->FLTCR2 &= ~(DFSDM_FLTCR2_CKABIE);
whj123999's avatar
whj123999 已提交
1060 1061 1062 1063 1064 1065 1066 1067
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start short circuit detection in polling mode.
  * @note   Same mode has to be used for all channels
1068 1069
  * @param  hdfsdm_channel DFSDM channel handle.
  * @param  Threshold Short circuit detector threshold.
whj123999's avatar
whj123999 已提交
1070
  *         This parameter must be a number between Min_Data = 0 and Max_Data = 255.
1071
  * @param  BreakSignal Break signals assigned to short circuit event.
whj123999's avatar
whj123999 已提交
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
  *         This parameter can be a values combination of @ref DFSDM_BreakSignals.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
                                            uint32_t Threshold,
                                            uint32_t BreakSignal)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
  assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold));
  assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal));
M
Mr.Tiger 已提交
1085

whj123999's avatar
whj123999 已提交
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Configure threshold and break signals */
    hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT);
1096
    hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_Pos) | \
whj123999's avatar
whj123999 已提交
1097
                                         Threshold);
M
Mr.Tiger 已提交
1098

whj123999's avatar
whj123999 已提交
1099 1100 1101 1102 1103 1104 1105 1106 1107
    /* Start short circuit detection */
    hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to poll for the short circuit detection.
1108 1109
  * @param  hdfsdm_channel DFSDM channel handle.
  * @param  Timeout Timeout value in milliseconds.
whj123999's avatar
whj123999 已提交
1110 1111
  * @retval HAL status
  */
M
Mr.Tiger 已提交
1112
HAL_StatusTypeDef HAL_DFSDM_ChannelPollForScd(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
whj123999's avatar
whj123999 已提交
1113 1114 1115 1116
                                              uint32_t Timeout)
{
  uint32_t tickstart;
  uint32_t channel;
M
Mr.Tiger 已提交
1117 1118
  DFSDM_Filter_TypeDef *filter0Instance;

whj123999's avatar
whj123999 已提交
1119 1120 1121
  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));

M
Mr.Tiger 已提交
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    return HAL_ERROR;
  }
  else
  {
    /* Get channel number from channel instance */
    channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
M
Mr.Tiger 已提交
1145

whj123999's avatar
whj123999 已提交
1146 1147 1148 1149
    /* Get timeout */
    tickstart = HAL_GetTick();

    /* Wait short circuit detection */
M
Mr.Tiger 已提交
1150
    while (((filter0Instance->FLTISR & DFSDM_FLTISR_SCDF) >> (DFSDM_FLTISR_SCDF_Pos + channel)) == 0U)
whj123999's avatar
whj123999 已提交
1151 1152 1153 1154
    {
      /* Check the Timeout */
      if(Timeout != HAL_MAX_DELAY)
      {
1155
        if(((HAL_GetTick()-tickstart) > Timeout) || (Timeout == 0U))
whj123999's avatar
whj123999 已提交
1156 1157 1158 1159 1160 1161
        {
          /* Return timeout status */
          return HAL_TIMEOUT;
        }
      }
    }
M
Mr.Tiger 已提交
1162

whj123999's avatar
whj123999 已提交
1163
    /* Clear short circuit detection flag */
M
Mr.Tiger 已提交
1164 1165
    filter0Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRSCDF_Pos + channel));

whj123999's avatar
whj123999 已提交
1166 1167 1168 1169 1170 1171 1172
    /* Return function status */
    return HAL_OK;
  }
}

/**
  * @brief  This function allows to stop short circuit detection in polling mode.
1173
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
1174 1175 1176 1177 1178 1179
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  HAL_StatusTypeDef status = HAL_OK;
  uint32_t channel;
M
Mr.Tiger 已提交
1180
  DFSDM_Filter_TypeDef *filter0Instance;
whj123999's avatar
whj123999 已提交
1181 1182 1183

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
M
Mr.Tiger 已提交
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Stop short circuit detection */
    hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN);
M
Mr.Tiger 已提交
1208

whj123999's avatar
whj123999 已提交
1209 1210
    /* Clear short circuit detection flag */
    channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
M
Mr.Tiger 已提交
1211
    filter0Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
whj123999's avatar
whj123999 已提交
1212 1213 1214 1215 1216 1217 1218 1219
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start short circuit detection in interrupt mode.
  * @note   Same mode has to be used for all channels
1220 1221
  * @param  hdfsdm_channel DFSDM channel handle.
  * @param  Threshold Short circuit detector threshold.
whj123999's avatar
whj123999 已提交
1222
  *         This parameter must be a number between Min_Data = 0 and Max_Data = 255.
1223
  * @param  BreakSignal Break signals assigned to short circuit event.
whj123999's avatar
whj123999 已提交
1224 1225 1226 1227 1228 1229 1230 1231
  *         This parameter can be a values combination of @ref DFSDM_BreakSignals.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
                                               uint32_t Threshold,
                                               uint32_t BreakSignal)
{
  HAL_StatusTypeDef status = HAL_OK;
M
Mr.Tiger 已提交
1232
  DFSDM_Filter_TypeDef *filter0Instance;
whj123999's avatar
whj123999 已提交
1233 1234 1235 1236 1237

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
  assert_param(IS_DFSDM_CHANNEL_SCD_THRESHOLD(Threshold));
  assert_param(IS_DFSDM_BREAK_SIGNALS(BreakSignal));
M
Mr.Tiger 已提交
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
1252 1253 1254 1255 1256 1257 1258 1259 1260
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Activate short circuit detection interrupt */
M
Mr.Tiger 已提交
1261
    filter0Instance->FLTCR2 |= DFSDM_FLTCR2_SCDIE;
whj123999's avatar
whj123999 已提交
1262 1263 1264

    /* Configure threshold and break signals */
    hdfsdm_channel->Instance->CHAWSCDR &= ~(DFSDM_CHAWSCDR_BKSCD | DFSDM_CHAWSCDR_SCDT);
1265
    hdfsdm_channel->Instance->CHAWSCDR |= ((BreakSignal << DFSDM_CHAWSCDR_BKSCD_Pos) | \
whj123999's avatar
whj123999 已提交
1266
                                         Threshold);
M
Mr.Tiger 已提交
1267

whj123999's avatar
whj123999 已提交
1268 1269 1270 1271 1272 1273 1274 1275
    /* Start short circuit detection */
    hdfsdm_channel->Instance->CHCFGR1 |= DFSDM_CHCFGR1_SCDEN;
  }
  /* Return function status */
  return status;
}

/**
M
Mr.Tiger 已提交
1276
  * @brief  Short circuit detection callback.
1277
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
1278 1279 1280 1281 1282 1283
  * @retval None
  */
__weak void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_channel);
M
Mr.Tiger 已提交
1284

whj123999's avatar
whj123999 已提交
1285 1286 1287 1288 1289 1290 1291 1292
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_DFSDM_ChannelScdCallback could be implemented in the user file
   */
}

/**
  * @brief  This function allows to stop short circuit detection in interrupt mode.
  * @note   Interrupt will be disabled for all channels
1293
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
1294 1295 1296 1297 1298 1299
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  HAL_StatusTypeDef status = HAL_OK;
  uint32_t channel;
M
Mr.Tiger 已提交
1300
  DFSDM_Filter_TypeDef *filter0Instance;
whj123999's avatar
whj123999 已提交
1301 1302 1303

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
M
Mr.Tiger 已提交
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Stop short circuit detection */
    hdfsdm_channel->Instance->CHCFGR1 &= ~(DFSDM_CHCFGR1_SCDEN);
M
Mr.Tiger 已提交
1328

whj123999's avatar
whj123999 已提交
1329 1330
    /* Clear short circuit detection flag */
    channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->Instance);
M
Mr.Tiger 已提交
1331
    filter0Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
whj123999's avatar
whj123999 已提交
1332 1333

    /* Disable short circuit detection interrupt */
M
Mr.Tiger 已提交
1334
    filter0Instance->FLTCR2 &= ~(DFSDM_FLTCR2_SCDIE);
whj123999's avatar
whj123999 已提交
1335 1336 1337 1338 1339 1340 1341
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to get channel analog watchdog value.
1342
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
1343 1344 1345 1346 1347 1348 1349 1350 1351
  * @retval Channel analog watchdog value.
  */
int16_t HAL_DFSDM_ChannelGetAwdValue(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  return (int16_t) hdfsdm_channel->Instance->CHWDATAR;
}

/**
  * @brief  This function allows to modify channel offset value.
1352 1353
  * @param  hdfsdm_channel DFSDM channel handle.
  * @param  Offset DFSDM channel offset.
whj123999's avatar
whj123999 已提交
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
  *         This parameter must be a number between Min_Data = -8388608 and Max_Data = 8388607.
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_ChannelModifyOffset(DFSDM_Channel_HandleTypeDef *hdfsdm_channel,
                                                int32_t Offset)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_CHANNEL_ALL_INSTANCE(hdfsdm_channel->Instance));
  assert_param(IS_DFSDM_CHANNEL_OFFSET(Offset));
M
Mr.Tiger 已提交
1365

whj123999's avatar
whj123999 已提交
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
  /* Check DFSDM channel state */
  if(hdfsdm_channel->State != HAL_DFSDM_CHANNEL_STATE_READY)
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Modify channel offset */
    hdfsdm_channel->Instance->CHCFGR2 &= ~(DFSDM_CHCFGR2_OFFSET);
1376
    hdfsdm_channel->Instance->CHCFGR2 |= ((uint32_t) Offset << DFSDM_CHCFGR2_OFFSET_Pos);
whj123999's avatar
whj123999 已提交
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
  }
  /* Return function status */
  return status;
}

/**
  * @}
  */

/** @defgroup DFSDM_Exported_Functions_Group3_Channel Channel state function
 *  @brief    Channel state function
 *
@verbatim
  ==============================================================================
                   ##### Channel state function #####
  ==============================================================================
    [..]  This section provides function allowing to:
      (+) Get channel handle state.
@endverbatim
  * @{
  */

/**
  * @brief  This function allows to get the current DFSDM channel handle state.
1401
  * @param  hdfsdm_channel DFSDM channel handle.
whj123999's avatar
whj123999 已提交
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
  * @retval DFSDM channel state.
  */
HAL_DFSDM_Channel_StateTypeDef HAL_DFSDM_ChannelGetState(DFSDM_Channel_HandleTypeDef *hdfsdm_channel)
{
  /* Return DFSDM channel handle state */
  return hdfsdm_channel->State;
}

/**
  * @}
  */

/** @defgroup DFSDM_Exported_Functions_Group1_Filter Filter initialization and de-initialization functions
M
Mr.Tiger 已提交
1415
 *  @brief    Filter initialization and de-initialization functions
whj123999's avatar
whj123999 已提交
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
 *
@verbatim
  ==============================================================================
        ##### Filter initialization and de-initialization functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Initialize the DFSDM filter.
      (+) De-initialize the DFSDM filter.
@endverbatim
  * @{
  */

/**
  * @brief  Initialize the DFSDM filter according to the specified parameters
  *         in the DFSDM_FilterInitTypeDef structure and initialize the associated handle.
1431
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
1432 1433 1434 1435
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_FilterInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
M
Mr.Tiger 已提交
1436 1437
  const DFSDM_Filter_TypeDef *filter0Instance;

whj123999's avatar
whj123999 已提交
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
  /* Check DFSDM Channel handle */
  if(hdfsdm_filter == NULL)
  {
    return HAL_ERROR;
  }

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
  assert_param(IS_DFSDM_FILTER_REG_TRIGGER(hdfsdm_filter->Init.RegularParam.Trigger));
  assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.FastMode));
  assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.RegularParam.DmaMode));
  assert_param(IS_DFSDM_FILTER_INJ_TRIGGER(hdfsdm_filter->Init.InjectedParam.Trigger));
  assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.ScanMode));
  assert_param(IS_FUNCTIONAL_STATE(hdfsdm_filter->Init.InjectedParam.DmaMode));
  assert_param(IS_DFSDM_FILTER_SINC_ORDER(hdfsdm_filter->Init.FilterParam.SincOrder));
  assert_param(IS_DFSDM_FILTER_OVS_RATIO(hdfsdm_filter->Init.FilterParam.Oversampling));
  assert_param(IS_DFSDM_FILTER_INTEGRATOR_OVS_RATIO(hdfsdm_filter->Init.FilterParam.IntOversampling));

M
Mr.Tiger 已提交
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_FILTER_INSTANCE(hdfsdm_filter->Instance))
  {
    filter0Instance = DFSDM1_Filter0;
  }
  else
  {
    filter0Instance = DFSDM2_Filter0;
  }
#else /* DFSDM2_Channel0 */
  filter0Instance = DFSDM1_Filter0;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
1469
  /* Check parameters compatibility */
M
Mr.Tiger 已提交
1470 1471 1472
  if ((hdfsdm_filter->Instance == filter0Instance) &&
      ((hdfsdm_filter->Init.RegularParam.Trigger  == DFSDM_FILTER_SYNC_TRIGGER) ||
       (hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_SYNC_TRIGGER)))
whj123999's avatar
whj123999 已提交
1473 1474 1475 1476 1477 1478 1479 1480 1481
  {
    return HAL_ERROR;
  }

  /* Initialize DFSDM filter variables with default values */
  hdfsdm_filter->RegularContMode     = DFSDM_CONTINUOUS_CONV_OFF;
  hdfsdm_filter->InjectedChannelsNbr = 1;
  hdfsdm_filter->InjConvRemaining    = 1;
  hdfsdm_filter->ErrorCode           = DFSDM_FILTER_ERROR_NONE;
M
Mr.Tiger 已提交
1482

1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  /* Reset callback pointers to the weak predefined callbacks */
  hdfsdm_filter->AwdCallback             = HAL_DFSDM_FilterAwdCallback;
  hdfsdm_filter->RegConvCpltCallback     = HAL_DFSDM_FilterRegConvCpltCallback;
  hdfsdm_filter->RegConvHalfCpltCallback = HAL_DFSDM_FilterRegConvHalfCpltCallback;
  hdfsdm_filter->InjConvCpltCallback     = HAL_DFSDM_FilterInjConvCpltCallback;
  hdfsdm_filter->InjConvHalfCpltCallback = HAL_DFSDM_FilterInjConvHalfCpltCallback;
  hdfsdm_filter->ErrorCallback           = HAL_DFSDM_FilterErrorCallback;

  /* Call MSP init function */
  if(hdfsdm_filter->MspInitCallback == NULL)
  {
    hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
  }
  hdfsdm_filter->MspInitCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
1499 1500
  /* Call MSP init function */
  HAL_DFSDM_FilterMspInit(hdfsdm_filter);
1501
#endif
whj123999's avatar
whj123999 已提交
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548

  /* Set regular parameters */
  hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC);
  if(hdfsdm_filter->Init.RegularParam.FastMode == ENABLE)
  {
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_FAST;
  }
  else
  {
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_FAST);
  }

  if(hdfsdm_filter->Init.RegularParam.DmaMode == ENABLE)
  {
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RDMAEN;
  }
  else
  {
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RDMAEN);
  }

  /* Set injected parameters */
  hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC | DFSDM_FLTCR1_JEXTEN | DFSDM_FLTCR1_JEXTSEL);
  if(hdfsdm_filter->Init.InjectedParam.Trigger == DFSDM_FILTER_EXT_TRIGGER)
  {
    assert_param(IS_DFSDM_FILTER_EXT_TRIG(hdfsdm_filter->Init.InjectedParam.ExtTrigger));
    assert_param(IS_DFSDM_FILTER_EXT_TRIG_EDGE(hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge));
    hdfsdm_filter->Instance->FLTCR1 |= (hdfsdm_filter->Init.InjectedParam.ExtTrigger);
  }

  if(hdfsdm_filter->Init.InjectedParam.ScanMode == ENABLE)
  {
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSCAN;
  }
  else
  {
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSCAN);
  }

  if(hdfsdm_filter->Init.InjectedParam.DmaMode == ENABLE)
  {
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JDMAEN;
  }
  else
  {
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JDMAEN);
  }
M
Mr.Tiger 已提交
1549

whj123999's avatar
whj123999 已提交
1550 1551 1552
  /* Set filter parameters */
  hdfsdm_filter->Instance->FLTFCR &= ~(DFSDM_FLTFCR_FORD | DFSDM_FLTFCR_FOSR | DFSDM_FLTFCR_IOSR);
  hdfsdm_filter->Instance->FLTFCR |= (hdfsdm_filter->Init.FilterParam.SincOrder |
M
Mr.Tiger 已提交
1553 1554
                                      ((hdfsdm_filter->Init.FilterParam.Oversampling - 1U) << DFSDM_FLTFCR_FOSR_Pos) |
                                      (hdfsdm_filter->Init.FilterParam.IntOversampling - 1U));
whj123999's avatar
whj123999 已提交
1555 1556 1557 1558 1559 1560

  /* Store regular and injected triggers and injected scan mode*/
  hdfsdm_filter->RegularTrigger   = hdfsdm_filter->Init.RegularParam.Trigger;
  hdfsdm_filter->InjectedTrigger  = hdfsdm_filter->Init.InjectedParam.Trigger;
  hdfsdm_filter->ExtTriggerEdge   = hdfsdm_filter->Init.InjectedParam.ExtTriggerEdge;
  hdfsdm_filter->InjectedScanMode = hdfsdm_filter->Init.InjectedParam.ScanMode;
M
Mr.Tiger 已提交
1561

whj123999's avatar
whj123999 已提交
1562 1563 1564 1565 1566
  /* Enable DFSDM filter */
  hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;

  /* Set DFSDM filter to ready state */
  hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_READY;
M
Mr.Tiger 已提交
1567

whj123999's avatar
whj123999 已提交
1568 1569 1570 1571 1572
  return HAL_OK;
}

/**
  * @brief  De-initializes the DFSDM filter.
1573
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_FilterDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Check DFSDM filter handle */
  if(hdfsdm_filter == NULL)
  {
    return HAL_ERROR;
  }

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
M
Mr.Tiger 已提交
1586

whj123999's avatar
whj123999 已提交
1587 1588
  /* Disable the DFSDM filter */
  hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
M
Mr.Tiger 已提交
1589

whj123999's avatar
whj123999 已提交
1590
  /* Call MSP deinit function */
1591 1592 1593 1594 1595 1596 1597
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  if(hdfsdm_filter->MspDeInitCallback == NULL)
  {
    hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
  }
  hdfsdm_filter->MspDeInitCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
1598
  HAL_DFSDM_FilterMspDeInit(hdfsdm_filter);
1599
#endif
whj123999's avatar
whj123999 已提交
1600 1601 1602 1603 1604 1605 1606 1607 1608

  /* Set DFSDM filter in reset state */
  hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_RESET;

  return HAL_OK;
}

/**
  * @brief  Initializes the DFSDM filter MSP.
1609
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
1610 1611 1612 1613 1614 1615
  * @retval None
  */
__weak void HAL_DFSDM_FilterMspInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_filter);
M
Mr.Tiger 已提交
1616

whj123999's avatar
whj123999 已提交
1617 1618 1619 1620 1621 1622 1623
  /* NOTE : This function should not be modified, when the function is needed,
            the HAL_DFSDM_FilterMspInit could be implemented in the user file.
   */
}

/**
  * @brief  De-initializes the DFSDM filter MSP.
1624
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
1625 1626 1627 1628 1629 1630
  * @retval None
  */
__weak void HAL_DFSDM_FilterMspDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_filter);
M
Mr.Tiger 已提交
1631

whj123999's avatar
whj123999 已提交
1632 1633 1634 1635 1636
  /* NOTE : This function should not be modified, when the function is needed,
            the HAL_DFSDM_FilterMspDeInit could be implemented in the user file.
   */
}

1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
/**
  * @brief  Register a user DFSDM filter callback
  *         to be used instead of the weak predefined callback.
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  CallbackID ID of the callback to be registered.
  *         This parameter can be one of the following values:
  *           @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID.
  * @param  pCallback pointer to the callback function.
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_Filter_RegisterCallback(DFSDM_Filter_HandleTypeDef        *hdfsdm_filter,
                                                    HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID,
                                                    pDFSDM_Filter_CallbackTypeDef      pCallback)
{
  HAL_StatusTypeDef status = HAL_OK;

  if(pCallback == NULL)
  {
    /* update the error code */
    hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
    /* update return status */
    status = HAL_ERROR;
  }
  else
  {
    if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
    {
      switch (CallbackID)
      {
M
Mr.Tiger 已提交
1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
        case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID :
          hdfsdm_filter->RegConvCpltCallback = pCallback;
          break;
        case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID :
          hdfsdm_filter->RegConvHalfCpltCallback = pCallback;
          break;
        case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID :
          hdfsdm_filter->InjConvCpltCallback = pCallback;
          break;
        case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID :
          hdfsdm_filter->InjConvHalfCpltCallback = pCallback;
          break;
        case HAL_DFSDM_FILTER_ERROR_CB_ID :
          hdfsdm_filter->ErrorCallback = pCallback;
          break;
        case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
          hdfsdm_filter->MspInitCallback = pCallback;
          break;
        case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
          hdfsdm_filter->MspDeInitCallback = pCallback;
          break;
        default :
          /* update the error code */
          hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
          /* update return status */
          status = HAL_ERROR;
          break;
1700 1701 1702 1703 1704 1705
      }
    }
    else if(HAL_DFSDM_FILTER_STATE_RESET == hdfsdm_filter->State)
    {
      switch (CallbackID)
      {
M
Mr.Tiger 已提交
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
        case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
          hdfsdm_filter->MspInitCallback = pCallback;
          break;
        case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
          hdfsdm_filter->MspDeInitCallback = pCallback;
          break;
        default :
          /* update the error code */
          hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
          /* update return status */
          status = HAL_ERROR;
          break;
1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
      }
    }
    else
    {
      /* update the error code */
      hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
      /* update return status */
      status = HAL_ERROR;
    }
  }
  return status;
}

/**
  * @brief  Unregister a user DFSDM filter callback.
  *         DFSDM filter callback is redirected to the weak predefined callback.
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  CallbackID ID of the callback to be unregistered.
  *         This parameter can be one of the following values:
  *           @arg @ref HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID regular conversion complete callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID half regular conversion complete callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID injected conversion complete callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID half injected conversion complete callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_ERROR_CB_ID error callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_MSPINIT_CB_ID MSP init callback ID.
  *           @arg @ref HAL_DFSDM_FILTER_MSPDEINIT_CB_ID MSP de-init callback ID.
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_Filter_UnRegisterCallback(DFSDM_Filter_HandleTypeDef        *hdfsdm_filter,
                                                      HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID)
{
  HAL_StatusTypeDef status = HAL_OK;

  if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
  {
    switch (CallbackID)
    {
M
Mr.Tiger 已提交
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
      case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID :
        hdfsdm_filter->RegConvCpltCallback = HAL_DFSDM_FilterRegConvCpltCallback;
        break;
      case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID :
        hdfsdm_filter->RegConvHalfCpltCallback = HAL_DFSDM_FilterRegConvHalfCpltCallback;
        break;
      case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID :
        hdfsdm_filter->InjConvCpltCallback = HAL_DFSDM_FilterInjConvCpltCallback;
        break;
      case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID :
        hdfsdm_filter->InjConvHalfCpltCallback = HAL_DFSDM_FilterInjConvHalfCpltCallback;
        break;
      case HAL_DFSDM_FILTER_ERROR_CB_ID :
        hdfsdm_filter->ErrorCallback = HAL_DFSDM_FilterErrorCallback;
        break;
      case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
        hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
        break;
      case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
        hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
        break;
      default :
        /* update the error code */
        hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
        /* update return status */
        status = HAL_ERROR;
        break;
1782 1783 1784 1785 1786 1787
    }
  }
  else if(HAL_DFSDM_FILTER_STATE_RESET == hdfsdm_filter->State)
  {
    switch (CallbackID)
    {
M
Mr.Tiger 已提交
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799
      case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
        hdfsdm_filter->MspInitCallback = HAL_DFSDM_FilterMspInit;
        break;
      case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
        hdfsdm_filter->MspDeInitCallback = HAL_DFSDM_FilterMspDeInit;
        break;
      default :
        /* update the error code */
        hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
        /* update return status */
        status = HAL_ERROR;
        break;
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872
    }
  }
  else
  {
    /* update the error code */
    hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
    /* update return status */
    status = HAL_ERROR;
  }
  return status;
}

/**
  * @brief  Register a user DFSDM filter analog watchdog callback
  *         to be used instead of the weak predefined callback.
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  pCallback pointer to the DFSDM filter analog watchdog callback function.
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_Filter_RegisterAwdCallback(DFSDM_Filter_HandleTypeDef      *hdfsdm_filter,
                                                       pDFSDM_Filter_AwdCallbackTypeDef pCallback)
{
  HAL_StatusTypeDef status = HAL_OK;

  if(pCallback == NULL)
  {
    /* update the error code */
    hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
    /* update return status */
    status = HAL_ERROR;
  }
  else
  {
    if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
    {
      hdfsdm_filter->AwdCallback = pCallback;
    }
    else
    {
      /* update the error code */
      hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
      /* update return status */
      status = HAL_ERROR;
    }
  }
  return status;
}

/**
  * @brief  Unregister a user DFSDM filter analog watchdog callback.
  *         DFSDM filter AWD callback is redirected to the weak predefined callback.
  * @param  hdfsdm_filter DFSDM filter handle.
  * @retval HAL status.
  */
HAL_StatusTypeDef HAL_DFSDM_Filter_UnRegisterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  if(HAL_DFSDM_FILTER_STATE_READY == hdfsdm_filter->State)
  {
    hdfsdm_filter->AwdCallback = HAL_DFSDM_FilterAwdCallback;
  }
  else
  {
    /* update the error code */
    hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
    /* update return status */
    status = HAL_ERROR;
  }
  return status;
}
#endif /* USE_HAL_DFSDM_REGISTER_CALLBACKS */

whj123999's avatar
whj123999 已提交
1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893
/**
  * @}
  */

/** @defgroup DFSDM_Exported_Functions_Group2_Filter Filter control functions
 *  @brief    Filter control functions
 *
@verbatim
  ==============================================================================
                    ##### Filter control functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Select channel and enable/disable continuous mode for regular conversion.
      (+) Select channels for injected conversion.
@endverbatim
  * @{
  */

/**
  * @brief  This function allows to select channel and to enable/disable
  *         continuous mode for regular conversion.
1894 1895
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Channel Channel for regular conversion.
whj123999's avatar
whj123999 已提交
1896
  *         This parameter can be a value of @ref DFSDM_Channel_Selection.
1897
  * @param  ContinuousMode Enable/disable continuous mode for regular conversion.
whj123999's avatar
whj123999 已提交
1898 1899 1900 1901 1902 1903 1904 1905
  *         This parameter can be a value of @ref DFSDM_ContinuousMode.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterConfigRegChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                   uint32_t                    Channel,
                                                   uint32_t                    ContinuousMode)
{
  HAL_StatusTypeDef status = HAL_OK;
M
Mr.Tiger 已提交
1906

whj123999's avatar
whj123999 已提交
1907 1908 1909 1910
  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
  assert_param(IS_DFSDM_REGULAR_CHANNEL(Channel));
  assert_param(IS_DFSDM_CONTINUOUS_MODE(ContinuousMode));
M
Mr.Tiger 已提交
1911

whj123999's avatar
whj123999 已提交
1912
  /* Check DFSDM filter state */
M
Mr.Tiger 已提交
1913
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) &&
whj123999's avatar
whj123999 已提交
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR))
  {
    /* Configure channel and continuous mode for regular conversion */
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RCH | DFSDM_FLTCR1_RCONT);
    if(ContinuousMode == DFSDM_CONTINUOUS_CONV_ON)
    {
      hdfsdm_filter->Instance->FLTCR1 |= (uint32_t) (((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET) |
                                                     DFSDM_FLTCR1_RCONT);
    }
    else
    {
      hdfsdm_filter->Instance->FLTCR1 |= (uint32_t) ((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET);
    }
    /* Store continuous mode information */
    hdfsdm_filter->RegularContMode = ContinuousMode;
M
Mr.Tiger 已提交
1929
  }
whj123999's avatar
whj123999 已提交
1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940
  else
  {
    status = HAL_ERROR;
  }

  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to select channels for injected conversion.
1941 1942
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Channel Channels for injected conversion.
whj123999's avatar
whj123999 已提交
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
  *         This parameter can be a values combination of @ref DFSDM_Channel_Selection.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterConfigInjChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                   uint32_t                    Channel)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
  assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel));
M
Mr.Tiger 已提交
1954

whj123999's avatar
whj123999 已提交
1955
  /* Check DFSDM filter state */
M
Mr.Tiger 已提交
1956
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_RESET) &&
whj123999's avatar
whj123999 已提交
1957 1958 1959 1960 1961 1962 1963 1964
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_ERROR))
  {
    /* Configure channel for injected conversion */
    hdfsdm_filter->Instance->FLTJCHGR = (uint32_t) (Channel & DFSDM_LSB_MASK);
    /* Store number of injected channels */
    hdfsdm_filter->InjectedChannelsNbr = DFSDM_GetInjChannelsNbr(Channel);
    /* Update number of injected channels remaining */
    hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
M
Mr.Tiger 已提交
1965
                                       hdfsdm_filter->InjectedChannelsNbr : 1U;
whj123999's avatar
whj123999 已提交
1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @}
  */

/** @defgroup DFSDM_Exported_Functions_Group3_Filter Filter operation functions
 *  @brief    Filter operation functions
 *
@verbatim
  ==============================================================================
                    ##### Filter operation functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Start conversion of regular/injected channel.
      (+) Poll for the end of regular/injected conversion.
      (+) Stop conversion of regular/injected channel.
      (+) Start conversion of regular/injected channel and enable interrupt.
      (+) Call the callback functions at the end of regular/injected conversions.
      (+) Stop conversion of regular/injected channel and disable interrupt.
      (+) Start conversion of regular/injected channel and enable DMA transfer.
      (+) Stop conversion of regular/injected channel and disable DMA transfer.
      (+) Start analog watchdog and enable interrupt.
      (+) Call the callback function when analog watchdog occurs.
      (+) Stop analog watchdog and disable interrupt.
      (+) Start extreme detector.
      (+) Stop extreme detector.
      (+) Get result of regular channel conversion.
      (+) Get result of injected channel conversion.
      (+) Get extreme detector maximum and minimum values.
      (+) Get conversion time.
      (+) Handle DFSDM interrupt request.
@endverbatim
  * @{
  */

/**
  * @brief  This function allows to start regular conversion in polling mode.
M
Mr.Tiger 已提交
2011
  * @note   This function should be called only when DFSDM filter instance is
whj123999's avatar
whj123999 已提交
2012
  *         in idle state or if injected conversion is ongoing.
2013
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
     (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
  {
    /* Start regular conversion */
    DFSDM_RegConvStart(hdfsdm_filter);
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to poll for the end of regular conversion.
  * @note   This function should be called only if regular conversion is ongoing.
2041 2042
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Timeout Timeout value in milliseconds.
whj123999's avatar
whj123999 已提交
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterPollForRegConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                       uint32_t                    Timeout)
{
  uint32_t tickstart;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
  {
    /* Return error status */
    return HAL_ERROR;
  }
  else
  {
    /* Get timeout */
M
Mr.Tiger 已提交
2063
    tickstart = HAL_GetTick();
whj123999's avatar
whj123999 已提交
2064 2065 2066 2067 2068 2069 2070

    /* Wait end of regular conversion */
    while((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_REOCF) != DFSDM_FLTISR_REOCF)
    {
      /* Check the Timeout */
      if(Timeout != HAL_MAX_DELAY)
      {
M
Mr.Tiger 已提交
2071
        if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
whj123999's avatar
whj123999 已提交
2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082
        {
          /* Return timeout status */
          return HAL_TIMEOUT;
        }
      }
    }
    /* Check if overrun occurs */
    if((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_ROVRF) == DFSDM_FLTISR_ROVRF)
    {
      /* Update error code and call error callback */
      hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN;
2083 2084 2085
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
      hdfsdm_filter->ErrorCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
2086
      HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
2087
#endif
whj123999's avatar
whj123999 已提交
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106

      /* Clear regular overrun flag */
      hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF;
    }
    /* Update DFSDM filter state only if not continuous conversion and SW trigger */
    if((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
       (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
    {
      hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
                             HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
    }
    /* Return function status */
    return HAL_OK;
  }
}

/**
  * @brief  This function allows to stop regular conversion in polling mode.
  * @note   This function should be called only if regular conversion is ongoing.
2107
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Stop regular conversion */
    DFSDM_RegConvStop(hdfsdm_filter);
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start regular conversion in interrupt mode.
M
Mr.Tiger 已提交
2135
  * @note   This function should be called only when DFSDM filter instance is
whj123999's avatar
whj123999 已提交
2136
  *         in idle state or if injected conversion is ongoing.
2137
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
     (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
  {
    /* Enable interrupts for regular conversions */
    hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE);
M
Mr.Tiger 已提交
2153

whj123999's avatar
whj123999 已提交
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
    /* Start regular conversion */
    DFSDM_RegConvStart(hdfsdm_filter);
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to stop regular conversion in interrupt mode.
  * @note   This function should be called only if regular conversion is ongoing.
2168
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Disable interrupts for regular conversions */
    hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE | DFSDM_FLTCR2_ROVRIE);
M
Mr.Tiger 已提交
2189

whj123999's avatar
whj123999 已提交
2190 2191 2192 2193 2194 2195 2196 2197 2198
    /* Stop regular conversion */
    DFSDM_RegConvStop(hdfsdm_filter);
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start regular conversion in DMA mode.
M
Mr.Tiger 已提交
2199
  * @note   This function should be called only when DFSDM filter instance is
whj123999's avatar
whj123999 已提交
2200 2201 2202 2203
  *         in idle state or if injected conversion is ongoing.
  *         Please note that data on buffer will contain signed regular conversion
  *         value on 24 most significant bits and corresponding channel on 3 least
  *         significant bits.
2204 2205 2206
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  pData The destination buffer address.
  * @param  Length The length of data to be transferred from DFSDM filter to memory.
whj123999's avatar
whj123999 已提交
2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                   int32_t                    *pData,
                                                   uint32_t                    Length)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check destination address and length */
2219
  if((pData == NULL) || (Length == 0U))
whj123999's avatar
whj123999 已提交
2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231
  {
    status = HAL_ERROR;
  }
  /* Check that DMA is enabled for regular conversion */
  else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN)
  {
    status = HAL_ERROR;
  }
  /* Check parameters compatibility */
  else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
          (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
          (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \
2232
          (Length != 1U))
whj123999's avatar
whj123999 已提交
2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250
  {
    status = HAL_ERROR;
  }
  else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
          (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
          (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR))
  {
    status = HAL_ERROR;
  }
  /* Check DFSDM filter state */
  else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
          (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
  {
    /* Set callbacks on DMA handler */
    hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt;
    hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError;
    hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ?\
                                                   DFSDM_DMARegularHalfConvCplt : NULL;
M
Mr.Tiger 已提交
2251

whj123999's avatar
whj123999 已提交
2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276
    /* Start DMA in interrupt mode */
    if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)&hdfsdm_filter->Instance->FLTRDATAR, \
                        (uint32_t) pData, Length) != HAL_OK)
    {
      /* Set DFSDM filter in error state */
      hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
      status = HAL_ERROR;
    }
    else
    {
      /* Start regular conversion */
      DFSDM_RegConvStart(hdfsdm_filter);
    }
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start regular conversion in DMA mode and to get
  *         only the 16 most significant bits of conversion.
M
Mr.Tiger 已提交
2277
  * @note   This function should be called only when DFSDM filter instance is
whj123999's avatar
whj123999 已提交
2278 2279 2280
  *         in idle state or if injected conversion is ongoing.
  *         Please note that data on buffer will contain signed 16 most significant
  *         bits of regular conversion.
2281 2282 2283
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  pData The destination buffer address.
  * @param  Length The length of data to be transferred from DFSDM filter to memory.
whj123999's avatar
whj123999 已提交
2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterRegularMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                      int16_t                    *pData,
                                                      uint32_t                    Length)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check destination address and length */
2296
  if((pData == NULL) || (Length == 0U))
whj123999's avatar
whj123999 已提交
2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308
  {
    status = HAL_ERROR;
  }
  /* Check that DMA is enabled for regular conversion */
  else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_RDMAEN) != DFSDM_FLTCR1_RDMAEN)
  {
    status = HAL_ERROR;
  }
  /* Check parameters compatibility */
  else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
          (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
          (hdfsdm_filter->hdmaReg->Init.Mode == DMA_NORMAL) && \
2309
          (Length != 1U))
whj123999's avatar
whj123999 已提交
2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327
  {
    status = HAL_ERROR;
  }
  else if((hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER) && \
          (hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
          (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR))
  {
    status = HAL_ERROR;
  }
  /* Check DFSDM filter state */
  else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
          (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ))
  {
    /* Set callbacks on DMA handler */
    hdfsdm_filter->hdmaReg->XferCpltCallback = DFSDM_DMARegularConvCplt;
    hdfsdm_filter->hdmaReg->XferErrorCallback = DFSDM_DMAError;
    hdfsdm_filter->hdmaReg->XferHalfCpltCallback = (hdfsdm_filter->hdmaReg->Init.Mode == DMA_CIRCULAR) ?\
                                                   DFSDM_DMARegularHalfConvCplt : NULL;
M
Mr.Tiger 已提交
2328

whj123999's avatar
whj123999 已提交
2329
    /* Start DMA in interrupt mode */
2330
    if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaReg, (uint32_t)(&hdfsdm_filter->Instance->FLTRDATAR) + 2U, \
whj123999's avatar
whj123999 已提交
2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353
                        (uint32_t) pData, Length) != HAL_OK)
    {
      /* Set DFSDM filter in error state */
      hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
      status = HAL_ERROR;
    }
    else
    {
      /* Start regular conversion */
      DFSDM_RegConvStart(hdfsdm_filter);
    }
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to stop regular conversion in DMA mode.
  * @note   This function should be called only if regular conversion is ongoing.
2354
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG) && \
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Stop current DMA transfer */
    if(HAL_DMA_Abort(hdfsdm_filter->hdmaReg) != HAL_OK)
    {
      /* Set DFSDM filter in error state */
      hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
      status = HAL_ERROR;
    }
    else
    {
      /* Stop regular conversion */
      DFSDM_RegConvStop(hdfsdm_filter);
    }
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to get regular conversion value.
2392 2393
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Channel Corresponding channel of regular conversion.
whj123999's avatar
whj123999 已提交
2394 2395 2396 2397 2398
  * @retval Regular conversion value
  */
int32_t HAL_DFSDM_FilterGetRegularValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                        uint32_t                   *Channel)
{
2399 2400
  uint32_t reg;
  int32_t  value;
M
Mr.Tiger 已提交
2401

whj123999's avatar
whj123999 已提交
2402 2403
  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2404
  assert_param(Channel != (void *)0);
whj123999's avatar
whj123999 已提交
2405 2406 2407

  /* Get value of data register for regular channel */
  reg = hdfsdm_filter->Instance->FLTRDATAR;
M
Mr.Tiger 已提交
2408

whj123999's avatar
whj123999 已提交
2409 2410
  /* Extract channel and regular conversion value */
  *Channel = (reg & DFSDM_FLTRDATAR_RDATACH);
2411 2412 2413 2414
  /* Regular conversion value is a signed value located on 24 MSB of register */
  /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
  reg &= DFSDM_FLTRDATAR_RDATA;
  value = ((int32_t)reg) / 256;
whj123999's avatar
whj123999 已提交
2415 2416 2417 2418 2419 2420 2421

  /* return regular conversion value */
  return value;
}

/**
  * @brief  This function allows to start injected conversion in polling mode.
M
Mr.Tiger 已提交
2422
  * @note   This function should be called only when DFSDM filter instance is
whj123999's avatar
whj123999 已提交
2423
  *         in idle state or if regular conversion is ongoing.
2424
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
     (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
  {
    /* Start injected conversion */
    DFSDM_InjConvStart(hdfsdm_filter);
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to poll for the end of injected conversion.
  * @note   This function should be called only if injected conversion is ongoing.
2452 2453
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Timeout Timeout value in milliseconds.
whj123999's avatar
whj123999 已提交
2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterPollForInjConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                       uint32_t                    Timeout)
{
  uint32_t tickstart;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
  {
    /* Return error status */
    return HAL_ERROR;
  }
  else
  {
    /* Get timeout */
M
Mr.Tiger 已提交
2474
    tickstart = HAL_GetTick();
whj123999's avatar
whj123999 已提交
2475 2476 2477 2478 2479 2480 2481

    /* Wait end of injected conversions */
    while((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JEOCF) != DFSDM_FLTISR_JEOCF)
    {
      /* Check the Timeout */
      if(Timeout != HAL_MAX_DELAY)
      {
M
Mr.Tiger 已提交
2482
        if(((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
whj123999's avatar
whj123999 已提交
2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493
        {
          /* Return timeout status */
          return HAL_TIMEOUT;
        }
      }
    }
    /* Check if overrun occurs */
    if((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_JOVRF) == DFSDM_FLTISR_JOVRF)
    {
      /* Update error code and call error callback */
      hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN;
2494 2495 2496
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
      hdfsdm_filter->ErrorCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
2497
      HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
2498
#endif
whj123999's avatar
whj123999 已提交
2499 2500 2501 2502 2503 2504 2505

      /* Clear injected overrun flag */
      hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF;
    }

    /* Update remaining injected conversions */
    hdfsdm_filter->InjConvRemaining--;
2506
    if(hdfsdm_filter->InjConvRemaining == 0U)
whj123999's avatar
whj123999 已提交
2507 2508 2509 2510 2511 2512 2513
    {
      /* Update DFSDM filter state only if trigger is software */
      if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
      {
        hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
                               HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
      }
M
Mr.Tiger 已提交
2514

whj123999's avatar
whj123999 已提交
2515 2516
      /* end of injected sequence, reset the value */
      hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
2517
                                         hdfsdm_filter->InjectedChannelsNbr : 1U;
whj123999's avatar
whj123999 已提交
2518 2519 2520 2521 2522 2523 2524 2525 2526 2527
    }

    /* Return function status */
    return HAL_OK;
  }
}

/**
  * @brief  This function allows to stop injected conversion in polling mode.
  * @note   This function should be called only if injected conversion is ongoing.
2528
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Stop injected conversion */
    DFSDM_InjConvStop(hdfsdm_filter);
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start injected conversion in interrupt mode.
M
Mr.Tiger 已提交
2556
  * @note   This function should be called only when DFSDM filter instance is
whj123999's avatar
whj123999 已提交
2557
  *         in idle state or if regular conversion is ongoing.
2558
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
     (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
  {
    /* Enable interrupts for injected conversions */
    hdfsdm_filter->Instance->FLTCR2 |= (DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE);
M
Mr.Tiger 已提交
2574

whj123999's avatar
whj123999 已提交
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
    /* Start injected conversion */
    DFSDM_InjConvStart(hdfsdm_filter);
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to stop injected conversion in interrupt mode.
  * @note   This function should be called only if injected conversion is ongoing.
2589
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Disable interrupts for injected conversions */
    hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE | DFSDM_FLTCR2_JOVRIE);
M
Mr.Tiger 已提交
2610

whj123999's avatar
whj123999 已提交
2611 2612 2613 2614 2615 2616 2617 2618 2619
    /* Stop injected conversion */
    DFSDM_InjConvStop(hdfsdm_filter);
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start injected conversion in DMA mode.
M
Mr.Tiger 已提交
2620
  * @note   This function should be called only when DFSDM filter instance is
whj123999's avatar
whj123999 已提交
2621 2622 2623 2624
  *         in idle state or if regular conversion is ongoing.
  *         Please note that data on buffer will contain signed injected conversion
  *         value on 24 most significant bits and corresponding channel on 3 least
  *         significant bits.
2625 2626 2627
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  pData The destination buffer address.
  * @param  Length The length of data to be transferred from DFSDM filter to memory.
whj123999's avatar
whj123999 已提交
2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                    int32_t                    *pData,
                                                    uint32_t                    Length)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check destination address and length */
2640
  if((pData == NULL) || (Length == 0U))
whj123999's avatar
whj123999 已提交
2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669
  {
    status = HAL_ERROR;
  }
  /* Check that DMA is enabled for injected conversion */
  else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN)
  {
    status = HAL_ERROR;
  }
  /* Check parameters compatibility */
  else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
          (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \
          (Length > hdfsdm_filter->InjConvRemaining))
  {
    status = HAL_ERROR;
  }
  else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
          (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR))
  {
    status = HAL_ERROR;
  }
  /* Check DFSDM filter state */
  else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
          (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
  {
    /* Set callbacks on DMA handler */
    hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt;
    hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError;
    hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ?\
                                                   DFSDM_DMAInjectedHalfConvCplt : NULL;
M
Mr.Tiger 已提交
2670

whj123999's avatar
whj123999 已提交
2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695
    /* Start DMA in interrupt mode */
    if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)&hdfsdm_filter->Instance->FLTJDATAR, \
                        (uint32_t) pData, Length) != HAL_OK)
    {
      /* Set DFSDM filter in error state */
      hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
      status = HAL_ERROR;
    }
    else
    {
      /* Start injected conversion */
      DFSDM_InjConvStart(hdfsdm_filter);
    }
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start injected conversion in DMA mode and to get
  *         only the 16 most significant bits of conversion.
M
Mr.Tiger 已提交
2696
  * @note   This function should be called only when DFSDM filter instance is
whj123999's avatar
whj123999 已提交
2697 2698 2699
  *         in idle state or if regular conversion is ongoing.
  *         Please note that data on buffer will contain signed 16 most significant
  *         bits of injected conversion.
2700 2701 2702
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  pData The destination buffer address.
  * @param  Length The length of data to be transferred from DFSDM filter to memory.
whj123999's avatar
whj123999 已提交
2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                       int16_t                    *pData,
                                                       uint32_t                    Length)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check destination address and length */
2715
  if((pData == NULL) || (Length == 0U))
whj123999's avatar
whj123999 已提交
2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744
  {
    status = HAL_ERROR;
  }
  /* Check that DMA is enabled for injected conversion */
  else if((hdfsdm_filter->Instance->FLTCR1 & DFSDM_FLTCR1_JDMAEN) != DFSDM_FLTCR1_JDMAEN)
  {
    status = HAL_ERROR;
  }
  /* Check parameters compatibility */
  else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
          (hdfsdm_filter->hdmaInj->Init.Mode == DMA_NORMAL) && \
          (Length > hdfsdm_filter->InjConvRemaining))
  {
    status = HAL_ERROR;
  }
  else if((hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER) && \
          (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR))
  {
    status = HAL_ERROR;
  }
  /* Check DFSDM filter state */
  else if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) || \
          (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG))
  {
    /* Set callbacks on DMA handler */
    hdfsdm_filter->hdmaInj->XferCpltCallback = DFSDM_DMAInjectedConvCplt;
    hdfsdm_filter->hdmaInj->XferErrorCallback = DFSDM_DMAError;
    hdfsdm_filter->hdmaInj->XferHalfCpltCallback = (hdfsdm_filter->hdmaInj->Init.Mode == DMA_CIRCULAR) ?\
                                                   DFSDM_DMAInjectedHalfConvCplt : NULL;
M
Mr.Tiger 已提交
2745

whj123999's avatar
whj123999 已提交
2746
    /* Start DMA in interrupt mode */
2747
    if(HAL_DMA_Start_IT(hdfsdm_filter->hdmaInj, (uint32_t)(&hdfsdm_filter->Instance->FLTJDATAR) + 2U, \
whj123999's avatar
whj123999 已提交
2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770
                        (uint32_t) pData, Length) != HAL_OK)
    {
      /* Set DFSDM filter in error state */
      hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
      status = HAL_ERROR;
    }
    else
    {
      /* Start injected conversion */
      DFSDM_InjConvStart(hdfsdm_filter);
    }
  }
  else
  {
    status = HAL_ERROR;
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to stop injected conversion in DMA mode.
  * @note   This function should be called only if injected conversion is ongoing.
2771
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Check DFSDM filter state */
  if((hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_INJ) && \
     (hdfsdm_filter->State != HAL_DFSDM_FILTER_STATE_REG_INJ))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Stop current DMA transfer */
    if(HAL_DMA_Abort(hdfsdm_filter->hdmaInj) != HAL_OK)
    {
      /* Set DFSDM filter in error state */
      hdfsdm_filter->State = HAL_DFSDM_FILTER_STATE_ERROR;
      status = HAL_ERROR;
    }
    else
    {
      /* Stop regular conversion */
      DFSDM_InjConvStop(hdfsdm_filter);
    }
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to get injected conversion value.
2809 2810
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Channel Corresponding channel of injected conversion.
whj123999's avatar
whj123999 已提交
2811 2812
  * @retval Injected conversion value
  */
M
Mr.Tiger 已提交
2813
int32_t HAL_DFSDM_FilterGetInjectedValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
whj123999's avatar
whj123999 已提交
2814 2815
                                         uint32_t                   *Channel)
{
2816 2817
  uint32_t reg;
  int32_t  value;
M
Mr.Tiger 已提交
2818

whj123999's avatar
whj123999 已提交
2819 2820
  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
2821
  assert_param(Channel != (void *)0);
whj123999's avatar
whj123999 已提交
2822 2823 2824

  /* Get value of data register for injected channel */
  reg = hdfsdm_filter->Instance->FLTJDATAR;
M
Mr.Tiger 已提交
2825

whj123999's avatar
whj123999 已提交
2826 2827
  /* Extract channel and injected conversion value */
  *Channel = (reg & DFSDM_FLTJDATAR_JDATACH);
2828 2829 2830 2831
  /* Injected conversion value is a signed value located on 24 MSB of register */
  /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
  reg &= DFSDM_FLTJDATAR_JDATA;
  value = ((int32_t)reg) / 256;
whj123999's avatar
whj123999 已提交
2832 2833 2834 2835 2836 2837 2838

  /* return regular conversion value */
  return value;
}

/**
  * @brief  This function allows to start filter analog watchdog in interrupt mode.
2839 2840
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  awdParam DFSDM filter analog watchdog parameters.
whj123999's avatar
whj123999 已提交
2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterAwdStart_IT(DFSDM_Filter_HandleTypeDef   *hdfsdm_filter,
                                              DFSDM_Filter_AwdParamTypeDef *awdParam)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
  assert_param(IS_DFSDM_FILTER_AWD_DATA_SOURCE(awdParam->DataSource));
  assert_param(IS_DFSDM_INJECTED_CHANNEL(awdParam->Channel));
  assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->HighThreshold));
  assert_param(IS_DFSDM_FILTER_AWD_THRESHOLD(awdParam->LowThreshold));
  assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->HighBreakSignal));
  assert_param(IS_DFSDM_BREAK_SIGNALS(awdParam->LowBreakSignal));
M
Mr.Tiger 已提交
2856

whj123999's avatar
whj123999 已提交
2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871
  /* Check DFSDM filter state */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
     (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Set analog watchdog data source */
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL);
    hdfsdm_filter->Instance->FLTCR1 |= awdParam->DataSource;

    /* Set thresholds and break signals */
    hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH);
2872
    hdfsdm_filter->Instance->FLTAWHTR |= (((uint32_t) awdParam->HighThreshold << DFSDM_FLTAWHTR_AWHT_Pos) | \
M
Mr.Tiger 已提交
2873
                                          awdParam->HighBreakSignal);
whj123999's avatar
whj123999 已提交
2874
    hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL);
2875
    hdfsdm_filter->Instance->FLTAWLTR |= (((uint32_t) awdParam->LowThreshold << DFSDM_FLTAWLTR_AWLT_Pos) | \
M
Mr.Tiger 已提交
2876
                                          awdParam->LowBreakSignal);
whj123999's avatar
whj123999 已提交
2877 2878 2879

    /* Set channels and interrupt for analog watchdog */
    hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH);
2880
    hdfsdm_filter->Instance->FLTCR2 |= (((awdParam->Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_AWDCH_Pos) | \
whj123999's avatar
whj123999 已提交
2881 2882 2883 2884 2885 2886 2887 2888
                                        DFSDM_FLTCR2_AWDIE);
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to stop filter analog watchdog in interrupt mode.
2889
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2890 2891 2892 2893 2894 2895 2896 2897
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterAwdStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
M
Mr.Tiger 已提交
2898

whj123999's avatar
whj123999 已提交
2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912
  /* Check DFSDM filter state */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
     (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Reset channels for analog watchdog and deactivate interrupt */
    hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_AWDCH | DFSDM_FLTCR2_AWDIE);

    /* Clear all analog watchdog flags */
    hdfsdm_filter->Instance->FLTAWCFR = (DFSDM_FLTAWCFR_CLRAWHTF | DFSDM_FLTAWCFR_CLRAWLTF);
M
Mr.Tiger 已提交
2913

whj123999's avatar
whj123999 已提交
2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926
    /* Reset thresholds and break signals */
    hdfsdm_filter->Instance->FLTAWHTR &= ~(DFSDM_FLTAWHTR_AWHT | DFSDM_FLTAWHTR_BKAWH);
    hdfsdm_filter->Instance->FLTAWLTR &= ~(DFSDM_FLTAWLTR_AWLT | DFSDM_FLTAWLTR_BKAWL);

    /* Reset analog watchdog data source */
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_AWFSEL);
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to start extreme detector feature.
2927 2928
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Channel Channels where extreme detector is enabled.
whj123999's avatar
whj123999 已提交
2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939
  *         This parameter can be a values combination of @ref DFSDM_Channel_Selection.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterExdStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                           uint32_t                    Channel)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
  assert_param(IS_DFSDM_INJECTED_CHANNEL(Channel));
M
Mr.Tiger 已提交
2940

whj123999's avatar
whj123999 已提交
2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951
  /* Check DFSDM filter state */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
     (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Set channels for extreme detector */
    hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH);
M
Mr.Tiger 已提交
2952
    hdfsdm_filter->Instance->FLTCR2 |= ((Channel & DFSDM_LSB_MASK) << DFSDM_FLTCR2_EXCH_Pos);
whj123999's avatar
whj123999 已提交
2953 2954 2955 2956 2957 2958 2959
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to stop extreme detector feature.
2960
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
2961 2962 2963 2964 2965 2966 2967 2968 2969 2970
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DFSDM_FilterExdStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  HAL_StatusTypeDef status = HAL_OK;
  __IO uint32_t     reg1;
  __IO uint32_t     reg2;

  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
M
Mr.Tiger 已提交
2971

whj123999's avatar
whj123999 已提交
2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985
  /* Check DFSDM filter state */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_RESET) || \
     (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_ERROR))
  {
    /* Return error status */
    status = HAL_ERROR;
  }
  else
  {
    /* Reset channels for extreme detector */
    hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_EXCH);

    /* Clear extreme detector values */
    reg1 = hdfsdm_filter->Instance->FLTEXMAX;
M
Mr.Tiger 已提交
2986
    reg2 = hdfsdm_filter->Instance->FLTEXMIN;
whj123999's avatar
whj123999 已提交
2987 2988 2989 2990 2991 2992 2993 2994 2995
    UNUSED(reg1); /* To avoid GCC warning */
    UNUSED(reg2); /* To avoid GCC warning */
  }
  /* Return function status */
  return status;
}

/**
  * @brief  This function allows to get extreme detector maximum value.
2996 2997
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Channel Corresponding channel.
whj123999's avatar
whj123999 已提交
2998 2999 3000 3001 3002 3003
  * @retval Extreme detector maximum value
  *         This value is between Min_Data = -8388608 and Max_Data = 8388607.
  */
int32_t HAL_DFSDM_FilterGetExdMaxValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                       uint32_t                   *Channel)
{
3004 3005
  uint32_t reg;
  int32_t  value;
M
Mr.Tiger 已提交
3006

whj123999's avatar
whj123999 已提交
3007 3008
  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
3009
  assert_param(Channel != (void *)0);
whj123999's avatar
whj123999 已提交
3010 3011 3012

  /* Get value of extreme detector maximum register */
  reg = hdfsdm_filter->Instance->FLTEXMAX;
M
Mr.Tiger 已提交
3013

whj123999's avatar
whj123999 已提交
3014 3015
  /* Extract channel and extreme detector maximum value */
  *Channel = (reg & DFSDM_FLTEXMAX_EXMAXCH);
3016 3017 3018 3019
  /* Extreme detector maximum value is a signed value located on 24 MSB of register */
  /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
  reg &= DFSDM_FLTEXMAX_EXMAX;
  value = ((int32_t)reg) / 256;
whj123999's avatar
whj123999 已提交
3020 3021 3022 3023 3024 3025 3026

  /* return extreme detector maximum value */
  return value;
}

/**
  * @brief  This function allows to get extreme detector minimum value.
3027 3028
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Channel Corresponding channel.
whj123999's avatar
whj123999 已提交
3029 3030 3031 3032 3033 3034
  * @retval Extreme detector minimum value
  *         This value is between Min_Data = -8388608 and Max_Data = 8388607.
  */
int32_t HAL_DFSDM_FilterGetExdMinValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                       uint32_t                   *Channel)
{
3035 3036
  uint32_t reg;
  int32_t  value;
M
Mr.Tiger 已提交
3037

whj123999's avatar
whj123999 已提交
3038 3039
  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));
3040
  assert_param(Channel != (void *)0);
whj123999's avatar
whj123999 已提交
3041 3042 3043

  /* Get value of extreme detector minimum register */
  reg = hdfsdm_filter->Instance->FLTEXMIN;
M
Mr.Tiger 已提交
3044

whj123999's avatar
whj123999 已提交
3045 3046
  /* Extract channel and extreme detector minimum value */
  *Channel = (reg & DFSDM_FLTEXMIN_EXMINCH);
3047 3048 3049 3050
  /* Extreme detector minimum value is a signed value located on 24 MSB of register */
  /* So after applying a mask on these bits we have to perform a division by 256 (2 raised to the power of 8) */
  reg &= DFSDM_FLTEXMIN_EXMIN;
  value = ((int32_t)reg) / 256;
whj123999's avatar
whj123999 已提交
3051 3052 3053 3054 3055 3056 3057

  /* return extreme detector minimum value */
  return value;
}

/**
  * @brief  This function allows to get conversion time value.
3058
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3059 3060 3061 3062 3063
  * @retval Conversion time value
  * @note   To get time in second, this value has to be divided by DFSDM clock frequency.
  */
uint32_t HAL_DFSDM_FilterGetConvTimeValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
3064 3065
  uint32_t reg;
  uint32_t value;
M
Mr.Tiger 已提交
3066

whj123999's avatar
whj123999 已提交
3067 3068 3069 3070 3071
  /* Check parameters */
  assert_param(IS_DFSDM_FILTER_ALL_INSTANCE(hdfsdm_filter->Instance));

  /* Get value of conversion timer register */
  reg = hdfsdm_filter->Instance->FLTCNVTIMR;
M
Mr.Tiger 已提交
3072

whj123999's avatar
whj123999 已提交
3073
  /* Extract conversion time value */
3074
  value = ((reg & DFSDM_FLTCNVTIMR_CNVCNT) >> DFSDM_FLTCNVTIMR_CNVCNT_Pos);
whj123999's avatar
whj123999 已提交
3075 3076 3077 3078 3079 3080 3081

  /* return extreme detector minimum value */
  return value;
}

/**
  * @brief  This function handles the DFSDM interrupts.
3082
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3083 3084 3085 3086
  * @retval None
  */
void HAL_DFSDM_IRQHandler(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
M
Mr.Tiger 已提交
3087 3088 3089 3090
  DFSDM_Channel_HandleTypeDef **channelHandleTable;
  const DFSDM_Filter_TypeDef   *filter0Instance;
  uint32_t channelNumber;

3091 3092 3093
  /* Get FTLISR and FLTCR2 register values */
  const uint32_t temp_fltisr = hdfsdm_filter->Instance->FLTISR;
  const uint32_t temp_fltcr2 = hdfsdm_filter->Instance->FLTCR2;
M
Mr.Tiger 已提交
3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113

#if defined(DFSDM2_Channel0)
  if (IS_DFSDM1_FILTER_INSTANCE(hdfsdm_filter->Instance))
  {
    channelHandleTable = a_dfsdm1ChannelHandle;
    filter0Instance    = DFSDM1_Filter0;
    channelNumber      = DFSDM1_CHANNEL_NUMBER;
  }
  else
  {
    channelHandleTable = a_dfsdm2ChannelHandle;
    filter0Instance    = DFSDM2_Filter0;
    channelNumber      = DFSDM2_CHANNEL_NUMBER;
  }
#else /* DFSDM2_Channel0 */
  channelHandleTable = a_dfsdm1ChannelHandle;
  filter0Instance    = DFSDM1_Filter0;
  channelNumber      = DFSDM1_CHANNEL_NUMBER;
#endif /* DFSDM2_Channel0 */

whj123999's avatar
whj123999 已提交
3114
  /* Check if overrun occurs during regular conversion */
3115 3116
  if(((temp_fltisr & DFSDM_FLTISR_ROVRF) != 0U) && \
     ((temp_fltcr2 & DFSDM_FLTCR2_ROVRIE) != 0U))
whj123999's avatar
whj123999 已提交
3117 3118 3119 3120 3121 3122 3123 3124
  {
    /* Clear regular overrun flag */
    hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRROVRF;

    /* Update error code */
    hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_REGULAR_OVERRUN;

    /* Call error callback */
3125 3126 3127
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
    hdfsdm_filter->ErrorCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3128
    HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
3129
#endif
whj123999's avatar
whj123999 已提交
3130 3131
  }
  /* Check if overrun occurs during injected conversion */
3132 3133
  else if(((temp_fltisr & DFSDM_FLTISR_JOVRF) != 0U) && \
          ((temp_fltcr2 & DFSDM_FLTCR2_JOVRIE) != 0U))
whj123999's avatar
whj123999 已提交
3134 3135 3136 3137 3138 3139 3140 3141
  {
    /* Clear injected overrun flag */
    hdfsdm_filter->Instance->FLTICR = DFSDM_FLTICR_CLRJOVRF;

    /* Update error code */
    hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_INJECTED_OVERRUN;

    /* Call error callback */
3142 3143 3144
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
    hdfsdm_filter->ErrorCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3145
    HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
3146
#endif
whj123999's avatar
whj123999 已提交
3147 3148
  }
  /* Check if end of regular conversion */
3149 3150
  else if(((temp_fltisr & DFSDM_FLTISR_REOCF) != 0U) && \
          ((temp_fltcr2 & DFSDM_FLTCR2_REOCIE) != 0U))
whj123999's avatar
whj123999 已提交
3151 3152
  {
    /* Call regular conversion complete callback */
3153 3154 3155
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
    hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3156
    HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter);
3157
#endif
whj123999's avatar
whj123999 已提交
3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171

    /* End of conversion if mode is not continuous and software trigger */
    if((hdfsdm_filter->RegularContMode == DFSDM_CONTINUOUS_CONV_OFF) && \
       (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
    {
      /* Disable interrupts for regular conversions */
      hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_REOCIE);

      /* Update DFSDM filter state */
      hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
                             HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
    }
  }
  /* Check if end of injected conversion */
3172 3173
  else if(((temp_fltisr & DFSDM_FLTISR_JEOCF) != 0U) && \
          ((temp_fltcr2 & DFSDM_FLTCR2_JEOCIE) != 0U))
whj123999's avatar
whj123999 已提交
3174 3175
  {
    /* Call injected conversion complete callback */
3176 3177 3178
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
    hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3179
    HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter);
3180
#endif
whj123999's avatar
whj123999 已提交
3181 3182 3183

    /* Update remaining injected conversions */
    hdfsdm_filter->InjConvRemaining--;
3184
    if(hdfsdm_filter->InjConvRemaining == 0U)
whj123999's avatar
whj123999 已提交
3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197
    {
      /* End of conversion if trigger is software */
      if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
      {
        /* Disable interrupts for injected conversions */
        hdfsdm_filter->Instance->FLTCR2 &= ~(DFSDM_FLTCR2_JEOCIE);

        /* Update DFSDM filter state */
        hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
                               HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
      }
      /* end of injected sequence, reset the value */
      hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
3198
                                         hdfsdm_filter->InjectedChannelsNbr : 1U;
whj123999's avatar
whj123999 已提交
3199 3200 3201
    }
  }
  /* Check if analog watchdog occurs */
3202 3203
  else if(((temp_fltisr & DFSDM_FLTISR_AWDF) != 0U) && \
          ((temp_fltcr2 & DFSDM_FLTCR2_AWDIE) != 0U))
whj123999's avatar
whj123999 已提交
3204
  {
3205 3206
    uint32_t reg;
    uint32_t threshold;
whj123999's avatar
whj123999 已提交
3207
    uint32_t channel = 0;
M
Mr.Tiger 已提交
3208

whj123999's avatar
whj123999 已提交
3209 3210
    /* Get channel and threshold */
    reg = hdfsdm_filter->Instance->FLTAWSR;
3211
    threshold = ((reg & DFSDM_FLTAWSR_AWLTF) != 0U) ? DFSDM_AWD_LOW_THRESHOLD : DFSDM_AWD_HIGH_THRESHOLD;
whj123999's avatar
whj123999 已提交
3212 3213
    if(threshold == DFSDM_AWD_HIGH_THRESHOLD)
    {
3214
      reg = reg >> DFSDM_FLTAWSR_AWHTF_Pos;
whj123999's avatar
whj123999 已提交
3215
    }
M
Mr.Tiger 已提交
3216
    while (((reg & 1U) == 0U) && (channel < (channelNumber - 1U)))
whj123999's avatar
whj123999 已提交
3217 3218 3219 3220 3221 3222
    {
      channel++;
      reg = reg >> 1;
    }
    /* Clear analog watchdog flag */
    hdfsdm_filter->Instance->FLTAWCFR = (threshold == DFSDM_AWD_HIGH_THRESHOLD) ? \
3223 3224
                                        (1UL << (DFSDM_FLTAWSR_AWHTF_Pos + channel)) : \
                                        (1UL << channel);
whj123999's avatar
whj123999 已提交
3225 3226

    /* Call analog watchdog callback */
3227 3228 3229
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
    hdfsdm_filter->AwdCallback(hdfsdm_filter, channel, threshold);
#else
whj123999's avatar
whj123999 已提交
3230
    HAL_DFSDM_FilterAwdCallback(hdfsdm_filter, channel, threshold);
3231
#endif
whj123999's avatar
whj123999 已提交
3232 3233
  }
  /* Check if clock absence occurs */
M
Mr.Tiger 已提交
3234
  else if((hdfsdm_filter->Instance == filter0Instance) && \
3235 3236
         ((temp_fltisr & DFSDM_FLTISR_CKABF) != 0U) && \
         ((temp_fltcr2 & DFSDM_FLTCR2_CKABIE) != 0U))
whj123999's avatar
whj123999 已提交
3237
  {
3238
    uint32_t reg;
whj123999's avatar
whj123999 已提交
3239
    uint32_t channel = 0;
M
Mr.Tiger 已提交
3240

3241
    reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_CKABF) >> DFSDM_FLTISR_CKABF_Pos);
whj123999's avatar
whj123999 已提交
3242

M
Mr.Tiger 已提交
3243
    while (channel < channelNumber)
whj123999's avatar
whj123999 已提交
3244 3245
    {
      /* Check if flag is set and corresponding channel is enabled */
M
Mr.Tiger 已提交
3246
      if (((reg & 1U) != 0U) && (channelHandleTable[channel] != NULL))
whj123999's avatar
whj123999 已提交
3247 3248
      {
        /* Check clock absence has been enabled for this channel */
M
Mr.Tiger 已提交
3249
        if ((channelHandleTable[channel]->Instance->CHCFGR1 & DFSDM_CHCFGR1_CKABEN) != 0U)
whj123999's avatar
whj123999 已提交
3250 3251
        {
          /* Clear clock absence flag */
3252
          hdfsdm_filter->Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRCKABF_Pos + channel));
whj123999's avatar
whj123999 已提交
3253 3254

          /* Call clock absence callback */
3255
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
M
Mr.Tiger 已提交
3256
          channelHandleTable[channel]->CkabCallback(channelHandleTable[channel]);
3257
#else
M
Mr.Tiger 已提交
3258
          HAL_DFSDM_ChannelCkabCallback(channelHandleTable[channel]);
3259
#endif
whj123999's avatar
whj123999 已提交
3260 3261 3262 3263 3264 3265 3266
        }
      }
      channel++;
      reg = reg >> 1;
    }
  }
  /* Check if short circuit detection occurs */
M
Mr.Tiger 已提交
3267
  else if((hdfsdm_filter->Instance == filter0Instance) && \
3268 3269
         ((temp_fltisr & DFSDM_FLTISR_SCDF) != 0U) && \
         ((temp_fltcr2 & DFSDM_FLTCR2_SCDIE) != 0U))
whj123999's avatar
whj123999 已提交
3270
  {
3271
    uint32_t reg;
whj123999's avatar
whj123999 已提交
3272
    uint32_t channel = 0;
M
Mr.Tiger 已提交
3273

whj123999's avatar
whj123999 已提交
3274
    /* Get channel */
3275
    reg = ((hdfsdm_filter->Instance->FLTISR & DFSDM_FLTISR_SCDF) >> DFSDM_FLTISR_SCDF_Pos);
M
Mr.Tiger 已提交
3276
    while (((reg & 1U) == 0U) && (channel < (channelNumber - 1U)))
whj123999's avatar
whj123999 已提交
3277 3278 3279 3280
    {
      channel++;
      reg = reg >> 1;
    }
M
Mr.Tiger 已提交
3281

whj123999's avatar
whj123999 已提交
3282
    /* Clear short circuit detection flag */
3283
    hdfsdm_filter->Instance->FLTICR = (1UL << (DFSDM_FLTICR_CLRSCDF_Pos + channel));
whj123999's avatar
whj123999 已提交
3284 3285

    /* Call short circuit detection callback */
3286
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
M
Mr.Tiger 已提交
3287
    channelHandleTable[channel]->ScdCallback(channelHandleTable[channel]);
3288
#else
M
Mr.Tiger 已提交
3289
    HAL_DFSDM_ChannelScdCallback(channelHandleTable[channel]);
3290
#endif
whj123999's avatar
whj123999 已提交
3291 3292 3293 3294
  }
}

/**
M
Mr.Tiger 已提交
3295
  * @brief  Regular conversion complete callback.
whj123999's avatar
whj123999 已提交
3296 3297
  * @note   In interrupt mode, user has to read conversion value in this function
  *         using HAL_DFSDM_FilterGetRegularValue.
3298
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3299 3300 3301 3302 3303 3304
  * @retval None
  */
__weak void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_filter);
M
Mr.Tiger 已提交
3305

whj123999's avatar
whj123999 已提交
3306 3307 3308 3309 3310 3311
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_DFSDM_FilterRegConvCpltCallback could be implemented in the user file.
   */
}

/**
M
Mr.Tiger 已提交
3312
  * @brief  Half regular conversion complete callback.
3313
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3314 3315 3316 3317 3318 3319
  * @retval None
  */
__weak void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_filter);
M
Mr.Tiger 已提交
3320

whj123999's avatar
whj123999 已提交
3321 3322 3323 3324 3325 3326
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_DFSDM_FilterRegConvHalfCpltCallback could be implemented in the user file.
   */
}

/**
M
Mr.Tiger 已提交
3327
  * @brief  Injected conversion complete callback.
whj123999's avatar
whj123999 已提交
3328 3329
  * @note   In interrupt mode, user has to read conversion value in this function
  *         using HAL_DFSDM_FilterGetInjectedValue.
3330
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3331 3332 3333 3334 3335 3336
  * @retval None
  */
__weak void HAL_DFSDM_FilterInjConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_filter);
M
Mr.Tiger 已提交
3337

whj123999's avatar
whj123999 已提交
3338 3339 3340 3341 3342 3343
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_DFSDM_FilterInjConvCpltCallback could be implemented in the user file.
   */
}

/**
M
Mr.Tiger 已提交
3344
  * @brief  Half injected conversion complete callback.
3345
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3346 3347 3348 3349 3350 3351
  * @retval None
  */
__weak void HAL_DFSDM_FilterInjConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_filter);
M
Mr.Tiger 已提交
3352

whj123999's avatar
whj123999 已提交
3353 3354 3355 3356 3357 3358
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_DFSDM_FilterInjConvHalfCpltCallback could be implemented in the user file.
   */
}

/**
M
Mr.Tiger 已提交
3359
  * @brief  Filter analog watchdog callback.
3360 3361 3362
  * @param  hdfsdm_filter DFSDM filter handle.
  * @param  Channel Corresponding channel.
  * @param  Threshold Low or high threshold has been reached.
whj123999's avatar
whj123999 已提交
3363 3364 3365 3366 3367 3368 3369 3370 3371
  * @retval None
  */
__weak void HAL_DFSDM_FilterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                        uint32_t Channel, uint32_t Threshold)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_filter);
  UNUSED(Channel);
  UNUSED(Threshold);
M
Mr.Tiger 已提交
3372

whj123999's avatar
whj123999 已提交
3373 3374 3375 3376 3377 3378
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_DFSDM_FilterAwdCallback could be implemented in the user file.
   */
}

/**
M
Mr.Tiger 已提交
3379
  * @brief  Error callback.
3380
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3381 3382 3383 3384 3385 3386
  * @retval None
  */
__weak void HAL_DFSDM_FilterErrorCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(hdfsdm_filter);
M
Mr.Tiger 已提交
3387

whj123999's avatar
whj123999 已提交
3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412
  /* NOTE : This function should not be modified, when the callback is needed,
            the HAL_DFSDM_FilterErrorCallback could be implemented in the user file.
   */
}

/**
  * @}
  */

/** @defgroup DFSDM_Exported_Functions_Group4_Filter Filter state functions
 *  @brief    Filter state functions
 *
@verbatim
  ==============================================================================
                     ##### Filter state functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Get the DFSDM filter state.
      (+) Get the DFSDM filter error.
@endverbatim
  * @{
  */

/**
  * @brief  This function allows to get the current DFSDM filter handle state.
3413
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3414 3415 3416 3417 3418 3419 3420 3421 3422 3423
  * @retval DFSDM filter state.
  */
HAL_DFSDM_Filter_StateTypeDef HAL_DFSDM_FilterGetState(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  /* Return DFSDM filter handle state */
  return hdfsdm_filter->State;
}

/**
  * @brief  This function allows to get the current DFSDM filter error.
3424
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446
  * @retval DFSDM filter error code.
  */
uint32_t HAL_DFSDM_FilterGetError(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
{
  return hdfsdm_filter->ErrorCode;
}

/**
  * @}
  */

/**
  * @}
  */
/* End of exported functions -------------------------------------------------*/

/* Private functions ---------------------------------------------------------*/
/** @addtogroup DFSDM_Private_Functions DFSDM Private Functions
  * @{
  */

/**
M
Mr.Tiger 已提交
3447
  * @brief  DMA half transfer complete callback for regular conversion.
3448
  * @param  hdma DMA handle.
whj123999's avatar
whj123999 已提交
3449 3450
  * @retval None
  */
M
Mr.Tiger 已提交
3451
static void DFSDM_DMARegularHalfConvCplt(DMA_HandleTypeDef *hdma)
whj123999's avatar
whj123999 已提交
3452 3453
{
  /* Get DFSDM filter handle */
M
Mr.Tiger 已提交
3454
  DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
whj123999's avatar
whj123999 已提交
3455 3456

  /* Call regular half conversion complete callback */
3457 3458 3459
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  hdfsdm_filter->RegConvHalfCpltCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3460
  HAL_DFSDM_FilterRegConvHalfCpltCallback(hdfsdm_filter);
3461
#endif
whj123999's avatar
whj123999 已提交
3462 3463 3464
}

/**
M
Mr.Tiger 已提交
3465
  * @brief  DMA transfer complete callback for regular conversion.
3466
  * @param  hdma DMA handle.
whj123999's avatar
whj123999 已提交
3467 3468
  * @retval None
  */
M
Mr.Tiger 已提交
3469
static void DFSDM_DMARegularConvCplt(DMA_HandleTypeDef *hdma)
whj123999's avatar
whj123999 已提交
3470 3471
{
  /* Get DFSDM filter handle */
M
Mr.Tiger 已提交
3472
  DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
whj123999's avatar
whj123999 已提交
3473 3474

  /* Call regular conversion complete callback */
3475 3476 3477
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3478
  HAL_DFSDM_FilterRegConvCpltCallback(hdfsdm_filter);
3479
#endif
whj123999's avatar
whj123999 已提交
3480 3481 3482
}

/**
M
Mr.Tiger 已提交
3483
  * @brief  DMA half transfer complete callback for injected conversion.
3484
  * @param  hdma DMA handle.
whj123999's avatar
whj123999 已提交
3485 3486
  * @retval None
  */
M
Mr.Tiger 已提交
3487
static void DFSDM_DMAInjectedHalfConvCplt(DMA_HandleTypeDef *hdma)
whj123999's avatar
whj123999 已提交
3488 3489
{
  /* Get DFSDM filter handle */
M
Mr.Tiger 已提交
3490
  DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
whj123999's avatar
whj123999 已提交
3491 3492

  /* Call injected half conversion complete callback */
3493 3494 3495
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  hdfsdm_filter->InjConvHalfCpltCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3496
  HAL_DFSDM_FilterInjConvHalfCpltCallback(hdfsdm_filter);
3497
#endif
whj123999's avatar
whj123999 已提交
3498 3499 3500
}

/**
M
Mr.Tiger 已提交
3501
  * @brief  DMA transfer complete callback for injected conversion.
3502
  * @param  hdma DMA handle.
whj123999's avatar
whj123999 已提交
3503 3504
  * @retval None
  */
M
Mr.Tiger 已提交
3505
static void DFSDM_DMAInjectedConvCplt(DMA_HandleTypeDef *hdma)
whj123999's avatar
whj123999 已提交
3506 3507
{
  /* Get DFSDM filter handle */
M
Mr.Tiger 已提交
3508
  DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
whj123999's avatar
whj123999 已提交
3509 3510

  /* Call injected conversion complete callback */
3511 3512 3513
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3514
  HAL_DFSDM_FilterInjConvCpltCallback(hdfsdm_filter);
3515
#endif
whj123999's avatar
whj123999 已提交
3516 3517 3518
}

/**
M
Mr.Tiger 已提交
3519
  * @brief  DMA error callback.
3520
  * @param  hdma DMA handle.
whj123999's avatar
whj123999 已提交
3521 3522
  * @retval None
  */
M
Mr.Tiger 已提交
3523
static void DFSDM_DMAError(DMA_HandleTypeDef *hdma)
whj123999's avatar
whj123999 已提交
3524 3525
{
  /* Get DFSDM filter handle */
M
Mr.Tiger 已提交
3526
  DFSDM_Filter_HandleTypeDef *hdfsdm_filter = (DFSDM_Filter_HandleTypeDef*) ((DMA_HandleTypeDef*)hdma)->Parent;
whj123999's avatar
whj123999 已提交
3527 3528 3529 3530 3531

  /* Update error code */
  hdfsdm_filter->ErrorCode = DFSDM_FILTER_ERROR_DMA;

  /* Call error callback */
3532 3533 3534
#if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
  hdfsdm_filter->ErrorCallback(hdfsdm_filter);
#else
whj123999's avatar
whj123999 已提交
3535
  HAL_DFSDM_FilterErrorCallback(hdfsdm_filter);
3536
#endif
whj123999's avatar
whj123999 已提交
3537 3538 3539 3540
}

/**
  * @brief  This function allows to get the number of injected channels.
3541
  * @param  Channels bitfield of injected channels.
whj123999's avatar
whj123999 已提交
3542 3543 3544 3545 3546 3547
  * @retval Number of injected channels.
  */
static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels)
{
  uint32_t nbChannels = 0;
  uint32_t tmp;
M
Mr.Tiger 已提交
3548

whj123999's avatar
whj123999 已提交
3549
  /* Get the number of channels from bitfield */
M
Mr.Tiger 已提交
3550
  tmp = (uint32_t)(Channels & DFSDM_LSB_MASK);
3551
  while(tmp != 0U)
whj123999's avatar
whj123999 已提交
3552
  {
3553
    if((tmp & 1U) != 0U)
whj123999's avatar
whj123999 已提交
3554 3555 3556
    {
      nbChannels++;
    }
M
Mr.Tiger 已提交
3557
    tmp = (uint32_t)(tmp >> 1);
whj123999's avatar
whj123999 已提交
3558 3559 3560 3561 3562 3563
  }
  return nbChannels;
}

/**
  * @brief  This function allows to get the channel number from channel instance.
3564
  * @param  Instance DFSDM channel instance.
whj123999's avatar
whj123999 已提交
3565 3566
  * @retval Channel number.
  */
3567
static uint32_t DFSDM_GetChannelFromInstance(const DFSDM_Channel_TypeDef* Instance)
whj123999's avatar
whj123999 已提交
3568
{
3569
  uint32_t channel;
M
Mr.Tiger 已提交
3570

whj123999's avatar
whj123999 已提交
3571 3572 3573 3574 3575
  /* Get channel from instance */
  if(Instance == DFSDM1_Channel0)
  {
    channel = 0;
  }
M
Mr.Tiger 已提交
3576 3577 3578 3579 3580 3581 3582 3583 3584 3585
#if defined(DFSDM2_Channel0)
  else if (Instance == DFSDM2_Channel0)
  {
    channel = 0;
  }
  else if (Instance == DFSDM2_Channel1)
  {
    channel = 1;
  }
#endif /* DFSDM2_Channel0 */
whj123999's avatar
whj123999 已提交
3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609
  else if(Instance == DFSDM1_Channel1)
  {
    channel = 1;
  }
  else if(Instance == DFSDM1_Channel2)
  {
    channel = 2;
  }
  else if(Instance == DFSDM1_Channel3)
  {
    channel = 3;
  }
  else if(Instance == DFSDM1_Channel4)
  {
    channel = 4;
  }
  else if(Instance == DFSDM1_Channel5)
  {
    channel = 5;
  }
  else if(Instance == DFSDM1_Channel6)
  {
    channel = 6;
  }
M
Mr.Tiger 已提交
3610
  else /* DFSDM1_Channel7 */
whj123999's avatar
whj123999 已提交
3611
  {
M
Mr.Tiger 已提交
3612
      channel = 7;
3613
  }
M
Mr.Tiger 已提交
3614

whj123999's avatar
whj123999 已提交
3615 3616 3617 3618 3619
  return channel;
}

/**
  * @brief  This function allows to really start regular conversion.
3620
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3621 3622
  * @retval None
  */
M
Mr.Tiger 已提交
3623
static void DFSDM_RegConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
whj123999's avatar
whj123999 已提交
3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634
{
  /* Check regular trigger */
  if(hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER)
  {
    /* Software start of regular conversion */
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
  }
  else /* synchronous trigger */
  {
    /* Disable DFSDM filter */
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
M
Mr.Tiger 已提交
3635

whj123999's avatar
whj123999 已提交
3636 3637 3638 3639 3640
    /* Set RSYNC bit in DFSDM_FLTCR1 register */
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSYNC;

    /* Enable DFSDM  filter */
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
M
Mr.Tiger 已提交
3641

whj123999's avatar
whj123999 已提交
3642 3643 3644 3645 3646 3647 3648 3649 3650
    /* If injected conversion was in progress, restart it */
    if(hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ)
    {
      if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
      {
        hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
      }
      /* Update remaining injected conversions */
      hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
3651
                                         hdfsdm_filter->InjectedChannelsNbr : 1U;
whj123999's avatar
whj123999 已提交
3652 3653 3654 3655 3656 3657 3658 3659 3660
    }
  }
  /* Update DFSDM filter state */
  hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \
                          HAL_DFSDM_FILTER_STATE_REG : HAL_DFSDM_FILTER_STATE_REG_INJ;
}

/**
  * @brief  This function allows to really stop regular conversion.
3661
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3662 3663
  * @retval None
  */
M
Mr.Tiger 已提交
3664
static void DFSDM_RegConvStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
whj123999's avatar
whj123999 已提交
3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676
{
  /* Disable DFSDM filter */
  hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);

  /* If regular trigger was synchronous, reset RSYNC bit in DFSDM_FLTCR1 register */
  if(hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SYNC_TRIGGER)
  {
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_RSYNC);
  }

  /* Enable DFSDM filter */
  hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
M
Mr.Tiger 已提交
3677

whj123999's avatar
whj123999 已提交
3678 3679 3680 3681 3682 3683 3684 3685 3686
  /* If injected conversion was in progress, restart it */
  if(hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ)
  {
    if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
    {
      hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
    }
    /* Update remaining injected conversions */
    hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
3687
                                       hdfsdm_filter->InjectedChannelsNbr : 1U;
whj123999's avatar
whj123999 已提交
3688
  }
M
Mr.Tiger 已提交
3689

whj123999's avatar
whj123999 已提交
3690 3691 3692 3693 3694 3695 3696
  /* Update DFSDM filter state */
  hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) ? \
                          HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_INJ;
}

/**
  * @brief  This function allows to really start injected conversion.
3697
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3698 3699
  * @retval None
  */
M
Mr.Tiger 已提交
3700
static void DFSDM_InjConvStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
whj123999's avatar
whj123999 已提交
3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711
{
  /* Check injected trigger */
  if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SW_TRIGGER)
  {
    /* Software start of injected conversion */
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSWSTART;
  }
  else /* external or synchronous trigger */
  {
    /* Disable DFSDM filter */
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);
M
Mr.Tiger 已提交
3712

whj123999's avatar
whj123999 已提交
3713 3714 3715 3716 3717 3718 3719 3720 3721 3722
    if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER)
    {
      /* Set JSYNC bit in DFSDM_FLTCR1 register */
      hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_JSYNC;
    }
    else /* external trigger */
    {
      /* Set JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
      hdfsdm_filter->Instance->FLTCR1 |= hdfsdm_filter->ExtTriggerEdge;
    }
M
Mr.Tiger 已提交
3723

whj123999's avatar
whj123999 已提交
3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740
    /* Enable DFSDM filter */
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;

    /* If regular conversion was in progress, restart it */
    if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG) && \
       (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
    {
      hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
    }
  }
  /* Update DFSDM filter state */
  hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_READY) ? \
                         HAL_DFSDM_FILTER_STATE_INJ : HAL_DFSDM_FILTER_STATE_REG_INJ;
}

/**
  * @brief  This function allows to really stop injected conversion.
3741
  * @param  hdfsdm_filter DFSDM filter handle.
whj123999's avatar
whj123999 已提交
3742 3743
  * @retval None
  */
M
Mr.Tiger 已提交
3744
static void DFSDM_InjConvStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter)
whj123999's avatar
whj123999 已提交
3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758
{
  /* Disable DFSDM filter */
  hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_DFEN);

  /* If injected trigger was synchronous, reset JSYNC bit in DFSDM_FLTCR1 register */
  if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_SYNC_TRIGGER)
  {
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JSYNC);
  }
  else if(hdfsdm_filter->InjectedTrigger == DFSDM_FILTER_EXT_TRIGGER)
  {
    /* Reset JEXTEN[1:0] bits in DFSDM_FLTCR1 register */
    hdfsdm_filter->Instance->FLTCR1 &= ~(DFSDM_FLTCR1_JEXTEN);
  }
3759 3760 3761 3762
  else
  {
    /* Nothing to do */
  }
M
Mr.Tiger 已提交
3763

whj123999's avatar
whj123999 已提交
3764 3765
  /* Enable DFSDM filter */
  hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_DFEN;
M
Mr.Tiger 已提交
3766

whj123999's avatar
whj123999 已提交
3767 3768 3769 3770 3771 3772 3773 3774 3775
  /* If regular conversion was in progress, restart it */
  if((hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_REG_INJ) && \
     (hdfsdm_filter->RegularTrigger == DFSDM_FILTER_SW_TRIGGER))
  {
    hdfsdm_filter->Instance->FLTCR1 |= DFSDM_FLTCR1_RSWSTART;
  }

  /* Update remaining injected conversions */
  hdfsdm_filter->InjConvRemaining = (hdfsdm_filter->InjectedScanMode == ENABLE) ? \
3776
                                     hdfsdm_filter->InjectedChannelsNbr : 1U;
whj123999's avatar
whj123999 已提交
3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790

  /* Update DFSDM filter state */
  hdfsdm_filter->State = (hdfsdm_filter->State == HAL_DFSDM_FILTER_STATE_INJ) ? \
                          HAL_DFSDM_FILTER_STATE_READY : HAL_DFSDM_FILTER_STATE_REG;
}

/**
  * @}
  */
/* End of private functions --------------------------------------------------*/

/**
  * @}
  */
3791

whj123999's avatar
whj123999 已提交
3792
#endif /* HAL_DFSDM_MODULE_ENABLED */
3793

whj123999's avatar
whj123999 已提交
3794 3795 3796 3797 3798
/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/