Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes log #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ FORKNAME = raceflight
CC3D_TARGETS = CC3D CC3D_OPBL
F1_TARGETS = NAZE OLIMEXINO CJMCU EUSTM32F103RC PORT103R ALIENWIIF1 AFROMINI
F3_TARGETS = STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO SPRACINGF3 IRCFUSIONF3 SPARKY ALIENWIIF3 COLIBRI_RACE MOTOLAB RMDO LUX_RACE
F4_TARGETS = REVO REVO_OPBL SPARKY2 SPARKY2_OPBL REVONANO REVONANO_OPBL ALIENFLIGHTF4 BLUEJAYF4 VRCORE QUANTON KKNGF4
F4_TARGETS = REVO REVO_OPBL SPARKY2 SPARKY2_OPBL REVONANO REVONANO_OPBL ALIENFLIGHTF4 BLUEJAYF4 VRCORE QUANTON KKNGF4 KAKUTEF4

F405_TARGETS = REVO REVO_OPBL SPARKY2 SPARKY2_OPBL ALIENFLIGHTF4 BLUEJAYF4 VRCORE QUANTON KKNGF4
F405_TARGETS = REVO REVO_OPBL SPARKY2 SPARKY2_OPBL ALIENFLIGHTF4 BLUEJAYF4 VRCORE QUANTON KKNGF4 KAKUTEF4
F405_TARGETS_16 = QUANTON
F411_TARGETS = REVONANO REVONANO_OPBL

Expand Down Expand Up @@ -459,7 +459,10 @@ STM32F4xx_COMMON_SRC = \
drivers/timer.c \
drivers/timer_stm32f4xx.c \
drivers/flash_m25p16.c \
io/flashfs.c
io/flashfs.c \
drivers/light_ws2811strip.c \
drivers/light_ws2811strip_stm32f4xx.c \
drivers/dma_stm32f4xx.c

VCP_SRC = \
vcp/hw_config.c \
Expand Down Expand Up @@ -693,6 +696,14 @@ SPARKY2_SRC = $(STM32F4xx_COMMON_SRC) \
$(COMMON_SRC) \
$(VCPF4_SRC)

KAKUTEF4_SRC = $(STM32F4xx_COMMON_SRC) \
drivers/accgyro_spi_mpu9250.c \
drivers/barometer_ms5611.c \
drivers/compass_hmc5883l.c \
$(HIGHEND_SRC) \
$(COMMON_SRC) \
$(VCPF4_SRC)

ALIENFLIGHTF4_SRC = $(STM32F4xx_COMMON_SRC) \
drivers/accgyro_spi_mpu9250.c \
drivers/barometer_bmp280.c \
Expand Down Expand Up @@ -747,7 +758,8 @@ STM32F30x_COMMON_SRC = \
drivers/sound_beeper.c \
drivers/system_stm32f30x.c \
drivers/timer.c \
drivers/timer_stm32f30x.c
drivers/timer_stm32f30x.c \
drivers/dma.c

NAZE32PRO_SRC = \
$(STM32F30x_COMMON_SRC) \
Expand Down Expand Up @@ -915,7 +927,7 @@ LTO_FLAGS = $(OPTIMIZE)
else
ifeq ($(TARGET),$(filter $(TARGET),SPARKY2 SPARKY2_OPBL))
OPTIMIZE = -O2
else ifeq ($(TARGET),$(filter $(TARGET),REVO REVO_OPBL REVONANO REVONANO_OPBL ALIENFLIGHTF4 BLUEJAYF4 VRCORE KKNGF4))
else ifeq ($(TARGET),$(filter $(TARGET),REVO REVO_OPBL REVONANO REVONANO_OPBL ALIENFLIGHTF4 BLUEJAYF4 VRCORE KKNGF4 KAKUTEF4))
OPTIMIZE = -O2
else
OPTIMIZE = -Os
Expand Down
87 changes: 87 additions & 0 deletions src/main/drivers/dma.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

#include <stdbool.h>
#include <string.h>
#include <stdint.h>

#include <platform.h>

#include "build_config.h"

#include "drivers/dma.h"

/*
* DMA handlers for DMA resources that are shared between different features depending on run-time configuration.
*/
static dmaHandlers_t dmaHandlers;

#if defined(STM32F1) || defined(STM32F3)
void dmaNoOpHandler(DMA_Channel_TypeDef *channel)
{
UNUSED(channel);
}

