Auto updated submodule references [18-01-2025]
[betaflight.git] / src / platform / APM32 / apm32f4xx_ddl_ex.h
blob187448df8d38189ea9f03e9cde81b1bb14a25b41
1 /*
2 * This file is part of Betaflight.
4 * Betaflight is free software. You can redistribute this software
5 * and/or modify this software under the terms of the GNU General
6 * Public License as published by the Free Software Foundation,
7 * either version 3 of the License, or (at your option) any later
8 * version.
10 * Betaflight is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this software.
19 * If not, see <http://www.gnu.org/licenses/>.
22 #pragma once
24 #include "apm32f4xx.h"
25 #include "common/utils.h"
27 // XXX Followings are straight copy of stm32f7xx_ll_ex.h.
28 // XXX Consider consolidation when LL-DShot is stable.
30 __STATIC_INLINE void DDL_EX_TMR_DisableIT(TMR_TypeDef *TMRx, uint32_t Sources)
32 CLEAR_BIT(TMRx->DIEN, Sources);
34 __STATIC_INLINE void DDL_EX_TMR_EnableIT(TMR_TypeDef *TMRx, uint32_t Sources)
36 SET_BIT(TMRx->DIEN, Sources);
38 __STATIC_INLINE uint32_t DDL_EX_DMA_Stream_to_Stream(DMA_Stream_TypeDef *DMAx_Streamy)
40 STATIC_ASSERT(DMA1_Stream0_BASE - DMA1_BASE == sizeof(DMA_TypeDef), DMA_TypeDef_has_padding);
41 STATIC_ASSERT(DMA1_Stream1_BASE - DMA1_Stream0_BASE == sizeof(DMA_Stream_TypeDef), DMA_Stream_TypeDef_has_padding);
43 const size_t firstStreamOffset = sizeof(DMA_TypeDef);
44 const size_t streamSize = sizeof(DMA_Stream_TypeDef);
46 return (((uint32_t) DMAx_Streamy & 0XFF) - firstStreamOffset) / streamSize;
48 __STATIC_INLINE DMA_TypeDef *DDL_EX_DMA_Stream_to_DMA(DMA_Stream_TypeDef *DMAx_Streamy)
50 // clear stream address
51 return (DMA_TypeDef *) (((uint32_t) DMAx_Streamy) & ((uint32_t) ~0XFF));
53 __STATIC_INLINE uint32_t DDL_EX_DMA_DeInit(DMA_Stream_TypeDef *DMAx_Streamy)
55 DMA_TypeDef *DMA = DDL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
56 const uint32_t Stream = DDL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
58 return DDL_DMA_DeInit(DMA, Stream);
60 __STATIC_INLINE uint32_t DDL_EX_DMA_Init(DMA_Stream_TypeDef *DMAx_Streamy, DDL_DMA_InitTypeDef *DMA_InitStruct)
62 DMA_TypeDef *DMA = DDL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
63 const uint32_t Stream = DDL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
65 return DDL_DMA_Init(DMA, Stream, DMA_InitStruct);
67 __STATIC_INLINE void DDL_EX_DMA_SetDataLength(DMA_Stream_TypeDef* DMAx_Streamy, uint32_t NbData)
69 MODIFY_REG(DMAx_Streamy->NDATA, DMA_NDATAx, NbData);
72 __STATIC_INLINE uint32_t DDL_EX_DMA_GetDataLength(DMA_Stream_TypeDef* DMAx_Streamy)
74 DMA_TypeDef *DMA = DDL_EX_DMA_Stream_to_DMA(DMAx_Streamy);
75 const uint32_t Stream = DDL_EX_DMA_Stream_to_Stream(DMAx_Streamy);
77 return DDL_DMA_GetDataLength(DMA, Stream);
80 __STATIC_INLINE void DDL_EX_DMA_EnableResource(DMA_Stream_TypeDef *DMAx_Streamy)
82 SET_BIT(DMAx_Streamy->SCFG, DMA_SCFGx_EN);
84 __STATIC_INLINE void DDL_EX_DMA_DisableResource(DMA_Stream_TypeDef *DMAx_Streamy)
86 CLEAR_BIT(DMAx_Streamy->SCFG, DMA_SCFGx_EN);
89 __STATIC_INLINE void DDL_EX_DMA_EnableIT_TC(DMA_Stream_TypeDef *DMAx_Streamy)
91 SET_BIT(DMAx_Streamy->SCFG, DMA_SCFGx_TXCIEN);
94 __STATIC_INLINE void DDL_EX_TMR_CC_EnableNChannel(TMR_TypeDef *TMRx, uint32_t Channel)
96 DDL_TMR_CC_EnableChannel(TMRx, 4 * Channel);