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)
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/>.
23 #include "stm32f7xx.h"
24 #include "common/utils.h"
26 #define DMA_STREAM_MASK 0xFFU
28 __STATIC_INLINE DMA_TypeDef
*LL_EX_DMA_Stream_to_DMA(DMA_Stream_TypeDef
*DMAx_Streamy
)
30 // clear stream address
31 return (DMA_TypeDef
*) (((uint32_t) DMAx_Streamy
) & ((uint32_t) ~DMA_STREAM_MASK
));
34 __STATIC_INLINE
uint32_t LL_EX_DMA_Stream_to_Stream(DMA_Stream_TypeDef
*DMAx_Streamy
)
36 STATIC_ASSERT(DMA1_Stream0_BASE
- DMA1_BASE
== sizeof(DMA_TypeDef
), DMA_TypeDef_has_padding
);
37 STATIC_ASSERT(DMA1_Stream1_BASE
- DMA1_Stream0_BASE
== sizeof(DMA_Stream_TypeDef
), DMA_Stream_TypeDef_has_padding
);
39 const size_t firstStreamOffset
= sizeof(DMA_TypeDef
);
40 const size_t streamSize
= sizeof(DMA_Stream_TypeDef
);
42 return (((uint32_t) DMAx_Streamy
& DMA_STREAM_MASK
) - firstStreamOffset
) / streamSize
;
45 #undef DMA_STREAM_MASK
47 __STATIC_INLINE
uint32_t LL_EX_DMA_Init(DMA_Stream_TypeDef
*DMAx_Streamy
, LL_DMA_InitTypeDef
*DMA_InitStruct
) {
48 DMA_TypeDef
*DMA
= LL_EX_DMA_Stream_to_DMA(DMAx_Streamy
);
49 const uint32_t Stream
= LL_EX_DMA_Stream_to_Stream(DMAx_Streamy
);
51 return LL_DMA_Init(DMA
, Stream
, DMA_InitStruct
);
54 __STATIC_INLINE
uint32_t LL_EX_DMA_DeInit(DMA_Stream_TypeDef
*DMAx_Streamy
) {
55 DMA_TypeDef
*DMA
= LL_EX_DMA_Stream_to_DMA(DMAx_Streamy
);
56 const uint32_t Stream
= LL_EX_DMA_Stream_to_Stream(DMAx_Streamy
);
58 return LL_DMA_DeInit(DMA
, Stream
);
61 __STATIC_INLINE
void LL_EX_DMA_SetChannelSelection(DMA_Stream_TypeDef
*DMAx_Streamy
, uint32_t Channel
)
63 MODIFY_REG(DMAx_Streamy
->CR
, DMA_SxCR_CHSEL
, Channel
);
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
);