[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / drivers / stm32h7xx_ll_ex.h
blob8c28cdecd889cfa874be315998c892eb7a13c076
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "stm32h7xx.h"
24 #include "common/utils.h"
26 // XXX Followings are straight copy of stm32f7xx_ll_ex.h.
27 // XXX Consider consolidation when LL-DShot is stable.
29 #define DMA_STREAM_MASK 0xFFU
31 __STATIC_INLINE DMA_TypeDef *LL_EX_DMA_Stream_to_DMA(DMA_Stream_TypeDef *DMAx_Streamy)
33 // clear stream address
34 return (DMA_TypeDef *) (((uint32_t) DMAx_Streamy) & ((uint32_t) ~DMA_STREAM_MASK));
37 __STATIC_INLINE uint32_t LL_EX_DMA_Stream_to_Stream(DMA_Stream_TypeDef *DMAx_Streamy)
39 STATIC_ASSERT(DMA1_Stream0_BASE - DMA1_BASE == sizeof(DMA_TypeDef), DMA_TypeDef_has_padding);
40 STATIC_ASSERT(DMA1_Stream1_BASE - DMA1_Stream0_BASE == sizeof(DMA_Stream_TypeDef), DMA_Stream_TypeDef_has_padding);
42 const size_t firstStreamOffset = sizeof(DMA_TypeDef);
43 const size_t streamSize = sizeof(DMA_Stream_TypeDef);
45 return (((uint32_t) DMAx_Streamy & DMA_STREAM_MASK) - firstStreamOffset) / streamSize;
48 #undef DMA_STREAM_MASK
50 __STATIC_INLINE uint32_t LL_EX_DMA_Init(DMA_Stream_TypeDef *DMAx_Streamy, LL_DMA_InitTypeDef *DMA_InitStruct)
52 DMA_TypeDef *DMA = LL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
53 const uint32_t Stream = LL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
55 return LL_DMA_Init(DMA, Stream, DMA_InitStruct);
58 __STATIC_INLINE uint32_t LL_EX_DMA_DeInit(DMA_Stream_TypeDef *DMAx_Streamy)
60 DMA_TypeDef *DMA = LL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
61 const uint32_t Stream = LL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
63 return LL_DMA_DeInit(DMA, Stream);
66 __STATIC_INLINE void LL_EX_DMA_EnableResource(DMA_Stream_TypeDef *DMAx_Streamy)
68 SET_BIT(DMAx_Streamy->CR, DMA_SxCR_EN);
71 __STATIC_INLINE void LL_EX_DMA_DisableResource(DMA_Stream_TypeDef *DMAx_Streamy)
73 CLEAR_BIT(DMAx_Streamy->CR, DMA_SxCR_EN);
76 __STATIC_INLINE void LL_EX_DMA_EnableIT_TC(DMA_Stream_TypeDef *DMAx_Streamy)
78 SET_BIT(DMAx_Streamy->CR, DMA_SxCR_TCIE);
81 __STATIC_INLINE void LL_EX_DMA_SetDataLength(DMA_Stream_TypeDef* DMAx_Streamy, uint32_t NbData)
83 MODIFY_REG(DMAx_Streamy->NDTR, DMA_SxNDT, NbData);
86 __STATIC_INLINE uint32_t LL_EX_DMA_GetDataLength(DMA_Stream_TypeDef* DMAx_Streamy)
88 DMA_TypeDef *DMA = LL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
89 const uint32_t Stream = LL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
90 return LL_DMA_GetDataLength(DMA, Stream);
93 __STATIC_INLINE void LL_EX_TIM_EnableIT(TIM_TypeDef *TIMx, uint32_t Sources)
95 SET_BIT(TIMx->DIER, Sources);
98 __STATIC_INLINE void LL_EX_TIM_DisableIT(TIM_TypeDef *TIMx, uint32_t Sources)
100 CLEAR_BIT(TIMx->DIER, Sources);
103 __STATIC_INLINE void LL_EX_TIM_CC_EnableNChannel(TIM_TypeDef *TIMx, uint32_t Channel)
105 LL_TIM_CC_EnableChannel(TIMx, 4 * Channel);