Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / stm32h7xx_ll_ex.h
blobb846c430f03a6fc5a6cef2203340f1aea309350f
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) {
51 DMA_TypeDef *DMA = LL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
52 const uint32_t Stream = LL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
54 return LL_DMA_Init(DMA, Stream, DMA_InitStruct);
57 __STATIC_INLINE uint32_t LL_EX_DMA_DeInit(DMA_Stream_TypeDef *DMAx_Streamy) {
58 DMA_TypeDef *DMA = LL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
59 const uint32_t Stream = LL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
61 return LL_DMA_DeInit(DMA, Stream);
64 __STATIC_INLINE void LL_EX_DMA_EnableResource(DMA_Stream_TypeDef *DMAx_Streamy)
66 SET_BIT(DMAx_Streamy->CR, DMA_SxCR_EN);
69 __STATIC_INLINE void LL_EX_DMA_DisableResource(DMA_Stream_TypeDef *DMAx_Streamy)
71 CLEAR_BIT(DMAx_Streamy->CR, DMA_SxCR_EN);
74 __STATIC_INLINE void LL_EX_DMA_EnableIT_TC(DMA_Stream_TypeDef *DMAx_Streamy)
76 SET_BIT(DMAx_Streamy->CR, DMA_SxCR_TCIE);
79 __STATIC_INLINE void LL_EX_DMA_SetDataLength(DMA_Stream_TypeDef* DMAx_Streamy, uint32_t NbData)
81 MODIFY_REG(DMAx_Streamy->NDTR, DMA_SxNDT, NbData);
84 __STATIC_INLINE uint32_t LL_EX_DMA_GetDataLength(DMA_Stream_TypeDef* DMAx_Streamy)
86 DMA_TypeDef *DMA = LL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
87 const uint32_t Stream = LL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
88 return LL_DMA_GetDataLength(DMA, Stream);
91 __STATIC_INLINE void LL_EX_TIM_EnableIT(TIM_TypeDef *TIMx, uint32_t Sources)
93 SET_BIT(TIMx->DIER, Sources);
96 __STATIC_INLINE void LL_EX_TIM_DisableIT(TIM_TypeDef *TIMx, uint32_t Sources)
98 CLEAR_BIT(TIMx->DIER, Sources);
101 __STATIC_INLINE void LL_EX_TIM_CC_EnableNChannel(TIM_TypeDef *TIMx, uint32_t Channel)
103 LL_TIM_CC_EnableChannel(TIMx, 4 * Channel);