void DMA1_Channel2_IRQHandler(void)
{
dmaHandlers.dma1Channel2IRQHandler(DMA1_Channel2);
}

void DMA1_Channel3_IRQHandler(void)
{
dmaHandlers.dma1Channel3IRQHandler(DMA1_Channel3);
}

void DMA1_Channel6_IRQHandler(void)
{
dmaHandlers.dma1Channel6IRQHandler(DMA1_Channel6);
}

void DMA1_Channel7_IRQHandler(void)
{
dmaHandlers.dma1Channel7IRQHandler(DMA1_Channel7);
}
#endif

void dmaInit(void)
{
memset(&dmaHandlers, 0, sizeof(dmaHandlers));
dmaHandlers.dma1Channel2IRQHandler = dmaNoOpHandler;
dmaHandlers.dma1Channel3IRQHandler = dmaNoOpHandler;
dmaHandlers.dma1Channel6IRQHandler = dmaNoOpHandler;
dmaHandlers.dma1Channel7IRQHandler = dmaNoOpHandler;
}

void dmaSetHandler(dmaHandlerIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback)
{
switch (identifier) {
case DMA1_CH2_HANDLER:
dmaHandlers.dma1Channel2IRQHandler = callback;
break;
case DMA1_CH3_HANDLER:
dmaHandlers.dma1Channel3IRQHandler = callback;
break;
case DMA1_CH6_HANDLER:
dmaHandlers.dma1Channel6IRQHandler = callback;
break;
case DMA1_CH7_HANDLER:
dmaHandlers.dma1Channel7IRQHandler = callback;
break;
}
}


58 changes: 58 additions & 0 deletions src/main/drivers/dma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/


#pragma once
#include <platform.h>

#if defined(STM32F4)
typedef void (*dmaCallbackHandlerFuncPtr)(DMA_Stream_TypeDef *stream);

typedef enum {
DMA1_ST2_HANDLER = 0,
DMA1_ST7_HANDLER,
} dmaHandlerIdentifier_e;

typedef struct dmaHandlers_s {
dmaCallbackHandlerFuncPtr dma1Stream2IRQHandler;
dmaCallbackHandlerFuncPtr dma1Stream7IRQHandler;
} dmaHandlers_t;

#else

typedef void (*dmaCallbackHandlerFuncPtr)(DMA_Channel_TypeDef *channel);

typedef enum {
DMA1_CH2_HANDLER = 0,
DMA1_CH3_HANDLER,
DMA1_CH6_HANDLER,
DMA1_CH7_HANDLER,
} dmaHandlerIdentifier_e;

typedef struct dmaHandlers_s {
dmaCallbackHandlerFuncPtr dma1Channel2IRQHandler;
dmaCallbackHandlerFuncPtr dma1Channel3IRQHandler;
dmaCallbackHandlerFuncPtr dma1Channel6IRQHandler;
dmaCallbackHandlerFuncPtr dma1Channel7IRQHandler;
} dmaHandlers_t;

#endif

void dmaInit(void);
void dmaSetHandler(dmaHandlerIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback);


67 changes: 67 additions & 0 deletions src/main/drivers/dma_stm32f4xx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

#include <stdbool.h>
#include <string.h>
#include <stdint.h>

#include <platform.h>

#include "build_config.h"

#include "drivers/dma.h"

/*
* DMA handlers for DMA resources that are shared between different features depending on run-time configuration.
*/
static dmaHandlers_t dmaHandlers;

void dmaNoOpHandler(DMA_Stream_TypeDef *stream)
{
UNUSED(stream);
}

void DMA1_Stream2_IRQHandler(void)
{
dmaHandlers.dma1Stream2IRQHandler(DMA1_Stream2);
}

void DMA1_Stream7_IRQHandler(void)
{
dmaHandlers.dma1Stream7IRQHandler(DMA1_Stream7);
}

void dmaInit(void)
{
memset(&dmaHandlers, 0, sizeof(dmaHandlers));
dmaHandlers.dma1Stream2IRQHandler = dmaNoOpHandler;
dmaHandlers.dma1Stream7IRQHandler = dmaNoOpHandler;
}

void dmaSetHandler(dmaHandlerIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback)
{
switch (identifier) {
case DMA1_ST2_HANDLER:
dmaHandlers.dma1Stream2IRQHandler = callback;
break;
case DMA1_ST7_HANDLER:
dmaHandlers.dma1Stream7IRQHandler = callback;
break;
}
}


