diff --git a/Makefile b/Makefile index 093d2bd5ca3..698f28567a9 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,8 @@ $(error Unknown target MCU specified.) endif GROUP_1_TARGETS := ALIENFLIGHTF3 ALIENFLIGHTF4 AIRHEROF3 AIRHEROF3_QUAD COLIBRI_RACE LUX_RACE SPARKY REVO SPARKY2 COLIBRI KISSFC FALCORE FF_F35_LIGHTNING FF_FORTINIF4 FF_PIKOF4 FF_PIKOF4OSD -GROUP_2_TARGETS := SPRACINGF3 SPRACINGF3EVO SPRACINGF3EVO_1SS SPRACINGF3MINI SPRACINGF3NEO SPRACINGF4EVO CLRACINGF4AIR CLRACINGF4AIRV2 BEEROTORF4 BETAFLIGHTF3 BETAFLIGHTF4 PIKOBLX +GROUP_2_TARGETS := SPRACINGF3 SPRACINGF3EVO SPRACINGF3EVO_1SS SPRACINGF3MINI SPRACINGF4EVO CLRACINGF4AIR CLRACINGF4AIRV2 BEEROTORF4 BETAFLIGHTF3 BETAFLIGHTF4 PIKOBLX +# SPRACINGF3NEO GROUP_3_TARGETS := OMNIBUS AIRBOTF4 BLUEJAYF4 OMNIBUSF4 OMNIBUSF4PRO OMNIBUSF4V3 FIREWORKSV2 SPARKY2 MATEKF405 OMNIBUSF7 DYSF4PRO OMNIBUSF4PRO_LEDSTRIPM5 OMNIBUSF7NXT OMNIBUSF7V2 ASGARD32F4 GROUP_4_TARGETS := ANYFC ANYFCF7 ANYFCF7_EXTERNAL_BARO ANYFCM7 ALIENFLIGHTNGF7 PIXRACER YUPIF4 YUPIF4MINI YUPIF4R2 YUPIF7 MATEKF405SE MATEKF411 MATEKF722 MATEKF405OSD MATEKF405_SERVOS6 GROUP_OTHER_TARGETS := $(filter-out $(GROUP_1_TARGETS) $(GROUP_2_TARGETS) $(GROUP_3_TARGETS) $(GROUP_4_TARGETS), $(VALID_TARGETS)) diff --git a/make/mcu/STM32F3.mk b/make/mcu/STM32F3.mk index 06cfa44e473..232ce7fe042 100644 --- a/make/mcu/STM32F3.mk +++ b/make/mcu/STM32F3.mk @@ -70,7 +70,7 @@ MCU_COMMON_SRC = \ drivers/accgyro/accgyro.c \ drivers/adc_stm32f30x.c \ drivers/bus_i2c_stm32f30x.c \ - drivers/dma.c \ + drivers/dma_stm32f3xx.c \ drivers/serial_uart_stm32f30x.c \ drivers/system_stm32f30x.c \ drivers/timer_impl_stdperiph.c \ diff --git a/src/main/common/memory.c b/src/main/common/memory.c index 977c6aad5a4..f6aea5c057b 100644 --- a/src/main/common/memory.c +++ b/src/main/common/memory.c @@ -33,7 +33,7 @@ #include "fc/runtime_config.h" #if !defined(DYNAMIC_HEAP_SIZE) -#define DYNAMIC_HEAP_SIZE (1024) +#define DYNAMIC_HEAP_SIZE (2048) #endif static uint32_t dynHeap[DYNAMIC_HEAP_SIZE / sizeof(uint32_t)]; diff --git a/src/main/common/utils.h b/src/main/common/utils.h index e3c41e9238b..a17f77d8195 100644 --- a/src/main/common/utils.h +++ b/src/main/common/utils.h @@ -28,12 +28,21 @@ #define CONCAT_HELPER(x,y) x ## y #define CONCAT(x,y) CONCAT_HELPER(x, y) +#define CONCAT4_HELPER(x, y, z, w) x ## y ## z ## w +#define CONCAT4(x, y, z, w) CONCAT4_HELPER(x, y, z, w) + #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) #define EXPAND_I(x) x #define EXPAND(x) EXPAND_I(x) +// Expand all argumens and call macro with them. When expansion of some argument contains ',', it will be passed as multiple arguments +// #define TAKE3(_1,_2,_3) CONCAT3(_1,_2,_3) +// #define MULTI2 A,B +// PP_CALL(TAKE3, MULTI2, C) expands to ABC +#define PP_CALL(macro, ...) macro(__VA_ARGS__) + #if !defined(UNUSED) #define UNUSED(x) (void)(x) #endif diff --git a/src/main/drivers/bus_spi.h b/src/main/drivers/bus_spi.h index 0653b03976f..22cb3e66ef6 100644 --- a/src/main/drivers/bus_spi.h +++ b/src/main/drivers/bus_spi.h @@ -19,6 +19,7 @@ #include "drivers/io_types.h" #include "drivers/rcc_types.h" +#include "drivers/dma.h" #if defined(STM32F4) || defined(STM32F3) #define SPI_IO_AF_CFG IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_NOPULL) @@ -74,7 +75,7 @@ typedef struct SPIDevice_s { #if defined(STM32F7) SPI_HandleTypeDef hspi; DMA_HandleTypeDef hdma; - uint8_t dmaIrqHandler; + dmaTag_t dmaTag; #endif const uint16_t * divisorMap; } spiDevice_t; diff --git a/src/main/drivers/bus_spi_hal.c b/src/main/drivers/bus_spi_hal.c index e279d254059..afc660f770d 100644 --- a/src/main/drivers/bus_spi_hal.c +++ b/src/main/drivers/bus_spi_hal.c @@ -84,10 +84,10 @@ static const uint16_t spiDivisorMapSlow[] = { }; static spiDevice_t spiHardwareMap[] = { - { .dev = SPI1, .nss = IO_TAG(SPI1_NSS_PIN), .sck = IO_TAG(SPI1_SCK_PIN), .miso = IO_TAG(SPI1_MISO_PIN), .mosi = IO_TAG(SPI1_MOSI_PIN), .rcc = RCC_APB2(SPI1), .af = GPIO_AF5_SPI1, .leadingEdge = false, .dmaIrqHandler = DMA2_ST3_HANDLER, .divisorMap = spiDivisorMapFast }, - { .dev = SPI2, .nss = IO_TAG(SPI2_NSS_PIN), .sck = IO_TAG(SPI2_SCK_PIN), .miso = IO_TAG(SPI2_MISO_PIN), .mosi = IO_TAG(SPI2_MOSI_PIN), .rcc = RCC_APB1(SPI2), .af = GPIO_AF5_SPI2, .leadingEdge = false, .dmaIrqHandler = DMA1_ST4_HANDLER, .divisorMap = spiDivisorMapSlow }, - { .dev = SPI3, .nss = IO_TAG(SPI3_NSS_PIN), .sck = IO_TAG(SPI3_SCK_PIN), .miso = IO_TAG(SPI3_MISO_PIN), .mosi = IO_TAG(SPI3_MOSI_PIN), .rcc = RCC_APB1(SPI3), .af = GPIO_AF6_SPI3, .leadingEdge = false, .dmaIrqHandler = DMA1_ST7_HANDLER, .divisorMap = spiDivisorMapSlow }, - { .dev = SPI4, .nss = IO_TAG(SPI4_NSS_PIN), .sck = IO_TAG(SPI4_SCK_PIN), .miso = IO_TAG(SPI4_MISO_PIN), .mosi = IO_TAG(SPI4_MOSI_PIN), .rcc = RCC_APB2(SPI4), .af = GPIO_AF5_SPI4, .leadingEdge = false, .dmaIrqHandler = DMA2_ST1_HANDLER, .divisorMap = spiDivisorMapSlow } + { .dev = SPI1, .nss = IO_TAG(SPI1_NSS_PIN), .sck = IO_TAG(SPI1_SCK_PIN), .miso = IO_TAG(SPI1_MISO_PIN), .mosi = IO_TAG(SPI1_MOSI_PIN), .rcc = RCC_APB2(SPI1), .af = GPIO_AF5_SPI1, .leadingEdge = false, .dmaTag = DMA_TAG(2,3,0), .divisorMap = spiDivisorMapFast }, + { .dev = SPI2, .nss = IO_TAG(SPI2_NSS_PIN), .sck = IO_TAG(SPI2_SCK_PIN), .miso = IO_TAG(SPI2_MISO_PIN), .mosi = IO_TAG(SPI2_MOSI_PIN), .rcc = RCC_APB1(SPI2), .af = GPIO_AF5_SPI2, .leadingEdge = false, .dmaTag = DMA_TAG(1,4,0), .divisorMap = spiDivisorMapSlow }, + { .dev = SPI3, .nss = IO_TAG(SPI3_NSS_PIN), .sck = IO_TAG(SPI3_SCK_PIN), .miso = IO_TAG(SPI3_MISO_PIN), .mosi = IO_TAG(SPI3_MOSI_PIN), .rcc = RCC_APB1(SPI3), .af = GPIO_AF6_SPI3, .leadingEdge = false, .dmaTag = DMA_TAG(1,7,0), .divisorMap = spiDivisorMapSlow }, + { .dev = SPI4, .nss = IO_TAG(SPI4_NSS_PIN), .sck = IO_TAG(SPI4_SCK_PIN), .miso = IO_TAG(SPI4_MISO_PIN), .mosi = IO_TAG(SPI4_MOSI_PIN), .rcc = RCC_APB2(SPI4), .af = GPIO_AF5_SPI4, .leadingEdge = false, .dmaTag = DMA_TAG(2,1,0), .divisorMap = spiDivisorMapSlow } }; SPIDevice spiDeviceByInstance(SPI_TypeDef *instance) @@ -354,7 +354,7 @@ DMA_HandleTypeDef* spiSetDMATransmit(DMA_Stream_TypeDef *Stream, uint32_t Channe __HAL_LINKDMA(&spiHardwareMap[device].hspi, hdmatx, spiHardwareMap[device].hdma); // DMA TX Interrupt - dmaSetHandler(spiHardwareMap[device].dmaIrqHandler, dmaSPIIRQHandler, NVIC_BUILD_PRIORITY(3, 0), (uint32_t)device); + dmaSetHandler(dmaGetByTag(spiHardwareMap[device].dmaTag), dmaSPIIRQHandler, NVIC_BUILD_PRIORITY(3, 0), (uint32_t)device); //HAL_CLEANCACHE(pData,Size); // And Transmit diff --git a/src/main/drivers/dma.c b/src/main/drivers/dma.c deleted file mode 100644 index a830efd0588..00000000000 --- a/src/main/drivers/dma.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This file is part of Cleanflight. - * - * Cleanflight is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Cleanflight is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cleanflight. If not, see . - */ - -#include -#include -#include - -#include - -#include "drivers/nvic.h" -#include "dma.h" - -/* - * DMA descriptors. - */ -static dmaChannelDescriptor_t dmaDescriptors[] = { - DEFINE_DMA_CHANNEL(DMA1, DMA1_Channel1, 0, DMA1_Channel1_IRQn, RCC_AHBPeriph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Channel2, 4, DMA1_Channel2_IRQn, RCC_AHBPeriph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Channel3, 8, DMA1_Channel3_IRQn, RCC_AHBPeriph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Channel4, 12, DMA1_Channel4_IRQn, RCC_AHBPeriph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Channel5, 16, DMA1_Channel5_IRQn, RCC_AHBPeriph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Channel6, 20, DMA1_Channel6_IRQn, RCC_AHBPeriph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Channel7, 24, DMA1_Channel7_IRQn, RCC_AHBPeriph_DMA1), -#if defined(STM32F3) - DEFINE_DMA_CHANNEL(DMA2, DMA2_Channel1, 0, DMA2_Channel1_IRQn, RCC_AHBPeriph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Channel2, 4, DMA2_Channel2_IRQn, RCC_AHBPeriph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Channel3, 8, DMA2_Channel3_IRQn, RCC_AHBPeriph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Channel4, 12, DMA2_Channel4_IRQn, RCC_AHBPeriph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Channel5, 16, DMA2_Channel5_IRQn, RCC_AHBPeriph_DMA2), -#endif -}; - -/* - * DMA IRQ Handlers - */ -DEFINE_DMA_IRQ_HANDLER(1, 1, DMA1_CH1_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 2, DMA1_CH2_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 3, DMA1_CH3_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 4, DMA1_CH4_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 5, DMA1_CH5_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 6, DMA1_CH6_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 7, DMA1_CH7_HANDLER) - -#if defined(STM32F3) -DEFINE_DMA_IRQ_HANDLER(2, 1, DMA2_CH1_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 2, DMA2_CH2_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 3, DMA2_CH3_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 4, DMA2_CH4_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 5, DMA2_CH5_HANDLER) -#endif - - -void dmaInit(dmaHandlerIdentifier_e identifier, resourceOwner_e owner, uint8_t resourceIndex) -{ - RCC_AHBPeriphClockCmd(dmaDescriptors[identifier].rcc, ENABLE); - dmaDescriptors[identifier].owner = owner; - dmaDescriptors[identifier].resourceIndex = resourceIndex; -} - -dmaHandlerIdentifier_e dmaFindHandlerIdentifier(DMA_Channel_TypeDef* channel) -{ - dmaHandlerIdentifier_e i; - - for (i = 0; i < (sizeof(dmaDescriptors) / sizeof(dmaDescriptors[0])); i++) { - if (channel == dmaDescriptors[i].ref) { - return i; - } - } - - // Shouldn't get here - return 0; -} - -void dmaEnableClock(dmaHandlerIdentifier_e identifier) -{ - RCC_AHBPeriphClockCmd(dmaDescriptors[identifier].rcc, ENABLE); -} - -void dmaSetHandler(dmaHandlerIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam) -{ - NVIC_InitTypeDef NVIC_InitStructure; - - dmaEnableClock(identifier); - - dmaDescriptors[identifier].irqHandlerCallback = callback; - dmaDescriptors[identifier].userParam = userParam; - - NVIC_InitStructure.NVIC_IRQChannel = dmaDescriptors[identifier].irqN; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(priority); - NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(priority); - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); -} - diff --git a/src/main/drivers/dma.h b/src/main/drivers/dma.h index 1adc3182c96..b9c9b5cd57f 100644 --- a/src/main/drivers/dma.h +++ b/src/main/drivers/dma.h @@ -15,49 +15,61 @@ * along with Cleanflight. If not, see . */ +#pragma once + #include "resource.h" struct dmaChannelDescriptor_s; -typedef void (*dmaCallbackHandlerFuncPtr)(struct dmaChannelDescriptor_s *channelDescriptor); + +typedef uint16_t dmaTag_t; // Packed DMA adapter/channel/stream +typedef struct dmaChannelDescriptor_s * DMA_t; + +#if defined(UNIT_TEST) +typedef uint32_t DMA_TypeDef; +#endif + +#define DMA_TAG(dma, stream, channel) ( (((dma) & 0x03) << 7) | (((stream) & 0x07) << 4) | (((channel) & 0x0F) << 0) ) +#define DMA_NONE (0) + +#define DMATAG_GET_DMA(x) ( ((x) >> 7) & 0x03 ) +#define DMATAG_GET_STREAM(x) ( ((x) >> 4) & 0x07 ) +#define DMATAG_GET_CHANNEL(x) ( ((x) >> 0) & 0x0F ) + +typedef void (*dmaCallbackHandlerFuncPtr)(DMA_t channelDescriptor); typedef struct dmaChannelDescriptor_s { + dmaTag_t tag; DMA_TypeDef* dma; -#if defined(STM32F4) || defined(STM32F7) +#if defined(STM32F4) + DMA_Stream_TypeDef* ref; +#elif defined(STM32F7) DMA_Stream_TypeDef* ref; + DMA_HandleTypeDef hdma; #else DMA_Channel_TypeDef* ref; #endif dmaCallbackHandlerFuncPtr irqHandlerCallback; - uint8_t flagsShift; - IRQn_Type irqN; + uint32_t flagsShift; + IRQn_Type irqNumber; uint32_t rcc; uint32_t userParam; resourceOwner_e owner; uint8_t resourceIndex; } dmaChannelDescriptor_t; -#if defined(STM32F4) || defined(STM32F7) +#if defined(STM32F4) + +#define DEFINE_DMA_CHANNEL(d, s, f) { \ + .tag = DMA_TAG(d, s, 0), \ + .dma = DMA##d, \ + .ref = DMA##d##_Stream##s, \ + .irqHandlerCallback = NULL, \ + .flagsShift = f, \ + .irqNumber = DMA##d##_Stream##s##_IRQn, \ + .rcc = RCC_AHB1Periph_DMA##d, \ + .userParam = 0 \ + } -typedef enum { - DMA1_ST0_HANDLER = 0, - DMA1_ST1_HANDLER, - DMA1_ST2_HANDLER, - DMA1_ST3_HANDLER, - DMA1_ST4_HANDLER, - DMA1_ST5_HANDLER, - DMA1_ST6_HANDLER, - DMA1_ST7_HANDLER, - DMA2_ST0_HANDLER, - DMA2_ST1_HANDLER, - DMA2_ST2_HANDLER, - DMA2_ST3_HANDLER, - DMA2_ST4_HANDLER, - DMA2_ST5_HANDLER, - DMA2_ST6_HANDLER, - DMA2_ST7_HANDLER, -} dmaHandlerIdentifier_e; - -#define DEFINE_DMA_CHANNEL(d, s, f, i, r) {.dma = d, .ref = s, .irqHandlerCallback = NULL, .flagsShift = f, .irqN = i, .rcc = r, .userParam = 0} #define DEFINE_DMA_IRQ_HANDLER(d, s, i) void DMA ## d ## _Stream ## s ## _IRQHandler(void) {\ if (dmaDescriptors[i].irqHandlerCallback)\ dmaDescriptors[i].irqHandlerCallback(&dmaDescriptors[i]);\ @@ -73,24 +85,47 @@ typedef enum { #define DMA_IT_DMEIF ((uint32_t)0x00000004) #define DMA_IT_FEIF ((uint32_t)0x00000001) -#else +#elif defined(STM32F7) + +#define DEFINE_DMA_CHANNEL(d, s, f) { \ + .tag = DMA_TAG(d, s, 0), \ + .dma = DMA##d, \ + .ref = DMA##d##_Stream##s, \ + .irqHandlerCallback = NULL, \ + .flagsShift = f, \ + .irqNumber = DMA##d##_Stream##s##_IRQn, \ + .rcc = RCC_AHB1ENR_DMA##d##EN, \ + .userParam = 0 \ + } + +#define DEFINE_DMA_IRQ_HANDLER(d, s, i) void DMA ## d ## _Stream ## s ## _IRQHandler(void) {\ + if (dmaDescriptors[i].irqHandlerCallback)\ + dmaDescriptors[i].irqHandlerCallback(&dmaDescriptors[i]);\ + } + +#define DMA_CLEAR_FLAG(d, flag) if (d->flagsShift > 31) d->dma->HIFCR = (flag << (d->flagsShift - 32)); else d->dma->LIFCR = (flag << d->flagsShift) +#define DMA_GET_FLAG_STATUS(d, flag) (d->flagsShift > 31 ? d->dma->HISR & (flag << (d->flagsShift - 32)): d->dma->LISR & (flag << d->flagsShift)) + + +#define DMA_IT_TCIF ((uint32_t)0x00000020) +#define DMA_IT_HTIF ((uint32_t)0x00000010) +#define DMA_IT_TEIF ((uint32_t)0x00000008) +#define DMA_IT_DMEIF ((uint32_t)0x00000004) +#define DMA_IT_FEIF ((uint32_t)0x00000001) + +#else // STM32F3 + +#define DEFINE_DMA_CHANNEL(d, c, f) { \ + .tag = DMA_TAG(d, 0, c), \ + .dma = DMA##d, \ + .ref = DMA##d##_Channel##c, \ + .irqHandlerCallback = NULL, \ + .flagsShift = f, \ + .irqNumber = DMA##d##_Channel##c##_IRQn, \ + .rcc = RCC_AHBPeriph_DMA##d, \ + .userParam = 0 \ + } -typedef enum { - DMA1_CH1_HANDLER = 0, - DMA1_CH2_HANDLER, - DMA1_CH3_HANDLER, - DMA1_CH4_HANDLER, - DMA1_CH5_HANDLER, - DMA1_CH6_HANDLER, - DMA1_CH7_HANDLER, - DMA2_CH1_HANDLER, - DMA2_CH2_HANDLER, - DMA2_CH3_HANDLER, - DMA2_CH4_HANDLER, - DMA2_CH5_HANDLER, -} dmaHandlerIdentifier_e; - -#define DEFINE_DMA_CHANNEL(d, c, f, i, r) {.dma = d, .ref = c, .irqHandlerCallback = NULL, .flagsShift = f, .irqN = i, .rcc = r, .userParam = 0} #define DEFINE_DMA_IRQ_HANDLER(d, c, i) void DMA ## d ## _Channel ## c ## _IRQHandler(void) {\ if (dmaDescriptors[i].irqHandlerCallback)\ dmaDescriptors[i].irqHandlerCallback(&dmaDescriptors[i]);\ @@ -105,18 +140,15 @@ typedef enum { #endif -#if defined(STM32F7) -//#define HAL_CLEANINVALIDATECACHE(addr, size) (SCB_CleanInvalidateDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f))) -//#define HAL_CLEANCACHE(addr, size) (SCB_CleanDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f))) -#endif - #if defined(STM32F4) || defined(STM32F7) -dmaHandlerIdentifier_e dmaFindHandlerIdentifier(DMA_Stream_TypeDef* stream); +DMA_t dmaFindHandlerIdentifier(DMA_Stream_TypeDef* stream); #else -dmaHandlerIdentifier_e dmaFindHandlerIdentifier(DMA_Channel_TypeDef* channel); +DMA_t dmaFindHandlerIdentifier(DMA_Channel_TypeDef* channel); #endif -void dmaInit(dmaHandlerIdentifier_e identifier, resourceOwner_e owner, uint8_t resourceIndex); -void dmaEnableClock(dmaHandlerIdentifier_e identifier); -void dmaSetHandler(dmaHandlerIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam); - +DMA_t dmaGetByTag(dmaTag_t tag); +uint32_t dmaGetChannelByTag(dmaTag_t tag); +void dmaInit(DMA_t dma, resourceOwner_e owner, uint8_t resourceIndex); +void dmaEnableClock(DMA_t dma); +void dmaSetHandler(DMA_t dma, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam); +void dmaCleanInterrupts(DMA_t dma); \ No newline at end of file diff --git a/src/main/drivers/dma_stm32f3xx.c b/src/main/drivers/dma_stm32f3xx.c new file mode 100644 index 00000000000..a9462213348 --- /dev/null +++ b/src/main/drivers/dma_stm32f3xx.c @@ -0,0 +1,113 @@ +/* + * This file is part of Cleanflight. + * + * Cleanflight is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cleanflight is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cleanflight. If not, see . + */ + +#include +#include +#include + +#include + +#include "build/debug.h" +#include "common/utils.h" +#include "drivers/nvic.h" +#include "drivers/dma.h" + +/* + * DMA descriptors. + */ +static dmaChannelDescriptor_t dmaDescriptors[] = { + [0] = DEFINE_DMA_CHANNEL(1, 1, 0), // DMA1_CH1 + [1] = DEFINE_DMA_CHANNEL(1, 2, 4), // DMA1_CH2 + [2] = DEFINE_DMA_CHANNEL(1, 3, 8), // DMA1_CH3 + [3] = DEFINE_DMA_CHANNEL(1, 4, 12), // DMA1_CH4 + [4] = DEFINE_DMA_CHANNEL(1, 5, 16), // DMA1_CH5 + [5] = DEFINE_DMA_CHANNEL(1, 6, 20), // DMA1_CH6 + [6] = DEFINE_DMA_CHANNEL(1, 7, 24), // DMA1_CH7 + + [7] = DEFINE_DMA_CHANNEL(2, 1, 0), // DMA2_CH1 + [8] = DEFINE_DMA_CHANNEL(2, 2, 4), // DMA2_CH2 + [9] = DEFINE_DMA_CHANNEL(2, 3, 8), // DMA2_CH3 + [10] = DEFINE_DMA_CHANNEL(2, 4, 12), // DMA2_CH4 + [11] = DEFINE_DMA_CHANNEL(2, 5, 16), // DMA2_CH5 +}; + +/* + * DMA IRQ Handlers + */ +DEFINE_DMA_IRQ_HANDLER(1, 1, 0) // // DMA1_CH1 = dmaDescriptors[0] +DEFINE_DMA_IRQ_HANDLER(1, 2, 1) +DEFINE_DMA_IRQ_HANDLER(1, 3, 2) +DEFINE_DMA_IRQ_HANDLER(1, 4, 3) +DEFINE_DMA_IRQ_HANDLER(1, 5, 4) +DEFINE_DMA_IRQ_HANDLER(1, 6, 5) +DEFINE_DMA_IRQ_HANDLER(1, 7, 6) +DEFINE_DMA_IRQ_HANDLER(2, 1, 7) +DEFINE_DMA_IRQ_HANDLER(2, 2, 8) +DEFINE_DMA_IRQ_HANDLER(2, 3, 9) +DEFINE_DMA_IRQ_HANDLER(2, 4, 10) +DEFINE_DMA_IRQ_HANDLER(2, 5, 11) + +DMA_t dmaGetByTag(dmaTag_t tag) +{ + for (unsigned i = 0; i < ARRAYLEN(dmaDescriptors); i++) { + // On F3 we match DMA and Channel, stream not used + if (DMATAG_GET_DMA(dmaDescriptors[i].tag) == DMATAG_GET_DMA(tag) && DMATAG_GET_CHANNEL(dmaDescriptors[i].tag) == DMATAG_GET_CHANNEL(tag)) { + return (DMA_t)&dmaDescriptors[i]; + } + } + + return (DMA_t) NULL; +} + +void dmaEnableClock(DMA_t dma) +{ + RCC_AHBPeriphClockCmd(dma->rcc, ENABLE); +} + +void dmaInit(DMA_t dma, resourceOwner_e owner, uint8_t resourceIndex) +{ + dmaEnableClock(dma); + dma->owner = owner; + dma->resourceIndex = resourceIndex; +} + +void dmaSetHandler(DMA_t dma, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam) +{ + NVIC_InitTypeDef NVIC_InitStructure; + + dmaEnableClock(dma); + + dma->irqHandlerCallback = callback; + dma->userParam = userParam; + + NVIC_InitStructure.NVIC_IRQChannel = dma->irqNumber; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(priority); + NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(priority); + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +DMA_t dmaFindHandlerIdentifier(DMA_Channel_TypeDef* channel) +{ + for (unsigned i = 0; i < (sizeof(dmaDescriptors) / sizeof(dmaDescriptors[0])); i++) { + if (channel == dmaDescriptors[i].ref) { + return &dmaDescriptors[i]; + } + } + + return NULL; +} diff --git a/src/main/drivers/dma_stm32f4xx.c b/src/main/drivers/dma_stm32f4xx.c index 259fe942a25..c27bb52508a 100644 --- a/src/main/drivers/dma_stm32f4xx.c +++ b/src/main/drivers/dma_stm32f4xx.c @@ -21,91 +21,107 @@ #include +#include "build/debug.h" +#include "common/utils.h" #include "drivers/nvic.h" -#include "dma.h" +#include "drivers/dma.h" /* * DMA descriptors. */ static dmaChannelDescriptor_t dmaDescriptors[] = { - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream0, 0, DMA1_Stream0_IRQn, RCC_AHB1Periph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream1, 6, DMA1_Stream1_IRQn, RCC_AHB1Periph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream2, 16, DMA1_Stream2_IRQn, RCC_AHB1Periph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream3, 22, DMA1_Stream3_IRQn, RCC_AHB1Periph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream4, 32, DMA1_Stream4_IRQn, RCC_AHB1Periph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream5, 38, DMA1_Stream5_IRQn, RCC_AHB1Periph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream6, 48, DMA1_Stream6_IRQn, RCC_AHB1Periph_DMA1), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream7, 54, DMA1_Stream7_IRQn, RCC_AHB1Periph_DMA1), - - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream0, 0, DMA2_Stream0_IRQn, RCC_AHB1Periph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream1, 6, DMA2_Stream1_IRQn, RCC_AHB1Periph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream2, 16, DMA2_Stream2_IRQn, RCC_AHB1Periph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream3, 22, DMA2_Stream3_IRQn, RCC_AHB1Periph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream4, 32, DMA2_Stream4_IRQn, RCC_AHB1Periph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream5, 38, DMA2_Stream5_IRQn, RCC_AHB1Periph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream6, 48, DMA2_Stream6_IRQn, RCC_AHB1Periph_DMA2), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream7, 54, DMA2_Stream7_IRQn, RCC_AHB1Periph_DMA2), + [0] = DEFINE_DMA_CHANNEL(1, 0, 0), // DMA1_ST0 + [1] = DEFINE_DMA_CHANNEL(1, 1, 6), // DMA1_ST1 + [2] = DEFINE_DMA_CHANNEL(1, 2, 16), // DMA1_ST2 + [3] = DEFINE_DMA_CHANNEL(1, 3, 22), // DMA1_ST3 + [4] = DEFINE_DMA_CHANNEL(1, 4, 32), // DMA1_ST4 + [5] = DEFINE_DMA_CHANNEL(1, 5, 38), // DMA1_ST5 + [6] = DEFINE_DMA_CHANNEL(1, 6, 48), // DMA1_ST6 + [7] = DEFINE_DMA_CHANNEL(1, 7, 54), // DMA1_ST7 + + [8] = DEFINE_DMA_CHANNEL(2, 0, 0), // DMA2_ST0 + [9] = DEFINE_DMA_CHANNEL(2, 1, 6), // DMA2_ST1 + [10] = DEFINE_DMA_CHANNEL(2, 2, 16), // DMA2_ST2 + [11] = DEFINE_DMA_CHANNEL(2, 3, 22), // DMA2_ST3 + [12] = DEFINE_DMA_CHANNEL(2, 4, 32), // DMA2_ST4 + [13] = DEFINE_DMA_CHANNEL(2, 5, 38), // DMA2_ST5 + [14] = DEFINE_DMA_CHANNEL(2, 6, 48), // DMA2_ST6 + [15] = DEFINE_DMA_CHANNEL(2, 7, 54) // DMA2_ST7 }; /* * DMA IRQ Handlers */ -DEFINE_DMA_IRQ_HANDLER(1, 0, DMA1_ST0_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 1, DMA1_ST1_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 2, DMA1_ST2_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 3, DMA1_ST3_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 4, DMA1_ST4_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 5, DMA1_ST5_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 6, DMA1_ST6_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 7, DMA1_ST7_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 0, DMA2_ST0_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 1, DMA2_ST1_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 2, DMA2_ST2_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 3, DMA2_ST3_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 4, DMA2_ST4_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 5, DMA2_ST5_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 6, DMA2_ST6_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 7, DMA2_ST7_HANDLER) - -void dmaInit(dmaHandlerIdentifier_e identifier, resourceOwner_e owner, uint8_t resourceIndex) +DEFINE_DMA_IRQ_HANDLER(1, 0, 0) // DMA1_ST0 = dmaDescriptors[0] +DEFINE_DMA_IRQ_HANDLER(1, 1, 1) +DEFINE_DMA_IRQ_HANDLER(1, 2, 2) +DEFINE_DMA_IRQ_HANDLER(1, 3, 3) +DEFINE_DMA_IRQ_HANDLER(1, 4, 4) +DEFINE_DMA_IRQ_HANDLER(1, 5, 5) +DEFINE_DMA_IRQ_HANDLER(1, 6, 6) +DEFINE_DMA_IRQ_HANDLER(1, 7, 7) +DEFINE_DMA_IRQ_HANDLER(2, 0, 8) +DEFINE_DMA_IRQ_HANDLER(2, 1, 9) +DEFINE_DMA_IRQ_HANDLER(2, 2, 10) +DEFINE_DMA_IRQ_HANDLER(2, 3, 11) +DEFINE_DMA_IRQ_HANDLER(2, 4, 12) +DEFINE_DMA_IRQ_HANDLER(2, 5, 13) +DEFINE_DMA_IRQ_HANDLER(2, 6, 14) +DEFINE_DMA_IRQ_HANDLER(2, 7, 15) + +DMA_t dmaGetByTag(dmaTag_t tag) { - RCC_AHB1PeriphClockCmd(dmaDescriptors[identifier].rcc, ENABLE); - dmaDescriptors[identifier].owner = owner; - dmaDescriptors[identifier].resourceIndex = resourceIndex; -} - -dmaHandlerIdentifier_e dmaFindHandlerIdentifier(DMA_Stream_TypeDef* stream) -{ - dmaHandlerIdentifier_e i; - - for (i = 0; i < (sizeof(dmaDescriptors) / sizeof(dmaDescriptors[0])); i++) { - if (stream == dmaDescriptors[i].ref) { - return i; + for (unsigned i = 0; i < ARRAYLEN(dmaDescriptors); i++) { + // On F4/F7 we match only DMA and Stream. Channel is needed when connecting DMA to peripheral + if (DMATAG_GET_DMA(dmaDescriptors[i].tag) == DMATAG_GET_DMA(tag) && DMATAG_GET_STREAM(dmaDescriptors[i].tag) == DMATAG_GET_STREAM(tag)) { + return (DMA_t)&dmaDescriptors[i]; } } - // Shouldn't get here - return 0; + return (DMA_t) NULL; } -void dmaEnableClock(dmaHandlerIdentifier_e identifier) +void dmaEnableClock(DMA_t dma) { - RCC_AHB1PeriphClockCmd(dmaDescriptors[identifier].rcc, ENABLE); + RCC_AHB1PeriphClockCmd(dma->rcc, ENABLE); } -void dmaSetHandler(dmaHandlerIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam) +void dmaInit(DMA_t dma, resourceOwner_e owner, uint8_t resourceIndex) +{ + dmaEnableClock(dma); + dma->owner = owner; + dma->resourceIndex = resourceIndex; +} + +void dmaSetHandler(DMA_t dma, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam) { NVIC_InitTypeDef NVIC_InitStructure; - dmaEnableClock(identifier); + dmaEnableClock(dma); - dmaDescriptors[identifier].irqHandlerCallback = callback; - dmaDescriptors[identifier].userParam = userParam; + dma->irqHandlerCallback = callback; + dma->userParam = userParam; - NVIC_InitStructure.NVIC_IRQChannel = dmaDescriptors[identifier].irqN; + NVIC_InitStructure.NVIC_IRQChannel = dma->irqNumber; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(priority); NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(priority); NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } +uint32_t dmaGetChannelByTag(dmaTag_t tag) +{ + static const uint32_t dmaChannel[8] = { DMA_Channel_0, DMA_Channel_1, DMA_Channel_2, DMA_Channel_3, DMA_Channel_4, DMA_Channel_5, DMA_Channel_6, DMA_Channel_7 }; + return dmaChannel[DMATAG_GET_CHANNEL(tag)]; +} + +DMA_t dmaFindHandlerIdentifier(DMA_Stream_TypeDef * stream) +{ + for (unsigned i = 0; i < (sizeof(dmaDescriptors) / sizeof(dmaDescriptors[0])); i++) { + if (stream == dmaDescriptors[i].ref) { + return &dmaDescriptors[i]; + } + } + + return NULL; +} diff --git a/src/main/drivers/dma_stm32f7xx.c b/src/main/drivers/dma_stm32f7xx.c index baee3efae5c..c74e8649e11 100644 --- a/src/main/drivers/dma_stm32f7xx.c +++ b/src/main/drivers/dma_stm32f7xx.c @@ -21,6 +21,7 @@ #include +#include "common/utils.h" #include "drivers/nvic.h" #include "drivers/dma.h" @@ -28,82 +29,88 @@ * DMA descriptors. */ static dmaChannelDescriptor_t dmaDescriptors[] = { - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream0, 0, DMA1_Stream0_IRQn, RCC_AHB1ENR_DMA1EN), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream1, 6, DMA1_Stream1_IRQn, RCC_AHB1ENR_DMA1EN), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream2, 16, DMA1_Stream2_IRQn, RCC_AHB1ENR_DMA1EN), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream3, 22, DMA1_Stream3_IRQn, RCC_AHB1ENR_DMA1EN), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream4, 32, DMA1_Stream4_IRQn, RCC_AHB1ENR_DMA1EN), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream5, 38, DMA1_Stream5_IRQn, RCC_AHB1ENR_DMA1EN), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream6, 48, DMA1_Stream6_IRQn, RCC_AHB1ENR_DMA1EN), - DEFINE_DMA_CHANNEL(DMA1, DMA1_Stream7, 54, DMA1_Stream7_IRQn, RCC_AHB1ENR_DMA1EN), - - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream0, 0, DMA2_Stream0_IRQn, RCC_AHB1ENR_DMA2EN), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream1, 6, DMA2_Stream1_IRQn, RCC_AHB1ENR_DMA2EN), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream2, 16, DMA2_Stream2_IRQn, RCC_AHB1ENR_DMA2EN), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream3, 22, DMA2_Stream3_IRQn, RCC_AHB1ENR_DMA2EN), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream4, 32, DMA2_Stream4_IRQn, RCC_AHB1ENR_DMA2EN), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream5, 38, DMA2_Stream5_IRQn, RCC_AHB1ENR_DMA2EN), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream6, 48, DMA2_Stream6_IRQn, RCC_AHB1ENR_DMA2EN), - DEFINE_DMA_CHANNEL(DMA2, DMA2_Stream7, 54, DMA2_Stream7_IRQn, RCC_AHB1ENR_DMA2EN), + [0] = DEFINE_DMA_CHANNEL(1, 0, 0), // DMA1_ST0 + [1] = DEFINE_DMA_CHANNEL(1, 1, 6), // DMA1_ST1 + [2] = DEFINE_DMA_CHANNEL(1, 2, 16), // DMA1_ST2 + [3] = DEFINE_DMA_CHANNEL(1, 3, 22), // DMA1_ST3 + [4] = DEFINE_DMA_CHANNEL(1, 4, 32), // DMA1_ST4 + [5] = DEFINE_DMA_CHANNEL(1, 5, 38), // DMA1_ST5 + [6] = DEFINE_DMA_CHANNEL(1, 6, 48), // DMA1_ST6 + [7] = DEFINE_DMA_CHANNEL(1, 7, 54), // DMA1_ST7 + [8] = DEFINE_DMA_CHANNEL(2, 0, 0), // DMA2_ST0 + [9] = DEFINE_DMA_CHANNEL(2, 1, 6), // DMA2_ST1 + [10] = DEFINE_DMA_CHANNEL(2, 2, 16), // DMA2_ST2 + [11] = DEFINE_DMA_CHANNEL(2, 3, 22), // DMA2_ST3 + [12] = DEFINE_DMA_CHANNEL(2, 4, 32), // DMA2_ST4 + [13] = DEFINE_DMA_CHANNEL(2, 5, 38), // DMA2_ST5 + [14] = DEFINE_DMA_CHANNEL(2, 6, 48), // DMA2_ST6 + [15] = DEFINE_DMA_CHANNEL(2, 7, 54) // DMA2_ST7 }; /* * DMA IRQ Handlers */ -DEFINE_DMA_IRQ_HANDLER(1, 0, DMA1_ST0_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 1, DMA1_ST1_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 2, DMA1_ST2_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 3, DMA1_ST3_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 4, DMA1_ST4_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 5, DMA1_ST5_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 6, DMA1_ST6_HANDLER) -DEFINE_DMA_IRQ_HANDLER(1, 7, DMA1_ST7_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 0, DMA2_ST0_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 1, DMA2_ST1_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 2, DMA2_ST2_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 3, DMA2_ST3_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 4, DMA2_ST4_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 5, DMA2_ST5_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 6, DMA2_ST6_HANDLER) -DEFINE_DMA_IRQ_HANDLER(2, 7, DMA2_ST7_HANDLER) +DEFINE_DMA_IRQ_HANDLER(1, 0, 0) // DMA1_ST0 = dmaDescriptors[0] +DEFINE_DMA_IRQ_HANDLER(1, 1, 1) +DEFINE_DMA_IRQ_HANDLER(1, 2, 2) +DEFINE_DMA_IRQ_HANDLER(1, 3, 3) +DEFINE_DMA_IRQ_HANDLER(1, 4, 4) +DEFINE_DMA_IRQ_HANDLER(1, 5, 5) +DEFINE_DMA_IRQ_HANDLER(1, 6, 6) +DEFINE_DMA_IRQ_HANDLER(1, 7, 7) +DEFINE_DMA_IRQ_HANDLER(2, 0, 8) +DEFINE_DMA_IRQ_HANDLER(2, 1, 9) +DEFINE_DMA_IRQ_HANDLER(2, 2, 10) +DEFINE_DMA_IRQ_HANDLER(2, 3, 11) +DEFINE_DMA_IRQ_HANDLER(2, 4, 12) +DEFINE_DMA_IRQ_HANDLER(2, 5, 13) +DEFINE_DMA_IRQ_HANDLER(2, 6, 14) +DEFINE_DMA_IRQ_HANDLER(2, 7, 15) -static void enableDmaClock(uint32_t rcc) +DMA_t dmaGetByTag(dmaTag_t tag) +{ + for (unsigned i = 0; i < ARRAYLEN(dmaDescriptors); i++) { + // On F4/F7 we match only DMA and Stream. Channel is needed when connecting DMA to peripheral + if (DMATAG_GET_DMA(dmaDescriptors[i].tag) == DMATAG_GET_DMA(tag) && DMATAG_GET_STREAM(dmaDescriptors[i].tag) == DMATAG_GET_STREAM(tag)) { + return (DMA_t)&dmaDescriptors[i]; + } + } + + return (DMA_t) NULL; +} + +void dmaEnableClock(DMA_t dma) { do { __IO uint32_t tmpreg; - SET_BIT(RCC->AHB1ENR, rcc); + SET_BIT(RCC->AHB1ENR, dma->rcc); /* Delay after an RCC peripheral clock enabling */ - tmpreg = READ_BIT(RCC->AHB1ENR, rcc); + tmpreg = READ_BIT(RCC->AHB1ENR, dma->rcc); UNUSED(tmpreg); } while (0); } -void dmaInit(dmaHandlerIdentifier_e identifier, resourceOwner_e owner, uint8_t resourceIndex) +void dmaInit(DMA_t dma, resourceOwner_e owner, uint8_t resourceIndex) { - enableDmaClock(dmaDescriptors[identifier].rcc); - dmaDescriptors[identifier].owner = owner; - dmaDescriptors[identifier].resourceIndex = resourceIndex; + dmaEnableClock(dma); + dma->owner = owner; + dma->resourceIndex = resourceIndex; } -void dmaSetHandler(dmaHandlerIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam) +void dmaSetHandler(DMA_t dma, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam) { - //clock - //RCC_AHB1PeriphClockCmd(dmaDescriptors[identifier].rcc, ENABLE); - - do { - __IO uint32_t tmpreg; - SET_BIT(RCC->AHB1ENR, dmaDescriptors[identifier].rcc); - /* Delay after an RCC peripheral clock enabling */ - tmpreg = READ_BIT(RCC->AHB1ENR, dmaDescriptors[identifier].rcc); - UNUSED(tmpreg); - } while (0); + dmaEnableClock(dma); - dmaDescriptors[identifier].irqHandlerCallback = callback; - dmaDescriptors[identifier].userParam = userParam; + dma->irqHandlerCallback = callback; + dma->userParam = userParam; - - HAL_NVIC_SetPriority(dmaDescriptors[identifier].irqN, NVIC_PRIORITY_BASE(priority), NVIC_PRIORITY_SUB(priority)); - HAL_NVIC_EnableIRQ(dmaDescriptors[identifier].irqN); + HAL_NVIC_SetPriority(dma->irqNumber, NVIC_PRIORITY_BASE(priority), NVIC_PRIORITY_SUB(priority)); + HAL_NVIC_EnableIRQ(dma->irqNumber); } +uint32_t dmaGetChannelByTag(dmaTag_t tag) +{ + static const uint32_t dmaChannel[8] = { DMA_CHANNEL_0, DMA_CHANNEL_1, DMA_CHANNEL_2, DMA_CHANNEL_3, DMA_CHANNEL_4, DMA_CHANNEL_5, DMA_CHANNEL_6, DMA_CHANNEL_7 }; + return dmaChannel[DMATAG_GET_CHANNEL(tag)]; +} diff --git a/src/main/drivers/io.h b/src/main/drivers/io.h index 0cc43017eff..bc888ccef9c 100644 --- a/src/main/drivers/io.h +++ b/src/main/drivers/io.h @@ -41,6 +41,7 @@ #define IOCFG_OUT_PP IO_CONFIG(GPIO_MODE_OUTPUT_PP, GPIO_SPEED_FREQ_LOW, GPIO_NOPULL) #define IOCFG_OUT_PP_25 IO_CONFIG(GPIO_MODE_OUTPUT_PP, GPIO_SPEED_FREQ_HIGH, GPIO_NOPULL) #define IOCFG_OUT_OD IO_CONFIG(GPIO_MODE_OUTPUT_OD, GPIO_SPEED_FREQ_LOW, GPIO_NOPULL) +#define IOCFG_AF_PP_FAST IO_CONFIG(GPIO_MODE_AF_PP, GPIO_SPEED_FREQ_VERY_HIGH, GPIO_PULLDOWN) #define IOCFG_AF_PP IO_CONFIG(GPIO_MODE_AF_PP, GPIO_SPEED_FREQ_LOW, GPIO_NOPULL) #define IOCFG_AF_PP_PD IO_CONFIG(GPIO_MODE_AF_PP, GPIO_SPEED_FREQ_LOW, GPIO_PULLDOWN) #define IOCFG_AF_PP_UP IO_CONFIG(GPIO_MODE_AF_PP, GPIO_SPEED_FREQ_LOW, GPIO_PULLUP) @@ -57,6 +58,7 @@ #define IOCFG_OUT_PP IO_CONFIG(GPIO_Mode_OUT, 0, GPIO_OType_PP, GPIO_PuPd_NOPULL) // TODO #define IOCFG_OUT_PP_25 IO_CONFIG(GPIO_Mode_OUT, GPIO_Speed_25MHz, GPIO_OType_PP, GPIO_PuPd_NOPULL) #define IOCFG_OUT_OD IO_CONFIG(GPIO_Mode_OUT, 0, GPIO_OType_OD, GPIO_PuPd_NOPULL) +#define IOCFG_AF_PP_FAST IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_DOWN) #define IOCFG_AF_PP IO_CONFIG(GPIO_Mode_AF, 0, GPIO_OType_PP, GPIO_PuPd_NOPULL) #define IOCFG_AF_PP_PD IO_CONFIG(GPIO_Mode_AF, 0, GPIO_OType_PP, GPIO_PuPd_DOWN) #define IOCFG_AF_PP_UP IO_CONFIG(GPIO_Mode_AF, 0, GPIO_OType_PP, GPIO_PuPd_UP) diff --git a/src/main/drivers/light_ws2811strip.c b/src/main/drivers/light_ws2811strip.c index cbf0ac93e83..0bb02c98a31 100644 --- a/src/main/drivers/light_ws2811strip.c +++ b/src/main/drivers/light_ws2811strip.c @@ -33,22 +33,23 @@ #ifdef USE_LED_STRIP #include "build/build_config.h" +#include "build/debug.h" #include "common/color.h" #include "common/colorconversion.h" -#include "dma.h" + +#include "drivers/dma.h" #include "drivers/io.h" -#include "light_ws2811strip.h" +#include "drivers/timer.h" +#include "drivers/light_ws2811strip.h" -#if defined(STM32F4) || defined(STM32F7) -uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; -#else -uint8_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; -#endif -volatile uint8_t ws2811LedDataTransferInProgress = 0; +static uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; +static IO_t ws2811IO = IO_NONE; +static TCH_t * ws2811TCH = NULL; +static bool ws2811Initialised = false; -uint16_t BIT_COMPARE_1 = 0; -uint16_t BIT_COMPARE_0 = 0; +static uint16_t BIT_COMPARE_1 = 0; +static uint16_t BIT_COMPARE_0 = 0; static hsvColor_t ledColorBuffer[WS2811_LED_STRIP_LENGTH]; @@ -90,22 +91,46 @@ void setStripColors(const hsvColor_t *colors) void ws2811LedStripInit(void) { + const timerHardware_t * timHw = timerGetByTag(IO_TAG(WS2811_PIN), TIM_USE_ANY); + + if (timHw == NULL) { + return; + } + + ws2811TCH = timerGetTCH(timHw); + if (ws2811TCH == NULL) { + return; + } + + /* Compute the prescaler value */ + uint16_t period = WS2811_TIMER_HZ / WS2811_CARRIER_HZ; + + BIT_COMPARE_1 = period * 2 / 3; + BIT_COMPARE_0 = period / 3; + + ws2811IO = IOGetByTag(IO_TAG(WS2811_PIN)); + IOInit(ws2811IO, OWNER_LED_STRIP, RESOURCE_OUTPUT, 0); + IOConfigGPIOAF(ws2811IO, IOCFG_AF_PP_FAST, timHw->alternateFunction); + + timerConfigBase(ws2811TCH, period, WS2811_TIMER_HZ); + timerPWMConfigChannel(ws2811TCH, 0); + timerPWMConfigChannelDMA(ws2811TCH, ledStripDMABuffer, WS2811_DMA_BUFFER_SIZE); + + // Zero out DMA buffer memset(&ledStripDMABuffer, 0, sizeof(ledStripDMABuffer)); - ws2811LedStripHardwareInit(); + ws2811Initialised = true; + ws2811UpdateStrip(); } bool isWS2811LedStripReady(void) { - return !ws2811LedDataTransferInProgress; + return !timerPWMDMAInProgress(ws2811TCH); } STATIC_UNIT_TESTED uint16_t dmaBufferOffset; static int16_t ledIndex; -#define USE_FAST_DMA_BUFFER_IMPL -#ifdef USE_FAST_DMA_BUFFER_IMPL - STATIC_UNIT_TESTED void fastUpdateLEDDMABuffer(rgbColor24bpp_t *color) { uint32_t grb = (color->rgb.g << 16) | (color->rgb.r << 8) | (color->rgb.b); @@ -114,25 +139,6 @@ STATIC_UNIT_TESTED void fastUpdateLEDDMABuffer(rgbColor24bpp_t *color) ledStripDMABuffer[dmaBufferOffset++] = (grb & (1 << index)) ? BIT_COMPARE_1 : BIT_COMPARE_0; } } -#else -STATIC_UNIT_TESTED void updateLEDDMABuffer(uint8_t componentValue) -{ - uint8_t bitIndex; - - for (bitIndex = 0; bitIndex < 8; bitIndex++) - { - if ((componentValue << bitIndex) & 0x80 ) // data sent MSB first, j = 0 is MSB j = 7 is LSB - { - ledStripDMABuffer[dmaBufferOffset] = BIT_COMPARE_1; - } - else - { - ledStripDMABuffer[dmaBufferOffset] = BIT_COMPARE_0; // compare value for logical 0 - } - dmaBufferOffset++; - } -} -#endif /* * This method is non-blocking unless an existing LED update is in progress. @@ -143,7 +149,7 @@ void ws2811UpdateStrip(void) static rgbColor24bpp_t *rgb24; // don't wait - risk of infinite block, just get an update next time round - if (ws2811LedDataTransferInProgress) { + if (timerPWMDMAInProgress(ws2811TCH)) { return; } @@ -155,20 +161,17 @@ void ws2811UpdateStrip(void) while (ledIndex < WS2811_LED_STRIP_LENGTH) { rgb24 = hsvToRgb24(&ledColorBuffer[ledIndex]); - -#ifdef USE_FAST_DMA_BUFFER_IMPL fastUpdateLEDDMABuffer(rgb24); -#else - updateLEDDMABuffer(rgb24->rgb.g); - updateLEDDMABuffer(rgb24->rgb.r); - updateLEDDMABuffer(rgb24->rgb.b); -#endif - ledIndex++; } - ws2811LedDataTransferInProgress = 1; - ws2811LedStripDMAEnable(); + // Initiate hardware transfer + if (!ws2811Initialised || !ws2811TCH) { + return; + } + + timerPWMPrepareDMA(ws2811TCH, WS2811_DMA_BUFFER_SIZE); + timerPWMStartDMA(ws2811TCH); } #endif diff --git a/src/main/drivers/light_ws2811strip.h b/src/main/drivers/light_ws2811strip.h index 762e704d7ad..85337a9d466 100644 --- a/src/main/drivers/light_ws2811strip.h +++ b/src/main/drivers/light_ws2811strip.h @@ -26,12 +26,13 @@ #define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE + WS2811_DELAY_BUFFER_LENGTH) // number of bytes needed is #LEDs * 24 bytes + 42 trailing bytes) -#define WS2811_TIMER_MHZ 24 -#define WS2811_CARRIER_HZ 800000 +#define WS2811_TIMER_HZ 24000000 +#define WS2811_CARRIER_HZ 800000 void ws2811LedStripInit(void); void ws2811LedStripHardwareInit(void); void ws2811LedStripDMAEnable(void); +bool ws2811LedStripDMAInProgress(void); void ws2811UpdateStrip(void); @@ -45,13 +46,3 @@ void setStripColor(const hsvColor_t *color); void setStripColors(const hsvColor_t *colors); bool isWS2811LedStripReady(void); - -#if defined(STM32F4) || defined(STM32F7) -extern uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; -#else -extern uint8_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; -#endif -extern volatile uint8_t ws2811LedDataTransferInProgress; - -extern uint16_t BIT_COMPARE_1; -extern uint16_t BIT_COMPARE_0; \ No newline at end of file diff --git a/src/main/drivers/light_ws2811strip_hal.c b/src/main/drivers/light_ws2811strip_hal.c deleted file mode 100644 index b6d5cc1b2a0..00000000000 --- a/src/main/drivers/light_ws2811strip_hal.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * This file is part of Cleanflight. - * - * Cleanflight is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Cleanflight is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cleanflight. If not, see . - */ - -#include -#include - -#include "platform.h" - -#ifdef USE_LED_STRIP - -#include "common/color.h" -#include "light_ws2811strip.h" -#include "drivers/nvic.h" -#include "dma.h" -#include "drivers/io.h" -#include "drivers/system.h" -#include "rcc.h" -#include "timer.h" - -#if !defined(WS2811_PIN) -#define WS2811_PIN PA0 -#define WS2811_TIMER TIM5 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST2_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream2 -#define WS2811_DMA_IT DMA_IT_TCIF2 -#define WS2811_DMA_CHANNEL DMA_Channel_6 -#define WS2811_TIMER_CHANNEL TIM_Channel_1 -#define WS2811_TIMER_GPIO_AF GPIO_AF2_TIM5 -#endif - -static IO_t ws2811IO = IO_NONE; -bool ws2811Initialised = false; - -static TIM_HandleTypeDef TimHandle; -static uint16_t timerChannel = 0; -static bool timerNChannel = false; - -void WS2811_DMA_IRQHandler(dmaChannelDescriptor_t* descriptor) -{ - HAL_DMA_IRQHandler(TimHandle.hdma[descriptor->userParam]); - if(timerNChannel) { - HAL_TIMEx_PWMN_Stop_DMA(&TimHandle,timerChannel); - } else { - HAL_TIM_PWM_Stop_DMA(&TimHandle,timerChannel); - } - ws2811LedDataTransferInProgress = 0; -} - -void ws2811LedStripHardwareInit(void) -{ - const timerHardware_t *timerHardware = timerGetByTag(IO_TAG(WS2811_PIN), TIM_USE_ANY); - TIM_TypeDef *timer = timerHardware->tim; - timerChannel = timerHardware->channel; - - if (timerHardware == NULL) { - return; - } - TimHandle.Instance = timer; - - /* Compute the prescaler value */ - uint16_t prescaler = timerGetPrescalerByDesiredMhz(timer, WS2811_TIMER_MHZ); - uint16_t period = 1000000 * WS2811_TIMER_MHZ / WS2811_CARRIER_HZ; - - BIT_COMPARE_1 = period / 3 * 2; - BIT_COMPARE_0 = period / 3; - - TimHandle.Init.Prescaler = prescaler; - TimHandle.Init.Period = period; // 800kHz - TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) { - /* Initialization Error */ - return; - } - - static DMA_HandleTypeDef hdma_tim; - - ws2811IO = IOGetByTag(IO_TAG(WS2811_PIN)); - IOInit(ws2811IO, OWNER_LED_STRIP, RESOURCE_OUTPUT, 0); - IOConfigGPIOAF(ws2811IO, IO_CONFIG(GPIO_MODE_AF_PP, GPIO_SPEED_FREQ_VERY_HIGH, GPIO_PULLDOWN), timerHardware->alternateFunction); - - __DMA1_CLK_ENABLE(); - - /* Set the parameters to be configured */ - hdma_tim.Init.Channel = WS2811_DMA_CHANNEL; - hdma_tim.Init.Direction = DMA_MEMORY_TO_PERIPH; - hdma_tim.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_tim.Init.MemInc = DMA_MINC_ENABLE; - hdma_tim.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; - hdma_tim.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; - hdma_tim.Init.Mode = DMA_NORMAL; - hdma_tim.Init.Priority = DMA_PRIORITY_HIGH; - hdma_tim.Init.FIFOMode = DMA_FIFOMODE_DISABLE; - hdma_tim.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; - hdma_tim.Init.MemBurst = DMA_MBURST_SINGLE; - hdma_tim.Init.PeriphBurst = DMA_PBURST_SINGLE; - - /* Set hdma_tim instance */ - hdma_tim.Instance = WS2811_DMA_STREAM; - - uint16_t dmaSource = timerDmaSource(timerChannel); - - /* Link hdma_tim to hdma[x] (channelx) */ - __HAL_LINKDMA(&TimHandle, hdma[dmaSource], hdma_tim); - - dmaInit(WS2811_DMA_HANDLER_IDENTIFER, OWNER_LED_STRIP, 0); - dmaSetHandler(WS2811_DMA_HANDLER_IDENTIFER, WS2811_DMA_IRQHandler, NVIC_PRIO_WS2811_DMA, dmaSource); - - /* Initialize TIMx DMA handle */ - if (HAL_DMA_Init(TimHandle.hdma[dmaSource]) != HAL_OK) { - /* Initialization Error */ - return; - } - - TIM_OC_InitTypeDef TIM_OCInitStructure; - - /* PWM1 Mode configuration: Channel1 */ - TIM_OCInitStructure.OCMode = TIM_OCMODE_PWM1; - if (timerHardware->output & TIMER_OUTPUT_N_CHANNEL) { - timerNChannel = true; - } - TIM_OCInitStructure.OCIdleState = TIM_OCIDLESTATE_RESET; - TIM_OCInitStructure.OCPolarity = (timerHardware->output & TIMER_OUTPUT_INVERTED) ? TIM_OCPOLARITY_LOW: TIM_OCPOLARITY_HIGH; - TIM_OCInitStructure.OCNIdleState = TIM_OCNIDLESTATE_RESET; - TIM_OCInitStructure.OCNPolarity = (timerHardware->output & TIMER_OUTPUT_INVERTED) ? TIM_OCNPOLARITY_LOW : TIM_OCNPOLARITY_HIGH; - - TIM_OCInitStructure.Pulse = 0; - TIM_OCInitStructure.OCFastMode = TIM_OCFAST_DISABLE; - if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &TIM_OCInitStructure, timerChannel) != HAL_OK) { - /* Configuration Error */ - return; - } - - ws2811Initialised = true; -} - -void ws2811LedStripDMAEnable(void) -{ - if (!ws2811Initialised) { - ws2811LedDataTransferInProgress = 0; - return; - } - - if (timerNChannel) { - if (HAL_TIMEx_PWMN_Start_DMA(&TimHandle, timerChannel, ledStripDMABuffer, WS2811_DMA_BUFFER_SIZE) != HAL_OK) { - /* Starting PWM generation Error */ - ws2811LedDataTransferInProgress = 0; - return; - } - } else { - if (HAL_TIM_PWM_Start_DMA(&TimHandle, timerChannel, ledStripDMABuffer, WS2811_DMA_BUFFER_SIZE) != HAL_OK) { - /* Starting PWM generation Error */ - ws2811LedDataTransferInProgress = 0; - return; - } - } -} -#endif diff --git a/src/main/drivers/light_ws2811strip_stdperiph.c b/src/main/drivers/light_ws2811strip_stdperiph.c deleted file mode 100755 index 233fd80bbd1..00000000000 --- a/src/main/drivers/light_ws2811strip_stdperiph.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * This file is part of Cleanflight. - * - * Cleanflight is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Cleanflight is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Cleanflight. If not, see . - */ - -#include -#include - -#include "platform.h" - -#ifdef USE_LED_STRIP - -#include "drivers/io.h" -#include "drivers/nvic.h" - -#include "common/color.h" -#include "light_ws2811strip.h" -#include "dma.h" -#include "drivers/system.h" -#include "rcc.h" -#include "timer.h" - -#if !defined(WS2811_PIN) -#if defined(STM32F4) - #define WS2811_PIN PA0 - #define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST2_HANDLER - #define WS2811_DMA_STREAM DMA1_Stream2 - #define WS2811_DMA_CHANNEL DMA_Channel_6 -#elif defined(STM32F3) - #define WS2811_PIN PB8 // TIM16_CH1 - #define WS2811_DMA_STREAM DMA1_Channel3 - #define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH3_HANDLER -#endif -#endif - - -static IO_t ws2811IO = IO_NONE; -bool ws2811Initialised = false; -#if defined(STM32F4) -static DMA_Stream_TypeDef *dmaRef = NULL; -#elif defined(STM32F3) -static DMA_Channel_TypeDef *dmaRef = NULL; -#else -#error "No MCU definition in light_ws2811strip_stdperiph.c" -#endif -static TIM_TypeDef *timer = NULL; - -static void WS2811_DMA_IRQHandler(dmaChannelDescriptor_t *descriptor) -{ - if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_TCIF)) { - ws2811LedDataTransferInProgress = 0; - DMA_Cmd(descriptor->ref, DISABLE); - DMA_CLEAR_FLAG(descriptor, DMA_IT_TCIF); - } -} - -void ws2811LedStripHardwareInit(void) -{ - DMA_InitTypeDef DMA_InitStructure; - - const timerHardware_t *timerHardware = timerGetByTag(IO_TAG(WS2811_PIN), TIM_USE_ANY); - - if (timerHardware == NULL) { - return; - } - - timer = timerHardware->tim; - - ws2811IO = IOGetByTag(IO_TAG(WS2811_PIN)); - IOInit(ws2811IO, OWNER_LED_STRIP, RESOURCE_OUTPUT, 0); - IOConfigGPIOAF(ws2811IO, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_UP), timerHardware->alternateFunction); - - // Stop timer - TIM_Cmd(timer, DISABLE); - - /* Compute the prescaler value */ - uint16_t period = 1000000 * WS2811_TIMER_MHZ / WS2811_CARRIER_HZ; - - BIT_COMPARE_1 = period / 3 * 2; - BIT_COMPARE_0 = period / 3; - - /* PWM1 Mode configuration */ - timerConfigBase(timer, period, WS2811_TIMER_MHZ); - timerPWMConfigChannel(timer, timerHardware->channel, timerHardware->output & TIMER_OUTPUT_N_CHANNEL, timerHardware->output & TIMER_OUTPUT_INVERTED, 0); - - TIM_CtrlPWMOutputs(timer, ENABLE); - TIM_ARRPreloadConfig(timer, ENABLE); - - TIM_CCxCmd(timer, timerHardware->channel, TIM_CCx_Enable); - TIM_Cmd(timer, ENABLE); - - // dmaInit(timerHardware->dmaIrqHandler, OWNER_LED_STRIP, 0); - // dmaSetHandler(timerHardware->dmaIrqHandler, WS2811_DMA_IRQHandler, NVIC_PRIO_WS2811_DMA, 0); - //dmaRef = timerHardware->dmaRef; - dmaRef = WS2811_DMA_STREAM; - dmaInit(WS2811_DMA_HANDLER_IDENTIFER, OWNER_LED_STRIP, 0); - dmaSetHandler(WS2811_DMA_HANDLER_IDENTIFER, WS2811_DMA_IRQHandler, NVIC_PRIO_WS2811_DMA, 0); - - DMA_DeInit(dmaRef); - - /* configure DMA */ - DMA_Cmd(dmaRef, DISABLE); - DMA_DeInit(dmaRef); - DMA_StructInit(&DMA_InitStructure); - DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)timerCCR(timer, timerHardware->channel); - DMA_InitStructure.DMA_BufferSize = WS2811_DMA_BUFFER_SIZE; - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - -#if defined(STM32F4) - DMA_InitStructure.DMA_Channel = WS2811_DMA_CHANNEL; //timerHardware->dmaChannel; - DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)ledStripDMABuffer; - DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; - DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; - DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; - DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; -#elif defined(STM32F3) - DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ledStripDMABuffer; - DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; - DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; - DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; - DMA_InitStructure.DMA_Priority = DMA_Priority_High; - DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; -#endif - DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; - - DMA_Init(dmaRef, &DMA_InitStructure); - TIM_DMACmd(timer, timerDmaSource(timerHardware->channel), ENABLE); - DMA_ITConfig(dmaRef, DMA_IT_TC, ENABLE); - ws2811Initialised = true; -} - -void ws2811LedStripDMAEnable(void) -{ - if (!ws2811Initialised) - return; - - DMA_SetCurrDataCounter(dmaRef, WS2811_DMA_BUFFER_SIZE); // load number of bytes to be transferred - TIM_SetCounter(timer, 0); - TIM_Cmd(timer, ENABLE); - DMA_Cmd(dmaRef, ENABLE); -} - -#endif diff --git a/src/main/drivers/nvic.h b/src/main/drivers/nvic.h index 100159b0c63..52aa554e80a 100644 --- a/src/main/drivers/nvic.h +++ b/src/main/drivers/nvic.h @@ -11,29 +11,13 @@ #define NVIC_PRIO_GYRO_INT_EXTI NVIC_BUILD_PRIORITY(0x0f, 0x0f) #define NVIC_PRIO_MAG_INT_EXTI NVIC_BUILD_PRIORITY(0x0f, 0x0f) #define NVIC_PRIO_WS2811_DMA NVIC_BUILD_PRIORITY(1, 2) // TODO - is there some reason to use high priority? (or to use DMA IRQ at all?) -#define NVIC_PRIO_SERIALUART1_TXDMA NVIC_BUILD_PRIORITY(1, 1) -#define NVIC_PRIO_SERIALUART1_RXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART1 NVIC_BUILD_PRIORITY(1, 1) -#define NVIC_PRIO_SERIALUART2_TXDMA NVIC_BUILD_PRIORITY(1, 0) -#define NVIC_PRIO_SERIALUART2_RXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART2 NVIC_BUILD_PRIORITY(1, 2) -#define NVIC_PRIO_SERIALUART3_TXDMA NVIC_BUILD_PRIORITY(1, 0) -#define NVIC_PRIO_SERIALUART3_RXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART3 NVIC_BUILD_PRIORITY(1, 2) -#define NVIC_PRIO_SERIALUART4_TXDMA NVIC_BUILD_PRIORITY(1, 0) -#define NVIC_PRIO_SERIALUART4_RXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART4 NVIC_BUILD_PRIORITY(1, 2) -#define NVIC_PRIO_SERIALUART5_TXDMA NVIC_BUILD_PRIORITY(1, 0) -#define NVIC_PRIO_SERIALUART5_RXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART5 NVIC_BUILD_PRIORITY(1, 2) -#define NVIC_PRIO_SERIALUART6_TXDMA NVIC_BUILD_PRIORITY(1, 0) -#define NVIC_PRIO_SERIALUART6_RXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART6 NVIC_BUILD_PRIORITY(1, 2) -#define NVIC_PRIO_SERIALUART7_TXDMA NVIC_BUILD_PRIORITY(1, 0) -#define NVIC_PRIO_SERIALUART7_RXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART7 NVIC_BUILD_PRIORITY(1, 2) -#define NVIC_PRIO_SERIALUART8_TXDMA NVIC_BUILD_PRIORITY(1, 0) -#define NVIC_PRIO_SERIALUART8_RXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART8 NVIC_BUILD_PRIORITY(1, 2) #define NVIC_PRIO_I2C_ER NVIC_BUILD_PRIORITY(0, 0) #define NVIC_PRIO_I2C_EV NVIC_BUILD_PRIORITY(0, 0) diff --git a/src/main/drivers/pwm_mapping.c b/src/main/drivers/pwm_mapping.c index e43b31a0f84..4c6f5027c3d 100644 --- a/src/main/drivers/pwm_mapping.c +++ b/src/main/drivers/pwm_mapping.c @@ -69,7 +69,7 @@ pwmIOConfiguration_t *pwmInit(drv_pwm_config_t *init) const timerHardware_t *timerHardwarePtr = &timerHardware[timerIndex]; int type = MAP_TO_NONE; -#if defined(STM32F303xC) && defined(USE_UART3) +#if defined(STM32F3) && defined(USE_UART3) // skip UART3 ports (PB10/PB11) if (init->useUART3 && (timerHardwarePtr->tag == IO_TAG(UART3_TX_PIN) || timerHardwarePtr->tag == IO_TAG(UART3_RX_PIN))) { addBootlogEvent6(BOOT_EVENT_TIMER_CH_SKIPPED, BOOT_EVENT_FLAGS_WARNING, timerIndex, pwmIOConfiguration.motorCount, pwmIOConfiguration.servoCount, 3); @@ -85,36 +85,34 @@ pwmIOConfiguration_t *pwmInit(drv_pwm_config_t *init) #endif #if defined(USE_SOFTSERIAL1) - const timerHardware_t *ss1TimerHardware = timerGetByTag(IO_TAG(SOFTSERIAL_1_RX_PIN), TIM_USE_ANY); - if (init->useSoftSerial && ss1TimerHardware != NULL && ss1TimerHardware->tim == timerHardwarePtr->tim) { - addBootlogEvent6(BOOT_EVENT_TIMER_CH_SKIPPED, BOOT_EVENT_FLAGS_WARNING, timerIndex, pwmIOConfiguration.motorCount, pwmIOConfiguration.servoCount, 3); - continue; + if (init->useSoftSerial) { + const timerHardware_t *ss1TimerHardware = timerGetByTag(IO_TAG(SOFTSERIAL_1_RX_PIN), TIM_USE_ANY); + if (ss1TimerHardware != NULL && ss1TimerHardware->tim == timerHardwarePtr->tim) { + addBootlogEvent6(BOOT_EVENT_TIMER_CH_SKIPPED, BOOT_EVENT_FLAGS_WARNING, timerIndex, pwmIOConfiguration.motorCount, pwmIOConfiguration.servoCount, 3); + continue; + } } #endif #if defined(USE_SOFTSERIAL2) - const timerHardware_t *ss2TimerHardware = timerGetByTag(IO_TAG(SOFTSERIAL_2_RX_PIN), TIM_USE_ANY); - if (init->useSoftSerial && ss2TimerHardware != NULL && ss2TimerHardware->tim == timerHardwarePtr->tim) { - addBootlogEvent6(BOOT_EVENT_TIMER_CH_SKIPPED, BOOT_EVENT_FLAGS_WARNING, timerIndex, pwmIOConfiguration.motorCount, pwmIOConfiguration.servoCount, 3); - continue; + if (init->useSoftSerial) { + const timerHardware_t *ss2TimerHardware = timerGetByTag(IO_TAG(SOFTSERIAL_2_RX_PIN), TIM_USE_ANY); + if (ss2TimerHardware != NULL && ss2TimerHardware->tim == timerHardwarePtr->tim) { + addBootlogEvent6(BOOT_EVENT_TIMER_CH_SKIPPED, BOOT_EVENT_FLAGS_WARNING, timerIndex, pwmIOConfiguration.motorCount, pwmIOConfiguration.servoCount, 3); + continue; + } } #endif -#ifdef WS2811_TIMER +#if defined(USE_LED_STRIP) // skip LED Strip output if (init->useLEDStrip) { - if (timerHardwarePtr->tim == WS2811_TIMER) { + const timerHardware_t * ledTimHw = timerGetByTag(IO_TAG(WS2811_PIN), TIM_USE_ANY); + if (ledTimHw != NULL && timerHardwarePtr->tim == ledTimHw->tim) { addBootlogEvent6(BOOT_EVENT_TIMER_CH_SKIPPED, BOOT_EVENT_FLAGS_WARNING, timerIndex, pwmIOConfiguration.motorCount, pwmIOConfiguration.servoCount, 3); continue; } -#if defined(STM32F303xC) && defined(WS2811_PIN) - if (timerHardwarePtr->tag == IO_TAG(WS2811_PIN)) { - addBootlogEvent6(BOOT_EVENT_TIMER_CH_SKIPPED, BOOT_EVENT_FLAGS_WARNING, timerIndex, pwmIOConfiguration.motorCount, pwmIOConfiguration.servoCount, 3); - continue; - } -#endif } - #endif #ifdef VBAT_ADC_PIN @@ -186,7 +184,7 @@ pwmIOConfiguration_t *pwmInit(drv_pwm_config_t *init) if (type == MAP_TO_PPM_INPUT) { #if defined(USE_RX_PPM) - ppmInConfig(timerHardwarePtr, init->pwmProtocolType); + ppmInConfig(timerHardwarePtr); pwmIOConfiguration.ioConfigurations[pwmIOConfiguration.ioCount].flags = PWM_PF_PPM; pwmIOConfiguration.ppmInputCount++; @@ -208,7 +206,7 @@ pwmIOConfiguration_t *pwmInit(drv_pwm_config_t *init) continue; } - if (pwmMotorConfig(timerHardwarePtr, pwmIOConfiguration.motorCount, init->motorPwmRate, init->idlePulse, init->pwmProtocolType, init->enablePWMOutput)) { + if (pwmMotorConfig(timerHardwarePtr, pwmIOConfiguration.motorCount, init->motorPwmRate, init->pwmProtocolType, init->enablePWMOutput)) { if (init->useFastPwm) { pwmIOConfiguration.ioConfigurations[pwmIOConfiguration.ioCount].flags = PWM_PF_MOTOR | PWM_PF_OUTPUT_PROTOCOL_FASTPWM | PWM_PF_OUTPUT_PROTOCOL_PWM; } else if (init->pwmProtocolType == PWM_TYPE_BRUSHED) { diff --git a/src/main/drivers/pwm_mapping.h b/src/main/drivers/pwm_mapping.h index f383995ed2c..11929d12954 100644 --- a/src/main/drivers/pwm_mapping.h +++ b/src/main/drivers/pwm_mapping.h @@ -33,7 +33,7 @@ #define MAX_SERVOS 8 #endif -#define PWM_TIMER_MHZ 1 +#define PWM_TIMER_HZ 1000000 #define PULSE_1MS (1000) // 1ms pulse width @@ -68,8 +68,6 @@ typedef struct drv_pwm_config_s { uint16_t servoCenterPulse; uint8_t pwmProtocolType; uint16_t motorPwmRate; - uint16_t idlePulse; // PWM value to use when initializing the driver. set this to either PULSE_1MS (regular pwm), - // some higher value (used by 3d mode), or 0, for brushed pwm drivers. rangefinderIOConfig_t rangefinderIOConfig; } drv_pwm_config_t; diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 2c264871836..30d23ab33af 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -35,16 +35,18 @@ #include "fc/config.h" #include "fc/runtime_config.h" -#define MULTISHOT_5US_PW (MULTISHOT_TIMER_MHZ * 5) -#define MULTISHOT_20US_MULT (MULTISHOT_TIMER_MHZ * 20 / 1000.0f) +#define MULTISHOT_5US_PW (MULTISHOT_TIMER_HZ * 5 / 1000000.0f) +#define MULTISHOT_20US_MULT (MULTISHOT_TIMER_HZ * 20 / 1000000.0f / 1000.0f) typedef void (*pwmWriteFuncPtr)(uint8_t index, uint16_t value); // function pointer used to write motors typedef struct { + TCH_t * tch; volatile timCCR_t *ccr; - TIM_TypeDef *tim; uint16_t period; pwmWriteFuncPtr pwmWritePtr; + float pulseOffset; + float pulseScale; } pwmOutputPort_t; static pwmOutputPort_t pwmOutputPorts[MAX_PWM_OUTPUT_PORTS]; @@ -62,38 +64,41 @@ static uint8_t allocatedOutputPortCount = 0; static bool pwmMotorsEnabled = true; -static void pwmOutConfigTimer(pwmOutputPort_t * p, const timerHardware_t *timerHardware, uint8_t mhz, uint16_t period, uint16_t value) +static void pwmOutConfigTimer(pwmOutputPort_t * p, TCH_t * tch, uint32_t hz, uint16_t period, uint16_t value) { - timerConfigBase(timerHardware->tim, period, mhz); - timerPWMConfigChannel(timerHardware->tim, timerHardware->channel, timerHardware->output & TIMER_OUTPUT_N_CHANNEL, timerHardware->output & TIMER_OUTPUT_INVERTED, value); + p->tch = tch; + + timerConfigBase(p->tch, period, hz); + timerPWMConfigChannel(p->tch, value); + timerPWMStart(p->tch); - if (timerHardware->output & TIMER_OUTPUT_ENABLED) { - timerPWMStart(timerHardware->tim, timerHardware->channel, timerHardware->output & TIMER_OUTPUT_N_CHANNEL); - } - - timerEnable(timerHardware->tim); + timerEnable(p->tch); - p->ccr = timerCCR(timerHardware->tim, timerHardware->channel); p->period = period; - p->tim = timerHardware->tim; - + p->ccr = timerCCR(p->tch); *p->ccr = 0; } -static pwmOutputPort_t *pwmOutConfigMotor(const timerHardware_t *timerHardware, uint8_t mhz, uint16_t period, uint16_t value, bool enableOutput) +static pwmOutputPort_t *pwmOutConfigMotor(const timerHardware_t *timHw, uint32_t hz, uint16_t period, uint16_t value, bool enableOutput) { if (allocatedOutputPortCount >= MAX_PWM_OUTPUT_PORTS) { DEBUG_TRACE("Attempt to allocate PWM output beyond MAX_PWM_OUTPUT_PORTS"); return NULL; } + // Attempt to allocate TCH + TCH_t * tch = timerGetTCH(timHw); + if (tch == NULL) { + return NULL; + } + pwmOutputPort_t *p = &pwmOutputPorts[allocatedOutputPortCount++]; - const IO_t io = IOGetByTag(timerHardware->tag); + const IO_t io = IOGetByTag(timHw->tag); IOInit(io, OWNER_MOTOR, RESOURCE_OUTPUT, allocatedOutputPortCount); if (enableOutput) { - IOConfigGPIOAF(io, IOCFG_AF_PP, timerHardware->alternateFunction); + IOConfigGPIOAF(io, IOCFG_AF_PP, timHw->alternateFunction); } else { // If PWM outputs are disabled - configure as GPIO and drive low @@ -101,37 +106,15 @@ static pwmOutputPort_t *pwmOutConfigMotor(const timerHardware_t *timerHardware, IOLo(io); } - pwmOutConfigTimer(p, timerHardware, mhz, period, value); + pwmOutConfigTimer(p, tch, hz, period, value); return p; } -static void pwmWriteBrushed(uint8_t index, uint16_t value) -{ - *motors[index]->ccr = (value - 1000) * motors[index]->period / 1000; -} - -#ifndef BRUSHED_MOTORS static void pwmWriteStandard(uint8_t index, uint16_t value) { - *motors[index]->ccr = value; -} - -static void pwmWriteOneShot125(uint8_t index, uint16_t value) -{ - *motors[index]->ccr = lrintf((float)(value * ONESHOT125_TIMER_MHZ/8.0f)); + *motors[index]->ccr = lrintf((value * motors[index]->pulseScale) + motors[index]->pulseOffset); } -static void pwmWriteOneShot42(uint8_t index, uint16_t value) -{ - *motors[index]->ccr = lrintf((float)(value * ONESHOT42_TIMER_MHZ/24.0f)); -} - -static void pwmWriteMultiShot(uint8_t index, uint16_t value) -{ - *motors[index]->ccr = lrintf(((float)(value-1000) * MULTISHOT_20US_MULT) + MULTISHOT_5US_PW); -} -#endif - void pwmWriteMotor(uint8_t index, uint16_t value) { if (motors[index] && index < MAX_MOTORS && pwmMotorsEnabled) { @@ -162,51 +145,71 @@ bool isMotorBrushed(uint16_t motorPwmRate) return (motorPwmRate > 500); } -bool pwmMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse, motorPwmProtocolTypes_e proto, bool enableOutput) +static pwmOutputPort_t * motorConfigPwm(const timerHardware_t *timerHardware, float sMin, float sLen, uint32_t motorPwmRateHz, bool enableOutput) +{ + const uint32_t baseClockHz = timerGetBaseClockHW(timerHardware); + const uint32_t prescaler = ((baseClockHz / motorPwmRateHz) + 0xffff) / 0x10000; /* rounding up */ + const uint32_t timerHz = baseClockHz / prescaler; + const uint32_t period = timerHz / motorPwmRateHz; + + pwmOutputPort_t * port = pwmOutConfigMotor(timerHardware, timerHz, period, 0, enableOutput); + + if (port) { + port->pulseScale = ((sLen == 0) ? period : (sLen * timerHz)) / 1000.0f; + port->pulseOffset = (sMin * timerHz) - (port->pulseScale * 1000); + } + + return port; +} + +bool pwmMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, motorPwmProtocolTypes_e proto, bool enableOutput) { - uint32_t timerMhzCounter; + pwmOutputPort_t * port = NULL; pwmWriteFuncPtr pwmWritePtr; - switch (proto) { #ifdef BRUSHED_MOTORS - default: + proto = PWM_TYPE_BRUSHED; // Override proto #endif + + switch (proto) { case PWM_TYPE_BRUSHED: - timerMhzCounter = PWM_BRUSHED_TIMER_MHZ; - pwmWritePtr = pwmWriteBrushed; - idlePulse = 0; + port = motorConfigPwm(timerHardware, 0.0f, 0.0f, motorPwmRate, enableOutput); + pwmWritePtr = pwmWriteStandard; break; -#ifndef BRUSHED_MOTORS case PWM_TYPE_ONESHOT125: - timerMhzCounter = ONESHOT125_TIMER_MHZ; - pwmWritePtr = pwmWriteOneShot125; + port = motorConfigPwm(timerHardware, 125e-6f, 125e-6f, motorPwmRate, enableOutput); + pwmWritePtr = pwmWriteStandard; break; case PWM_TYPE_ONESHOT42: - timerMhzCounter = ONESHOT42_TIMER_MHZ; - pwmWritePtr = pwmWriteOneShot42; + port = motorConfigPwm(timerHardware, 42e-6f, 42e-6f, motorPwmRate, enableOutput); + pwmWritePtr = pwmWriteStandard; break; case PWM_TYPE_MULTISHOT: - timerMhzCounter = MULTISHOT_TIMER_MHZ; - pwmWritePtr = pwmWriteMultiShot; + port = motorConfigPwm(timerHardware, 5e-6f, 20e-6f, motorPwmRate, enableOutput); + pwmWritePtr = pwmWriteStandard; break; - case PWM_TYPE_STANDARD: +#ifdef USE_DSHOT + case PWM_TYPE_DSHOT1200: + case PWM_TYPE_DSHOT600: + case PWM_TYPE_DSHOT300: + case PWM_TYPE_DSHOT150: + port = NULL; + break; +#endif + default: - timerMhzCounter = PWM_TIMER_MHZ; + case PWM_TYPE_STANDARD: + port = motorConfigPwm(timerHardware, 1e-3f, 1e-3f, motorPwmRate, enableOutput); pwmWritePtr = pwmWriteStandard; break; -#endif } - const uint32_t hz = timerMhzCounter * 1000000; - - pwmOutputPort_t * port = pwmOutConfigMotor(timerHardware, timerMhzCounter, hz / motorPwmRate, idlePulse, enableOutput); - if (port) { + port->pwmWritePtr = pwmWritePtr; motors[motorIndex] = port; - motors[motorIndex]->pwmWritePtr = pwmWritePtr; return true; } @@ -215,7 +218,7 @@ bool pwmMotorConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, ui bool pwmServoConfig(const timerHardware_t *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse, bool enableOutput) { - pwmOutputPort_t * port = pwmOutConfigMotor(timerHardware, PWM_TIMER_MHZ, 1000000 / servoPwmRate, servoCenterPulse, enableOutput); + pwmOutputPort_t * port = pwmOutConfigMotor(timerHardware, PWM_TIMER_HZ, PWM_TIMER_HZ / servoPwmRate, servoCenterPulse, enableOutput); if (port) { servos[servoIndex] = port; @@ -261,15 +264,21 @@ void pwmWriteBeeper(bool onoffBeep) void beeperPwmInit(ioTag_t tag, uint16_t frequency) { - const timerHardware_t *timer = timerGetByTag(tag, TIM_USE_BEEPER); - if (timer) { + beeperPwm = NULL; + + const timerHardware_t *timHw = timerGetByTag(tag, TIM_USE_BEEPER); + + if (timHw) { + // Attempt to allocate TCH + TCH_t * tch = timerGetTCH(timHw); + if (tch == NULL) { + return NULL; + } + beeperPwm = &beeperPwmPort; beeperFrequency = frequency; - IOConfigGPIOAF(IOGetByTag(tag), IOCFG_AF_PP, timer->alternateFunction); - pwmOutConfigTimer(beeperPwm, timer, PWM_TIMER_MHZ, 1000000 / beeperFrequency, (1000000 / beeperFrequency) / 2); - } - else { - beeperPwm = NULL; + IOConfigGPIOAF(IOGetByTag(tag), IOCFG_AF_PP, timHw->alternateFunction); + pwmOutConfigTimer(beeperPwm, tch, PWM_TIMER_HZ, 1000000 / beeperFrequency, (1000000 / beeperFrequency) / 2); } } #endif diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index 3943e254688..0aa5faeec82 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -19,29 +19,18 @@ #include "drivers/io_types.h" -#if defined(STM32F40_41xxx) // must be multiples of timer clock -#define ONESHOT125_TIMER_MHZ 12 -#define ONESHOT42_TIMER_MHZ 21 -#define MULTISHOT_TIMER_MHZ 84 -#define PWM_BRUSHED_TIMER_MHZ 21 -#elif defined(STM32F7) -#define ONESHOT125_TIMER_MHZ 9 -#define ONESHOT42_TIMER_MHZ 27 -#define MULTISHOT_TIMER_MHZ 54 -#define PWM_BRUSHED_TIMER_MHZ 27 -#else -#define ONESHOT125_TIMER_MHZ 8 -#define ONESHOT42_TIMER_MHZ 24 -#define MULTISHOT_TIMER_MHZ 72 -#define PWM_BRUSHED_TIMER_MHZ 24 -#endif - typedef enum { PWM_TYPE_STANDARD = 0, PWM_TYPE_ONESHOT125, PWM_TYPE_ONESHOT42, PWM_TYPE_MULTISHOT, - PWM_TYPE_BRUSHED + PWM_TYPE_BRUSHED, +#ifdef USE_DSHOT + PWM_TYPE_DSHOT150, + PWM_TYPE_DSHOT300, + PWM_TYPE_DSHOT600, + PWM_TYPE_DSHOT1200, +#endif } motorPwmProtocolTypes_e; void pwmWriteMotor(uint8_t index, uint16_t value); @@ -52,7 +41,7 @@ void pwmWriteServo(uint8_t index, uint16_t value); void pwmDisableMotors(void); void pwmEnableMotors(void); struct timerHardware_s; -bool pwmMotorConfig(const struct timerHardware_s *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, uint16_t idlePulse, motorPwmProtocolTypes_e proto, bool enableOutput); +bool pwmMotorConfig(const struct timerHardware_s *timerHardware, uint8_t motorIndex, uint16_t motorPwmRate, motorPwmProtocolTypes_e proto, bool enableOutput); bool pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse, bool enableOutput); void pwmWriteBeeper(bool onoffBeep); void beeperPwmInit(ioTag_t tag, uint16_t frequency); \ No newline at end of file diff --git a/src/main/drivers/rx_pwm.c b/src/main/drivers/rx_pwm.c index 8858c58c2ad..7b791ee77bd 100644 --- a/src/main/drivers/rx_pwm.c +++ b/src/main/drivers/rx_pwm.c @@ -71,9 +71,8 @@ typedef struct { uint8_t missedEvents; - const timerHardware_t *timerHardware; - timerCCHandlerRec_t edgeCb; - timerOvrHandlerRec_t overflowCb; + timerCallbacks_t cb; + const TCH_t * tch; } pwmInputPort_t; static pwmInputPort_t pwmInputPorts[PWM_INPUT_PORT_COUNT]; @@ -170,9 +169,9 @@ static void ppmInit(void) ppmDev.overflowed = false; } -static void ppmOverflowCallback(timerOvrHandlerRec_t* cbRec, captureCompare_t capture) +static void ppmOverflowCallback(struct TCH_s * tch, uint32_t capture) { - UNUSED(cbRec); + UNUSED(tch); ppmISREvent(SOURCE_OVERFLOW, capture); ppmDev.largeCounter += capture + 1; @@ -181,9 +180,9 @@ static void ppmOverflowCallback(timerOvrHandlerRec_t* cbRec, captureCompare_t ca } } -static void ppmEdgeCallback(timerCCHandlerRec_t* cbRec, captureCompare_t capture) +static void ppmEdgeCallback(struct TCH_s * tch, uint32_t capture) { - UNUSED(cbRec); + UNUSED(tch); ppmISREvent(SOURCE_EDGE, capture); int32_t i; @@ -303,10 +302,10 @@ bool isPWMDataBeingReceived(void) return false; } -static void pwmOverflowCallback(timerOvrHandlerRec_t* cbRec, captureCompare_t capture) +static void pwmOverflowCallback(struct TCH_s * tch, uint32_t capture) { UNUSED(capture); - pwmInputPort_t *pwmInputPort = container_of(cbRec, pwmInputPort_t, overflowCb); + pwmInputPort_t *pwmInputPort = (pwmInputPort_t *)tch->cb->callbackParam; if (++pwmInputPort->missedEvents > MAX_MISSED_PWM_EVENTS) { captures[pwmInputPort->channel] = PPM_RCVR_TIMEOUT; @@ -314,15 +313,14 @@ static void pwmOverflowCallback(timerOvrHandlerRec_t* cbRec, captureCompare_t ca } } -static void pwmEdgeCallback(timerCCHandlerRec_t *cbRec, captureCompare_t capture) +static void pwmEdgeCallback(struct TCH_s * tch, uint32_t capture) { - pwmInputPort_t *pwmInputPort = container_of(cbRec, pwmInputPort_t, edgeCb); - const timerHardware_t *timerHardwarePtr = pwmInputPort->timerHardware; + pwmInputPort_t *pwmInputPort = (pwmInputPort_t *)tch->cb->callbackParam; if (pwmInputPort->state == 0) { pwmInputPort->rise = capture; pwmInputPort->state = 1; - timerChConfigIC(timerHardwarePtr, false, INPUT_FILTER_TICKS); + timerChConfigIC(tch, false, INPUT_FILTER_TICKS); } else { pwmInputPort->fall = capture; @@ -331,13 +329,13 @@ static void pwmEdgeCallback(timerCCHandlerRec_t *cbRec, captureCompare_t capture pwmInputPort->capture = pwmInputPort->fall - pwmInputPort->rise; } else { - pwmInputPort->capture = (pwmInputPort->fall + timerGetPeriod(timerHardwarePtr)) - pwmInputPort->rise; + pwmInputPort->capture = (pwmInputPort->fall + timerGetPeriod(tch)) - pwmInputPort->rise; } captures[pwmInputPort->channel] = pwmInputPort->capture; // switch state pwmInputPort->state = 0; - timerChConfigIC(timerHardwarePtr, true, INPUT_FILTER_TICKS); + timerChConfigIC(tch, true, INPUT_FILTER_TICKS); pwmInputPort->missedEvents = 0; } } @@ -346,74 +344,50 @@ void pwmInConfig(const timerHardware_t *timerHardwarePtr, uint8_t channel) { pwmInputPort_t *self = &pwmInputPorts[channel]; + TCH_t * tch = timerGetTCH(timerHardware); + if (tch == NULL) { + return NULL; + } + self->state = 0; self->missedEvents = 0; self->channel = channel; self->mode = INPUT_MODE_PWM; - self->timerHardware = timerHardwarePtr; IO_t io = IOGetByTag(timerHardwarePtr->tag); IOInit(io, OWNER_PWMINPUT, RESOURCE_INPUT, RESOURCE_INDEX(channel)); IOConfigGPIOAF(io, timerHardwarePtr->ioMode, timerHardwarePtr->alternateFunction); - timerConfigure(timerHardwarePtr, (uint16_t)PWM_TIMER_PERIOD, PWM_TIMER_MHZ); - timerChCCHandlerInit(&self->edgeCb, pwmEdgeCallback); - timerChOvrHandlerInit(&self->overflowCb, pwmOverflowCallback); - timerChConfigCallbacks(timerHardwarePtr, &self->edgeCb, &self->overflowCb); - timerChConfigIC(timerHardwarePtr, true, INPUT_FILTER_TICKS); + timerConfigure(tch, (uint16_t)PWM_TIMER_PERIOD, PWM_TIMER_HZ); + timerChInitCallbacks(&self->cb, (void*)self, &pwmEdgeCallback, &pwmOverflowCallback); + timerChConfigCallbacks(tch, &self->cb); + timerChConfigIC(tch, true, INPUT_FILTER_TICKS); } #define UNUSED_PPM_TIMER_REFERENCE 0 #define FIRST_PWM_PORT 0 -void ppmAvoidPWMTimerClash(const timerHardware_t *timerHardwarePtr, uint8_t motorPwmProtocol) +void ppmInConfig(const timerHardware_t *timerHardwarePtr) { - for (int timerIndex = 0; timerIndex < timerHardwareCount; timerIndex++) { - // If PPM input timer is also mapped to motor - set PPM divisor accordingly - if (((timerHardware[timerIndex].usageFlags & (TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR)) == 0) || timerHardware[timerIndex].tim != timerHardwarePtr->tim) - continue; - - switch (motorPwmProtocol) { - case PWM_TYPE_ONESHOT125: - ppmCountDivisor = ONESHOT125_TIMER_MHZ; - break; - case PWM_TYPE_ONESHOT42: - ppmCountDivisor = ONESHOT42_TIMER_MHZ; - break; - case PWM_TYPE_MULTISHOT: - ppmCountDivisor = MULTISHOT_TIMER_MHZ; - break; - case PWM_TYPE_BRUSHED: - ppmCountDivisor = PWM_BRUSHED_TIMER_MHZ; - break; - default: - break; - } - - return; + TCH_t * tch = timerGetTCH(timerHardware); + if (tch == NULL) { + return NULL; } -} -void ppmInConfig(const timerHardware_t *timerHardwarePtr, uint8_t motorPwmProtocol) -{ ppmInit(); - ppmAvoidPWMTimerClash(timerHardwarePtr, motorPwmProtocol); - pwmInputPort_t *self = &pwmInputPorts[FIRST_PWM_PORT]; self->mode = INPUT_MODE_PPM; - self->timerHardware = timerHardwarePtr; IO_t io = IOGetByTag(timerHardwarePtr->tag); IOInit(io, OWNER_PPMINPUT, RESOURCE_INPUT, 0); IOConfigGPIOAF(io, timerHardwarePtr->ioMode, timerHardwarePtr->alternateFunction); - timerConfigure(timerHardwarePtr, (uint16_t)PPM_TIMER_PERIOD, PWM_TIMER_MHZ); - timerChCCHandlerInit(&self->edgeCb, ppmEdgeCallback); - timerChOvrHandlerInit(&self->overflowCb, ppmOverflowCallback); - timerChConfigCallbacks(timerHardwarePtr, &self->edgeCb, &self->overflowCb); - timerChConfigIC(timerHardwarePtr, true, INPUT_FILTER_TICKS); + timerConfigure(tch, (uint16_t)PPM_TIMER_PERIOD, PWM_TIMER_HZ); + timerChInitCallbacks(&self->cb, (void*)self, &ppmEdgeCallback, &ppmOverflowCallback); + timerChConfigCallbacks(tch, &self->cb); + timerChConfigIC(tch, true, INPUT_FILTER_TICKS); } uint16_t ppmRead(uint8_t channel) diff --git a/src/main/drivers/rx_pwm.h b/src/main/drivers/rx_pwm.h index bf213311f8b..8757cf6e1cc 100644 --- a/src/main/drivers/rx_pwm.h +++ b/src/main/drivers/rx_pwm.h @@ -25,7 +25,7 @@ typedef enum { #define PPM_RCVR_TIMEOUT 0 struct timerHardware_s; -void ppmInConfig(const struct timerHardware_s *timerHardwarePtr, uint8_t motorPwmProtocol); +void ppmInConfig(const struct timerHardware_s *timerHardwarePtr); void pwmInConfig(const struct timerHardware_s *timerHardwarePtr, uint8_t channel); uint16_t pwmRead(uint8_t channel); diff --git a/src/main/drivers/serial_softserial.c b/src/main/drivers/serial_softserial.c index e9f77cbb109..ddee3e8808e 100644 --- a/src/main/drivers/serial_softserial.c +++ b/src/main/drivers/serial_softserial.c @@ -37,7 +37,7 @@ #include "drivers/nvic.h" #include "drivers/io.h" -#include "timer.h" +#include "drivers/timer.h" #include "serial.h" #include "serial_softserial.h" @@ -67,11 +67,11 @@ typedef struct softSerial_s { IO_t rxIO; IO_t txIO; - const timerHardware_t *timerHardware; -#ifdef USE_HAL_DRIVER - const TIM_HandleTypeDef *timerHandle; -#endif - const timerHardware_t *exTimerHardware; + TCH_t * tch; + TCH_t * exTch; + + timerCallbacks_t tchCallbacks; + timerCallbacks_t exTchCallbacks; volatile uint8_t rxBuffer[SOFTSERIAL_BUFFER_SIZE]; volatile uint8_t txBuffer[SOFTSERIAL_BUFFER_SIZE]; @@ -93,17 +93,14 @@ typedef struct softSerial_s { uint8_t softSerialPortIndex; timerMode_e timerMode; - - timerOvrHandlerRec_t overCb; - timerCCHandlerRec_t edgeCb; } softSerial_t; static const struct serialPortVTable softSerialVTable; // Forward static softSerial_t softSerialPorts[MAX_SOFTSERIAL_PORTS]; -void onSerialTimerOverflow(timerOvrHandlerRec_t *cbRec, captureCompare_t capture); -void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture); +void onSerialTimerOverflow(TCH_t * tch, uint32_t capture); +void onSerialRxPinChange(TCH_t * tch, uint32_t capture); static void setTxSignal(softSerial_t *softSerial, uint8_t state) { @@ -120,21 +117,17 @@ static void setTxSignal(softSerial_t *softSerial, uint8_t state) static void serialEnableCC(softSerial_t *softSerial) { -#ifdef USE_HAL_DRIVER - TIM_CCxChannelCmd(softSerial->timerHardware->tim, softSerial->timerHardware->channel, TIM_CCx_ENABLE); -#else - TIM_CCxCmd(softSerial->timerHardware->tim, softSerial->timerHardware->channel, TIM_CCx_Enable); -#endif + timerChCaptureEnable(softSerial->tch); } static void serialInputPortActivate(softSerial_t *softSerial) { if (softSerial->port.options & SERIAL_INVERTED) { const uint8_t pinConfig = (softSerial->port.options & SERIAL_BIDIR_NOPULL) ? IOCFG_AF_PP : IOCFG_AF_PP_PD; - IOConfigGPIOAF(softSerial->rxIO, pinConfig, softSerial->timerHardware->alternateFunction); + IOConfigGPIOAF(softSerial->rxIO, pinConfig, softSerial->tch->timHw->alternateFunction); } else { const uint8_t pinConfig = (softSerial->port.options & SERIAL_BIDIR_NOPULL) ? IOCFG_AF_PP : IOCFG_AF_PP_UP; - IOConfigGPIOAF(softSerial->rxIO, pinConfig, softSerial->timerHardware->alternateFunction); + IOConfigGPIOAF(softSerial->rxIO, pinConfig, softSerial->tch->timHw->alternateFunction); } softSerial->rxActive = true; @@ -142,36 +135,29 @@ static void serialInputPortActivate(softSerial_t *softSerial) softSerial->rxBitIndex = 0; // Enable input capture - serialEnableCC(softSerial); } static void serialInputPortDeActivate(softSerial_t *softSerial) { // Disable input capture - -#ifdef USE_HAL_DRIVER - TIM_CCxChannelCmd(softSerial->timerHardware->tim, softSerial->timerHardware->channel, TIM_CCx_DISABLE); -#else - TIM_CCxCmd(softSerial->timerHardware->tim, softSerial->timerHardware->channel, TIM_CCx_Disable); -#endif - - IOConfigGPIOAF(softSerial->rxIO, IOCFG_IN_FLOATING, softSerial->timerHardware->alternateFunction); + timerChCaptureDisable(softSerial->tch); + IOConfigGPIOAF(softSerial->rxIO, IOCFG_IN_FLOATING, softSerial->tch->timHw->alternateFunction); softSerial->rxActive = false; } static void serialOutputPortActivate(softSerial_t *softSerial) { - if (softSerial->exTimerHardware) - IOConfigGPIOAF(softSerial->txIO, IOCFG_OUT_PP, softSerial->exTimerHardware->alternateFunction); + if (softSerial->exTch) + IOConfigGPIOAF(softSerial->txIO, IOCFG_OUT_PP, softSerial->exTch->timHw->alternateFunction); else IOConfigGPIO(softSerial->txIO, IOCFG_OUT_PP); } static void serialOutputPortDeActivate(softSerial_t *softSerial) { - if (softSerial->exTimerHardware) - IOConfigGPIOAF(softSerial->txIO, IOCFG_IN_FLOATING, softSerial->exTimerHardware->alternateFunction); + if (softSerial->exTch) + IOConfigGPIOAF(softSerial->txIO, IOCFG_IN_FLOATING, softSerial->exTch->timHw->alternateFunction); else IOConfigGPIO(softSerial->txIO, IOCFG_IN_FLOATING); } @@ -181,9 +167,9 @@ static bool isTimerPeriodTooLarge(uint32_t timerPeriod) return timerPeriod > 0xFFFF; } -static void serialTimerConfigureTimebase(const timerHardware_t *timerHardwarePtr, uint32_t baud) +static void serialTimerConfigureTimebase(TCH_t * tch, uint32_t baud) { - uint32_t baseClock = SystemCoreClock/timerClockDivisor(timerHardwarePtr->tim); + uint32_t baseClock = SystemCoreClock / timerClockDivisor(tch->timHw->tim); uint32_t clock = baseClock; uint32_t timerPeriod; @@ -199,9 +185,7 @@ static void serialTimerConfigureTimebase(const timerHardware_t *timerHardwarePtr } } while (isTimerPeriodTooLarge(timerPeriod)); - uint16_t mhz = baseClock / 1000000; // XXX Prepare for mhz > 255 - - timerConfigure(timerHardwarePtr, timerPeriod, mhz); + timerConfigure(tch, timerPeriod, baseClock); } static void resetBuffers(softSerial_t *softSerial) @@ -251,7 +235,11 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb return NULL; } - softSerial->timerHardware = timerTx; + softSerial->tch = timerGetTCH(timerTx); + if (!softSerial->tch) { + return NULL; + } + softSerial->txIO = txIO; softSerial->rxIO = txIO; IOInit(txIO, OWNER_SOFTSERIAL, RESOURCE_UART_TXRX, RESOURCE_INDEX(portIndex)); @@ -262,26 +250,39 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb return NULL; } + softSerial->tch = timerGetTCH(timerRx); + if (!softSerial->tch) { + return NULL; + } + softSerial->rxIO = rxIO; - softSerial->timerHardware = timerRx; IOInit(rxIO, OWNER_SOFTSERIAL, RESOURCE_UART_RX, RESOURCE_INDEX(portIndex)); } if (mode & MODE_TX) { // Need a pin on TX - if (!tagTx) + if (!tagTx) { return NULL; + } softSerial->txIO = txIO; if (!(mode & MODE_RX)) { // TX Simplex, must have a timer - if (!timerTx) + if (!timerTx) { + return NULL; + } + + softSerial->tch = timerGetTCH(timerTx); + if (!softSerial->tch) { return NULL; - softSerial->timerHardware = timerTx; + } } else { // Duplex - softSerial->exTimerHardware = timerTx; + softSerial->exTch = timerGetTCH(timerTx); + if (!softSerial->tch) { + return NULL; + } } IOInit(txIO, OWNER_SOFTSERIAL, RESOURCE_UART_TX, RESOURCE_INDEX(portIndex)); } @@ -305,33 +306,28 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb softSerial->isTransmittingData = false; // Configure master timer (on RX); time base and input capture - - serialTimerConfigureTimebase(softSerial->timerHardware, baud); - timerChConfigIC(softSerial->timerHardware, (options & SERIAL_INVERTED) ? ICPOLARITY_RISING : ICPOLARITY_FALLING, 0); - - // Initialize callbacks - timerChCCHandlerInit(&softSerial->edgeCb, onSerialRxPinChange); - timerChOvrHandlerInit(&softSerial->overCb, onSerialTimerOverflow); + serialTimerConfigureTimebase(softSerial->tch, baud); + timerChConfigIC(softSerial->tch, options & SERIAL_INVERTED, 0); // Configure bit clock interrupt & handler. // If we have an extra timer (on TX), it is initialized and configured // for overflow interrupt. // Receiver input capture is configured when input is activated. - - if ((mode & MODE_TX) && softSerial->exTimerHardware && softSerial->exTimerHardware->tim != softSerial->timerHardware->tim) { + if ((mode & MODE_TX) && softSerial->exTch && softSerial->exTch->timHw->tim != softSerial->tch->timHw->tim) { softSerial->timerMode = TIMER_MODE_DUAL; - serialTimerConfigureTimebase(softSerial->exTimerHardware, baud); - timerChConfigCallbacks(softSerial->exTimerHardware, NULL, &softSerial->overCb); - timerChConfigCallbacks(softSerial->timerHardware, &softSerial->edgeCb, NULL); + serialTimerConfigureTimebase(softSerial->exTch, baud); + + timerChInitCallbacks(&softSerial->tchCallbacks, softSerial, onSerialRxPinChange, NULL); + timerChInitCallbacks(&softSerial->exTchCallbacks, softSerial, NULL, onSerialTimerOverflow); + + timerChConfigCallbacks(softSerial->tch, &softSerial->tchCallbacks); + timerChConfigCallbacks(softSerial->exTch, &softSerial->exTchCallbacks); } else { softSerial->timerMode = TIMER_MODE_SINGLE; - timerChConfigCallbacks(softSerial->timerHardware, &softSerial->edgeCb, &softSerial->overCb); + timerChInitCallbacks(&softSerial->tchCallbacks, softSerial, onSerialRxPinChange, onSerialTimerOverflow); + timerChConfigCallbacks(softSerial->tch, &softSerial->tchCallbacks); } -#ifdef USE_HAL_DRIVER - softSerial->timerHandle = timerFindTimerHandle(softSerial->timerHardware->tim); -#endif - if (!(options & SERIAL_BIDIR)) { serialOutputPortActivate(softSerial); setTxSignal(softSerial, ENABLE); @@ -416,7 +412,7 @@ void prepareForNextRxByte(softSerial_t *softSerial) softSerial->isSearchingForStartBit = true; if (softSerial->rxEdge == LEADING) { softSerial->rxEdge = TRAILING; - timerChConfigIC(softSerial->timerHardware, (softSerial->port.options & SERIAL_INVERTED) ? ICPOLARITY_RISING : ICPOLARITY_FALLING, 0); + timerChConfigIC(softSerial->tch, softSerial->port.options & SERIAL_INVERTED, 0); serialEnableCC(softSerial); } } @@ -472,11 +468,11 @@ void processRxState(softSerial_t *softSerial) } } -void onSerialTimerOverflow(timerOvrHandlerRec_t *cbRec, captureCompare_t capture) +void onSerialTimerOverflow(TCH_t * tch, uint32_t capture) { UNUSED(capture); - softSerial_t *self = container_of(cbRec, softSerial_t, overCb); + softSerial_t * self = (softSerial_t *)tch->cb->callbackParam; if (self->port.mode & MODE_TX) processTxState(self); @@ -485,11 +481,11 @@ void onSerialTimerOverflow(timerOvrHandlerRec_t *cbRec, captureCompare_t capture processRxState(self); } -void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture) +void onSerialRxPinChange(TCH_t * tch, uint32_t capture) { UNUSED(capture); - softSerial_t *self = container_of(cbRec, softSerial_t, edgeCb); + softSerial_t * self = (softSerial_t *)tch->cb->callbackParam; bool inverted = self->port.options & SERIAL_INVERTED; if ((self->port.mode & MODE_RX) == 0) { @@ -501,9 +497,9 @@ void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture) // of the bit period. #ifdef USE_HAL_DRIVER - __HAL_TIM_SetCounter(self->timerHandle, __HAL_TIM_GetAutoreload(self->timerHandle) / 2); + __HAL_TIM_SET_COUNTER(self->tch->timCtx->timHandle, __HAL_TIM_GET_AUTORELOAD(self->tch->timCtx->timHandle) / 2); #else - TIM_SetCounter(self->timerHardware->tim, self->timerHardware->tim->ARR / 2); + TIM_SetCounter(self->tch->timHw->tim, timerGetPeriod(self->tch) / 2); #endif // For a mono-timer full duplex configuration, this may clobber the @@ -515,7 +511,7 @@ void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture) self->transmissionErrors++; } - timerChConfigIC(self->timerHardware, inverted ? ICPOLARITY_FALLING : ICPOLARITY_RISING, 0); + timerChConfigIC(self->tch, !inverted, 0); #ifdef STM32F7 serialEnableCC(self); #endif @@ -536,10 +532,10 @@ void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture) if (self->rxEdge == TRAILING) { self->rxEdge = LEADING; - timerChConfigIC(self->timerHardware, inverted ? ICPOLARITY_FALLING : ICPOLARITY_RISING, 0); + timerChConfigIC(self->tch, !inverted, 0); } else { self->rxEdge = TRAILING; - timerChConfigIC(self->timerHardware, inverted ? ICPOLARITY_RISING : ICPOLARITY_FALLING, 0); + timerChConfigIC(self->tch, inverted, 0); } #ifdef STM32F7 serialEnableCC(self); @@ -608,7 +604,7 @@ void softSerialSetBaudRate(serialPort_t *s, uint32_t baudRate) softSerial->port.baudRate = baudRate; - serialTimerConfigureTimebase(softSerial->timerHardware, baudRate); + serialTimerConfigureTimebase(softSerial->tch, baudRate); } void softSerialSetMode(serialPort_t *instance, portMode_t mode) diff --git a/src/main/drivers/serial_uart.c b/src/main/drivers/serial_uart.c index 53ec080dee3..02becdcea51 100644 --- a/src/main/drivers/serial_uart.c +++ b/src/main/drivers/serial_uart.c @@ -146,7 +146,6 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr rxCallbac } else { return (serialPort_t *)s; } - s->txDMAEmpty = true; // common serial initialisation code should move to serialPort::init() s->port.rxBufferHead = s->port.rxBufferTail = 0; @@ -160,110 +159,13 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr rxCallbac uartReconfigure(s); - // Receive DMA or IRQ - DMA_InitTypeDef DMA_InitStructure; if (mode & MODE_RX) { -#ifdef STM32F4 - if (s->rxDMAStream) { - DMA_StructInit(&DMA_InitStructure); - DMA_InitStructure.DMA_PeripheralBaseAddr = s->rxDMAPeripheralBaseAddr; - DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ; - DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ; - DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ; - DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; -#else - if (s->rxDMAChannel) { - DMA_StructInit(&DMA_InitStructure); - DMA_InitStructure.DMA_PeripheralBaseAddr = s->rxDMAPeripheralBaseAddr; - DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; - DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; -#endif - DMA_InitStructure.DMA_BufferSize = s->port.rxBufferSize; - -#ifdef STM32F4 - DMA_InitStructure.DMA_Channel = s->rxDMAChannel; - DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; - DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; - DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)s->port.rxBuffer; - DMA_DeInit(s->rxDMAStream); - DMA_Init(s->rxDMAStream, &DMA_InitStructure); - DMA_Cmd(s->rxDMAStream, ENABLE); - USART_DMACmd(s->USARTx, USART_DMAReq_Rx, ENABLE); - s->rxDMAPos = DMA_GetCurrDataCounter(s->rxDMAStream); -#else - DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; - DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; - DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)s->port.rxBuffer; - DMA_DeInit(s->rxDMAChannel); - DMA_Init(s->rxDMAChannel, &DMA_InitStructure); - DMA_Cmd(s->rxDMAChannel, ENABLE); - USART_DMACmd(s->USARTx, USART_DMAReq_Rx, ENABLE); - s->rxDMAPos = DMA_GetCurrDataCounter(s->rxDMAChannel); -#endif - } else { - USART_ClearITPendingBit(s->USARTx, USART_IT_RXNE); - USART_ITConfig(s->USARTx, USART_IT_RXNE, ENABLE); - } + USART_ClearITPendingBit(s->USARTx, USART_IT_RXNE); + USART_ITConfig(s->USARTx, USART_IT_RXNE, ENABLE); } - // Transmit DMA or IRQ if (mode & MODE_TX) { -#ifdef STM32F4 - if (s->txDMAStream) { - DMA_StructInit(&DMA_InitStructure); - DMA_InitStructure.DMA_PeripheralBaseAddr = s->txDMAPeripheralBaseAddr; - DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; - DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ; - DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ; - DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ; - DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; -#else - if (s->txDMAChannel) { - DMA_StructInit(&DMA_InitStructure); - DMA_InitStructure.DMA_PeripheralBaseAddr = s->txDMAPeripheralBaseAddr; - DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; - DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; - DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; - DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; - DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; - DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; -#endif - DMA_InitStructure.DMA_BufferSize = s->port.txBufferSize; - -#ifdef STM32F4 - DMA_InitStructure.DMA_Channel = s->txDMAChannel; - DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; - DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; - DMA_DeInit(s->txDMAStream); - DMA_Init(s->txDMAStream, &DMA_InitStructure); - DMA_ITConfig(s->txDMAStream, DMA_IT_TC | DMA_IT_FE | DMA_IT_TE | DMA_IT_DME, ENABLE); - DMA_SetCurrDataCounter(s->txDMAStream, 0); -#else - DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; - DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; - DMA_DeInit(s->txDMAChannel); - DMA_Init(s->txDMAChannel, &DMA_InitStructure); - DMA_ITConfig(s->txDMAChannel, DMA_IT_TC, ENABLE); - DMA_SetCurrDataCounter(s->txDMAChannel, 0); - s->txDMAChannel->CNDTR = 0; -#endif - USART_DMACmd(s->USARTx, USART_DMAReq_Tx, ENABLE); - } else { - USART_ITConfig(s->USARTx, USART_IT_TXE, ENABLE); - } + USART_ITConfig(s->USARTx, USART_IT_TXE, ENABLE); } USART_Cmd(s->USARTx, ENABLE); @@ -285,52 +187,9 @@ void uartSetMode(serialPort_t *instance, portMode_t mode) uartReconfigure(uartPort); } -void uartStartTxDMA(uartPort_t *s) -{ -#ifdef STM32F4 - DMA_Cmd(s->txDMAStream, DISABLE); - DMA_MemoryTargetConfig(s->txDMAStream, (uint32_t)&s->port.txBuffer[s->port.txBufferTail], DMA_Memory_0); - //s->txDMAStream->M0AR = (uint32_t)&s->port.txBuffer[s->port.txBufferTail]; - if (s->port.txBufferHead > s->port.txBufferTail) { - s->txDMAStream->NDTR = s->port.txBufferHead - s->port.txBufferTail; - s->port.txBufferTail = s->port.txBufferHead; - } - else { - s->txDMAStream->NDTR = s->port.txBufferSize - s->port.txBufferTail; - s->port.txBufferTail = 0; - } - s->txDMAEmpty = false; - DMA_Cmd(s->txDMAStream, ENABLE); -#else - s->txDMAChannel->CMAR = (uint32_t)&s->port.txBuffer[s->port.txBufferTail]; - if (s->port.txBufferHead > s->port.txBufferTail) { - s->txDMAChannel->CNDTR = s->port.txBufferHead - s->port.txBufferTail; - s->port.txBufferTail = s->port.txBufferHead; - } else { - s->txDMAChannel->CNDTR = s->port.txBufferSize - s->port.txBufferTail; - s->port.txBufferTail = 0; - } - s->txDMAEmpty = false; - DMA_Cmd(s->txDMAChannel, ENABLE); -#endif -} - uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance) { const uartPort_t *s = (const uartPort_t*)instance; -#ifdef STM32F4 - if (s->rxDMAStream) { - uint32_t rxDMAHead = s->rxDMAStream->NDTR; -#else - if (s->rxDMAChannel) { - uint32_t rxDMAHead = s->rxDMAChannel->CNDTR; -#endif - if (rxDMAHead >= s->rxDMAPos) { - return rxDMAHead - s->rxDMAPos; - } else { - return s->port.rxBufferSize + rxDMAHead - s->rxDMAPos; - } - } if (s->port.rxBufferHead >= s->port.rxBufferTail) { return s->port.rxBufferHead - s->port.rxBufferTail; @@ -351,48 +210,13 @@ uint32_t uartTotalTxBytesFree(const serialPort_t *instance) bytesUsed = s->port.txBufferSize + s->port.txBufferHead - s->port.txBufferTail; } -#ifdef STM32F4 - if (s->txDMAStream) { - /* - * When we queue up a DMA request, we advance the Tx buffer tail before the transfer finishes, so we must add - * the remaining size of that in-progress transfer here instead: - */ - bytesUsed += s->txDMAStream->NDTR; -#else - if (s->txDMAChannel) { - /* - * When we queue up a DMA request, we advance the Tx buffer tail before the transfer finishes, so we must add - * the remaining size of that in-progress transfer here instead: - */ - bytesUsed += s->txDMAChannel->CNDTR; -#endif - /* - * If the Tx buffer is being written to very quickly, we might have advanced the head into the buffer - * space occupied by the current DMA transfer. In that case the "bytesUsed" total will actually end up larger - * than the total Tx buffer size, because we'll end up transmitting the same buffer region twice. (So we'll be - * transmitting a garbage mixture of old and new bytes). - * - * Be kind to callers and pretend like our buffer can only ever be 100% full. - */ - if (bytesUsed >= s->port.txBufferSize - 1) { - return 0; - } - } - return (s->port.txBufferSize - 1) - bytesUsed; } bool isUartTransmitBufferEmpty(const serialPort_t *instance) { const uartPort_t *s = (const uartPort_t *)instance; -#ifdef STM32F4 - if (s->txDMAStream) -#else - if (s->txDMAChannel) -#endif - return s->txDMAEmpty; - else - return s->port.txBufferTail == s->port.txBufferHead; + return s->port.txBufferTail == s->port.txBufferHead; } uint8_t uartRead(serialPort_t *instance) @@ -400,21 +224,11 @@ uint8_t uartRead(serialPort_t *instance) uint8_t ch; uartPort_t *s = (uartPort_t *)instance; -#ifdef STM32F4 - if (s->rxDMAStream) { -#else - if (s->rxDMAChannel) { -#endif - ch = s->port.rxBuffer[s->port.rxBufferSize - s->rxDMAPos]; - if (--s->rxDMAPos == 0) - s->rxDMAPos = s->port.rxBufferSize; + ch = s->port.rxBuffer[s->port.rxBufferTail]; + if (s->port.rxBufferTail + 1 >= s->port.rxBufferSize) { + s->port.rxBufferTail = 0; } else { - ch = s->port.rxBuffer[s->port.rxBufferTail]; - if (s->port.rxBufferTail + 1 >= s->port.rxBufferSize) { - s->port.rxBufferTail = 0; - } else { - s->port.rxBufferTail++; - } + s->port.rxBufferTail++; } return ch; @@ -430,17 +244,7 @@ void uartWrite(serialPort_t *instance, uint8_t ch) s->port.txBufferHead++; } -#ifdef STM32F4 - if (s->txDMAStream) { - if (!(s->txDMAStream->CR & 1)) -#else - if (s->txDMAChannel) { - if (!(s->txDMAChannel->CCR & 1)) -#endif - uartStartTxDMA(s); - } else { - USART_ITConfig(s->USARTx, USART_IT_TXE, ENABLE); - } + USART_ITConfig(s->USARTx, USART_IT_TXE, ENABLE); } const struct serialPortVTable uartVTable[] = { diff --git a/src/main/drivers/serial_uart.h b/src/main/drivers/serial_uart.h index 3b318f16f97..0f30b7d4a7b 100644 --- a/src/main/drivers/serial_uart.h +++ b/src/main/drivers/serial_uart.h @@ -54,32 +54,10 @@ typedef enum { typedef struct { serialPort_t port; -#if defined(STM32F7) - DMA_HandleTypeDef rxDMAHandle; - DMA_HandleTypeDef txDMAHandle; -#endif -#if defined(STM32F4) || defined(STM32F7) - DMA_Stream_TypeDef *rxDMAStream; - DMA_Stream_TypeDef *txDMAStream; - uint32_t rxDMAChannel; - uint32_t txDMAChannel; -#else - DMA_Channel_TypeDef *rxDMAChannel; - DMA_Channel_TypeDef *txDMAChannel; -#endif - uint32_t rxDMAIrq; - uint32_t txDMAIrq; - - uint32_t rxDMAPos; - bool txDMAEmpty; - - uint32_t txDMAPeripheralBaseAddr; - uint32_t rxDMAPeripheralBaseAddr; - #ifdef USE_HAL_DRIVER - // All USARTs can also be used as UART, and we use them only as UART. UART_HandleTypeDef Handle; #endif + USART_TypeDef *USARTx; } uartPort_t; diff --git a/src/main/drivers/serial_uart_hal.c b/src/main/drivers/serial_uart_hal.c index 12540cc81fb..b14f984ef89 100644 --- a/src/main/drivers/serial_uart_hal.c +++ b/src/main/drivers/serial_uart_hal.c @@ -31,7 +31,6 @@ #include "common/utils.h" #include "drivers/io.h" #include "drivers/nvic.h" -#include "dma.h" #include "serial.h" #include "serial_uart.h" @@ -96,82 +95,21 @@ static void uartReconfigure(uartPort_t *uartPort) HAL_UART_Init(&uartPort->Handle); } - // Receive DMA or IRQ - if (uartPort->port.mode & MODE_RX) - { - if (uartPort->rxDMAStream) - { - uartPort->rxDMAHandle.Instance = uartPort->rxDMAStream; - uartPort->rxDMAHandle.Init.Channel = uartPort->rxDMAChannel; - uartPort->rxDMAHandle.Init.Direction = DMA_PERIPH_TO_MEMORY; - uartPort->rxDMAHandle.Init.PeriphInc = DMA_PINC_DISABLE; - uartPort->rxDMAHandle.Init.MemInc = DMA_MINC_ENABLE; - uartPort->rxDMAHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - uartPort->rxDMAHandle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - uartPort->rxDMAHandle.Init.Mode = DMA_CIRCULAR; - uartPort->rxDMAHandle.Init.FIFOMode = DMA_FIFOMODE_DISABLE; - uartPort->rxDMAHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_1QUARTERFULL; - uartPort->rxDMAHandle.Init.PeriphBurst = DMA_PBURST_SINGLE; - uartPort->rxDMAHandle.Init.MemBurst = DMA_MBURST_SINGLE; - uartPort->rxDMAHandle.Init.Priority = DMA_PRIORITY_MEDIUM; - - - HAL_DMA_DeInit(&uartPort->rxDMAHandle); - HAL_DMA_Init(&uartPort->rxDMAHandle); - /* Associate the initialized DMA handle to the UART handle */ - __HAL_LINKDMA(&uartPort->Handle, hdmarx, uartPort->rxDMAHandle); - - HAL_UART_Receive_DMA(&uartPort->Handle, (uint8_t*)uartPort->port.rxBuffer, uartPort->port.rxBufferSize); - - uartPort->rxDMAPos = __HAL_DMA_GET_COUNTER(&uartPort->rxDMAHandle); + if (uartPort->port.mode & MODE_RX) { + /* Enable the UART Parity Error Interrupt */ + SET_BIT(uartPort->USARTx->CR1, USART_CR1_PEIE); - } - else - { - /* Enable the UART Parity Error Interrupt */ - SET_BIT(uartPort->USARTx->CR1, USART_CR1_PEIE); - - /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ - SET_BIT(uartPort->USARTx->CR3, USART_CR3_EIE); + /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ + SET_BIT(uartPort->USARTx->CR3, USART_CR3_EIE); - /* Enable the UART Data Register not empty Interrupt */ - SET_BIT(uartPort->USARTx->CR1, USART_CR1_RXNEIE); - } + /* Enable the UART Data Register not empty Interrupt */ + SET_BIT(uartPort->USARTx->CR1, USART_CR1_RXNEIE); } - // Transmit DMA or IRQ + // Transmit IRQ if (uartPort->port.mode & MODE_TX) { - - if (uartPort->txDMAStream) { - uartPort->txDMAHandle.Instance = uartPort->txDMAStream; - uartPort->txDMAHandle.Init.Channel = uartPort->txDMAChannel; - uartPort->txDMAHandle.Init.Direction = DMA_MEMORY_TO_PERIPH; - uartPort->txDMAHandle.Init.PeriphInc = DMA_PINC_DISABLE; - uartPort->txDMAHandle.Init.MemInc = DMA_MINC_ENABLE; - uartPort->txDMAHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - uartPort->txDMAHandle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - uartPort->txDMAHandle.Init.Mode = DMA_NORMAL; - uartPort->txDMAHandle.Init.FIFOMode = DMA_FIFOMODE_DISABLE; - uartPort->txDMAHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_1QUARTERFULL; - uartPort->txDMAHandle.Init.PeriphBurst = DMA_PBURST_SINGLE; - uartPort->txDMAHandle.Init.MemBurst = DMA_MBURST_SINGLE; - uartPort->txDMAHandle.Init.Priority = DMA_PRIORITY_MEDIUM; - - - HAL_DMA_DeInit(&uartPort->txDMAHandle); - HAL_StatusTypeDef status = HAL_DMA_Init(&uartPort->txDMAHandle); - if (status != HAL_OK) - { - while (1); - } - /* Associate the initialized DMA handle to the UART handle */ - __HAL_LINKDMA(&uartPort->Handle, hdmatx, uartPort->txDMAHandle); - - __HAL_DMA_SET_COUNTER(&uartPort->txDMAHandle, 0); - } else { - /* Enable the UART Transmit Data Register Empty Interrupt */ - SET_BIT(uartPort->USARTx->CR1, USART_CR1_TXEIE); - } + /* Enable the UART Transmit Data Register Empty Interrupt */ + SET_BIT(uartPort->USARTx->CR1, USART_CR1_TXEIE); } return; } @@ -218,8 +156,6 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, } - s->txDMAEmpty = true; - // common serial initialisation code should move to serialPort::init() s->port.rxBufferHead = s->port.rxBufferTail = 0; s->port.txBufferHead = s->port.txBufferTail = 0; @@ -249,42 +185,10 @@ void uartSetMode(serialPort_t *instance, portMode_t mode) uartReconfigure(uartPort); } -void uartStartTxDMA(uartPort_t *s) -{ - uint16_t size = 0; - uint32_t fromwhere=0; - HAL_UART_StateTypeDef state = HAL_UART_GetState(&s->Handle); - if ((state & HAL_UART_STATE_BUSY_TX) == HAL_UART_STATE_BUSY_TX) - return; - - if (s->port.txBufferHead > s->port.txBufferTail) { - size = s->port.txBufferHead - s->port.txBufferTail; - fromwhere = s->port.txBufferTail; - s->port.txBufferTail = s->port.txBufferHead; - } else { - size = s->port.txBufferSize - s->port.txBufferTail; - fromwhere = s->port.txBufferTail; - s->port.txBufferTail = 0; - } - s->txDMAEmpty = false; - //HAL_CLEANCACHE((uint8_t *)&s->port.txBuffer[fromwhere],size); - HAL_UART_Transmit_DMA(&s->Handle, (uint8_t *)&s->port.txBuffer[fromwhere], size); -} - uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance) { uartPort_t *s = (uartPort_t*)instance; - if (s->rxDMAStream) { - uint32_t rxDMAHead = __HAL_DMA_GET_COUNTER(s->Handle.hdmarx); - - if (rxDMAHead >= s->rxDMAPos) { - return rxDMAHead - s->rxDMAPos; - } else { - return s->port.rxBufferSize + rxDMAHead - s->rxDMAPos; - } - } - if (s->port.rxBufferHead >= s->port.rxBufferTail) { return s->port.rxBufferHead - s->port.rxBufferTail; } else { @@ -304,37 +208,13 @@ uint32_t uartTotalTxBytesFree(const serialPort_t *instance) bytesUsed = s->port.txBufferSize + s->port.txBufferHead - s->port.txBufferTail; } - if (s->txDMAStream) { - /* - * When we queue up a DMA request, we advance the Tx buffer tail before the transfer finishes, so we must add - * the remaining size of that in-progress transfer here instead: - */ - bytesUsed += __HAL_DMA_GET_COUNTER(s->Handle.hdmatx); - - /* - * If the Tx buffer is being written to very quickly, we might have advanced the head into the buffer - * space occupied by the current DMA transfer. In that case the "bytesUsed" total will actually end up larger - * than the total Tx buffer size, because we'll end up transmitting the same buffer region twice. (So we'll be - * transmitting a garbage mixture of old and new bytes). - * - * Be kind to callers and pretend like our buffer can only ever be 100% full. - */ - if (bytesUsed >= s->port.txBufferSize - 1) { - return 0; - } - } - return (s->port.txBufferSize - 1) - bytesUsed; } bool isUartTransmitBufferEmpty(const serialPort_t *instance) { uartPort_t *s = (uartPort_t *)instance; - if (s->txDMAStream) - - return s->txDMAEmpty; - else - return s->port.txBufferTail == s->port.txBufferHead; + return s->port.txBufferTail == s->port.txBufferHead; } uint8_t uartRead(serialPort_t *instance) @@ -343,18 +223,11 @@ uint8_t uartRead(serialPort_t *instance) uartPort_t *s = (uartPort_t *)instance; - if (s->rxDMAStream) { - - ch = s->port.rxBuffer[s->port.rxBufferSize - s->rxDMAPos]; - if (--s->rxDMAPos == 0) - s->rxDMAPos = s->port.rxBufferSize; + ch = s->port.rxBuffer[s->port.rxBufferTail]; + if (s->port.rxBufferTail + 1 >= s->port.rxBufferSize) { + s->port.rxBufferTail = 0; } else { - ch = s->port.rxBuffer[s->port.rxBufferTail]; - if (s->port.rxBufferTail + 1 >= s->port.rxBufferSize) { - s->port.rxBufferTail = 0; - } else { - s->port.rxBufferTail++; - } + s->port.rxBufferTail++; } return ch; @@ -370,12 +243,7 @@ void uartWrite(serialPort_t *instance, uint8_t ch) s->port.txBufferHead++; } - if (s->txDMAStream) { - if (!(s->txDMAStream->CR & 1)) - uartStartTxDMA(s); - } else { - __HAL_UART_ENABLE_IT(&s->Handle, UART_IT_TXE); - } + __HAL_UART_ENABLE_IT(&s->Handle, UART_IT_TXE); } const struct serialPortVTable uartVTable[] = { diff --git a/src/main/drivers/serial_uart_stm32f30x.c b/src/main/drivers/serial_uart_stm32f30x.c index e71e145f4fc..b76cd2bf6bf 100644 --- a/src/main/drivers/serial_uart_stm32f30x.c +++ b/src/main/drivers/serial_uart_stm32f30x.c @@ -31,7 +31,6 @@ #include "drivers/time.h" #include "drivers/io.h" #include "drivers/nvic.h" -#include "dma.h" #include "rcc.h" #include "serial.h" @@ -99,18 +98,6 @@ static uartPort_t uartPort4; static uartPort_t uartPort5; #endif -static void handleUsartTxDma(dmaChannelDescriptor_t* descriptor) -{ - uartPort_t *s = (uartPort_t*)(descriptor->userParam); - DMA_CLEAR_FLAG(descriptor, DMA_IT_TCIF); - DMA_Cmd(descriptor->ref, DISABLE); - - if (s->port.txBufferHead != s->port.txBufferTail) - uartStartTxDMA(s); - else - s->txDMAEmpty = true; -} - void serialUARTInit(IO_t tx, IO_t rx, portMode_t mode, portOptions_t options, uint8_t af, uint8_t index) { if (options & SERIAL_BIDIR) { @@ -141,7 +128,9 @@ void serialUARTInit(IO_t tx, IO_t rx, portMode_t mode, portOptions_t options, ui #ifdef USE_UART1 uartPort_t *serialUART1(uint32_t baudRate, portMode_t mode, portOptions_t options) { + NVIC_InitTypeDef NVIC_InitStructure; uartPort_t *s; + static volatile uint8_t rx1Buffer[UART1_RX_BUFFER_SIZE]; static volatile uint8_t tx1Buffer[UART1_TX_BUFFER_SIZE]; @@ -155,32 +144,17 @@ uartPort_t *serialUART1(uint32_t baudRate, portMode_t mode, portOptions_t option s->port.rxBufferSize = UART1_RX_BUFFER_SIZE; s->port.txBufferSize = UART1_TX_BUFFER_SIZE; -#ifdef USE_UART1_RX_DMA - s->rxDMAChannel = DMA1_Channel5; -#endif - s->txDMAChannel = DMA1_Channel4; - s->USARTx = USART1; - s->rxDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->RDR; - s->txDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->TDR; - RCC_ClockCmd(RCC_APB2(USART1), ENABLE); - RCC_ClockCmd(RCC_AHB(DMA1), ENABLE); serialUARTInit(IOGetByTag(IO_TAG(UART1_TX_PIN)), IOGetByTag(IO_TAG(UART1_RX_PIN)), mode, options, GPIO_AF_7, 1); - dmaSetHandler(DMA1_CH4_HANDLER, handleUsartTxDma, NVIC_PRIO_SERIALUART1_TXDMA, (uint32_t)&uartPort1); - -#ifndef USE_UART1_RX_DMA - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_SERIALUART1_RXDMA); - NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_SERIALUART1_RXDMA); + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_SERIALUART1); + NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_SERIALUART1); NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); -#endif return s; } @@ -189,7 +163,9 @@ uartPort_t *serialUART1(uint32_t baudRate, portMode_t mode, portOptions_t option #ifdef USE_UART2 uartPort_t *serialUART2(uint32_t baudRate, portMode_t mode, portOptions_t options) { + NVIC_InitTypeDef NVIC_InitStructure; uartPort_t *s; + static volatile uint8_t rx2Buffer[UART2_RX_BUFFER_SIZE]; static volatile uint8_t tx2Buffer[UART2_TX_BUFFER_SIZE]; @@ -205,37 +181,15 @@ uartPort_t *serialUART2(uint32_t baudRate, portMode_t mode, portOptions_t option s->USARTx = USART2; -#ifdef USE_UART2_RX_DMA - s->rxDMAChannel = DMA1_Channel6; - s->rxDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->RDR; -#endif -#ifdef USE_UART2_TX_DMA - s->txDMAChannel = DMA1_Channel7; - s->txDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->TDR; -#endif - RCC_ClockCmd(RCC_APB1(USART2), ENABLE); -#if defined(USE_UART2_TX_DMA) || defined(USE_UART2_RX_DMA) - RCC_ClockCmd(RCC_AHB(DMA1), ENABLE); -#endif - serialUARTInit(IOGetByTag(IO_TAG(UART2_TX_PIN)), IOGetByTag(IO_TAG(UART2_RX_PIN)), mode, options, GPIO_AF_7, 2); -#ifdef USE_UART2_TX_DMA - // DMA TX Interrupt - dmaSetHandler(DMA1_CH7_HANDLER, handleUsartTxDma, NVIC_PRIO_SERIALUART2_TXDMA, (uint32_t)&uartPort2); -#endif - -#ifndef USE_UART2_RX_DMA - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_SERIALUART2_RXDMA); - NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_SERIALUART2_RXDMA); + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_SERIALUART2); + NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_SERIALUART2); NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); -#endif return s; } @@ -244,7 +198,9 @@ uartPort_t *serialUART2(uint32_t baudRate, portMode_t mode, portOptions_t option #ifdef USE_UART3 uartPort_t *serialUART3(uint32_t baudRate, portMode_t mode, portOptions_t options) { + NVIC_InitTypeDef NVIC_InitStructure; uartPort_t *s; + static volatile uint8_t rx3Buffer[UART3_RX_BUFFER_SIZE]; static volatile uint8_t tx3Buffer[UART3_TX_BUFFER_SIZE]; @@ -260,37 +216,15 @@ uartPort_t *serialUART3(uint32_t baudRate, portMode_t mode, portOptions_t option s->USARTx = USART3; -#ifdef USE_UART3_RX_DMA - s->rxDMAChannel = DMA1_Channel3; - s->rxDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->RDR; -#endif -#ifdef USE_UART3_TX_DMA - s->txDMAChannel = DMA1_Channel2; - s->txDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->TDR; -#endif - RCC_ClockCmd(RCC_APB1(USART3), ENABLE); -#if defined(USE_UART3_TX_DMA) || defined(USE_UART3_RX_DMA) - RCC_AHBClockCmd(RCC_AHB(DMA1), ENABLE); -#endif - serialUARTInit(IOGetByTag(IO_TAG(UART3_TX_PIN)), IOGetByTag(IO_TAG(UART3_RX_PIN)), mode, options, GPIO_AF_7, 3); -#ifdef USE_UART3_TX_DMA - // DMA TX Interrupt - dmaSetHandler(DMA1_CH2_HANDLER, handleUsartTxDma, NVIC_PRIO_SERIALUART3_TXDMA, (uint32_t)&uartPort3); -#endif - -#ifndef USE_UART3_RX_DMA - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_SERIALUART3_RXDMA); - NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_SERIALUART3_RXDMA); + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_SERIALUART3); + NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(NVIC_PRIO_SERIALUART3); NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); -#endif return s; } @@ -368,7 +302,7 @@ void usartIrqHandler(uartPort_t *s) { uint32_t ISR = s->USARTx->ISR; - if (!s->rxDMAChannel && (ISR & USART_FLAG_RXNE)) { + if (ISR & USART_FLAG_RXNE) { if (s->port.rxCallback) { s->port.rxCallback(s->USARTx->RDR, s->port.rxCallbackData); } else { @@ -379,7 +313,7 @@ void usartIrqHandler(uartPort_t *s) } } - if (!s->txDMAChannel && (ISR & USART_FLAG_TXE)) { + if (ISR & USART_FLAG_TXE) { if (s->port.txBufferTail != s->port.txBufferHead) { USART_SendData(s->USARTx, s->port.txBuffer[s->port.txBufferTail++]); if (s->port.txBufferTail >= s->port.txBufferSize) { diff --git a/src/main/drivers/serial_uart_stm32f4xx.c b/src/main/drivers/serial_uart_stm32f4xx.c index df4343ed66b..aaafc2b25a7 100644 --- a/src/main/drivers/serial_uart_stm32f4xx.c +++ b/src/main/drivers/serial_uart_stm32f4xx.c @@ -24,7 +24,6 @@ #include "drivers/io.h" #include "rcc.h" #include "drivers/nvic.h" -#include "dma.h" #include "serial.h" #include "serial_uart.h" @@ -36,9 +35,6 @@ typedef struct uartDevice_s { USART_TypeDef* dev; uartPort_t port; - uint32_t DMAChannel; - DMA_Stream_TypeDef *txDMAStream; - DMA_Stream_TypeDef *rxDMAStream; ioTag_t rx; ioTag_t tx; volatile uint8_t rxBuffer[UART_RX_BUFFER_SIZE]; @@ -47,23 +43,14 @@ typedef struct uartDevice_s { rccPeriphTag_t rcc_apb2; rccPeriphTag_t rcc_apb1; uint8_t af; - uint8_t txIrq; - uint8_t rxIrq; - uint32_t txPriority; - uint32_t rxPriority; + uint8_t irq; + uint32_t irqPriority; } uartDevice_t; //static uartPort_t uartPort[MAX_UARTS]; #ifdef USE_UART1 static uartDevice_t uart1 = { - .DMAChannel = DMA_Channel_4, -#ifdef USE_UART1_RX_DMA - .rxDMAStream = DMA2_Stream5, -#endif -#ifdef USE_UART1_TX_DMA - .txDMAStream = DMA2_Stream7, -#endif .dev = USART1, .rx = IO_TAG(UART1_RX_PIN), .tx = IO_TAG(UART1_TX_PIN), @@ -72,23 +59,14 @@ static uartDevice_t uart1 = .rcc_ahb1 = UART1_AHB1_PERIPHERALS, #endif .rcc_apb2 = RCC_APB2(USART1), - .txIrq = DMA2_ST7_HANDLER, - .rxIrq = USART1_IRQn, - .txPriority = NVIC_PRIO_SERIALUART1_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART1 + .irq = USART1_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART1 }; #endif #ifdef USE_UART2 static uartDevice_t uart2 = { - .DMAChannel = DMA_Channel_4, -#ifdef USE_UART2_RX_DMA - .rxDMAStream = DMA1_Stream5, -#endif -#ifdef USE_UART2_TX_DMA - .txDMAStream = DMA1_Stream6, -#endif .dev = USART2, .rx = IO_TAG(UART2_RX_PIN), .tx = IO_TAG(UART2_TX_PIN), @@ -97,23 +75,14 @@ static uartDevice_t uart2 = .rcc_ahb1 = UART2_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(USART2), - .txIrq = DMA1_ST6_HANDLER, - .rxIrq = USART2_IRQn, - .txPriority = NVIC_PRIO_SERIALUART2_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART2 + .irq = USART2_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART2 }; #endif #ifdef USE_UART3 static uartDevice_t uart3 = { - .DMAChannel = DMA_Channel_4, -#ifdef USE_UART3_RX_DMA - .rxDMAStream = DMA1_Stream1, -#endif -#ifdef USE_UART3_TX_DMA - .txDMAStream = DMA1_Stream3, -#endif .dev = USART3, .rx = IO_TAG(UART3_RX_PIN), .tx = IO_TAG(UART3_TX_PIN), @@ -122,23 +91,14 @@ static uartDevice_t uart3 = .rcc_ahb1 = UART3_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(USART3), - .txIrq = DMA1_ST3_HANDLER, - .rxIrq = USART3_IRQn, - .txPriority = NVIC_PRIO_SERIALUART3_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART3 + .irq = USART3_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART3 }; #endif #ifdef USE_UART4 static uartDevice_t uart4 = { - .DMAChannel = DMA_Channel_4, -#ifdef USE_UART4_RX_DMA - .rxDMAStream = DMA1_Stream2, -#endif -#ifdef USE_UART4_TX_DMA - .txDMAStream = DMA1_Stream4, -#endif .dev = UART4, .rx = IO_TAG(UART4_RX_PIN), .tx = IO_TAG(UART4_TX_PIN), @@ -147,23 +107,14 @@ static uartDevice_t uart4 = .rcc_ahb1 = UART4_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(UART4), - .txIrq = DMA1_ST4_HANDLER, - .rxIrq = UART4_IRQn, - .txPriority = NVIC_PRIO_SERIALUART4_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART4 + .irq = UART4_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART4 }; #endif #ifdef USE_UART5 static uartDevice_t uart5 = { - .DMAChannel = DMA_Channel_4, -#ifdef USE_UART5_RX_DMA - .rxDMAStream = DMA1_Stream0, -#endif -#ifdef USE_UART5_TX_DMA - .txDMAStream = DMA1_Stream7, -#endif .dev = UART5, .rx = IO_TAG(UART5_RX_PIN), .tx = IO_TAG(UART5_TX_PIN), @@ -172,23 +123,14 @@ static uartDevice_t uart5 = .rcc_ahb1 = UART5_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(UART5), - .txIrq = DMA1_ST7_HANDLER, - .rxIrq = UART5_IRQn, - .txPriority = NVIC_PRIO_SERIALUART5_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART5 + .irq = UART5_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART5 }; #endif #ifdef USE_UART6 static uartDevice_t uart6 = { - .DMAChannel = DMA_Channel_5, -#ifdef USE_UART6_RX_DMA - .rxDMAStream = DMA2_Stream1, -#endif -#ifdef USE_UART6_RX_DMA - .txDMAStream = DMA2_Stream6, -#endif .dev = USART6, .rx = IO_TAG(UART6_RX_PIN), .tx = IO_TAG(UART6_TX_PIN), @@ -197,52 +139,34 @@ static uartDevice_t uart6 = .rcc_ahb1 = UART6_AHB1_PERIPHERALS, #endif .rcc_apb2 = RCC_APB2(USART6), - .txIrq = DMA2_ST6_HANDLER, - .rxIrq = USART6_IRQn, - .txPriority = NVIC_PRIO_SERIALUART6_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART6 + .irq = USART6_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART6 }; #endif #ifdef USE_UART7 static uartDevice_t uart7 = { - .DMAChannel = DMA_Channel_5, -#ifdef USE_UART7_RX_DMA - .rxDMAStream = DMA1_Stream3, -#endif -#ifdef USE_UART7_TX_DMA - .txDMAStream = DMA1_Stream1, -#endif .dev = UART7, .rx = IO_TAG(UART7_RX_PIN), .tx = IO_TAG(UART7_TX_PIN), .af = GPIO_AF_UART7, .rcc_apb1 = RCC_APB1(UART7), - .rxIrq = UART7_IRQn, - .txPriority = NVIC_PRIO_SERIALUART7_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART7 + .irq = UART7_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART7 }; #endif #ifdef USE_UART8 static uartDevice_t uart8 = { - .DMAChannel = DMA_Channel_5, -#ifdef USE_UART8_RX_DMA - .rxDMAStream = DMA1_Stream6, -#endif -#ifdef USE_UART8_TX_DMA - .txDMAStream = DMA1_Stream0, -#endif .dev = UART8, .rx = IO_TAG(UART8_RX_PIN), .tx = IO_TAG(UART8_TX_PIN), .af = GPIO_AF_UART8, .rcc_apb1 = RCC_APB1(UART8), - .rxIrq = UART8_IRQn, - .txPriority = NVIC_PRIO_SERIALUART8_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART8 + .irq = UART8_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART8 }; #endif @@ -291,7 +215,7 @@ static uartDevice_t* uartHardwareMap[] = { void uartIrqHandler(uartPort_t *s) { - if (!s->rxDMAStream && (USART_GetITStatus(s->USARTx, USART_IT_RXNE) == SET)) { + if (USART_GetITStatus(s->USARTx, USART_IT_RXNE) == SET) { if (s->port.rxCallback) { s->port.rxCallback(s->USARTx->DR, s->port.rxCallbackData); } else { @@ -300,7 +224,7 @@ void uartIrqHandler(uartPort_t *s) } } - if (!s->txDMAStream && (USART_GetITStatus(s->USARTx, USART_IT_TXE) == SET)) { + if (USART_GetITStatus(s->USARTx, USART_IT_TXE) == SET) { if (s->port.txBufferTail != s->port.txBufferHead) { USART_SendData(s->USARTx, s->port.txBuffer[s->port.txBufferTail]); s->port.txBufferTail = (s->port.txBufferTail + 1) % s->port.txBufferSize; @@ -315,41 +239,6 @@ void uartIrqHandler(uartPort_t *s) } } -#if defined(USE_UART1_TX_DMA) || defined(USE_UART2_TX_DMA) || defined(USE_UART3_TX_DMA) || defined(USE_UART4_TX_DMA) || defined(USE_UART5_TX_DMA) || defined(USE_UART6_TX_DMA) -static void handleUsartTxDma(uartPort_t *s) -{ - DMA_Cmd(s->txDMAStream, DISABLE); - - if (s->port.txBufferHead != s->port.txBufferTail) - uartStartTxDMA(s); - else - s->txDMAEmpty = true; -} - -void dmaIRQHandler(dmaChannelDescriptor_t* descriptor) -{ - uartPort_t *s = &(((uartDevice_t*)(descriptor->userParam))->port); - if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_TCIF)) - { - DMA_CLEAR_FLAG(descriptor, DMA_IT_TCIF); - DMA_CLEAR_FLAG(descriptor, DMA_IT_HTIF); - if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_FEIF)) - { - DMA_CLEAR_FLAG(descriptor, DMA_IT_FEIF); - } - handleUsartTxDma(s); - } - if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_TEIF)) - { - DMA_CLEAR_FLAG(descriptor, DMA_IT_TEIF); - } - if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_DMEIF)) - { - DMA_CLEAR_FLAG(descriptor, DMA_IT_DMEIF); - } -} -#endif - uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_t mode, portOptions_t options) { uartPort_t *s; @@ -369,15 +258,6 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_t mode, s->port.txBufferSize = sizeof(uart->txBuffer); s->USARTx = uart->dev; - if (uart->rxDMAStream) { - s->rxDMAChannel = uart->DMAChannel; - s->rxDMAStream = uart->rxDMAStream; - } - s->txDMAChannel = uart->DMAChannel; - s->txDMAStream = uart->txDMAStream; - - s->txDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->DR; - s->rxDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->DR; IO_t tx = IOGetByTag(uart->tx); IO_t rx = IOGetByTag(uart->rx); @@ -410,18 +290,11 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_t mode, } } -#if defined(USE_UART1_TX_DMA) || defined(USE_UART2_TX_DMA) || defined(USE_UART3_TX_DMA) || defined(USE_UART4_TX_DMA) || defined(USE_UART5_TX_DMA) || defined(USE_UART6_TX_DMA) - // DMA TX Interrupt - dmaSetHandler(uart->txIrq, dmaIRQHandler, uart->txPriority, (uint32_t)uart); -#endif - - if (!(s->rxDMAChannel)) { - NVIC_InitStructure.NVIC_IRQChannel = uart->rxIrq; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(uart->rxPriority); - NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(uart->rxPriority); - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - } + NVIC_InitStructure.NVIC_IRQChannel = uart->irq; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(uart->irqPriority); + NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(uart->irqPriority); + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); return s; } diff --git a/src/main/drivers/serial_uart_stm32f7xx.c b/src/main/drivers/serial_uart_stm32f7xx.c index 71b31820280..3a4674a72ec 100644 --- a/src/main/drivers/serial_uart_stm32f7xx.c +++ b/src/main/drivers/serial_uart_stm32f7xx.c @@ -24,23 +24,17 @@ #include "drivers/io.h" #include "rcc.h" #include "drivers/nvic.h" -#include "dma.h" #include "serial.h" #include "serial_uart.h" #include "serial_uart_impl.h" -static void handleUsartTxDma(uartPort_t *s); - #define UART_RX_BUFFER_SIZE UART1_RX_BUFFER_SIZE #define UART_TX_BUFFER_SIZE UART1_TX_BUFFER_SIZE typedef struct uartDevice_s { USART_TypeDef* dev; uartPort_t port; - uint32_t DMAChannel; - DMA_Stream_TypeDef *txDMAStream; - DMA_Stream_TypeDef *rxDMAStream; ioTag_t rx; ioTag_t tx; volatile uint8_t rxBuffer[UART_RX_BUFFER_SIZE]; @@ -49,23 +43,14 @@ typedef struct uartDevice_s { rccPeriphTag_t rcc_apb2; rccPeriphTag_t rcc_apb1; uint8_t af; - uint8_t txIrq; - uint8_t rxIrq; - uint32_t txPriority; - uint32_t rxPriority; + uint8_t irq; + uint32_t irqPriority; } uartDevice_t; //static uartPort_t uartPort[MAX_UARTS]; #ifdef USE_UART1 static uartDevice_t uart1 = { - .DMAChannel = DMA_CHANNEL_4, -#ifdef USE_UART1_RX_DMA - .rxDMAStream = DMA2_Stream5, -#endif -#ifdef USE_UART1_TX_DMA - .txDMAStream = DMA2_Stream7, -#endif .dev = USART1, .rx = IO_TAG(UART1_RX_PIN), .tx = IO_TAG(UART1_TX_PIN), @@ -74,23 +59,14 @@ static uartDevice_t uart1 = .rcc_ahb1 = UART1_AHB1_PERIPHERALS, #endif .rcc_apb2 = RCC_APB2(USART1), - .txIrq = DMA2_ST7_HANDLER, - .rxIrq = USART1_IRQn, - .txPriority = NVIC_PRIO_SERIALUART1_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART1 + .irq = USART1_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART1 }; #endif #ifdef USE_UART2 static uartDevice_t uart2 = { - .DMAChannel = DMA_CHANNEL_4, -#ifdef USE_UART2_RX_DMA - .rxDMAStream = DMA1_Stream5, -#endif -#ifdef USE_UART2_TX_DMA - .txDMAStream = DMA1_Stream6, -#endif .dev = USART2, .rx = IO_TAG(UART2_RX_PIN), .tx = IO_TAG(UART2_TX_PIN), @@ -99,23 +75,14 @@ static uartDevice_t uart2 = .rcc_ahb1 = UART2_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(USART2), - .txIrq = DMA1_ST6_HANDLER, - .rxIrq = USART2_IRQn, - .txPriority = NVIC_PRIO_SERIALUART2_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART2 + .irq = USART2_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART2 }; #endif #ifdef USE_UART3 static uartDevice_t uart3 = { - .DMAChannel = DMA_CHANNEL_4, -#ifdef USE_UART3_RX_DMA - .rxDMAStream = DMA1_Stream1, -#endif -#ifdef USE_UART3_TX_DMA - .txDMAStream = DMA1_Stream3, -#endif .dev = USART3, .rx = IO_TAG(UART3_RX_PIN), .tx = IO_TAG(UART3_TX_PIN), @@ -124,23 +91,14 @@ static uartDevice_t uart3 = .rcc_ahb1 = UART3_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(USART3), - .txIrq = DMA1_ST3_HANDLER, - .rxIrq = USART3_IRQn, - .txPriority = NVIC_PRIO_SERIALUART3_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART3 + .irq = USART3_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART3 }; #endif #ifdef USE_UART4 static uartDevice_t uart4 = { - .DMAChannel = DMA_CHANNEL_4, -#ifdef USE_UART4_RX_DMA - .rxDMAStream = DMA1_Stream2, -#endif -#ifdef USE_UART4_TX_DMA - .txDMAStream = DMA1_Stream4, -#endif .dev = UART4, .rx = IO_TAG(UART4_RX_PIN), .tx = IO_TAG(UART4_TX_PIN), @@ -149,23 +107,14 @@ static uartDevice_t uart4 = .rcc_ahb1 = UART4_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(UART4), - .txIrq = DMA1_ST4_HANDLER, - .rxIrq = UART4_IRQn, - .txPriority = NVIC_PRIO_SERIALUART4_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART4 + .irq = UART4_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART4 }; #endif #ifdef USE_UART5 static uartDevice_t uart5 = { - .DMAChannel = DMA_CHANNEL_4, -#ifdef USE_UART5_RX_DMA - .rxDMAStream = DMA1_Stream0, -#endif -#ifdef USE_UART5_TX_DMA - .txDMAStream = DMA1_Stream7, -#endif .dev = UART5, .rx = IO_TAG(UART5_RX_PIN), .tx = IO_TAG(UART5_TX_PIN), @@ -174,23 +123,14 @@ static uartDevice_t uart5 = .rcc_ahb1 = UART5_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(UART5), - .txIrq = DMA1_ST7_HANDLER, - .rxIrq = UART5_IRQn, - .txPriority = NVIC_PRIO_SERIALUART5_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART5 + .irq = UART5_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART5 }; #endif #ifdef USE_UART6 static uartDevice_t uart6 = { - .DMAChannel = DMA_CHANNEL_5, -#ifdef USE_UART6_RX_DMA - .rxDMAStream = DMA2_Stream1, -#endif -#ifdef USE_UART6_TX_DMA - .txDMAStream = DMA2_Stream6, -#endif .dev = USART6, .rx = IO_TAG(UART6_RX_PIN), .tx = IO_TAG(UART6_TX_PIN), @@ -199,23 +139,14 @@ static uartDevice_t uart6 = .rcc_ahb1 = UART6_AHB1_PERIPHERALS, #endif .rcc_apb2 = RCC_APB2(USART6), - .txIrq = DMA2_ST6_HANDLER, - .rxIrq = USART6_IRQn, - .txPriority = NVIC_PRIO_SERIALUART6_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART6 + .irq = USART6_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART6 }; #endif #ifdef USE_UART7 static uartDevice_t uart7 = { - .DMAChannel = DMA_CHANNEL_5, -#ifdef USE_UART7_RX_DMA - .rxDMAStream = DMA1_Stream3, -#endif -#ifdef USE_UART7_TX_DMA - .txDMAStream = DMA1_Stream1, -#endif .dev = UART7, .rx = IO_TAG(UART7_RX_PIN), .tx = IO_TAG(UART7_TX_PIN), @@ -224,22 +155,13 @@ static uartDevice_t uart7 = .rcc_ahb1 = UART7_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(UART7), - .txIrq = DMA1_ST1_HANDLER, - .rxIrq = UART7_IRQn, - .txPriority = NVIC_PRIO_SERIALUART7_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART7 + .irq = UART7_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART7 }; #endif #ifdef USE_UART8 static uartDevice_t uart8 = { - .DMAChannel = DMA_CHANNEL_5, -#ifdef USE_UART8_RX_DMA - .rxDMAStream = DMA1_Stream6, -#endif -#ifdef USE_UART8_TX_DMA - .txDMAStream = DMA1_Stream0, -#endif .dev = UART8, .rx = IO_TAG(UART8_RX_PIN), .tx = IO_TAG(UART8_TX_PIN), @@ -248,10 +170,8 @@ static uartDevice_t uart8 = .rcc_ahb1 = UART8_AHB1_PERIPHERALS, #endif .rcc_apb1 = RCC_APB1(UART8), - .txIrq = DMA1_ST0_HANDLER, - .rxIrq = UART8_IRQn, - .txPriority = NVIC_PRIO_SERIALUART8_TXDMA, - .rxPriority = NVIC_PRIO_SERIALUART8 + .irq = UART8_IRQn, + .irqPriority = NVIC_PRIO_SERIALUART8 }; #endif @@ -342,7 +262,7 @@ void uartIrqHandler(uartPort_t *s) } /* UART in mode Transmitter ------------------------------------------------*/ - if (!s->txDMAStream && (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET)) { + if (__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) { /* Check that a Tx process is ongoing */ if (huart->gState != HAL_UART_STATE_BUSY_TX) { if (s->port.txBufferTail == s->port.txBufferHead) { @@ -363,28 +283,9 @@ void uartIrqHandler(uartPort_t *s) /* UART in mode Transmitter (transmission end) -----------------------------*/ if ((__HAL_UART_GET_IT(huart, UART_IT_TC) != RESET)) { HAL_UART_IRQHandler(huart); - if (s->txDMAStream) { - handleUsartTxDma(s); - } - } -} - -static void handleUsartTxDma(uartPort_t *s) -{ - if (s->port.txBufferHead != s->port.txBufferTail) - uartStartTxDMA(s); - else - { - s->txDMAEmpty = true; } } -void dmaIRQHandler(dmaChannelDescriptor_t* descriptor) -{ - uartPort_t *s = &(((uartDevice_t*)(descriptor->userParam))->port); - HAL_DMA_IRQHandler(&s->txDMAHandle); -} - uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_t mode, portOptions_t options) { uartPort_t *s; @@ -403,22 +304,6 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_t mode, s->port.txBufferSize = sizeof(uart->txBuffer); s->USARTx = uart->dev; - if (uart->rxDMAStream) { - s->rxDMAChannel = uart->DMAChannel; - s->rxDMAStream = uart->rxDMAStream; - } - - if (uart->txDMAStream) { - s->txDMAChannel = uart->DMAChannel; - s->txDMAStream = uart->txDMAStream; - - // DMA TX Interrupt - dmaInit(uart->txIrq, OWNER_SERIAL, RESOURCE_INDEX(device)); - dmaSetHandler(uart->txIrq, dmaIRQHandler, uart->txPriority, (uint32_t)uart); - } - - s->txDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->TDR; - s->rxDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->RDR; s->Handle.Instance = uart->dev; @@ -441,10 +326,8 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_t mode, } } - if (!s->rxDMAChannel) { - HAL_NVIC_SetPriority(uart->rxIrq, NVIC_PRIORITY_BASE(uart->rxPriority), NVIC_PRIORITY_SUB(uart->rxPriority)); - HAL_NVIC_EnableIRQ(uart->rxIrq); - } + HAL_NVIC_SetPriority(uart->irq, NVIC_PRIORITY_BASE(uart->irqPriority), NVIC_PRIORITY_SUB(uart->irqPriority)); + HAL_NVIC_EnableIRQ(uart->irq); return s; } diff --git a/src/main/drivers/timer.c b/src/main/drivers/timer.c index 06c1c0be435..fcb8c9430c8 100755 --- a/src/main/drivers/timer.c +++ b/src/main/drivers/timer.c @@ -23,6 +23,7 @@ #include "platform.h" #include "build/atomic.h" +#include "build/debug.h" #include "common/utils.h" #include "common/memory.h" @@ -35,17 +36,7 @@ #include "drivers/timer.h" #include "drivers/timer_impl.h" -#define TIM_N(n) (1 << (n)) - -/* - Groups that allow running different period (ex 50Hz servos + 400Hz throttle + etc): - TIM1 2 channels - TIM2 4 channels - TIM3 4 channels - TIM4 4 channels -*/ - -timerConfig_t * timerConfig[HARDWARE_TIMER_DEFINITION_COUNT]; +timHardwareContext_t * timerCtx[HARDWARE_TIMER_DEFINITION_COUNT]; // return index of timer in timer table. Lowest timer has index 0 uint8_t lookupTimerIndex(const TIM_TypeDef *tim) @@ -63,127 +54,114 @@ uint8_t lookupTimerIndex(const TIM_TypeDef *tim) return ~1; } -static inline uint8_t lookupChannelIndex(const uint16_t channel) -{ - return channel >> 2; -} - -void timerNVICConfigure(uint8_t irq, int irqPriority) +void timerConfigBase(TCH_t * tch, uint16_t period, uint32_t hz) { - impl_timerNVICConfigure(irq, irqPriority); -} + if (tch == NULL) { + return; + } -void timerConfigBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz) -{ - impl_timerConfigBase(tim, period, mhz); + impl_timerConfigBase(tch, period, hz); } // old interface for PWM inputs. It should be replaced -void timerConfigure(const timerHardware_t *timerHardwarePtr, uint16_t period, uint8_t mhz) +void timerConfigure(TCH_t * tch, uint16_t period, uint32_t hz) { - unsigned timer = lookupTimerIndex(timerHardwarePtr->tim); - - impl_timerConfigBase(timerDefinitions[timer].tim, period, mhz); - impl_enableTimer(timerDefinitions[timer].tim); - - if (timerDefinitions[timer].irq != 0) { - impl_timerNVICConfigure(timerDefinitions[timer].irq, NVIC_PRIO_TIMER); + if (tch == NULL) { + return; } - if (timerDefinitions[timer].secondIrq != 0) { - impl_timerNVICConfigure(timerDefinitions[timer].secondIrq, NVIC_PRIO_TIMER); - } + impl_timerConfigBase(tch, period, hz); + impl_timerNVICConfigure(tch, NVIC_PRIO_TIMER); + impl_enableTimer(tch); } -void timerChCCHandlerInit(timerCCHandlerRec_t *self, timerCCHandlerCallback *fn) +TCH_t * timerGetTCH(const timerHardware_t * timHw) { - self->fn = fn; -} + const int timerIndex = lookupTimerIndex(timHw->tim); + + if (timerIndex >= HARDWARE_TIMER_DEFINITION_COUNT) { + DEBUG_TRACE("Can't find hardware timer definition"); + return NULL; + } -void timerChOvrHandlerInit(timerOvrHandlerRec_t *self, timerOvrHandlerCallback *fn) -{ - self->fn = fn; - self->next = NULL; -} + // If timer context does not exist - allocate memory + if (timerCtx[timerIndex] == NULL) { + timerCtx[timerIndex] = memAllocate(sizeof(timHardwareContext_t), OWNER_TIMER); + + // Check for OOM + if (timerCtx[timerIndex] == NULL) { + DEBUG_TRACE("Can't allocate TCH object"); + return NULL; + } -// update overflow callback list -// some synchronization mechanism is neccesary to avoid disturbing other channels (BASEPRI used now) -static void timerChConfig_UpdateOverflow(timerConfig_t *cfg, TIM_TypeDef *tim) { - timerOvrHandlerRec_t **chain = &cfg->overflowCallbackActive; - ATOMIC_BLOCK(NVIC_PRIO_TIMER) { - for (int i = 0; i < CC_CHANNELS_PER_TIMER; i++) - if (cfg->overflowCallback[i]) { - *chain = cfg->overflowCallback[i]; - chain = &cfg->overflowCallback[i]->next; - } - *chain = NULL; - } + // Initialize parent object + memset(timerCtx[timerIndex], 0, sizeof(timHardwareContext_t)); + timerCtx[timerIndex]->timDef = &timerDefinitions[timerIndex]; + timerCtx[timerIndex]->ch[0].timCtx = timerCtx[timerIndex]; + timerCtx[timerIndex]->ch[1].timCtx = timerCtx[timerIndex]; + timerCtx[timerIndex]->ch[2].timCtx = timerCtx[timerIndex]; + timerCtx[timerIndex]->ch[3].timCtx = timerCtx[timerIndex]; - // enable or disable IRQ - if (cfg->overflowCallbackActive) { - impl_timerEnableIT(tim, IMPL_TIM_IT_UPDATE_INTERRUPT); + // Implementation-specific init + impl_timerInitContext(timerCtx[timerIndex]); } - else { - impl_timerDisableIT(tim, IMPL_TIM_IT_UPDATE_INTERRUPT); - } -} -timerConfig_t * timerGetConfigContext(int timerIndex) -{ - // If timer context does not exist - allocate memory - if (timerConfig[timerIndex] == NULL) { - timerConfig[timerIndex] = memAllocate(sizeof(timerConfig_t), OWNER_TIMER); - } + // Initialize timer channel object + timerCtx[timerIndex]->ch[timHw->channelIndex].timHw = timHw; + timerCtx[timerIndex]->ch[timHw->channelIndex].dma = NULL; + timerCtx[timerIndex]->ch[timHw->channelIndex].cb = NULL; + timerCtx[timerIndex]->ch[timHw->channelIndex].dmaState = TCH_DMA_IDLE; - return timerConfig[timerIndex]; + return &timerCtx[timerIndex]->ch[timHw->channelIndex]; } // config edge and overflow callback for channel. Try to avoid overflowCallback, it is a bit expensive -void timerChConfigCallbacks(const timerHardware_t *timHw, timerCCHandlerRec_t *edgeCallback, timerOvrHandlerRec_t *overflowCallback) +void timerChInitCallbacks(timerCallbacks_t * cb, void * callbackParam, timerCallbackFn * edgeCallback, timerCallbackFn * overflowCallback) { - uint8_t timerIndex = lookupTimerIndex(timHw->tim); + cb->callbackParam = callbackParam; + cb->callbackEdge = edgeCallback; + cb->callbackOvr = overflowCallback; +} - if (timerIndex >= HARDWARE_TIMER_DEFINITION_COUNT) { +void timerChConfigCallbacks(TCH_t * tch, timerCallbacks_t * cb) +{ + if (tch == NULL) { return; } - uint8_t channelIndex = lookupChannelIndex(timHw->channel); - if (edgeCallback == NULL) // disable irq before changing callback to NULL - impl_timerDisableIT(timHw->tim, TIM_IT_CCx(timHw->channel)); - - timerConfig_t * cfg = timerGetConfigContext(timerIndex); - - if (cfg) { - // setup callback info - cfg->edgeCallback[channelIndex] = edgeCallback; - cfg->overflowCallback[channelIndex] = overflowCallback; + if (cb->callbackEdge == NULL) { + impl_timerDisableIT(tch, TIM_IT_CCx(tch->timHw->channelIndex)); + } + + if (cb->callbackOvr == NULL) { + impl_timerDisableIT(tch, IMPL_TIM_IT_UPDATE_INTERRUPT); + } - // enable channel IRQ - if (edgeCallback) - impl_timerEnableIT(timHw->tim, TIM_IT_CCx(timHw->channel)); + tch->cb = cb; - timerChConfig_UpdateOverflow(cfg, timHw->tim); + if (cb->callbackEdge) { + impl_timerEnableIT(tch, TIM_IT_CCx(tch->timHw->channelIndex)); } - else { - // OOM error, disable IRQs for this timer - impl_timerDisableIT(timHw->tim, TIM_IT_CCx(timHw->channel)); + + if (cb->callbackOvr) { + impl_timerEnableIT(tch, IMPL_TIM_IT_UPDATE_INTERRUPT); } } // Configure input captupre -void timerChConfigIC(const timerHardware_t *timHw, bool polarityRising, unsigned inputFilterTicks) +void timerChConfigIC(TCH_t * tch, bool polarityRising, unsigned inputFilterSamples) { - impl_timerChConfigIC(timHw, polarityRising, inputFilterTicks); + impl_timerChConfigIC(tch, polarityRising, inputFilterSamples); } -uint16_t timerGetPeriod(const timerHardware_t *timHw) +uint16_t timerGetPeriod(TCH_t * tch) { - return timHw->tim->ARR; + return tch->timHw->tim->ARR; } void timerInit(void) { - memset(timerConfig, 0, sizeof (timerConfig)); + memset(timerCtx, 0, sizeof (timerCtx)); /* enable the timer peripherals */ for (int i = 0; i < timerHardwareCount; i++) { @@ -199,7 +177,7 @@ void timerInit(void) } } -const timerHardware_t *timerGetByTag(ioTag_t tag, timerUsageFlag_e flag) +const timerHardware_t * timerGetByTag(ioTag_t tag, timerUsageFlag_e flag) { if (!tag) { return NULL; @@ -215,36 +193,67 @@ const timerHardware_t *timerGetByTag(ioTag_t tag, timerUsageFlag_e flag) return NULL; } -void timerPWMConfigChannel(TIM_TypeDef * tim, uint8_t channel, bool isNChannel, bool inverted, uint16_t value) +void timerPWMConfigChannel(TCH_t * tch, uint16_t value) { - impl_timerPWMConfigChannel(tim, channel, isNChannel, inverted, value); + impl_timerPWMConfigChannel(tch, value); } -void timerEnable(TIM_TypeDef * tim) +void timerEnable(TCH_t * tch) { - impl_enableTimer(tim); + impl_enableTimer(tch); } -void timerPWMStart(TIM_TypeDef * tim, uint8_t channel, bool isNChannel) +void timerPWMStart(TCH_t * tch) { - impl_timerPWMStart(tim, channel, isNChannel); + impl_timerPWMStart(tch); } -uint16_t timerDmaSource(uint8_t channel) +volatile timCCR_t *timerCCR(TCH_t * tch) { - return impl_timerDmaSource(channel); + return impl_timerCCR(tch); } -volatile timCCR_t * timerCCR(TIM_TypeDef *tim, uint8_t channel) +void timerChCaptureEnable(TCH_t * tch) { - return impl_timerCCR(tim, channel); + impl_timerChCaptureCompareEnable(tch, true); } -uint16_t timerGetPrescalerByDesiredMhz(TIM_TypeDef *tim, uint16_t mhz) +void timerChCaptureDisable(TCH_t * tch) { - // protection here for desired MHZ > SystemCoreClock??? - if ((uint32_t)(mhz * 1000000) > (SystemCoreClock / timerClockDivisor(tim))) { - return 0; - } - return (uint16_t)(round((SystemCoreClock / timerClockDivisor(tim) / (mhz * 1000000)) - 1)); + impl_timerChCaptureCompareEnable(tch, false); +} + +uint32_t timerGetBaseClock(TCH_t * tch) +{ + return timerGetBaseClockHW(tch->timHw); +} + +uint32_t timerGetBaseClockHW(const timerHardware_t * timHw) +{ + return SystemCoreClock / timerClockDivisor(timHw->tim); } + +bool timerPWMConfigChannelDMA(TCH_t * tch, void * dmaBuffer, uint32_t dmaBufferSize) +{ + return impl_timerPWMConfigChannelDMA(tch, dmaBuffer, dmaBufferSize); +} + +void timerPWMPrepareDMA(TCH_t * tch, uint32_t dmaBufferSize) +{ + impl_timerPWMPrepareDMA(tch, dmaBufferSize); +} + +void timerPWMStartDMA(TCH_t * tch) +{ + impl_timerPWMStartDMA(tch); +} + +void timerPWMStopDMA(TCH_t * tch) +{ + impl_timerPWMStopDMA(tch); +} + +bool timerPWMDMAInProgress(TCH_t * tch) +{ + return tch->dmaState != TCH_DMA_IDLE; +} \ No newline at end of file diff --git a/src/main/drivers/timer.h b/src/main/drivers/timer.h index c762bc907e8..2fe3c39e3f8 100644 --- a/src/main/drivers/timer.h +++ b/src/main/drivers/timer.h @@ -21,7 +21,11 @@ #include #include "drivers/io_types.h" -#include "rcc_types.h" +#include "drivers/dma.h" +#include "drivers/rcc_types.h" +#include "drivers/timer_def.h" + +#define CC_CHANNELS_PER_TIMER 4 // TIM_Channel_1..4 typedef uint16_t captureCompare_t; // 16 bit on both 103 and 303, just register access must be 32bit sometimes (use timCCR_t) @@ -49,22 +53,6 @@ typedef uint32_t timCNT_t; #error "Unknown CPU defined" #endif - -// use different types from capture and overflow - multiple overflow handlers are implemented as linked list -struct timerCCHandlerRec_s; -struct timerOvrHandlerRec_s; -typedef void timerCCHandlerCallback(struct timerCCHandlerRec_s* self, uint16_t capture); -typedef void timerOvrHandlerCallback(struct timerOvrHandlerRec_s* self, uint16_t capture); - -typedef struct timerCCHandlerRec_s { - timerCCHandlerCallback* fn; -} timerCCHandlerRec_t; - -typedef struct timerOvrHandlerRec_s { - timerOvrHandlerCallback* fn; - struct timerOvrHandlerRec_s* next; -} timerOvrHandlerRec_t; - typedef struct timerDef_s { TIM_TypeDef * tim; rccPeriphTag_t rcc; @@ -85,24 +73,62 @@ typedef enum { TIM_USE_BEEPER = (1 << 25), } timerUsageFlag_e; +// TCH hardware definition (listed in target.c) typedef struct timerHardware_s { TIM_TypeDef *tim; ioTag_t tag; - uint8_t channel; + uint8_t channelIndex; uint8_t output; ioConfig_t ioMode; -#if defined(STM32F3) || defined(STM32F4) || defined(STM32F7) uint8_t alternateFunction; -#endif uint32_t usageFlags; + dmaTag_t dmaTag; } timerHardware_t; enum { - TIMER_OUTPUT_ENABLED = 0x01, + TIMER_OUTPUT_NONE = 0x00, TIMER_OUTPUT_INVERTED = 0x02, TIMER_OUTPUT_N_CHANNEL= 0x04 }; +typedef enum { + TCH_DMA_IDLE = 0, + TCH_DMA_READY, + TCH_DMA_ACTIVE, +} tchDmaState_e; + +// Some forward declarations for types +struct TCH_s; +struct timHardwareContext_s; + +// Timer generic callback +typedef void timerCallbackFn(struct TCH_s * tch, uint32_t value); + +typedef struct timerCallbacks_s { + void * callbackParam; + timerCallbackFn * callbackEdge; + timerCallbackFn * callbackOvr; +} timerCallbacks_t; + +// Run-time TCH (Timer CHannel) context +typedef struct TCH_s { + struct timHardwareContext_s * timCtx; // Run-time initialized to parent timer + const timerHardware_t * timHw; // Link to timerHardware_t definition (target-specific) + const timerCallbacks_t * cb; + DMA_t dma; // Timer channel DMA handle + volatile tchDmaState_e dmaState; + void * dmaBuffer; +} TCH_t; + +// Run-time timer context (dynamically allocated), includes 4x TCH +typedef struct timHardwareContext_s { + const timerDef_t * timDef; +#ifdef USE_HAL_DRIVER + TIM_HandleTypeDef * timHandle; +#endif + TCH_t ch[CC_CHANNELS_PER_TIMER]; +} timHardwareContext_t; + #if defined(STM32F3) #define HARDWARE_TIMER_DEFINITION_COUNT 17 #elif defined(STM32F4) @@ -113,9 +139,13 @@ enum { #error "Unknown CPU defined" #endif +// Per MCU timer definitions +extern timHardwareContext_t * timerCtx[HARDWARE_TIMER_DEFINITION_COUNT]; +extern const timerDef_t timerDefinitions[HARDWARE_TIMER_DEFINITION_COUNT]; + +// Per target timer output definitions extern const timerHardware_t timerHardware[]; extern const int timerHardwareCount; -extern const timerDef_t timerDefinitions[]; typedef enum { TYPE_FREE, @@ -135,35 +165,37 @@ typedef enum { TYPE_TIMER } channelType_t; -const timerHardware_t *timerGetByTag(ioTag_t tag, timerUsageFlag_e flag); +uint8_t timerClockDivisor(TIM_TypeDef *tim); +uint32_t timerGetBaseClockHW(const timerHardware_t * timHw); -void timerConfigure(const timerHardware_t *timHw, uint16_t period, uint8_t mhz); // This interface should be replaced. +const timerHardware_t * timerGetByTag(ioTag_t tag, timerUsageFlag_e flag); +TCH_t * timerGetTCH(const timerHardware_t * timHw); -void timerChConfigIC(const timerHardware_t *timHw, bool polarityRising, unsigned inputFilterSamples); +uint32_t timerGetBaseClock(TCH_t * tch); +void timerConfigure(TCH_t * tch, uint16_t period, uint32_t hz); // This interface should be replaced. -void timerChCCHandlerInit(timerCCHandlerRec_t *self, timerCCHandlerCallback *fn); -void timerChOvrHandlerInit(timerOvrHandlerRec_t *self, timerOvrHandlerCallback *fn); -void timerChConfigCallbacks(const timerHardware_t *channel, timerCCHandlerRec_t *edgeCallback, timerOvrHandlerRec_t *overflowCallback); +void timerChInitCallbacks(timerCallbacks_t * cb, void * callbackParam, timerCallbackFn * edgeCallback, timerCallbackFn * overflowCallback); +void timerChConfigIC(TCH_t * tch, bool polarityRising, unsigned inputFilterSamples); +void timerChConfigCallbacks(TCH_t * tch, timerCallbacks_t * cb); +void timerChCaptureEnable(TCH_t * tch); +void timerChCaptureDisable(TCH_t * tch); void timerInit(void); void timerStart(void); -uint8_t timerClockDivisor(TIM_TypeDef *tim); -uint32_t timerClock(TIM_TypeDef *tim); +void timerConfigBase(TCH_t * tch, uint16_t period, uint32_t hz); // TODO - just for migration +uint16_t timerGetPeriod(TCH_t * tch); -void timerConfigBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz); // TODO - just for migration - -uint16_t timerGetPeriod(const timerHardware_t *timHw); - -#if defined(USE_HAL_DRIVER) -TIM_HandleTypeDef * timerFindTimerHandle(TIM_TypeDef *tim); -#endif +void timerEnable(TCH_t * tch); +void timerPWMConfigChannel(TCH_t * tch, uint16_t value); +void timerPWMStart(TCH_t * tch); -void timerEnable(TIM_TypeDef * tim); -void timerPWMConfigChannel(TIM_TypeDef * tim, uint8_t channel, bool isNChannel, bool inverted, uint16_t value); -void timerPWMStart(TIM_TypeDef * tim, uint8_t channel, bool isNChannel); +bool timerPWMConfigChannelDMA(TCH_t * tch, void * dmaBuffer, uint32_t dmaBufferSize); +void timerPWMPrepareDMA(TCH_t * tch, uint32_t dmaBufferSize); +void timerPWMStartDMA(TCH_t * tch); +void timerPWMStopDMA(TCH_t * tch); +bool timerPWMDMAInProgress(TCH_t * tch); -volatile timCCR_t *timerCCR(TIM_TypeDef *tim, uint8_t channel); -uint16_t timerDmaSource(uint8_t channel); +volatile timCCR_t *timerCCR(TCH_t * tch); uint16_t timerGetPrescalerByDesiredMhz(TIM_TypeDef *tim, uint16_t mhz); diff --git a/src/main/drivers/timer_def.h b/src/main/drivers/timer_def.h new file mode 100644 index 00000000000..28c1fe2ec49 --- /dev/null +++ b/src/main/drivers/timer_def.h @@ -0,0 +1,75 @@ +/* + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ + +#pragma once + +#include "drivers/dma.h" + +// Macros expand to keep DMA descriptor table compatible with Betaflight +#define DEF_TIM_DMAMAP(variant, timch) CONCAT(DEF_TIM_DMAMAP__, PP_CALL(CONCAT(DEF_TIM_DMAMAP_VARIANT__, variant), CONCAT(DEF_TIM_DMA__, DEF_TIM_TCH2BTCH(timch)), DMA_VARIANT_MISSING, DMA_VARIANT_MISSING)) +#define DEF_TIM_DMAMAP_VARIANT__0(_0, ...) _0 +#define DEF_TIM_DMAMAP_VARIANT__1(_0, _1, ...) _1 +#define DEF_TIM_DMAMAP_VARIANT__2(_0, _1, _2, ...) _2 + +// Timer channel indexes +#define DEF_TIM_CHNL_CH1 0 +#define DEF_TIM_CHNL_CH1N 0 +#define DEF_TIM_CHNL_CH2 1 +#define DEF_TIM_CHNL_CH2N 1 +#define DEF_TIM_CHNL_CH3 2 +#define DEF_TIM_CHNL_CH3N 2 +#define DEF_TIM_CHNL_CH4 3 +#define DEF_TIM_CHNL_CH4N 3 + +// map to base channel (strip N from channel); works only when channel N exists +#define DEF_TIM_TCH2BTCH(timch) CONCAT(BTCH_, timch) +#define BTCH_TIM1_CH1N BTCH_TIM1_CH1 +#define BTCH_TIM1_CH2N BTCH_TIM1_CH2 +#define BTCH_TIM1_CH3N BTCH_TIM1_CH3 + +#define BTCH_TIM8_CH1N BTCH_TIM8_CH1 +#define BTCH_TIM8_CH2N BTCH_TIM8_CH2 +#define BTCH_TIM8_CH3N BTCH_TIM8_CH3 + +#define BTCH_TIM20_CH1N BTCH_TIM20_CH1 +#define BTCH_TIM20_CH2N BTCH_TIM20_CH2 +#define BTCH_TIM20_CH3N BTCH_TIM20_CH3 + +#define BTCH_TIM15_CH1N BTCH_TIM15_CH1 +#define BTCH_TIM16_CH1N BTCH_TIM16_CH1 + +// Default output flags +#define DEF_TIM_OUTPUT(ch) DEF_TIM_OUTPUT__ ## ch +#define DEF_TIM_OUTPUT__CH1 (TIMER_OUTPUT_NONE) +#define DEF_TIM_OUTPUT__CH2 (TIMER_OUTPUT_NONE) +#define DEF_TIM_OUTPUT__CH3 (TIMER_OUTPUT_NONE) +#define DEF_TIM_OUTPUT__CH4 (TIMER_OUTPUT_NONE) +#define DEF_TIM_OUTPUT__CH1N (TIMER_OUTPUT_N_CHANNEL) +#define DEF_TIM_OUTPUT__CH2N (TIMER_OUTPUT_N_CHANNEL) +#define DEF_TIM_OUTPUT__CH3N (TIMER_OUTPUT_N_CHANNEL) +#define DEF_TIM_OUTPUT__CH4N (TIMER_OUTPUT_N_CHANNEL) + +#if defined(STM32F3) + #include "timer_def_stm32f3xx.h" +#elif defined(STM32F4) + #include "timer_def_stm32f4xx.h" +#elif defined(STM32F7) + #include "timer_def_stm32f7xx.h" +#else + #error "Unknown CPU defined" +#endif + diff --git a/src/main/drivers/timer_def_stm32f3xx.h b/src/main/drivers/timer_def_stm32f3xx.h new file mode 100644 index 00000000000..3c5e7469ad8 --- /dev/null +++ b/src/main/drivers/timer_def_stm32f3xx.h @@ -0,0 +1,189 @@ +/* + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ + +#pragma once + +#define DEF_TIM_DMAMAP__D(dma, channel) DMA_TAG(dma, 0, channel) +#define DEF_TIM_DMAMAP__NONE DMA_NONE + +#define DEF_TIM(tim, ch, pin, usage, flags) { tim, IO_TAG(pin), DEF_TIM_CHNL_##ch, DEF_TIM_OUTPUT(ch) | flags, IOCFG_AF_PP, DEF_TIM_AF(TCH_## tim ## _ ## ch, pin), usage, DEF_TIM_DMAMAP(0, tim ## _ ## ch) } + +// AF mappings +#define DEF_TIM_AF(timch, pin) CONCAT(DEF_TIM_AF__, DEF_TIM_AF__ ## pin ## __ ## timch) +#define DEF_TIM_AF__D(af_n) GPIO_AF_ ## af_n + +/* add the DMA mappings here */ +// D(dma_n, channel_n) + +#define DEF_TIM_DMA__BTCH_TIM1_CH1 D(1, 2) +#define DEF_TIM_DMA__BTCH_TIM1_CH2 D(1, 3) +#define DEF_TIM_DMA__BTCH_TIM1_CH4 D(1, 4) +#define DEF_TIM_DMA__BTCH_TIM1_TRIG D(1, 4) +#define DEF_TIM_DMA__BTCH_TIM1_COM D(1, 4) +#define DEF_TIM_DMA__BTCH_TIM1_CH3 D(1, 6) + +#define DEF_TIM_DMA__BTCH_TIM2_CH3 D(1, 1) +#define DEF_TIM_DMA__BTCH_TIM2_CH1 D(1, 5) +#define DEF_TIM_DMA__BTCH_TIM2_CH2 D(1, 7) +#define DEF_TIM_DMA__BTCH_TIM2_CH4 D(1, 7) + +#define DEF_TIM_DMA__BTCH_TIM3_CH2 NONE +#define DEF_TIM_DMA__BTCH_TIM3_CH3 D(1, 2) +#define DEF_TIM_DMA__BTCH_TIM3_CH4 D(1, 3) +#define DEF_TIM_DMA__BTCH_TIM3_CH1 D(1, 6) +#define DEF_TIM_DMA__BTCH_TIM3_TRIG D(1, 6) + +#define DEF_TIM_DMA__BTCH_TIM4_CH1 D(1, 1) +#define DEF_TIM_DMA__BTCH_TIM4_CH2 D(1, 4) +#define DEF_TIM_DMA__BTCH_TIM4_CH3 D(1, 5) +#define DEF_TIM_DMA__BTCH_TIM4_CH4 NONE + +#define DEF_TIM_DMA__BTCH_TIM15_CH1 D(1, 5) +#define DEF_TIM_DMA__BTCH_TIM15_CH2 NONE +#define DEF_TIM_DMA__BTCH_TIM15_UP D(1, 5) +#define DEF_TIM_DMA__BTCH_TIM15_TRIG D(1, 5) +#define DEF_TIM_DMA__BTCH_TIM15_COM D(1, 5) + +// #ifdef REMAP_TIM16_DMA +// #define DEF_TIM_DMA__BTCH_TIM16_CH1 D(1, 6) +// #else +#define DEF_TIM_DMA__BTCH_TIM16_CH1 D(1, 3) +// #endif + +// #ifdef REMAP_TIM17_DMA +// #define DEF_TIM_DMA__BTCH_TIM17_CH1 D(1, 7) +// #else +#define DEF_TIM_DMA__BTCH_TIM17_CH1 D(1, 1) +// #endif + +#define DEF_TIM_DMA__BTCH_TIM8_CH3 D(2, 1) +#define DEF_TIM_DMA__BTCH_TIM8_CH4 D(2, 2) +#define DEF_TIM_DMA__BTCH_TIM8_TRIG D(2, 2) +#define DEF_TIM_DMA__BTCH_TIM8_COM D(2, 2) +#define DEF_TIM_DMA__BTCH_TIM8_CH1 D(2, 3) +#define DEF_TIM_DMA__BTCH_TIM8_CH2 D(2, 5) + +// AF table + +#define DEF_TIM_AF__PA0__TCH_TIM2_CH1 D(1) +#define DEF_TIM_AF__PA1__TCH_TIM2_CH2 D(1) +#define DEF_TIM_AF__PA2__TCH_TIM2_CH3 D(1) +#define DEF_TIM_AF__PA3__TCH_TIM2_CH4 D(1) +#define DEF_TIM_AF__PA5__TCH_TIM2_CH1 D(1) +#define DEF_TIM_AF__PA6__TCH_TIM16_CH1 D(1) +#define DEF_TIM_AF__PA7__TCH_TIM17_CH1 D(1) +#define DEF_TIM_AF__PA12__TCH_TIM16_CH1 D(1) +#define DEF_TIM_AF__PA13__TCH_TIM16_CH1N D(1) +#define DEF_TIM_AF__PA15__TCH_TIM2_CH1 D(1) + +#define DEF_TIM_AF__PA4__TCH_TIM3_CH2 D(2) +#define DEF_TIM_AF__PA6__TCH_TIM3_CH1 D(2) +#define DEF_TIM_AF__PA7__TCH_TIM3_CH2 D(2) +#define DEF_TIM_AF__PA15__TCH_TIM8_CH1 D(2) + +#define DEF_TIM_AF__PA7__TCH_TIM8_CH1N D(4) + +#define DEF_TIM_AF__PA14__TCH_TIM8_CH2 D(5) + +#define DEF_TIM_AF__PA7__TCH_TIM1_CH1N D(6) +#define DEF_TIM_AF__PA8__TCH_TIM1_CH1 D(6) +#define DEF_TIM_AF__PA9__TCH_TIM1_CH2 D(6) +#define DEF_TIM_AF__PA10__TCH_TIM1_CH3 D(6) +#define DEF_TIM_AF__PA11__TCH_TIM1_CH1N D(6) +#define DEF_TIM_AF__PA12__TCH_TIM1_CH2N D(6) + +#define DEF_TIM_AF__PA1__TCH_TIM15_CH1N D(9) +#define DEF_TIM_AF__PA2__TCH_TIM15_CH1 D(9) +#define DEF_TIM_AF__PA3__TCH_TIM15_CH2 D(9) + +#define DEF_TIM_AF__PA9__TCH_TIM2_CH3 D(10) +#define DEF_TIM_AF__PA10__TCH_TIM2_CH4 D(10) +#define DEF_TIM_AF__PA11__TCH_TIM4_CH1 D(10) +#define DEF_TIM_AF__PA12__TCH_TIM4_CH2 D(10) +#define DEF_TIM_AF__PA13__TCH_TIM4_CH3 D(10) +#define DEF_TIM_AF__PA11__TCH_TIM1_CH4 D(11) + +#define DEF_TIM_AF__PB3__TCH_TIM2_CH2 D(1) +#define DEF_TIM_AF__PB4__TCH_TIM16_CH1 D(1) +#define DEF_TIM_AF__PB6__TCH_TIM16_CH1N D(1) +#define DEF_TIM_AF__PB7__TCH_TIM17_CH1N D(1) +#define DEF_TIM_AF__PB8__TCH_TIM16_CH1 D(1) +#define DEF_TIM_AF__PB9__TCH_TIM17_CH1 D(1) +#define DEF_TIM_AF__PB10__TCH_TIM2_CH3 D(1) +#define DEF_TIM_AF__PB11__TCH_TIM2_CH4 D(1) +#define DEF_TIM_AF__PB14__TCH_TIM15_CH1 D(1) +#define DEF_TIM_AF__PB15__TCH_TIM15_CH2 D(1) + +#define DEF_TIM_AF__PB0__TCH_TIM3_CH3 D(2) +#define DEF_TIM_AF__PB1__TCH_TIM3_CH4 D(2) +#define DEF_TIM_AF__PB4__TCH_TIM3_CH1 D(2) +#define DEF_TIM_AF__PB5__TCH_TIM3_CH2 D(2) +#define DEF_TIM_AF__PB6__TCH_TIM4_CH1 D(2) +#define DEF_TIM_AF__PB7__TCH_TIM4_CH2 D(2) +#define DEF_TIM_AF__PB8__TCH_TIM4_CH3 D(2) +#define DEF_TIM_AF__PB9__TCH_TIM4_CH4 D(2) +#define DEF_TIM_AF__PB15__TCH_TIM15_CH1N D(2) + +#define DEF_TIM_AF__PB5__TCH_TIM8_CH3N D(3) + +#define DEF_TIM_AF__PB0__TCH_TIM8_CH2N D(4) +#define DEF_TIM_AF__PB1__TCH_TIM8_CH3N D(4) +#define DEF_TIM_AF__PB3__TCH_TIM8_CH1N D(4) +#define DEF_TIM_AF__PB4__TCH_TIM8_CH2N D(4) +#define DEF_TIM_AF__PB15__TCH_TIM1_CH3N D(4) + +#define DEF_TIM_AF__PB6__TCH_TIM8_CH1 D(5) + +#define DEF_TIM_AF__PB0__TCH_TIM1_CH2N D(6) +#define DEF_TIM_AF__PB1__TCH_TIM1_CH3N D(6) +#define DEF_TIM_AF__PB13__TCH_TIM1_CH1N D(6) +#define DEF_TIM_AF__PB14__TCH_TIM1_CH2N D(6) + +#define DEF_TIM_AF__PB5__TCH_TIM17_CH1 D(10) +#define DEF_TIM_AF__PB7__TCH_TIM3_CH4 D(10) +#define DEF_TIM_AF__PB8__TCH_TIM8_CH2 D(10) +#define DEF_TIM_AF__PB9__TCH_TIM8_CH3 D(10) + +#define DEF_TIM_AF__PC6__TCH_TIM3_CH1 D(2) +#define DEF_TIM_AF__PC7__TCH_TIM3_CH2 D(2) +#define DEF_TIM_AF__PC8__TCH_TIM3_CH3 D(2) +#define DEF_TIM_AF__PC9__TCH_TIM3_CH4 D(2) + +#define DEF_TIM_AF__PC6__TCH_TIM8_CH1 D(4) +#define DEF_TIM_AF__PC7__TCH_TIM8_CH2 D(4) +#define DEF_TIM_AF__PC8__TCH_TIM8_CH3 D(4) +#define DEF_TIM_AF__PC9__TCH_TIM8_CH4 D(4) + +#define DEF_TIM_AF__PC10__TCH_TIM8_CH1N D(4) +#define DEF_TIM_AF__PC11__TCH_TIM8_CH2N D(4) +#define DEF_TIM_AF__PC12__TCH_TIM8_CH3N D(4) +#define DEF_TIM_AF__PC13__TCH_TIM8_CH1N D(4) + +#define DEF_TIM_AF__PD3__TCH_TIM2_CH1 D(2) +#define DEF_TIM_AF__PD4__TCH_TIM2_CH2 D(2) +#define DEF_TIM_AF__PD6__TCH_TIM2_CH4 D(2) +#define DEF_TIM_AF__PD7__TCH_TIM2_CH3 D(2) + +#define DEF_TIM_AF__PD12__TCH_TIM4_CH1 D(2) +#define DEF_TIM_AF__PD13__TCH_TIM4_CH2 D(2) +#define DEF_TIM_AF__PD14__TCH_TIM4_CH3 D(2) +#define DEF_TIM_AF__PD15__TCH_TIM4_CH4 D(2) + +#define DEF_TIM_AF__PD1__TCH_TIM8_CH4 D(4) + +#define DEF_TIM_AF__PF9__TCH_TIM15_CH1 D(3) +#define DEF_TIM_AF__PF10__TCH_TIM15_CH2 D(3) diff --git a/src/main/drivers/timer_def_stm32f4xx.h b/src/main/drivers/timer_def_stm32f4xx.h new file mode 100644 index 00000000000..cd51c1f49d8 --- /dev/null +++ b/src/main/drivers/timer_def_stm32f4xx.h @@ -0,0 +1,75 @@ +/* + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ + +#pragma once + +#define DEF_TIM_DMAMAP__D(dma, stream, channel) DMA_TAG(dma, stream, channel) +#define DEF_TIM_DMAMAP__NONE DMA_NONE + +#define DEF_TIM(tim, ch, pin, usage, flags, dmavar) { tim, IO_TAG(pin), DEF_TIM_CHNL_ ## ch, DEF_TIM_OUTPUT(ch) | flags, IOCFG_AF_PP, GPIO_AF_ ## tim, usage, DEF_TIM_DMAMAP(dmavar, tim ## _ ## ch) } + +// AF mappings +#define DEF_TIM_AF(timch, pin) CONCAT(DEF_TIM_AF__, DEF_TIM_AF__ ## pin ## __ ## timch) +#define DEF_TIM_AF__D(af_n) GPIO_AF_ ## af_n + +/* add the DMA mappings here */ + +#define DEF_TIM_DMA__BTCH_TIM1_CH1 D(2, 6, 0),D(2, 1, 6),D(2, 3, 6) +#define DEF_TIM_DMA__BTCH_TIM1_CH2 D(2, 6, 0),D(2, 2, 6) +#define DEF_TIM_DMA__BTCH_TIM1_CH3 D(2, 6, 0),D(2, 6, 6) +#define DEF_TIM_DMA__BTCH_TIM1_CH4 D(2, 4, 6) + +#define DEF_TIM_DMA__BTCH_TIM2_CH1 D(1, 5, 3) +#define DEF_TIM_DMA__BTCH_TIM2_CH2 D(1, 6, 3) +#define DEF_TIM_DMA__BTCH_TIM2_CH3 D(1, 1, 3) +#define DEF_TIM_DMA__BTCH_TIM2_CH4 D(1, 7, 3),D(1, 6, 3) + +#define DEF_TIM_DMA__BTCH_TIM3_CH1 D(1, 4, 5) +#define DEF_TIM_DMA__BTCH_TIM3_CH2 D(1, 5, 5) +#define DEF_TIM_DMA__BTCH_TIM3_CH3 D(1, 7, 5) +#define DEF_TIM_DMA__BTCH_TIM3_CH4 D(1, 2, 5) + +#define DEF_TIM_DMA__BTCH_TIM4_CH1 D(1, 0, 2) +#define DEF_TIM_DMA__BTCH_TIM4_CH2 D(1, 3, 2) +#define DEF_TIM_DMA__BTCH_TIM4_CH3 D(1, 7, 2) + +#define DEF_TIM_DMA__BTCH_TIM5_CH1 D(1, 2, 6) +#define DEF_TIM_DMA__BTCH_TIM5_CH2 D(1, 4, 6) +#define DEF_TIM_DMA__BTCH_TIM5_CH3 D(1, 0, 6) +#define DEF_TIM_DMA__BTCH_TIM5_CH4 D(1, 1, 6),D(1, 3, 6) + +#define DEF_TIM_DMA__BTCH_TIM8_CH1 D(2, 2, 0),D(2, 2, 7) +#define DEF_TIM_DMA__BTCH_TIM8_CH2 D(2, 2, 0),D(2, 3, 7) +#define DEF_TIM_DMA__BTCH_TIM8_CH3 D(2, 2, 0),D(2, 4, 7) +#define DEF_TIM_DMA__BTCH_TIM8_CH4 D(2, 7, 7) + +#define DEF_TIM_DMA__BTCH_TIM4_CH4 NONE + +#define DEF_TIM_DMA__BTCH_TIM9_CH1 NONE +#define DEF_TIM_DMA__BTCH_TIM9_CH2 NONE + +#define DEF_TIM_DMA__BTCH_TIM10_CH1 NONE + +#define DEF_TIM_DMA__BTCH_TIM11_CH1 NONE + +#define DEF_TIM_DMA__BTCH_TIM12_CH1 NONE +#define DEF_TIM_DMA__BTCH_TIM12_CH2 NONE + +#define DEF_TIM_DMA__BTCH_TIM13_CH1 NONE + +#define DEF_TIM_DMA__BTCH_TIM14_CH1 NONE + diff --git a/src/main/drivers/timer_def_stm32f7xx.h b/src/main/drivers/timer_def_stm32f7xx.h new file mode 100644 index 00000000000..85d763a9043 --- /dev/null +++ b/src/main/drivers/timer_def_stm32f7xx.h @@ -0,0 +1,212 @@ +/* + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ + +#pragma once + +// Mappings for STDLIB defines +// #define DEF_TIM_CHNL_CH1 TIM_CHANNEL_1 +// #define DEF_TIM_CHNL_CH1N TIM_CHANNEL_1 +// #define DEF_TIM_CHNL_CH2 TIM_CHANNEL_2 +// #define DEF_TIM_CHNL_CH2N TIM_CHANNEL_2 +// #define DEF_TIM_CHNL_CH3 TIM_CHANNEL_3 +// #define DEF_TIM_CHNL_CH3N TIM_CHANNEL_3 +// #define DEF_TIM_CHNL_CH4 TIM_CHANNEL_4 +// #define DEF_TIM_CHNL_CH4N TIM_CHANNEL_4 + +#define DEF_TIM_DMAMAP__D(dma, stream, channel) DMA_TAG(dma, stream, channel) +#define DEF_TIM_DMAMAP__NONE DMA_NONE + +#define DEF_TIM(tim, ch, pin, usage, flags, dmavar) { tim, IO_TAG(pin), DEF_TIM_CHNL_ ## ch, DEF_TIM_OUTPUT(ch) | flags, IOCFG_AF_PP, DEF_TIM_AF(TCH_## tim ## _ ## ch, pin), usage, DEF_TIM_DMAMAP(dmavar, tim ## _ ## ch) } + +// AF mappings +#define DEF_TIM_AF(timch, pin) CONCAT(DEF_TIM_AF__, DEF_TIM_AF__ ## pin ## __ ## timch) +#define DEF_TIM_AF__D(af_n, tim_n) GPIO_AF ## af_n ## _TIM ## tim_n + +/* F7 Stream Mappings */ +// D(DMAx, Stream, Channel) +#define DEF_TIM_DMA__BTCH_TIM1_CH1 D(2, 6, 0),D(2, 1, 6),D(2, 3, 6) +#define DEF_TIM_DMA__BTCH_TIM1_CH2 D(2, 6, 0),D(2, 2, 6) +#define DEF_TIM_DMA__BTCH_TIM1_CH3 D(2, 6, 0),D(2, 6, 6) +#define DEF_TIM_DMA__BTCH_TIM1_CH4 D(2, 4, 6) + +#define DEF_TIM_DMA__BTCH_TIM2_CH1 D(1, 5, 3) +#define DEF_TIM_DMA__BTCH_TIM2_CH2 D(1, 6, 3) +#define DEF_TIM_DMA__BTCH_TIM2_CH3 D(1, 1, 3) +#define DEF_TIM_DMA__BTCH_TIM2_CH4 D(1, 7, 3),D(1, 6, 3) + +#define DEF_TIM_DMA__BTCH_TIM3_CH1 D(1, 4, 5) +#define DEF_TIM_DMA__BTCH_TIM3_CH2 D(1, 5, 5) +#define DEF_TIM_DMA__BTCH_TIM3_CH3 D(1, 7, 5) +#define DEF_TIM_DMA__BTCH_TIM3_CH4 D(1, 2, 5) + +#define DEF_TIM_DMA__BTCH_TIM4_CH1 D(1, 0, 2) +#define DEF_TIM_DMA__BTCH_TIM4_CH2 D(1, 3, 2) +#define DEF_TIM_DMA__BTCH_TIM4_CH3 D(1, 7, 2) + +#define DEF_TIM_DMA__BTCH_TIM5_CH1 D(1, 2, 6) +#define DEF_TIM_DMA__BTCH_TIM5_CH2 D(1, 4, 6) +#define DEF_TIM_DMA__BTCH_TIM5_CH3 D(1, 0, 6) +#define DEF_TIM_DMA__BTCH_TIM5_CH4 D(1, 1, 6),D(1, 3, 6) + +#define DEF_TIM_DMA__BTCH_TIM8_CH1 D(2, 2, 7),D(2, 2, 0) +#define DEF_TIM_DMA__BTCH_TIM8_CH2 D(2, 3, 7),D(2, 2, 0) +#define DEF_TIM_DMA__BTCH_TIM8_CH3 D(2, 4, 7),D(2, 2, 0) +#define DEF_TIM_DMA__BTCH_TIM8_CH4 D(2, 7, 7) + +#define DEF_TIM_DMA__BTCH_TIM4_CH4 NONE + +#define DEF_TIM_DMA__BTCH_TIM9_CH1 NONE +#define DEF_TIM_DMA__BTCH_TIM9_CH2 NONE + +#define DEF_TIM_DMA__BTCH_TIM10_CH1 NONE + +#define DEF_TIM_DMA__BTCH_TIM11_CH1 NONE + +#define DEF_TIM_DMA__BTCH_TIM12_CH1 NONE +#define DEF_TIM_DMA__BTCH_TIM12_CH2 NONE + +#define DEF_TIM_DMA__BTCH_TIM13_CH1 NONE + +#define DEF_TIM_DMA__BTCH_TIM14_CH1 NONE + +// TIM_UP table +#define DEF_TIM_DMA__BTCH_TIM1_UP D(2, 5, 6) +#define DEF_TIM_DMA__BTCH_TIM2_UP D(1, 7, 3) +#define DEF_TIM_DMA__BTCH_TIM3_UP D(1, 2, 5) +#define DEF_TIM_DMA__BTCH_TIM4_UP D(1, 6, 2) +#define DEF_TIM_DMA__BTCH_TIM5_UP D(1, 0, 6) +#define DEF_TIM_DMA__BTCH_TIM6_UP D(1, 1, 7) +#define DEF_TIM_DMA__BTCH_TIM7_UP D(1, 4, 1) +#define DEF_TIM_DMA__BTCH_TIM8_UP D(2, 1, 7) +#define DEF_TIM_DMA__BTCH_TIM9_UP NONE +#define DEF_TIM_DMA__BTCH_TIM10_UP NONE +#define DEF_TIM_DMA__BTCH_TIM11_UP NONE +#define DEF_TIM_DMA__BTCH_TIM12_UP NONE +#define DEF_TIM_DMA__BTCH_TIM13_UP NONE +#define DEF_TIM_DMA__BTCH_TIM14_UP NONE + +// AF table + +//PORTA +#define DEF_TIM_AF__PA0__TCH_TIM2_CH1 D(1, 2) +#define DEF_TIM_AF__PA1__TCH_TIM2_CH2 D(1, 2) +#define DEF_TIM_AF__PA2__TCH_TIM2_CH3 D(1, 2) +#define DEF_TIM_AF__PA3__TCH_TIM2_CH4 D(1, 2) +#define DEF_TIM_AF__PA5__TCH_TIM2_CH1 D(1, 2) +#define DEF_TIM_AF__PA7__TCH_TIM1_CH1N D(1, 1) +#define DEF_TIM_AF__PA8__TCH_TIM1_CH1 D(1, 1) +#define DEF_TIM_AF__PA9__TCH_TIM1_CH2 D(1, 1) +#define DEF_TIM_AF__PA10__TCH_TIM1_CH3 D(1, 1) +#define DEF_TIM_AF__PA11__TCH_TIM1_CH1N D(1, 1) +#define DEF_TIM_AF__PA15__TCH_TIM2_CH1 D(1, 2) + +#define DEF_TIM_AF__PA0__TCH_TIM5_CH1 D(2, 5) +#define DEF_TIM_AF__PA1__TCH_TIM5_CH2 D(2, 5) +#define DEF_TIM_AF__PA2__TCH_TIM5_CH3 D(2, 5) +#define DEF_TIM_AF__PA3__TCH_TIM5_CH4 D(2, 5) +#define DEF_TIM_AF__PA6__TCH_TIM3_CH1 D(2, 3) +#define DEF_TIM_AF__PA7__TCH_TIM3_CH2 D(2, 3) + +#define DEF_TIM_AF__PA2__TCH_TIM9_CH1 D(3, 9) +#define DEF_TIM_AF__PA3__TCH_TIM9_CH2 D(3, 9) +#define DEF_TIM_AF__PA5__TCH_TIM8_CH1N D(3, 8) +#define DEF_TIM_AF__PA7__TCH_TIM8_CH1N D(3, 8) + +#define DEF_TIM_AF__PA6__TCH_TIM13_CH1 D(9, 13) +#define DEF_TIM_AF__PA7__TCH_TIM14_CH1 D(9, 14) + +//PORTB +#define DEF_TIM_AF__PB0__TCH_TIM1_CH2N D(1, 1) +#define DEF_TIM_AF__PB1__TCH_TIM1_CH3N D(1, 1) +#define DEF_TIM_AF__PB3__TCH_TIM2_CH2 D(1, 2) +#define DEF_TIM_AF__PB10__TCH_TIM2_CH3 D(1, 2) +#define DEF_TIM_AF__PB11__TCH_TIM2_CH4 D(1, 2) +#define DEF_TIM_AF__PB13__TCH_TIM1_CH1N D(1, 1) +#define DEF_TIM_AF__PB14__TCH_TIM1_CH2N D(1, 1) +#define DEF_TIM_AF__PB15__TCH_TIM1_CH3N D(1, 1) + +#define DEF_TIM_AF__PB0__TCH_TIM3_CH3 D(2, 3) +#define DEF_TIM_AF__PB1__TCH_TIM3_CH4 D(2, 3) +#define DEF_TIM_AF__PB4__TCH_TIM3_CH1 D(2, 3) +#define DEF_TIM_AF__PB5__TCH_TIM3_CH2 D(2, 3) +#define DEF_TIM_AF__PB6__TCH_TIM4_CH1 D(2, 4) +#define DEF_TIM_AF__PB7__TCH_TIM4_CH2 D(2, 4) +#define DEF_TIM_AF__PB8__TCH_TIM4_CH3 D(2, 4) +#define DEF_TIM_AF__PB9__TCH_TIM4_CH4 D(2, 4) + +#define DEF_TIM_AF__PB0__TCH_TIM8_CH2N D(3, 8) +#define DEF_TIM_AF__PB1__TCH_TIM8_CH3N D(3, 8) +#define DEF_TIM_AF__PB8__TCH_TIM10_CH1 D(3, 10) +#define DEF_TIM_AF__PB9__TCH_TIM11_CH1 D(3, 11) +#define DEF_TIM_AF__PB14__TCH_TIM8_CH2N D(3, 8) +#define DEF_TIM_AF__PB15__TCH_TIM8_CH3N D(3, 8) + +#define DEF_TIM_AF__PB14__TCH_TIM12_CH1 D(9, 12) +#define DEF_TIM_AF__PB15__TCH_TIM12_CH2 D(9, 12) + +//PORTC +#define DEF_TIM_AF__PC6__TCH_TIM3_CH1 D(2, 3) +#define DEF_TIM_AF__PC7__TCH_TIM3_CH2 D(2, 3) +#define DEF_TIM_AF__PC8__TCH_TIM3_CH3 D(2, 3) +#define DEF_TIM_AF__PC9__TCH_TIM3_CH4 D(2, 3) + +#define DEF_TIM_AF__PC6__TCH_TIM8_CH1 D(3, 8) +#define DEF_TIM_AF__PC7__TCH_TIM8_CH2 D(3, 8) +#define DEF_TIM_AF__PC8__TCH_TIM8_CH3 D(3, 8) +#define DEF_TIM_AF__PC9__TCH_TIM8_CH4 D(3, 8) + +//PORTD +#define DEF_TIM_AF__PD12__TCH_TIM4_CH1 D(2, 4) +#define DEF_TIM_AF__PD13__TCH_TIM4_CH2 D(2, 4) +#define DEF_TIM_AF__PD14__TCH_TIM4_CH3 D(2, 4) +#define DEF_TIM_AF__PD15__TCH_TIM4_CH4 D(2, 4) + +//PORTE +#define DEF_TIM_AF__PE8__TCH_TIM1_CH1N D(1, 1) +#define DEF_TIM_AF__PE9__TCH_TIM1_CH1 D(1, 1) +#define DEF_TIM_AF__PE10__TCH_TIM1_CH2N D(1, 1) +#define DEF_TIM_AF__PE11__TCH_TIM1_CH2 D(1, 1) +#define DEF_TIM_AF__PE12__TCH_TIM1_CH3N D(1, 1) +#define DEF_TIM_AF__PE13__TCH_TIM1_CH3 D(1, 1) +#define DEF_TIM_AF__PE14__TCH_TIM1_CH4 D(1, 1) + +#define DEF_TIM_AF__PE5__TCH_TIM9_CH1 D(3, 9) +#define DEF_TIM_AF__PE6__TCH_TIM9_CH2 D(3, 9) + +//PORTF +#define DEF_TIM_AF__PF6__TCH_TIM10_CH1 D(3, 10) +#define DEF_TIM_AF__PF7__TCH_TIM11_CH1 D(3, 11) + +//PORTH +#define DEF_TIM_AF__PH10__TCH_TIM5_CH1 D(2, 5) +#define DEF_TIM_AF__PH11__TCH_TIM5_CH2 D(2, 5) +#define DEF_TIM_AF__PH12__TCH_TIM5_CH3 D(2, 5) + +#define DEF_TIM_AF__PH13__TCH_TIM8_CH1N D(3, 8) +#define DEF_TIM_AF__PH14__TCH_TIM8_CH2N D(3, 8) +#define DEF_TIM_AF__PH15__TCH_TIM8_CH3N D(3, 8) + +#define DEF_TIM_AF__PH6__TCH_TIM12_CH1 D(9, 12) +#define DEF_TIM_AF__PH9__TCH_TIM12_CH2 D(9, 12) + +//PORTI +#define DEF_TIM_AF__PI0__TCH_TIM5_CH4 D(2, 5) + +#define DEF_TIM_AF__PI2__TCH_TIM8_CH4 D(3, 8) +#define DEF_TIM_AF__PI5__TCH_TIM8_CH1 D(3, 8) +#define DEF_TIM_AF__PI6__TCH_TIM8_CH2 D(3, 8) +#define DEF_TIM_AF__PI7__TCH_TIM8_CH3 D(3, 8) diff --git a/src/main/drivers/timer_impl.h b/src/main/drivers/timer_impl.h index 5f413d67b54..aa9b7fee271 100644 --- a/src/main/drivers/timer_impl.h +++ b/src/main/drivers/timer_impl.h @@ -1,64 +1,61 @@ /* - * This file is part of Cleanflight. + * This file is part of INAV. * - * Cleanflight is free software: you can redistribute it and/or modify + * INAV is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * Cleanflight is distributed in the hope that it will be useful, + * INAV is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Cleanflight. If not, see . + * along with INAV. If not, see . */ #pragma once -#define CC_CHANNELS_PER_TIMER 4 // TIM_Channel_1..4 - #if defined(USE_HAL_DRIVER) # define IMPL_TIM_IT_UPDATE_INTERRUPT TIM_IT_UPDATE -# define TIM_IT_CCx(ch) (TIM_IT_CC1 << ((ch) / 4)) +# define TIM_IT_CCx(chIdx) (TIM_IT_CC1 << (chIdx)) #else # define IMPL_TIM_IT_UPDATE_INTERRUPT TIM_IT_Update -# define TIM_IT_CCx(ch) (TIM_IT_CC1 << ((ch) / 4)) +# define TIM_IT_CCx(chIdx) (TIM_IT_CC1 << (chIdx)) #endif -typedef struct timerConfig_s { - timerCCHandlerRec_t *edgeCallback[CC_CHANNELS_PER_TIMER]; - timerOvrHandlerRec_t *overflowCallback[CC_CHANNELS_PER_TIMER]; - timerOvrHandlerRec_t *overflowCallbackActive; // null-terminated linkded list of active overflow callbacks -} timerConfig_t; - -extern timerConfig_t * timerConfig[HARDWARE_TIMER_DEFINITION_COUNT]; - #define _TIM_IRQ_HANDLER2(name, i, j) \ void name(void) \ { \ - impl_timerCaptureCompareHandler(TIM ## i, timerConfig[i - 1]); \ - impl_timerCaptureCompareHandler(TIM ## j, timerConfig[j - 1]); \ + impl_timerCaptureCompareHandler(TIM ## i, timerCtx[i - 1]); \ + impl_timerCaptureCompareHandler(TIM ## j, timerCtx[j - 1]); \ } struct dummy #define _TIM_IRQ_HANDLER(name, i) \ void name(void) \ { \ - impl_timerCaptureCompareHandler(TIM ## i, timerConfig[i - 1]); \ + impl_timerCaptureCompareHandler(TIM ## i, timerCtx[i - 1]); \ } struct dummy uint8_t lookupTimerIndex(const TIM_TypeDef *tim); -void impl_timerNVICConfigure(uint8_t irq, int irqPriority); -void impl_timerConfigBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz); -void impl_enableTimer(TIM_TypeDef * tim); -void impl_timerEnableIT(TIM_TypeDef * tim, uint32_t interrupt); -void impl_timerDisableIT(TIM_TypeDef * tim, uint32_t interrupt); -void impl_timerClearFlag(TIM_TypeDef * tim, uint32_t flag); -void impl_timerChConfigIC(const timerHardware_t *timHw, bool polarityRising, unsigned inputFilterTicks); -void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timerConfig_t *timerConfig); -void impl_timerPWMConfigChannel(TIM_TypeDef * tim, uint8_t channel, bool isNChannel, bool inverted, uint16_t value); -void impl_timerPWMStart(TIM_TypeDef * tim, unsigned channel, bool isNChannel); -uint16_t impl_timerDmaSource(uint8_t channel); -volatile timCCR_t * impl_timerCCR(TIM_TypeDef *tim, uint8_t channel); - +void impl_timerInitContext(timHardwareContext_t * timCtx); + +volatile timCCR_t * impl_timerCCR(TCH_t * tch); +void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timHardwareContext_t * timerCtx); + +void impl_timerNVICConfigure(TCH_t * tch, int irqPriority); +void impl_timerConfigBase(TCH_t * tch, uint16_t period, uint32_t hz); +void impl_enableTimer(TCH_t * tch); +void impl_timerEnableIT(TCH_t * tch, uint32_t interrupt); +void impl_timerDisableIT(TCH_t * tch, uint32_t interrupt); +void impl_timerClearFlag(TCH_t * tch, uint32_t flag); +void impl_timerChConfigIC(TCH_t * tch, bool polarityRising, unsigned inputFilterTicks); +void impl_timerChCaptureCompareEnable(TCH_t * tch, bool enable); + +void impl_timerPWMConfigChannel(TCH_t * tch, uint16_t value); +void impl_timerPWMStart(TCH_t * tch); +bool impl_timerPWMConfigChannelDMA(TCH_t * tch, void * dmaBuffer, uint32_t dmaBufferSize); +void impl_timerPWMPrepareDMA(TCH_t * tch, uint32_t dmaBufferSize); +void impl_timerPWMStartDMA(TCH_t * tch); +void impl_timerPWMStopDMA(TCH_t * tch); diff --git a/src/main/drivers/timer_impl_hal.c b/src/main/drivers/timer_impl_hal.c index cb1e0af4fad..1008c965631 100644 --- a/src/main/drivers/timer_impl_hal.c +++ b/src/main/drivers/timer_impl_hal.c @@ -1,9 +1,19 @@ /* - modified version of StdPeriph function is located here. - TODO - what license does apply here? - original file was lincesed under MCD-ST Liberty SW License Agreement V2 - http://www.st.com/software_license_agreement_liberty_v2 -*/ + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ #include #include @@ -12,6 +22,7 @@ #include "platform.h" #include "build/atomic.h" +#include "build/debug.h" #include "common/utils.h" @@ -22,9 +33,17 @@ #include "drivers/timer.h" #include "drivers/timer_impl.h" +extern uint32_t timerClock(TIM_TypeDef *tim); + +const uint16_t lookupDMAIndexTable[] = { TIM_DMA_ID_CC1, TIM_DMA_ID_CC2, TIM_DMA_ID_CC3, TIM_DMA_ID_CC4 }; +const uint16_t lookupDMASourceTable[] = { TIM_DMA_CC1, TIM_DMA_CC2, TIM_DMA_CC3, TIM_DMA_CC4 }; +const uint8_t lookupTIMChannelTable[] = { TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, TIM_CHANNEL_4 }; + +static const uint16_t lookupDMALLStreamTable[] = { LL_DMA_STREAM_0, LL_DMA_STREAM_1, LL_DMA_STREAM_2, LL_DMA_STREAM_3, LL_DMA_STREAM_4, LL_DMA_STREAM_5, LL_DMA_STREAM_6, LL_DMA_STREAM_7 }; + static TIM_HandleTypeDef timerHandle[HARDWARE_TIMER_DEFINITION_COUNT]; -TIM_HandleTypeDef * timerFindTimerHandle(TIM_TypeDef *tim) +static TIM_HandleTypeDef * timerFindTimerHandle(TIM_TypeDef *tim) { uint8_t timerIndex = lookupTimerIndex(tim); if (timerIndex >= HARDWARE_TIMER_DEFINITION_COUNT) { @@ -34,105 +53,126 @@ TIM_HandleTypeDef * timerFindTimerHandle(TIM_TypeDef *tim) return &timerHandle[timerIndex]; } -void impl_timerNVICConfigure(uint8_t irq, int irqPriority) +void impl_timerInitContext(timHardwareContext_t * timCtx) { - HAL_NVIC_SetPriority(irq, NVIC_PRIORITY_BASE(irqPriority), NVIC_PRIORITY_SUB(irqPriority)); - HAL_NVIC_EnableIRQ(irq); + timCtx->timHandle = timerFindTimerHandle(timCtx->timDef->tim); } -void impl_timerConfigBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz) +void impl_timerNVICConfigure(TCH_t * tch, int irqPriority) { - uint8_t timerIndex = lookupTimerIndex(tim); + if (tch->timCtx->timDef->irq) { + HAL_NVIC_SetPriority(tch->timCtx->timDef->irq, NVIC_PRIORITY_BASE(irqPriority), NVIC_PRIORITY_SUB(irqPriority)); + HAL_NVIC_EnableIRQ(tch->timCtx->timDef->irq); + } - if (timerIndex >= HARDWARE_TIMER_DEFINITION_COUNT) { - return; + if (tch->timCtx->timDef->secondIrq) { + HAL_NVIC_SetPriority(tch->timCtx->timDef->secondIrq, NVIC_PRIORITY_BASE(irqPriority), NVIC_PRIORITY_SUB(irqPriority)); + HAL_NVIC_EnableIRQ(tch->timCtx->timDef->secondIrq); } +} + +void impl_timerConfigBase(TCH_t * tch, uint16_t period, uint32_t hz) +{ + // Get and verify HAL TIM_Handle object + TIM_HandleTypeDef * timHandle = tch->timCtx->timHandle; + TIM_TypeDef * timer = tch->timCtx->timDef->tim; - if (timerHandle[timerIndex].Instance == tim) - { - // already configured + if (timHandle->Instance == timer) { return; } - timerHandle[timerIndex].Instance = tim; - timerHandle[timerIndex].Init.Period = (period - 1) & 0xffff; // AKA TIMx_ARR - timerHandle[timerIndex].Init.Prescaler = (timerClock(tim) / ((uint32_t)mhz * 1000000)) - 1; - timerHandle[timerIndex].Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - timerHandle[timerIndex].Init.CounterMode = TIM_COUNTERMODE_UP; - timerHandle[timerIndex].Init.RepetitionCounter = 0x0000; + timHandle->Instance = timer; + timHandle->Init.Prescaler = (timerGetBaseClock(tch) / hz) - 1; + timHandle->Init.Period = (period - 1) & 0xffff; // AKA TIMx_ARR + timHandle->Init.RepetitionCounter = 0; + timHandle->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + timHandle->Init.CounterMode = TIM_COUNTERMODE_UP; + timHandle->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; - HAL_TIM_Base_Init(&timerHandle[timerIndex]); - if (tim == TIM1 || tim == TIM2 || tim == TIM3 || tim == TIM4 || tim == TIM5 || tim == TIM8 || tim == TIM9) - { + HAL_TIM_Base_Init(timHandle); + if (timer == TIM1 || timer == TIM2 || timer == TIM3 || timer == TIM4 || timer == TIM5 || timer == TIM8 || timer == TIM9) { TIM_ClockConfigTypeDef sClockSourceConfig; memset(&sClockSourceConfig, 0, sizeof(sClockSourceConfig)); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - if (HAL_TIM_ConfigClockSource(&timerHandle[timerIndex], &sClockSourceConfig) != HAL_OK) { + if (HAL_TIM_ConfigClockSource(timHandle, &sClockSourceConfig) != HAL_OK) { return; } } - if (tim == TIM1 || tim == TIM2 || tim == TIM3 || tim == TIM4 || tim == TIM5 || tim == TIM8 ) - { + + if (timer == TIM1 || timer == TIM2 || timer == TIM3 || timer == TIM4 || timer == TIM5 || timer == TIM8) { TIM_MasterConfigTypeDef sMasterConfig; memset(&sMasterConfig, 0, sizeof(sMasterConfig)); sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - if (HAL_TIMEx_MasterConfigSynchronization(&timerHandle[timerIndex], &sMasterConfig) != HAL_OK) { + if (HAL_TIMEx_MasterConfigSynchronization(timHandle, &sMasterConfig) != HAL_OK) { return; } } } -void impl_enableTimer(TIM_TypeDef * tim) +void impl_timerPWMConfigChannel(TCH_t * tch, uint16_t value) { - TIM_HandleTypeDef * Handle = timerFindTimerHandle(tim); - if (Handle == NULL) { - return; - } + const bool inverted = tch->timHw->output & TIMER_OUTPUT_INVERTED; - HAL_TIM_Base_Start(Handle); -} + TIM_OC_InitTypeDef TIM_OCInitStructure; -void impl_timerPWMStart(TIM_TypeDef * tim, unsigned channel, bool isNChannel) -{ - TIM_HandleTypeDef * Handle = timerFindTimerHandle(tim); - if (Handle == NULL) { - return; - } + TIM_OCInitStructure.OCMode = TIM_OCMODE_PWM1; + TIM_OCInitStructure.OCIdleState = TIM_OCIDLESTATE_SET; + TIM_OCInitStructure.OCPolarity = inverted ? TIM_OCPOLARITY_LOW : TIM_OCPOLARITY_HIGH; + TIM_OCInitStructure.OCNIdleState = TIM_OCNIDLESTATE_SET; + TIM_OCInitStructure.OCNPolarity = inverted ? TIM_OCNPOLARITY_LOW : TIM_OCNPOLARITY_HIGH; + TIM_OCInitStructure.Pulse = value; + TIM_OCInitStructure.OCFastMode = TIM_OCFAST_DISABLE; - if (isNChannel) - HAL_TIMEx_PWMN_Start(Handle, channel); - else - HAL_TIM_PWM_Start(Handle, channel); + HAL_TIM_PWM_ConfigChannel(tch->timCtx->timHandle, &TIM_OCInitStructure, lookupTIMChannelTable[tch->timHw->channelIndex]); } -void impl_timerEnableIT(TIM_TypeDef * tim, uint32_t interrupt) +volatile timCCR_t * impl_timerCCR(TCH_t * tch) { - TIM_HandleTypeDef * Handle = timerFindTimerHandle(tim); - if (Handle == NULL) { - return; + switch (tch->timHw->channelIndex) { + case 0: + return &tch->timHw->tim->CCR1; + break; + case 1: + return &tch->timHw->tim->CCR2; + break; + case 2: + return &tch->timHw->tim->CCR3; + break; + case 3: + return &tch->timHw->tim->CCR4; + break; } + return NULL; +} - __HAL_TIM_ENABLE_IT(Handle, interrupt); +void impl_enableTimer(TCH_t * tch) +{ + HAL_TIM_Base_Start(tch->timCtx->timHandle); } -void impl_timerDisableIT(TIM_TypeDef * tim, uint32_t interrupt) +void impl_timerPWMStart(TCH_t * tch) { - TIM_HandleTypeDef * Handle = timerFindTimerHandle(tim); - if (Handle == NULL) { - return; + if (tch->timHw->output & TIMER_OUTPUT_N_CHANNEL) { + HAL_TIMEx_PWMN_Start(tch->timCtx->timHandle, lookupTIMChannelTable[tch->timHw->channelIndex]); } + else { + HAL_TIM_PWM_Start(tch->timCtx->timHandle, lookupTIMChannelTable[tch->timHw->channelIndex]); + } +} - __HAL_TIM_DISABLE_IT(Handle, interrupt); +void impl_timerEnableIT(TCH_t * tch, uint32_t interrupt) +{ + __HAL_TIM_ENABLE_IT(tch->timCtx->timHandle, interrupt); } -void impl_timerClearFlag(TIM_TypeDef * tim, uint32_t flag) +void impl_timerDisableIT(TCH_t * tch, uint32_t interrupt) { - TIM_HandleTypeDef * Handle = timerFindTimerHandle(tim); - if (Handle == NULL) { - return; - } + __HAL_TIM_DISABLE_IT(tch->timCtx->timHandle, interrupt); +} - __HAL_TIM_CLEAR_FLAG(Handle, flag); +void impl_timerClearFlag(TCH_t * tch, uint32_t flag) +{ + __HAL_TIM_CLEAR_FLAG(tch->timCtx->timHandle, flag); } // calculate input filter constant @@ -147,29 +187,28 @@ static unsigned getFilter(unsigned ticks) 16*5, 16*6, 16*8, 32*5, 32*6, 32*8 }; - for (unsigned i = 1; i < ARRAYLEN(ftab); i++) - if (ftab[i] > ticks) + + for (unsigned i = 1; i < ARRAYLEN(ftab); i++) { + if (ftab[i] > ticks) { return i - 1; + } + } + return 0x0f; } -void impl_timerChConfigIC(const timerHardware_t *timHw, bool polarityRising, unsigned inputFilterTicks) +void impl_timerChConfigIC(TCH_t * tch, bool polarityRising, unsigned inputFilterTicks) { - TIM_HandleTypeDef * Handle = timerFindTimerHandle(timHw->tim); - if (Handle == NULL) { - return; - } - TIM_IC_InitTypeDef TIM_ICInitStructure; TIM_ICInitStructure.ICPolarity = polarityRising ? TIM_ICPOLARITY_RISING : TIM_ICPOLARITY_FALLING; TIM_ICInitStructure.ICSelection = TIM_ICSELECTION_DIRECTTI; TIM_ICInitStructure.ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.ICFilter = getFilter(inputFilterTicks); - HAL_TIM_IC_ConfigChannel(Handle,&TIM_ICInitStructure, timHw->channel); + HAL_TIM_IC_ConfigChannel(tch->timCtx->timHandle, &TIM_ICInitStructure, lookupTIMChannelTable[tch->timHw->channelIndex]); } -void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timerConfig_t * timerConfig) +void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timHardwareContext_t *timerCtx) { unsigned tim_status = tim->SR & tim->DIER; @@ -181,28 +220,35 @@ void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timerConfig_t * timerConf tim->SR = mask; tim_status &= mask; - if (timerConfig) { + if (timerCtx) { switch (bit) { case __builtin_clz(TIM_IT_UPDATE): { const uint16_t capture = tim->ARR; - timerOvrHandlerRec_t *cb = timerConfig->overflowCallbackActive; - while (cb) { - cb->fn(cb, capture); - cb = cb->next; + if (timerCtx->ch[0].cb && timerCtx->ch[0].cb->callbackOvr) { + timerCtx->ch[0].cb->callbackOvr(&timerCtx->ch[0], capture); + } + if (timerCtx->ch[1].cb && timerCtx->ch[1].cb->callbackOvr) { + timerCtx->ch[1].cb->callbackOvr(&timerCtx->ch[1], capture); + } + if (timerCtx->ch[2].cb && timerCtx->ch[2].cb->callbackOvr) { + timerCtx->ch[2].cb->callbackOvr(&timerCtx->ch[2], capture); + } + if (timerCtx->ch[3].cb && timerCtx->ch[3].cb->callbackOvr) { + timerCtx->ch[3].cb->callbackOvr(&timerCtx->ch[3], capture); } break; } case __builtin_clz(TIM_IT_CC1): - timerConfig->edgeCallback[0]->fn(timerConfig->edgeCallback[0], tim->CCR1); + timerCtx->ch[0].cb->callbackEdge(&timerCtx->ch[0], tim->CCR1); break; case __builtin_clz(TIM_IT_CC2): - timerConfig->edgeCallback[1]->fn(timerConfig->edgeCallback[1], tim->CCR2); + timerCtx->ch[1].cb->callbackEdge(&timerCtx->ch[1], tim->CCR2); break; case __builtin_clz(TIM_IT_CC3): - timerConfig->edgeCallback[2]->fn(timerConfig->edgeCallback[2], tim->CCR3); + timerCtx->ch[2].cb->callbackEdge(&timerCtx->ch[2], tim->CCR3); break; case __builtin_clz(TIM_IT_CC4): - timerConfig->edgeCallback[3]->fn(timerConfig->edgeCallback[3], tim->CCR4); + timerCtx->ch[3].cb->callbackEdge(&timerCtx->ch[3], tim->CCR4); break; } } @@ -233,58 +279,143 @@ void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timerConfig_t * timerConf } } -void impl_timerPWMConfigChannel(TIM_TypeDef * tim, uint8_t channel, bool isNChannel, bool inverted, uint16_t value) +void impl_timerChCaptureCompareEnable(TCH_t * tch, bool enable) { - UNUSED(isNChannel); + static const uint32_t lookupTIMLLChannelTable[] = { LL_TIM_CHANNEL_CH1, LL_TIM_CHANNEL_CH2, LL_TIM_CHANNEL_CH3, LL_TIM_CHANNEL_CH4 }; - TIM_HandleTypeDef * Handle = timerFindTimerHandle(tim); - if (Handle == NULL) { - return; + if (enable) { + LL_TIM_CC_EnableChannel(tch->timHw->tim, lookupTIMLLChannelTable[tch->timHw->channelIndex]); + } + else { + LL_TIM_CC_DisableChannel(tch->timHw->tim, lookupTIMLLChannelTable[tch->timHw->channelIndex]); } - TIM_OC_InitTypeDef TIM_OCInitStructure; + //TIM_CCxChannelCmd(tch->timHw->tim, lookupTIMChannelTable[tch->timHw->channelIndex], (enable ? TIM_CCx_ENABLE : TIM_CCx_DISABLE)); +} - TIM_OCInitStructure.OCMode = TIM_OCMODE_PWM1; - TIM_OCInitStructure.OCIdleState = TIM_OCIDLESTATE_SET; - TIM_OCInitStructure.OCPolarity = inverted ? TIM_OCPOLARITY_LOW : TIM_OCPOLARITY_HIGH; - TIM_OCInitStructure.OCNIdleState = TIM_OCNIDLESTATE_SET; - TIM_OCInitStructure.OCNPolarity = inverted ? TIM_OCNPOLARITY_LOW : TIM_OCNPOLARITY_HIGH; - TIM_OCInitStructure.Pulse = value; - TIM_OCInitStructure.OCFastMode = TIM_OCFAST_DISABLE; +// HAL_LL additionan implementation for enabling multiple DMA channels in one operation +static inline void LL_TIM_EnableDMAReq_CCx(TIM_TypeDef * TIMx, uint16_t dmaSources) +{ + SET_BIT(TIMx->DIER, dmaSources & (TIM_DMA_CC1 | TIM_DMA_CC2 | TIM_DMA_CC3 | TIM_DMA_CC4)); +} - HAL_TIM_PWM_ConfigChannel(Handle, &TIM_OCInitStructure, channel); +static inline void LL_TIM_DisableDMAReq_CCx(TIM_TypeDef * TIMx, uint16_t dmaSources) +{ + CLEAR_BIT(TIMx->DIER, dmaSources & (TIM_DMA_CC1 | TIM_DMA_CC2 | TIM_DMA_CC3 | TIM_DMA_CC4)); } -uint16_t impl_timerDmaSource(uint8_t channel) +static void impl_timerDMA_IRQHandler(DMA_t descriptor) { - switch (channel) { - case TIM_CHANNEL_1: - return TIM_DMA_ID_CC1; - case TIM_CHANNEL_2: - return TIM_DMA_ID_CC2; - case TIM_CHANNEL_3: - return TIM_DMA_ID_CC3; - case TIM_CHANNEL_4: - return TIM_DMA_ID_CC4; + if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_TCIF)) { + TCH_t * tch = (TCH_t *)descriptor->userParam; + tch->dmaState = TCH_DMA_IDLE; + + LL_DMA_DisableStream(tch->dma->dma, lookupDMALLStreamTable[DMATAG_GET_STREAM(tch->dma->tag)]); + LL_TIM_DisableDMAReq_CCx(tch->timHw->tim, lookupDMASourceTable[tch->timHw->channelIndex]); + + DMA_CLEAR_FLAG(descriptor, DMA_IT_TCIF); } - return 0; } -volatile timCCR_t * impl_timerCCR(TIM_TypeDef *tim, uint8_t channel) +bool impl_timerPWMConfigChannelDMA(TCH_t * tch, void * dmaBuffer, uint32_t dmaBufferSize) { - switch (channel) { - case TIM_CHANNEL_1: - return &tim->CCR1; - break; - case TIM_CHANNEL_2: - return &tim->CCR2; - break; - case TIM_CHANNEL_3: - return &tim->CCR3; - break; - case TIM_CHANNEL_4: - return &tim->CCR4; - break; + (void)dmaBufferSize; + + tch->dma = dmaGetByTag(tch->timHw->dmaTag); + tch->dmaBuffer = dmaBuffer; + if (tch->dma == NULL) { + return false; } - return NULL; -} \ No newline at end of file + + // We assume that timer channels are already initialized by calls to: + // timerConfigBase + // timerPWMConfigChannel + + LL_DMA_DeInit(tch->dma->dma, lookupDMALLStreamTable[DMATAG_GET_STREAM(tch->dma->tag)]); + + LL_DMA_InitTypeDef init; + LL_DMA_StructInit(&init); + + init.Channel = dmaGetChannelByTag(tch->timHw->dmaTag); + + init.PeriphOrM2MSrcAddress = (uint32_t)impl_timerCCR(tch); + init.PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT; + init.PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_WORD; + init.MemoryOrM2MDstAddress = (uint32_t)dmaBuffer; + init.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT; + init.MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_WORD; + init.NbData = dmaBufferSize; + init.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH; + init.Mode = LL_DMA_MODE_NORMAL; + init.Priority = LL_DMA_PRIORITY_HIGH; + init.FIFOMode = DMA_FIFOMODE_DISABLE; + init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; + init.MemBurst = DMA_MBURST_SINGLE; + init.PeriphBurst = DMA_PBURST_SINGLE; + + dmaInit(tch->dma, OWNER_TIMER, 0); + dmaSetHandler(tch->dma, impl_timerDMA_IRQHandler, NVIC_PRIO_WS2811_DMA, (uint32_t)tch); + + LL_DMA_Init(tch->dma->dma, lookupDMALLStreamTable[DMATAG_GET_STREAM(tch->dma->tag)], &init); + + // Start PWM generation + if (tch->timHw->output & TIMER_OUTPUT_N_CHANNEL) { + HAL_TIMEx_PWMN_Start(tch->timCtx->timHandle, lookupTIMChannelTable[tch->timHw->channelIndex]); + } + else { + HAL_TIM_PWM_Start(tch->timCtx->timHandle, lookupTIMChannelTable[tch->timHw->channelIndex]); + } + + return true; +} + +void impl_timerPWMPrepareDMA(TCH_t * tch, uint32_t dmaBufferSize) +{ + const uint32_t streamLL = lookupDMALLStreamTable[DMATAG_GET_STREAM(tch->dma->tag)]; + DMA_TypeDef * dmaBase = tch->dma->dma; + + tch->dmaState = TCH_DMA_READY; + + LL_DMA_DisableStream(dmaBase, streamLL); + LL_DMA_SetDataLength(dmaBase, streamLL, dmaBufferSize); + LL_DMA_ConfigAddresses(dmaBase, streamLL, (uint32_t)tch->dmaBuffer, (uint32_t)impl_timerCCR(tch), LL_DMA_DIRECTION_MEMORY_TO_PERIPH); + LL_DMA_EnableIT_TC(dmaBase, streamLL); + LL_DMA_EnableStream(dmaBase, streamLL); +} + +void impl_timerPWMStartDMA(TCH_t * tch) +{ + uint16_t dmaSources = 0; + timHardwareContext_t * timCtx = tch->timCtx; + + if (timCtx->ch[0].dmaState == TCH_DMA_READY) { + timCtx->ch[0].dmaState = TCH_DMA_ACTIVE; + dmaSources |= TIM_DMA_CC1; + } + + if (timCtx->ch[1].dmaState == TCH_DMA_READY) { + timCtx->ch[1].dmaState = TCH_DMA_ACTIVE; + dmaSources |= TIM_DMA_CC2; + } + + if (timCtx->ch[2].dmaState == TCH_DMA_READY) { + timCtx->ch[2].dmaState = TCH_DMA_ACTIVE; + dmaSources |= TIM_DMA_CC3; + } + + if (timCtx->ch[3].dmaState == TCH_DMA_READY) { + timCtx->ch[3].dmaState = TCH_DMA_ACTIVE; + dmaSources |= TIM_DMA_CC4; + } + + if (dmaSources) { + LL_TIM_SetCounter(tch->timHw->tim, 0); + LL_TIM_EnableDMAReq_CCx(tch->timHw->tim, dmaSources); + } +} + +void impl_timerPWMStopDMA(TCH_t * tch) +{ + (void)tch; + // FIXME +} diff --git a/src/main/drivers/timer_impl_stdperiph.c b/src/main/drivers/timer_impl_stdperiph.c index ae076c12de3..f02445ffc6c 100644 --- a/src/main/drivers/timer_impl_stdperiph.c +++ b/src/main/drivers/timer_impl_stdperiph.c @@ -1,9 +1,19 @@ /* - modified version of StdPeriph function is located here. - TODO - what license does apply here? - original file was lincesed under MCD-ST Liberty SW License Agreement V2 - http://www.st.com/software_license_agreement_liberty_v2 -*/ + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ #include #include @@ -11,6 +21,7 @@ #include "platform.h" #include "build/atomic.h" +#include "build/debug.h" #include "common/utils.h" @@ -18,57 +29,73 @@ #include "drivers/rcc.h" #include "drivers/time.h" #include "drivers/nvic.h" +#include "drivers/dma.h" #include "drivers/timer.h" #include "drivers/timer_impl.h" -void impl_timerNVICConfigure(uint8_t irq, int irqPriority) +const uint16_t lookupDMASourceTable[4] = { TIM_DMA_CC1, TIM_DMA_CC2, TIM_DMA_CC3, TIM_DMA_CC4 }; +const uint8_t lookupTIMChannelTable[4] = { TIM_Channel_1, TIM_Channel_2, TIM_Channel_3, TIM_Channel_4 }; + +void impl_timerInitContext(timHardwareContext_t * timCtx) +{ + (void)timCtx; // NoOp +} + +void impl_timerNVICConfigure(TCH_t * tch, int irqPriority) { NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = irq; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(irqPriority); NVIC_InitStructure.NVIC_IRQChannelSubPriority = NVIC_PRIORITY_SUB(irqPriority); NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + + if (tch->timCtx->timDef->irq) { + NVIC_InitStructure.NVIC_IRQChannel = tch->timCtx->timDef->irq; + NVIC_Init(&NVIC_InitStructure); + } + + if (tch->timCtx->timDef->secondIrq) { + NVIC_InitStructure.NVIC_IRQChannel = tch->timCtx->timDef->secondIrq; + NVIC_Init(&NVIC_InitStructure); + } } -void impl_timerConfigBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz) +void impl_timerConfigBase(TCH_t * tch, uint16_t period, uint32_t hz) { + TIM_TypeDef * tim = tch->timCtx->timDef->tim; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = (period - 1) & 0xffff; // AKA TIMx_ARR - TIM_TimeBaseStructure.TIM_Prescaler = timerGetPrescalerByDesiredMhz(tim, mhz); + TIM_TimeBaseStructure.TIM_Prescaler = (timerGetBaseClock(tch) / hz) - 1; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); } -void impl_enableTimer(TIM_TypeDef * tim) +void impl_enableTimer(TCH_t * tch) { - TIM_Cmd(tim, ENABLE); + TIM_Cmd(tch->timHw->tim, ENABLE); } -void impl_timerPWMStart(TIM_TypeDef * tim, unsigned channel, bool isNChannel) +void impl_timerPWMStart(TCH_t * tch) { - UNUSED(channel); - UNUSED(isNChannel); - TIM_CtrlPWMOutputs(tim, ENABLE); + TIM_CtrlPWMOutputs(tch->timHw->tim, ENABLE); } -void impl_timerEnableIT(TIM_TypeDef * tim, uint32_t interrupt) +void impl_timerEnableIT(TCH_t * tch, uint32_t interrupt) { - TIM_ITConfig(tim, interrupt, ENABLE); + TIM_ITConfig(tch->timHw->tim, interrupt, ENABLE); } -void impl_timerDisableIT(TIM_TypeDef * tim, uint32_t interrupt) +void impl_timerDisableIT(TCH_t * tch, uint32_t interrupt) { - TIM_ITConfig(tim, interrupt, DISABLE); + TIM_ITConfig(tch->timHw->tim, interrupt, DISABLE); } -void impl_timerClearFlag(TIM_TypeDef * tim, uint32_t flag) +void impl_timerClearFlag(TCH_t * tch, uint32_t flag) { - TIM_ClearFlag(tim, flag); + TIM_ClearFlag(tch->timHw->tim, flag); } // calculate input filter constant @@ -83,27 +110,31 @@ static unsigned getFilter(unsigned ticks) 16*5, 16*6, 16*8, 32*5, 32*6, 32*8 }; - for (unsigned i = 1; i < ARRAYLEN(ftab); i++) - if (ftab[i] > ticks) + + for (unsigned i = 1; i < ARRAYLEN(ftab); i++) { + if (ftab[i] > ticks) { return i - 1; + } + } + return 0x0f; } -void impl_timerChConfigIC(const timerHardware_t *timHw, bool polarityRising, unsigned inputFilterTicks) +void impl_timerChConfigIC(TCH_t * tch, bool polarityRising, unsigned inputFilterTicks) { TIM_ICInitTypeDef TIM_ICInitStructure; TIM_ICStructInit(&TIM_ICInitStructure); - TIM_ICInitStructure.TIM_Channel = timHw->channel; + TIM_ICInitStructure.TIM_Channel = lookupTIMChannelTable[tch->timHw->channelIndex]; TIM_ICInitStructure.TIM_ICPolarity = polarityRising ? TIM_ICPolarity_Rising : TIM_ICPolarity_Falling; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = getFilter(inputFilterTicks); - TIM_ICInit(timHw->tim, &TIM_ICInitStructure); + TIM_ICInit(tch->timHw->tim, &TIM_ICInitStructure); } -void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timerConfig_t *timerConfig) +void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timHardwareContext_t *timerCtx) { unsigned tim_status = tim->SR & tim->DIER; @@ -115,28 +146,35 @@ void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timerConfig_t *timerConfi tim->SR = mask; tim_status &= mask; - if (timerConfig) { + if (timerCtx) { switch (bit) { case __builtin_clz(TIM_IT_Update): { const uint16_t capture = tim->ARR; - timerOvrHandlerRec_t *cb = timerConfig->overflowCallbackActive; - while (cb) { - cb->fn(cb, capture); - cb = cb->next; + if (timerCtx->ch[0].cb && timerCtx->ch[0].cb->callbackOvr) { + timerCtx->ch[0].cb->callbackOvr(&timerCtx->ch[0], capture); + } + if (timerCtx->ch[1].cb && timerCtx->ch[1].cb->callbackOvr) { + timerCtx->ch[1].cb->callbackOvr(&timerCtx->ch[1], capture); + } + if (timerCtx->ch[2].cb && timerCtx->ch[2].cb->callbackOvr) { + timerCtx->ch[2].cb->callbackOvr(&timerCtx->ch[2], capture); + } + if (timerCtx->ch[3].cb && timerCtx->ch[3].cb->callbackOvr) { + timerCtx->ch[3].cb->callbackOvr(&timerCtx->ch[3], capture); } break; } case __builtin_clz(TIM_IT_CC1): - timerConfig->edgeCallback[0]->fn(timerConfig->edgeCallback[0], tim->CCR1); + timerCtx->ch[0].cb->callbackEdge(&timerCtx->ch[0], tim->CCR1); break; case __builtin_clz(TIM_IT_CC2): - timerConfig->edgeCallback[1]->fn(timerConfig->edgeCallback[1], tim->CCR2); + timerCtx->ch[1].cb->callbackEdge(&timerCtx->ch[1], tim->CCR2); break; case __builtin_clz(TIM_IT_CC3): - timerConfig->edgeCallback[2]->fn(timerConfig->edgeCallback[2], tim->CCR3); + timerCtx->ch[2].cb->callbackEdge(&timerCtx->ch[2], tim->CCR3); break; case __builtin_clz(TIM_IT_CC4): - timerConfig->edgeCallback[3]->fn(timerConfig->edgeCallback[3], tim->CCR4); + timerCtx->ch[3].cb->callbackEdge(&timerCtx->ch[3], tim->CCR4); break; } } @@ -167,15 +205,17 @@ void impl_timerCaptureCompareHandler(TIM_TypeDef *tim, timerConfig_t *timerConfi } } -void impl_timerPWMConfigChannel(TIM_TypeDef * tim, uint8_t channel, bool isNChannel, bool inverted, uint16_t value) +void impl_timerPWMConfigChannel(TCH_t * tch, uint16_t value) { + const bool inverted = tch->timHw->output & TIMER_OUTPUT_INVERTED; + TIM_OCInitTypeDef TIM_OCInitStructure; TIM_OCStructInit(&TIM_OCInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_Pulse = value; - if (isNChannel) { + if (tch->timHw->output & TIMER_OUTPUT_N_CHANNEL) { TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_OCNPolarity = inverted ? TIM_OCPolarity_Low : TIM_OCPolarity_High; @@ -187,56 +227,160 @@ void impl_timerPWMConfigChannel(TIM_TypeDef * tim, uint8_t channel, bool isNChan TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; } - switch (channel) { - case TIM_Channel_1: - TIM_OC1Init(tim, &TIM_OCInitStructure); - TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable); + switch (tch->timHw->channelIndex) { + case 0: + TIM_OC1Init(tch->timHw->tim, &TIM_OCInitStructure); + TIM_OC1PreloadConfig(tch->timHw->tim, TIM_OCPreload_Enable); break; - case TIM_Channel_2: - TIM_OC2Init(tim, &TIM_OCInitStructure); - TIM_OC2PreloadConfig(tim, TIM_OCPreload_Enable); + case 1: + TIM_OC2Init(tch->timHw->tim, &TIM_OCInitStructure); + TIM_OC2PreloadConfig(tch->timHw->tim, TIM_OCPreload_Enable); break; - case TIM_Channel_3: - TIM_OC3Init(tim, &TIM_OCInitStructure); - TIM_OC3PreloadConfig(tim, TIM_OCPreload_Enable); + case 2: + TIM_OC3Init(tch->timHw->tim, &TIM_OCInitStructure); + TIM_OC3PreloadConfig(tch->timHw->tim, TIM_OCPreload_Enable); break; - case TIM_Channel_4: - TIM_OC4Init(tim, &TIM_OCInitStructure); - TIM_OC4PreloadConfig(tim, TIM_OCPreload_Enable); + case 3: + TIM_OC4Init(tch->timHw->tim, &TIM_OCInitStructure); + TIM_OC4PreloadConfig(tch->timHw->tim, TIM_OCPreload_Enable); break; } } -uint16_t impl_timerDmaSource(uint8_t channel) +volatile timCCR_t * impl_timerCCR(TCH_t * tch) { - switch (channel) { - case TIM_Channel_1: - return TIM_DMA_CC1; - case TIM_Channel_2: - return TIM_DMA_CC2; - case TIM_Channel_3: - return TIM_DMA_CC3; - case TIM_Channel_4: - return TIM_DMA_CC4; - } - return 0; -} - -volatile timCCR_t * impl_timerCCR(TIM_TypeDef *tim, uint8_t channel) -{ - switch (channel) { - case TIM_Channel_1: - return &tim->CCR1; + switch (tch->timHw->channelIndex) { + case 0: + return &tch->timHw->tim->CCR1; break; - case TIM_Channel_2: - return &tim->CCR2; + case 1: + return &tch->timHw->tim->CCR2; break; - case TIM_Channel_3: - return &tim->CCR3; + case 2: + return &tch->timHw->tim->CCR3; break; - case TIM_Channel_4: - return &tim->CCR4; + case 3: + return &tch->timHw->tim->CCR4; break; } return NULL; -} \ No newline at end of file +} + +void impl_timerChCaptureCompareEnable(TCH_t * tch, bool enable) +{ + TIM_CCxCmd(tch->timHw->tim, lookupTIMChannelTable[tch->timHw->channelIndex], (enable ? TIM_CCx_Enable : TIM_CCx_Disable)); +} + +static void impl_timerDMA_IRQHandler(DMA_t descriptor) +{ + if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_TCIF)) { + TCH_t * tch = (TCH_t *)descriptor->userParam; + tch->dmaState = TCH_DMA_IDLE; + + DMA_Cmd(tch->dma->ref, DISABLE); + TIM_DMACmd(tch->timHw->tim, lookupDMASourceTable[tch->timHw->channelIndex], DISABLE); + + DMA_CLEAR_FLAG(descriptor, DMA_IT_TCIF); + } +} + +bool impl_timerPWMConfigChannelDMA(TCH_t * tch, void * dmaBuffer, uint32_t dmaBufferSize) +{ + DMA_InitTypeDef DMA_InitStructure; + TIM_TypeDef * timer = tch->timHw->tim; + + tch->dma = dmaGetByTag(tch->timHw->dmaTag); + if (tch->dma == NULL) { + return false; + } + + // We assume that timer channels are already initialized by calls to: + // timerConfigBase + // timerPWMConfigChannel + + TIM_CtrlPWMOutputs(timer, ENABLE); + TIM_ARRPreloadConfig(timer, ENABLE); + + TIM_CCxCmd(timer, lookupTIMChannelTable[tch->timHw->channelIndex], TIM_CCx_Enable); + TIM_Cmd(timer, ENABLE); + + dmaInit(tch->dma, OWNER_TIMER, 0); + dmaSetHandler(tch->dma, impl_timerDMA_IRQHandler, NVIC_PRIO_WS2811_DMA, (uint32_t)tch); + + DMA_DeInit(tch->dma->ref); + DMA_Cmd(tch->dma->ref, DISABLE); + + DMA_DeInit(tch->dma->ref); + DMA_StructInit(&DMA_InitStructure); + + DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)impl_timerCCR(tch); + DMA_InitStructure.DMA_BufferSize = dmaBufferSize; + DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; + DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; + DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; + DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; + +#ifdef STM32F4 + DMA_InitStructure.DMA_Channel = dmaGetChannelByTag(tch->timHw->dmaTag); + DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dmaBuffer; + DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; + DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; + DMA_InitStructure.DMA_Priority = DMA_Priority_High; +#else // F3 + DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)dmaBuffer; + DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; + DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; + DMA_InitStructure.DMA_Priority = DMA_Priority_High; + DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; +#endif + + DMA_Init(tch->dma->ref, &DMA_InitStructure); + DMA_ITConfig(tch->dma->ref, DMA_IT_TC, ENABLE); + + return true; +} + +void impl_timerPWMPrepareDMA(TCH_t * tch, uint32_t dmaBufferSize) +{ + tch->dmaState = TCH_DMA_READY; + DMA_SetCurrDataCounter(tch->dma->ref, dmaBufferSize); + DMA_Cmd(tch->dma->ref, ENABLE); +} + +void impl_timerPWMStartDMA(TCH_t * tch) +{ + uint16_t dmaSources = 0; + timHardwareContext_t * timCtx = tch->timCtx; + + if (timCtx->ch[0].dmaState == TCH_DMA_READY) { + timCtx->ch[0].dmaState = TCH_DMA_ACTIVE; + dmaSources |= TIM_DMA_CC1; + } + + if (timCtx->ch[1].dmaState == TCH_DMA_READY) { + timCtx->ch[1].dmaState = TCH_DMA_ACTIVE; + dmaSources |= TIM_DMA_CC2; + } + + if (timCtx->ch[2].dmaState == TCH_DMA_READY) { + timCtx->ch[2].dmaState = TCH_DMA_ACTIVE; + dmaSources |= TIM_DMA_CC3; + } + + if (timCtx->ch[3].dmaState == TCH_DMA_READY) { + timCtx->ch[3].dmaState = TCH_DMA_ACTIVE; + dmaSources |= TIM_DMA_CC4; + } + + if (dmaSources) { + TIM_SetCounter(tch->timHw->tim, 0); + TIM_DMACmd(tch->timHw->tim, dmaSources, ENABLE); + } +} + +void impl_timerPWMStopDMA(TCH_t * tch) +{ + DMA_Cmd(tch->dma->ref, DISABLE); + TIM_DMACmd(tch->timHw->tim, lookupDMASourceTable[tch->timHw->channelIndex], DISABLE); + TIM_Cmd(tch->timHw->tim, ENABLE); +} diff --git a/src/main/drivers/timer_stm32f30x.c b/src/main/drivers/timer_stm32f30x.c index 5a2647695ec..5aaa4df2055 100644 --- a/src/main/drivers/timer_stm32f30x.c +++ b/src/main/drivers/timer_stm32f30x.c @@ -1,10 +1,20 @@ /* - modified version of StdPeriph function is located here. - TODO - what license does apply here? - original file was lincesed under MCD-ST Liberty SW License Agreement V2 - http://www.st.com/software_license_agreement_liberty_v2 -*/ - + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ + #include #include diff --git a/src/main/drivers/timer_stm32f30x.h b/src/main/drivers/timer_stm32f30x.h deleted file mode 100644 index 78138587589..00000000000 --- a/src/main/drivers/timer_stm32f30x.h +++ /dev/null @@ -1,6 +0,0 @@ - -#pragma once - -#include "stm32f30x.h" - -void TIM_SelectOCxM_NoDisable(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode); diff --git a/src/main/drivers/timer_stm32f4xx.c b/src/main/drivers/timer_stm32f4xx.c index 041178ed35d..75b46f1cf8f 100644 --- a/src/main/drivers/timer_stm32f4xx.c +++ b/src/main/drivers/timer_stm32f4xx.c @@ -1,9 +1,19 @@ /* - modified version of StdPeriph function is located here. - TODO - what license does apply here? - original file was lincesed under MCD-ST Liberty SW License Agreement V2 - http://www.st.com/software_license_agreement_liberty_v2 -*/ + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ #include #include diff --git a/src/main/drivers/timer_stm32f4xx.h b/src/main/drivers/timer_stm32f4xx.h deleted file mode 100644 index 52094cbc03c..00000000000 --- a/src/main/drivers/timer_stm32f4xx.h +++ /dev/null @@ -1,6 +0,0 @@ - -#pragma once - -#include "stm32f4xx.h" - -void TIM_SelectOCxM_NoDisable(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode); diff --git a/src/main/drivers/timer_stm32f7xx.c b/src/main/drivers/timer_stm32f7xx.c index fa1253e461f..4f8057baf1a 100644 --- a/src/main/drivers/timer_stm32f7xx.c +++ b/src/main/drivers/timer_stm32f7xx.c @@ -1,9 +1,19 @@ /* - modified version of StdPeriph function is located here. - TODO - what license does apply here? - original file was lincesed under MCD-ST Liberty SW License Agreement V2 - http://www.st.com/software_license_agreement_liberty_v2 -*/ + * This file is part of INAV. + * + * INAV is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * INAV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with INAV. If not, see . + */ #include #include diff --git a/src/main/drivers/timer_stm32f7xx.h b/src/main/drivers/timer_stm32f7xx.h deleted file mode 100644 index 286291aab87..00000000000 --- a/src/main/drivers/timer_stm32f7xx.h +++ /dev/null @@ -1,6 +0,0 @@ - -#pragma once - -#include "stm32f7xx.h" - -void TIM_SelectOCxM_NoDisable(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode); diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index bbcdc2d70df..cee828d3c2e 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -319,15 +319,10 @@ void init(void) (motorConfig()->motorPwmProtocol == PWM_TYPE_MULTISHOT); #endif pwm_params.motorPwmRate = motorConfig()->motorPwmRate; - pwm_params.idlePulse = motorConfig()->mincommand; - if (feature(FEATURE_3D)) { - pwm_params.idlePulse = flight3DConfig()->neutral3d; - } if (motorConfig()->motorPwmProtocol == PWM_TYPE_BRUSHED) { pwm_params.useFastPwm = false; featureClear(FEATURE_3D); - pwm_params.idlePulse = 0; // brushed motors } pwm_params.enablePWMOutput = feature(FEATURE_PWM_OUTPUT_ENABLE); diff --git a/src/main/platform.h b/src/main/platform.h index b2eb9a21e7f..67365d6ba69 100644 --- a/src/main/platform.h +++ b/src/main/platform.h @@ -20,6 +20,12 @@ #if defined(STM32F7) #include "stm32f7xx.h" #include "stm32f7xx_hal.h" +#include "stm32f7xx_ll_spi.h" +#include "stm32f7xx_ll_gpio.h" +#include "stm32f7xx_ll_dma.h" +#include "stm32f7xx_ll_rcc.h" +#include "stm32f7xx_ll_bus.h" +#include "stm32f7xx_ll_tim.h" // Chip Unique ID on F7 #if defined(STM32F722xx) diff --git a/src/main/target/AIRBOTF4/target.c b/src/main/target/AIRBOTF4/target.c index 8a05e21c1ef..8dd2f4b042c 100644 --- a/src/main/target/AIRBOTF4/target.c +++ b/src/main/target/AIRBOTF4/target.c @@ -24,18 +24,20 @@ #include "drivers/bus.h" const timerHardware_t timerHardware[] = { - { TIM12, IO_TAG(PB14), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_PPM | TIM_USE_PWM }, // PPM / S.BUS input, above MOTOR1 - { TIM12, IO_TAG(PB15), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, 0 }, // Connected: small CH2 pad, not used as PWM, definition inherited from REVO target - GPIO_PartialRemap_TIM3 - { TIM8, IO_TAG(PC6), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, 0 }, // Connected: UART6 TX, not used as PWM, definition inherited from REVO target - { TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, 0 }, // Connected: UART6 RX, not used as PWM, definition inherited from REVO target - { TIM8, IO_TAG(PC8), TIM_Channel_3, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, 0 }, // Connected: small CH5 pad, not used as PWM, definition inherited from REVO target - { TIM8, IO_TAG(PC9), TIM_Channel_4, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, 0 }, // Connected: small CH6 pad, not used as PWM, definition inherited from REVO target - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_1 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_2 - { TIM9, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_3 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_4 - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // MOTOR_5 - GPIO_PartialRemap_TIM3 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // MOTOR_6 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1_OUT D1_ST7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2_OUT D1_ST2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S3_OUT D1_ST6 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT D1_ST1 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_ANY, 0, 0), // S5_OUT / LED + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6_OUT + DEF_TIM(TIM4, CH1, PB6, TIM_USE_ANY, 0, 0), // LED D1_ST0, n/a on older AIRBOTF4 + + DEF_TIM(TIM12, CH1, PB14, TIM_USE_PWM | TIM_USE_PPM, 0, 0), // PPM (5th pin on FlexiIO port) + DEF_TIM(TIM12, CH2, PB15, TIM_USE_PWM, 0, 0), // S2_IN + DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM | TIM_USE_FW_SERVO, 0, 0), // S3_IN + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM | TIM_USE_FW_SERVO, 0, 0), // S4_IN + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM | TIM_USE_FW_SERVO, 0, 0), // S5_IN + DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM | TIM_USE_FW_SERVO, 0, 0), // S6_IN }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/AIRBOTF4/target.h b/src/main/target/AIRBOTF4/target.h index 8204dad9d81..089f394d0a1 100644 --- a/src/main/target/AIRBOTF4/target.h +++ b/src/main/target/AIRBOTF4/target.h @@ -131,12 +131,7 @@ #define SENSORS_SET (SENSOR_ACC|SENSOR_MAG|SENSOR_BARO) #define USE_LED_STRIP -// LED Strip can run off Pin 5 (PA1) of the MOTOR outputs. -#define WS2811_GPIO_AF GPIO_AF_TIM5 #define WS2811_PIN PA1 -#define WS2811_DMA_STREAM DMA1_Stream4 -#define WS2811_DMA_CHANNEL DMA_Channel_6 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST4_HANDLER #define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT diff --git a/src/main/target/AIRBOTF4/target.mk b/src/main/target/AIRBOTF4/target.mk index 4afa232072d..18d944f30cf 100644 --- a/src/main/target/AIRBOTF4/target.mk +++ b/src/main/target/AIRBOTF4/target.mk @@ -17,5 +17,4 @@ TARGET_SRC = \ drivers/compass/compass_lis3mdl.c \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c + drivers/light_ws2811strip.c \ No newline at end of file diff --git a/src/main/target/AIRHEROF3/target.c b/src/main/target/AIRHEROF3/target.c index ce6b5a18da6..ae56e77391a 100755 --- a/src/main/target/AIRHEROF3/target.c +++ b/src/main/target/AIRHEROF3/target.c @@ -25,24 +25,28 @@ #include "drivers/bus.h" const timerHardware_t timerHardware[] = { - { TIM2, IO_TAG(PA0), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PPM | TIM_USE_PWM }, // PWM1 - RC1 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // PWM2 - RC2 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // PWM3 - RC3 - { TIM2, IO_TAG(PA3), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // PWM4 - RC4 - { TIM3, IO_TAG(PA6), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM }, // PWM5 - RC5 - { TIM3, IO_TAG(PA7), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM }, // PWM6 - RC6 + DEF_TIM(TIM2, CH1, PA0, TIM_USE_PPM | TIM_USE_PWM, 0), + DEF_TIM(TIM2, CH2, PA1, TIM_USE_PWM, 0), + DEF_TIM(TIM2, CH3, PA2, TIM_USE_PWM, 0), + DEF_TIM(TIM2, CH4, PA3, TIM_USE_PWM, 0), + DEF_TIM(TIM3, CH1, PA6, TIM_USE_PWM | TIM_USE_ANY, 0), + DEF_TIM(TIM3, CH2, PA7, TIM_USE_PWM, 0), - //{ TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_2}, // PWM7 - not broken out - //{ TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2}, // PWM8 - not broken out - - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM9 - OUT1 - { TIM1, IO_TAG(PA11), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_11, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM10 - OUT2 - { TIM8, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM11 - OUT3 - { TIM4, IO_TAG(PB7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM12 - OUT4 +#if 1 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // DMA1_CH2 + DEF_TIM(TIM1, CH4, PA11, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // DMA1_CH4 + DEF_TIM(TIM8, CH1, PB6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // DMA2_CH3 + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // DMA1_CH4 - conflict with TIM1_CH4 +#else + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // DMA1_CH2 + DEF_TIM(TIM4, CH1, PA11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // DMA1_CH1 + DEF_TIM(TIM8, CH1, PB6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // DMA2_CH3 + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // DMA1_CH4 +#endif #if !defined(AIRHEROF3_QUAD) - { TIM8, IO_TAG(PB8), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM13 - OUT5 - { TIM8, IO_TAG(PB9), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO } // PWM14 - OUT6 + DEF_TIM(TIM8, CH2, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // DMA2_CH5 + DEF_TIM(TIM8, CH3, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // DMA2_CH1 #endif }; diff --git a/src/main/target/AIRHEROF3/target.h b/src/main/target/AIRHEROF3/target.h index 2007c0f7f0e..53f1a52acf6 100755 --- a/src/main/target/AIRHEROF3/target.h +++ b/src/main/target/AIRHEROF3/target.h @@ -85,11 +85,7 @@ /* #define USE_LED_STRIP -#define WS2811_TIMER TIM3 #define WS2811_PIN PA6 -#define WS2811_DMA_CHANNEL DMA1_Channel6 -#define WS2811_DMA_TC_FLAG DMA1_FLAG_TC6 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH6_HANDLER */ #define DEFAULT_FEATURES (FEATURE_TX_PROF_SEL | FEATURE_VBAT | FEATURE_SOFTSERIAL) diff --git a/src/main/target/AIRHEROF3/target.mk b/src/main/target/AIRHEROF3/target.mk index ae84a2c8aab..94c3ebd60ea 100755 --- a/src/main/target/AIRHEROF3/target.mk +++ b/src/main/target/AIRHEROF3/target.mk @@ -13,7 +13,6 @@ TARGET_SRC = \ drivers/compass/compass_lis3mdl.c \ drivers/rangefinder/rangefinder_hcsr04.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_softserial.c \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c diff --git a/src/main/target/ALIENFLIGHTF3/target.c b/src/main/target/ALIENFLIGHTF3/target.c index 05c8843e45a..5964e1318a4 100644 --- a/src/main/target/ALIENFLIGHTF3/target.c +++ b/src/main/target/ALIENFLIGHTF3/target.c @@ -24,19 +24,18 @@ const timerHardware_t timerHardware[] = { // up to 10 Motor Outputs - { TIM15, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - PB15 - TIM1_CH3N, TIM15_CH1N, *TIM15_CH2 - { TIM15, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - PB14 - TIM1_CH2N, *TIM15_CH1 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PA8 - *TIM1_CH1, TIM4_ETR - { TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N - { TIM3, IO_TAG(PA6), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - PA6 - *TIM3_CH1, TIM8_BKIN, TIM1_BKIN, TIM16_CH1 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - PA2 - *TIM2_CH3, !TIM15_CH1 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM7 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N - { TIM17, IO_TAG(PA7), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM8 - PA7 - !TIM3_CH2, *TIM17_CH1, TIM1_CH1N, TIM8_CH1 - { TIM3, IO_TAG(PA4), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM9 - PA4 - *TIM3_CH2 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM10 - PA1 - *TIM2_CH2, TIM15_CH1N + DEF_TIM(TIM1, CH3N, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 - PB15 - NONE + DEF_TIM(TIM15, CH1, PB14, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 - PB14 - DMA1_CH5 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PA8 - DMA1_CH2 + DEF_TIM(TIM8, CH2N, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PB0 - DMA2_CH5 + DEF_TIM(TIM16, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 - PA6 - DMA1_CH3 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM6 - PA2 - DMA1_CH1 + DEF_TIM(TIM8, CH3N, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM7 - PB1 - DMA2_CH1 + DEF_TIM(TIM17, CH1, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO | TIM_USE_ANY, 0), // PWM8 - PA7 - DMA1_CH7 + DEF_TIM(TIM3, CH2, PA4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM9 - PA4 - DMA_NONE + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM10 - PA1 - DMA1_CH7 - // PPM PORT - Also USART2 RX (AF5) - { TIM2, IO_TAG(PA3), TIM_Channel_4, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_PPM } // PPM - PA3 - TIM2_CH4, TIM15_CH2 - PWM13 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_PPM, 0), // PPM - PA3 - DMA1_CH7 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/ALIENFLIGHTF4/target.c b/src/main/target/ALIENFLIGHTF4/target.c index 938544d2d31..9412799ab07 100644 --- a/src/main/target/ALIENFLIGHTF4/target.c +++ b/src/main/target/ALIENFLIGHTF4/target.c @@ -23,19 +23,19 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PA8), TIM_Channel_1, 0, IOCFG_IPD, GPIO_AF_TIM1, TIM_USE_PPM | TIM_USE_PWM }, // PWM1 - PA8 RC1 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_IPD, GPIO_AF_TIM3, TIM_USE_PWM }, // PWM2 - PB0 RC2 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_IPD, GPIO_AF_TIM3, TIM_USE_PWM }, // PWM3 - PB1 RC3 - { TIM1, IO_TAG(PB14), TIM_Channel_2, 0, IOCFG_IPD, GPIO_AF_TIM1, TIM_USE_PWM }, // PWM4 - PA14 RC4 - { TIM1, IO_TAG(PB15), TIM_Channel_3, 0, IOCFG_IPD, GPIO_AF_TIM1, TIM_USE_PWM }, // PWM5 - PA15 RC5 - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM6 - PB8 OUT1 - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM7 - PB9 OUT2 - { TIM5, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM8 - PA0 OUT3 - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM9 - PA1 OUT4 - { TIM8, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM10 - PC6 OUT5 - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM11 - PC7 OUT6 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM13 - PC8 OUT7 - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM13 - PC9 OUT8 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_PWM | TIM_USE_PPM, 0, 1), // PWM1 - PA8 RC1 - DMA2_ST1 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_PWM, 0, 0), // PWM2 - PB0 RC2 - DMA1_ST5 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_PWM, 0, 0), // PWM3 - PB1 RC3 - DMA1_ST7 + DEF_TIM(TIM1, CH2, PB14, TIM_USE_PWM, 0, 1), // PWM4 - PA14 RC4 - DMA2_ST2 + DEF_TIM(TIM1, CH3, PB15, TIM_USE_PWM | TIM_USE_LED, 0, 0), // PWM5 - PA15 RC5 - DMA2_ST6 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // PWM6 - PB8 OUT1 - DMA1_ST7 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // PWM7 - PB9 OUT2 - DMA_NONE + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM8 - PA0 OUT3 - DMA1_ST2 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM9 - PA1 OUT4 - DMA1_ST4 + DEF_TIM(TIM8, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM10 - PC6 OUT5 - DMA2_ST2 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM11 - PC7 OUT6 - DMA2_ST3 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // PWM13 - PC8 OUT7 - DMA2_ST4 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM13 - PC9 OUT8 - DMA2_ST7 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/ALIENFLIGHTF4/target.h b/src/main/target/ALIENFLIGHTF4/target.h index 92afdbb512b..224be2b765d 100644 --- a/src/main/target/ALIENFLIGHTF4/target.h +++ b/src/main/target/ALIENFLIGHTF4/target.h @@ -169,12 +169,6 @@ #define USE_LED_STRIP // LED Strip can run off Pin 41 (PA8) of the ESC outputs. #define WS2811_PIN PA8 -#define WS2811_TIMER TIM1 -#define WS2811_DMA_HANDLER_IDENTIFER DMA2_ST1_HANDLER -#define WS2811_DMA_STREAM DMA2_Stream1 -#define WS2811_DMA_IT DMA_IT_TCIF1 -#define WS2811_DMA_CHANNEL DMA_Channel_6 -#define WS2811_TIMER_CHANNEL TIM_Channel_1 #define USE_SPEKTRUM_BIND // USART2, PA3 diff --git a/src/main/target/ALIENFLIGHTF4/target.mk b/src/main/target/ALIENFLIGHTF4/target.mk index ac039d95fcf..12cfd715478 100644 --- a/src/main/target/ALIENFLIGHTF4/target.mk +++ b/src/main/target/ALIENFLIGHTF4/target.mk @@ -13,5 +13,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_mpu9250.c \ drivers/compass/compass_lis3mdl.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c + drivers/light_ws2811strip.c diff --git a/src/main/target/ALIENFLIGHTNGF7/target.c b/src/main/target/ALIENFLIGHTNGF7/target.c index c71704ddbf7..1a912077924 100644 --- a/src/main/target/ALIENFLIGHTNGF7/target.c +++ b/src/main/target/ALIENFLIGHTNGF7/target.c @@ -22,23 +22,20 @@ #include "drivers/pwm_mapping.h" #include "drivers/timer.h" -#define TIM_EN TIMER_OUTPUT_ENABLED -#define TIM_EN_N TIMER_OUTPUT_ENABLED | TIMER_OUTPUT_N_CHANNEL - const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PA8), TIM_CHANNEL_1, 0, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_PPM | TIM_USE_PWM | TIM_USE_LED }, // PWM1 - PA8 RC1 - { TIM3, IO_TAG(PB1), TIM_CHANNEL_4, 0, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_PWM | TIM_USE_MC_SERVO }, // PWM2 - PB1 RC2 - { TIM12, IO_TAG(PB15), TIM_CHANNEL_2, 0, IOCFG_AF_PP_PD, GPIO_AF9_TIM12, TIM_USE_PWM | TIM_USE_MC_SERVO }, // PWM3 - PA15 RC3 - { TIM4, IO_TAG(PB8), TIM_CHANNEL_3, 0, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_PWM | TIM_USE_MC_SERVO }, // PWM4 - PB8 RC4 - { TIM4, IO_TAG(PB9), TIM_CHANNEL_4, 0, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_PWM | TIM_USE_MC_SERVO }, // PWM5 - PB9 RC5 - { TIM8, IO_TAG(PC6), TIM_CHANNEL_1, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - PC6 OUT1 - { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM7 - PC7 OUT2 - { TIM12, IO_TAG(PB14), TIM_CHANNEL_1, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF9_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM9 - PA14 OUT3 - { TIM3, IO_TAG(PB0), TIM_CHANNEL_3, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM10 - PB0 OUT4 - { TIM5, IO_TAG(PA0), TIM_CHANNEL_1, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM11 - PA0 OUT5 - { TIM5, IO_TAG(PA1), TIM_CHANNEL_2, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM12 - PA1 OUT6 - { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM13 - PC8 OUT7 - { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM14 - PC9 OUT8 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_PPM | TIM_USE_LED, 0, 1), // PPM - DMA2_ST1 + DEF_TIM(TIM8, CH1, PC6, TIM_USE_MC_SERVO, 0, 0), // PWM1 - DMA2_ST2 + DEF_TIM(TIM3, CH2, PC7, TIM_USE_MC_SERVO, 0, 0), // PWM2 - DMA1_ST5 + DEF_TIM(TIM8, CH2N, PB14, TIM_USE_MC_SERVO, 0, 0), // PWM3 - DMA2_ST3 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_SERVO, 0, 0), // PWM4 - DMA1_ST7 + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_SERVO, 0, 0), // PWM5 - DMA1_ST2 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM6 - DMA2_ST4 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM7 - DMA1_ST4 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM8 - DMA2_ST7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM9 - DMA1_ST2 + DEF_TIM(TIM1, CH3N, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM10 - DMA2_ST6 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM11 - DMA1_ST7 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // PWM12 - DMA_NONE }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/ALIENFLIGHTNGF7/target.h b/src/main/target/ALIENFLIGHTNGF7/target.h index 918b4971de9..a0d1989ea5f 100644 --- a/src/main/target/ALIENFLIGHTNGF7/target.h +++ b/src/main/target/ALIENFLIGHTNGF7/target.h @@ -183,13 +183,6 @@ #define USE_LED_STRIP // LED Strip can run off Pin 41 (PA8) of the ESC outputs. #define WS2811_PIN PA8 -#define WS2811_TIMER TIM1 -#define WS2811_DMA_HANDLER_IDENTIFER DMA2_ST1_HANDLER -#define WS2811_DMA_STREAM DMA2_Stream1 -#define WS2811_DMA_IT DMA_IT_TCIF1 -#define WS2811_DMA_CHANNEL DMA_CHANNEL_6 -#define WS2811_TIMER_CHANNEL TIM_CHANNEL_1 -#define WS2811_TIMER_GPIO_AF GPIO_AF1_TIM1 #define USE_SPEKTRUM_BIND // USART2, PA3 diff --git a/src/main/target/ALIENFLIGHTNGF7/target.mk b/src/main/target/ALIENFLIGHTNGF7/target.mk index db6cba5ba96..4beb04ddd82 100644 --- a/src/main/target/ALIENFLIGHTNGF7/target.mk +++ b/src/main/target/ALIENFLIGHTNGF7/target.mk @@ -15,5 +15,4 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_lis3mdl.c \ drivers/max7456.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_hal.c + drivers/light_ws2811strip.c diff --git a/src/main/target/ANYFC/target.c b/src/main/target/ANYFC/target.c index 8bc7c8cc4e6..02ccf460825 100644 --- a/src/main/target/ANYFC/target.c +++ b/src/main/target/ANYFC/target.c @@ -23,23 +23,23 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM12, IO_TAG(PB14), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_PPM | TIM_USE_PWM }, // S1_IN - { TIM12, IO_TAG(PB15), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_PWM }, // S2_IN - { TIM8, IO_TAG(PC6), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PWM }, // S3_IN - { TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PWM }, // S4_IN - { TIM8, IO_TAG(PC9), TIM_Channel_4, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PWM }, // S5_IN - { TIM8, IO_TAG(PC8), TIM_Channel_3, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PWM }, // S6_IN + DEF_TIM(TIM12, CH1, PB14, TIM_USE_PWM | TIM_USE_PPM, 0, 0), // S1_IN + DEF_TIM(TIM12, CH2, PB15, TIM_USE_PWM, 0, 0), // S2_IN + DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM, 0, 0), // S3_IN + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM, 0, 0), // S4_IN + DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM, 0, 0), // S6_IN + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0, 0), // S5_IN - { TIM2, IO_TAG(PB3), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S10_OUT 16 - { TIM5, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S6_OUT 12 - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S5_OUT 11 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT 7 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT 8 - { TIM2, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT 9 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT 10 - { TIM2, IO_TAG(PA15), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S7_OUT 13 - { TIM3, IO_TAG(PB5), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S8_OUT 14 - { TIM3, IO_TAG(PB4), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S9_OUT 15 + DEF_TIM(TIM2, CH2, PB3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S10_OUT 16 + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S6_OUT 12 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S5_OUT 11 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1_OUT 7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2_OUT 8 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S3_OUT 9 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT 10 + DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S7_OUT 13 + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S8_OUT 14 + DEF_TIM(TIM3, CH1, PB4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S9_OUT 15 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/ANYFC/target.h b/src/main/target/ANYFC/target.h index f6fc3aa695e..2237486b0cf 100644 --- a/src/main/target/ANYFC/target.h +++ b/src/main/target/ANYFC/target.h @@ -119,16 +119,7 @@ #define RSSI_ADC_CHANNEL ADC_CHN_3 #define USE_LED_STRIP -// LED Strip can run off Pin 6 (PA0) of the ESC outputs. #define WS2811_PIN PA0 -#define WS2811_TIMER TIM5 -#define WS2811_TIMER_CHANNEL TIM_Channel_1 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST2_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream2 -#define WS2811_DMA_FLAG DMA_FLAG_TCIF2 -#define WS2811_DMA_IT DMA_IT_TCIF2 -#define WS2811_DMA_CHANNEL DMA_Channel_6 -#define WS2811_DMA_IRQ DMA1_Stream2_IRQn #define SENSORS_SET (SENSOR_ACC|SENSOR_MAG|SENSOR_BARO) diff --git a/src/main/target/ANYFC/target.mk b/src/main/target/ANYFC/target.mk index e9d3377e755..c2f6de44b4b 100644 --- a/src/main/target/ANYFC/target.mk +++ b/src/main/target/ANYFC/target.mk @@ -11,6 +11,5 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/pitotmeter_ms4525.c diff --git a/src/main/target/ANYFCF7/target.c b/src/main/target/ANYFCF7/target.c index 07acf8c341f..1a06c3b3eda 100644 --- a/src/main/target/ANYFCF7/target.c +++ b/src/main/target/ANYFCF7/target.c @@ -23,44 +23,23 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM12, IO_TAG(PB14), TIM_CHANNEL_1, 0, IOCFG_AF_PP_PD, GPIO_AF9_TIM12, TIM_USE_PPM | TIM_USE_PWM }, // S1_IN 1 - { TIM12, IO_TAG(PB15), TIM_CHANNEL_2, 0, IOCFG_AF_PP_PD, GPIO_AF9_TIM12, TIM_USE_PWM }, // S2_IN 2 - { TIM8, IO_TAG(PC6), TIM_CHANNEL_1, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_PWM | TIM_USE_MC_SERVO }, // S3_IN 3 - { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_PWM | TIM_USE_MC_SERVO }, // S4_IN 4 - { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_PWM | TIM_USE_MC_SERVO }, // S6_IN 6 - { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_PWM | TIM_USE_MC_SERVO }, // S5_IN 5 + DEF_TIM(TIM12, CH1, PB14, TIM_USE_PWM | TIM_USE_PPM, 0, 0 ), // S1_IN + DEF_TIM(TIM12, CH2, PB15, TIM_USE_PWM, 0, 0 ), // S2_IN + DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM, 0, 0 ), // S3_IN DMA2_ST2 DMA2_ST2 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM, 0, 0 ), // S4_IN DMA2_ST3 DMA2_ST2 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0, 0 ), // S5_IN DMA2_ST4 DMA2_ST2 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM, 0, 0 ), // S6_IN DMA2_ST7 - { TIM4, IO_TAG(PB8), TIM_CHANNEL_3, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S10_OUT16 - { TIM2, IO_TAG(PA2), TIM_CHANNEL_3, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S6_OUT 12 - { TIM4, IO_TAG(PB9), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S5_OUT 11 - { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT 7 - { TIM5, IO_TAG(PA1), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT 8 - { TIM9, IO_TAG(PE6), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF3_TIM9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT 9 - { TIM3, IO_TAG(PB5), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT 10 - { TIM5, IO_TAG(PA0), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S7_OUT 13 - { TIM2, IO_TAG(PB3), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S8_OUT 14 - { TIM3, IO_TAG(PB4), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S9_OUT 15 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S10_OUT 1 DMA1_ST7 + DEF_TIM(TIM5, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S6_OUT 2 DMA1_ST0 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S5_OUT + DEF_TIM(TIM5, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S1_OUT 4 DMA1_ST1 DMA1_ST3 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S2_OUT 3 DMA1_ST4 + DEF_TIM(TIM9, CH2, PE6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S3_OUT + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S4_OUT DMA1_ST5 + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S7_OUT DMA1_ST2 + DEF_TIM(TIM2, CH2, PB3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO | TIM_USE_LED, 0, 0 ), // S8_OUT DMA1_ST6 + DEF_TIM(TIM3, CH1, PB4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S9_OUT DMA1_ST4 }; -// ALTERNATE LAYOUT -//const timerHardware_t timerHardware[] = { -// { TIM12, IO_TAG(PB14), TIM_CHANNEL_1, TIM8_BRK_TIM12_IRQn, 0, IOCFG_AF_PP_PD, GPIO_AF9_TIM12 }, // S1_IN -// { TIM12, IO_TAG(PB15), TIM_CHANNEL_2, TIM8_BRK_TIM12_IRQn, 0, IOCFG_AF_PP_PD, GPIO_AF9_TIM12 }, // S2_IN -// { TIM8, IO_TAG(PC6), TIM_CHANNEL_1, TIM8_CC_IRQn, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8 }, // S3_IN -// { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, TIM8_CC_IRQn, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8 }, // S4_IN -// { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, TIM8_CC_IRQn, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8 }, // S5_IN -// { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, TIM8_CC_IRQn, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8 }, // S6_IN -// -// { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, TIM2_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM2 }, // S1_OUT -// { TIM5, IO_TAG(PA1), TIM_CHANNEL_2, TIM5_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM5 }, // S2_OUT -// { TIM9, IO_TAG(PE6), TIM_CHANNEL_2, TIM1_BRK_TIM9_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF3_TIM9 }, // S3_OUT -// { TIM3, IO_TAG(PB5), TIM_CHANNEL_2, TIM3_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3 }, // S4_OUT -// { TIM11, IO_TAG(PB9), TIM_CHANNEL_1, TIM1_TRG_COM_TIM11_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF3_TIM11 }, // S5_OUT -// { TIM9, IO_TAG(PA2), TIM_CHANNEL_1, TIM1_BRK_TIM9_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF3_TIM9 }, // S6_OUT -// { TIM5, IO_TAG(PA0), TIM_CHANNEL_1, TIM5_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM5 }, // S7_OUT -// { TIM2, IO_TAG(PB3), TIM_CHANNEL_2, TIM2_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM2 }, // S8_OUT -// { TIM3, IO_TAG(PB4), TIM_CHANNEL_1, TIM3_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3 }, // S9_OUT -// { TIM10, IO_TAG(PB8), TIM_CHANNEL_1, TIM1_UP_TIM10_IRQn, 1, IOCFG_AF_PP_PD, GPIO_AF3_TIM10 }, // S10_OUT -//}; - const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/ANYFCF7/target.h b/src/main/target/ANYFCF7/target.h index dc981bda7cc..bb3a361c681 100644 --- a/src/main/target/ANYFCF7/target.h +++ b/src/main/target/ANYFCF7/target.h @@ -177,18 +177,7 @@ #define RSSI_ADC_CHANNEL ADC_CHN_3 #define USE_LED_STRIP - -// LED Strip can run off Pin 6 (PA0) of the ESC outputs. #define WS2811_PIN PA1 -#define WS2811_TIMER TIM5 -#define WS2811_TIMER_CHANNEL TIM_CHANNEL_2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST4_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream4 -#define WS2811_DMA_FLAG DMA_FLAG_TCIF4 -#define WS2811_DMA_IT DMA_IT_TCIF4 -#define WS2811_DMA_CHANNEL DMA_CHANNEL_6 -#define WS2811_DMA_IRQ DMA1_Stream4_IRQn -#define WS2811_TIMER_GPIO_AF GPIO_AF2_TIM5 #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/ANYFCF7/target.mk b/src/main/target/ANYFCF7/target.mk index 203f4ae8164..7d35e5c1784 100644 --- a/src/main/target/ANYFCF7/target.mk +++ b/src/main/target/ANYFCF7/target.mk @@ -14,7 +14,6 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_hal.c \ drivers/pitotmeter_ms4525.c \ drivers/max7456.c diff --git a/src/main/target/ANYFCM7/target.c b/src/main/target/ANYFCM7/target.c index 202869bfbd8..d31dedbf18d 100644 --- a/src/main/target/ANYFCM7/target.c +++ b/src/main/target/ANYFCM7/target.c @@ -26,23 +26,23 @@ #define TIM_EN_N TIMER_OUTPUT_ENABLED | TIMER_OUTPUT_N_CHANNEL const timerHardware_t timerHardware[] = { - { TIM12, IO_TAG(PB14), TIM_CHANNEL_1, 0, IOCFG_AF_PP_PD, GPIO_AF9_TIM12, TIM_USE_PWM | TIM_USE_PPM }, // S1_IN - { TIM12, IO_TAG(PB15), TIM_CHANNEL_2, 0, IOCFG_AF_PP_PD, GPIO_AF9_TIM12, TIM_USE_PWM }, // S2_IN - { TIM8, IO_TAG(PC6), TIM_CHANNEL_1, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_PWM }, // S3_IN - { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_PWM }, // S4_IN - { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_PWM }, // S5_IN - { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, 0, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_PWM }, // S6_IN + DEF_TIM(TIM12, CH1, PB14, TIM_USE_PWM | TIM_USE_PPM, 0, 0 ), // S1_IN + DEF_TIM(TIM12, CH2, PB15, TIM_USE_PWM, 0, 0 ), // S2_IN + DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM, 0, 0 ), // S3_IN DMA2_ST2 DMA2_ST2 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM, 0, 0 ), // S4_IN DMA2_ST3 DMA2_ST2 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0, 0 ), // S5_IN DMA2_ST4 DMA2_ST2 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM, 0, 0 ), // S6_IN DMA2_ST7 - { TIM4, IO_TAG(PB8), TIM_CHANNEL_3, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S10_OUT PWM16 - { TIM2, IO_TAG(PA2), TIM_CHANNEL_3, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S6_OUT PWM12 - { TIM4, IO_TAG(PB7), TIM_CHANNEL_2, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S5_OUT PWM11 - { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT PWM7 - { TIM5, IO_TAG(PA1), TIM_CHANNEL_2, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT PWM8 - { TIM1, IO_TAG(PB0), TIM_CHANNEL_2, TIM_EN_N, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT PWM9 - { TIM3, IO_TAG(PB5), TIM_CHANNEL_2, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT PWM10 - { TIM5, IO_TAG(PA0), TIM_CHANNEL_1, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S7_OUT PWM13 - { TIM1, IO_TAG(PB1), TIM_CHANNEL_3, TIM_EN_N, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S8_OUT PWM14 - { TIM3, IO_TAG(PB4), TIM_CHANNEL_1, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S9_OUT PWM15 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S10_OUT 1 DMA1_ST7 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S6_OUT 2 DMA1_ST1 + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S5_OUT 3 DMA1_ST3 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 1 ), // S1_OUT 4 DMA1_ST7 DMA1_ST6 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S2_OUT DMA1_ST4 + DEF_TIM(TIM1, CH2N, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1 ), // S3_OUT DMA2_ST6 DMA2_ST2 + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO | TIM_USE_LED, 0, 0 ), // S4_OUT DMA1_ST5 + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S7_OUT DMA1_ST2 + DEF_TIM(TIM1, CH3N, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S8_OUT DMA2_ST6 + DEF_TIM(TIM3, CH1, PB4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S9_OUT DMA1_ST4 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/ANYFCM7/target.mk b/src/main/target/ANYFCM7/target.mk index b8c1fb61dea..924248bb62c 100644 --- a/src/main/target/ANYFCM7/target.mk +++ b/src/main/target/ANYFCM7/target.mk @@ -11,6 +11,5 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_hal.c \ drivers/pitotmeter_ms4525.c \ drivers/max7456.c diff --git a/src/main/target/ASGARD32F4/target.c b/src/main/target/ASGARD32F4/target.c index 82733b2a17b..19e8938877a 100644 --- a/src/main/target/ASGARD32F4/target.c +++ b/src/main/target/ASGARD32F4/target.c @@ -30,26 +30,17 @@ #include "drivers/timer.h" #include "drivers/bus.h" -#define DEF_TIM_CHNL_CH1 TIM_Channel_1 -#define DEF_TIM_CHNL_CH2 TIM_Channel_2 -#define DEF_TIM_CHNL_CH3 TIM_Channel_3 -#define DEF_TIM_CHNL_CH4 TIM_Channel_4 - -#define DEF_TIM(_tim, _ch, _pin, _usage, _flags) \ - { _tim, IO_TAG(_pin), DEF_TIM_CHNL_##_ch, _flags, IOCFG_AF_PP, GPIO_AF_##_tim, _usage } - - const timerHardware_t timerHardware[] = { - // DEF_TIM(TIM1, CH1, PA8, TIM_USE_PPM, 0), // PPM - timer clash with SS1_TX + // DEF_TIM(TIM1, CH1, PA8, TIM_USE_PPM, 0, 0), // PPM - timer clash with SS1_TX - DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR, 1), // M1 - DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR, 1), // M2 - DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR, 1), // M3 - DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR, 1), // M4 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR, 1, 0), // M1 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR, 1, 0), // M2 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR, 1, 0), // M3 + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR, 1, 0), // M4 // DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0), // LED strip - timer clash with M4 output - DEF_TIM(TIM1, CH2, PA9, TIM_USE_ANY, 0), // SS1 + DEF_TIM(TIM1, CH2, PA9, TIM_USE_ANY, 0, 0), // SS1 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/ASGARD32F4/target.mk b/src/main/target/ASGARD32F4/target.mk index 62e119d7ff0..2382c6005d3 100644 --- a/src/main/target/ASGARD32F4/target.mk +++ b/src/main/target/ASGARD32F4/target.mk @@ -15,5 +15,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/BEEROTORF4/target.c b/src/main/target/BEEROTORF4/target.c index d11c1fa41b3..997c6b3f865 100644 --- a/src/main/target/BEEROTORF4/target.c +++ b/src/main/target/BEEROTORF4/target.c @@ -23,20 +23,19 @@ #include "drivers/pwm_mapping.h" #include "drivers/timer.h" - const timerHardware_t timerHardware[] = { - { TIM9, IO_TAG(PA3), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM9, TIM_USE_PPM }, // PPM IN - - { TIM1, IO_TAG(PB0), TIM_Channel_2, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // M1 - { TIM1, IO_TAG(PB1), TIM_Channel_3, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // M2 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1 , IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // M3 - { TIM5, IO_TAG(PA0), TIM_Channel_1, 1 , IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // M4 - { TIM3, IO_TAG(PC6), TIM_Channel_1, 1 , IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // M5 - { TIM3, IO_TAG(PC7), TIM_Channel_2, 1 , IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // M6 - { TIM3, IO_TAG(PB5), TIM_Channel_2, 1 , IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // M7 - { TIM11, IO_TAG(PB9), TIM_Channel_1, 1 , IOCFG_AF_PP, GPIO_AF_TIM11, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // M8 - - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_LED }, // LED_STRIP / TRANSPONDER + DEF_TIM(TIM9, CH2, PA3, TIM_USE_PPM, 0, 0), // PPM IN + + DEF_TIM(TIM1, CH2N, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // M1 - DMAR: DMA2_ST5 + DEF_TIM(TIM1, CH3N, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // M2 - + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // M3 - DMAR: DMA1_ST7 + DEF_TIM(TIM2, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // M4 - + DEF_TIM(TIM8, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // M5 - DMAR: DMA2_ST1 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // M6 - + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // M7 - DMAR: DMA1_ST2 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // M8 - DMAR: DMA1_ST6 + + DEF_TIM(TIM4, CH3, PB8, TIM_USE_LED, 0, 0), // LED_STRIP / TRANSPONDER - DMA1_ST7 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/BEEROTORF4/target.h b/src/main/target/BEEROTORF4/target.h index 2a58651bb4b..77df46f73d3 100644 --- a/src/main/target/BEEROTORF4/target.h +++ b/src/main/target/BEEROTORF4/target.h @@ -145,16 +145,7 @@ #define RSSI_ADC_CHANNEL ADC_CHN_3 #define USE_LED_STRIP -#define WS2811_GPIO_AF GPIO_AF_TIM4 #define WS2811_PIN PB8 -#define WS2811_TIMER TIM4 -#define WS2811_TIMER_CHANNEL TIM_Channel_3 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST7_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream7 -#define WS2811_DMA_CHANNEL DMA_Channel_2 -#define WS2811_DMA_IRQ DMA1_Stream7_IRQn -#define WS2811_DMA_FLAG DMA_FLAG_TCIF7 -#define WS2811_DMA_IT DMA_IT_TCIF7 //#define TRANSPONDER //#define TRANSPONDER_GPIO_AF GPIO_AF_TIM4 diff --git a/src/main/target/BEEROTORF4/target.mk b/src/main/target/BEEROTORF4/target.mk index de1088af58c..aaa180a4f8c 100644 --- a/src/main/target/BEEROTORF4/target.mk +++ b/src/main/target/BEEROTORF4/target.mk @@ -15,5 +15,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/max7456.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ No newline at end of file + drivers/light_ws2811strip.c \ No newline at end of file diff --git a/src/main/target/BETAFLIGHTF3/target.c b/src/main/target/BETAFLIGHTF3/target.c index 486e51039a2..265c88da5f3 100755 --- a/src/main/target/BETAFLIGHTF3/target.c +++ b/src/main/target/BETAFLIGHTF3/target.c @@ -23,19 +23,25 @@ #include "drivers/timer.h" #include "drivers/pwm_mapping.h" -/*#include "drivers/dma.h"*/ const timerHardware_t timerHardware[] = { - { TIM4, IO_TAG(PB7), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PPM }, // Pin PPM - PB7 - { TIM16, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - { TIM8, IO_TAG(PA7), TIM_Channel_1, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - { TIM8, IO_TAG(PB8), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - { TIM17, IO_TAG(PB9), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - { TIM1, IO_TAG(PB0), TIM_Channel_2, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - { TIM8, IO_TAG(PB1), TIM_Channel_3, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - { TIM2, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM7 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM8 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_LED } // LED STRIP + DEF_TIM(TIM4, CH2, PB7, TIM_USE_PPM, 0), // PPM DMA(1,4) + + // Motors 1-4 + DEF_TIM(TIM16, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 UP(1,6) + DEF_TIM(TIM8, CH1N, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 UP(2,1) + DEF_TIM(TIM8, CH2, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 UP(2,1) + DEF_TIM(TIM17, CH1, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 UP(1,7) + + // Motors 5-6 or SoftSerial + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM6 + + // Motors 7-8 or UART2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM7/UART2_RX + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM8/UART2_TX + + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0), // LED DMA(1,2) }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/BETAFLIGHTF4/target.c b/src/main/target/BETAFLIGHTF4/target.c index e246b0ad37a..18d56e7e8bc 100755 --- a/src/main/target/BETAFLIGHTF4/target.c +++ b/src/main/target/BETAFLIGHTF4/target.c @@ -24,17 +24,16 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM4, IO_TAG(PB8), TIM_Channel_3, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_PPM }, // PPM + DEF_TIM(TIM4, CH3, PB8, TIM_USE_PPM, 0, 0), // PPM // Motors - // { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, - { TIM1, IO_TAG(PB0), TIM_Channel_2, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, + DEF_TIM(TIM1, CH2, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1_OUT D2_ST6 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S2_OUT D1_ST2 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S3_OUT D1_ST6 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT D1_ST1 // LED strip - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_LED }, // D1_ST0 + DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // D1_ST0 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/BETAFLIGHTF4/target.h b/src/main/target/BETAFLIGHTF4/target.h index 209bfacba3d..bb6632871c2 100755 --- a/src/main/target/BETAFLIGHTF4/target.h +++ b/src/main/target/BETAFLIGHTF4/target.h @@ -157,9 +157,6 @@ #define USE_LED_STRIP #define WS2811_PIN PB6 -#define WS2811_DMA_STREAM DMA1_Stream0 -#define WS2811_DMA_CHANNEL DMA_Channel_2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST0_HANDLER #define SERIALRX_PROVIDER SERIALRX_SBUS #define DEFAULT_RX_TYPE RX_TYPE_SERIAL diff --git a/src/main/target/BETAFLIGHTF4/target.mk b/src/main/target/BETAFLIGHTF4/target.mk index 04624e14e9d..bd9ccab5213 100755 --- a/src/main/target/BETAFLIGHTF4/target.mk +++ b/src/main/target/BETAFLIGHTF4/target.mk @@ -20,5 +20,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/max7456.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ No newline at end of file + drivers/light_ws2811strip.c \ No newline at end of file diff --git a/src/main/target/BLUEJAYF4/target.c b/src/main/target/BLUEJAYF4/target.c index b82c2e2a201..138fa9b18dd 100644 --- a/src/main/target/BLUEJAYF4/target.c +++ b/src/main/target/BLUEJAYF4/target.c @@ -23,14 +23,15 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_PPM }, // PPM IN + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PPM, 0, 0 ), // PPM IN - { TIM5, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR}, // S1_OUT - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT - { TIM9, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S5_OUT - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S6_OUT + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S1_OUT - DMA1_ST2 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S2_OUT - DMA1_ST4 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S3_OUT - DMA1_ST1 + DEF_TIM(TIM9, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S4_OUT - no DMA + // DEF_TIM(TIM5, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1 ), // S4_OUT - DMA1_ST3 (Could be DMA1_ST1 with dmaopt=0) + DEF_TIM(TIM3, CH4, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO | TIM_USE_LED, 0, 0 ), // S5_OUT - DMA1_ST2 + DEF_TIM(TIM3, CH3, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S6_OUT - DMA1_ST7 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/BLUEJAYF4/target.h b/src/main/target/BLUEJAYF4/target.h index b525ea3414a..51cfc7cc3ad 100644 --- a/src/main/target/BLUEJAYF4/target.h +++ b/src/main/target/BLUEJAYF4/target.h @@ -139,17 +139,7 @@ #define VBAT_ADC_CHANNEL ADC_CHN_1 #define USE_LED_STRIP -// LED Strip can run off Pin 6 (PB1) of the ESC outputs. #define WS2811_PIN PB1 -#define WS2811_TIMER TIM3 -#define WS2811_TIMER_CHANNEL TIM_Channel_4 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST2_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream2 -#define WS2811_DMA_FLAG DMA_FLAG_TCIF2 -#define WS2811_DMA_IT DMA_IT_TCIF2 -#define WS2811_DMA_CHANNEL DMA_Channel_5 -#define WS2811_DMA_IRQ DMA1_Stream2_IRQn - #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/BLUEJAYF4/target.mk b/src/main/target/BLUEJAYF4/target.mk index 68495696e8c..45a97b49995 100644 --- a/src/main/target/BLUEJAYF4/target.mk +++ b/src/main/target/BLUEJAYF4/target.mk @@ -13,6 +13,4 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c - + drivers/light_ws2811strip.c \ No newline at end of file diff --git a/src/main/target/CHEBUZZF3/target.c b/src/main/target/CHEBUZZF3/target.c index 8a4f760e9ba..f447c82cc10 100644 --- a/src/main/target/CHEBUZZF3/target.c +++ b/src/main/target/CHEBUZZF3/target.c @@ -24,25 +24,25 @@ const timerHardware_t timerHardware[] = { // INPUTS CH1-8 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_6, TIM_USE_PPM | TIM_USE_PWM }, // PWM1 - PA8 - { TIM16, IO_TAG(PB8), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_PWM }, // PWM2 - PB8 - { TIM17, IO_TAG(PB9), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_PWM }, // PWM3 - PB9 - { TIM8, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_4, TIM_USE_PWM }, // PWM4 - PC6 - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_4, TIM_USE_PWM }, // PWM5 - PC7 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_4, TIM_USE_PWM }, // PWM6 - PC8 - { TIM15, IO_TAG(PF9), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_3, TIM_USE_PWM }, // PWM7 - PF9 - { TIM15, IO_TAG(PF10), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_3, TIM_USE_PWM }, // PWM8 - PF10 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_PPM, 0), // PWM1 - PA8 + DEF_TIM(TIM16, CH1, PB8, TIM_USE_PWM, 0), // PWM2 - PB8 + DEF_TIM(TIM17, CH1, PB9, TIM_USE_PWM, 0), // PWM3 - PB9 + DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM, 0), // PWM4 - PC6 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM, 0), // PWM5 - PC7 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0), // PWM6 - PC8 + DEF_TIM(TIM15, CH1, PF9, TIM_USE_PWM, 0), // PWM7 - PF9 + DEF_TIM(TIM15, CH2, PF10, TIM_USE_PWM, 0), // PWM8 - PF10 - { TIM4, IO_TAG(PD12), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM9 - PD12 - { TIM4, IO_TAG(PD13), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM10 - PD13 - { TIM4, IO_TAG(PD14), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM11 - PD14 - { TIM4, IO_TAG(PD15), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM12 - PD15 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM13 - PA1 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM14 - PA2 - { TIM2, IO_TAG(PA3), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_ANY }, // PWM15 - PA3 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_ANY }, // PWM16 - PB0 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_ANY }, // PWM17 - PB1 - { TIM3, IO_TAG(PA4), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_ANY } // PWM18 - PA4 + DEF_TIM(TIM4, CH1, PD12, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM9 - PD12 + DEF_TIM(TIM4, CH2, PD13, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM10 - PD13 + DEF_TIM(TIM4, CH3, PD14, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM11 - PD14 + DEF_TIM(TIM4, CH4, PD15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM12 - PD15 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM13 - PA1 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM14 - PA2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_ANY, 0), // PWM15 - PA3 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_ANY, 0), // PWM16 - PB0 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_ANY, 0), // PWM17 - PB1 + DEF_TIM(TIM3, CH2, PA4, TIM_USE_ANY, 0), // PWM18 - PA4 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/CLRACINGF4AIR/target.c b/src/main/target/CLRACINGF4AIR/target.c index 4bb2314deca..5554bc3f2c0 100644 --- a/src/main/target/CLRACINGF4AIR/target.c +++ b/src/main/target/CLRACINGF4AIR/target.c @@ -21,23 +21,23 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM11, IO_TAG(PB9), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_TIM11, TIM_USE_PPM | TIM_USE_PWM }, // PPM - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_LED }, // LED_STRIP + DEF_TIM(TIM11, CH1, PB9, TIM_USE_PPM, 0, 0), + DEF_TIM(TIM4, CH3, PB8, TIM_USE_LED, 0, 0), #if defined(CLRACINGF4AIRV2) || defined(CLRACINGF4AIRV3) - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR 3 ELE - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR 4 ROLL 1 - { TIM12, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR 5 ROLL 2 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR 1 ESC - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR 2 ESC - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR 6 YAW + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), + DEF_TIM(TIM12, CH2, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), #else - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_1 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_2 - { TIM9, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // SERVO_1 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // SERVO_2 - { TIM12, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // SERVO_3 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // SERVO_4 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), + DEF_TIM(TIM9, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), + DEF_TIM(TIM12, CH2, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), #endif }; diff --git a/src/main/target/CLRACINGF4AIR/target.h b/src/main/target/CLRACINGF4AIR/target.h index f69eb59f9f3..cc8cf51a425 100644 --- a/src/main/target/CLRACINGF4AIR/target.h +++ b/src/main/target/CLRACINGF4AIR/target.h @@ -74,9 +74,6 @@ #define USE_LED_STRIP #define WS2811_PIN PB8 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST7_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream7 -#define WS2811_DMA_CHANNEL DMA_Channel_2 #define USE_VCP diff --git a/src/main/target/CLRACINGF4AIR/target.mk b/src/main/target/CLRACINGF4AIR/target.mk index f88b689f7e1..416569f682c 100644 --- a/src/main/target/CLRACINGF4AIR/target.mk +++ b/src/main/target/CLRACINGF4AIR/target.mk @@ -10,5 +10,4 @@ TARGET_SRC = \ drivers/barometer/barometer_bmp280.c \ drivers/compass/compass_mpu9250.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/COLIBRI/target.c b/src/main/target/COLIBRI/target.c index d380481f5fd..c418ec9977d 100755 --- a/src/main/target/COLIBRI/target.c +++ b/src/main/target/COLIBRI/target.c @@ -24,23 +24,25 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PA10), TIM_Channel_3, 0, IOCFG_IPD, GPIO_AF_TIM1, TIM_USE_PPM | TIM_USE_PWM }, // S1_IN - { TIM8, IO_TAG(PC6), TIM_Channel_1, 0, IOCFG_IPD, GPIO_AF_TIM8, TIM_USE_PWM }, // S2_IN - { TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_IPD, GPIO_AF_TIM8, TIM_USE_PWM }, // S3_IN - { TIM8, IO_TAG(PC8), TIM_Channel_3, 0, IOCFG_IPD, GPIO_AF_TIM8, TIM_USE_PWM }, // S4_IN - { TIM2, IO_TAG(PA15), TIM_Channel_1, 0, IOCFG_IPD, GPIO_AF_TIM2, TIM_USE_PWM }, // S5_IN - { TIM2, IO_TAG(PB3), TIM_Channel_2, 0, IOCFG_IPD, GPIO_AF_TIM2, TIM_USE_PWM }, // S6_IN - { TIM5, IO_TAG(PA0), TIM_Channel_1, 0, IOCFG_IPD, GPIO_AF_TIM5, TIM_USE_PWM }, // S7_IN - { TIM5, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_IPD, GPIO_AF_TIM5, TIM_USE_PWM }, // S8_IN + DEF_TIM(TIM1, CH3, PA10, TIM_USE_PWM | TIM_USE_PPM, 0, 0), // S1_IN + DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM, 0, 0), // S2_IN + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM, 0, 0), // S3_IN + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0, 0), // S4_IN + DEF_TIM(TIM2, CH1, PA15, TIM_USE_PWM, 0, 0), // S5_IN + DEF_TIM(TIM2, CH2, PB3, TIM_USE_PWM, 0, 0), // S6_IN + DEF_TIM(TIM5, CH1, PA0, TIM_USE_PWM, 0, 0), // S7_IN + DEF_TIM(TIM5, CH2, PA1, TIM_USE_PWM, 0, 0), // S8_IN - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S1_OUT - { TIM3, IO_TAG(PB4), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S2_OUT - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT - { TIM12, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT - { TIM3, IO_TAG(PB5), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S5_OUT - { TIM12, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S6_OUT - { TIM10, IO_TAG(PB8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM10, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, // S7_OUT - { TIM11, IO_TAG(PB9), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM11, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, // S8_OUT + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S1_OUT + DEF_TIM(TIM3, CH1, PB4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S2_OUT + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S3_OUT + DEF_TIM(TIM12, CH2, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S5_OUT + DEF_TIM(TIM12, CH1, PB14, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S6_OUT + DEF_TIM(TIM10, CH1, PB8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0, 0), // S7_OUT + DEF_TIM(TIM11, CH1, PB9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0, 0), // S8_OUT + + DEF_TIM(TIM4, CH2, PB7, TIM_USE_LED, 0, 0) }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/COLIBRI_RACE/target.c b/src/main/target/COLIBRI_RACE/target.c index 31bcbe2a0d5..f4fc7a58ed7 100644 --- a/src/main/target/COLIBRI_RACE/target.c +++ b/src/main/target/COLIBRI_RACE/target.c @@ -23,18 +23,18 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PA8), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_6, TIM_USE_PPM }, // PWM1 - PA8 - { TIM3, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - PC6 - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PC7 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PMW4 - PC8 - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - PC9 - { TIM2, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM6 - PA0 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM7 - PA1 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM8 - PA2 - { TIM2, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM9 - PA3 - { TIM15, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM10 - PB14 - { TIM15, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM11 - PB15 - { TIM16, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_LED }, + DEF_TIM(TIM1, CH1, PA8, TIM_USE_PPM, 0), // PWM1 - PA8 + DEF_TIM(TIM3, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 - PC6 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PC7 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PMW4 - PC8 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 - PC9 + DEF_TIM(TIM2, CH1, PA0, TIM_USE_MC_MOTOR, 0), // PWM6 - PA0 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR, 0), // PWM7 - PA1 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR, 0), // PWM8 - PA2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR, 0), // PWM9 - PA3 + DEF_TIM(TIM15, CH1, PB14, TIM_USE_MC_MOTOR, 0), // PWM10 - PB14 + DEF_TIM(TIM15, CH2, PB15, TIM_USE_MC_MOTOR, 0), // PWM11 - PB15 + DEF_TIM(TIM16, CH1, PA6, TIM_USE_LED, 0), // PWM11 - PB15 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/COLIBRI_RACE/target.h b/src/main/target/COLIBRI_RACE/target.h index fd178eb5cc9..c252263b0b1 100755 --- a/src/main/target/COLIBRI_RACE/target.h +++ b/src/main/target/COLIBRI_RACE/target.h @@ -111,10 +111,7 @@ #define RSSI_ADC_CHANNEL ADC_CHN_3 #define USE_LED_STRIP -#define WS2811_PIN PA6 // TIM16_CH1 -#define WS2811_DMA_STREAM DMA1_Channel3 -#define WS2811_DMA_TC_FLAG DMA1_FLAG_TC3 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH3_HANDLER +#define WS2811_PIN PA6 #define DEFAULT_FEATURES (FEATURE_TX_PROF_SEL | FEATURE_VBAT) #define DEFAULT_RX_TYPE RX_TYPE_SERIAL diff --git a/src/main/target/COLIBRI_RACE/target.mk b/src/main/target/COLIBRI_RACE/target.mk index 2260fb42c94..d016226a767 100644 --- a/src/main/target/COLIBRI_RACE/target.mk +++ b/src/main/target/COLIBRI_RACE/target.mk @@ -13,6 +13,4 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c - + drivers/light_ws2811strip.c diff --git a/src/main/target/DALRCF405/target.c b/src/main/target/DALRCF405/target.c index 71727d41575..a8d8deb8f34 100644 --- a/src/main/target/DALRCF405/target.c +++ b/src/main/target/DALRCF405/target.c @@ -22,19 +22,19 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM12, IO_TAG(PB15), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM10, TIM_USE_PPM }, + DEF_TIM(TIM12, CH2, PB15, TIM_USE_PPM, 0, 0), // PPM - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, - { TIM8, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM1, IO_TAG(PA10), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0, 0), // S1 (1,7) + DEF_TIM(TIM8, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S2 (2,2) + DEF_TIM(TIM1, CH3, PA10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S3 (2,6) + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S4 (2,1) (2.3 2.6) + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S5 (2,4) (2.2) + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S6 (1,2) + DEF_TIM(TIM3, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S7 (1,5) + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S8 (2,7) + DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // LED STRIP(1,0) - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM3, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_LED }, - { TIM2, IO_TAG(PA5), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_PWM }, + DEF_TIM(TIM2, CH1, PA5, TIM_USE_ANY, 0, 0), // FC CAM }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/DALRCF405/target.h b/src/main/target/DALRCF405/target.h index 8812ced5f01..aa65225ffc0 100644 --- a/src/main/target/DALRCF405/target.h +++ b/src/main/target/DALRCF405/target.h @@ -133,9 +133,7 @@ //LED_STRIP #define USE_LED_STRIP #define WS2811_PIN PB6 -#define WS2811_DMA_STREAM DMA1_Stream0 -#define WS2811_DMA_CHANNEL DMA_Channel_2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST0_HANDLER + //ADC #define USE_ADC #define ADC_INSTANCE ADC1 diff --git a/src/main/target/DALRCF405/target.mk b/src/main/target/DALRCF405/target.mk index 0c71c508094..6b8b76d1b42 100644 --- a/src/main/target/DALRCF405/target.mk +++ b/src/main/target/DALRCF405/target.mk @@ -17,6 +17,5 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/F4BY/target.c b/src/main/target/F4BY/target.c index 57796e1d8cc..eeaf06b027f 100644 --- a/src/main/target/F4BY/target.c +++ b/src/main/target/F4BY/target.c @@ -6,25 +6,25 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM3, IO_TAG(PC9), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_PPM | TIM_USE_PWM }, // S1_IN - { TIM3, IO_TAG(PC8), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_PWM }, // S2_IN - { TIM3, IO_TAG(PC6), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_PWM }, // S3_IN - { TIM3, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_PWM }, // S4_IN - { TIM4, IO_TAG(PD15), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_PWM }, // S5_IN - { TIM4, IO_TAG(PD14), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_PWM }, // S6_IN - { TIM4, IO_TAG(PD13), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_PWM }, // S7_IN - { TIM4, IO_TAG(PD12), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_PWM }, // S8_IN + DEF_TIM(TIM3, CH4, PC9, TIM_USE_PPM | TIM_USE_PWM, 0, 0), // S1_IN + DEF_TIM(TIM3, CH3, PC8, TIM_USE_PWM, 0, 0), // S2_IN + DEF_TIM(TIM3, CH1, PC6, TIM_USE_PWM, 0, 0), // S3_IN + DEF_TIM(TIM3, CH2, PC7, TIM_USE_PWM, 0, 0), // S4_IN + DEF_TIM(TIM4, CH4, PD15, TIM_USE_PWM, 0, 0), // S5_IN + DEF_TIM(TIM4, CH3, PD14, TIM_USE_PWM, 0, 0), // S6_IN + DEF_TIM(TIM4, CH2, PD13, TIM_USE_PWM, 0, 0), // S7_IN + DEF_TIM(TIM4, CH1, PD12, TIM_USE_PWM, 0, 0), // S8_IN - { TIM2, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT - { TIM5, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO}, // S3_OUT - { TIM5, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO}, // S4_OUT - { TIM1, IO_TAG(PE9), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO}, // S5_OUT - { TIM1, IO_TAG(PE11), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO}, // S6_OUT - { TIM1, IO_TAG(PE13), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO}, // S7_OUT - { TIM1, IO_TAG(PE14), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO}, // S8_OUT + DEF_TIM(TIM2, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1_OUT + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2_OUT + DEF_TIM(TIM5, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S3_OUT + DEF_TIM(TIM5, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT + DEF_TIM(TIM1, CH1, PE9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S5_OUT + DEF_TIM(TIM1, CH2, PE11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S6_OUT + DEF_TIM(TIM1, CH3, PE13, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S7_OUT + DEF_TIM(TIM1, CH4, PE14, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S8_OUT - { TIM9, IO_TAG(PE6), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM9, TIM_USE_ANY }, // HC-SR04 echo if needed + DEF_TIM(TIM9, CH2, PE6, TIM_USE_ANY, 0, 0), // sonar echo if needed }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/F4BY/target.mk b/src/main/target/F4BY/target.mk index f70cb91b5d0..e5221e515ea 100644 --- a/src/main/target/F4BY/target.mk +++ b/src/main/target/F4BY/target.mk @@ -2,13 +2,13 @@ F405_TARGETS += $(TARGET) FEATURES += SDCARD VCP TARGET_SRC = \ - drivers/accgyro/accgyro_mpu6000.c \ - drivers/barometer/barometer_ms56xx.c \ + drivers/accgyro/accgyro_mpu6000.c \ + drivers/barometer/barometer_ms56xx.c \ drivers/compass/compass_hmc5883l.c \ drivers/compass/compass_qmc5883l.c \ drivers/compass/compass_ist8310.c \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ - drivers/rangefinder/rangefinder_hcsr04.c \ - drivers/max7456.c \ No newline at end of file + drivers/rangefinder/rangefinder_hcsr04.c \ + drivers/max7456.c \ No newline at end of file diff --git a/src/main/target/FALCORE/target.c b/src/main/target/FALCORE/target.c index 8d6fd3ef893..cc6c8181b6e 100755 --- a/src/main/target/FALCORE/target.c +++ b/src/main/target/FALCORE/target.c @@ -24,23 +24,23 @@ const timerHardware_t timerHardware[] = { // MOTOR outputs - { TIM8, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR }, // PWM1 - PC6 - TIM8_CH1 - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR }, // PWM2 - PC7 - TIM8_CH2 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR }, // PWM3 - PC8 - TIM8_CH3 - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR }, // PWM4 - PC9 - TIM8_CH4 + DEF_TIM(TIM8, CH1, PC6, TIM_USE_MC_MOTOR, 1), + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR, 1), + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR, 1), + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR, 1), // Additional servo outputs - { TIM3, IO_TAG(PA4), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_SERVO }, // PWM5 - PA4 - TIM3_CH2 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_SERVO }, // PWM6 - PB1 - TIM3_CH4 + DEF_TIM(TIM3, CH2, PA4, TIM_USE_MC_SERVO, 0), + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_SERVO, 0), // PPM PORT - Also USART2 RX (AF5) - { TIM2, IO_TAG(PA3), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PPM }, // PPM - PA3 - TIM2_CH4 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_PPM, 0), // LED_STRIP - { TIM1, IO_TAG(PA8), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_ANY }, // GPIO_TIMER / LED_STRIP + DEF_TIM(TIM1, CH1, PA8, TIM_USE_ANY, 0), // PWM_BUZZER - { TIM16, IO_TAG(PB4), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_BEEPER }, // BUZZER - PB4 - TIM16_CH1N + DEF_TIM(TIM16, CH1, PB4, TIM_USE_BEEPER, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FALCORE/target.h b/src/main/target/FALCORE/target.h index 5e24a7839d9..3b303426ed9 100755 --- a/src/main/target/FALCORE/target.h +++ b/src/main/target/FALCORE/target.h @@ -110,10 +110,7 @@ #define RSSI_ADC_CHANNEL ADC_CHN_2 #define USE_LED_STRIP -#define USE_LED_STRIP_ON_DMA1_CHANNEL2 #define WS2811_PIN PA8 -#define WS2811_DMA_STREAM DMA1_Channel2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER #define USE_SERIAL_4WAY_BLHELI_INTERFACE diff --git a/src/main/target/FALCORE/target.mk b/src/main/target/FALCORE/target.mk index b47dc5e2c1a..087ec3e13f4 100755 --- a/src/main/target/FALCORE/target.mk +++ b/src/main/target/FALCORE/target.mk @@ -12,6 +12,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/barometer/barometer_ms56xx.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c - + drivers/light_ws2811strip.c \ No newline at end of file diff --git a/src/main/target/FF_F35_LIGHTNING/target.c b/src/main/target/FF_F35_LIGHTNING/target.c index fd434cee4eb..86ca96b9166 100644 --- a/src/main/target/FF_F35_LIGHTNING/target.c +++ b/src/main/target/FF_F35_LIGHTNING/target.c @@ -22,14 +22,14 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S5_OUT - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S6_OUT + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), - { TIM2, IO_TAG(PB10), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_PPM }, // PPM IN + DEF_TIM(TIM2, CH3, PB10, TIM_USE_PPM, 0, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FF_FORTINIF4/target.c b/src/main/target/FF_FORTINIF4/target.c index a05b6ccd0c2..98ea019571c 100644 --- a/src/main/target/FF_FORTINIF4/target.c +++ b/src/main/target/FF_FORTINIF4/target.c @@ -22,21 +22,13 @@ #include "drivers/pwm_mapping.h" #include "drivers/timer.h" -#define TIM_EN TIMER_OUTPUT_ENABLED - const timerHardware_t timerHardware[] = { - { TIM3, IO_TAG(PB0), TIM_Channel_3, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S1_OUT - { TIM3, IO_TAG(PB1), TIM_Channel_4, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S2_OUT - { TIM2, IO_TAG(PA2), TIM_Channel_3, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT - { TIM2, IO_TAG(PA3), TIM_Channel_4, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT - { TIM4, IO_TAG(PB9), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_PPM | TIM_USE_MC_SERVO }, // PPM IN - { TIM4, IO_TAG(PB7), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_LED | TIM_USE_MC_SERVO }, // LED -// DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, TIMER_OUTPUT_STANDARD, 0 ), // S1_OUT - DMA1_ST7 -// DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, TIMER_OUTPUT_STANDARD, 0 ), // S2_OUT - DMA1_ST2 -// DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, TIMER_OUTPUT_STANDARD, 1 ), // S3_OUT - DMA1_ST6 -// DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, TIMER_OUTPUT_STANDARD, 0 ), // S4_OUT - DMA1_ST1 -// DEF_TIM(TIM4, CH4, PB9, TIM_USE_PPM, TIMER_INPUT_ENABLED, 0 ), // PPM IN -// DEF_TIM(TIM4, CH2, PB7, TIM_USE_LED, TIMER_OUTPUT_STANDARD, 0), // LED - DMA1_ST3 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0 ), // S1_OUT - DMA1_ST7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0 ), // S2_OUT - DMA1_ST2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 1 ), // S3_OUT - DMA1_ST6 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0 ), // S4_OUT - DMA1_ST1 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_PPM, 0, 0 ), // PPM IN + DEF_TIM(TIM4, CH2, PB7, TIM_USE_LED, 0, 0), // LED - DMA1_ST3 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FF_FORTINIF4/target.mk b/src/main/target/FF_FORTINIF4/target.mk index a6b838a95e4..581916350df 100644 --- a/src/main/target/FF_FORTINIF4/target.mk +++ b/src/main/target/FF_FORTINIF4/target.mk @@ -4,5 +4,4 @@ FEATURES += VCP ONBOARDFLASH TARGET_SRC = \ drivers/accgyro/accgyro_mpu6500.c \ drivers/max7456.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c + drivers/light_ws2811strip.c \ No newline at end of file diff --git a/src/main/target/FF_PIKOF4/target.c b/src/main/target/FF_PIKOF4/target.c index 34083d8dc6a..14a5ab95d5b 100644 --- a/src/main/target/FF_PIKOF4/target.c +++ b/src/main/target/FF_PIKOF4/target.c @@ -26,30 +26,19 @@ const timerHardware_t timerHardware[] = { #if defined(FF_PIKOF4OSD) - { TIM2, IO_TAG(PA3), TIM_Channel_4, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT // TIM2_CH4 | TIM5_CH4 | TIM9_CH2 - { TIM3, IO_TAG(PB1), TIM_Channel_4, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT // TIM1_CH3N | TIM3_CH4 | TIM8_CH3N - { TIM5, IO_TAG(PA2), TIM_Channel_3, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT // TIM2_CH3 | TIM5_CH3 | TIM9_CH1 - { TIM3, IO_TAG(PB0), TIM_Channel_3, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT // TIM1_CH2N | TIM3_CH3 | TIM8_CH2N - { TIM12, IO_TAG(PB14), TIM_Channel_1, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // RC4 // TIM1_CH2N | TIM8_CH2N | TIM12_CH1 - { TIM12, IO_TAG(PB15), TIM_Channel_2, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // RC5 // TIM1_CH3N | TIM8_CH3N | TIM12_CH2 -// DEF_TIM(TIM5, CH4, PA3, TIM_USE_MOTOR, 0, 0 ), // S1_OUT - DMA1_ST7 -// DEF_TIM(TIM3, CH3, PB1, TIM_USE_MOTOR, 0, 0 ), // S2_OUT - DMA1_ST1 -// DEF_TIM(TIM5, CH3, PA2, TIM_USE_MOTOR, 0, 0 ), // S3_OUT - DMA1_ST6 -// DEF_TIM(TIM3, CH4, PB0, TIM_USE_MOTOR, 0, 0 ), // S4_OUT - DMA1_ST2 -// DEF_TIM(TIM8, CH2N, PB14, TIM_USE_MOTOR, 0, 0 ), // PA14 RC4 - DMA2_ST6, *DMA2_ST2 -// DEF_TIM(TIM1, CH3N, PB15, TIM_USE_MOTOR, 0, 0 ), // PA15 RC5 - DMA2_ST6, DMA2_ST6 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), + DEF_TIM(TIM3, CH3, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), + DEF_TIM(TIM5, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM3, CH4, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM12, CH1, PB14, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM12, CH2, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), #else - { TIM2, IO_TAG(PA3), TIM_Channel_4, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT // TIM2_CH4 | TIM5_CH4 | TIM9_CH2 - { TIM3, IO_TAG(PB0), TIM_Channel_3, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S2_OUT // TIM1_CH2N | TIM3_CH3 | TIM8_CH2N - { TIM5, IO_TAG(PA2), TIM_Channel_3, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT // TIM2_CH3 | TIM5_CH3 | TIM9_CH1 - { TIM3, IO_TAG(PB1), TIM_Channel_4, TIM_EN, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT // TIM1_CH3N | TIM3_CH4 | TIM8_CH3N -// DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, 0, 1 ), // S1_OUT - DMA1_ST6 -// DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 0, 0 ), // S2_OUT - DMA1_ST7 -// DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 0, 0 ), // S3_OUT - DMA1_ST1 -// DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 0, 0 ), // S4_OUT - DMA1_ST2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM5, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), #endif - { TIM4, IO_TAG(PB7), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM4, TIM_USE_LED | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // LED -// DEF_TIM(TIM4, CH2, PB7, TIM_USE_LED, 0, 0 ), // LED - DMA1_ST3 + DEF_TIM(TIM4, CH2, PB7, TIM_USE_LED, 0, 0 ), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FF_PIKOF4/target.mk b/src/main/target/FF_PIKOF4/target.mk index f6b7d8dd416..234c6ad4458 100644 --- a/src/main/target/FF_PIKOF4/target.mk +++ b/src/main/target/FF_PIKOF4/target.mk @@ -5,6 +5,5 @@ TARGET_SRC = \ drivers/accgyro/accgyro_mpu6000.c \ drivers/accgyro/accgyro_mpu6500.c \ drivers/max7456.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c + drivers/light_ws2811strip.c \ No newline at end of file diff --git a/src/main/target/FIREWORKSV2/target.c b/src/main/target/FIREWORKSV2/target.c index 51fa5fcde46..7073a54d23f 100644 --- a/src/main/target/FIREWORKSV2/target.c +++ b/src/main/target/FIREWORKSV2/target.c @@ -30,26 +30,17 @@ #include "drivers/timer.h" #include "drivers/bus.h" -#define DEF_TIM_CHNL_CH1 TIM_Channel_1 -#define DEF_TIM_CHNL_CH2 TIM_Channel_2 -#define DEF_TIM_CHNL_CH3 TIM_Channel_3 -#define DEF_TIM_CHNL_CH4 TIM_Channel_4 - -#define DEF_TIM(_tim, _ch, _pin, _usage, _flags) \ - { _tim, IO_TAG(_pin), DEF_TIM_CHNL_##_ch, _flags, IOCFG_AF_PP, GPIO_AF_##_tim, _usage } - - const timerHardware_t timerHardware[] = { - DEF_TIM(TIM10, CH1, PB8, TIM_USE_PPM, 0), // PPM + DEF_TIM(TIM10, CH1, PB8, TIM_USE_PPM, 0, 0), // PPM - DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1), // S1_OUT - DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1), // S2_OUT - DEF_TIM(TIM9, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), // S3_OUT - DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), // S4_OUT + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), // S1_OUT + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), // S2_OUT + DEF_TIM(TIM9, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S3_OUT + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S4_OUT - DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0), // LED strip + DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // LED strip - DEF_TIM(TIM1, CH2, PA9, TIM_USE_ANY, 0), // SS1 + DEF_TIM(TIM1, CH2, PA9, TIM_USE_ANY, 0, 0), // SS1 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FIREWORKSV2/target.mk b/src/main/target/FIREWORKSV2/target.mk index 62e119d7ff0..2382c6005d3 100644 --- a/src/main/target/FIREWORKSV2/target.mk +++ b/src/main/target/FIREWORKSV2/target.mk @@ -15,5 +15,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/FISHDRONEF4/target.c b/src/main/target/FISHDRONEF4/target.c index 31805ed2f9e..5273c1d426a 100644 --- a/src/main/target/FISHDRONEF4/target.c +++ b/src/main/target/FISHDRONEF4/target.c @@ -23,21 +23,21 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM5, IO_TAG(PA0), TIM_Channel_1, 0, IOCFG_AF_PP , GPIO_AF_TIM5, TIM_USE_PPM | TIM_USE_PWM }, // S1_IN(PPM) - { TIM5, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP , GPIO_AF_TIM5, TIM_USE_PWM }, // S2_IN - { TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_AF_PP , GPIO_AF_TIM3, TIM_USE_PWM }, // S3_IN - { TIM2, IO_TAG(PB10), TIM_Channel_3, 0, IOCFG_AF_PP , GPIO_AF_TIM2, TIM_USE_PWM }, // S4_IN - { TIM2, IO_TAG(PB11), TIM_Channel_4, 0, IOCFG_AF_PP , GPIO_AF_TIM2, TIM_USE_PWM }, // S5_IN - { TIM1, IO_TAG(PA8), TIM_Channel_1, 0, IOCFG_AF_PP , GPIO_AF_TIM1, TIM_USE_PWM }, // S6_IN + DEF_TIM(TIM5, CH1, PA0, TIM_USE_PWM | TIM_USE_PPM, 0, 0 ), // PPM IN + DEF_TIM(TIM5, CH2, PA1, TIM_USE_PWM, 0, 0 ), + DEF_TIM(TIM3, CH3, PB0, TIM_USE_PWM, 0, 0 ), + DEF_TIM(TIM2, CH3, PB10, TIM_USE_PWM, 0, 0 ), + DEF_TIM(TIM2, CH4, PB11, TIM_USE_PWM, 0, 0 ), + DEF_TIM(TIM1, CH1, PA8, TIM_USE_PWM, 0, 0 ), - { TIM12, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR },// S1_OUT - { TIM12, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR },// S2_OUT - { TIM8, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S5_OUT - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S6_OUT + DEF_TIM(TIM12, CH1, PB14, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), + DEF_TIM(TIM12, CH2, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), + DEF_TIM(TIM8, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP , GPIO_AF_TIM3, TIM_USE_LED }, // LED_STRIP + DEF_TIM(TIM3, CH4, PB1, TIM_USE_LED, 0, 0 ), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FISHDRONEF4/target.h b/src/main/target/FISHDRONEF4/target.h index f9f1a95c4c5..ec0fbaaab3c 100644 --- a/src/main/target/FISHDRONEF4/target.h +++ b/src/main/target/FISHDRONEF4/target.h @@ -135,14 +135,6 @@ // *************** WS2811 ***************************** #define USE_LED_STRIP #define WS2811_PIN PB1 -#define WS2811_TIMER TIM3 -#define WS2811_TIMER_CHANNEL TIM_Channel_4 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST2_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream2 -#define WS2811_DMA_FLAG DMA_FLAG_TCIF2 -#define WS2811_DMA_IT DMA_IT_TCIF2 -#define WS2811_DMA_CHANNEL DMA_Channel_5 -#define WS2811_DMA_IRQ DMA1_Stream2_IRQn // *************** IIC ***************************** #define USE_I2C diff --git a/src/main/target/FISHDRONEF4/target.mk b/src/main/target/FISHDRONEF4/target.mk index 2efb86bbe2b..ab900e2a149 100644 --- a/src/main/target/FISHDRONEF4/target.mk +++ b/src/main/target/FISHDRONEF4/target.mk @@ -14,5 +14,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c\ drivers/max7456.c diff --git a/src/main/target/FRSKYF3/target.c b/src/main/target/FRSKYF3/target.c index 707a7aa0b3c..1a7c406e954 100644 --- a/src/main/target/FRSKYF3/target.c +++ b/src/main/target/FRSKYF3/target.c @@ -23,17 +23,16 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { + DEF_TIM(TIM8, CH3, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 + DEF_TIM(TIM8, CH2, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM6 + DEF_TIM(TIM2, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM7 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM8 - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - { TIM2, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - { TIM2, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM7 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM8 - - // DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED|TIM_USE_TRANSPONDER, TIMER_OUTPUT_ENABLED), // LED + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0), // LED }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FRSKYF4/target.c b/src/main/target/FRSKYF4/target.c index 043e19c675c..11d40beb500 100755 --- a/src/main/target/FRSKYF4/target.c +++ b/src/main/target/FRSKYF4/target.c @@ -22,30 +22,15 @@ #include "drivers/timer.h" #include "drivers/pwm_mapping.h" -#define DEF_TIM_CHNL_CH1 TIM_Channel_1 -#define DEF_TIM_CHNL_CH2 TIM_Channel_2 -#define DEF_TIM_CHNL_CH3 TIM_Channel_3 -#define DEF_TIM_CHNL_CH4 TIM_Channel_4 - -#define DEF_TIM(_tim, _ch, _pin, _usage, _flags) \ - { _tim, IO_TAG(_pin), DEF_TIM_CHNL_##_ch, _flags, IOCFG_AF_PP, GPIO_AF_##_tim, _usage } - const timerHardware_t timerHardware[] = { - // DEF_TIM(TIM4, CH3, PB8, TIM_USE_PWM | TIM_USE_PPM, 0), // PPM - // DEF_TIM(TIM4, CH4, PB9, TIM_USE_PWM, 0), // S2_IN - // DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM, 0), // S3_IN, UART6_TX - // DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM, 0), // S4_IN, UART6_RX - // DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0), // S5_IN - // DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM, 0), // S6_IN - - DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1), // S1_OUT - DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1), // S2_OUT - DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), // S3_OUT - DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), // S4_OUT - DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), // S5_OUT - DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), // S6_OUT - - DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0), // LED strip + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), // S1_OUT + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), // S2_OUT + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S3_OUT + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S4_OUT + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S5_OUT + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S6_OUT + + DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // LED strip }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FURYF3/target.c b/src/main/target/FURYF3/target.c index 3de9ca129ff..eaeefa0bfa6 100755 --- a/src/main/target/FURYF3/target.c +++ b/src/main/target/FURYF3/target.c @@ -8,18 +8,17 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM2, IO_TAG(PB3), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PPM | TIM_USE_PWM }, // PPM IN + DEF_TIM(TIM2, CH2, PB3, TIM_USE_PPM, 0), // PPM IN + + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR, 0), + DEF_TIM(TIM4, CH1, PB6, TIM_USE_MC_MOTOR, 0), + DEF_TIM(TIM17, CH1, PB5, TIM_USE_MC_MOTOR, 0), + DEF_TIM(TIM16, CH1, PB4, TIM_USE_MC_MOTOR, 0), - { TIM4, IO_TAG(PB7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR }, // PWM4 - S1 - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR }, // PWM5 - S2 - { TIM17, IO_TAG(PB5), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR }, // PWM6 - S3 - { TIM16, IO_TAG(PB4), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM7 - S4 - - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_MOTOR }, // SS1 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_MOTOR }, // SS1 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N - - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_ANY }, // GPIO TIMER - LED_STRIP + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR, 0), + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR, 0), + DEF_TIM(TIM1, CH1, PA8, TIM_USE_ANY, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/FURYF3/target.h b/src/main/target/FURYF3/target.h index dbe4aef801e..12c596c9925 100755 --- a/src/main/target/FURYF3/target.h +++ b/src/main/target/FURYF3/target.h @@ -146,13 +146,7 @@ #define CURRENT_METER_ADC_CHANNEL ADC_CHN_3 #define USE_LED_STRIP -#define USE_LED_STRIP_ON_DMA1_CHANNEL2 #define WS2811_PIN PA8 -#define WS2811_TIMER TIM1 -#define WS2811_DMA_STREAM DMA1_Channel2 -#define WS2811_IRQ DMA1_Channel2_IRQn -#define WS2811_DMA_TC_FLAG DMA1_FLAG_TC2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER #define USE_RANGEFINDER #define USE_RANGEFINDER_HCSR04 diff --git a/src/main/target/FURYF3/target.mk b/src/main/target/FURYF3/target.mk index 62126108842..758082e8986 100755 --- a/src/main/target/FURYF3/target.mk +++ b/src/main/target/FURYF3/target.mk @@ -16,6 +16,5 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_softserial.c diff --git a/src/main/target/KAKUTEF4/target.c b/src/main/target/KAKUTEF4/target.c index f381a0c57f5..48082d288a0 100755 --- a/src/main/target/KAKUTEF4/target.c +++ b/src/main/target/KAKUTEF4/target.c @@ -29,20 +29,20 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PPM }, // PPM + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PPM, 0, 0), // PPM IN - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_1 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_2 - { TIM2, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_3 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_4 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1_OUT - DMA1_ST7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2_OUT - DMA1_ST2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S3_OUT - DMA1_ST6 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT - DMA1_ST1 - #if defined(KAKUTEF4V2) - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_LED } - #else - { TIM5, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_5 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_6 - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_LED } - #endif +#if defined(KAKUTEF4V2) + DEF_TIM(TIM8, CH3, PC8, TIM_USE_LED, 0, 0), // LED_STRIP - DMA2_ST2 +#else + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S5_OUT - DMA1_ST2 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S6_OUT - DMA2_ST4 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_LED, 0, 0), // LED_STRIP - DMA1_ST4 +#endif }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/KAKUTEF4/target.mk b/src/main/target/KAKUTEF4/target.mk index 99264125b89..74fab0fb57f 100755 --- a/src/main/target/KAKUTEF4/target.mk +++ b/src/main/target/KAKUTEF4/target.mk @@ -13,5 +13,4 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/KAKUTEF7/target.c b/src/main/target/KAKUTEF7/target.c index 0dd1f8b4034..f0451514875 100755 --- a/src/main/target/KAKUTEF7/target.c +++ b/src/main/target/KAKUTEF7/target.c @@ -31,16 +31,16 @@ BUSDEV_REGISTER_SPI_TAG(busdev_icm20689, DEVHW_ICM20689, ICM20689_SPI_BUS, ICM20689_CS_PIN, ICM20689_EXTI_PIN, 0, DEVFLAGS_NONE); const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PE13), TIM_CHANNEL_3, 0, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_PPM }, // PPM + DEF_TIM(TIM1, CH3, PE13, TIM_USE_PPM, 0, 1), // PPM, DMA2_ST6 - { TIM3, IO_TAG(PB0), TIM_CHANNEL_3, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_1 - { TIM3, IO_TAG(PB1), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_2 - { TIM1, IO_TAG(PE9), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_3 - { TIM1, IO_TAG(PE11), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_4 - { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_5 - { TIM5, IO_TAG(PA3), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_6 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // M1 , DMA1_ST7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // M2 , DMA1_ST2 + DEF_TIM(TIM1, CH1, PE9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 2), // M3 , DMA2_ST2 + DEF_TIM(TIM1, CH2, PE11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // M4 , DMA2_ST4 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // M5 , DMA2_ST7 + DEF_TIM(TIM5, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // M6 , DMA1_ST1 - { TIM4, IO_TAG(PD12), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_LED } + DEF_TIM(TIM4, CH1, PD12, TIM_USE_LED, 0, 0), // LED_TRIP, DMA1_ST0 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/KAKUTEF7/target.mk b/src/main/target/KAKUTEF7/target.mk index 037f63f7a9c..f22a7f7d6fa 100755 --- a/src/main/target/KAKUTEF7/target.mk +++ b/src/main/target/KAKUTEF7/target.mk @@ -12,5 +12,4 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/KFC32F3_INAV/target.c b/src/main/target/KFC32F3_INAV/target.c index 7f1edfe84be..6c6abf12dab 100755 --- a/src/main/target/KFC32F3_INAV/target.c +++ b/src/main/target/KFC32F3_INAV/target.c @@ -24,17 +24,19 @@ const timerHardware_t timerHardware[] = { - { TIM2, IO_TAG(PA0), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PPM }, // // PPM - PA0 - *TIM2_CH1 - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_IPD, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_IPD, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM2 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_IPD, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - { TIM4, IO_TAG(PB7), TIM_Channel_2, 1, IOCFG_IPD, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_IPD, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_IPD, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - { TIM2, IO_TAG(PB10), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM7 - { TIM2, IO_TAG(PB11), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM8 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_ANY | TIM_USE_LED }, // S1_out - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_IPD, GPIO_AF_1, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO |TIM_USE_ANY }, // S2_out + DEF_TIM(TIM2, CH1, PA0, TIM_USE_PPM, 0), // PPM + + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM3 + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM4 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM5 + DEF_TIM(TIM4, CH1, PB6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM6 + DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM7 + DEF_TIM(TIM2, CH4, PB11, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM8 + + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR | TIM_USE_LED, 0), // S1_out + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // S2_out }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/KFC32F3_INAV/target.mk b/src/main/target/KFC32F3_INAV/target.mk index aeb7043a5e5..ea79e38e767 100644 --- a/src/main/target/KFC32F3_INAV/target.mk +++ b/src/main/target/KFC32F3_INAV/target.mk @@ -16,6 +16,5 @@ TARGET_SRC = \ drivers/flash_m25p16.c \ drivers/max7456.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c diff --git a/src/main/target/KISSFC/target.c b/src/main/target/KISSFC/target.c index d7dd821de9f..9e3b854b9b4 100644 --- a/src/main/target/KISSFC/target.c +++ b/src/main/target/KISSFC/target.c @@ -27,17 +27,18 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1 | TIMER_OUTPUT_INVERTED, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - { TIM1, IO_TAG(PB0), TIM_Channel_2, 1 | TIMER_OUTPUT_INVERTED | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - { TIM15, IO_TAG(PB14), TIM_Channel_1, 1 | TIMER_OUTPUT_INVERTED, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - { TIM15, IO_TAG(PB15), TIM_Channel_2, 1 | TIMER_OUTPUT_INVERTED, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - { TIM3, IO_TAG(PA6), TIM_Channel_1, 1 | TIMER_OUTPUT_INVERTED, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - { TIM3, IO_TAG(PA7), TIM_Channel_2, 1 | TIMER_OUTPUT_INVERTED, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - { TIM4, IO_TAG(PA13), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_PWM }, // AUX1 - { TIM2, IO_TAG(PB3), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // TX2 - { TIM8, IO_TAG(PA15), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM }, // ROLL - { TIM2, IO_TAG(PA2), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // PITCH - { TIM2, IO_TAG(PB11), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // YAW + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), + DEF_TIM(TIM1, CH2N, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), + DEF_TIM(TIM15, CH1, PB14, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM15, CH2, PB15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM3, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM3, CH2, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + + DEF_TIM(TIM4, CH3, PA13, TIM_USE_PWM, 0), + DEF_TIM(TIM2, CH2, PB3, TIM_USE_PWM | TIM_USE_PPM, 0), + DEF_TIM(TIM8, CH1, PA15, TIM_USE_PWM, 0), + DEF_TIM(TIM2, CH3, PA2, TIM_USE_PWM, 0), + DEF_TIM(TIM2, CH4, PB11, TIM_USE_PWM, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/KROOZX/target.c b/src/main/target/KROOZX/target.c index 331f590d2ca..4dcba204f35 100755 --- a/src/main/target/KROOZX/target.c +++ b/src/main/target/KROOZX/target.c @@ -23,17 +23,20 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - {TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PPM }, // PPM IN - {TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR }, // PWM2 - {TIM5, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR }, // PWM3 - {TIM5, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR }, // PWM4 - {TIM5, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR }, // PWM5 - {TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR }, // PWM6 - {TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR }, // PWM7 - {TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR }, // PWM8 - {TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR }, // PWM9 - {TIM12, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_MC_MOTOR }, // PWM10 - {TIM12, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_MC_MOTOR }, // PWM11 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PPM, 0, 0), // PPM IN + + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR, 0, 0), // PWM4 + DEF_TIM(TIM5, CH4, PA3, TIM_USE_MC_MOTOR, 0, 0), // PWM2 + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR, 0, 0), // PWM3 + DEF_TIM(TIM5, CH3, PA2, TIM_USE_MC_MOTOR, 0, 0), // PWM1 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR, 0, 0), // PWM5 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR, 0, 0), // PWM6 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR, 0, 0), // PWM7 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR, 0, 0), // PWM8 + DEF_TIM(TIM4, CH1, PB14, TIM_USE_MC_MOTOR, 0, 0), // PWM9 + DEF_TIM(TIM4, CH2, PB15, TIM_USE_MC_MOTOR, 0, 0), // PWM10 + + DEF_TIM(TIM8, CH1, PC6, TIM_USE_LED, 0, 0), // LED_STRIP }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/KROOZX/target.h b/src/main/target/KROOZX/target.h index 91ebd7e91fe..2b0e2bbf3eb 100755 --- a/src/main/target/KROOZX/target.h +++ b/src/main/target/KROOZX/target.h @@ -148,16 +148,7 @@ #define DEFAULT_FEATURES (FEATURE_TX_PROF_SEL | FEATURE_VBAT | FEATURE_CURRENT_METER | FEATURE_OSD) #define USE_LED_STRIP -#define WS2811_GPIO_AF GPIO_AF_TIM3 #define WS2811_PIN PC6 -#define WS2811_TIMER TIM3 -#define WS2811_TIMER_CHANNEL TIM_Channel_1 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST4_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream4 -#define WS2811_DMA_CHANNEL DMA_Channel_5 -#define WS2811_DMA_IRQ DMA1_Stream4_IRQn -#define WS2811_DMA_FLAG DMA_FLAG_TCIF4 -#define WS2811_DMA_IT DMA_IT_TCIF4 #define USE_SERIAL_4WAY_BLHELI_INTERFACE diff --git a/src/main/target/KROOZX/target.mk b/src/main/target/KROOZX/target.mk index 9fc70c0a69f..529d41babbf 100755 --- a/src/main/target/KROOZX/target.mk +++ b/src/main/target/KROOZX/target.mk @@ -12,5 +12,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/max7456.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ No newline at end of file + drivers/light_ws2811strip.c \ No newline at end of file diff --git a/src/main/target/LUX_RACE/target.c b/src/main/target/LUX_RACE/target.c index 31bcbe2a0d5..95b2b654283 100644 --- a/src/main/target/LUX_RACE/target.c +++ b/src/main/target/LUX_RACE/target.c @@ -23,18 +23,21 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PA8), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_6, TIM_USE_PPM }, // PWM1 - PA8 - { TIM3, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - PC6 - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PC7 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PMW4 - PC8 - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - PC9 - { TIM2, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM6 - PA0 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM7 - PA1 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM8 - PA2 - { TIM2, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM9 - PA3 - { TIM15, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM10 - PB14 - { TIM15, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_MC_MOTOR }, // PWM11 - PB15 - { TIM16, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_LED }, + DEF_TIM(TIM1, CH1, PA8, TIM_USE_PPM, 0), // PWM1 - PA8 + + DEF_TIM(TIM3, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 - PC6 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PC7 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PMW4 - PC8 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 - PC9 + + DEF_TIM(TIM2, CH1, PA0, TIM_USE_MC_MOTOR, 0), // PWM6 - PA0 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR, 0), // PWM7 - PA1 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR, 0), // PWM8 - PA2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR, 0), // PWM9 - PA3 + DEF_TIM(TIM15, CH1, PB14, TIM_USE_MC_MOTOR, 0), // PWM10 - PB14 + DEF_TIM(TIM15, CH2, PB15, TIM_USE_MC_MOTOR, 0), // PWM11 - PB15 + + DEF_TIM(TIM16, CH1, PA6, TIM_USE_LED, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/LUX_RACE/target.mk b/src/main/target/LUX_RACE/target.mk index 81adcd66c61..67886273cb8 100644 --- a/src/main/target/LUX_RACE/target.mk +++ b/src/main/target/LUX_RACE/target.mk @@ -6,6 +6,5 @@ TARGET_SRC = \ drivers/accgyro/accgyro_mpu6500.c \ drivers/accgyro/accgyro_mpu9250.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_usb_vcp.c \ diff --git a/src/main/target/MATEKF405/target.c b/src/main/target/MATEKF405/target.c index bb140f936e3..dca8a2d71bb 100644 --- a/src/main/target/MATEKF405/target.c +++ b/src/main/target/MATEKF405/target.c @@ -22,31 +22,31 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM9, IO_TAG(PA3), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM9, TIM_USE_PPM }, + DEF_TIM(TIM9, CH2, PA3, TIM_USE_PPM, 0, 0), // PPM #ifdef MATEKF405_SERVOS6 - { TIM3, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //S1 DMA1_ST4 MT1 + DEF_TIM(TIM3, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 #else - { TIM3, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, + DEF_TIM(TIM3, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0, 0), // S1 #endif - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S2 DMA2_ST3 SV3 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S3 DMA2_ST4 SV4 - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S4 DMA3_ST7 SV5 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S2 UP(2,1) + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S3 UP(2,1) + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4 UP(2,1) - { TIM2, IO_TAG(PA15), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_LED }, //S5 DMA1_ST5 2812LED + DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S5 UP(1,7) #ifdef MATEKF405_SERVOS6 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, //S6 DMA2_ST6 SV6 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6 UP(2,5) #else - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S6 UP(2,5) #endif - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, //S7 DMA1_ST7 MT2 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S7 D(1,7)!S5 UP(2,6) + DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // LED D(1,0) UP(2,6) - { TIM5, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_PWM }, //TX2 - - { TIM5, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_PWM }, //TX4 softserial1_tx - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_PWM }, //RX4 softserial1_rx + DEF_TIM(TIM5, CH3, PA2, TIM_USE_PWM, 0, 0), // TX2 + DEF_TIM(TIM5, CH1, PA0, TIM_USE_PWM, 0, 0), // TX4 UP(1,6) D(1,2)!S1 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_PWM, 0, 0), // RX4 UP(1,6) D(1,4) }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/MATEKF405/target.h b/src/main/target/MATEKF405/target.h index 940b91c62fa..e9db251de7b 100644 --- a/src/main/target/MATEKF405/target.h +++ b/src/main/target/MATEKF405/target.h @@ -198,9 +198,6 @@ #define USE_LED_STRIP #define WS2811_PIN PA15 // S5 pad for iNav -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST5_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream5 -#define WS2811_DMA_CHANNEL DMA_Channel_3 #define USE_SPEKTRUM_BIND #define BIND_PIN PA3 // RX2 diff --git a/src/main/target/MATEKF405/target.mk b/src/main/target/MATEKF405/target.mk index c728eab7ad4..db90296bfff 100755 --- a/src/main/target/MATEKF405/target.mk +++ b/src/main/target/MATEKF405/target.mk @@ -18,5 +18,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/MATEKF405SE/target.c b/src/main/target/MATEKF405SE/target.c index 945179e5cc7..6e77baa43f1 100644 --- a/src/main/target/MATEKF405SE/target.c +++ b/src/main/target/MATEKF405SE/target.c @@ -22,20 +22,21 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM4, IO_TAG(PB7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //S1 - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //S2 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S3 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S4 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S5 - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S6 - { TIM12, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, //S7 - { TIM12, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, //S8 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, //S9 + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), // S1 + DEF_TIM(TIM4, CH1, PB6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), // S2 - { TIM2, IO_TAG(PA15), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_LED }, //2812LED - { TIM9, IO_TAG(PA3), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM9, TIM_USE_PPM }, //RX2 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S3 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S4 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S5 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // S6 + DEF_TIM(TIM12, CH1, PB14, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 1, 0), // S7 + DEF_TIM(TIM12, CH2, PB15, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 1, 0), // S8 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 1, 0), // S9 - { TIM5, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_PWM }, //TX2 softserial1_Tx + DEF_TIM(TIM2, CH1, PA15, TIM_USE_LED, 0, 0), //2812LED + + DEF_TIM(TIM9, CH2, PA3, TIM_USE_PPM, 0, 0), //RX2 + DEF_TIM(TIM5, CH3, PA2, TIM_USE_ANY, 0, 0), //TX2 softserial1_Tx }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/MATEKF405SE/target.mk b/src/main/target/MATEKF405SE/target.mk index 49849d517cc..339663ec331 100644 --- a/src/main/target/MATEKF405SE/target.mk +++ b/src/main/target/MATEKF405SE/target.mk @@ -16,5 +16,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/MATEKF411/target.c b/src/main/target/MATEKF411/target.c index d85fec5bbac..d67eb33f449 100755 --- a/src/main/target/MATEKF411/target.c +++ b/src/main/target/MATEKF411/target.c @@ -23,16 +23,21 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM3, IO_TAG(PB4), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //S1 - { TIM3, IO_TAG(PB5), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //S2 - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S3 - { TIM4, IO_TAG(PB7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S4 - { TIM2, IO_TAG(PB3), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, //S5 - { TIM2, IO_TAG(PB10), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, //S6 - { TIM2, IO_TAG(PA15), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_CHNFW | TIM_USE_FW_SERVO }, //S7 - - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_LED}, //2812LED - { TIM5, IO_TAG(PA0), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_PPM }, //use rssi pad for PPM/softserial_tx1 + // DEF_TIM(TIM9, CH2, PA3, TIM_USE_PPM, 0, 0), // PPM IN + + DEF_TIM(TIM3, CH1, PB4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1_OUT + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2_OUT + DEF_TIM(TIM4, CH1, PB6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S3_OUT + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT + + DEF_TIM(TIM2, CH2, PB3, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S5 + DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6 + DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_CHNFW | TIM_USE_FW_SERVO, 0, 0), // S7 + + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0, 0), // LED + DEF_TIM(TIM5, CH1, PA0, TIM_USE_PPM, 0, 0), //use rssi pad for PPM/softserial_tx1 + + //DEF_TIM(TIM5, CH3, PA2, TIM_USE_ANY, 0, 0), // TX2 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/MATEKF411/target.h b/src/main/target/MATEKF411/target.h index 6b6a87d2517..d8cf191c3d8 100755 --- a/src/main/target/MATEKF411/target.h +++ b/src/main/target/MATEKF411/target.h @@ -123,9 +123,6 @@ // *************** LED2812 ************************ #define USE_LED_STRIP #define WS2811_PIN PA8 -#define WS2811_DMA_HANDLER_IDENTIFER DMA2_ST1_HANDLER -#define WS2811_DMA_STREAM DMA2_Stream1 -#define WS2811_DMA_CHANNEL DMA_Channel_6 // *************** OTHERS ************************* #define DEFAULT_FEATURES (FEATURE_TX_PROF_SEL | FEATURE_OSD | FEATURE_CURRENT_METER | FEATURE_VBAT | FEATURE_TELEMETRY | FEATURE_SOFTSERIAL ) diff --git a/src/main/target/MATEKF411/target.mk b/src/main/target/MATEKF411/target.mk index e025819ce19..e85b53c33af 100755 --- a/src/main/target/MATEKF411/target.mk +++ b/src/main/target/MATEKF411/target.mk @@ -14,5 +14,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/MATEKF722/target.c b/src/main/target/MATEKF722/target.c index 41c2b57bb3a..e341087775a 100755 --- a/src/main/target/MATEKF722/target.c +++ b/src/main/target/MATEKF722/target.c @@ -28,19 +28,20 @@ #define TIM_EN_N TIMER_OUTPUT_ENABLED | TIMER_OUTPUT_N_CHANNEL const timerHardware_t timerHardware[] = { - { TIM5, IO_TAG(PA3), TIM_CHANNEL_4, 0, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_PPM }, + DEF_TIM(TIM5, CH4, PA3, TIM_USE_PPM, 0, 0), // PPM - { TIM3, IO_TAG(PC6), TIM_CHANNEL_1, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //S1 DMA1_ST4 MT1 - { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S2 DMA2_ST3 SV3 - { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S3 DMA2_ST4 SV4 - { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF3_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //S4 DMA2_ST7 SV5 - { TIM3, IO_TAG(PB1), TIM_CHANNEL_4, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //S5 DMA1_ST2 MT2 - { TIM1, IO_TAG(PA8), TIM_CHANNEL_1, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, //S6 DMA2_ST6 SV6 - { TIM4, IO_TAG(PB8), TIM_CHANNEL_3, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_MC_CHNFW | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, //S7 DMA1_ST7 + DEF_TIM(TIM3, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 DMA1_ST4 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S2 DMA2_ST3 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S3 DMA2_ST2 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4 DMA2_ST7 - //{ TIM5, IO_TAG(PA2), TIM_CHANNEL_3, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_ANY }, + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S5 DMA1_ST2 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6 DMA2_ST6 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_CHNFW | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S7 DMA1_ST7 - { TIM2, IO_TAG(PA15), TIM_CHANNEL_1, TIM_EN, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_LED}, //2812 STRIP DMA1_ST5 + // DEF_TIM(TIM5, CH3, PA2, TIM_USE_ANY, 0, 0), // TX2/S8 DMA1_ST0 + + DEF_TIM(TIM2, CH1, PA15, TIM_USE_LED, 0, 0), // LED STRIP DMA1_ST5 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/MATEKF722/target.h b/src/main/target/MATEKF722/target.h index bcf30f4fbf0..1f53d9c4a07 100755 --- a/src/main/target/MATEKF722/target.h +++ b/src/main/target/MATEKF722/target.h @@ -154,9 +154,6 @@ #define USE_LED_STRIP #define WS2811_PIN PA15 //TIM2_CH1 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST5_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream5 -#define WS2811_DMA_CHANNEL DMA_CHANNEL_3 #define USE_SPEKTRUM_BIND #define BIND_PIN PA3 //USART2_RX diff --git a/src/main/target/MATEKF722/target.mk b/src/main/target/MATEKF722/target.mk index 7af4a300ce8..a9af6d5e6e3 100755 --- a/src/main/target/MATEKF722/target.mk +++ b/src/main/target/MATEKF722/target.mk @@ -13,7 +13,6 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_hal.c \ drivers/max7456.c \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ diff --git a/src/main/target/MOTOLAB/target.c b/src/main/target/MOTOLAB/target.c index 82e228ec175..d6abc0ab093 100644 --- a/src/main/target/MOTOLAB/target.c +++ b/src/main/target/MOTOLAB/target.c @@ -23,16 +23,16 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM3, IO_TAG(PA4), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - PA4 - *TIM3_CH2 - { TIM3, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - PA6 - *TIM3_CH1, TIM8_BKIN, TIM1_BKIN, TIM16_CH1 - { TIM8, IO_TAG(PB0), TIM_Channel_2, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N - { TIM8, IO_TAG(PB1), TIM_Channel_3, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - PA1 - *TIM2_CH2, TIM15_CH1N - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - PA2 - *TIM2_CH3, !TIM15_CH1 - { TIM15, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM7 - PA3 - *TIM15_CH2, TIM2_CH4 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM8 - PA8 - *TIM1_CH1, TIM4_ETR - { TIM17, IO_TAG(PA7), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_PPM }, // PPM - PA7 - *TIM17_CH1, TIM1_CH1N, TIM8_CH1 - { TIM16, IO_TAG(PB8), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_ANY }, + DEF_TIM(TIM3, CH2, PA4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 - PA4 - *TIM3_CH2 + DEF_TIM(TIM3, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 - PA6 - *TIM3_CH1, TIM8_BKIN, TIM1_BKIN, TIM16_CH1 + DEF_TIM(TIM8, CH2N, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N + DEF_TIM(TIM8, CH3N, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 - PA1 - *TIM2_CH2, TIM15_CH1N + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM6 - PA2 - *TIM2_CH3, !TIM15_CH1 + DEF_TIM(TIM15, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM7 - PA3 - *TIM15_CH2, TIM2_CH4 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM8 - PA8 - *TIM1_CH1, TIM4_ETR + DEF_TIM(TIM17, CH1, PA7, TIM_USE_PPM, 0), // PPM - PA7 - *TIM17_CH1, TIM1_CH1N, TIM8_CH1 + DEF_TIM(TIM16, CH1, PB8, TIM_USE_LED, 0), // LED - PB8 - *TIM16_CH1, TIM4_CH3, TIM8_CH2 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/MOTOLAB/target.h b/src/main/target/MOTOLAB/target.h index 3ab28a06606..278bd9654dc 100644 --- a/src/main/target/MOTOLAB/target.h +++ b/src/main/target/MOTOLAB/target.h @@ -102,11 +102,6 @@ #define USE_LED_STRIP_ON_DMA1_CHANNEL3 #define WS2811_PIN PB8 // TIM16_CH1 -#define WS2811_TIMER TIM16 -#define WS2811_DMA_STREAM DMA1_Channel3 -#define WS2811_IRQ DMA1_Channel3_IRQn -#define WS2811_DMA_TC_FLAG DMA1_FLAG_TC3 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH3_HANDLER #define USE_SPEKTRUM_BIND diff --git a/src/main/target/MOTOLAB/target.mk b/src/main/target/MOTOLAB/target.mk index 2108fd450e1..e9d744c1420 100644 --- a/src/main/target/MOTOLAB/target.mk +++ b/src/main/target/MOTOLAB/target.mk @@ -13,6 +13,5 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_softserial.c diff --git a/src/main/target/OMNIBUS/target.c b/src/main/target/OMNIBUS/target.c index 2af6170fc34..acddb3ca638 100644 --- a/src/main/target/OMNIBUS/target.c +++ b/src/main/target/OMNIBUS/target.c @@ -24,20 +24,22 @@ const timerHardware_t timerHardware[] = { // PWM1 PPM Pad - { TIM3, IO_TAG(PB4), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PPM }, // Pin PPM - PB4 + DEF_TIM(TIM3, CH1, PB4, TIM_USE_PPM, 0), // PPM - PB4 + // PB5 / TIM3 CH2 is connected to USBPresent // PWM2-PWM5 - { TIM8, IO_TAG(PB8), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR },// Pin PWM1 - PB8 - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // Pin PWM2 - PB9 - { TIM15, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // Pin PWM3 - PA3 - { TIM15, IO_TAG(PA2), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // Pin PWM4 - PA2 + DEF_TIM(TIM8, CH2, PB8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0), // PWM1 - PB8 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 - PB9 + DEF_TIM(TIM15, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PA3 + DEF_TIM(TIM15, CH1, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PA2 + // For iNav, PWM6&7 (PWM pins 5&6) are shared with UART3 - { TIM2, IO_TAG(PB10), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // Pin PWM5 - PB10 - TIM2_CH3 / UART3_TX (AF7) - { TIM2, IO_TAG(PB11), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // Pin PWM6 - PB11 - TIM2_CH4 / UART3_RX (AF7) + DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PA2 + DEF_TIM(TIM2, CH4, PB11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PA2 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_LED }, + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/OMNIBUS/target.h b/src/main/target/OMNIBUS/target.h index 4065b5ebfaf..6d23bec592f 100644 --- a/src/main/target/OMNIBUS/target.h +++ b/src/main/target/OMNIBUS/target.h @@ -135,8 +135,6 @@ #define USE_LED_STRIP #define WS2811_PIN PA8 -#define WS2811_DMA_STREAM DMA1_Channel2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER //#define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/OMNIBUS/target.mk b/src/main/target/OMNIBUS/target.mk index 242885cc355..455590cc16b 100644 --- a/src/main/target/OMNIBUS/target.mk +++ b/src/main/target/OMNIBUS/target.mk @@ -17,6 +17,5 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_usb_vcp.c \ drivers/max7456.c diff --git a/src/main/target/OMNIBUSF4/target.c b/src/main/target/OMNIBUSF4/target.c index 6d97277868b..af511885f9c 100644 --- a/src/main/target/OMNIBUSF4/target.c +++ b/src/main/target/OMNIBUSF4/target.c @@ -25,27 +25,30 @@ const timerHardware_t timerHardware[] = { #if defined(OMNIBUSF4PRO) || defined(OMNIBUSF4V3) - { TIM10, IO_TAG(PB8), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM10, TIM_USE_PPM }, // PPM - { TIM4, IO_TAG(PB9), TIM_Channel_4, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_ANY }, // S2_IN + DEF_TIM(TIM10, CH1, PB8, TIM_USE_PPM, 0, 0), // PPM + DEF_TIM(TIM4, CH4, PB9, TIM_USE_ANY, 0, 0), // S2_IN #else - { TIM12, IO_TAG(PB14), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_PPM }, // PPM / S.BUS input, above MOTOR1 - { TIM12, IO_TAG(PB15), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_ANY }, // Connected: small CH2 pad, not used as PWM, definition inherited from REVO target - GPIO_PartialRemap_TIM3 + DEF_TIM(TIM12, CH1, PB14, TIM_USE_PPM, 0, 0), // PPM + DEF_TIM(TIM12, CH2, PB15, TIM_USE_ANY, 0, 0), // S2_IN #endif - { TIM8, IO_TAG(PC6), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_ANY }, // Connected: UART6 TX, not used as PWM, definition inherited from REVO target - { TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_ANY }, // Connected: UART6 RX, not used as PWM, definition inherited from REVO target - { TIM8, IO_TAG(PC8), TIM_Channel_3, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_ANY }, // Connected: small CH5 pad, not used as PWM, definition inherited from REVO target - { TIM8, IO_TAG(PC9), TIM_Channel_4, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_ANY }, // Connected: small CH6 pad, not used as PWM, definition inherited from REVO target - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_1 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // MOTOR_2 - { TIM9, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_3 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_4 + DEF_TIM(TIM8, CH1, PC6, TIM_USE_ANY, 0, 0), // S3_IN, UART6_TX + DEF_TIM(TIM8, CH2, PC7, TIM_USE_ANY, 0, 0), // S4_IN, UART6_RX + DEF_TIM(TIM8, CH3, PC8, TIM_USE_ANY, 0, 0), // S5_IN + DEF_TIM(TIM8, CH4, PC9, TIM_USE_ANY, 0, 0), // S6_IN + + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1_OUT D1_ST7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2_OUT D1_ST2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S3_OUT D1_ST6 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT D1_ST1 + + // { TIM9, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // MOTOR_3 #if (defined(OMNIBUSF4PRO) || defined(OMNIBUSF4V3)) && !defined(OMNIBUSF4PRO_LEDSTRIPM5) - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // MOTOR_5 - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_LED }, // LED strip for F4 V2 / F4-Pro-0X and later + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S5_OUT + DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // LED strip for F4 V2 / F4-Pro-0X and later (RCD_CS for F4) #else - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // MOTOR_5 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S5_OUT #endif - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // MOTOR_6 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6_OUT }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/OMNIBUSF4/target.h b/src/main/target/OMNIBUSF4/target.h index dd420f158ec..c005a66abcc 100644 --- a/src/main/target/OMNIBUSF4/target.h +++ b/src/main/target/OMNIBUSF4/target.h @@ -230,15 +230,9 @@ #define USE_LED_STRIP #if (defined(OMNIBUSF4PRO) || defined(OMNIBUSF4V3)) && !defined(OMNIBUSF4PRO_LEDSTRIPM5) -# define WS2811_PIN PB6 -# define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST0_HANDLER -# define WS2811_DMA_STREAM DMA1_Stream0 -# define WS2811_DMA_CHANNEL DMA_Channel_2 +# define WS2811_PIN PB6 #else -# define WS2811_PIN PA1 -# define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST4_HANDLER -# define WS2811_DMA_STREAM DMA1_Stream4 -# define WS2811_DMA_CHANNEL DMA_Channel_6 +# define WS2811_PIN PA1 #endif #define DEFAULT_RX_TYPE RX_TYPE_PPM diff --git a/src/main/target/OMNIBUSF4/target.mk b/src/main/target/OMNIBUSF4/target.mk index e89dfcf8f38..fd9f4af5e8f 100644 --- a/src/main/target/OMNIBUSF4/target.mk +++ b/src/main/target/OMNIBUSF4/target.mk @@ -16,5 +16,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/OMNIBUSF7/target.c b/src/main/target/OMNIBUSF7/target.c index 0d56fb85ece..3132b03ac68 100644 --- a/src/main/target/OMNIBUSF7/target.c +++ b/src/main/target/OMNIBUSF7/target.c @@ -35,13 +35,15 @@ BUSDEV_REGISTER_SPI( busdev_max7456, DEVHW_MAX7456, MAX7456_SPI_BUS, const timerHardware_t timerHardware[] = { - { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, 0, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_PPM | TIM_USE_PWM }, //PPM Input on UART2 RX - { TIM3, IO_TAG(PB0), TIM_CHANNEL_3, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //Motor 1 - { TIM3, IO_TAG(PB1), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, //Motor 2 - { TIM1, IO_TAG(PE9), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //Motor 3 - { TIM1, IO_TAG(PE11), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, //Motor 4 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_PPM, 0, 0 ), // UART2_RX, joined with PE13 + // DEF_TIM(TIM1, CH3, PE13, TIM_USE_NONE, 0, 0 ), // RC1 / PPM, unusable - // DEF_TIM(TIM4, CH1, PD12, TIM_USE_LED, 1, 0 ), // LED + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // M1 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // M2 + DEF_TIM(TIM1, CH1, PE9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 2 ), // M3 + DEF_TIM(TIM1, CH2, PE11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1 ), // M4 + + DEF_TIM(TIM4, CH1, PD12, TIM_USE_LED, 0, 0 ), // LED }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/OMNIBUSF7/target.h b/src/main/target/OMNIBUSF7/target.h index ecff774e878..0f23ef3bb6f 100644 --- a/src/main/target/OMNIBUSF7/target.h +++ b/src/main/target/OMNIBUSF7/target.h @@ -197,13 +197,6 @@ //Following configuration needs to be reviewed, when LED is enabled, VCP stops to work //Until someone with deeper knowledge od DMA fixes it, LED are disabled in target #define WS2811_PIN PD12 -#define WS2811_TIMER TIM4 -#define WS2811_TIMER_CHANNEL TIM_CHANNEL_1 -#define WS2811_DMA_HANDLER_IDENTIFER DMA2_ST4_HANDLER -#define WS2811_DMA_STREAM DMA2_Stream4 -#define WS2811_DMA_IT DMA_IT_TCIF2 -#define WS2811_DMA_CHANNEL DMA_CHANNEL_6 -#define WS2811_TIMER_GPIO_AF GPIO_AF2_TIM4 #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/OMNIBUSF7/target.mk b/src/main/target/OMNIBUSF7/target.mk index 2aedbd6fc54..1fc43f1f964 100644 --- a/src/main/target/OMNIBUSF7/target.mk +++ b/src/main/target/OMNIBUSF7/target.mk @@ -15,6 +15,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_hal.c \ - drivers/max7456.c - + drivers/max7456.c \ No newline at end of file diff --git a/src/main/target/OMNIBUSF7NXT/target.c b/src/main/target/OMNIBUSF7NXT/target.c index e3f725b0b4a..92fce68aaff 100644 --- a/src/main/target/OMNIBUSF7NXT/target.c +++ b/src/main/target/OMNIBUSF7NXT/target.c @@ -30,45 +30,26 @@ #include "drivers/timer.h" #include "drivers/bus.h" -#define DEF_TIM_CHNL_CH1 TIM_CHANNEL_1 -#define DEF_TIM_CHNL_CH2 TIM_CHANNEL_2 -#define DEF_TIM_CHNL_CH3 TIM_CHANNEL_3 -#define DEF_TIM_CHNL_CH4 TIM_CHANNEL_4 - -#define GPIO_AF_PA9_TIM1 GPIO_AF1_TIM1 -#define GPIO_AF_PB0_TIM3 GPIO_AF2_TIM3 -#define GPIO_AF_PB1_TIM3 GPIO_AF2_TIM3 -#define GPIO_AF_PB4_TIM3 GPIO_AF2_TIM3 -#define GPIO_AF_PB5_TIM3 GPIO_AF2_TIM3 -#define GPIO_AF_PB6_TIM4 GPIO_AF2_TIM4 -#define GPIO_AF_PC8_TIM8 GPIO_AF3_TIM8 -#define GPIO_AF_PC9_TIM8 GPIO_AF3_TIM8 - -#define DEF_TIM(_tim, _ch, _pin, _usage, _flags) \ - { _tim, IO_TAG(_pin), DEF_TIM_CHNL_##_ch, _flags, IOCFG_AF_PP, GPIO_AF_##_pin##_##_tim, _usage } - // Board hardware definitions BUSDEV_REGISTER_SPI_TAG(busdev_mpu6000, DEVHW_MPU6000, MPU6000_SPI_BUS, MPU6000_CS_PIN, NONE, 0, DEVFLAGS_NONE); BUSDEV_REGISTER_SPI_TAG(busdev_mpu6500, DEVHW_MPU6500, MPU6500_SPI_BUS, MPU6500_CS_PIN, NONE, 1, DEVFLAGS_NONE); -//BUSDEV_REGISTER_SPI(busdev_lps25h, DEVHW_LPS25H, LPS25H_SPI_BUS, LPS25H_CS_PIN, NONE, DEVFLAGS_NONE); - const timerHardware_t timerHardware[] = { // DEF_TIM(TIM10, CH1, PB8, TIM_USE_PPM, 0), // PPM // OUTPUT 1-4 - DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), - DEF_TIM(TIM3, CH1, PB4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), - DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), - DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1), + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), + DEF_TIM(TIM3, CH1, PB4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 1, 0), // OUTPUT 5-6 - DEF_TIM(TIM8, CH3, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1), - DEF_TIM(TIM8, CH4, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1), + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 1, 0), // AUXILARY pins - DEF_TIM(TIM1, CH2, PA9, TIM_USE_LED, 1), // LED - DEF_TIM(TIM4, CH1, PB6, TIM_USE_ANY, 0) // SS1 TX + DEF_TIM(TIM1, CH2, PA9, TIM_USE_LED, 1, 0), // LED + DEF_TIM(TIM4, CH1, PB6, TIM_USE_ANY, 0, 0) // SS1 TX }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/OMNIBUSF7NXT/target.h b/src/main/target/OMNIBUSF7NXT/target.h index bf0798adaa2..a9dc454b45e 100644 --- a/src/main/target/OMNIBUSF7NXT/target.h +++ b/src/main/target/OMNIBUSF7NXT/target.h @@ -161,9 +161,6 @@ #define USE_LED_STRIP #define WS2811_PIN PA9 -#define WS2811_DMA_HANDLER_IDENTIFER DMA2_ST2_HANDLER -#define WS2811_DMA_STREAM DMA2_Stream2 -#define WS2811_DMA_CHANNEL DMA_CHANNEL_6 #define DEFAULT_FEATURES (FEATURE_TX_PROF_SEL | FEATURE_BLACKBOX | FEATURE_VBAT | FEATURE_OSD | FEATURE_CURRENT_METER | FEATURE_SOFTSERIAL | FEATURE_TELEMETRY) #define DEFAULT_RX_TYPE RX_TYPE_SERIAL diff --git a/src/main/target/OMNIBUSF7NXT/target.mk b/src/main/target/OMNIBUSF7NXT/target.mk index a8bd54ada9e..0578d34bc2e 100644 --- a/src/main/target/OMNIBUSF7NXT/target.mk +++ b/src/main/target/OMNIBUSF7NXT/target.mk @@ -12,5 +12,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_hal.c \ drivers/max7456.c diff --git a/src/main/target/PIKOBLX/target.c b/src/main/target/PIKOBLX/target.c index 6989507d3e5..42133dfc25f 100644 --- a/src/main/target/PIKOBLX/target.c +++ b/src/main/target/PIKOBLX/target.c @@ -23,16 +23,15 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM3, IO_TAG(PA4), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - PA4 - *TIM3_CH2 - { TIM3, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - PA6 - *TIM3_CH1, TIM8_BKIN, TIM1_BKIN, TIM16_CH1 - { TIM8, IO_TAG(PB0), TIM_Channel_2, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N - { TIM8, IO_TAG(PB1), TIM_Channel_3, 1 | TIMER_OUTPUT_N_CHANNEL, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N - /*{ TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N*/ - /*{ TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N*/ - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - PA1 - *TIM2_CH2, TIM15_CH1N - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - PA2 - *TIM2_CH3, !TIM15_CH1 - { TIM17, IO_TAG(PA7), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PPM }//, // PPM - PA7 - *TIM17_CH1, TIM1_CH1N, TIM8_CH1 - /*{ TIM16, IO_TAG(PB8), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_LED }*/ + DEF_TIM(TIM3, CH2, PA4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), + DEF_TIM(TIM3, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), + DEF_TIM(TIM8, CH2N, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM8, CH3N, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + + DEF_TIM(TIM17, CH1, PA7, TIM_USE_PPM, 0), + DEF_TIM(TIM16, CH1, PB8, TIM_USE_LED, 0), }; diff --git a/src/main/target/PIKOBLX/target.h b/src/main/target/PIKOBLX/target.h index 7a2560ba983..2d167eaeacf 100644 --- a/src/main/target/PIKOBLX/target.h +++ b/src/main/target/PIKOBLX/target.h @@ -77,27 +77,11 @@ #define VBAT_ADC_CHANNEL ADC_CHN_2 #define RSSI_ADC_CHANNEL ADC_CHN_3 -//#define USE_LED_STRIP -#define USE_LED_STRIP_ON_DMA1_CHANNEL3 +#define USE_LED_STRIP #define WS2811_PIN PB8 // TIM16_CH1 -#define WS2811_TIMER TIM16 -#define WS2811_DMA_STREAM DMA1_Channel3 -#define WS2811_IRQ DMA1_Channel3_IRQn -#define WS2811_DMA_TC_FLAG DMA1_FLAG_TC3 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH3_HANDLER - -#define TRANSPONDER -#define TRANSPONDER_GPIO GPIOA -#define TRANSPONDER_GPIO_AHB_PERIPHERAL RCC_AHBPeriph_GPIOA -#define TRANSPONDER_GPIO_AF GPIO_AF_6 -#define TRANSPONDER_PIN GPIO_Pin_8 -#define TRANSPONDER_PIN_SOURCE GPIO_PinSource8 -#define TRANSPONDER_TIMER TIM1 -#define TRANSPONDER_TIMER_APB2_PERIPHERAL RCC_APB2Periph_TIM1 -#define TRANSPONDER_DMA_CHANNEL DMA1_Channel2 -#define TRANSPONDER_IRQ DMA1_Channel2_IRQn -#define TRANSPONDER_DMA_TC_FLAG DMA1_FLAG_TC2 -#define TRANSPONDER_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER + +// #define USE_TRANSPONDER +// #define TRANSPONDER_PIN PA8 #define USE_SPEKTRUM_BIND // USART3, PB11 diff --git a/src/main/target/PIKOBLX/target.mk b/src/main/target/PIKOBLX/target.mk index a3e3ce0c822..d53a4c76d1f 100644 --- a/src/main/target/PIKOBLX/target.mk +++ b/src/main/target/PIKOBLX/target.mk @@ -5,7 +5,6 @@ TARGET_SRC = \ drivers/accgyro/accgyro_mpu.c \ drivers/accgyro/accgyro_mpu6000.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_softserial.c # seth neiman dec06.16 porting inav to PIKO BLX using betaflight target related files from before timer.h/timer_def.h changes diff --git a/src/main/target/PIXRACER/target.c b/src/main/target/PIXRACER/target.c index 3ccb3a4dd29..fcd15cde95d 100755 --- a/src/main/target/PIXRACER/target.c +++ b/src/main/target/PIXRACER/target.c @@ -36,13 +36,15 @@ BUSDEV_REGISTER_I2C_TAG(busdev_mag3110, DEVHW_MAG3110, MAG_I2C_BUS, BUSDEV_REGISTER_SPI_TAG(busdev_hmc5983_spi, DEVHW_HMC5883, MPU9250_SPI_BUS, PE15, NONE, 1, DEVFLAGS_NONE); const timerHardware_t timerHardware[] = { - { TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_PPM }, // PPM shared uart6 pc7 - { TIM1, IO_TAG(PE14), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S1_OUT - { TIM1, IO_TAG(PE13), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S2_OUT - { TIM1, IO_TAG(PE11), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT - { TIM1, IO_TAG(PE9), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT - { TIM4, IO_TAG(PD13), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S5_OUT - { TIM4, IO_TAG(PD14), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S6_OUT + DEF_TIM(TIM3, CH3, PB0, TIM_USE_PPM, 0, 0 ), // PPM shared uart6 pc7 + + DEF_TIM(TIM1, CH4, PE14, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S1_OUT + DEF_TIM(TIM1, CH3, PE13, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S2_OUT + DEF_TIM(TIM1, CH2, PE11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S3_OUT + DEF_TIM(TIM1, CH1, PE9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S4_OUT + + DEF_TIM(TIM4, CH2, PD13, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S5_OUT + DEF_TIM(TIM4, CH3, PD14, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S6_OUT }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/RADIX/target.c b/src/main/target/RADIX/target.c index 7433461eee1..88d6f5aea40 100644 --- a/src/main/target/RADIX/target.c +++ b/src/main/target/RADIX/target.c @@ -25,13 +25,14 @@ /* TIMERS */ const timerHardware_t timerHardware[] = { - { TIM12, IO_TAG(PB14), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_PPM }, - { TIM5, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR }, // S3_OUT - { TIM5, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR }, // S4_OUT - { TIM1, IO_TAG(PA10), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM1, TIM_USE_MC_MOTOR }, // S5_OUT - { TIM2, IO_TAG(PA15), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR }, // S6_OUT - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR }, // S5_OUT - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR }, // S6_OUT + DEF_TIM(TIM12, CH1, PB14, TIM_USE_PPM, 0, 0), // PPM In + DEF_TIM(TIM5, CH3, PA2, TIM_USE_MC_MOTOR, 0, 0), // S1 + DEF_TIM(TIM5, CH4, PA3, TIM_USE_MC_MOTOR, 0, 0), // S2 + DEF_TIM(TIM1, CH3, PA10, TIM_USE_MC_MOTOR, 0, 0), // S3 + DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_MOTOR, 0, 0), // S4 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR, 0, 0), // S5 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR, 0, 0), // S6 + DEF_TIM(TIM11, CH1, PB9, TIM_USE_ANY, 0, 0), // Camera Control }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/RCEXPLORERF3/target.c b/src/main/target/RCEXPLORERF3/target.c index aa997b65fd9..1a0e3596bcc 100644 --- a/src/main/target/RCEXPLORERF3/target.c +++ b/src/main/target/RCEXPLORERF3/target.c @@ -24,13 +24,13 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PA8 - { TIM17, IO_TAG(PA7), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR | TIM_USE_MC_SERVO }, // PWM2 - PA7 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - PB0 - { TIM3, IO_TAG(PA4), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - PA4 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - PB1 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PPM }, // PWM6 - PPM - { TIM16, IO_TAG(PB8), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_ANY } + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PA8 + DEF_TIM(TIM17, CH1, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR | TIM_USE_MC_SERVO, 0), // PWM2 - PA7 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PB0 + DEF_TIM(TIM3, CH2, PA4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 - PA4 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 - PB1 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_PPM, 0), // PWM6 - PPM + DEF_TIM(TIM16, CH1, PB8, TIM_USE_LED, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/RCEXPLORERF3/target.h b/src/main/target/RCEXPLORERF3/target.h index 76a9233c8e9..53cc0371dd0 100644 --- a/src/main/target/RCEXPLORERF3/target.h +++ b/src/main/target/RCEXPLORERF3/target.h @@ -92,10 +92,7 @@ #define RSSI_ADC_CHANNEL ADC_CHN_3 #define USE_LED_STRIP // LED strip configuration using PWM motor output pin 5. -#define USE_LED_STRIP_ON_DMA1_CHANNEL3 #define WS2811_PIN PB8 // TIM16_CH1 -#define WS2811_DMA_STREAM DMA1_Channel3 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH3_HANDLER #define USE_RANGEFINDER #define USE_RANGEFINDER_HCSR04 diff --git a/src/main/target/RCEXPLORERF3/target.mk b/src/main/target/RCEXPLORERF3/target.mk index ddcf6783a3a..e7a04881a54 100644 --- a/src/main/target/RCEXPLORERF3/target.mk +++ b/src/main/target/RCEXPLORERF3/target.mk @@ -14,5 +14,4 @@ TARGET_SRC = \ drivers/display_ug2864hsweg01.c \ drivers/serial_usb_vcp.c \ drivers/flash_m25p16.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c + drivers/light_ws2811strip.c diff --git a/src/main/target/REVO/target.c b/src/main/target/REVO/target.c index aa427710c89..ca8c2e7cef4 100644 --- a/src/main/target/REVO/target.c +++ b/src/main/target/REVO/target.c @@ -20,8 +20,9 @@ #include #include "drivers/io.h" #include "drivers/bus.h" -#include "drivers/pwm_mapping.h" #include "drivers/timer.h" +#include "drivers/timer_def.h" +#include "drivers/pwm_mapping.h" /* GYRO */ BUSDEV_REGISTER_SPI_TAG(busdev_mpu6000, DEVHW_MPU6000, MPU6000_SPI_BUS, MPU6000_CS_PIN, MPU6000_EXTI_PIN, 0, DEVFLAGS_NONE); @@ -38,19 +39,19 @@ BUSDEV_REGISTER_SPI (busdev_m25p16, DEVHW_M25P16, M25P16_SPI_BUS, /* TIMERS */ const timerHardware_t timerHardware[] = { - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT - { TIM9, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_ANY }, // S5_OUT - GPIO_PartialRemap_TIM3 - { TIM5, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // S6_OUT - - { TIM12, IO_TAG(PB14), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_PWM | TIM_USE_PPM }, // PWM1 - PPM (5th pin on FlexiIO port) - { TIM12, IO_TAG(PB15), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM12, TIM_USE_PWM }, // PWM2 - S2_IN - GPIO_PartialRemap_TIM3 - { TIM8, IO_TAG(PC6), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PWM | TIM_USE_FW_SERVO }, // PWM3 - S3_IN - { TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PWM | TIM_USE_FW_SERVO }, // PWM4 - S4_IN - { TIM8, IO_TAG(PC8), TIM_Channel_3, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PWM | TIM_USE_FW_SERVO }, // PWM5 - S5_IN - { TIM8, IO_TAG(PC9), TIM_Channel_4, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_PWM | TIM_USE_FW_SERVO }, // PWM6 - S6_IN + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1_OUT D1_ST7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S2_OUT D1_ST2 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S3_OUT D1_ST6 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4_OUT D1_ST1 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_ANY, 0, 0), // S5_OUT / LED + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6_OUT D1_ST2 + + DEF_TIM(TIM12, CH1, PB14, TIM_USE_PWM | TIM_USE_PPM, 0, 0), // PPM (5th pin on FlexiIO port) + DEF_TIM(TIM12, CH2, PB15, TIM_USE_PWM, 0, 0), // S2_IN + DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM | TIM_USE_FW_SERVO, 0, 0), // S3_IN + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM | TIM_USE_FW_SERVO, 0, 0), // S4_IN + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM | TIM_USE_FW_SERVO, 0, 0), // S5_IN + DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM | TIM_USE_FW_SERVO, 0, 0), // S6_IN }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/REVO/target.h b/src/main/target/REVO/target.h index d0400ac33c1..d2097506c95 100644 --- a/src/main/target/REVO/target.h +++ b/src/main/target/REVO/target.h @@ -105,6 +105,10 @@ #define UART6_RX_PIN PC7 #define UART6_TX_PIN PC6 +// #define USE_SOFTSERIAL1 +// #define SOFTSERIAL_1_RX_PIN PC8 +// #define SOFTSERIAL_1_TX_PIN PC9 + #define SERIAL_PORT_COUNT 4 //VCP, USART1, USART3, USART6 #define USE_SPI @@ -133,11 +137,7 @@ #define SENSORS_SET (SENSOR_ACC|SENSOR_MAG|SENSOR_BARO) #define USE_LED_STRIP -// LED Strip can run off Pin 5 (PA1) of the MOTOR outputs. #define WS2811_PIN PA1 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST4_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream4 -#define WS2811_DMA_CHANNEL DMA_Channel_6 #define ENABLE_BLACKBOX_LOGGING_ON_SPIFLASH_BY_DEFAULT diff --git a/src/main/target/REVO/target.mk b/src/main/target/REVO/target.mk index ca4f1d64e65..1d448f30744 100644 --- a/src/main/target/REVO/target.mk +++ b/src/main/target/REVO/target.mk @@ -13,6 +13,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/pitotmeter_adc.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c - + drivers/light_ws2811strip.c diff --git a/src/main/target/RMDO/target.c b/src/main/target/RMDO/target.c index ca8c94c1f34..59769ba5055 100644 --- a/src/main/target/RMDO/target.c +++ b/src/main/target/RMDO/target.c @@ -23,25 +23,25 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM16, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - PA6 - TIM3_CH1, TIM8_BKIN, TIM1_BKIN, *TIM16_CH1 - { TIM17, IO_TAG(PA7), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - PA7 - TIM3_CH2, *TIM17_CH1, TIM1_CH1N, TIM8_CH1 - { TIM4, IO_TAG(PA11), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PA11 - { TIM4, IO_TAG(PA12), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - PA12 - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - PB8 - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - PB9 - { TIM15, IO_TAG(PA2), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM7 - PA2 - { TIM15, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM8 - PA3 + DEF_TIM(TIM16, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 - PA6 - TIM3_CH1, TIM8_BKIN, TIM1_BKIN, *TIM16_CH1 + DEF_TIM(TIM17, CH1, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 - PA7 - TIM3_CH2, *TIM17_CH1, TIM1_CH1N, TIM8_CH1 + DEF_TIM(TIM4, CH1, PA11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PA11 + DEF_TIM(TIM4, CH2, PA12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PA12 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 - PB8 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM6 - PB9 + DEF_TIM(TIM15, CH1, PA2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM7 - PA2 + DEF_TIM(TIM15, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM8 - PA3 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_LED }, // GPIO_TIMER / LED_STRIP + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0), // GPIO_TIMER / LED_STRIP - { TIM2, IO_TAG(PA0), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM | TIM_USE_PPM }, // RC_CH1 - PA0 - *TIM2_CH1 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // RC_CH2 - PA1 - *TIM2_CH2, TIM15_CH1N - { TIM2, IO_TAG(PB11), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // RC_CH3 - PB11 - *TIM2_CH4, USART3_RX (AF7) - { TIM2, IO_TAG(PB10), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // RC_CH4 - PB10 - *TIM2_CH3, USART3_TX (AF7) - { TIM3, IO_TAG(PB4), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_SERVO }, // RC_CH5 - PB4 - *TIM3_CH1 - { TIM3, IO_TAG(PB5), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_SERVO }, // RC_CH6 - PB5 - *TIM3_CH2 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_SERVO }, // RC_CH7 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N - { TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_SERVO }, // RC_CH8 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N + DEF_TIM(TIM2, CH1, PA0, TIM_USE_PWM | TIM_USE_PPM, 0), // RC_CH1 - PA0 - *TIM2_CH1 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_PWM, 0), // RC_CH2 - PA1 - *TIM2_CH2, TIM15_CH1N + DEF_TIM(TIM2, CH4, PB11, TIM_USE_PWM, 0), // RC_CH3 - PB11 - *TIM2_CH4, UART3_RX (AF7) + DEF_TIM(TIM2, CH3, PB10, TIM_USE_PWM, 0), // RC_CH4 - PB10 - *TIM2_CH3, UART3_TX (AF7) + DEF_TIM(TIM3, CH1, PB4, TIM_USE_PWM, 0), // RC_CH5 - PB4 - *TIM3_CH1 + DEF_TIM(TIM3, CH2, PB5, TIM_USE_PWM, 0), // RC_CH6 - PB5 - *TIM3_CH2 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_PWM, 0), // RC_CH7 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N + DEF_TIM(TIM3, CH4, PB1, TIM_USE_PWM, 0), // RC_CH8 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N }; diff --git a/src/main/target/RMDO/target.h b/src/main/target/RMDO/target.h index a589850ec6a..1e78f6df93b 100644 --- a/src/main/target/RMDO/target.h +++ b/src/main/target/RMDO/target.h @@ -105,8 +105,6 @@ #define USE_LED_STRIP_ON_DMA1_CHANNEL2 #define WS2811_PIN PA8 -#define WS2811_DMA_STREAM DMA1_Channel2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER #undef NAV_MAX_WAYPOINTS #define NAV_MAX_WAYPOINTS 30 diff --git a/src/main/target/RMDO/target.mk b/src/main/target/RMDO/target.mk index 35e6269bac5..ced7c059419 100644 --- a/src/main/target/RMDO/target.mk +++ b/src/main/target/RMDO/target.mk @@ -17,6 +17,5 @@ TARGET_SRC = \ drivers/compass/compass_lis3mdl.c \ drivers/flash_m25p16.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_softserial.c diff --git a/src/main/target/SPARKY/target.c b/src/main/target/SPARKY/target.c index ead259c2445..9a7829f2533 100644 --- a/src/main/target/SPARKY/target.c +++ b/src/main/target/SPARKY/target.c @@ -24,21 +24,21 @@ const timerHardware_t timerHardware[] = { // 6 3-pin headers - { TIM15, IO_TAG(PB15), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, // PWM1 - PB15 - TIM1_CH3N, TIM15_CH1N, *TIM15_CH2 - { TIM15, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, // PWM2 - PB14 - TIM1_CH2N, *TIM15_CH1 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PA8 - *TIM1_CH1, TIM4_ETR - { TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N - { TIM16, IO_TAG(PA6), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO | TIM_USE_LED }, // PWM5 - PA6 - *TIM3_CH1, TIM8_BKIN, TIM1_BKIN, TIM16_CH1 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - PA2 - *TIM2_CH3, !TIM15_CH1 + DEF_TIM(TIM15, CH2, PB15, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0), // PWM1 - PB15 - TIM1_CH3N, TIM15_CH1N, *TIM15_CH2 + DEF_TIM(TIM15, CH1, PB14, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0), // PWM2 - PB14 - TIM1_CH2N, *TIM15_CH1 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PA8 - *TIM1_CH1, TIM4_ETR + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PB0 - *TIM3_CH3, TIM1_CH2N, TIM8_CH2N + DEF_TIM(TIM16, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO | TIM_USE_LED, 0), // PWM5 - PA6 - *TIM3_CH1, TIM8_BKIN, TIM1_BKIN, TIM16_CH1 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM6 - PA2 - *TIM2_CH3, !TIM15_CH1 // PWM7 - PMW10 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM7 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N - { TIM17, IO_TAG(PA7), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM8 - PA7 - !TIM3_CH2, *TIM17_CH1, TIM1_CH1N, TIM8_CH1 - { TIM3, IO_TAG(PA4), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM9 - PA4 - *TIM3_CH2 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM10 - PA1 - *TIM2_CH2, TIM15_CH1N + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM7 - PB1 - *TIM3_CH4, TIM1_CH3N, TIM8_CH3N + DEF_TIM(TIM17, CH1, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM8 - PA7 - !TIM3_CH2, *TIM17_CH1, TIM1_CH1N, TIM8_CH1 + DEF_TIM(TIM3, CH2, PA4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM9 - PA4 - *TIM3_CH2 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM10 - PA1 - *TIM2_CH2, TIM15_CH1N // PPM PORT - Also USART2 RX (AF5) - { TIM2, IO_TAG(PA3), TIM_Channel_4, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_PPM } // PPM - PA3 - TIM2_CH4, TIM15_CH2 - PWM13 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_PPM, 0), // PPM - PA3 - TIM2_CH4, TIM15_CH2 - PWM13 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/SPARKY/target.h b/src/main/target/SPARKY/target.h index ede88c4095d..6b028cb0d6f 100644 --- a/src/main/target/SPARKY/target.h +++ b/src/main/target/SPARKY/target.h @@ -91,8 +91,6 @@ #define USE_LED_STRIP #define USE_LED_STRIP_ON_DMA1_CHANNEL3 #define WS2811_PIN PA6 // TIM16_CH1 -#define WS2811_DMA_STREAM DMA1_Channel3 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH3_HANDLER #define USE_SERIAL_4WAY_BLHELI_INTERFACE diff --git a/src/main/target/SPARKY/target.mk b/src/main/target/SPARKY/target.mk index c8615f89d75..eb23cc1bbd7 100644 --- a/src/main/target/SPARKY/target.mk +++ b/src/main/target/SPARKY/target.mk @@ -14,6 +14,4 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c - + drivers/light_ws2811strip.c diff --git a/src/main/target/SPARKY2/target.c b/src/main/target/SPARKY2/target.c index d78e9c37fa7..1de5d4c598b 100644 --- a/src/main/target/SPARKY2/target.c +++ b/src/main/target/SPARKY2/target.c @@ -24,18 +24,18 @@ #include "drivers/bus.h" const timerHardware_t timerHardware[] = { - { TIM8, IO_TAG(PC7), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_PPM | TIM_USE_PWM}, // PPM IN - { TIM12, IO_TAG(PB14), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_PWM}, // S2_IN - { TIM12, IO_TAG(PB15), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_PWM}, // S3_IN - GPIO_PartialRemap_TIM3 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_PWM}, // S4_IN - { TIM8, IO_TAG(PC9), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_PWM}, // S5_IN + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM | TIM_USE_PPM, 0, 0 ), // PPM IN + DEF_TIM(TIM12, CH1, PB14, TIM_USE_PWM, 0, 0 ), // S2_IN + DEF_TIM(TIM12, CH2, PB15, TIM_USE_PWM, 0, 0 ), // S3_IN - GPIO_PartialRemap_TIM3 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0, 0 ), // S4_IN + DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM, 0, 0 ), // S5_IN - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR}, // S1_OUT - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR}, // S2_OUT - { TIM9, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO}, // S3_OUT - { TIM2, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO}, // S4_OUT - { TIM5, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO}, // S5_OUT - GPIO_PartialRemap_TIM3 - { TIM5, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO}, // S6_OUT + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S1_OUT + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S2_OUT + DEF_TIM(TIM9, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S3_OUT + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S4_OUT + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0 ), // S5_OUT - GPIO_PartialRemap_TIM3 + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0 ), // S6_OUT }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/SPARKY2/target.h b/src/main/target/SPARKY2/target.h index ae771ebe6b9..6ddb0d65fc0 100644 --- a/src/main/target/SPARKY2/target.h +++ b/src/main/target/SPARKY2/target.h @@ -118,8 +118,8 @@ #define VBAT_ADC_CHANNEL ADC_CHN_2 #define CURRENT_METER_ADC_CHANNEL ADC_CHN_1 -#define USE_LED_STRIP -#define LED_STRIP_TIMER TIM5 +// #define USE_LED_STRIP +// #define WS2811_PIN PA1 #define USE_RANGEFINDER #define USE_RANGEFINDER_VL53L0X diff --git a/src/main/target/SPARKY2/target.mk b/src/main/target/SPARKY2/target.mk index dfdc5f99e8d..1487b00b103 100644 --- a/src/main/target/SPARKY2/target.mk +++ b/src/main/target/SPARKY2/target.mk @@ -14,6 +14,4 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c - + drivers/light_ws2811strip.c diff --git a/src/main/target/SPEEDYBEEF4/target.c b/src/main/target/SPEEDYBEEF4/target.c index f050f9a7517..3c5b3162c8a 100644 --- a/src/main/target/SPEEDYBEEF4/target.c +++ b/src/main/target/SPEEDYBEEF4/target.c @@ -24,16 +24,17 @@ #include "drivers/bus.h" const timerHardware_t timerHardware[] = { - { TIM5, IO_TAG(PA3), TIM_Channel_4, 0, IOCFG_AF_PP_UP, GPIO_AF_TIM5, TIM_USE_PPM}, // PPM - { TIM8, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP_UP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1 UP(1,2) - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP_UP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2 UP(2,1) - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_UP, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3 UP(2,1) - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4 UP(2,1) - { TIM2, IO_TAG(PA15), TIM_Channel_1, 1, IOCFG_AF_PP_UP, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO}, //S5 UP(1,7) - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_UP, GPIO_AF_TIM1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO}, // S6 UP(2,5) + DEF_TIM(TIM5, CH4, PA3, TIM_USE_PPM, 0, 0), // PPM - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP_UP, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO}, //S7 UP(1,7) - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP_UP, GPIO_AF_TIM5, TIM_USE_LED}, // S6 UP(2,5) + DEF_TIM(TIM8, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0), // S1 UP(1,2) + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 1), // S2 UP(2,1) + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // S3 UP(2,1) + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // S4 UP(2,1) + DEF_TIM(TIM2, CH1, PA15, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S5 UP(1,7) + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S6 UP(2,5) + + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0), // S7 D(1,7)!S5 UP(2,6) + DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // LED D(1,0) UP(2,6) }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/SPEEDYBEEF4/target.mk b/src/main/target/SPEEDYBEEF4/target.mk index e4d4cb7b6f6..e040a0dbedb 100644 --- a/src/main/target/SPEEDYBEEF4/target.mk +++ b/src/main/target/SPEEDYBEEF4/target.mk @@ -15,5 +15,4 @@ TARGET_SRC = \ drivers/pitotmeter_ms4525.c \ drivers/pitotmeter_adc.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c diff --git a/src/main/target/SPRACINGF3/target.c b/src/main/target/SPRACINGF3/target.c index eefdfc561c3..d5cc9bcd6ae 100644 --- a/src/main/target/SPRACINGF3/target.c +++ b/src/main/target/SPRACINGF3/target.c @@ -21,28 +21,29 @@ #include "drivers/io.h" #include "drivers/pwm_mapping.h" #include "drivers/timer.h" +#include "drivers/timer_def.h" #include "drivers/bus.h" -const timerHardware_t timerHardware[] = { - { TIM16, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - { TIM17, IO_TAG(PA7), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - { TIM4, IO_TAG(PA11), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - { TIM4, IO_TAG(PA12), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - { TIM15, IO_TAG(PA2), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM7 - { TIM15, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM8 +const timerHardware_t timerHardware[] = { + DEF_TIM(TIM16, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 + DEF_TIM(TIM17, CH1, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 + DEF_TIM(TIM4, CH1, PA11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 + DEF_TIM(TIM4, CH2, PA12, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM6 + DEF_TIM(TIM15, CH1, PA2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM7 + DEF_TIM(TIM15, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM8 - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_LED }, // GPIO_TIMER / LED_STRIP + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0), // GPIO_TIMER / LED_STRIP - { TIM2, IO_TAG(PA0), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PPM | TIM_USE_PWM }, // RC_CH1 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM}, // RC_CH2 - { TIM2, IO_TAG(PB11), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // RC_CH3 - { TIM2, IO_TAG(PB10), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // RC_CH4 - { TIM3, IO_TAG(PB4), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_SERVO }, // RC_CH5 - { TIM3, IO_TAG(PB5), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_SERVO }, // RC_CH6 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_SERVO }, // RC_CH7 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PWM | TIM_USE_MC_SERVO }, // RC_CH8 + DEF_TIM(TIM2, CH1, PA0, TIM_USE_PWM | TIM_USE_PPM, 0), // RC_CH1 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_PWM, 0), // RC_CH2 + DEF_TIM(TIM2, CH4, PB11, TIM_USE_PWM, 0), // RC_CH3 + DEF_TIM(TIM2, CH3, PB10, TIM_USE_PWM, 0), // RC_CH4 + DEF_TIM(TIM3, CH1, PB4, TIM_USE_PWM | TIM_USE_MC_SERVO, 0), // RC_CH5 + DEF_TIM(TIM3, CH2, PB5, TIM_USE_PWM | TIM_USE_MC_SERVO, 0), // RC_CH6 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_PWM | TIM_USE_MC_SERVO, 0), // RC_CH7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_PWM | TIM_USE_MC_SERVO, 0), // RC_CH8 }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/SPRACINGF3/target.h b/src/main/target/SPRACINGF3/target.h index 468d716ab22..4717440c16b 100644 --- a/src/main/target/SPRACINGF3/target.h +++ b/src/main/target/SPRACINGF3/target.h @@ -101,8 +101,6 @@ #define USE_LED_STRIP #define WS2811_PIN PA8 -#define WS2811_DMA_STREAM DMA1_Channel2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER #define USE_RANGEFINDER #define USE_RANGEFINDER_HCSR04 diff --git a/src/main/target/SPRACINGF3/target.mk b/src/main/target/SPRACINGF3/target.mk index b2508f0e397..c8549b88c4d 100644 --- a/src/main/target/SPRACINGF3/target.mk +++ b/src/main/target/SPRACINGF3/target.mk @@ -14,5 +14,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_softserial.c diff --git a/src/main/target/SPRACINGF3EVO/target.c b/src/main/target/SPRACINGF3EVO/target.c index 24665c4c252..640a139bf0c 100755 --- a/src/main/target/SPRACINGF3EVO/target.c +++ b/src/main/target/SPRACINGF3EVO/target.c @@ -24,28 +24,29 @@ const timerHardware_t timerHardware[] = { // PPM / UART2 RX - { TIM8, IO_TAG(PA15), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PPM }, // PPM + DEF_TIM(TIM8, CH1, PA15, TIM_USE_PPM, 0), // PPM + + DEF_TIM(TIM2, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 [TIM2_CH1 (D1_CH5)] + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 [TIM2_CH2 (D1_CH7)] [TIM15_CH1N (D1_CH5)] + DEF_TIM(TIM15, CH1, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 [TIM2_CH3 (D1_CH1)] [TIM15_CH1 (D1_CH5)] + DEF_TIM(TIM15, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 [TIM2_CH4 (D1_CH7)] - { TIM2, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - { TIM15, IO_TAG(PA2), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - { TIM15, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 #ifdef SPRACINGF3EVO_1SS - { TIM16, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM5 - PA6 - TIM3_CH1, TIM8_BKIN, TIM1_BKIN, *TIM16_CH1 - { TIM17, IO_TAG(PA7), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM6 - PA7 - TIM3_CH2, *TIM17_CH1, TIM1_CH1N, TIM8_CH1 + DEF_TIM(TIM16, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM5 + DEF_TIM(TIM17, CH1, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM6 #else - { TIM3, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM5 - { TIM3, IO_TAG(PA7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM6 + DEF_TIM(TIM3, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM5 + DEF_TIM(TIM3, CH2, PA7, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM6 #endif - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM7 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM8 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM7 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM8 // UART3 RX/TX - { TIM2, IO_TAG(PB10), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // RC_CH4 - PB10 - *TIM2_CH3, USART3_TX (AF7) - { TIM2, IO_TAG(PB11), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // RC_CH3 - PB11 - *TIM2_CH4, USART3_RX (AF7) + DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // RC_CH4 - PB10 - *TIM2_CH3, UART3_TX (AF7) + DEF_TIM(TIM2, CH4, PB11, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // RC_CH3 - PB11 - *TIM2_CH4, UART3_RX (AF7) // IR / LED Strip Pad - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_LED }, // GPIO_TIMER / LED_STRIP + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0), // LED_STRIP / TRANSPONDER }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/SPRACINGF3EVO/target.h b/src/main/target/SPRACINGF3EVO/target.h index 031d42aec8e..4e81674d930 100755 --- a/src/main/target/SPRACINGF3EVO/target.h +++ b/src/main/target/SPRACINGF3EVO/target.h @@ -130,10 +130,7 @@ #define RSSI_ADC_CHANNEL ADC_CHN_3 #define USE_LED_STRIP -#define USE_LED_STRIP_ON_DMA1_CHANNEL2 #define WS2811_PIN PA8 -#define WS2811_DMA_STREAM DMA1_Channel2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER #define USE_RANGEFINDER #define RANGEFINDER_I2C_BUS BUS_I2C1 diff --git a/src/main/target/SPRACINGF3EVO/target.mk b/src/main/target/SPRACINGF3EVO/target.mk index 3ebfe9a6b05..bc26cae3272 100755 --- a/src/main/target/SPRACINGF3EVO/target.mk +++ b/src/main/target/SPRACINGF3EVO/target.mk @@ -15,6 +15,5 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_usb_vcp.c \ drivers/serial_softserial.c diff --git a/src/main/target/SPRACINGF3MINI/target.c b/src/main/target/SPRACINGF3MINI/target.c index 5b88b0c3265..acf31a0384e 100644 --- a/src/main/target/SPRACINGF3MINI/target.c +++ b/src/main/target/SPRACINGF3MINI/target.c @@ -25,28 +25,28 @@ const timerHardware_t timerHardware[] = { // PPM Pad #ifdef SPRACINGF3MINI_MKII_REVA - { TIM3, IO_TAG(PB5), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PPM }, // PPM - PB5 + DEF_TIM(TIM3, CH2, PB5, TIM_USE_PPM, 0), // PPM - PB5 // PB4 / TIM3 CH1 is connected to USBPresent #else - { TIM3, IO_TAG(PB4), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_PPM }, // PPM - PB4 + DEF_TIM(TIM3, CH1, PB4, TIM_USE_PPM, 0), // PPM - PB4 // PB5 / TIM3 CH2 is connected to USBPresent #endif - { TIM16, IO_TAG(PA6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM1 - PA6 - { TIM17, IO_TAG(PA7), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM2 - PA7 - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM3 - PB8 - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM4 - PB9 - { TIM15, IO_TAG(PA2), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM5 - PA2 - { TIM15, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM6 - PA3 - { TIM2, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM7 - PA0 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM8 - PA1 + DEF_TIM(TIM16, CH1, PA6, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM1 - PA6 + DEF_TIM(TIM17, CH1, PA7, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // PWM2 - PA7 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM3 - PB8 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // PWM4 - PB9 + DEF_TIM(TIM15, CH1, PA2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM5 - PA2 + DEF_TIM(TIM15, CH2, PA3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM6 - PA3 + DEF_TIM(TIM2, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM7 - PA0 + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM8 - PA1 // UART3 RX/TX - { TIM2, IO_TAG(PB10), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM9 - PB10 - TIM2_CH3 / UART3_TX (AF7) - { TIM2, IO_TAG(PB11), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM10 - PB11 - TIM2_CH4 / UART3_RX (AF7) + DEF_TIM(TIM2, CH3, PB10, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM9 - PB10 - TIM2_CH3 / UART3_TX (AF7) + DEF_TIM(TIM2, CH4, PB11, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), // PWM10 - PB11 - TIM2_CH4 / UART3_RX (AF7) // LED Strip Pad - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_LED }, // GPIO_TIMER / LED_STRIP + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0), // LED_STRIP / TRANSPONDER }; diff --git a/src/main/target/SPRACINGF3MINI/target.h b/src/main/target/SPRACINGF3MINI/target.h index e6ac0b50b4a..07c50d56f44 100644 --- a/src/main/target/SPRACINGF3MINI/target.h +++ b/src/main/target/SPRACINGF3MINI/target.h @@ -130,8 +130,6 @@ #define USE_LED_STRIP #define WS2811_PIN PA8 -#define WS2811_DMA_STREAM DMA1_Channel2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER #define TRANSPONDER #define TRANSPONDER_GPIO GPIOA diff --git a/src/main/target/SPRACINGF3MINI/target.mk b/src/main/target/SPRACINGF3MINI/target.mk index f33eee9011f..aa9a87bdd19 100644 --- a/src/main/target/SPRACINGF3MINI/target.mk +++ b/src/main/target/SPRACINGF3MINI/target.mk @@ -15,7 +15,6 @@ TARGET_SRC = \ drivers/compass/compass_lis3mdl.c \ drivers/flash_m25p16.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/serial_softserial.c \ drivers/serial_usb_vcp.c \ drivers/rangefinder/rangefinder_hcsr04.c \ diff --git a/src/main/target/SPRACINGF3NEO/target.c b/src/main/target/SPRACINGF3NEO/target.c index 6b2a2a4d75e..6a932ead1bc 100755 --- a/src/main/target/SPRACINGF3NEO/target.c +++ b/src/main/target/SPRACINGF3NEO/target.c @@ -24,24 +24,23 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM15, IO_TAG(PA3), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_PWM | TIM_USE_PPM }, // PWM1 / PPM / UART2 RX - { TIM15, IO_TAG(PA2), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_9, TIM_USE_PWM }, // PWM2 + DEF_TIM(TIM15, CH2, PA3, TIM_USE_PWM | TIM_USE_PPM, 0), // PWM1 / PPM / UART2 RX + DEF_TIM(TIM15, CH1, PA2, TIM_USE_PWM, 0), // PWM2 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // ESC1 - { TIM3, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // ESC2 - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // ESC3 - { TIM3, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // ESC4 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // ESC1 + DEF_TIM(TIM3, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // ESC2 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // ESC3 + DEF_TIM(TIM3, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), // ESC4 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // ESC5 (FW motor) - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_4, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // ESC6 (FW motor) + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // ESC5 (FW motor) + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), // ESC6 (FW motor) - { TIM2, IO_TAG(PB10), TIM_Channel_3, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // PWM3 - PB10 - *TIM2_CH3, UART3_TX (AF7) - { TIM2, IO_TAG(PB11), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_PWM }, // PWM4 - PB11 - *TIM2_CH4, UART3_RX (AF7) - // with DSHOT DMA1-CH3 conflicts with TIM3_CH4 / ESC1. - //{ TIM16, IO_TAG(PB8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_1 }, // What's PB8 ??? + DEF_TIM(TIM2, CH3, PB10, TIM_USE_PWM, 0), // PWM3 - PB10 - *TIM2_CH3, UART3_TX (AF7) + DEF_TIM(TIM2, CH4, PB11, TIM_USE_PWM, 0), // PWM4 - PB11 - *TIM2_CH4, UART3_RX (AF7) - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_6, TIM_USE_LED } + DEF_TIM(TIM16, CH1, PB8, TIM_USE_ANY, 0), + DEF_TIM(TIM1, CH1, PA8, TIM_USE_LED, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/SPRACINGF3NEO/target.h b/src/main/target/SPRACINGF3NEO/target.h index cd8c8410cfe..dd165d275f3 100755 --- a/src/main/target/SPRACINGF3NEO/target.h +++ b/src/main/target/SPRACINGF3NEO/target.h @@ -20,8 +20,6 @@ #define TARGET_BOARD_IDENTIFIER "SP3N" #define TARGET_CONFIG -#define CONFIG_FASTLOOP_PREFERRED_ACC ACC_DEFAULT - #define LED0 PB9 #define LED1 PB2 @@ -87,9 +85,6 @@ #define UART3_TX_PIN PB10 #define UART3_RX_PIN PB11 -#define USE_ESCSERIAL -#define ESCSERIAL_TIMER_TX_HARDWARE 0 // PWM 1 - #define USE_I2C #define USE_I2C_DEVICE_1 @@ -156,8 +151,6 @@ #define USE_LED_STRIP #define WS2811_PIN PA8 -#define WS2811_DMA_STREAM DMA1_Channel2 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH2_HANDLER #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/SPRACINGF3NEO/target.mk b/src/main/target/SPRACINGF3NEO/target.mk_ old mode 100755 new mode 100644 similarity index 93% rename from src/main/target/SPRACINGF3NEO/target.mk rename to src/main/target/SPRACINGF3NEO/target.mk_ index 5d73c98f896..4e1c1016b8f --- a/src/main/target/SPRACINGF3NEO/target.mk +++ b/src/main/target/SPRACINGF3NEO/target.mk_ @@ -15,6 +15,5 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/max7456.c \ drivers/vtx_rtc6705.c diff --git a/src/main/target/SPRACINGF4EVO/target.c b/src/main/target/SPRACINGF4EVO/target.c index 89b5ff0dd9b..aebbb346984 100755 --- a/src/main/target/SPRACINGF4EVO/target.c +++ b/src/main/target/SPRACINGF4EVO/target.c @@ -23,26 +23,26 @@ const timerHardware_t timerHardware[] = { - { TIM9, IO_TAG(PA3), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM9, TIM_USE_PPM | TIM_USE_PWM }, // PPM - { TIM9, IO_TAG(PA2), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_TIM9, TIM_USE_PWM }, + DEF_TIM(TIM9, CH2, PA3, TIM_USE_PPM | TIM_USE_PWM, 0, 0), // PPM / PWM1 / UART2 RX + DEF_TIM(TIM9, CH1, PA2, TIM_USE_PWM, 0, 0), // PPM / PWM2 / UART2 TX - { TIM8, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM8, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, + DEF_TIM(TIM8, CH1, PC6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // ESC 1 + DEF_TIM(TIM8, CH2, PC7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // ESC 2 + DEF_TIM(TIM8, CH4, PC9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // ESC 3 + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1), // ESC 4 #if defined(SPRACINGF4EVO_REV) && (SPRACINGF4EVO_REV >= 2) - { TIM4, IO_TAG(PB6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM4, IO_TAG(PB7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, + DEF_TIM(TIM4, CH1, PB6, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // ESC 5 / Conflicts with USART5_RX / SPI3_RX - SPI3_RX can be mapped to DMA1_ST3_CH0 + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // ESC 6 / Conflicts with USART3_RX #else - { TIM4, IO_TAG(PB8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM4, IO_TAG(PB9), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, + DEF_TIM(TIM10, CH1, PB8, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // ESC 5 + DEF_TIM(TIM11, CH1, PB9, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0), // ESC 6 #endif - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR }, + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0, 0), // ESC 7 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_MOTOR, 0, 0), // ESC 8 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_ANY }, + DEF_TIM(TIM2, CH2, PA1, TIM_USE_LED, 0, 0), // LED Strip }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/SPRACINGF4EVO/target.h b/src/main/target/SPRACINGF4EVO/target.h index 6030c1acb2a..0cd522515a9 100755 --- a/src/main/target/SPRACINGF4EVO/target.h +++ b/src/main/target/SPRACINGF4EVO/target.h @@ -166,9 +166,6 @@ #define USE_LED_STRIP #define WS2811_PIN PA1 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST6_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream6 -#define WS2811_DMA_CHANNEL DMA_Channel_3 // ??? #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/SPRACINGF4EVO/target.mk b/src/main/target/SPRACINGF4EVO/target.mk index 8c6d1ac05f2..179fd78bc76 100755 --- a/src/main/target/SPRACINGF4EVO/target.mk +++ b/src/main/target/SPRACINGF4EVO/target.mk @@ -13,7 +13,6 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/compass/compass_lis3mdl.c \ drivers/barometer/barometer_ms56xx.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/light_ws2811strip.c \ drivers/max7456.c # drivers/vtx_rtc6705.c diff --git a/src/main/target/STM32F3DISCOVERY/target.c b/src/main/target/STM32F3DISCOVERY/target.c index d34236157a1..66450827ff9 100644 --- a/src/main/target/STM32F3DISCOVERY/target.c +++ b/src/main/target/STM32F3DISCOVERY/target.c @@ -23,20 +23,20 @@ #include "drivers/timer.h" const timerHardware_t timerHardware[] = { - { TIM1, IO_TAG(PA8), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_6, TIM_USE_PWM | TIM_USE_PPM }, // PWM1 - PA8 - { TIM16, IO_TAG(PB8), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_PWM | TIM_USE_LED }, // PWM2 - PB8 - { TIM17, IO_TAG(PB9), TIM_Channel_1, 0, IOCFG_AF_PP_PD, GPIO_AF_1, TIM_USE_PWM }, // PWM3 - PB9 - { TIM8, IO_TAG(PC6), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_4, TIM_USE_PWM }, // PWM4 - PC6 - { TIM8, IO_TAG(PC7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_4, TIM_USE_PWM }, // PWM5 - PC7 - { TIM8, IO_TAG(PC8), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_4, TIM_USE_PWM }, // PWM6 - PC8 - { TIM3, IO_TAG(PB1), TIM_Channel_4, 0, IOCFG_AF_PP_PD, GPIO_AF_2, TIM_USE_PWM }, // PWM7 - PB1 - { TIM3, IO_TAG(PA4), TIM_Channel_2, 0, IOCFG_AF_PP_PD, GPIO_AF_2, TIM_USE_PWM }, // PWM8 - PA2 - { TIM4, IO_TAG(PD12), TIM_Channel_1, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM9 - PD12 - { TIM4, IO_TAG(PD13), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // PWM10 - PD13 - { TIM4, IO_TAG(PD14), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM11 - PD14 - { TIM4, IO_TAG(PD15), TIM_Channel_4, 0, IOCFG_AF_PP, GPIO_AF_2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // PWM12 - PD15 - { TIM2, IO_TAG(PA1), TIM_Channel_2, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // PWM13 - PA1 - { TIM2, IO_TAG(PA2), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO } // PWM14 - PA2 + DEF_TIM(TIM1, CH1, PA8, TIM_USE_PWM | TIM_USE_PPM, 0), + DEF_TIM(TIM16, CH1, PB8, TIM_USE_PWM | TIM_USE_LED, 0), + DEF_TIM(TIM17, CH1, PB9, TIM_USE_PWM, 0), + DEF_TIM(TIM8, CH1, PC6, TIM_USE_PWM, 0), + DEF_TIM(TIM8, CH2, PC7, TIM_USE_PWM, 0), + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0), + DEF_TIM(TIM3, CH4, PB1, TIM_USE_PWM, 0), + DEF_TIM(TIM3, CH2, PA4, TIM_USE_PWM, 0), + DEF_TIM(TIM4, CH1, PD12, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), + DEF_TIM(TIM4, CH2, PD13, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0), + DEF_TIM(TIM4, CH3, PD14, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM4, CH4, PD15, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM2, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0), }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/STM32F3DISCOVERY/target.h b/src/main/target/STM32F3DISCOVERY/target.h index b476c4c21a7..c0d97b45006 100644 --- a/src/main/target/STM32F3DISCOVERY/target.h +++ b/src/main/target/STM32F3DISCOVERY/target.h @@ -135,9 +135,6 @@ #define USE_LED_STRIP #define WS2811_PIN PB8 // TIM16_CH1 -#define WS2811_TIMER TIM16 -#define WS2811_DMA_STREAM DMA1_Channel3 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_CH3_HANDLER #define USE_SPEKTRUM_BIND #define BIND_PIN PA3 // USART2, PA3 diff --git a/src/main/target/STM32F3DISCOVERY/target.mk b/src/main/target/STM32F3DISCOVERY/target.mk index 1db7bb0536c..03ebd7c0c72 100644 --- a/src/main/target/STM32F3DISCOVERY/target.mk +++ b/src/main/target/STM32F3DISCOVERY/target.mk @@ -30,6 +30,5 @@ TARGET_SRC = \ drivers/compass/compass_ist8308.c \ drivers/flash_m25p16.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c \ drivers/pitotmeter_ms4525.c diff --git a/src/main/target/YUPIF4/target.c b/src/main/target/YUPIF4/target.c index 3b49e281d12..81385400cdc 100644 --- a/src/main/target/YUPIF4/target.c +++ b/src/main/target/YUPIF4/target.c @@ -24,21 +24,23 @@ #include "drivers/bus.h" const timerHardware_t timerHardware[] = { - { TIM8, IO_TAG(PC8), TIM_Channel_3, 0, IOCFG_AF_PP, GPIO_AF_TIM8, TIM_USE_PPM }, - { TIM2, IO_TAG(PA0), TIM_Channel_1, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, - { TIM2, IO_TAG(PA1), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, - { TIM5, IO_TAG(PA2), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM5, IO_TAG(PA3), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, - { TIM3, IO_TAG(PB0), TIM_Channel_3, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PPM, 0, 0 ), // PPM IN + + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S1_OUT - DMA1_ST2 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S2_OUT - DMA1_ST4 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S3_OUT - DMA1_ST1 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1 ), // S4_OUT - DMA1_ST6 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0 ), // S5_OUT - DMA1_ST7 + #if defined (YUPIF4R2) - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_LED }, - { TIM12, IO_TAG(PB14), TIM_Channel_1, 1, IOCFG_AF_PP, GPIO_AF_TIM12, TIM_USE_BEEPER }, + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_LED, 0, 0 ), + DEF_TIM(TIM12, CH1, PB14, TIM_USE_BEEPER, 0, 0 ), // BEEPER PWM OPT #elif (YUPIF4MINI) - { TIM4, IO_TAG(PB7), TIM_Channel_2, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM4, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, - { TIM3, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_BEEPER }, + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0 ), + DEF_TIM(TIM3, CH4, PC9, TIM_USE_BEEPER, 0, 0 ), // BEEPER PWM #else - { TIM3, IO_TAG(PB1), TIM_Channel_4, 1, IOCFG_AF_PP_PD, GPIO_AF_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_LED }, - { TIM3, IO_TAG(PC9), TIM_Channel_4, 1, IOCFG_AF_PP, GPIO_AF_TIM3, TIM_USE_BEEPER }, + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_LED, 0, 0 ), + DEF_TIM(TIM3, CH4, PC9, TIM_USE_BEEPER, 0, 0 ), // BEEPER PWM #endif }; diff --git a/src/main/target/YUPIF4/target.h b/src/main/target/YUPIF4/target.h index a8b5db4f606..631f6692f51 100644 --- a/src/main/target/YUPIF4/target.h +++ b/src/main/target/YUPIF4/target.h @@ -155,10 +155,6 @@ // LED Strip can run off Pin 5 (PB1) of the motor outputs #define USE_LED_STRIP #define WS2811_PIN PB1 -#define WS2811_TIMER TIM8 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST2_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream2 -#define WS2811_DMA_CHANNEL DMA_Channel_5 // Features // #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/YUPIF4/target.mk b/src/main/target/YUPIF4/target.mk index 6a8de1be2a4..d1329a43f80 100644 --- a/src/main/target/YUPIF4/target.mk +++ b/src/main/target/YUPIF4/target.mk @@ -12,5 +12,4 @@ TARGET_SRC = \ drivers/compass/compass_ist8310.c \ drivers/compass/compass_mag3110.c \ drivers/max7456.c \ - drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_stdperiph.c + drivers/light_ws2811strip.c diff --git a/src/main/target/YUPIF7/target.c b/src/main/target/YUPIF7/target.c index e58c8dbe48a..c01c2c41bae 100644 --- a/src/main/target/YUPIF7/target.c +++ b/src/main/target/YUPIF7/target.c @@ -24,15 +24,15 @@ #include "drivers/bus.h" const timerHardware_t timerHardware[] = { - { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, 0, IOCFG_AF_PP, GPIO_AF3_TIM8, TIM_USE_PPM }, // PPM IN - { TIM2, IO_TAG(PA0), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S1_OUT - { TIM5, IO_TAG(PA1), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM5, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR }, // S2_OUT - { TIM2, IO_TAG(PA2), TIM_CHANNEL_3, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S3_OUT - { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF1_TIM2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO }, // S4_OUT - { TIM3, IO_TAG(PB0), TIM_CHANNEL_3, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO }, // S5_OUT - { TIM3, IO_TAG(PB1), TIM_CHANNEL_4, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM3, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_LED }, // S6_OUT - { TIM2, IO_TAG(PB7), TIM_CHANNEL_2, 1, IOCFG_AF_PP_PD, GPIO_AF2_TIM4, TIM_USE_ANY }, // ANY - { TIM12, IO_TAG(PB14), TIM_CHANNEL_1, 1, IOCFG_AF_PP_PD, GPIO_AF9_TIM12, TIM_USE_BEEPER }, // BEEPER PWM + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PPM, 0, 1 ), // PPM IN + DEF_TIM(TIM2, CH1, PA0, TIM_USE_MC_MOTOR | TIM_USE_FW_MOTOR, 0, 0 ), // S1_OUT - DMA1_ST2 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S2_OUT - DMA1_ST4 + DEF_TIM(TIM5, CH3, PA2, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 0 ), // S3_OUT - DMA1_ST1 + DEF_TIM(TIM5, CH4, PA3, TIM_USE_MC_MOTOR | TIM_USE_FW_SERVO, 0, 1 ), // S4_OUT - DMA1_ST6 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO, 0, 0 ), // S5_OUT - DMA1_ST7 - LED Control + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MC_MOTOR | TIM_USE_MC_SERVO | TIM_USE_FW_SERVO | TIM_USE_LED, 0, 0 ), // S6_OUT + DEF_TIM(TIM4, CH2, PB7, TIM_USE_ANY, 0, 0 ), // ANY + DEF_TIM(TIM12, CH1, PB14, TIM_USE_BEEPER, 0, 0 ), // BEEPER PWM }; const int timerHardwareCount = sizeof(timerHardware) / sizeof(timerHardware[0]); diff --git a/src/main/target/YUPIF7/target.h b/src/main/target/YUPIF7/target.h index 2a9802db211..0719b37341f 100644 --- a/src/main/target/YUPIF7/target.h +++ b/src/main/target/YUPIF7/target.h @@ -142,12 +142,6 @@ // LED Strip can run off Pin 5 (PB1) of the motor outputs #define USE_LED_STRIP #define WS2811_PIN PB1 -#define WS2811_TIMER TIM8 -#define WS2811_TIMER_CHANNEL TIM_CHANNEL_3 -#define WS2811_DMA_HANDLER_IDENTIFER DMA1_ST2_HANDLER -#define WS2811_DMA_STREAM DMA1_Stream2 -#define WS2811_DMA_CHANNEL DMA_CHANNEL_5 -#define WS2811_TIMER_GPIO_AF GPIO_AF3_TIM8 // Default configuration #define SERIALRX_PROVIDER SERIALRX_SBUS diff --git a/src/main/target/YUPIF7/target.mk b/src/main/target/YUPIF7/target.mk index 76833e976ba..daa1a78f0fa 100644 --- a/src/main/target/YUPIF7/target.mk +++ b/src/main/target/YUPIF7/target.mk @@ -12,5 +12,4 @@ TARGET_SRC = \ drivers/compass/compass_mag3110.c \ drivers/max7456.c \ drivers/light_ws2811strip.c \ - drivers/light_ws2811strip_hal.c \ drivers/serial_softserial.c diff --git a/src/main/target/common.h b/src/main/target/common.h index 90070fcfacc..e5dd936b16b 100755 --- a/src/main/target/common.h +++ b/src/main/target/common.h @@ -17,6 +17,12 @@ #pragma once +#if defined(STM32F3) +#define DYNAMIC_HEAP_SIZE 1536 +#else +#define DYNAMIC_HEAP_SIZE 2048 +#endif + #define I2C1_OVERCLOCK false #define I2C2_OVERCLOCK false #define USE_I2C_PULLUP // Enable built-in pullups on all boards in case external ones are too week