268 #include "stm32h7xx_hal.h"
273 #ifdef HAL_DFSDM_MODULE_ENABLED
285 #define DFSDM_FLTCR1_MSB_RCH_OFFSET 8
286 #define DFSDM_MSB_MASK 0xFFFF0000U
287 #define DFSDM_LSB_MASK 0x0000FFFFU
288 #define DFSDM_CKAB_TIMEOUT 5000U
289 #define DFSDM1_CHANNEL_NUMBER 8U
290 #if defined(DFSDM2_Channel0)
291 #define DFSDM2_CHANNEL_NUMBER 2U
302 static __IO uint32_t v_dfsdm1ChannelCounter = 0;
304 #if defined(DFSDM2_Channel0)
305 static __IO uint32_t v_dfsdm2ChannelCounter = 0;
316 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels);
358 __IO uint32_t *channelCounterPtr;
363 if(hdfsdm_channel ==
NULL)
381 #if defined(DFSDM2_Channel0)
382 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
384 channelCounterPtr = &v_dfsdm1ChannelCounter;
385 channelHandleTable = a_dfsdm1ChannelHandle;
390 channelCounterPtr = &v_dfsdm2ChannelCounter;
391 channelHandleTable = a_dfsdm2ChannelHandle;
392 channel0Instance = DFSDM2_Channel0;
395 channelCounterPtr = &v_dfsdm1ChannelCounter;
396 channelHandleTable = a_dfsdm1ChannelHandle;
401 if (channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance)] !=
NULL)
406 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
412 if(hdfsdm_channel->MspInitCallback ==
NULL)
416 hdfsdm_channel->MspInitCallback(hdfsdm_channel);
423 (*channelCounterPtr)++;
426 if(*channelCounterPtr == 1U)
476 channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance)] = hdfsdm_channel;
488 __IO uint32_t *channelCounterPtr;
493 if(hdfsdm_channel ==
NULL)
501 #if defined(DFSDM2_Channel0)
502 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
504 channelCounterPtr = &v_dfsdm1ChannelCounter;
505 channelHandleTable = a_dfsdm1ChannelHandle;
510 channelCounterPtr = &v_dfsdm2ChannelCounter;
511 channelHandleTable = a_dfsdm2ChannelHandle;
512 channel0Instance = DFSDM2_Channel0;
515 channelCounterPtr = &v_dfsdm1ChannelCounter;
516 channelHandleTable = a_dfsdm1ChannelHandle;
521 if (channelHandleTable[DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance)] ==
NULL)
530 (*channelCounterPtr)--;
533 if (*channelCounterPtr == 0U)
539 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
540 if(hdfsdm_channel->MspDeInitCallback ==
NULL)
544 hdfsdm_channel->MspDeInitCallback(hdfsdm_channel);
588 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
603 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID,
604 pDFSDM_Channel_CallbackTypeDef pCallback)
608 if(pCallback ==
NULL)
619 case HAL_DFSDM_CHANNEL_CKAB_CB_ID :
620 hdfsdm_channel->CkabCallback = pCallback;
622 case HAL_DFSDM_CHANNEL_SCD_CB_ID :
623 hdfsdm_channel->ScdCallback = pCallback;
625 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
626 hdfsdm_channel->MspInitCallback = pCallback;
628 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
629 hdfsdm_channel->MspDeInitCallback = pCallback;
641 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
642 hdfsdm_channel->MspInitCallback = pCallback;
644 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
645 hdfsdm_channel->MspDeInitCallback = pCallback;
675 HAL_DFSDM_Channel_CallbackIDTypeDef CallbackID)
683 case HAL_DFSDM_CHANNEL_CKAB_CB_ID :
686 case HAL_DFSDM_CHANNEL_SCD_CB_ID :
689 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
692 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
705 case HAL_DFSDM_CHANNEL_MSPINIT_CB_ID :
708 case HAL_DFSDM_CHANNEL_MSPDEINIT_CB_ID :
765 #if defined(DFSDM2_Channel0)
766 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
772 filter0Instance = DFSDM2_Filter0;
787 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance);
832 #if defined(DFSDM2_Channel0)
833 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
839 filter0Instance = DFSDM2_Filter0;
854 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance);
865 if(((
HAL_GetTick()-tickstart) > Timeout) || (Timeout == 0U))
895 #if defined(DFSDM2_Channel0)
896 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
902 filter0Instance = DFSDM2_Filter0;
920 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance);
946 #if defined(DFSDM2_Channel0)
947 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
953 filter0Instance = DFSDM2_Filter0;
968 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance);
1030 #if defined(DFSDM2_Channel0)
1031 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
1037 filter0Instance = DFSDM2_Filter0;
1055 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance);
1077 uint32_t BreakSignal)
1122 #if defined(DFSDM2_Channel0)
1123 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
1129 filter0Instance = DFSDM2_Filter0;
1144 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance);
1155 if(((
HAL_GetTick()-tickstart) > Timeout) || (Timeout == 0U))
1185 #if defined(DFSDM2_Channel0)
1186 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
1192 filter0Instance = DFSDM2_Filter0;
1210 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance);
1229 uint32_t BreakSignal)
1239 #if defined(DFSDM2_Channel0)
1240 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
1246 filter0Instance = DFSDM2_Filter0;
1305 #if defined(DFSDM2_Channel0)
1306 if (IS_DFSDM1_CHANNEL_INSTANCE(hdfsdm_channel->
Instance))
1312 filter0Instance = DFSDM2_Filter0;
1330 channel = DFSDM_GetChannelFromInstance(hdfsdm_channel->
Instance);
1407 return hdfsdm_channel->
State;
1439 if(hdfsdm_filter ==
NULL)
1456 #if defined(DFSDM2_Channel0)
1457 if (IS_DFSDM1_FILTER_INSTANCE(hdfsdm_filter->
Instance))
1463 filter0Instance = DFSDM2_Filter0;
1470 if ((hdfsdm_filter->
Instance == filter0Instance) &&
1483 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1493 if(hdfsdm_filter->MspInitCallback ==
NULL)
1497 hdfsdm_filter->MspInitCallback(hdfsdm_filter);
1579 if(hdfsdm_filter ==
NULL)
1591 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1592 if(hdfsdm_filter->MspDeInitCallback ==
NULL)
1596 hdfsdm_filter->MspDeInitCallback(hdfsdm_filter);
1637 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
1655 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID,
1656 pDFSDM_Filter_CallbackTypeDef pCallback)
1660 if(pCallback ==
NULL)
1663 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1673 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID :
1674 hdfsdm_filter->RegConvCpltCallback = pCallback;
1676 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID :
1677 hdfsdm_filter->RegConvHalfCpltCallback = pCallback;
1679 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID :
1680 hdfsdm_filter->InjConvCpltCallback = pCallback;
1682 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID :
1683 hdfsdm_filter->InjConvHalfCpltCallback = pCallback;
1685 case HAL_DFSDM_FILTER_ERROR_CB_ID :
1686 hdfsdm_filter->ErrorCallback = pCallback;
1688 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
1689 hdfsdm_filter->MspInitCallback = pCallback;
1691 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
1692 hdfsdm_filter->MspDeInitCallback = pCallback;
1696 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1706 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
1707 hdfsdm_filter->MspInitCallback = pCallback;
1709 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
1710 hdfsdm_filter->MspDeInitCallback = pCallback;
1714 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1723 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1747 HAL_DFSDM_Filter_CallbackIDTypeDef CallbackID)
1755 case HAL_DFSDM_FILTER_REGCONV_COMPLETE_CB_ID :
1758 case HAL_DFSDM_FILTER_REGCONV_HALFCOMPLETE_CB_ID :
1761 case HAL_DFSDM_FILTER_INJCONV_COMPLETE_CB_ID :
1764 case HAL_DFSDM_FILTER_INJCONV_HALFCOMPLETE_CB_ID :
1767 case HAL_DFSDM_FILTER_ERROR_CB_ID :
1770 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
1773 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
1778 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1788 case HAL_DFSDM_FILTER_MSPINIT_CB_ID :
1791 case HAL_DFSDM_FILTER_MSPDEINIT_CB_ID :
1796 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1805 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1820 pDFSDM_Filter_AwdCallbackTypeDef pCallback)
1824 if(pCallback ==
NULL)
1827 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1835 hdfsdm_filter->AwdCallback = pCallback;
1840 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1865 hdfsdm_filter->
ErrorCode = DFSDM_FILTER_ERROR_INVALID_CALLBACK;
1903 uint32_t ContinuousMode)
1920 hdfsdm_filter->
Instance->
FLTCR1 |= (uint32_t) (((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET) |
1925 hdfsdm_filter->
Instance->
FLTCR1 |= (uint32_t) ((Channel & DFSDM_MSB_MASK) << DFSDM_FLTCR1_MSB_RCH_OFFSET);
2028 DFSDM_RegConvStart(hdfsdm_filter);
2071 if(((
HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
2083 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2084 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
2127 DFSDM_RegConvStop(hdfsdm_filter);
2155 DFSDM_RegConvStart(hdfsdm_filter);
2191 DFSDM_RegConvStop(hdfsdm_filter);
2219 if((pData ==
NULL) || (Length == 0U))
2250 DFSDM_DMARegularHalfConvCplt :
NULL;
2254 (uint32_t) pData, Length) !=
HAL_OK)
2263 DFSDM_RegConvStart(hdfsdm_filter);
2296 if((pData ==
NULL) || (Length == 0U))
2327 DFSDM_DMARegularHalfConvCplt :
NULL;
2331 (uint32_t) pData, Length) !=
HAL_OK)
2340 DFSDM_RegConvStart(hdfsdm_filter);
2383 DFSDM_RegConvStop(hdfsdm_filter);
2414 value = ((int32_t)reg) / 256;
2439 DFSDM_InjConvStart(hdfsdm_filter);
2482 if(((
HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
2494 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
2495 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
2548 DFSDM_InjConvStop(hdfsdm_filter);
2576 DFSDM_InjConvStart(hdfsdm_filter);
2612 DFSDM_InjConvStop(hdfsdm_filter);
2640 if((pData ==
NULL) || (Length == 0U))
2669 DFSDM_DMAInjectedHalfConvCplt :
NULL;
2673 (uint32_t) pData, Length) !=
HAL_OK)
2682 DFSDM_InjConvStart(hdfsdm_filter);
2715 if((pData ==
NULL) || (Length == 0U))
2744 DFSDM_DMAInjectedHalfConvCplt :
NULL;
2748 (uint32_t) pData, Length) !=
HAL_OK)
2757 DFSDM_InjConvStart(hdfsdm_filter);
2800 DFSDM_InjConvStop(hdfsdm_filter);
2831 value = ((int32_t)reg) / 256;
2873 awdParam->HighBreakSignal);
2876 awdParam->LowBreakSignal);
2881 DFSDM_FLTCR2_AWDIE);
3019 value = ((int32_t)reg) / 256;
3050 value = ((int32_t)reg) / 256;
3089 uint32_t channelNumber;
3095 #if defined(DFSDM2_Channel0)
3096 if (IS_DFSDM1_FILTER_INSTANCE(hdfsdm_filter->
Instance))
3098 channelHandleTable = a_dfsdm1ChannelHandle;
3100 channelNumber = DFSDM1_CHANNEL_NUMBER;
3104 channelHandleTable = a_dfsdm2ChannelHandle;
3105 filter0Instance = DFSDM2_Filter0;
3106 channelNumber = DFSDM2_CHANNEL_NUMBER;
3109 channelHandleTable = a_dfsdm1ChannelHandle;
3111 channelNumber = DFSDM1_CHANNEL_NUMBER;
3125 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3126 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
3142 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3143 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
3153 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3154 hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter);
3176 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3177 hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter);
3207 uint32_t channel = 0;
3216 while (((reg & 1U) == 0U) && (channel < (channelNumber - 1U)))
3227 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3228 hdfsdm_filter->AwdCallback(hdfsdm_filter, channel, threshold);
3234 else if((hdfsdm_filter->
Instance == filter0Instance) && \
3239 uint32_t channel = 0;
3243 while (channel < channelNumber)
3246 if (((reg & 1U) != 0U) && (channelHandleTable[channel] !=
NULL))
3255 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3256 channelHandleTable[channel]->CkabCallback(channelHandleTable[channel]);
3267 else if((hdfsdm_filter->
Instance == filter0Instance) && \
3272 uint32_t channel = 0;
3276 while (((reg & 1U) == 0U) && (channel < (channelNumber - 1U)))
3286 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3287 channelHandleTable[channel]->ScdCallback(channelHandleTable[channel]);
3366 uint32_t Channel, uint32_t Threshold)
3419 return hdfsdm_filter->
State;
3457 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3458 hdfsdm_filter->RegConvHalfCpltCallback(hdfsdm_filter);
3475 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3476 hdfsdm_filter->RegConvCpltCallback(hdfsdm_filter);
3493 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3494 hdfsdm_filter->InjConvHalfCpltCallback(hdfsdm_filter);
3511 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3512 hdfsdm_filter->InjConvCpltCallback(hdfsdm_filter);
3532 #if (USE_HAL_DFSDM_REGISTER_CALLBACKS == 1)
3533 hdfsdm_filter->ErrorCallback(hdfsdm_filter);
3544 static uint32_t DFSDM_GetInjChannelsNbr(uint32_t Channels)
3546 uint32_t nbChannels = 0;
3550 tmp = (uint32_t)(Channels & DFSDM_LSB_MASK);
3553 if((tmp & 1U) != 0U)
3557 tmp = (uint32_t)(tmp >> 1);
3576 #if defined(DFSDM2_Channel0)
3577 else if (Instance == DFSDM2_Channel0)
3581 else if (Instance == DFSDM2_Channel1)