27 changes: 16 additions & 11 deletions src/main/drivers/io_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@ extern ioRec_t ioRecs[DEFIO_IO_USED_COUNT];

int IO_GPIOPortIdx(IO_t io);
int IO_GPIOPinIdx(IO_t io);
#if defined(STM32F10X)
int IO_GPIO_PinSource(IO_t io);
int IO_GPIO_PortSource(IO_t io);
#elif defined(STM32F303xC)
int IO_GPIO_PinSource(IO_t io);
int IO_GPIO_PortSource(IO_t io);
//#if defined(STM32F10X)
//int IO_GPIO_PinSource(IO_t io);
//int IO_GPIO_PortSource(IO_t io);
//#elif defined(STM32F303xC)
//int IO_GPIO_PinSource(IO_t io);
//int IO_GPIO_PortSource(IO_t io);
//int IO_EXTI_PortSourceGPIO(IO_t io);
//int IO_EXTI_PinSource(IO_t io);
//#elif defined(STM32F40_41xxx) || defined(STM32F411xE)

#if defined(STM32F3) || defined(STM32F4)
int IO_EXTI_PortSourceGPIO(IO_t io);
int IO_EXTI_PinSource(IO_t io);
#elif defined(STM32F40_41xxx) || defined(STM32F411xE)
int IO_EXTI_PinSource(IO_t io);
GPIO_TypeDef* IO_GPIO(IO_t io);
#endif

int IO_GPIO_PinSource(IO_t io);
int IO_GPIO_PortSource(IO_t io);
int IO_EXTI_PortSourceGPIO(IO_t io);
int IO_EXTI_PinSource(IO_t io);
# endif

uint32_t IO_EXTI_Line(IO_t io);
ioRec_t *IO_Rec(IO_t io);
9 changes: 6 additions & 3 deletions src/main/drivers/light_ws2811strip.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
#include <stdint.h>
#include <string.h>

#include "platform.h"
#include <platform.h>

#include "build_config.h"

#include "common/color.h"
#include "common/colorconversion.h"
#include "drivers/light_ws2811strip.h"
//#include "drivers/light_ws2811strip.h"
#include "light_ws2811strip.h"


uint8_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE];
volatile uint8_t ws2811LedDataTransferInProgress = 0;
Expand Down Expand Up @@ -133,7 +135,8 @@ void ws2811UpdateStrip(void)

// wait until previous transfer completes
while(ws2811LedDataTransferInProgress) {
waitCounter++;
//waitCounter++;
return;
}

dmaBufferOffset = 0; // reset buffer memory index
Expand Down
6 changes: 6 additions & 0 deletions src/main/drivers/light_ws2811strip.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@

#define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE + WS2811_DELAY_BUFFER_LENGTH) // number of bytes needed is #LEDs * 24 bytes + 42 trailing bytes)

#if defined(STM32F40_41xxx)
#define BIT_COMPARE_1 67 // timer compare value for logical 1
#define BIT_COMPARE_0 33 // timer compare value for logical 0
#else
#define BIT_COMPARE_1 17 // timer compare value for logical 1
#define BIT_COMPARE_0 9 // timer compare value for logical 0
#endif


void ws2811LedStripInit(void);

Expand Down
13 changes: 12 additions & 1 deletion src/main/drivers/light_ws2811strip_stm32f10x.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@
#include "platform.h"

#include "common/color.h"
#include "drivers/light_ws2811strip.h"
#include "light_ws2811strip.h"
#include "dma.h"
#include "nvic.h"

void ws2811DMAHandler(DMA_Channel_TypeDef *channel) {
if (DMA_GetFlagStatus(WS2811_DMA_TC_FLAG)) {
ws2811LedDataTransferInProgress = 0;
DMA_Cmd(channel, DISABLE);
DMA_ClearFlag(WS2811_DMA_TC_FLAG);
}
}

void ws2811LedStripHardwareInit(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
Expand Down Expand Up @@ -77,6 +86,8 @@ void ws2811LedStripHardwareInit(void)
/* DMA clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

dmaSetHandler(WS2811_DMA_HANDLER_IDENTIFER, ws2811DMAHandler);

/* DMA1 Channel6 Config */
DMA_DeInit(DMA1_Channel6);

Expand Down
Loading