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
)
49 DMA_TypeDef
*DMA
= LL_EX_DMA_Stream_to_DMA(DMAx_Streamy
);
50 const uint32_t Stream
= LL_EX_DMA_Stream_to_Stream(DMAx_Streamy
);
52 return LL_DMA_Init(DMA
, Stream
, DMA_InitStruct
);
55 __STATIC_INLINE
uint32_t LL_EX_DMA_DeInit(DMA_Stream_TypeDef
*DMAx_Streamy
)
57 DMA_TypeDef
*DMA
= LL_EX_DMA_Stream_to_DMA(DMAx_Streamy
);
58 const uint32_t Stream
= LL_EX_DMA_Stream_to_Stream(DMAx_Streamy
);
60 return LL_DMA_DeInit(DMA
, Stream
);
63 __STATIC_INLINE
void LL_EX_DMA_SetChannelSelection(DMA_Stream_TypeDef
*DMAx_Streamy
, uint32_t Channel
)
65 MODIFY_REG(DMAx_Streamy
->CR
, DMA_SxCR_CHSEL
, Channel
);
68 __STATIC_INLINE
void LL_EX_DMA_EnableResource(DMA_Stream_TypeDef
*DMAx_Streamy
)
70 SET_BIT(DMAx_Streamy
->CR
, DMA_SxCR_EN
);
73 __STATIC_INLINE
void LL_EX_DMA_DisableResource(DMA_Stream_TypeDef
*DMAx_Streamy
)
75 CLEAR_BIT(DMAx_Streamy
->CR
, DMA_SxCR_EN
);
78 __STATIC_INLINE
void LL_EX_DMA_EnableIT_TC(DMA_Stream_TypeDef
*DMAx_Streamy
)
80 SET_BIT(DMAx_Streamy
->CR
, DMA_SxCR_TCIE
);
83 __STATIC_INLINE
void LL_EX_DMA_SetDataLength(DMA_Stream_TypeDef
* DMAx_Streamy
, uint32_t NbData
)
85 MODIFY_REG(DMAx_Streamy
->NDTR
, DMA_SxNDT
, NbData
);
88 __STATIC_INLINE
uint32_t LL_EX_DMA_GetDataLength(DMA_Stream_TypeDef
* DMAx_Streamy
)
90 DMA_TypeDef
*DMA
= LL_EX_DMA_Stream_to_DMA(DMAx_Streamy
);
91 const uint32_t Stream
= LL_EX_DMA_Stream_to_Stream(DMAx_Streamy
);
92 return LL_DMA_GetDataLength(DMA
, Stream
);
95 __STATIC_INLINE
void LL_EX_TIM_EnableIT(TIM_TypeDef
*TIMx
, uint32_t Sources
)
97 SET_BIT(TIMx
->DIER
, Sources
);
100 __STATIC_INLINE
void LL_EX_TIM_DisableIT(TIM_TypeDef
*TIMx
, uint32_t Sources
)
102 CLEAR_BIT(TIMx
->DIER
, Sources
);
105 __STATIC_INLINE
void LL_EX_TIM_CC_EnableNChannel(TIM_TypeDef
*TIMx
, uint32_t Channel
)
107 LL_TIM_CC_EnableChannel(TIMx
, 4 * Channel
);