From 7c6d3efa1337cc87b04b5cc006e0d40b6a1c2d9a Mon Sep 17 00:00:00 2001 From: Sami Korhonen Date: Sun, 4 Dec 2016 09:48:47 +0200 Subject: [PATCH 01/30] NucleoF7 board support --- Makefile | 7 +- src/main/config/config_eeprom.c | 6 + src/main/drivers/serial_uart_hal.c | 5 +- src/main/platform.h | 2 +- src/main/target/NUCLEOF7/stm32f7xx_hal_conf.h | 438 ++++++++++++++++++ src/main/target/NUCLEOF7/target.c | 58 +++ src/main/target/NUCLEOF7/target.h | 163 +++++++ src/main/target/NUCLEOF7/target.mk | 9 + src/main/target/link/stm32_flash_f746.ld | 28 ++ 9 files changed, 712 insertions(+), 4 deletions(-) create mode 100644 src/main/target/NUCLEOF7/stm32f7xx_hal_conf.h create mode 100644 src/main/target/NUCLEOF7/target.c create mode 100644 src/main/target/NUCLEOF7/target.h create mode 100644 src/main/target/NUCLEOF7/target.mk create mode 100644 src/main/target/link/stm32_flash_f746.ld diff --git a/Makefile b/Makefile index f2edc40d5..2623e490b 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,7 @@ endif -include $(ROOT)/src/main/target/$(BASE_TARGET)/target.mk F4_TARGETS = $(F405_TARGETS) $(F411_TARGETS) -F7_TARGETS = $(F7X5XE_TARGETS) $(F7X5XG_TARGETS) $(F7X5XI_TARGETS) +F7_TARGETS = $(F7X5XE_TARGETS) $(F7X5XG_TARGETS) $(F7X5XI_TARGETS) $(F7X6XG_TARGETS) ifeq ($(filter $(TARGET),$(VALID_TARGETS)),) $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS). Have you prepared a valid target.mk?) @@ -136,7 +136,7 @@ endif 128K_TARGETS = $(F1_TARGETS) 256K_TARGETS = $(F3_TARGETS) 512K_TARGETS = $(F411_TARGETS) $(F7X5XE_TARGETS) -1024K_TARGETS = $(F405_TARGETS) $(F7X5XG_TARGETS) +1024K_TARGETS = $(F405_TARGETS) $(F7X5XG_TARGETS) $(F7X6XG_TARGETS) 2048K_TARGETS = $(F7X5XI_TARGETS) # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already. @@ -376,6 +376,9 @@ ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fs ifeq ($(TARGET),$(filter $(TARGET),$(F7X5XG_TARGETS))) DEVICE_FLAGS = -DSTM32F745xx -DUSE_HAL_DRIVER -D__FPU_PRESENT LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f745.ld +else ifeq ($(TARGET),$(filter $(TARGET),$(F7X6XG_TARGETS))) +DEVICE_FLAGS = -DSTM32F746xx -DUSE_HAL_DRIVER -D__FPU_PRESENT +LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f746.ld else $(error Unknown MCU for F7 target) endif diff --git a/src/main/config/config_eeprom.c b/src/main/config/config_eeprom.c index 0cc02f1f3..18c25d68b 100644 --- a/src/main/config/config_eeprom.c +++ b/src/main/config/config_eeprom.c @@ -51,6 +51,10 @@ #define FLASH_PAGE_SIZE ((uint32_t)0x40000) #endif + #if defined(STM32F746xx) + #define FLASH_PAGE_SIZE ((uint32_t)0x40000) + #endif + #if defined(STM32F40_41xxx) #define FLASH_PAGE_SIZE ((uint32_t)0x20000) #endif @@ -78,6 +82,8 @@ #define FLASH_PAGE_COUNT 3 // just to make calculations work #elif defined (STM32F745xx) #define FLASH_PAGE_COUNT 4 // just to make calculations work +#elif defined (STM32F746xx) +#define FLASH_PAGE_COUNT 4 // just to make calculations work #else #define FLASH_PAGE_COUNT ((FLASH_SIZE * 0x400) / FLASH_PAGE_SIZE) #endif diff --git a/src/main/drivers/serial_uart_hal.c b/src/main/drivers/serial_uart_hal.c index 0a00d2aac..ecbd54a5e 100644 --- a/src/main/drivers/serial_uart_hal.c +++ b/src/main/drivers/serial_uart_hal.c @@ -179,8 +179,11 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, { uartPort_t *s = NULL; - if (USARTx == USART1) { + if (false) { +#ifdef USE_UART1 + } else if (USARTx == USART1) { s = serialUART1(baudRate, mode, options); +#endif #ifdef USE_UART2 } else if (USARTx == USART2) { s = serialUART2(baudRate, mode, options); diff --git a/src/main/platform.h b/src/main/platform.h index 221222263..0f6439cbc 100644 --- a/src/main/platform.h +++ b/src/main/platform.h @@ -17,7 +17,7 @@ #pragma once -#if defined(STM32F745xx) +#if defined(STM32F745xx) || defined(STM32F746xx) #include "stm32f7xx.h" #include "stm32f7xx_hal.h" diff --git a/src/main/target/NUCLEOF7/stm32f7xx_hal_conf.h b/src/main/target/NUCLEOF7/stm32f7xx_hal_conf.h new file mode 100644 index 000000000..f2e5ffc8f --- /dev/null +++ b/src/main/target/NUCLEOF7/stm32f7xx_hal_conf.h @@ -0,0 +1,438 @@ +/** + ****************************************************************************** + * @file stm32f7xx_hal_conf.h + * @brief HAL configuration file. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2016 STMicroelectronics

+ * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F7xx_HAL_CONF_H +#define __STM32F7xx_HAL_CONF_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ + +/* ########################## Module Selection ############################## */ +/** + * @brief This is the list of modules to be used in the HAL driver + */ +#define HAL_MODULE_ENABLED + +#define HAL_ADC_MODULE_ENABLED +/* #define HAL_CAN_MODULE_ENABLED */ +/* #define HAL_CEC_MODULE_ENABLED */ +/* #define HAL_CRC_MODULE_ENABLED */ +/* #define HAL_CRYP_MODULE_ENABLED */ +/* #define HAL_DAC_MODULE_ENABLED */ +/* #define HAL_DCMI_MODULE_ENABLED */ +/* #define HAL_DMA2D_MODULE_ENABLED */ +/* #define HAL_ETH_MODULE_ENABLED */ +/* #define HAL_NAND_MODULE_ENABLED */ +/* #define HAL_NOR_MODULE_ENABLED */ +/* #define HAL_SRAM_MODULE_ENABLED */ +/* #define HAL_SDRAM_MODULE_ENABLED */ +/* #define HAL_HASH_MODULE_ENABLED */ +/* #define HAL_I2S_MODULE_ENABLED */ +/* #define HAL_IWDG_MODULE_ENABLED */ +/* #define HAL_LPTIM_MODULE_ENABLED */ +/* #define HAL_LTDC_MODULE_ENABLED */ +/* #define HAL_QSPI_MODULE_ENABLED */ +/* #define HAL_RNG_MODULE_ENABLED */ +/* #define HAL_RTC_MODULE_ENABLED */ +/* #define HAL_SAI_MODULE_ENABLED */ +/* #define HAL_SD_MODULE_ENABLED */ +/* #define HAL_SPDIFRX_MODULE_ENABLED */ +#define HAL_SPI_MODULE_ENABLED +#define HAL_TIM_MODULE_ENABLED +#define HAL_UART_MODULE_ENABLED +#define HAL_USART_MODULE_ENABLED +/* #define HAL_IRDA_MODULE_ENABLED */ +/* #define HAL_SMARTCARD_MODULE_ENABLED */ +/* #define HAL_WWDG_MODULE_ENABLED */ +#define HAL_PCD_MODULE_ENABLED +/* #define HAL_HCD_MODULE_ENABLED */ +/* #define HAL_DFSDM_MODULE_ENABLED */ +/* #define HAL_DSI_MODULE_ENABLED */ +/* #define HAL_JPEG_MODULE_ENABLED */ +/* #define HAL_MDIOS_MODULE_ENABLED */ +#define HAL_GPIO_MODULE_ENABLED +#define HAL_DMA_MODULE_ENABLED +#define HAL_RCC_MODULE_ENABLED +#define HAL_FLASH_MODULE_ENABLED +#define HAL_PWR_MODULE_ENABLED +#define HAL_I2C_MODULE_ENABLED +#define HAL_CORTEX_MODULE_ENABLED + +/* ########################## HSE/HSI Values adaptation ##################### */ +/** + * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSE is used as system clock source, directly or through the PLL). + */ +#if !defined (HSE_VALUE) + #define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */ +#endif /* HSE_VALUE */ + +#if !defined (HSE_STARTUP_TIMEOUT) + #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ +#endif /* HSE_STARTUP_TIMEOUT */ + +/** + * @brief Internal High Speed oscillator (HSI) value. + * This value is used by the RCC HAL module to compute the system frequency + * (when HSI is used as system clock source, directly or through the PLL). + */ +#if !defined (HSI_VALUE) + #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ +#endif /* HSI_VALUE */ + +/** + * @brief Internal Low Speed oscillator (LSI) value. + */ +#if !defined (LSI_VALUE) + #define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/ +#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz + The real value may vary depending on the variations + in voltage and temperature. */ +/** + * @brief External Low Speed oscillator (LSE) value. + */ +#if !defined (LSE_VALUE) + #define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External Low Speed oscillator in Hz */ +#endif /* LSE_VALUE */ + +#if !defined (LSE_STARTUP_TIMEOUT) + #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ +#endif /* LSE_STARTUP_TIMEOUT */ + +/** + * @brief External clock source for I2S peripheral + * This value is used by the I2S HAL module to compute the I2S clock source + * frequency, this source is inserted directly through I2S_CKIN pad. + */ +#if !defined (EXTERNAL_CLOCK_VALUE) + #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000U) /*!< Value of the Internal oscillator in Hz*/ +#endif /* EXTERNAL_CLOCK_VALUE */ + +/* Tip: To avoid modifying this file each time you need to use different HSE, + === you can define the HSE value in your toolchain compiler preprocessor. */ + +/* ########################### System Configuration ######################### */ +/** + * @brief This is the HAL system configuration section + */ +#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */ +#define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */ +#define USE_RTOS 0U +#define PREFETCH_ENABLE 0U +#define ART_ACCLERATOR_ENABLE 0U /* To enable instruction cache and prefetch */ + +/* ########################## Assert Selection ############################## */ +/** + * @brief Uncomment the line below to expanse the "assert_param" macro in the + * HAL drivers code + */ +/* #define USE_FULL_ASSERT 1 */ + +/* ################## Ethernet peripheral configuration ##################### */ + +/* Section 1 : Ethernet peripheral configuration */ + +/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ +#define MAC_ADDR0 2U +#define MAC_ADDR1 0U +#define MAC_ADDR2 0U +#define MAC_ADDR3 0U +#define MAC_ADDR4 0U +#define MAC_ADDR5 0U + +/* Definition of the Ethernet driver buffers size and count */ +#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ +#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ +#define ETH_RXBUFNB ((uint32_t)4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ +#define ETH_TXBUFNB ((uint32_t)4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ + +/* Section 2: PHY configuration section */ + +/* DP83848_PHY_ADDRESS Address*/ +#define DP83848_PHY_ADDRESS 0x01U +/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ +#define PHY_RESET_DELAY ((uint32_t)0x000000FFU) +/* PHY Configuration delay */ +#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU) + +#define PHY_READ_TO ((uint32_t)0x0000FFFFU) +#define PHY_WRITE_TO ((uint32_t)0x0000FFFFU) + +/* Section 3: Common PHY Registers */ + +#define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */ +#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */ + +#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ +#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ +#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ +#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ +#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ +#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ +#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ +#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ +#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ +#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ + +#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ +#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ +#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ + +/* Section 4: Extended PHY Registers */ +#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ + +#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ +#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ + +/* ################## SPI peripheral configuration ########################## */ + +/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver +* Activated: CRC code is present inside driver +* Deactivated: CRC code cleaned from driver +*/ + +#define USE_SPI_CRC 0U + +/* Includes ------------------------------------------------------------------*/ +/** + * @brief Include module's header file + */ + +#ifdef HAL_RCC_MODULE_ENABLED + #include "stm32f7xx_hal_rcc.h" +#endif /* HAL_RCC_MODULE_ENABLED */ + +#ifdef HAL_GPIO_MODULE_ENABLED + #include "stm32f7xx_hal_gpio.h" +#endif /* HAL_GPIO_MODULE_ENABLED */ + +#ifdef HAL_DMA_MODULE_ENABLED + #include "stm32f7xx_hal_dma.h" +#endif /* HAL_DMA_MODULE_ENABLED */ + +#ifdef HAL_CORTEX_MODULE_ENABLED + #include "stm32f7xx_hal_cortex.h" +#endif /* HAL_CORTEX_MODULE_ENABLED */ + +#ifdef HAL_ADC_MODULE_ENABLED + #include "stm32f7xx_hal_adc.h" +#endif /* HAL_ADC_MODULE_ENABLED */ + +#ifdef HAL_CAN_MODULE_ENABLED + #include "stm32f7xx_hal_can.h" +#endif /* HAL_CAN_MODULE_ENABLED */ + +#ifdef HAL_CEC_MODULE_ENABLED + #include "stm32f7xx_hal_cec.h" +#endif /* HAL_CEC_MODULE_ENABLED */ + +#ifdef HAL_CRC_MODULE_ENABLED + #include "stm32f7xx_hal_crc.h" +#endif /* HAL_CRC_MODULE_ENABLED */ + +#ifdef HAL_CRYP_MODULE_ENABLED + #include "stm32f7xx_hal_cryp.h" +#endif /* HAL_CRYP_MODULE_ENABLED */ + +#ifdef HAL_DMA2D_MODULE_ENABLED + #include "stm32f7xx_hal_dma2d.h" +#endif /* HAL_DMA2D_MODULE_ENABLED */ + +#ifdef HAL_DAC_MODULE_ENABLED + #include "stm32f7xx_hal_dac.h" +#endif /* HAL_DAC_MODULE_ENABLED */ + +#ifdef HAL_DCMI_MODULE_ENABLED + #include "stm32f7xx_hal_dcmi.h" +#endif /* HAL_DCMI_MODULE_ENABLED */ + +#ifdef HAL_ETH_MODULE_ENABLED + #include "stm32f7xx_hal_eth.h" +#endif /* HAL_ETH_MODULE_ENABLED */ + +#ifdef HAL_FLASH_MODULE_ENABLED + #include "stm32f7xx_hal_flash.h" +#endif /* HAL_FLASH_MODULE_ENABLED */ + +#ifdef HAL_SRAM_MODULE_ENABLED + #include "stm32f7xx_hal_sram.h" +#endif /* HAL_SRAM_MODULE_ENABLED */ + +#ifdef HAL_NOR_MODULE_ENABLED + #include "stm32f7xx_hal_nor.h" +#endif /* HAL_NOR_MODULE_ENABLED */ + +#ifdef HAL_NAND_MODULE_ENABLED + #include "stm32f7xx_hal_nand.h" +#endif /* HAL_NAND_MODULE_ENABLED */ + +#ifdef HAL_SDRAM_MODULE_ENABLED + #include "stm32f7xx_hal_sdram.h" +#endif /* HAL_SDRAM_MODULE_ENABLED */ + +#ifdef HAL_HASH_MODULE_ENABLED + #include "stm32f7xx_hal_hash.h" +#endif /* HAL_HASH_MODULE_ENABLED */ + +#ifdef HAL_I2C_MODULE_ENABLED + #include "stm32f7xx_hal_i2c.h" +#endif /* HAL_I2C_MODULE_ENABLED */ + +#ifdef HAL_I2S_MODULE_ENABLED + #include "stm32f7xx_hal_i2s.h" +#endif /* HAL_I2S_MODULE_ENABLED */ + +#ifdef HAL_IWDG_MODULE_ENABLED + #include "stm32f7xx_hal_iwdg.h" +#endif /* HAL_IWDG_MODULE_ENABLED */ + +#ifdef HAL_LPTIM_MODULE_ENABLED + #include "stm32f7xx_hal_lptim.h" +#endif /* HAL_LPTIM_MODULE_ENABLED */ + +#ifdef HAL_LTDC_MODULE_ENABLED + #include "stm32f7xx_hal_ltdc.h" +#endif /* HAL_LTDC_MODULE_ENABLED */ + +#ifdef HAL_PWR_MODULE_ENABLED + #include "stm32f7xx_hal_pwr.h" +#endif /* HAL_PWR_MODULE_ENABLED */ + +#ifdef HAL_QSPI_MODULE_ENABLED + #include "stm32f7xx_hal_qspi.h" +#endif /* HAL_QSPI_MODULE_ENABLED */ + +#ifdef HAL_RNG_MODULE_ENABLED + #include "stm32f7xx_hal_rng.h" +#endif /* HAL_RNG_MODULE_ENABLED */ + +#ifdef HAL_RTC_MODULE_ENABLED + #include "stm32f7xx_hal_rtc.h" +#endif /* HAL_RTC_MODULE_ENABLED */ + +#ifdef HAL_SAI_MODULE_ENABLED + #include "stm32f7xx_hal_sai.h" +#endif /* HAL_SAI_MODULE_ENABLED */ + +#ifdef HAL_SD_MODULE_ENABLED + #include "stm32f7xx_hal_sd.h" +#endif /* HAL_SD_MODULE_ENABLED */ + +#ifdef HAL_SPDIFRX_MODULE_ENABLED + #include "stm32f7xx_hal_spdifrx.h" +#endif /* HAL_SPDIFRX_MODULE_ENABLED */ + +#ifdef HAL_SPI_MODULE_ENABLED + #include "stm32f7xx_hal_spi.h" +#endif /* HAL_SPI_MODULE_ENABLED */ + +#ifdef HAL_TIM_MODULE_ENABLED + #include "stm32f7xx_hal_tim.h" +#endif /* HAL_TIM_MODULE_ENABLED */ + +#ifdef HAL_UART_MODULE_ENABLED + #include "stm32f7xx_hal_uart.h" +#endif /* HAL_UART_MODULE_ENABLED */ + +#ifdef HAL_USART_MODULE_ENABLED + #include "stm32f7xx_hal_usart.h" +#endif /* HAL_USART_MODULE_ENABLED */ + +#ifdef HAL_IRDA_MODULE_ENABLED + #include "stm32f7xx_hal_irda.h" +#endif /* HAL_IRDA_MODULE_ENABLED */ + +#ifdef HAL_SMARTCARD_MODULE_ENABLED + #include "stm32f7xx_hal_smartcard.h" +#endif /* HAL_SMARTCARD_MODULE_ENABLED */ + +#ifdef HAL_WWDG_MODULE_ENABLED + #include "stm32f7xx_hal_wwdg.h" +#endif /* HAL_WWDG_MODULE_ENABLED */ + +#ifdef HAL_PCD_MODULE_ENABLED + #include "stm32f7xx_hal_pcd.h" +#endif /* HAL_PCD_MODULE_ENABLED */ + +#ifdef HAL_HCD_MODULE_ENABLED + #include "stm32f7xx_hal_hcd.h" +#endif /* HAL_HCD_MODULE_ENABLED */ + +#ifdef HAL_DFSDM_MODULE_ENABLED + #include "stm32f7xx_hal_dfsdm.h" +#endif /* HAL_DFSDM_MODULE_ENABLED */ + +#ifdef HAL_DSI_MODULE_ENABLED + #include "stm32f7xx_hal_dsi.h" +#endif /* HAL_DSI_MODULE_ENABLED */ + +#ifdef HAL_JPEG_MODULE_ENABLED + #include "stm32f7xx_hal_jpeg.h" +#endif /* HAL_JPEG_MODULE_ENABLED */ + +#ifdef HAL_MDIOS_MODULE_ENABLED + #include "stm32f7xx_hal_mdios.h" +#endif /* HAL_MDIOS_MODULE_ENABLED */ + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval None + */ + #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ + void assert_failed(uint8_t* file, uint32_t line); +#else + #define assert_param(expr) ((void)0U) +#endif /* USE_FULL_ASSERT */ + +#ifdef __cplusplus +} +#endif + +#endif /* __STM32F7xx_HAL_CONF_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/src/main/target/NUCLEOF7/target.c b/src/main/target/NUCLEOF7/target.c new file mode 100644 index 000000000..f20a73af6 --- /dev/null +++ b/src/main/target/NUCLEOF7/target.c @@ -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 . + */ + +#include + +#include +#include "drivers/io.h" +#include "drivers/dma.h" + +#include "drivers/timer.h" + +#if defined(USE_DSHOT) +// DSHOT TEST +const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { + { TIM12, IO_TAG(PB15), TIM_CHANNEL_2, TIM_USE_PWM | TIM_USE_PPM, 0, GPIO_AF9_TIM12, NULL, 0, 0 }, // S2_IN + { TIM8, IO_TAG(PC6), TIM_CHANNEL_1, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S3_IN + { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S4_IN + { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S5_IN + { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S6_IN + + { TIM4, IO_TAG(PB8), TIM_CHANNEL_3, TIM_USE_MOTOR, 1, GPIO_AF2_TIM4, DMA1_Stream7, DMA_CHANNEL_2, DMA1_ST7_HANDLER }, // S10_OUT 1 + { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, TIM_USE_MOTOR, 1, GPIO_AF1_TIM2, DMA1_Stream6, DMA_CHANNEL_3, DMA1_ST6_HANDLER }, // S1_OUT 4 + { TIM3, IO_TAG(PB5), TIM_CHANNEL_2, TIM_USE_MOTOR, 1, GPIO_AF2_TIM3, DMA1_Stream5, DMA_CHANNEL_5, DMA1_ST5_HANDLER }, // S4_OUT + { TIM4, IO_TAG(PB9), TIM_CHANNEL_4, TIM_USE_MOTOR, 1, GPIO_AF2_TIM4, NULL, 0, 0 }, // S5_OUT 3 + { TIM9, IO_TAG(PE6), TIM_CHANNEL_2, TIM_USE_MOTOR, 1, GPIO_AF3_TIM9, NULL, 0, 0 }, // S3_OUT + { TIM3, IO_TAG(PB4), TIM_CHANNEL_1, TIM_USE_MOTOR, 1, GPIO_AF2_TIM3, NULL, 0, 0 }, // S9_OUT +}; +#else +// STANDARD LAYOUT +const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { + { TIM12, IO_TAG(PB15), TIM_CHANNEL_2, TIM_USE_PWM | TIM_USE_PPM, 0, GPIO_AF9_TIM12, NULL, 0, 0 }, // S2_IN + { TIM8, IO_TAG(PC6), TIM_CHANNEL_1, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S3_IN + { TIM8, IO_TAG(PC7), TIM_CHANNEL_2, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S4_IN + { TIM8, IO_TAG(PC9), TIM_CHANNEL_4, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S5_IN + { TIM8, IO_TAG(PC8), TIM_CHANNEL_3, TIM_USE_PWM, 0, GPIO_AF3_TIM8, NULL, 0, 0 }, // S6_IN + + { TIM4, IO_TAG(PB8), TIM_CHANNEL_3, TIM_USE_MOTOR | TIM_USE_LED, 1, GPIO_AF2_TIM4, DMA1_Stream7, DMA_CHANNEL_2, DMA1_ST7_HANDLER }, // S10_OUT 1 + { TIM4, IO_TAG(PB9), TIM_CHANNEL_4, TIM_USE_MOTOR, 1, GPIO_AF2_TIM4, NULL, 0, 0 }, // S5_OUT 3 + { TIM2, IO_TAG(PA3), TIM_CHANNEL_4, TIM_USE_MOTOR, 1, GPIO_AF1_TIM2, NULL, 0, 0 }, // S1_OUT 4 + { TIM9, IO_TAG(PE6), TIM_CHANNEL_2, TIM_USE_MOTOR, 1, GPIO_AF3_TIM9, NULL, 0, 0 }, // S3_OUT + { TIM3, IO_TAG(PB5), TIM_CHANNEL_2, TIM_USE_MOTOR, 1, GPIO_AF2_TIM3, NULL, 0, 0 }, // S4_OUT + { TIM3, IO_TAG(PB4), TIM_CHANNEL_1, TIM_USE_MOTOR, 1, GPIO_AF2_TIM3, NULL, 0, 0 }, // S9_OUT +}; +#endif diff --git a/src/main/target/NUCLEOF7/target.h b/src/main/target/NUCLEOF7/target.h new file mode 100644 index 000000000..a1cf620a8 --- /dev/null +++ b/src/main/target/NUCLEOF7/target.h @@ -0,0 +1,163 @@ +/* + * 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 . + */ + +#pragma once + +#define TARGET_BOARD_IDENTIFIER "NUC7" + +#define CONFIG_START_FLASH_ADDRESS (0x080C0000) + +#define USBD_PRODUCT_STRING "NucleoF7" + +//#define USE_DSHOT +//#define USE_ESC_TELEMETRY + +#define LED0 PB7 +#define LED1 PB14 + +//#define BEEPER PB2 +//#define BEEPER_INVERTED + +#define ACC +#define USE_FAKE_ACC +#define USE_ACC_MPU6050 +#define ACC_MPU6050_ALIGN CW270_DEG + +#define GYRO +#define USE_FAKE_GYRO +#define USE_GYRO_MPU6050 +#define GYRO_MPU6050_ALIGN CW270_DEG + +// MPU6050 interrupts +#define USE_MPU_DATA_READY_SIGNAL +#define MPU_INT_EXTI PB15 +#define USE_EXTI + +#define MAG +#define USE_FAKE_MAG +#define USE_MAG_HMC5883 +#define MAG_HMC5883_ALIGN CW270_DEG_FLIP + +#define BARO +#define USE_FAKE_BARO +#define USE_BARO_MS5611 + +#define USABLE_TIMER_CHANNEL_COUNT 16 + +#define USE_VCP +#define VBUS_SENSING_PIN PA9 + +//#define USE_UART1 +//#define UART1_RX_PIN PA10 +//#define UART1_TX_PIN PA9 + +#define USE_UART2 +#define UART2_RX_PIN PD6 +#define UART2_TX_PIN PD5 + +#define USE_UART3 +#define UART3_RX_PIN PD9 +#define UART3_TX_PIN PD8 + +#define USE_UART4 +#define UART4_RX_PIN PC11 +#define UART4_TX_PIN PC10 + +#define USE_UART5 +#define UART5_RX_PIN PD2 +#define UART5_TX_PIN PC12 + +#define USE_UART6 +#define UART6_RX_PIN PC7 +#define UART6_TX_PIN PC6 + +#define USE_UART7 +#define UART7_RX_PIN PE7 +#define UART7_TX_PIN PE8 + +#define USE_UART8 +#define UART8_RX_PIN PE0 +#define UART8_TX_PIN PE1 + +#define SERIAL_PORT_COUNT 8 //VCP, USART2, USART3, UART4, UART5, USART6, USART7, USART8 + +#define USE_SPI +#define USE_SPI_DEVICE_1 +#define USE_SPI_DEVICE_4 + +#define SPI1_NSS_PIN PA4 +#define SPI1_SCK_PIN PA5 +#define SPI1_MISO_PIN PA6 +#define SPI1_MOSI_PIN PA7 + +#define SPI4_NSS_PIN PE11 +#define SPI4_SCK_PIN PE12 +#define SPI4_MISO_PIN PE13 +#define SPI4_MOSI_PIN PE14 + +#define USE_SDCARD +#define SDCARD_DETECT_INVERTED +#define SDCARD_DETECT_PIN PF14 +#define SDCARD_DETECT_EXTI_LINE EXTI_Line14 +#define SDCARD_DETECT_EXTI_PIN_SOURCE EXTI_PinSource14 +#define SDCARD_DETECT_EXTI_PORT_SOURCE EXTI_PortSourceGPIOF +#define SDCARD_DETECT_EXTI_IRQn EXTI9_15_IRQn + +#define SDCARD_SPI_INSTANCE SPI4 +#define SDCARD_SPI_CS_PIN SPI4_NSS_PIN + +#define SDCARD_SPI_INITIALIZATION_CLOCK_DIVIDER 256 // 422kHz +// Divide to under 25MHz for normal operation: +#define SDCARD_SPI_FULL_SPEED_CLOCK_DIVIDER 8 // 27MHz + +#define SDCARD_DMA_CHANNEL_TX DMA2_Stream1 +#define SDCARD_DMA_CHANNEL_TX_COMPLETE_FLAG DMA_FLAG_TCIF1_5 +#define SDCARD_DMA_CLK RCC_AHB1Periph_DMA2 +#define SDCARD_DMA_CHANNEL DMA_CHANNEL_4 + +#define USE_I2C +#define I2C_DEVICE (I2CDEV_1) +#define I2C1_SCL PB8 +#define I2C1_SDA PB9 + +//#define I2C_DEVICE_EXT (I2CDEV_2) + +#define SENSORS_SET (SENSOR_ACC|SENSOR_MAG|SENSOR_BARO) + +#define USE_ADC +#define VBAT_ADC_PIN PA3 +#define CURRENT_METER_ADC_PIN PC0 +#define RSSI_ADC_GPIO_PIN PC3 + +#define LED_STRIP + +#define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT + +#define DEFAULT_FEATURES (FEATURE_BLACKBOX) +#define DEFAULT_RX_FEATURE FEATURE_RX_SERIAL +#define SERIALRX_PROVIDER SERIALRX_SBUS + +#define USE_SERIAL_4WAY_BLHELI_INTERFACE + +#define TARGET_IO_PORTA 0xffff +#define TARGET_IO_PORTB 0xffff +#define TARGET_IO_PORTC 0xffff +#define TARGET_IO_PORTD 0xffff +#define TARGET_IO_PORTE 0xffff +#define TARGET_IO_PORTF 0xffff + +#define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(12) | TIM_N(8) | TIM_N(9) | TIM_N(10) | TIM_N(11)) diff --git a/src/main/target/NUCLEOF7/target.mk b/src/main/target/NUCLEOF7/target.mk new file mode 100644 index 000000000..3be893c11 --- /dev/null +++ b/src/main/target/NUCLEOF7/target.mk @@ -0,0 +1,9 @@ +F7X6XG_TARGETS += $(TARGET) +FEATURES += SDCARD VCP + +TARGET_SRC = \ + drivers/accgyro_mpu6050.c \ + drivers/barometer_ms5611.c \ + drivers/compass_hmc5883l.c \ + drivers/light_ws2811strip.c \ + drivers/light_ws2811strip_hal.c diff --git a/src/main/target/link/stm32_flash_f746.ld b/src/main/target/link/stm32_flash_f746.ld new file mode 100644 index 000000000..1b92f2ba3 --- /dev/null +++ b/src/main/target/link/stm32_flash_f746.ld @@ -0,0 +1,28 @@ +/* +***************************************************************************** +** +** File : stm32_flash_f746.ld +** +** Abstract : Linker script for STM32F746VGTx Device with +** 1024KByte FLASH, 320KByte RAM +** +***************************************************************************** +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +/* Specify the memory areas */ +MEMORY +{ + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 768K + FLASH_CONFIG (r) : ORIGIN = 0x080C0000, LENGTH = 256K + + TCM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K + RAM (rwx) : ORIGIN = 0x20010000, LENGTH = 256K + MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K +} +/* note CCM could be used for stack */ +REGION_ALIAS("STACKRAM", TCM) + +INCLUDE "stm32_flash.ld" From aa1ae88ddf55a048c2106fa2840b659119c2a1e1 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Wed, 23 Nov 2016 20:01:20 +0100 Subject: [PATCH 02/30] Gitignore .idea folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 86b85dc44..67e2f3cbe 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ obj/ patches/ startup_stm32f10x_md_gcc.s +.idea # script-generated files docs/Manual.pdf From b53cbbefc3c71e802487ca4d3deecf872c7f5d87 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Wed, 23 Nov 2016 21:58:29 +0100 Subject: [PATCH 03/30] Moved ESC telemetry to sensors --- Makefile | 2 +- src/main/build/debug.h | 2 +- src/main/fc/config.h | 2 +- src/main/fc/fc_tasks.c | 29 ++-- src/main/io/serial_cli.c | 4 +- src/main/main.c | 8 +- src/main/scheduler/scheduler.h | 4 +- src/main/sensors/battery.c | 33 ++-- .../esc_telemetry.c => sensors/esc_sensor.c} | 142 +++++++++--------- src/main/sensors/esc_sensor.h | 10 ++ src/main/target/ANYFCF7/target.h | 2 +- src/main/target/BETAFLIGHTF3/target.h | 3 +- src/main/target/BLUEJAYF4/target.h | 3 +- src/main/target/DOGE/target.h | 3 +- src/main/target/FURYF3/target.h | 3 +- src/main/target/FURYF4/target.h | 3 +- src/main/target/FURYF7/target.h | 2 +- src/main/target/IMPULSERCF3/target.h | 3 +- src/main/target/KISSFC/target.h | 3 +- src/main/target/LUX_RACE/target.h | 3 +- src/main/target/MOTOLAB/target.h | 3 +- src/main/target/MULTIFLITEPICO/target.h | 3 +- src/main/target/OMNIBUS/target.h | 3 +- src/main/target/OMNIBUSF4/target.h | 3 +- src/main/target/REVO/target.h | 3 +- src/main/target/SPARKY2/target.h | 3 +- src/main/target/SPRACINGF3/target.h | 3 +- src/main/target/SPRACINGF3EVO/target.h | 3 +- src/main/target/STM32F3DISCOVERY/target.h | 3 +- src/main/target/X_RACERSPI/target.h | 3 +- src/main/telemetry/esc_telemetry.h | 12 -- src/main/telemetry/frsky.c | 2 +- src/main/telemetry/smartport.c | 4 +- 33 files changed, 154 insertions(+), 158 deletions(-) rename src/main/{telemetry/esc_telemetry.c => sensors/esc_sensor.c} (54%) create mode 100644 src/main/sensors/esc_sensor.h delete mode 100644 src/main/telemetry/esc_telemetry.h diff --git a/Makefile b/Makefile index f2edc40d5..58d269cca 100644 --- a/Makefile +++ b/Makefile @@ -593,7 +593,7 @@ HIGHEND_SRC = \ telemetry/smartport.c \ telemetry/ltm.c \ telemetry/mavlink.c \ - telemetry/esc_telemetry.c \ + sensors/esc_sensor.c \ ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS))) VCP_SRC = \ diff --git a/src/main/build/debug.h b/src/main/build/debug.h index 6b2e7ca9f..cd6fc1d78 100644 --- a/src/main/build/debug.h +++ b/src/main/build/debug.h @@ -59,7 +59,7 @@ typedef enum { DEBUG_VELOCITY, DEBUG_DTERM_FILTER, DEBUG_ANGLERATE, - DEBUG_ESC_TELEMETRY, + DEBUG_ESC_SENSOR, DEBUG_SCHEDULER, DEBUG_STACK, DEBUG_COUNT diff --git a/src/main/fc/config.h b/src/main/fc/config.h index c5fe4ecf6..0fe4f9e61 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -55,7 +55,7 @@ typedef enum { FEATURE_VTX = 1 << 24, FEATURE_RX_SPI = 1 << 25, FEATURE_SOFTSPI = 1 << 26, - FEATURE_ESC_TELEMETRY = 1 << 27 + FEATURE_ESC_SENSOR = 1 << 27, } features_e; void beeperOffSet(uint32_t mask); diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index f043290f6..c795c18d8 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -63,11 +63,11 @@ #include "sensors/compass.h" #include "sensors/gyro.h" #include "sensors/sonar.h" +#include "sensors/esc_sensor.h" #include "scheduler/scheduler.h" #include "telemetry/telemetry.h" -#include "telemetry/esc_telemetry.h" #include "config/feature.h" #include "config/config_profile.h" @@ -111,7 +111,7 @@ static void taskUpdateBattery(timeUs_t currentTimeUs) { #ifdef USE_ADC static uint32_t vbatLastServiced = 0; - if (feature(FEATURE_VBAT) || feature(FEATURE_ESC_TELEMETRY)) { + if (feature(FEATURE_VBAT) || feature(FEATURE_ESC_SENSOR)) { if (cmp32(currentTimeUs, vbatLastServiced) >= VBATINTERVAL) { vbatLastServiced = currentTimeUs; updateBattery(); @@ -120,7 +120,7 @@ static void taskUpdateBattery(timeUs_t currentTimeUs) #endif static uint32_t ibatLastServiced = 0; - if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_TELEMETRY)) { + if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_SENSOR)) { const int32_t ibatTimeSinceLastServiced = cmp32(currentTimeUs, ibatLastServiced); if (ibatTimeSinceLastServiced >= IBATINTERVAL) { @@ -203,15 +203,6 @@ static void taskTelemetry(timeUs_t currentTimeUs) } #endif -#ifdef USE_ESC_TELEMETRY -static void taskEscTelemetry(timeUs_t currentTimeUs) -{ - if (feature(FEATURE_ESC_TELEMETRY)) { - escTelemetryProcess(currentTimeUs); - } - } -#endif - void fcTasksInit(void) { schedulerInit(); @@ -277,8 +268,8 @@ void fcTasksInit(void) #ifdef USE_BST setTaskEnabled(TASK_BST_MASTER_PROCESS, true); #endif -#ifdef USE_ESC_TELEMETRY - setTaskEnabled(TASK_ESC_TELEMETRY, feature(FEATURE_ESC_TELEMETRY)); +#ifdef USE_ESC_SENSOR + setTaskEnabled(TASK_ESC_SENSOR, feature(FEATURE_ESC_SENSOR)); #endif #ifdef CMS #ifdef USE_MSP_DISPLAYPORT @@ -450,11 +441,11 @@ cfTask_t cfTasks[TASK_COUNT] = { }, #endif -#ifdef USE_ESC_TELEMETRY - [TASK_ESC_TELEMETRY] = { - .taskName = "ESC_TELEMETRY", - .taskFunc = taskEscTelemetry, - .desiredPeriod = 1000000 / 100, // 100 Hz +#ifdef USE_ESC_SENSOR + [TASK_ESC_SENSOR] = { + .taskName = "ESC_SENSOR", + .taskFunc = escSensorProcess, + .desiredPeriod = TASK_PERIOD_HZ(100), // 100 Hz every 10ms .staticPriority = TASK_PRIORITY_LOW, }, #endif diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 159df98af..25eaecb8f 100755 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -234,7 +234,7 @@ static const char * const featureNames[] = { "SONAR", "TELEMETRY", "CURRENT_METER", "3D", "RX_PARALLEL_PWM", "RX_MSP", "RSSI_ADC", "LED_STRIP", "DISPLAY", "OSD", "BLACKBOX", "CHANNEL_FORWARDING", "TRANSPONDER", "AIRMODE", - "SDCARD", "VTX", "RX_SPI", "SOFTSPI", "ESC_TELEMETRY", NULL + "SDCARD", "VTX", "RX_SPI", "SOFTSPI", "ESC_SENSOR", NULL }; // sync this with rxFailsafeChannelMode_e @@ -519,7 +519,7 @@ static const char * const lookupTableDebug[DEBUG_COUNT] = { "VELOCITY", "DFILTER", "ANGLERATE", - "ESC_TELEMETRY", + "ESC_SENSOR", "SCHEDULER", }; diff --git a/src/main/main.c b/src/main/main.c index cf1060a54..d87052746 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -104,7 +104,7 @@ #include "sensors/initialisation.h" #include "telemetry/telemetry.h" -#include "telemetry/esc_telemetry.h" +#include "sensors/esc_sensor.h" #include "flight/pid.h" #include "flight/imu.h" @@ -493,9 +493,9 @@ void init(void) } #endif -#ifdef USE_ESC_TELEMETRY - if (feature(FEATURE_ESC_TELEMETRY)) { - escTelemetryInit(); +#ifdef USE_ESC_SENSOR + if (feature(FEATURE_ESC_SENSOR)) { + escSensorInit(); } #endif diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index 36f5559ef..133943a3f 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -94,8 +94,8 @@ typedef enum { #ifdef USE_BST TASK_BST_MASTER_PROCESS, #endif -#ifdef USE_ESC_TELEMETRY - TASK_ESC_TELEMETRY, +#ifdef USE_ESC_SENSOR + TASK_ESC_SENSOR, #endif #ifdef CMS TASK_CMS, diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index 3a8a59a8a..a240570fc 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -34,8 +34,7 @@ #include "config/feature.h" #include "sensors/battery.h" - -#include "telemetry/esc_telemetry.h" +#include "sensors/esc_sensor.h" #include "fc/rc_controls.h" #include "io/beeper.h" @@ -84,9 +83,9 @@ static void updateBatteryVoltage(void) vBatFilterIsInitialised = true; } - #ifdef USE_ESC_TELEMETRY - if (batteryConfig->batteryMeterType == BATTERY_SENSOR_ESC && isEscTelemetryActive()) { - vbatLatest = getEscTelemetryVbat(); + #ifdef USE_ESC_SENSOR + if (feature(FEATURE_ESC_SENSOR) && batteryConfig->batteryMeterType == BATTERY_SENSOR_ESC) { + vbatLatest = getEscSensorVbat(); if (debugMode == DEBUG_BATTERY) { debug[0] = -1; } @@ -270,11 +269,9 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea updateCurrentDrawn(lastUpdateAt); - updateConsumptionWarning(); - break; case CURRENT_SENSOR_VIRTUAL: - amperageLatest = (int32_t)batteryConfig->currentMeterOffset; + amperage = (int32_t)batteryConfig->currentMeterOffset; if (ARMING_FLAG(ARMED)) { throttleStatus_e throttleStatus = calculateThrottleStatus(rxConfig, deadband3d_throttle); int throttleOffset = (int32_t)rcCommand[THROTTLE] - 1000; @@ -282,30 +279,24 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea throttleOffset = 0; } int throttleFactor = throttleOffset + (throttleOffset * throttleOffset / 50); - amperageLatest += throttleFactor * (int32_t)batteryConfig->currentMeterScale / 1000; + amperage += throttleFactor * (int32_t)batteryConfig->currentMeterScale / 1000; } - amperage = amperageLatest; updateCurrentDrawn(lastUpdateAt); - updateConsumptionWarning(); - break; case CURRENT_SENSOR_ESC: - #ifdef USE_ESC_TELEMETRY - if (isEscTelemetryActive()) { - amperageLatest = getEscTelemetryCurrent(); - amperage = amperageLatest; - mAhDrawn = getEscTelemetryConsumption(); + #ifdef USE_ESC_SENSOR + if (feature(FEATURE_ESC_SENSOR)) + { + amperage = getEscSensorCurrent(); + mAhDrawn = getEscSensorConsumption(); - updateConsumptionWarning(); + updateCurrentDrawn(lastUpdateAt); } - - break; #endif case CURRENT_SENSOR_NONE: amperage = 0; - amperageLatest = 0; break; } diff --git a/src/main/telemetry/esc_telemetry.c b/src/main/sensors/esc_sensor.c similarity index 54% rename from src/main/telemetry/esc_telemetry.c rename to src/main/sensors/esc_sensor.c index 0bde741ab..0e2e562ce 100644 --- a/src/main/telemetry/esc_telemetry.c +++ b/src/main/sensors/esc_sensor.c @@ -21,7 +21,7 @@ #include "sensors/battery.h" -#include "esc_telemetry.h" +#include "esc_sensor.h" #include "build/debug.h" @@ -68,64 +68,64 @@ typedef struct { } esc_telemetry_t; typedef enum { - ESC_TLM_FRAME_PENDING = 1 << 0, // 1 - ESC_TLM_FRAME_COMPLETE = 1 << 1 // 2 + ESC_SENSOR_FRAME_PENDING = 1 << 0, // 1 + ESC_SENSOR_FRAME_COMPLETE = 1 << 1 // 2 } escTlmFrameState_t; typedef enum { - ESC_TLM_TRIGGER_WAIT = 0, - ESC_TLM_TRIGGER_READY = 1 << 0, // 1 - ESC_TLM_TRIGGER_PENDING = 1 << 1 // 2 -} escTlmTriggerState_t; + ESC_SENSOR_TRIGGER_WAIT = 0, + ESC_SENSOR_TRIGGER_READY = 1 << 0, // 1 + ESC_SENSOR_TRIGGER_PENDING = 1 << 1, // 2 +} escSensorTriggerState_t; -#define ESC_TLM_BAUDRATE 115200 -#define ESC_TLM_BUFFSIZE 10 +#define ESC_SENSOR_BAUDRATE 115200 +#define ESC_SENSOR_BUFFSIZE 10 #define ESC_BOOTTIME 5000 // 5 seconds #define ESC_REQUEST_TIMEOUT 100 // 100 ms (data transfer takes only 900us) static bool tlmFrameDone = false; -static uint8_t tlm[ESC_TLM_BUFFSIZE] = { 0, }; +static uint8_t tlm[ESC_SENSOR_BUFFSIZE] = { 0, }; static uint8_t tlmFramePosition = 0; -static serialPort_t *escTelemetryPort = NULL; -static esc_telemetry_t escTelemetryData[MAX_SUPPORTED_MOTORS]; +static serialPort_t *escSensorPort = NULL; +static esc_telemetry_t escSensorData[MAX_SUPPORTED_MOTORS]; static uint32_t escTriggerTimestamp = -1; static uint32_t escTriggerLastTimestamp = -1; static uint8_t timeoutRetryCount = 0; -static uint8_t escTelemetryMotor = 0; // motor index -static bool escTelemetryEnabled = false; -static escTlmTriggerState_t escTelemetryTriggerState = ESC_TLM_TRIGGER_WAIT; +static uint8_t escSensorMotor = 0; // motor index +static bool escSensorEnabled = false; +static escSensorTriggerState_t escSensorTriggerState = ESC_SENSOR_TRIGGER_WAIT; static int16_t escVbat = 0; static int16_t escCurrent = 0; static int16_t escConsumption = 0; -static void escTelemetryDataReceive(uint16_t c); +static void escSensorDataReceive(uint16_t c); static uint8_t update_crc8(uint8_t crc, uint8_t crc_seed); static uint8_t get_crc8(uint8_t *Buf, uint8_t BufLen); static void selectNextMotor(void); -bool isEscTelemetryActive(void) +bool isEscSensorActive(void) { - return escTelemetryEnabled; + return escSensorEnabled; } -int16_t getEscTelemetryVbat(void) +int16_t getEscSensorVbat(void) { return escVbat / 10; } -int16_t getEscTelemetryCurrent(void) +int16_t getEscSensorCurrent(void) { return escCurrent; } -int16_t getEscTelemetryConsumption(void) +int16_t getEscSensorConsumption(void) { return escConsumption; } -bool escTelemetryInit(void) +bool escSensorInit(void) { serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_TELEMETRY_ESC); if (!portConfig) { @@ -135,35 +135,33 @@ bool escTelemetryInit(void) portOptions_t options = (SERIAL_NOT_INVERTED); // Initialize serial port - escTelemetryPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_ESC, escTelemetryDataReceive, ESC_TLM_BAUDRATE, MODE_RX, options); + escSensorPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_ESC, escSensorDataReceive, ESC_SENSOR_BAUDRATE, MODE_RX, options); - if (escTelemetryPort) { - escTelemetryEnabled = true; - batteryConfig()->currentMeterType = CURRENT_SENSOR_ESC; - batteryConfig()->batteryMeterType = BATTERY_SENSOR_ESC; + if (escSensorPort) { + escSensorEnabled = true; } - return escTelemetryPort != NULL; + return escSensorPort != NULL; } -void freeEscTelemetryPort(void) +void freeEscSensorPort(void) { - closeSerialPort(escTelemetryPort); - escTelemetryPort = NULL; - escTelemetryEnabled = false; + closeSerialPort(escSensorPort); + escSensorPort = NULL; + escSensorEnabled = false; } // Receive ISR callback -static void escTelemetryDataReceive(uint16_t c) +static void escSensorDataReceive(uint16_t c) { // KISS ESC sends some data during startup, ignore this for now (maybe future use) // startup data could be firmware version and serialnumber - if (escTelemetryTriggerState == ESC_TLM_TRIGGER_WAIT) return; + if (escSensorTriggerState == ESC_SENSOR_TRIGGER_WAIT) return; tlm[tlmFramePosition] = (uint8_t)c; - if (tlmFramePosition == ESC_TLM_BUFFSIZE - 1) { + if (tlmFramePosition == ESC_SENSOR_BUFFSIZE - 1) { tlmFrameDone = true; tlmFramePosition = 0; } else { @@ -171,9 +169,9 @@ static void escTelemetryDataReceive(uint16_t c) } } -uint8_t escTelemetryFrameStatus(void) +uint8_t escSensorFrameStatus(void) { - uint8_t frameStatus = ESC_TLM_FRAME_PENDING; + uint8_t frameStatus = ESC_SENSOR_FRAME_PENDING; uint16_t chksum, tlmsum; if (!tlmFrameDone) { @@ -183,28 +181,28 @@ uint8_t escTelemetryFrameStatus(void) tlmFrameDone = false; // Get CRC8 checksum - chksum = get_crc8(tlm, ESC_TLM_BUFFSIZE - 1); - tlmsum = tlm[ESC_TLM_BUFFSIZE - 1]; // last byte contains CRC value + chksum = get_crc8(tlm, ESC_SENSOR_BUFFSIZE - 1); + tlmsum = tlm[ESC_SENSOR_BUFFSIZE - 1]; // last byte contains CRC value if (chksum == tlmsum) { - escTelemetryData[escTelemetryMotor].skipped = false; - escTelemetryData[escTelemetryMotor].temperature = tlm[0]; - escTelemetryData[escTelemetryMotor].voltage = tlm[1] << 8 | tlm[2]; - escTelemetryData[escTelemetryMotor].current = tlm[3] << 8 | tlm[4]; - escTelemetryData[escTelemetryMotor].consumption = tlm[5] << 8 | tlm[6]; - escTelemetryData[escTelemetryMotor].rpm = tlm[7] << 8 | tlm[8]; + escSensorData[escSensorMotor].skipped = false; + escSensorData[escSensorMotor].temperature = tlm[0]; + escSensorData[escSensorMotor].voltage = tlm[1] << 8 | tlm[2]; + escSensorData[escSensorMotor].current = tlm[3] << 8 | tlm[4]; + escSensorData[escSensorMotor].consumption = tlm[5] << 8 | tlm[6]; + escSensorData[escSensorMotor].rpm = tlm[7] << 8 | tlm[8]; - frameStatus = ESC_TLM_FRAME_COMPLETE; + frameStatus = ESC_SENSOR_FRAME_COMPLETE; } return frameStatus; } -void escTelemetryProcess(timeUs_t currentTimeUs) +void escSensorProcess(timeUs_t currentTimeUs) { const timeMs_t currentTimeMs = currentTimeUs / 1000; - if (!escTelemetryEnabled) { + if (!escSensorEnabled) { return; } @@ -212,66 +210,66 @@ void escTelemetryProcess(timeUs_t currentTimeUs) if (millis() < ESC_BOOTTIME) { return; } - else if (escTelemetryTriggerState == ESC_TLM_TRIGGER_WAIT) { + else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_WAIT) { // Ready for starting requesting telemetry - escTelemetryTriggerState = ESC_TLM_TRIGGER_READY; - escTelemetryMotor = 0; + escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; + escSensorMotor = 0; escTriggerTimestamp = currentTimeMs; escTriggerLastTimestamp = escTriggerTimestamp; } - else if (escTelemetryTriggerState == ESC_TLM_TRIGGER_READY) { - if (debugMode == DEBUG_ESC_TELEMETRY) debug[0] = escTelemetryMotor+1; + else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_READY) { + if (debugMode == DEBUG_ESC_SENSOR) debug[0] = escSensorMotor+1; - motorDmaOutput_t * const motor = getMotorDmaOutput(escTelemetryMotor); + motorDmaOutput_t * const motor = getMotorDmaOutput(escSensorMotor); motor->requestTelemetry = true; - escTelemetryTriggerState = ESC_TLM_TRIGGER_PENDING; + escSensorTriggerState = ESC_SENSOR_TRIGGER_PENDING; } if (escTriggerTimestamp + ESC_REQUEST_TIMEOUT < currentTimeMs) { // ESC did not repond in time, retry timeoutRetryCount++; escTriggerTimestamp = currentTimeMs; - escTelemetryTriggerState = ESC_TLM_TRIGGER_READY; + escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; if (timeoutRetryCount == 4) { // Not responding after 3 times, skip motor - escTelemetryData[escTelemetryMotor].skipped = true; + escSensorData[escSensorMotor].skipped = true; selectNextMotor(); } - if (debugMode == DEBUG_ESC_TELEMETRY) debug[1]++; + if (debugMode == DEBUG_ESC_SENSOR) debug[1]++; } // Get received frame status - uint8_t state = escTelemetryFrameStatus(); + uint8_t state = escSensorFrameStatus(); - if (state == ESC_TLM_FRAME_COMPLETE) { + if (state == ESC_SENSOR_FRAME_COMPLETE) { // Wait until all ESCs are processed - if (escTelemetryMotor == getMotorCount()-1) { + if (escSensorMotor == getMotorCount()-1) { escCurrent = 0; escConsumption = 0; escVbat = 0; for (int i = 0; i < getMotorCount(); i++) { - if (!escTelemetryData[i].skipped) { - escVbat = i > 0 ? ((escVbat + escTelemetryData[i].voltage) / 2) : escTelemetryData[i].voltage; - escCurrent = escCurrent + escTelemetryData[i].current; - escConsumption = escConsumption + escTelemetryData[i].consumption; + if (!escSensorData[i].skipped) { + escVbat = i > 0 ? ((escVbat + escSensorData[i].voltage) / 2) : escSensorData[i].voltage; + escCurrent = escCurrent + escSensorData[i].current; + escConsumption = escConsumption + escSensorData[i].consumption; } } } - if (debugMode == DEBUG_ESC_TELEMETRY) debug[2] = escVbat; - if (debugMode == DEBUG_ESC_TELEMETRY) debug[3] = escCurrent; + if (debugMode == DEBUG_ESC_SENSOR) debug[2] = escVbat; + if (debugMode == DEBUG_ESC_SENSOR) debug[3] = escCurrent; selectNextMotor(); - escTelemetryTriggerState = ESC_TLM_TRIGGER_READY; + escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; } if (escTriggerLastTimestamp + 10000 < currentTimeMs) { // ESCs did not respond for 10 seconds // Disable ESC telemetry and fallback to onboard vbat sensor - freeEscTelemetryPort(); + freeEscSensorPort(); escVbat = 0; escCurrent = 0; escConsumption = 0; @@ -280,9 +278,9 @@ void escTelemetryProcess(timeUs_t currentTimeUs) static void selectNextMotor(void) { - escTelemetryMotor++; - if (escTelemetryMotor == getMotorCount()) { - escTelemetryMotor = 0; + escSensorMotor++; + if (escSensorMotor == getMotorCount()) { + escSensorMotor = 0; } escTriggerTimestamp = millis(); escTriggerLastTimestamp = escTriggerTimestamp; diff --git a/src/main/sensors/esc_sensor.h b/src/main/sensors/esc_sensor.h new file mode 100644 index 000000000..4ea61ee13 --- /dev/null +++ b/src/main/sensors/esc_sensor.h @@ -0,0 +1,10 @@ +#pragma once + +uint8_t escSensorFrameStatus(void); +bool escSensorInit(void); +bool isEscSensorActive(void); +int16_t getEscSensorVbat(void); +int16_t getEscSensorCurrent(void); +int16_t getEscSensorConsumption(void); + +void escSensorProcess(uint32_t currentTime); diff --git a/src/main/target/ANYFCF7/target.h b/src/main/target/ANYFCF7/target.h index bea085ae9..007488d4f 100644 --- a/src/main/target/ANYFCF7/target.h +++ b/src/main/target/ANYFCF7/target.h @@ -24,7 +24,7 @@ #define USBD_PRODUCT_STRING "AnyFCF7" #define USE_DSHOT -#define USE_ESC_TELEMETRY +#define USE_ESC_SENSOR #define LED0 PB7 #define LED1 PB6 diff --git a/src/main/target/BETAFLIGHTF3/target.h b/src/main/target/BETAFLIGHTF3/target.h index f22a23573..bfd47caef 100755 --- a/src/main/target/BETAFLIGHTF3/target.h +++ b/src/main/target/BETAFLIGHTF3/target.h @@ -44,7 +44,8 @@ #define MPU_INT_EXTI PC13 #define USE_EXTI -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM16_DMA #define REMAP_TIM17_DMA diff --git a/src/main/target/BLUEJAYF4/target.h b/src/main/target/BLUEJAYF4/target.h index ad588a23a..5ab4925f4 100644 --- a/src/main/target/BLUEJAYF4/target.h +++ b/src/main/target/BLUEJAYF4/target.h @@ -144,7 +144,8 @@ #define USE_ADC #define VBAT_ADC_PIN PC3 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define LED_STRIP #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT diff --git a/src/main/target/DOGE/target.h b/src/main/target/DOGE/target.h index 5b360ed8d..1f10fcb0f 100644 --- a/src/main/target/DOGE/target.h +++ b/src/main/target/DOGE/target.h @@ -125,7 +125,8 @@ #define ENSURE_MPU_DATA_READY_IS_LOW #define LED_STRIP -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define DEFAULT_RX_FEATURE FEATURE_RX_PPM diff --git a/src/main/target/FURYF3/target.h b/src/main/target/FURYF3/target.h index a858e9732..5497f9021 100644 --- a/src/main/target/FURYF3/target.h +++ b/src/main/target/FURYF3/target.h @@ -161,7 +161,8 @@ #define USE_SERIAL_4WAY_BLHELI_INTERFACE -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA #define TARGET_IO_PORTA 0xffff diff --git a/src/main/target/FURYF4/target.h b/src/main/target/FURYF4/target.h index 790d3096d..4d35a98fb 100644 --- a/src/main/target/FURYF4/target.h +++ b/src/main/target/FURYF4/target.h @@ -175,7 +175,8 @@ #define USE_SERIAL_4WAY_BLHELI_INTERFACE -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define TARGET_IO_PORTA 0xffff #define TARGET_IO_PORTB 0xffff diff --git a/src/main/target/FURYF7/target.h b/src/main/target/FURYF7/target.h index 35410dff5..2cbffeaed 100644 --- a/src/main/target/FURYF7/target.h +++ b/src/main/target/FURYF7/target.h @@ -24,7 +24,7 @@ #define USBD_PRODUCT_STRING "FuryF7" #define USE_DSHOT -#define USE_ESC_TELEMETRY +#define USE_ESC_SENSOR #define LED0 PB5 #define LED1 PB4 diff --git a/src/main/target/IMPULSERCF3/target.h b/src/main/target/IMPULSERCF3/target.h index 9689883a5..79382b81c 100644 --- a/src/main/target/IMPULSERCF3/target.h +++ b/src/main/target/IMPULSERCF3/target.h @@ -46,7 +46,8 @@ #define USE_FLASHFS #define USE_FLASH_M25P16 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA #define USE_VCP diff --git a/src/main/target/KISSFC/target.h b/src/main/target/KISSFC/target.h index 2551072af..b7a523d9c 100644 --- a/src/main/target/KISSFC/target.h +++ b/src/main/target/KISSFC/target.h @@ -23,7 +23,8 @@ #define SBUS_PORT_OPTIONS (SERIAL_STOPBITS_2 | SERIAL_PARITY_EVEN | SERIAL_INVERTED | SERIAL_BIDIR) -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define USE_ESCSERIAL #define ESCSERIAL_TIMER_TX_HARDWARE 6 diff --git a/src/main/target/LUX_RACE/target.h b/src/main/target/LUX_RACE/target.h index fa6eb8a9f..a6ca94cd7 100644 --- a/src/main/target/LUX_RACE/target.h +++ b/src/main/target/LUX_RACE/target.h @@ -46,7 +46,8 @@ #define USE_MPU_DATA_READY_SIGNAL #define ENSURE_MPU_DATA_READY_IS_LOW -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define USE_SPI #define USE_SPI_DEVICE_1 diff --git a/src/main/target/MOTOLAB/target.h b/src/main/target/MOTOLAB/target.h index ef18dbd7c..52a6bebef 100644 --- a/src/main/target/MOTOLAB/target.h +++ b/src/main/target/MOTOLAB/target.h @@ -95,7 +95,8 @@ #define RSSI_ADC_PIN PB2 #define LED_STRIP -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define SPEKTRUM_BIND // USART2, PB4 diff --git a/src/main/target/MULTIFLITEPICO/target.h b/src/main/target/MULTIFLITEPICO/target.h index e56633eaf..7e5a0f045 100755 --- a/src/main/target/MULTIFLITEPICO/target.h +++ b/src/main/target/MULTIFLITEPICO/target.h @@ -105,7 +105,8 @@ #define CURRENT_METER_ADC_PIN PA5 #define RSSI_ADC_PIN PB2 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA // UART1 TX uses DMA1_Channel4, which is also used by dshot on motor 4 diff --git a/src/main/target/OMNIBUS/target.h b/src/main/target/OMNIBUS/target.h index 166a57035..560858c50 100644 --- a/src/main/target/OMNIBUS/target.h +++ b/src/main/target/OMNIBUS/target.h @@ -128,7 +128,8 @@ // Divide to under 25MHz for normal operation: #define SDCARD_SPI_FULL_SPEED_CLOCK_DIVIDER 2 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR // DSHOT output 4 uses DMA1_Channel5, so don't use it for the SDCARD until we find an alternative #ifndef USE_DSHOT diff --git a/src/main/target/OMNIBUSF4/target.h b/src/main/target/OMNIBUSF4/target.h index 597091dbc..d83800187 100644 --- a/src/main/target/OMNIBUSF4/target.h +++ b/src/main/target/OMNIBUSF4/target.h @@ -155,7 +155,8 @@ #define VBAT_ADC_PIN PC2 //#define RSSI_ADC_PIN PA0 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define LED_STRIP diff --git a/src/main/target/REVO/target.h b/src/main/target/REVO/target.h index 710590d1d..b01bc2466 100644 --- a/src/main/target/REVO/target.h +++ b/src/main/target/REVO/target.h @@ -41,7 +41,8 @@ #endif -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define LED0 PB5 // Disable LED1, conflicts with AirbotF4/Flip32F4/Revolt beeper diff --git a/src/main/target/SPARKY2/target.h b/src/main/target/SPARKY2/target.h index 5a33df421..f404c6ac4 100644 --- a/src/main/target/SPARKY2/target.h +++ b/src/main/target/SPARKY2/target.h @@ -35,7 +35,8 @@ #define INVERTER PC6 #define INVERTER_USART USART6 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR // MPU9250 interrupt #define USE_EXTI diff --git a/src/main/target/SPRACINGF3/target.h b/src/main/target/SPRACINGF3/target.h index 3d906295e..40e65a5c5 100644 --- a/src/main/target/SPRACINGF3/target.h +++ b/src/main/target/SPRACINGF3/target.h @@ -115,7 +115,8 @@ #define CURRENT_METER_ADC_PIN PA5 #define RSSI_ADC_PIN PB2 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA // UART1 TX uses DMA1_Channel4, which is also used by dshot on motor 4 diff --git a/src/main/target/SPRACINGF3EVO/target.h b/src/main/target/SPRACINGF3EVO/target.h index ce7e3b368..eb2d21437 100755 --- a/src/main/target/SPRACINGF3EVO/target.h +++ b/src/main/target/SPRACINGF3EVO/target.h @@ -35,7 +35,8 @@ #define USE_MAG_DATA_READY_SIGNAL #define ENSURE_MAG_DATA_READY_IS_HIGH -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define GYRO #define USE_GYRO_SPI_MPU6500 diff --git a/src/main/target/STM32F3DISCOVERY/target.h b/src/main/target/STM32F3DISCOVERY/target.h index a43b50faf..1e7670eb3 100644 --- a/src/main/target/STM32F3DISCOVERY/target.h +++ b/src/main/target/STM32F3DISCOVERY/target.h @@ -169,7 +169,8 @@ #define RSSI_ADC_PIN PC2 #define EXTERNAL1_ADC_PIN PC3 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define LED_STRIP diff --git a/src/main/target/X_RACERSPI/target.h b/src/main/target/X_RACERSPI/target.h index 8ade29012..f530e660f 100644 --- a/src/main/target/X_RACERSPI/target.h +++ b/src/main/target/X_RACERSPI/target.h @@ -101,7 +101,8 @@ #define CURRENT_METER_ADC_PIN PA5 #define RSSI_ADC_PIN PB2 -#define USE_ESC_TELEMETRY +#define USE_DSHOT +#define USE_ESC_SENSOR #define REMAP_TIM17_DMA // UART1 TX uses DMA1_Channel4, which is also used by dshot on motor 4 diff --git a/src/main/telemetry/esc_telemetry.h b/src/main/telemetry/esc_telemetry.h deleted file mode 100644 index ca9c2a227..000000000 --- a/src/main/telemetry/esc_telemetry.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "common/time.h" - -uint8_t escTelemetryFrameStatus(void); -bool escTelemetryInit(void); -bool isEscTelemetryActive(void); -int16_t getEscTelemetryVbat(void); -int16_t getEscTelemetryCurrent(void); -int16_t getEscTelemetryConsumption(void); - -void escTelemetryProcess(timeUs_t currentTimeUs); diff --git a/src/main/telemetry/frsky.c b/src/main/telemetry/frsky.c index c2a5c0e5d..5f1700bea 100644 --- a/src/main/telemetry/frsky.c +++ b/src/main/telemetry/frsky.c @@ -529,7 +529,7 @@ void handleFrSkyTelemetry(rxConfig_t *rxConfig, uint16_t deadband3d_throttle) sendTemperature1(); sendThrottleOrBatterySizeAsRpm(rxConfig, deadband3d_throttle); - if ((feature(FEATURE_VBAT) || feature(FEATURE_ESC_TELEMETRY)) && batteryCellCount > 0) { + if ((feature(FEATURE_VBAT) || feature(FEATURE_ESC_SENSOR)) && batteryCellCount > 0) { sendVoltage(); sendVoltageAmp(); sendAmperage(); diff --git a/src/main/telemetry/smartport.c b/src/main/telemetry/smartport.c index 496013f14..4d1d19718 100644 --- a/src/main/telemetry/smartport.c +++ b/src/main/telemetry/smartport.c @@ -646,7 +646,7 @@ void handleSmartPortTelemetry(void) } break; case FSSP_DATAID_CURRENT : - if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_TELEMETRY)) { + if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_SENSOR)) { smartPortSendPackage(id, amperage / 10); // given in 10mA steps, unknown requested unit smartPortHasRequest = 0; } @@ -659,7 +659,7 @@ void handleSmartPortTelemetry(void) } break; case FSSP_DATAID_FUEL : - if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_TELEMETRY)) { + if (feature(FEATURE_CURRENT_METER) || feature(FEATURE_ESC_SENSOR)) { smartPortSendPackage(id, mAhDrawn); // given in mAh, unknown requested unit smartPortHasRequest = 0; } From 1561481e521ae06ec4cda41b65024eb0c2fde6f1 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Wed, 23 Nov 2016 22:44:22 +0100 Subject: [PATCH 04/30] Enable battery task when ESC sensor is available --- src/main/fc/fc_tasks.c | 2 +- src/main/sensors/battery.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index c795c18d8..cb04a8f23 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -109,7 +109,7 @@ static void taskHandleSerial(timeUs_t currentTimeUs) static void taskUpdateBattery(timeUs_t currentTimeUs) { -#ifdef USE_ADC +#if defined(USE_ADC) || defined(USE_ESC_SENSOR) static uint32_t vbatLastServiced = 0; if (feature(FEATURE_VBAT) || feature(FEATURE_ESC_SENSOR)) { if (cmp32(currentTimeUs, vbatLastServiced) >= VBATINTERVAL) { diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index a240570fc..e9591610a 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -295,6 +295,8 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea updateCurrentDrawn(lastUpdateAt); } #endif + + break; case CURRENT_SENSOR_NONE: amperage = 0; From 036c7d0c8986b64dd196253ee3eff81ed0654ba3 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Wed, 23 Nov 2016 23:51:57 +0100 Subject: [PATCH 05/30] Fixed review comments --- src/main/sensors/esc_sensor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/sensors/esc_sensor.c b/src/main/sensors/esc_sensor.c index 0e2e562ce..ee0217507 100644 --- a/src/main/sensors/esc_sensor.c +++ b/src/main/sensors/esc_sensor.c @@ -91,6 +91,7 @@ static esc_telemetry_t escSensorData[MAX_SUPPORTED_MOTORS]; static uint32_t escTriggerTimestamp = -1; static uint32_t escTriggerLastTimestamp = -1; static uint8_t timeoutRetryCount = 0; +static uint8_t totalRetryCount = 0; static uint8_t escSensorMotor = 0; // motor index static bool escSensorEnabled = false; @@ -218,7 +219,7 @@ void escSensorProcess(timeUs_t currentTimeUs) escTriggerLastTimestamp = escTriggerTimestamp; } else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_READY) { - if (debugMode == DEBUG_ESC_SENSOR) debug[0] = escSensorMotor+1; + DEBUG_SET(DEBUG_ESC_SENSOR, 0, escSensorMotor+1); motorDmaOutput_t * const motor = getMotorDmaOutput(escSensorMotor); motor->requestTelemetry = true; @@ -237,7 +238,7 @@ void escSensorProcess(timeUs_t currentTimeUs) selectNextMotor(); } - if (debugMode == DEBUG_ESC_SENSOR) debug[1]++; + DEBUG_SET(DEBUG_ESC_SENSOR, 1, ++totalRetryCount); } // Get received frame status @@ -259,8 +260,8 @@ void escSensorProcess(timeUs_t currentTimeUs) } } - if (debugMode == DEBUG_ESC_SENSOR) debug[2] = escVbat; - if (debugMode == DEBUG_ESC_SENSOR) debug[3] = escCurrent; + DEBUG_SET(DEBUG_ESC_SENSOR, 2, escVbat); + DEBUG_SET(DEBUG_ESC_SENSOR, 3, escCurrent); selectNextMotor(); escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; From 7e26afddf13795d954a9e3e6e2fbf07a2e9e9ad8 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Thu, 24 Nov 2016 20:49:23 +0100 Subject: [PATCH 06/30] Remove fallback on ADC sensor when ESC sensor fails --- src/main/sensors/battery.c | 7 +++++-- src/main/sensors/esc_sensor.c | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index e9591610a..7f6b62a49 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -84,12 +84,17 @@ static void updateBatteryVoltage(void) } #ifdef USE_ESC_SENSOR +<<<<<<< 0a89e28c8e6e538d5b283fe9a389c481f24523fb if (feature(FEATURE_ESC_SENSOR) && batteryConfig->batteryMeterType == BATTERY_SENSOR_ESC) { vbatLatest = getEscSensorVbat(); if (debugMode == DEBUG_BATTERY) { debug[0] = -1; } vbat = biquadFilterApply(&vBatFilter, vbatLatest); +======= + if (batteryConfig->batteryMeterType == BATTERY_SENSOR_ESC) { + vbatSample = vbatLatest = getEscSensorVbat(); +>>>>>>> Remove fallback on ADC sensor when ESC sensor fails } else #endif @@ -291,8 +296,6 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea { amperage = getEscSensorCurrent(); mAhDrawn = getEscSensorConsumption(); - - updateCurrentDrawn(lastUpdateAt); } #endif diff --git a/src/main/sensors/esc_sensor.c b/src/main/sensors/esc_sensor.c index ee0217507..a6b13fdca 100644 --- a/src/main/sensors/esc_sensor.c +++ b/src/main/sensors/esc_sensor.c @@ -269,11 +269,10 @@ void escSensorProcess(timeUs_t currentTimeUs) if (escTriggerLastTimestamp + 10000 < currentTimeMs) { // ESCs did not respond for 10 seconds - // Disable ESC telemetry and fallback to onboard vbat sensor + // Disable ESC telemetry and reset voltage and current to let the use know something is wrong freeEscSensorPort(); escVbat = 0; escCurrent = 0; - escConsumption = 0; } } From ff2f2dae874b18313f0f0b3b4c1e294ee99fe815 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Thu, 24 Nov 2016 21:00:46 +0100 Subject: [PATCH 07/30] Fixed Travis build warning --- src/main/sensors/battery.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index 7f6b62a49..721b1b8d4 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -292,6 +292,7 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea break; case CURRENT_SENSOR_ESC: #ifdef USE_ESC_SENSOR +<<<<<<< 2af7ff8434cfe047c841c85aae300154c7b4065e if (feature(FEATURE_ESC_SENSOR)) { amperage = getEscSensorCurrent(); @@ -299,6 +300,12 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea } #endif +======= + if (batteryConfig->currentMeterType == CURRENT_SENSOR_ESC) { + amperage = getEscSensorCurrent(); + mAhDrawn = getEscSensorConsumption(); + } +>>>>>>> Fixed Travis build warning break; case CURRENT_SENSOR_NONE: amperage = 0; From 2ffe57761e7e59382e393f7603f474922326c123 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Sun, 27 Nov 2016 11:16:38 +0100 Subject: [PATCH 08/30] Removed unnecessary enums for CURRENT_SENSOR_ESC and BATTERY_SENSOR_ESC --- src/main/sensors/battery.c | 12 ------------ src/main/sensors/battery.h | 3 ++- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index 721b1b8d4..bf1b13941 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -84,17 +84,12 @@ static void updateBatteryVoltage(void) } #ifdef USE_ESC_SENSOR -<<<<<<< 0a89e28c8e6e538d5b283fe9a389c481f24523fb if (feature(FEATURE_ESC_SENSOR) && batteryConfig->batteryMeterType == BATTERY_SENSOR_ESC) { vbatLatest = getEscSensorVbat(); if (debugMode == DEBUG_BATTERY) { debug[0] = -1; } vbat = biquadFilterApply(&vBatFilter, vbatLatest); -======= - if (batteryConfig->batteryMeterType == BATTERY_SENSOR_ESC) { - vbatSample = vbatLatest = getEscSensorVbat(); ->>>>>>> Remove fallback on ADC sensor when ESC sensor fails } else #endif @@ -292,7 +287,6 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea break; case CURRENT_SENSOR_ESC: #ifdef USE_ESC_SENSOR -<<<<<<< 2af7ff8434cfe047c841c85aae300154c7b4065e if (feature(FEATURE_ESC_SENSOR)) { amperage = getEscSensorCurrent(); @@ -300,12 +294,6 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea } #endif -======= - if (batteryConfig->currentMeterType == CURRENT_SENSOR_ESC) { - amperage = getEscSensorCurrent(); - mAhDrawn = getEscSensorConsumption(); - } ->>>>>>> Fixed Travis build warning break; case CURRENT_SENSOR_NONE: amperage = 0; diff --git a/src/main/sensors/battery.h b/src/main/sensors/battery.h index 01309a8c8..8f0b1d65f 100644 --- a/src/main/sensors/battery.h +++ b/src/main/sensors/battery.h @@ -31,7 +31,8 @@ typedef enum { CURRENT_SENSOR_NONE = 0, CURRENT_SENSOR_ADC, CURRENT_SENSOR_VIRTUAL, - CURRENT_SENSOR_ESC + CURRENT_SENSOR_ESC, + CURRENT_SENSOR_MAX = CURRENT_SENSOR_ESC } currentSensor_e; typedef enum { From c1d442279f6f0847e97acb5e757e4da285a81611 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Sun, 27 Nov 2016 12:27:25 +0100 Subject: [PATCH 09/30] Improved retry timeout check and 10 seconds of no response from ESCs check --- src/main/sensors/esc_sensor.c | 75 ++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/src/main/sensors/esc_sensor.c b/src/main/sensors/esc_sensor.c index a6b13fdca..fc11fc89d 100644 --- a/src/main/sensors/esc_sensor.c +++ b/src/main/sensors/esc_sensor.c @@ -89,7 +89,7 @@ static uint8_t tlmFramePosition = 0; static serialPort_t *escSensorPort = NULL; static esc_telemetry_t escSensorData[MAX_SUPPORTED_MOTORS]; static uint32_t escTriggerTimestamp = -1; -static uint32_t escTriggerLastTimestamp = -1; +static uint32_t escLastResponseTimestamp; static uint8_t timeoutRetryCount = 0; static uint8_t totalRetryCount = 0; @@ -208,7 +208,7 @@ void escSensorProcess(timeUs_t currentTimeUs) } // Wait period of time before requesting telemetry (let the system boot first) - if (millis() < ESC_BOOTTIME) { + if (currentTimeMs < ESC_BOOTTIME) { return; } else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_WAIT) { @@ -216,7 +216,7 @@ void escSensorProcess(timeUs_t currentTimeUs) escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; escSensorMotor = 0; escTriggerTimestamp = currentTimeMs; - escTriggerLastTimestamp = escTriggerTimestamp; + escLastResponseTimestamp = escTriggerTimestamp; } else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_READY) { DEBUG_SET(DEBUG_ESC_SENSOR, 0, escSensorMotor+1); @@ -225,49 +225,52 @@ void escSensorProcess(timeUs_t currentTimeUs) motor->requestTelemetry = true; escSensorTriggerState = ESC_SENSOR_TRIGGER_PENDING; } + else if (escSensorTriggerState == ESC_SENSOR_TRIGGER_PENDING) { - if (escTriggerTimestamp + ESC_REQUEST_TIMEOUT < currentTimeMs) { - // ESC did not repond in time, retry - timeoutRetryCount++; - escTriggerTimestamp = currentTimeMs; - escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; + if (escTriggerTimestamp + ESC_REQUEST_TIMEOUT < currentTimeMs) { + // ESC did not repond in time, retry + timeoutRetryCount++; + escTriggerTimestamp = currentTimeMs; + escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; - if (timeoutRetryCount == 4) { - // Not responding after 3 times, skip motor - escSensorData[escSensorMotor].skipped = true; - selectNextMotor(); + if (timeoutRetryCount == 4) { + // Not responding after 3 times, skip motor + escSensorData[escSensorMotor].skipped = true; + selectNextMotor(); + } + + DEBUG_SET(DEBUG_ESC_SENSOR, 1, ++totalRetryCount); } - DEBUG_SET(DEBUG_ESC_SENSOR, 1, ++totalRetryCount); - } + // Get received frame status + uint8_t state = escSensorFrameStatus(); - // Get received frame status - uint8_t state = escSensorFrameStatus(); + if (state == ESC_SENSOR_FRAME_COMPLETE) { + // Wait until all ESCs are processed + if (escSensorMotor == getMotorCount()-1) { + escCurrent = 0; + escConsumption = 0; + escVbat = 0; - if (state == ESC_SENSOR_FRAME_COMPLETE) { - // Wait until all ESCs are processed - if (escSensorMotor == getMotorCount()-1) { - escCurrent = 0; - escConsumption = 0; - escVbat = 0; - - for (int i = 0; i < getMotorCount(); i++) { - if (!escSensorData[i].skipped) { - escVbat = i > 0 ? ((escVbat + escSensorData[i].voltage) / 2) : escSensorData[i].voltage; - escCurrent = escCurrent + escSensorData[i].current; - escConsumption = escConsumption + escSensorData[i].consumption; + for (int i = 0; i < getMotorCount(); i++) { + if (!escSensorData[i].skipped) { + escVbat = i > 0 ? ((escVbat + escSensorData[i].voltage) / 2) : escSensorData[i].voltage; + escCurrent = escCurrent + escSensorData[i].current; + escConsumption = escConsumption + escSensorData[i].consumption; + } } } + + DEBUG_SET(DEBUG_ESC_SENSOR, 2, escVbat); + DEBUG_SET(DEBUG_ESC_SENSOR, 3, escCurrent); + + selectNextMotor(); + escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; + escLastResponseTimestamp = currentTimeMs; } - - DEBUG_SET(DEBUG_ESC_SENSOR, 2, escVbat); - DEBUG_SET(DEBUG_ESC_SENSOR, 3, escCurrent); - - selectNextMotor(); - escSensorTriggerState = ESC_SENSOR_TRIGGER_READY; } - if (escTriggerLastTimestamp + 10000 < currentTimeMs) { + if (escLastResponseTimestamp + 10000 < currentTimeMs) { // ESCs did not respond for 10 seconds // Disable ESC telemetry and reset voltage and current to let the use know something is wrong freeEscSensorPort(); @@ -282,8 +285,8 @@ static void selectNextMotor(void) if (escSensorMotor == getMotorCount()) { escSensorMotor = 0; } + timeoutRetryCount = 0; escTriggerTimestamp = millis(); - escTriggerLastTimestamp = escTriggerTimestamp; } //-- CRC From 8bd49918232fee0c6ca41d2ee3170ebc3c972333 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Mon, 5 Dec 2016 22:51:21 +0100 Subject: [PATCH 10/30] Fixed changed requested --- src/main/sensors/battery.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index bf1b13941..f090ae756 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -269,9 +269,11 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea updateCurrentDrawn(lastUpdateAt); + updateConsumptionWarning(); + break; case CURRENT_SENSOR_VIRTUAL: - amperage = (int32_t)batteryConfig->currentMeterOffset; + amperageLatest = (int32_t)batteryConfig->currentMeterOffset; if (ARMING_FLAG(ARMED)) { throttleStatus_e throttleStatus = calculateThrottleStatus(rxConfig, deadband3d_throttle); int throttleOffset = (int32_t)rcCommand[THROTTLE] - 1000; @@ -279,24 +281,30 @@ void updateCurrentMeter(int32_t lastUpdateAt, rxConfig_t *rxConfig, uint16_t dea throttleOffset = 0; } int throttleFactor = throttleOffset + (throttleOffset * throttleOffset / 50); - amperage += throttleFactor * (int32_t)batteryConfig->currentMeterScale / 1000; + amperageLatest += throttleFactor * (int32_t)batteryConfig->currentMeterScale / 1000; } + amperage = amperageLatest; updateCurrentDrawn(lastUpdateAt); + updateConsumptionWarning(); + break; case CURRENT_SENSOR_ESC: #ifdef USE_ESC_SENSOR - if (feature(FEATURE_ESC_SENSOR)) - { - amperage = getEscSensorCurrent(); + if (feature(FEATURE_ESC_SENSOR)) { + amperageLatest = getEscSensorCurrent(); + amperage = amperageLatest; mAhDrawn = getEscSensorConsumption(); + + updateConsumptionWarning(); } - #endif break; + #endif case CURRENT_SENSOR_NONE: amperage = 0; + amperageLatest = 0; break; } From 1eadcf3019dcb7a67582dc21d7170362d6f9b03c Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Mon, 5 Dec 2016 23:37:02 +0100 Subject: [PATCH 11/30] Added configuration for current and battery meter type through CLI --- src/main/io/serial_cli.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 25eaecb8f..9c6be899a 100755 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -415,7 +415,11 @@ static const char * const lookupTableGPSSBASMode[] = { #endif static const char * const lookupTableCurrentSensor[] = { - "NONE", "ADC", "VIRTUAL" + "NONE", "ADC", "VIRTUAL", "ESC" +}; + +static const char * const lookupTableBatterySensor[] = { + "NONE", "ADC", "ESC" }; #ifdef USE_SERVOS @@ -571,6 +575,7 @@ typedef enum { TABLE_BLACKBOX_DEVICE, #endif TABLE_CURRENT_SENSOR, + TABLE_BATTERY_SENSOR, #ifdef USE_SERVOS TABLE_GIMBAL_MODE, #endif @@ -611,6 +616,7 @@ static const lookupTableEntry_t lookupTables[] = { { lookupTableBlackboxDevice, sizeof(lookupTableBlackboxDevice) / sizeof(char *) }, #endif { lookupTableCurrentSensor, sizeof(lookupTableCurrentSensor) / sizeof(char *) }, + { lookupTableBatterySensor, sizeof(lookupTableBatterySensor) / sizeof(char *) }, #ifdef USE_SERVOS { lookupTableGimbalMode, sizeof(lookupTableGimbalMode) / sizeof(char *) }, #endif @@ -799,6 +805,7 @@ const clivalue_t valueTable[] = { { "current_meter_offset", VAR_INT16 | MASTER_VALUE, &batteryConfig()->currentMeterOffset, .config.minmax = { -16000, 16000 } }, { "multiwii_current_meter_output", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->multiwiiCurrentMeterOutput, .config.lookup = { TABLE_OFF_ON } }, { "current_meter_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->currentMeterType, .config.lookup = { TABLE_CURRENT_SENSOR } }, + { "battery_meter_type", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->batteryMeterType, .config.lookup = { TABLE_BATTERY_SENSOR } }, { "battery_notpresent_level", VAR_UINT8 | MASTER_VALUE, &batteryConfig()->batterynotpresentlevel, .config.minmax = { 0, 200 } }, { "use_vbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->useVBatAlerts, .config.lookup = { TABLE_OFF_ON } }, { "use_consumption_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &batteryConfig()->useConsumptionAlerts, .config.lookup = { TABLE_OFF_ON } }, From f0eebb5cd04b5880d2e68759823e3be1cf0b7beb Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Tue, 6 Dec 2016 23:24:17 +0100 Subject: [PATCH 12/30] Added battery meter type to end of MSP_(SET_)VOLTAGE_METER_CONFIG --- src/main/fc/fc_msp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 62d75cddb..48ae8c5dd 100755 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -882,6 +882,7 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn sbufWriteU8(dst, batteryConfig()->vbatmincellvoltage); sbufWriteU8(dst, batteryConfig()->vbatmaxcellvoltage); sbufWriteU8(dst, batteryConfig()->vbatwarningcellvoltage); + sbufWriteU8(dst, batteryConfig()->batteryMeterType); break; case MSP_CURRENT_METER_CONFIG: @@ -1662,6 +1663,7 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) batteryConfig()->vbatmincellvoltage = sbufReadU8(src); // vbatlevel_warn1 in MWC2.3 GUI batteryConfig()->vbatmaxcellvoltage = sbufReadU8(src); // vbatlevel_warn2 in MWC2.3 GUI batteryConfig()->vbatwarningcellvoltage = sbufReadU8(src); // vbatlevel when buzzer starts to alert + batteryConfig()->batteryMeterType = sbufReadU8(src); break; case MSP_SET_CURRENT_METER_CONFIG: From e93133860f92d112e37f29a368840fd1fec750df Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Tue, 6 Dec 2016 23:45:26 +0100 Subject: [PATCH 13/30] Rename FUNCTION_TELEMETRY_ESC to FUNCTION_ESC_SENSOR --- src/main/io/serial.h | 2 +- src/main/sensors/esc_sensor.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/io/serial.h b/src/main/io/serial.h index c8d7e3178..02f00d823 100644 --- a/src/main/io/serial.h +++ b/src/main/io/serial.h @@ -37,7 +37,7 @@ typedef enum { FUNCTION_BLACKBOX = (1 << 7), // 128 FUNCTION_TELEMETRY_MAVLINK = (1 << 9), // 512 - FUNCTION_TELEMETRY_ESC = (1 << 10) // 1024 + FUNCTION_ESC_SENSOR = (1 << 10) // 1024 } serialPortFunction_e; typedef enum { diff --git a/src/main/sensors/esc_sensor.c b/src/main/sensors/esc_sensor.c index fc11fc89d..af2c0aa11 100644 --- a/src/main/sensors/esc_sensor.c +++ b/src/main/sensors/esc_sensor.c @@ -128,7 +128,7 @@ int16_t getEscSensorConsumption(void) bool escSensorInit(void) { - serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_TELEMETRY_ESC); + serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_ESC_SENSOR); if (!portConfig) { return false; } @@ -136,7 +136,7 @@ bool escSensorInit(void) portOptions_t options = (SERIAL_NOT_INVERTED); // Initialize serial port - escSensorPort = openSerialPort(portConfig->identifier, FUNCTION_TELEMETRY_ESC, escSensorDataReceive, ESC_SENSOR_BAUDRATE, MODE_RX, options); + escSensorPort = openSerialPort(portConfig->identifier, FUNCTION_ESC_SENSOR, escSensorDataReceive, ESC_SENSOR_BAUDRATE, MODE_RX, options); if (escSensorPort) { escSensorEnabled = true; From 97ff8a154e0f4d4f6e7e5709ceeee0d01486b6a8 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Wed, 7 Dec 2016 00:03:30 +0100 Subject: [PATCH 14/30] Bumped MSP api version to 0.1.23 and added length check to MSP_SET_VOLTAGE_METER_TYPE --- src/main/fc/fc_msp.c | 4 +++- src/main/msp/msp_protocol.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 48ae8c5dd..bbc065145 100755 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -1663,7 +1663,9 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src) batteryConfig()->vbatmincellvoltage = sbufReadU8(src); // vbatlevel_warn1 in MWC2.3 GUI batteryConfig()->vbatmaxcellvoltage = sbufReadU8(src); // vbatlevel_warn2 in MWC2.3 GUI batteryConfig()->vbatwarningcellvoltage = sbufReadU8(src); // vbatlevel when buzzer starts to alert - batteryConfig()->batteryMeterType = sbufReadU8(src); + if (dataSize > 4) { + batteryConfig()->batteryMeterType = sbufReadU8(src); + } break; case MSP_SET_CURRENT_METER_CONFIG: diff --git a/src/main/msp/msp_protocol.h b/src/main/msp/msp_protocol.h index 84f0a60a1..925d38c14 100644 --- a/src/main/msp/msp_protocol.h +++ b/src/main/msp/msp_protocol.h @@ -59,7 +59,7 @@ #define MSP_PROTOCOL_VERSION 0 #define API_VERSION_MAJOR 1 // increment when major changes are made -#define API_VERSION_MINOR 22 // increment when any change is made, reset to zero when major changes are released after changing API_VERSION_MAJOR +#define API_VERSION_MINOR 23 // increment when any change is made, reset to zero when major changes are released after changing API_VERSION_MAJOR #define API_VERSION_LENGTH 2 From a59846a45a5673de726c802acfb203d909a57426 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Thu, 8 Dec 2016 20:59:24 +0100 Subject: [PATCH 15/30] Removed BATTERY_SENSOR.NONE --- src/main/io/serial_cli.c | 2 +- src/main/sensors/battery.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 9c6be899a..304918b0b 100755 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -419,7 +419,7 @@ static const char * const lookupTableCurrentSensor[] = { }; static const char * const lookupTableBatterySensor[] = { - "NONE", "ADC", "ESC" + "ADC", "ESC" }; #ifdef USE_SERVOS diff --git a/src/main/sensors/battery.h b/src/main/sensors/battery.h index 8f0b1d65f..cb4de3911 100644 --- a/src/main/sensors/battery.h +++ b/src/main/sensors/battery.h @@ -36,8 +36,7 @@ typedef enum { } currentSensor_e; typedef enum { - BATTERY_SENSOR_NONE = 0, - BATTERY_SENSOR_ADC, + BATTERY_SENSOR_ADC = 0, BATTERY_SENSOR_ESC } batterySensor_e; From f7518203aac9762cd24736fe7ddaed65d91aeb19 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sun, 4 Dec 2016 15:48:15 +1100 Subject: [PATCH 16/30] Initial rework - removing target specific code from main.c Moved FLASH to masterConfig Moved LED (named statusLeds) to masterConfig Fixed up some targets to remove defines from main.c --- src/main/config/config_master.h | 10 ++ src/main/drivers/flash.h | 5 + src/main/drivers/flash_m25p16.c | 14 +-- src/main/drivers/flash_m25p16.h | 4 +- src/main/drivers/light_led.c | 85 +++-------------- src/main/drivers/light_led.h | 9 +- src/main/fc/config.c | 46 ++++++++++ src/main/main.c | 92 ++++++------------- src/main/target/ALIENFLIGHTF3/config.c | 28 ++++++ .../target/ALIENFLIGHTF3/initialisation.c | 48 ++++++++++ src/main/target/ALIENFLIGHTF3/target.h | 1 + src/main/target/BLUEJAYF4/hardware_revision.c | 3 +- src/main/target/CJMCU/initialisation.c | 36 ++++++++ src/main/target/CJMCU/target.h | 1 + src/main/target/NAZE/config.c | 5 +- src/main/target/NAZE/hardware_revision.c | 1 + src/main/target/NAZE/initialisation.c | 44 +++++++++ src/main/target/NAZE/target.h | 10 +- src/main/target/SPRACINGF3/target.h | 1 + src/main/target/SPRACINGF3MINI/target.h | 8 +- src/main/target/X_RACERSPI/target.h | 2 +- 21 files changed, 288 insertions(+), 165 deletions(-) create mode 100644 src/main/target/ALIENFLIGHTF3/initialisation.c create mode 100644 src/main/target/CJMCU/initialisation.c create mode 100644 src/main/target/NAZE/initialisation.c diff --git a/src/main/config/config_master.h b/src/main/config/config_master.h index cc30a6974..338f56df8 100644 --- a/src/main/config/config_master.h +++ b/src/main/config/config_master.h @@ -31,6 +31,8 @@ #include "drivers/sonar_hcsr04.h" #include "drivers/sdcard.h" #include "drivers/vcd.h" +#include "drivers/light_led.h" +#include "drivers/flash.h" #include "fc/rc_controls.h" @@ -90,10 +92,12 @@ #define beeperConfig(x) (&masterConfig.beeperConfig) #define sonarConfig(x) (&masterConfig.sonarConfig) #define ledStripConfig(x) (&masterConfig.ledStripConfig) +#define statusLedConfig(x) (&masterConfig.statusLedConfig) #define osdProfile(x) (&masterConfig.osdProfile) #define vcdProfile(x) (&masterConfig.vcdProfile) #define sdcardConfig(x) (&masterConfig.sdcardConfig) #define blackboxConfig(x) (&masterConfig.blackboxConfig) +#define flashConfig(x) (&masterConfig.flashConfig) // System-wide @@ -162,6 +166,8 @@ typedef struct master_s { serialConfig_t serialConfig; telemetryConfig_t telemetryConfig; + statusLedConfig_t statusLedConfig; + #ifdef USE_PPM ppmConfig_t ppmConfig; #endif @@ -226,6 +232,10 @@ typedef struct master_s { blackboxConfig_t blackboxConfig; #endif +#ifdef USE_FLASHFS + flashConfig_t flashConfig; +#endif + uint32_t beeper_off_flags; uint32_t preferred_beeper_off_flags; diff --git a/src/main/drivers/flash.h b/src/main/drivers/flash.h index 21216825c..6a6f160b0 100644 --- a/src/main/drivers/flash.h +++ b/src/main/drivers/flash.h @@ -18,6 +18,7 @@ #pragma once #include +#include "drivers/io_types.h" typedef struct flashGeometry_s { uint16_t sectors; // Count of the number of erasable blocks on the device @@ -29,3 +30,7 @@ typedef struct flashGeometry_s { uint32_t totalSize; // This is just sectorSize * sectors } flashGeometry_t; + +typedef struct flashConfig_s { + ioTag_t csTag; +} flashConfig_t; diff --git a/src/main/drivers/flash_m25p16.c b/src/main/drivers/flash_m25p16.c index 67219ce30..c6429fe43 100644 --- a/src/main/drivers/flash_m25p16.c +++ b/src/main/drivers/flash_m25p16.c @@ -208,27 +208,21 @@ static bool m25p16_readIdentification() * Attempts to detect a connected m25p16. If found, true is returned and device capacity can be fetched with * m25p16_getGeometry(). */ -bool m25p16_init(ioTag_t csTag) +bool m25p16_init(flashConfig_t *flashConfig) { /* if we have already detected a flash device we can simply exit - - TODO: change the init param in favour of flash CFG when ParamGroups work is done - then cs pin can be specified in hardware_revision.c or config.c (dependent on revision). */ if (geometry.sectors) { return true; } - if (csTag) { - m25p16CsPin = IOGetByTag(csTag); + if (flashConfig->csTag) { + m25p16CsPin = IOGetByTag(flashConfig->csTag); } else { -#ifdef M25P16_CS_PIN - m25p16CsPin = IOGetByTag(IO_TAG(M25P16_CS_PIN)); -#else return false; -#endif } + IOInit(m25p16CsPin, OWNER_FLASH_CS, 0); IOConfigGPIO(m25p16CsPin, SPI_IO_CS_CFG); diff --git a/src/main/drivers/flash_m25p16.h b/src/main/drivers/flash_m25p16.h index ace78fc8b..f3cec0d9f 100644 --- a/src/main/drivers/flash_m25p16.h +++ b/src/main/drivers/flash_m25p16.h @@ -18,11 +18,11 @@ #pragma once #include -#include "io_types.h" +#include "flash.h" #define M25P16_PAGESIZE 256 -bool m25p16_init(ioTag_t csTag); +bool m25p16_init(flashConfig_t *flashConfig); void m25p16_eraseSector(uint32_t address); void m25p16_eraseCompletely(); diff --git a/src/main/drivers/light_led.c b/src/main/drivers/light_led.c index 1c9271883..8011f04cf 100644 --- a/src/main/drivers/light_led.c +++ b/src/main/drivers/light_led.c @@ -22,82 +22,23 @@ #include "light_led.h" -static const IO_t leds[] = { -#ifdef LED0 - DEFIO_IO(LED0), -#else - DEFIO_IO(NONE), -#endif -#ifdef LED1 - DEFIO_IO(LED1), -#else - DEFIO_IO(NONE), -#endif -#ifdef LED2 - DEFIO_IO(LED2), -#else - DEFIO_IO(NONE), -#endif -#if defined(LED0_A) || defined(LED1_A) || defined(LED2_A) -#ifdef LED0_A - DEFIO_IO(LED0_A), -#else - DEFIO_IO(NONE), -#endif -#ifdef LED1_A - DEFIO_IO(LED1_A), -#else - DEFIO_IO(NONE), -#endif -#ifdef LED2_A - DEFIO_IO(LED2_A), -#else - DEFIO_IO(NONE), -#endif -#endif -}; +static IO_t leds[LED_NUMBER]; +static uint8_t ledPolarity = 0; -uint8_t ledPolarity = 0 -#ifdef LED0_INVERTED - | BIT(0) -#endif -#ifdef LED1_INVERTED - | BIT(1) -#endif -#ifdef LED2_INVERTED - | BIT(2) -#endif -#ifdef LED0_A_INVERTED - | BIT(3) -#endif -#ifdef LED1_A_INVERTED - | BIT(4) -#endif -#ifdef LED2_A_INVERTED - | BIT(5) -#endif - ; - -static uint8_t ledOffset = 0; - -void ledInit(bool alternative_led) +void ledInit(statusLedConfig_t *statusLedConfig) { -#if defined(LED0_A) || defined(LED1_A) || defined(LED2_A) - if (alternative_led) { - ledOffset = LED_NUMBER; - } -#else - UNUSED(alternative_led); -#endif - LED0_OFF; LED1_OFF; LED2_OFF; + ledPolarity = statusLedConfig->polarity; for (int i = 0; i < LED_NUMBER; i++) { - if (leds[i + ledOffset]) { - IOInit(leds[i + ledOffset], OWNER_LED, RESOURCE_INDEX(i)); - IOConfigGPIO(leds[i + ledOffset], IOCFG_OUT_PP); + if (statusLedConfig->ledTags[i]) { + leds[i] = IOGetByTag(statusLedConfig->ledTags[i]); + IOInit(leds[i], OWNER_LED, RESOURCE_INDEX(i)); + IOConfigGPIO(leds[i], IOCFG_OUT_PP); + } else { + leds[i] = IO_NONE; } } @@ -108,11 +49,11 @@ void ledInit(bool alternative_led) void ledToggle(int led) { - IOToggle(leds[led + ledOffset]); + IOToggle(leds[led]); } void ledSet(int led, bool on) { - const bool inverted = (1 << (led + ledOffset)) & ledPolarity; - IOWrite(leds[led + ledOffset], on ? inverted : !inverted); + const bool inverted = (1 << (led)) & ledPolarity; + IOWrite(leds[led], on ? inverted : !inverted); } diff --git a/src/main/drivers/light_led.h b/src/main/drivers/light_led.h index 55814e1a1..d1ae47294 100644 --- a/src/main/drivers/light_led.h +++ b/src/main/drivers/light_led.h @@ -17,8 +17,15 @@ #pragma once +#include "drivers/io_types.h" + #define LED_NUMBER 3 +typedef struct statusLedConfig_s { + ioTag_t ledTags[LED_NUMBER]; + uint8_t polarity; +} statusLedConfig_t; + // Helpful macros #ifdef LED0 # define LED0_TOGGLE ledToggle(0) @@ -50,6 +57,6 @@ # define LED2_ON do {} while(0) #endif -void ledInit(bool alternative_led); +void ledInit(statusLedConfig_t *statusLedConfig); void ledToggle(int led); void ledSet(int led, bool state); diff --git a/src/main/fc/config.c b/src/main/fc/config.c index fa1cc67cd..59a8ca818 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -490,6 +490,46 @@ void resetMax7456Config(vcdProfile_t *pVcdProfile) } #endif +void resetStatusLedConfig(statusLedConfig_t *statusLedConfig) +{ + for (int i = 0; i < LED_NUMBER; i++) { + statusLedConfig->ledTags[i] = IO_TAG_NONE; + } + +#ifdef LED0 + statusLedConfig->ledTags[0] = IO_TAG(LED0); +#endif +#ifdef LED1 + statusLedConfig->ledTags[1] = IO_TAG(LED1); +#endif +#ifdef LED2 + statusLedConfig->ledTags[2] = IO_TAG(LED2); +#endif + + statusLedConfig->polarity = 0 +#ifdef LED0_INVERTED + | BIT(0) +#endif +#ifdef LED1_INVERTED + | BIT(1) +#endif +#ifdef LED2_INVERTED + | BIT(2) +#endif + ; +} + +#ifdef USE_FLASHFS +void resetFlashConfig(flashConfig_t *flashConfig) +{ +#ifdef M25P16_CS_PIN + flashConfig->csTag = IO_TAG(M25P16_CS_PIN); +#else + flashConfig->csTag = IO_TAG_NONE; +#endif +} +#endif + uint8_t getCurrentProfile(void) { return masterConfig.current_profile_index; @@ -789,6 +829,12 @@ void createDefaultConfig(master_t *config) } #endif +#ifdef USE_FLASHFS + resetFlashConfig(&config->flashConfig); +#endif + + resetStatusLedConfig(&config->statusLedConfig); + #if defined(TARGET_CONFIG) targetConfiguration(config); #endif diff --git a/src/main/main.c b/src/main/main.c index cf1060a54..4f080597c 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -124,6 +124,10 @@ #include "build/build_config.h" #include "build/debug.h" +#ifdef TARGET_BUS_INIT +void targetBusInit(void); +#endif + extern uint8_t motorControlEnable; #ifdef SOFTSERIAL_LOOPBACK @@ -172,11 +176,7 @@ void init(void) // Latch active features to be used for feature() in the remainder of init(). latchActiveFeatures(); -#ifdef ALIENFLIGHTF3 - ledInit(hardwareRevision == AFF3_REV_1 ? false : true); -#else - ledInit(false); -#endif + ledInit(&masterConfig.statusLedConfig); LED2_ON; #ifdef USE_EXTI @@ -291,7 +291,6 @@ void init(void) pwmRxSetInputFilteringMode(masterConfig.inputFilteringMode); #endif - systemState |= SYSTEM_STATE_MOTORS_READY; #ifdef BEEPER @@ -306,74 +305,48 @@ void init(void) bstInit(BST_DEVICE); #endif -#ifdef USE_SPI -#ifdef USE_SPI_DEVICE_1 - spiInit(SPIDEV_1); -#endif -#ifdef USE_SPI_DEVICE_2 - spiInit(SPIDEV_2); -#endif -#ifdef USE_SPI_DEVICE_3 -#ifdef ALIENFLIGHTF3 - if (hardwareRevision == AFF3_REV_2) { - spiInit(SPIDEV_3); - } +#ifdef TARGET_BUS_INIT + targetBusInit(); #else - spiInit(SPIDEV_3); -#endif -#endif -#ifdef USE_SPI_DEVICE_4 - spiInit(SPIDEV_4); -#endif -#endif + #ifdef USE_SPI + #ifdef USE_SPI_DEVICE_1 + spiInit(SPIDEV_1); + #endif + #ifdef USE_SPI_DEVICE_2 + spiInit(SPIDEV_2); + #endif + #ifdef USE_SPI_DEVICE_3 + spiInit(SPIDEV_3); + #endif + #ifdef USE_SPI_DEVICE_4 + spiInit(SPIDEV_4); + #endif + #endif -#ifdef VTX - vtxInit(); + #ifdef USE_I2C + i2cInit(I2C_DEVICE); + #endif #endif #ifdef USE_HARDWARE_REVISION_DETECTION updateHardwareRevision(); #endif -#if defined(NAZE) - if (hardwareRevision == NAZE32_SP) { - serialRemovePort(SERIAL_PORT_SOFTSERIAL2); - } else { - serialRemovePort(SERIAL_PORT_USART3); - } +#ifdef VTX + vtxInit(); #endif -#if defined(SPRACINGF3) && defined(SONAR) && defined(USE_SOFTSERIAL2) +#if defined(SONAR_SOFTSERIAL2_EXCLUSIVE) && defined(SONAR) && defined(USE_SOFTSERIAL2) if (feature(FEATURE_SONAR) && feature(FEATURE_SOFTSERIAL)) { serialRemovePort(SERIAL_PORT_SOFTSERIAL2); } #endif -#if defined(SPRACINGF3MINI) || defined(OMNIBUS) || defined(X_RACERSPI) -#if defined(SONAR) && defined(USE_SOFTSERIAL1) +#if defined(SONAR_SOFTSERIAL1_EXCLUSIVE) && defined(SONAR) && defined(USE_SOFTSERIAL1) if (feature(FEATURE_SONAR) && feature(FEATURE_SOFTSERIAL)) { serialRemovePort(SERIAL_PORT_SOFTSERIAL1); } #endif -#endif - -#ifdef USE_I2C -#if defined(NAZE) - if (hardwareRevision != NAZE32_SP) { - i2cInit(I2C_DEVICE); - } else { - if (!doesConfigurationUsePort(SERIAL_PORT_USART3)) { - i2cInit(I2C_DEVICE); - } - } -#elif defined(CC3D) - if (!doesConfigurationUsePort(SERIAL_PORT_USART3)) { - i2cInit(I2C_DEVICE); - } -#else - i2cInit(I2C_DEVICE); -#endif -#endif #ifdef USE_ADC /* these can be removed from features! */ @@ -383,7 +356,6 @@ void init(void) adcInit(&masterConfig.adcConfig); #endif - initBoardAlignment(&masterConfig.boardAlignment); #ifdef CMS @@ -513,12 +485,8 @@ void init(void) #endif #ifdef USE_FLASHFS -#ifdef NAZE - if (hardwareRevision == NAZE32_REV5) { - m25p16_init(IO_TAG_NONE); - } -#elif defined(USE_FLASH_M25P16) - m25p16_init(IO_TAG_NONE); +#if defined(USE_FLASH_M25P16) + m25p16_init(&masterConfig.flashConfig); #endif flashfsInit(); diff --git a/src/main/target/ALIENFLIGHTF3/config.c b/src/main/target/ALIENFLIGHTF3/config.c index 516b64a78..4bf94258b 100644 --- a/src/main/target/ALIENFLIGHTF3/config.c +++ b/src/main/target/ALIENFLIGHTF3/config.c @@ -45,6 +45,34 @@ // alternative defaults settings for AlienFlight targets void targetConfiguration(master_t *config) { + /* depending on revision ... depends on the LEDs to be utilised. */ + if (hardwareRevision == AFF3_REV_1) { + config->statusLedConfig.polarity = 0 +#ifdef LED0_A_INVERTED + | BIT(3) +#endif +#ifdef LED1_A_INVERTED + | BIT(4) +#endif +#ifdef LED2_A_INVERTED + | BIT(5) +#endif + ; + + for (int i = 0; i < LED_NUMBER; i++) { + config->statusLedConfig.ledTags[i] = IO_TAG_NONE; + } +#ifdef LED0_A + config->statusLedConfig.ledTags[0] = IO_TAG(LED0_A); +#endif +#ifdef LED1_A + config->statusLedConfig.ledTags[1] = IO_TAG(LED1_A); +#endif +#ifdef LED2_A + config->statusLedConfig.ledTags[2] = IO_TAG(LED2_A); +#endif + } + config->rxConfig.spektrum_sat_bind = 5; config->rxConfig.spektrum_sat_bind_autoreset = 1; config->compassConfig.mag_hardware = MAG_NONE; // disabled by default diff --git a/src/main/target/ALIENFLIGHTF3/initialisation.c b/src/main/target/ALIENFLIGHTF3/initialisation.c new file mode 100644 index 000000000..53fbb1f91 --- /dev/null +++ b/src/main/target/ALIENFLIGHTF3/initialisation.c @@ -0,0 +1,48 @@ +/* + * 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" +#include "drivers/bus_i2c.h" +#include "drivers/bus_spi.h" +#include "hardware_revision.h" + +void targetBusInit(void) +{ + #ifdef USE_SPI + #ifdef USE_SPI_DEVICE_1 + spiInit(SPIDEV_1); + #endif + #ifdef USE_SPI_DEVICE_2 + spiInit(SPIDEV_2); + #endif + #ifdef USE_SPI_DEVICE_3 + if (hardwareRevision == AFF3_REV_2) { + spiInit(SPIDEV_3); + } + #endif + #ifdef USE_SPI_DEVICE_4 + spiInit(SPIDEV_4); + #endif + #endif + + #ifdef USE_I2C + i2cInit(I2C_DEVICE); + #endif +} \ No newline at end of file diff --git a/src/main/target/ALIENFLIGHTF3/target.h b/src/main/target/ALIENFLIGHTF3/target.h index 63a3a9bb0..1627043e9 100644 --- a/src/main/target/ALIENFLIGHTF3/target.h +++ b/src/main/target/ALIENFLIGHTF3/target.h @@ -19,6 +19,7 @@ #define TARGET_BOARD_IDENTIFIER "AFF3" // AlienFlight F3. #define TARGET_CONFIG +#define TARGET_BUS_INIT #define CONFIG_FASTLOOP_PREFERRED_ACC ACC_DEFAULT diff --git a/src/main/target/BLUEJAYF4/hardware_revision.c b/src/main/target/BLUEJAYF4/hardware_revision.c index 7261aa223..cb70d05f7 100644 --- a/src/main/target/BLUEJAYF4/hardware_revision.c +++ b/src/main/target/BLUEJAYF4/hardware_revision.c @@ -85,7 +85,8 @@ void updateHardwareRevision(void) /* if flash exists on PB3 then Rev1 */ - if (m25p16_init(IO_TAG(PB3))) { + flashConfig_t flashConfig = { .csTag = IO_TAG(PB3) }; + if (m25p16_init(&flashConfig)) { hardwareRevision = BJF4_REV1; } else { IOInit(IOGetByTag(IO_TAG(PB3)), OWNER_FREE, 0); diff --git a/src/main/target/CJMCU/initialisation.c b/src/main/target/CJMCU/initialisation.c new file mode 100644 index 000000000..817dfc540 --- /dev/null +++ b/src/main/target/CJMCU/initialisation.c @@ -0,0 +1,36 @@ +/* + * 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" +#include "drivers/bus_i2c.h" +#include "drivers/bus_spi.h" +#include "io/serial.h" + +void targetBusInit(void) +{ + #if defined(USE_SPI) && defined(USE_SPI_DEVICE_1) + spiInit(SPIDEV_1); + #endif + + if (!doesConfigurationUsePort(SERIAL_PORT_USART3)) { + serialRemovePort(SERIAL_PORT_USART3); + i2cInit(I2C_DEVICE); + } +} \ No newline at end of file diff --git a/src/main/target/CJMCU/target.h b/src/main/target/CJMCU/target.h index de5afbd44..4f3d274b9 100644 --- a/src/main/target/CJMCU/target.h +++ b/src/main/target/CJMCU/target.h @@ -19,6 +19,7 @@ #define TARGET_BOARD_IDENTIFIER "CJM1" // CJMCU #define USE_HARDWARE_REVISION_DETECTION +#define TARGET_BUS_INIT #define LED0 PC14 #define LED1 PC13 diff --git a/src/main/target/NAZE/config.c b/src/main/target/NAZE/config.c index b4142093e..6e8e07591 100755 --- a/src/main/target/NAZE/config.c +++ b/src/main/target/NAZE/config.c @@ -35,6 +35,8 @@ void targetConfiguration(master_t *config) { + UNUSED(config); + #ifdef BEEBRAIN // alternative defaults settings for Beebrain target config->motorConfig.motorPwmRate = 4000; @@ -88,9 +90,8 @@ void targetConfiguration(master_t *config) } else { config->beeperConfig.isOpenDrain = true; config->beeperConfig.isInverted = false; + config->flashConfig.csTag = IO_TAG_NONE; } -#else - UNUSED(config); #endif } diff --git a/src/main/target/NAZE/hardware_revision.c b/src/main/target/NAZE/hardware_revision.c index 533d8bb58..031b4d43a 100755 --- a/src/main/target/NAZE/hardware_revision.c +++ b/src/main/target/NAZE/hardware_revision.c @@ -127,3 +127,4 @@ const extiConfig_t *selectMPUIntExtiConfigByHardwareRevision(void) } #endif } + diff --git a/src/main/target/NAZE/initialisation.c b/src/main/target/NAZE/initialisation.c new file mode 100644 index 000000000..9ff56b1f6 --- /dev/null +++ b/src/main/target/NAZE/initialisation.c @@ -0,0 +1,44 @@ +/* + * 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" +#include "drivers/bus_i2c.h" +#include "drivers/bus_spi.h" +#include "io/serial.h" +#include "hardware_revision.h" + +void targetBusInit(void) +{ + #ifdef USE_SPI + #ifdef USE_SPI_DEVICE_2 + spiInit(SPIDEV_2); + #endif + #endif + + if (hardwareRevision != NAZE32_SP) { + i2cInit(I2C_DEVICE); + serialRemovePort(SERIAL_PORT_SOFTSERIAL2); + } else { + if (!doesConfigurationUsePort(SERIAL_PORT_USART3)) { + serialRemovePort(SERIAL_PORT_USART3); + i2cInit(I2C_DEVICE); + } + } +} \ No newline at end of file diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h index 184ea76ee..2272a5552 100644 --- a/src/main/target/NAZE/target.h +++ b/src/main/target/NAZE/target.h @@ -19,6 +19,7 @@ #define TARGET_CONFIG #define USE_HARDWARE_REVISION_DETECTION +#define TARGET_BUS_INIT #define CLI_MINIMAL_VERBOSITY @@ -65,19 +66,14 @@ #define USE_SPI_DEVICE_2 #define NAZE_SPI_INSTANCE SPI2 -#define NAZE_SPI_CS_GPIO GPIOB #define NAZE_SPI_CS_PIN PB12 -#define NAZE_CS_GPIO_CLK_PERIPHERAL RCC_APB2Periph_GPIOB // We either have this 16mbit flash chip on SPI or the MPU6500 acc/gyro depending on board revision: -#define M25P16_CS_GPIO NAZE_SPI_CS_GPIO #define M25P16_CS_PIN NAZE_SPI_CS_PIN #define M25P16_SPI_INSTANCE NAZE_SPI_INSTANCE -#define MPU6500_CS_GPIO_CLK_PERIPHERAL NAZE_CS_GPIO_CLK_PERIPHERAL -#define MPU6500_CS_GPIO NAZE_SPI_CS_GPIO -#define MPU6500_CS_PIN NAZE_SPI_CS_PIN -#define MPU6500_SPI_INSTANCE NAZE_SPI_INSTANCE +#define MPU6500_CS_PIN NAZE_SPI_CS_PIN +#define MPU6500_SPI_INSTANCE NAZE_SPI_INSTANCE #define USE_FLASHFS #define USE_FLASH_M25P16 diff --git a/src/main/target/SPRACINGF3/target.h b/src/main/target/SPRACINGF3/target.h index 3d906295e..1c6ab3dd9 100644 --- a/src/main/target/SPRACINGF3/target.h +++ b/src/main/target/SPRACINGF3/target.h @@ -98,6 +98,7 @@ #define SOFTSERIAL_2_TIMER TIM3 #define SOFTSERIAL_2_TIMER_RX_HARDWARE 6 // PWM 7 #define SOFTSERIAL_2_TIMER_TX_HARDWARE 7 // PWM 8 +#define SONAR_SOFTSERIAL2_EXCLUSIVE #define USE_I2C #define I2C_DEVICE (I2CDEV_1) // PB6/SCL, PB7/SDA diff --git a/src/main/target/SPRACINGF3MINI/target.h b/src/main/target/SPRACINGF3MINI/target.h index 79c1508ac..451404d34 100644 --- a/src/main/target/SPRACINGF3MINI/target.h +++ b/src/main/target/SPRACINGF3MINI/target.h @@ -88,6 +88,7 @@ #define SOFTSERIAL_1_TIMER TIM2 #define SOFTSERIAL_1_TIMER_RX_HARDWARE 9 // PA0 / PAD3 #define SOFTSERIAL_1_TIMER_TX_HARDWARE 10 // PA1 / PAD4 +#define SONAR_SOFTSERIAL1_EXCLUSIVE #define USE_I2C #define I2C_DEVICE (I2CDEV_1) // PB6/SCL, PB7/SDA @@ -129,13 +130,6 @@ #define RSSI_ADC_PIN PB2 #define LED_STRIP -#define WS2811_PIN PA8 -#define WS2811_TIMER TIM1 -#define WS2811_DMA_CHANNEL 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 WS2811_TIMER_GPIO_AF GPIO_AF_6 #define TRANSPONDER diff --git a/src/main/target/X_RACERSPI/target.h b/src/main/target/X_RACERSPI/target.h index 8ade29012..00c4a08c4 100644 --- a/src/main/target/X_RACERSPI/target.h +++ b/src/main/target/X_RACERSPI/target.h @@ -71,7 +71,7 @@ #define SOFTSERIAL_1_TIMER TIM3 #define SOFTSERIAL_1_TIMER_RX_HARDWARE 4 // PWM 5 #define SOFTSERIAL_1_TIMER_TX_HARDWARE 5 // PWM 6 - +#define SONAR_SOFTSERIAL1_EXCLUSIVE #define USE_I2C #define I2C_DEVICE (I2CDEV_1) // PB6/SCL, PB7/SDA From b91b7a304dab58f8685c470670e308746d6c227a Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 10 Dec 2016 10:37:48 +1100 Subject: [PATCH 17/30] Corrected bits for LEDs for AFF3 given no extended LEDs in list now --- src/main/target/ALIENFLIGHTF3/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/target/ALIENFLIGHTF3/config.c b/src/main/target/ALIENFLIGHTF3/config.c index 4bf94258b..8d208fb7d 100644 --- a/src/main/target/ALIENFLIGHTF3/config.c +++ b/src/main/target/ALIENFLIGHTF3/config.c @@ -49,13 +49,13 @@ void targetConfiguration(master_t *config) if (hardwareRevision == AFF3_REV_1) { config->statusLedConfig.polarity = 0 #ifdef LED0_A_INVERTED - | BIT(3) + | BIT(0) #endif #ifdef LED1_A_INVERTED - | BIT(4) + | BIT(1) #endif #ifdef LED2_A_INVERTED - | BIT(5) + | BIT(2) #endif ; From 1040168b9a1dc48ca19aa8563543cfd27deefcd6 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 10 Dec 2016 10:40:21 +1100 Subject: [PATCH 18/30] Alternative LED configuration is for AFF3 REV2 --- src/main/target/ALIENFLIGHTF3/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/target/ALIENFLIGHTF3/config.c b/src/main/target/ALIENFLIGHTF3/config.c index 8d208fb7d..449bdaf6d 100644 --- a/src/main/target/ALIENFLIGHTF3/config.c +++ b/src/main/target/ALIENFLIGHTF3/config.c @@ -46,7 +46,7 @@ void targetConfiguration(master_t *config) { /* depending on revision ... depends on the LEDs to be utilised. */ - if (hardwareRevision == AFF3_REV_1) { + if (hardwareRevision == AFF3_REV_2) { config->statusLedConfig.polarity = 0 #ifdef LED0_A_INVERTED | BIT(0) From 71f17a8f2bfc61c8bb58a6f81db8522eb50d7f8c Mon Sep 17 00:00:00 2001 From: jflyper Date: Sat, 10 Dec 2016 21:01:44 +0900 Subject: [PATCH 19/30] CMS files as size optimized --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index ba33689db..3e02f53a4 100644 --- a/Makefile +++ b/Makefile @@ -686,6 +686,14 @@ SIZE_OPTIMISED_SRC = \ io/serial_4way_avrootloader.c \ io/serial_4way_stk500v2.c \ msp/msp_serial.c \ + cms/cms.c \ + cms/cms_menu_blackbox.c \ + cms/cms_menu_builtin.c \ + cms/cms_menu_imu.c \ + cms/cms_menu_ledstrip.c \ + cms/cms_menu_misc.c \ + cms/cms_menu_osd.c \ + cms/cms_menu_vtx.c ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS))) VCP_SRC = \ From 590b01a77ea3efd369309ffc536339fc26cc6134 Mon Sep 17 00:00:00 2001 From: Michael Jakob Date: Wed, 7 Dec 2016 22:33:47 +0100 Subject: [PATCH 20/30] Generalize brushed ESC auto detection Used for all AlienFlight and SPRACINGF3EVO targets --- src/main/drivers/pwm_output.c | 26 ++++++++ src/main/drivers/pwm_output.h | 12 ++++ src/main/fc/config.c | 16 ++++- src/main/main.c | 4 ++ src/main/target/ALIENFLIGHTF1/config.c | 7 +-- .../target/ALIENFLIGHTF1/hardware_revision.c | 59 ------------------- .../target/ALIENFLIGHTF1/hardware_revision.h | 37 ------------ src/main/target/ALIENFLIGHTF1/target.h | 3 +- src/main/target/ALIENFLIGHTF3/config.c | 7 +-- .../target/ALIENFLIGHTF3/hardware_revision.c | 13 ---- .../target/ALIENFLIGHTF3/hardware_revision.h | 7 --- src/main/target/ALIENFLIGHTF3/target.h | 2 +- src/main/target/ALIENFLIGHTF4/config.c | 3 - .../target/ALIENFLIGHTF4/hardware_revision.c | 13 ---- .../target/ALIENFLIGHTF4/hardware_revision.h | 7 --- src/main/target/ALIENFLIGHTF4/target.h | 2 +- src/main/target/SPRACINGF3EVO/target.h | 2 + 17 files changed, 65 insertions(+), 155 deletions(-) delete mode 100644 src/main/target/ALIENFLIGHTF1/hardware_revision.c delete mode 100644 src/main/target/ALIENFLIGHTF1/hardware_revision.h diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index ed58b2529..90ad21c90 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -24,6 +24,7 @@ #include "io.h" #include "timer.h" #include "pwm_output.h" +#include "system.h" #define MULTISHOT_5US_PW (MULTISHOT_TIMER_MHZ * 5) #define MULTISHOT_20US_MULT (MULTISHOT_TIMER_MHZ * 20 / 1000.0f) @@ -280,3 +281,28 @@ void servoInit(const servoConfig_t *servoConfig) } #endif + +#ifdef BRUSHED_ESC_AUTODETECT +uint8_t hardwareMotorType = MOTOR_UNKNOWN; + +void detectBrushedESC(void) +{ + int i = 0; + while (!(timerHardware[i].usageFlags & TIM_USE_MOTOR) && (i < USABLE_TIMER_CHANNEL_COUNT)) { + i++; + } + + IO_t MotorDetectPin = IOGetByTag(timerHardware[i].tag); + IOInit(MotorDetectPin, OWNER_SYSTEM, 0); + IOConfigGPIO(MotorDetectPin, IOCFG_IPU); + + delayMicroseconds(10); // allow configuration to settle + + // Check presence of brushed ESC's + if (IORead(MotorDetectPin)) { + hardwareMotorType = MOTOR_BRUSHLESS; + } else { + hardwareMotorType = MOTOR_BRUSHED; + } +} +#endif diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index 9d94a1d07..8c6488298 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -114,3 +114,15 @@ pwmOutputPort_t *pwmGetMotors(void); bool pwmIsSynced(void); void pwmDisableMotors(void); void pwmEnableMotors(void); + +#ifdef BRUSHED_ESC_AUTODETECT +typedef enum { + MOTOR_UNKNOWN = 0, + MOTOR_BRUSHED, + MOTOR_BRUSHLESS +} HardwareMotorTypes_e; + +extern uint8_t hardwareMotorType; + +void detectBrushedESC(void); +#endif diff --git a/src/main/fc/config.c b/src/main/fc/config.c index fa1cc67cd..dd94e4696 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -274,9 +274,19 @@ void resetMotorConfig(motorConfig_t *motorConfig) motorConfig->motorPwmProtocol = PWM_TYPE_BRUSHED; motorConfig->useUnsyncedPwm = true; #else - motorConfig->minthrottle = 1070; - motorConfig->motorPwmRate = BRUSHLESS_MOTORS_PWM_RATE; - motorConfig->motorPwmProtocol = PWM_TYPE_ONESHOT125; +#ifdef BRUSHED_ESC_AUTODETECT + if (hardwareMotorType == MOTOR_BRUSHED) { + motorConfig->minthrottle = 1000; + motorConfig->motorPwmRate = BRUSHED_MOTORS_PWM_RATE; + motorConfig->motorPwmProtocol = PWM_TYPE_BRUSHED; + motorConfig->useUnsyncedPwm = true; + } else +#endif + { + motorConfig->minthrottle = 1070; + motorConfig->motorPwmRate = BRUSHLESS_MOTORS_PWM_RATE; + motorConfig->motorPwmProtocol = PWM_TYPE_ONESHOT125; + } #endif motorConfig->maxthrottle = 2000; motorConfig->mincommand = 1000; diff --git a/src/main/main.c b/src/main/main.c index cf1060a54..5df667d93 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -158,6 +158,10 @@ void init(void) detectHardwareRevision(); #endif +#ifdef BRUSHED_ESC_AUTODETECT + detectBrushedESC(); +#endif + initEEPROM(); ensureEEPROMContainsValidData(); diff --git a/src/main/target/ALIENFLIGHTF1/config.c b/src/main/target/ALIENFLIGHTF1/config.c index 049a06e88..89bf61ecb 100644 --- a/src/main/target/ALIENFLIGHTF1/config.c +++ b/src/main/target/ALIENFLIGHTF1/config.c @@ -33,7 +33,7 @@ #include "config/config_profile.h" #include "config/config_master.h" -#include "hardware_revision.h" +#define BRUSHED_MOTORS_PWM_RATE 32000 // 32kHz // alternative defaults settings for AlienFlight targets void targetConfiguration(master_t *config) @@ -42,10 +42,7 @@ void targetConfiguration(master_t *config) config->rxConfig.spektrum_sat_bind_autoreset = 1; if (hardwareMotorType == MOTOR_BRUSHED) { - config->motorConfig.minthrottle = 1000; - config->motorConfig.motorPwmRate = 32000; - config->motorConfig.motorPwmProtocol = PWM_TYPE_BRUSHED; - config->motorConfig.useUnsyncedPwm = true; + config->motorConfig.motorPwmRate = BRUSHED_MOTORS_PWM_RATE; } config->profile[0].pidProfile.P8[ROLL] = 90; diff --git a/src/main/target/ALIENFLIGHTF1/hardware_revision.c b/src/main/target/ALIENFLIGHTF1/hardware_revision.c deleted file mode 100644 index 4ea15ecde..000000000 --- a/src/main/target/ALIENFLIGHTF1/hardware_revision.c +++ /dev/null @@ -1,59 +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 "platform.h" - -#include "build/build_config.h" - -#include "drivers/system.h" -#include "drivers/io.h" -#include "drivers/exti.h" -#include "hardware_revision.h" - -uint8_t hardwareRevision = AFF1_REV_1; -uint8_t hardwareMotorType = MOTOR_UNKNOWN; - -static IO_t MotorDetectPin = IO_NONE; - -void detectHardwareRevision(void) -{ - MotorDetectPin = IOGetByTag(IO_TAG(MOTOR_PIN)); - IOInit(MotorDetectPin, OWNER_SYSTEM, 0); - IOConfigGPIO(MotorDetectPin, IOCFG_IPU); - - delayMicroseconds(10); // allow configuration to settle - - // Check presence of brushed ESC's - if (IORead(MotorDetectPin)) { - hardwareMotorType = MOTOR_BRUSHLESS; - } else { - hardwareMotorType = MOTOR_BRUSHED; - } -} - -void updateHardwareRevision(void) -{ -} - -const extiConfig_t *selectMPUIntExtiConfigByHardwareRevision(void) -{ - return NULL; -} diff --git a/src/main/target/ALIENFLIGHTF1/hardware_revision.h b/src/main/target/ALIENFLIGHTF1/hardware_revision.h deleted file mode 100644 index 8fcb761fc..000000000 --- a/src/main/target/ALIENFLIGHTF1/hardware_revision.h +++ /dev/null @@ -1,37 +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 . - */ -#pragma once - -typedef enum awf1HardwareRevision_t { - AFF1_UNKNOWN = 0, - AFF1_REV_1, // MPU6050 (I2C) -} awf1HardwareRevision_e; - -typedef enum awf4HardwareMotorType_t { - MOTOR_UNKNOWN = 0, - MOTOR_BRUSHED, - MOTOR_BRUSHLESS -} awf4HardwareMotorType_e; - -extern uint8_t hardwareRevision; -extern uint8_t hardwareMotorType; - -void updateHardwareRevision(void); -void detectHardwareRevision(void); - -struct extiConfig_s; -const struct extiConfig_s *selectMPUIntExtiConfigByHardwareRevision(void); diff --git a/src/main/target/ALIENFLIGHTF1/target.h b/src/main/target/ALIENFLIGHTF1/target.h index 5bafc911c..02a730444 100644 --- a/src/main/target/ALIENFLIGHTF1/target.h +++ b/src/main/target/ALIENFLIGHTF1/target.h @@ -20,8 +20,7 @@ #define TARGET_BOARD_IDENTIFIER "AFF1" // AlienFlight F1. #define TARGET_CONFIG -#define USE_HARDWARE_REVISION_DETECTION -#define MOTOR_PIN PA8 +#define BRUSHED_ESC_AUTODETECT #define LED0 PB3 #define LED1 PB4 diff --git a/src/main/target/ALIENFLIGHTF3/config.c b/src/main/target/ALIENFLIGHTF3/config.c index 516b64a78..f99ee32ee 100644 --- a/src/main/target/ALIENFLIGHTF3/config.c +++ b/src/main/target/ALIENFLIGHTF3/config.c @@ -42,6 +42,8 @@ #include "hardware_revision.h" +#define BRUSHED_MOTORS_PWM_RATE 32000 // 32kHz + // alternative defaults settings for AlienFlight targets void targetConfiguration(master_t *config) { @@ -50,11 +52,8 @@ void targetConfiguration(master_t *config) config->compassConfig.mag_hardware = MAG_NONE; // disabled by default if (hardwareMotorType == MOTOR_BRUSHED) { - config->motorConfig.minthrottle = 1000; - config->motorConfig.motorPwmRate = 32000; - config->motorConfig.motorPwmProtocol = PWM_TYPE_BRUSHED; + config->motorConfig.motorPwmRate = BRUSHED_MOTORS_PWM_RATE; config->pid_process_denom = 2; - config->motorConfig.useUnsyncedPwm = true; } config->profile[0].pidProfile.P8[ROLL] = 90; diff --git a/src/main/target/ALIENFLIGHTF3/hardware_revision.c b/src/main/target/ALIENFLIGHTF3/hardware_revision.c index 0dd8ba2e4..e3942a0c1 100644 --- a/src/main/target/ALIENFLIGHTF3/hardware_revision.c +++ b/src/main/target/ALIENFLIGHTF3/hardware_revision.c @@ -29,10 +29,8 @@ #include "hardware_revision.h" uint8_t hardwareRevision = AFF3_UNKNOWN; -uint8_t hardwareMotorType = MOTOR_UNKNOWN; static IO_t HWDetectPin = IO_NONE; -static IO_t MotorDetectPin = IO_NONE; void detectHardwareRevision(void) { @@ -40,10 +38,6 @@ void detectHardwareRevision(void) IOInit(HWDetectPin, OWNER_SYSTEM, 0); IOConfigGPIO(HWDetectPin, IOCFG_IPU); - MotorDetectPin = IOGetByTag(IO_TAG(MOTOR_PIN)); - IOInit(MotorDetectPin, OWNER_SYSTEM, 0); - IOConfigGPIO(MotorDetectPin, IOCFG_IPU); - delayMicroseconds(10); // allow configuration to settle // Check hardware revision @@ -52,13 +46,6 @@ void detectHardwareRevision(void) } else { hardwareRevision = AFF3_REV_2; } - - // Check presence of brushed ESC's - if (IORead(MotorDetectPin)) { - hardwareMotorType = MOTOR_BRUSHLESS; - } else { - hardwareMotorType = MOTOR_BRUSHED; - } } void updateHardwareRevision(void) diff --git a/src/main/target/ALIENFLIGHTF3/hardware_revision.h b/src/main/target/ALIENFLIGHTF3/hardware_revision.h index 9b0618561..67cdbc931 100644 --- a/src/main/target/ALIENFLIGHTF3/hardware_revision.h +++ b/src/main/target/ALIENFLIGHTF3/hardware_revision.h @@ -22,14 +22,7 @@ typedef enum awf3HardwareRevision_t { AFF3_REV_2 // MPU6500 / MPU9250 (SPI) } awf3HardwareRevision_e; -typedef enum awf4HardwareMotorType_t { - MOTOR_UNKNOWN = 0, - MOTOR_BRUSHED, - MOTOR_BRUSHLESS -} awf4HardwareMotorType_e; - extern uint8_t hardwareRevision; -extern uint8_t hardwareMotorType; void updateHardwareRevision(void); void detectHardwareRevision(void); diff --git a/src/main/target/ALIENFLIGHTF3/target.h b/src/main/target/ALIENFLIGHTF3/target.h index 63a3a9bb0..f97ba9ac3 100644 --- a/src/main/target/ALIENFLIGHTF3/target.h +++ b/src/main/target/ALIENFLIGHTF3/target.h @@ -24,7 +24,7 @@ #define USE_HARDWARE_REVISION_DETECTION #define HW_PIN PB2 -#define MOTOR_PIN PB15 +#define BRUSHED_ESC_AUTODETECT // LED's V1 #define LED0 PB4 diff --git a/src/main/target/ALIENFLIGHTF4/config.c b/src/main/target/ALIENFLIGHTF4/config.c index 363a9704d..7a9b8bc54 100644 --- a/src/main/target/ALIENFLIGHTF4/config.c +++ b/src/main/target/ALIENFLIGHTF4/config.c @@ -61,11 +61,8 @@ void targetConfiguration(master_t *config) config->compassConfig.mag_hardware = MAG_NONE; // disabled by default if (hardwareMotorType == MOTOR_BRUSHED) { - config->motorConfig.minthrottle = 1000; config->motorConfig.motorPwmRate = BRUSHED_MOTORS_PWM_RATE; - config->motorConfig.motorPwmProtocol = PWM_TYPE_BRUSHED; config->pid_process_denom = 1; - config->motorConfig.useUnsyncedPwm = true; } if (hardwareRevision == AFF4_REV_1) { diff --git a/src/main/target/ALIENFLIGHTF4/hardware_revision.c b/src/main/target/ALIENFLIGHTF4/hardware_revision.c index 918e897c8..37f591828 100644 --- a/src/main/target/ALIENFLIGHTF4/hardware_revision.c +++ b/src/main/target/ALIENFLIGHTF4/hardware_revision.c @@ -28,10 +28,8 @@ #include "hardware_revision.h" uint8_t hardwareRevision = AFF4_UNKNOWN; -uint8_t hardwareMotorType = MOTOR_UNKNOWN; static IO_t HWDetectPin = IO_NONE; -static IO_t MotorDetectPin = IO_NONE; void detectHardwareRevision(void) { @@ -39,10 +37,6 @@ void detectHardwareRevision(void) IOInit(HWDetectPin, OWNER_SYSTEM, 0); IOConfigGPIO(HWDetectPin, IOCFG_IPU); - MotorDetectPin = IOGetByTag(IO_TAG(MOTOR_PIN)); - IOInit(MotorDetectPin, OWNER_SYSTEM, 0); - IOConfigGPIO(MotorDetectPin, IOCFG_IPU); - delayMicroseconds(10); // allow configuration to settle // Check hardware revision @@ -51,13 +45,6 @@ void detectHardwareRevision(void) } else { hardwareRevision = AFF4_REV_2; } - - // Check presence of brushed ESC's - if (IORead(MotorDetectPin)) { - hardwareMotorType = MOTOR_BRUSHLESS; - } else { - hardwareMotorType = MOTOR_BRUSHED; - } } void updateHardwareRevision(void) diff --git a/src/main/target/ALIENFLIGHTF4/hardware_revision.h b/src/main/target/ALIENFLIGHTF4/hardware_revision.h index e421b8896..410c8adca 100644 --- a/src/main/target/ALIENFLIGHTF4/hardware_revision.h +++ b/src/main/target/ALIENFLIGHTF4/hardware_revision.h @@ -22,14 +22,7 @@ typedef enum awf4HardwareRevision_t { AFF4_REV_2 // ICM-20602 (SPI), OpenSky RX (CC2510), Current Sensor (ACS712), SDCard Reader } awf4HardwareRevision_e; -typedef enum awf4HardwareMotorType_t { - MOTOR_UNKNOWN = 0, - MOTOR_BRUSHED, - MOTOR_BRUSHLESS -} awf4HardwareMotorType_e; - extern uint8_t hardwareRevision; -extern uint8_t hardwareMotorType; void updateHardwareRevision(void); void detectHardwareRevision(void); diff --git a/src/main/target/ALIENFLIGHTF4/target.h b/src/main/target/ALIENFLIGHTF4/target.h index 058759327..b85db3d9a 100644 --- a/src/main/target/ALIENFLIGHTF4/target.h +++ b/src/main/target/ALIENFLIGHTF4/target.h @@ -21,7 +21,7 @@ #define USE_HARDWARE_REVISION_DETECTION #define HW_PIN PC13 -#define MOTOR_PIN PB8 +#define BRUSHED_ESC_AUTODETECT #define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8) diff --git a/src/main/target/SPRACINGF3EVO/target.h b/src/main/target/SPRACINGF3EVO/target.h index 88e7d09f4..4cc76d154 100755 --- a/src/main/target/SPRACINGF3EVO/target.h +++ b/src/main/target/SPRACINGF3EVO/target.h @@ -21,6 +21,8 @@ #define CONFIG_FASTLOOP_PREFERRED_ACC ACC_DEFAULT +#define BRUSHED_ESC_AUTODETECT + #define LED0 PB8 #define BEEPER PC15 From fcb3ebf066971027e12eac6615fbda5ba4cb87a6 Mon Sep 17 00:00:00 2001 From: Michael Jakob Date: Fri, 9 Dec 2016 19:56:28 +0100 Subject: [PATCH 21/30] Change button code For SPRACINGF3MINI and OMNIBUS targets to new IO --- src/main/main.c | 23 ++++++++--------------- src/main/target/OMNIBUS/target.h | 6 ++---- src/main/target/SPRACINGF3MINI/target.h | 6 ++---- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/main/main.c b/src/main/main.c index 5df667d93..3c84bed7d 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -35,7 +35,6 @@ #include "drivers/sensor.h" #include "drivers/system.h" #include "drivers/dma.h" -#include "drivers/gpio.h" #include "drivers/io.h" #include "drivers/light_led.h" #include "drivers/sound_beeper.h" @@ -188,28 +187,22 @@ void init(void) #endif #if defined(BUTTONS) - gpio_config_t buttonAGpioConfig = { - BUTTON_A_PIN, - Mode_IPU, - Speed_2MHz - }; - gpioInit(BUTTON_A_PORT, &buttonAGpioConfig); + IO_t buttonAPin = IOGetByTag(IO_TAG(BUTTON_A_PIN)); + IOInit(buttonAPin, OWNER_SYSTEM, 0); + IOConfigGPIO(buttonAPin, IOCFG_IPU); - gpio_config_t buttonBGpioConfig = { - BUTTON_B_PIN, - Mode_IPU, - Speed_2MHz - }; - gpioInit(BUTTON_B_PORT, &buttonBGpioConfig); + IO_t buttonBPin = IOGetByTag(IO_TAG(BUTTON_B_PIN)); + IOInit(buttonBPin, OWNER_SYSTEM, 0); + IOConfigGPIO(buttonBPin, IOCFG_IPU); // Check status of bind plug and exit if not active - delayMicroseconds(10); // allow GPIO configuration to settle + delayMicroseconds(10); // allow configuration to settle if (!isMPUSoftReset()) { uint8_t secondsRemaining = 5; bool bothButtonsHeld; do { - bothButtonsHeld = !digitalIn(BUTTON_A_PORT, BUTTON_A_PIN) && !digitalIn(BUTTON_B_PORT, BUTTON_B_PIN); + bothButtonsHeld = !IORead(buttonAPin) && !IORead(buttonBPin); if (bothButtonsHeld) { if (--secondsRemaining == 0) { resetEEPROM(); diff --git a/src/main/target/OMNIBUS/target.h b/src/main/target/OMNIBUS/target.h index 166a57035..e88afed52 100644 --- a/src/main/target/OMNIBUS/target.h +++ b/src/main/target/OMNIBUS/target.h @@ -171,10 +171,8 @@ #define DEFAULT_FEATURES (FEATURE_VBAT | FEATURE_CURRENT_METER | FEATURE_BLACKBOX) #define BUTTONS -#define BUTTON_A_PORT GPIOB -#define BUTTON_A_PIN Pin_1 -#define BUTTON_B_PORT GPIOB -#define BUTTON_B_PIN Pin_0 +#define BUTTON_A_PIN PB1 +#define BUTTON_B_PIN PB0 #define AVOID_UART3_FOR_PWM_PPM diff --git a/src/main/target/SPRACINGF3MINI/target.h b/src/main/target/SPRACINGF3MINI/target.h index 79c1508ac..605e57a08 100644 --- a/src/main/target/SPRACINGF3MINI/target.h +++ b/src/main/target/SPRACINGF3MINI/target.h @@ -147,10 +147,8 @@ #define DEFAULT_FEATURES FEATURE_BLACKBOX #define BUTTONS -#define BUTTON_A_PORT GPIOB -#define BUTTON_A_PIN Pin_1 -#define BUTTON_B_PORT GPIOB -#define BUTTON_B_PIN Pin_0 +#define BUTTON_A_PIN PB1 +#define BUTTON_B_PIN PB0 #define SPEKTRUM_BIND // USART3, From 9220393a3cc72506dd7cc0c3b5b6aa0e94b0e468 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 11 Dec 2016 19:59:39 +1300 Subject: [PATCH 22/30] Re-enabled CLI verbose output for NAZE. --- src/main/target/NAZE/target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h index 184ea76ee..3b1f3c5fc 100644 --- a/src/main/target/NAZE/target.h +++ b/src/main/target/NAZE/target.h @@ -20,7 +20,7 @@ #define TARGET_CONFIG #define USE_HARDWARE_REVISION_DETECTION -#define CLI_MINIMAL_VERBOSITY +//#define CLI_MINIMAL_VERBOSITY #define BOARD_HAS_VOLTAGE_DIVIDER From c0a3e29cbf837b7854022a4ab1af0d133cb576de Mon Sep 17 00:00:00 2001 From: Sami Korhonen Date: Sun, 11 Dec 2016 11:31:54 +0200 Subject: [PATCH 23/30] Fix F7 motor output --- src/main/drivers/timer_hal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/drivers/timer_hal.c b/src/main/drivers/timer_hal.c index 263b49f00..127e2a1d5 100644 --- a/src/main/drivers/timer_hal.c +++ b/src/main/drivers/timer_hal.c @@ -872,7 +872,7 @@ const timerHardware_t *timerGetByTag(ioTag_t tag, timerUsageFlag_e flag) { for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) { if (timerHardware[i].tag == tag) { - if (timerHardware[i].output & flag) { + if (timerHardware[i].usageFlags & flag || flag == 0) { return &timerHardware[i]; } } From ad9852e0e8220be7d858c1071fc0e1ede20b3d61 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sun, 11 Dec 2016 20:41:05 +1100 Subject: [PATCH 24/30] Adjustments for REVOLT defaults --- src/main/target/REVO/target.c | 6 +++--- src/main/target/REVO/target.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/target/REVO/target.c b/src/main/target/REVO/target.c index 955d052cc..310ee9807 100644 --- a/src/main/target/REVO/target.c +++ b/src/main/target/REVO/target.c @@ -32,10 +32,10 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0, 0), // S5_IN DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM, 0, 0), // S6_IN #ifdef REVOLT - DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 1, 0), // S4_OUT D1_ST1 - DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 1, 0), // S2_OUT D1_ST2 - DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 1, 0), // S1_OUT D1_ST7 DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, 1, 1), // S3_OUT D1_ST6 + DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, 1, 0), // S2_OUT D1_ST2 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 1, 0), // S4_OUT D1_ST1 + DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 1, 0), // S1_OUT D1_ST7 DEF_TIM(TIM4, CH1, PB6, TIM_USE_LED, 0, 0), // LED for REVOLT D1_ST0 #else DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR, 1, 0), // S1_OUT D1_ST7 diff --git a/src/main/target/REVO/target.h b/src/main/target/REVO/target.h index 710590d1d..e6dc29eb4 100644 --- a/src/main/target/REVO/target.h +++ b/src/main/target/REVO/target.h @@ -78,6 +78,16 @@ #define USE_GYRO_SPI_MPU6000 #define ACC_MPU6000_ALIGN CW180_DEG +#elif defined(REVOLT) + + #define USE_ACC_MPU6500 + #define USE_ACC_SPI_MPU6500 + #define ACC_MPU6500_ALIGN CW0_DEG + + #define USE_GYRO_MPU6500 + #define USE_GYRO_SPI_MPU6500 + #define GYRO_MPU6500_ALIGN CW0_DEG + #else #define ACC #define USE_ACC_SPI_MPU6000 From 3debda45f3a67e39edca2e8d9bcacb5cdc83408d Mon Sep 17 00:00:00 2001 From: blckmn Date: Sun, 11 Dec 2016 20:43:09 +1100 Subject: [PATCH 25/30] Removed whitespace before #define --- src/main/target/REVO/target.h | 96 +++++++++++++++++------------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/main/target/REVO/target.h b/src/main/target/REVO/target.h index e6dc29eb4..9c153dc06 100644 --- a/src/main/target/REVO/target.h +++ b/src/main/target/REVO/target.h @@ -20,24 +20,24 @@ #define CONFIG_START_FLASH_ADDRESS (0x08080000) //0x08080000 to 0x080A0000 (FLASH_Sector_8) #if defined(AIRBOTF4) - #define TARGET_BOARD_IDENTIFIER "AIR4" - #define USBD_PRODUCT_STRING "AirbotF4" +#define TARGET_BOARD_IDENTIFIER "AIR4" +#define USBD_PRODUCT_STRING "AirbotF4" #elif defined(REVOLT) - #define TARGET_BOARD_IDENTIFIER "RVLT" - #define USBD_PRODUCT_STRING "Revolt" +#define TARGET_BOARD_IDENTIFIER "RVLT" +#define USBD_PRODUCT_STRING "Revolt" #elif defined(SOULF4) - #define TARGET_BOARD_IDENTIFIER "SOUL" - #define USBD_PRODUCT_STRING "DemonSoulF4" +#define TARGET_BOARD_IDENTIFIER "SOUL" +#define USBD_PRODUCT_STRING "DemonSoulF4" #else - #define TARGET_BOARD_IDENTIFIER "REVO" - #define USBD_PRODUCT_STRING "Revolution" +#define TARGET_BOARD_IDENTIFIER "REVO" +#define USBD_PRODUCT_STRING "Revolution" - #ifdef OPBL - #define USBD_SERIALNUMBER_STRING "0x8020000" - #endif +#ifdef OPBL +#define USBD_SERIALNUMBER_STRING "0x8020000" +#endif #endif @@ -46,17 +46,17 @@ #define LED0 PB5 // Disable LED1, conflicts with AirbotF4/Flip32F4/Revolt beeper #if defined(AIRBOTF4) - #define BEEPER PB4 - #define BEEPER_INVERTED +#define BEEPER PB4 +#define BEEPER_INVERTED #elif defined(REVOLT) - #define BEEPER PB4 +#define BEEPER PB4 #elif defined(SOULF4) - #define BEEPER PB6 - #define BEEPER_INVERTED +#define BEEPER PB6 +#define BEEPER_INVERTED #else - #define LED1 PB4 - // Leave beeper here but with none as io - so disabled unless mapped. - #define BEEPER NONE +#define LED1 PB4 +// Leave beeper here but with none as io - so disabled unless mapped. +#define BEEPER NONE #endif // PC0 used as inverter select GPIO @@ -70,40 +70,40 @@ #define MPU6500_SPI_INSTANCE SPI1 #if defined(SOULF4) - #define ACC - #define USE_ACC_SPI_MPU6000 - #define GYRO_MPU6000_ALIGN CW180_DEG +#define ACC +#define USE_ACC_SPI_MPU6000 +#define GYRO_MPU6000_ALIGN CW180_DEG - #define GYRO - #define USE_GYRO_SPI_MPU6000 - #define ACC_MPU6000_ALIGN CW180_DEG +#define GYRO +#define USE_GYRO_SPI_MPU6000 +#define ACC_MPU6000_ALIGN CW180_DEG #elif defined(REVOLT) - #define USE_ACC_MPU6500 - #define USE_ACC_SPI_MPU6500 - #define ACC_MPU6500_ALIGN CW0_DEG +#define USE_ACC_MPU6500 +#define USE_ACC_SPI_MPU6500 +#define ACC_MPU6500_ALIGN CW0_DEG - #define USE_GYRO_MPU6500 - #define USE_GYRO_SPI_MPU6500 - #define GYRO_MPU6500_ALIGN CW0_DEG +#define USE_GYRO_MPU6500 +#define USE_GYRO_SPI_MPU6500 +#define GYRO_MPU6500_ALIGN CW0_DEG #else - #define ACC - #define USE_ACC_SPI_MPU6000 - #define GYRO_MPU6000_ALIGN CW270_DEG +#define ACC +#define USE_ACC_SPI_MPU6000 +#define GYRO_MPU6000_ALIGN CW270_DEG - #define USE_ACC_MPU6500 - #define USE_ACC_SPI_MPU6500 - #define ACC_MPU6500_ALIGN CW270_DEG +#define USE_ACC_MPU6500 +#define USE_ACC_SPI_MPU6500 +#define ACC_MPU6500_ALIGN CW270_DEG - #define GYRO - #define USE_GYRO_SPI_MPU6000 - #define ACC_MPU6000_ALIGN CW270_DEG +#define GYRO +#define USE_GYRO_SPI_MPU6000 +#define ACC_MPU6000_ALIGN CW270_DEG - #define USE_GYRO_MPU6500 - #define USE_GYRO_SPI_MPU6500 - #define GYRO_MPU6500_ALIGN CW270_DEG +#define USE_GYRO_MPU6500 +#define USE_GYRO_SPI_MPU6500 +#define GYRO_MPU6500_ALIGN CW270_DEG #endif @@ -113,12 +113,12 @@ #define USE_MPU_DATA_READY_SIGNAL #if !defined(AIRBOTF4) && !defined(REVOLT) && !defined(SOULF4) - #define MAG - #define USE_MAG_HMC5883 - #define MAG_HMC5883_ALIGN CW90_DEG +#define MAG +#define USE_MAG_HMC5883 +#define MAG_HMC5883_ALIGN CW90_DEG - #define BARO - #define USE_BARO_MS5611 +#define BARO +#define USE_BARO_MS5611 #endif From f4e9ea40df2b7e33f3dd371135970d7060c458b9 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sun, 11 Dec 2016 09:45:21 +0000 Subject: [PATCH 26/30] Reordered accgyro functions to avoid forward declarations --- src/main/drivers/accgyro_adxl345.c | 35 +++++++--------- src/main/drivers/accgyro_bma280.c | 29 ++++++------- src/main/drivers/accgyro_l3g4200d.c | 41 +++++++++--------- src/main/drivers/accgyro_mma845x.c | 31 +++++++------- src/main/drivers/accgyro_mpu3050.c | 37 ++++++++--------- src/main/drivers/accgyro_mpu6050.c | 55 ++++++++++++------------- src/main/drivers/accgyro_mpu6500.c | 42 +++++++++---------- src/main/drivers/accgyro_spi_icm20689.c | 43 ++++++++++--------- 8 files changed, 147 insertions(+), 166 deletions(-) diff --git a/src/main/drivers/accgyro_adxl345.c b/src/main/drivers/accgyro_adxl345.c index 86ee11f4f..122062318 100644 --- a/src/main/drivers/accgyro_adxl345.c +++ b/src/main/drivers/accgyro_adxl345.c @@ -56,27 +56,8 @@ #define ADXL345_RANGE_16G 0x03 #define ADXL345_FIFO_STREAM 0x80 -static void adxl345Init(accDev_t *acc); -static bool adxl345Read(int16_t *accelData); - static bool useFifo = false; -bool adxl345Detect(drv_adxl345_config_t *init, accDev_t *acc) -{ - uint8_t sig = 0; - bool ack = i2cRead(MPU_I2C_INSTANCE, ADXL345_ADDRESS, 0x00, 1, &sig); - - if (!ack || sig != 0xE5) - return false; - - // use ADXL345's fifo to filter data or not - useFifo = init->useFifo; - - acc->init = adxl345Init; - acc->read = adxl345Read; - return true; -} - static void adxl345Init(accDev_t *acc) { if (useFifo) { @@ -135,3 +116,19 @@ static bool adxl345Read(int16_t *accelData) return true; } + +bool adxl345Detect(drv_adxl345_config_t *init, accDev_t *acc) +{ + uint8_t sig = 0; + bool ack = i2cRead(MPU_I2C_INSTANCE, ADXL345_ADDRESS, 0x00, 1, &sig); + + if (!ack || sig != 0xE5) + return false; + + // use ADXL345's fifo to filter data or not + useFifo = init->useFifo; + + acc->init = adxl345Init; + acc->read = adxl345Read; + return true; +} diff --git a/src/main/drivers/accgyro_bma280.c b/src/main/drivers/accgyro_bma280.c index 3b0ec6e85..3c285a942 100644 --- a/src/main/drivers/accgyro_bma280.c +++ b/src/main/drivers/accgyro_bma280.c @@ -32,22 +32,6 @@ #define BMA280_PMU_BW 0x10 #define BMA280_PMU_RANGE 0x0F -static void bma280Init(accDev_t *acc); -static bool bma280Read(int16_t *accelData); - -bool bma280Detect(accDev_t *acc) -{ - uint8_t sig = 0; - bool ack = i2cRead(MPU_I2C_INSTANCE, BMA280_ADDRESS, 0x00, 1, &sig); - - if (!ack || sig != 0xFB) - return false; - - acc->init = bma280Init; - acc->read = bma280Read; - return true; -} - static void bma280Init(accDev_t *acc) { i2cWrite(MPU_I2C_INSTANCE, BMA280_ADDRESS, BMA280_PMU_RANGE, 0x08); // +-8g range @@ -71,3 +55,16 @@ static bool bma280Read(int16_t *accelData) return true; } + +bool bma280Detect(accDev_t *acc) +{ + uint8_t sig = 0; + bool ack = i2cRead(MPU_I2C_INSTANCE, BMA280_ADDRESS, 0x00, 1, &sig); + + if (!ack || sig != 0xFB) + return false; + + acc->init = bma280Init; + acc->read = bma280Read; + return true; +} diff --git a/src/main/drivers/accgyro_l3g4200d.c b/src/main/drivers/accgyro_l3g4200d.c index 2183bebdf..170bb0fe7 100644 --- a/src/main/drivers/accgyro_l3g4200d.c +++ b/src/main/drivers/accgyro_l3g4200d.c @@ -54,28 +54,6 @@ #define L3G4200D_DLPF_78HZ 0x80 #define L3G4200D_DLPF_93HZ 0xC0 -static void l3g4200dInit(gyroDev_t *gyro); -static bool l3g4200dRead(gyroDev_t *gyro); - -bool l3g4200dDetect(gyroDev_t *gyro) -{ - uint8_t deviceid; - - delay(25); - - i2cRead(MPU_I2C_INSTANCE, L3G4200D_ADDRESS, L3G4200D_WHO_AM_I, 1, &deviceid); - if (deviceid != L3G4200D_ID) - return false; - - gyro->init = l3g4200dInit; - gyro->read = l3g4200dRead; - - // 14.2857dps/lsb scalefactor - gyro->scale = 1.0f / 14.2857f; - - return true; -} - static void l3g4200dInit(gyroDev_t *gyro) { bool ack; @@ -123,3 +101,22 @@ static bool l3g4200dRead(gyroDev_t *gyro) return true; } + +bool l3g4200dDetect(gyroDev_t *gyro) +{ + uint8_t deviceid; + + delay(25); + + i2cRead(MPU_I2C_INSTANCE, L3G4200D_ADDRESS, L3G4200D_WHO_AM_I, 1, &deviceid); + if (deviceid != L3G4200D_ID) + return false; + + gyro->init = l3g4200dInit; + gyro->read = l3g4200dRead; + + // 14.2857dps/lsb scalefactor + gyro->scale = 1.0f / 14.2857f; + + return true; +} diff --git a/src/main/drivers/accgyro_mma845x.c b/src/main/drivers/accgyro_mma845x.c index c4b65fdcc..7dcb4ed19 100644 --- a/src/main/drivers/accgyro_mma845x.c +++ b/src/main/drivers/accgyro_mma845x.c @@ -81,23 +81,6 @@ static uint8_t device_id; -static void mma8452Init(accDev_t *acc); -static bool mma8452Read(int16_t *accelData); - -bool mma8452Detect(accDev_t *acc) -{ - uint8_t sig = 0; - bool ack = i2cRead(MPU_I2C_INSTANCE, MMA8452_ADDRESS, MMA8452_WHO_AM_I, 1, &sig); - - if (!ack || (sig != MMA8452_DEVICE_SIGNATURE && sig != MMA8451_DEVICE_SIGNATURE)) - return false; - - acc->init = mma8452Init; - acc->read = mma8452Read; - device_id = sig; - return true; -} - static inline void mma8451ConfigureInterrupt(void) { #ifdef NAZE @@ -142,3 +125,17 @@ static bool mma8452Read(int16_t *accelData) return true; } + +bool mma8452Detect(accDev_t *acc) +{ + uint8_t sig = 0; + bool ack = i2cRead(MPU_I2C_INSTANCE, MMA8452_ADDRESS, MMA8452_WHO_AM_I, 1, &sig); + + if (!ack || (sig != MMA8452_DEVICE_SIGNATURE && sig != MMA8451_DEVICE_SIGNATURE)) + return false; + + acc->init = mma8452Init; + acc->read = mma8452Read; + device_id = sig; + return true; +} diff --git a/src/main/drivers/accgyro_mpu3050.c b/src/main/drivers/accgyro_mpu3050.c index 4d8d84fba..800c128c3 100644 --- a/src/main/drivers/accgyro_mpu3050.c +++ b/src/main/drivers/accgyro_mpu3050.c @@ -46,25 +46,6 @@ #define MPU3050_USER_RESET 0x01 #define MPU3050_CLK_SEL_PLL_GX 0x01 -static void mpu3050Init(gyroDev_t *gyro); -static bool mpu3050ReadTemp(int16_t *tempData); - -bool mpu3050Detect(gyroDev_t *gyro) -{ - if (mpuDetectionResult.sensor != MPU_3050) { - return false; - } - gyro->init = mpu3050Init; - gyro->read = mpuGyroRead; - gyro->temperature = mpu3050ReadTemp; - gyro->intStatus = checkMPUDataReady; - - // 16.4 dps/lsb scalefactor - gyro->scale = 1.0f / 16.4f; - - return true; -} - static void mpu3050Init(gyroDev_t *gyro) { bool ack; @@ -81,7 +62,7 @@ static void mpu3050Init(gyroDev_t *gyro) mpuConfiguration.write(MPU3050_PWR_MGM, MPU3050_CLK_SEL_PLL_GX); } -static bool mpu3050ReadTemp(int16_t *tempData) +static bool mpu3050ReadTemperature(int16_t *tempData) { uint8_t buf[2]; if (!mpuConfiguration.read(MPU3050_TEMP_OUT, 2, buf)) { @@ -92,3 +73,19 @@ static bool mpu3050ReadTemp(int16_t *tempData) return true; } + +bool mpu3050Detect(gyroDev_t *gyro) +{ + if (mpuDetectionResult.sensor != MPU_3050) { + return false; + } + gyro->init = mpu3050Init; + gyro->read = mpuGyroRead; + gyro->temperature = mpu3050ReadTemperature; + gyro->intStatus = checkMPUDataReady; + + // 16.4 dps/lsb scalefactor + gyro->scale = 1.0f / 16.4f; + + return true; +} diff --git a/src/main/drivers/accgyro_mpu6050.c b/src/main/drivers/accgyro_mpu6050.c index af91df4e8..eb57bc801 100644 --- a/src/main/drivers/accgyro_mpu6050.c +++ b/src/main/drivers/accgyro_mpu6050.c @@ -50,8 +50,17 @@ #define MPU6050_SMPLRT_DIV 0 // 8000Hz -static void mpu6050AccInit(accDev_t *acc); -static void mpu6050GyroInit(gyroDev_t *gyro); +static void mpu6050AccInit(accDev_t *acc) +{ + switch (mpuDetectionResult.resolution) { + case MPU_HALF_RESOLUTION: + acc->acc_1G = 256 * 4; + break; + case MPU_FULL_RESOLUTION: + acc->acc_1G = 512 * 4; + break; + } +} bool mpu6050AccDetect(accDev_t *acc) { @@ -66,33 +75,6 @@ bool mpu6050AccDetect(accDev_t *acc) return true; } -bool mpu6050GyroDetect(gyroDev_t *gyro) -{ - if (mpuDetectionResult.sensor != MPU_60x0) { - return false; - } - gyro->init = mpu6050GyroInit; - gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; - - // 16.4 dps/lsb scalefactor - gyro->scale = 1.0f / 16.4f; - - return true; -} - -static void mpu6050AccInit(accDev_t *acc) -{ - switch (mpuDetectionResult.resolution) { - case MPU_HALF_RESOLUTION: - acc->acc_1G = 256 * 4; - break; - case MPU_FULL_RESOLUTION: - acc->acc_1G = 512 * 4; - break; - } -} - static void mpu6050GyroInit(gyroDev_t *gyro) { mpuGyroInit(gyro); @@ -116,3 +98,18 @@ static void mpu6050GyroInit(gyroDev_t *gyro) mpuConfiguration.write(MPU_RA_INT_ENABLE, MPU_RF_DATA_RDY_EN); #endif } + +bool mpu6050GyroDetect(gyroDev_t *gyro) +{ + if (mpuDetectionResult.sensor != MPU_60x0) { + return false; + } + gyro->init = mpu6050GyroInit; + gyro->read = mpuGyroRead; + gyro->intStatus = checkMPUDataReady; + + // 16.4 dps/lsb scalefactor + gyro->scale = 1.0f / 16.4f; + + return true; +} diff --git a/src/main/drivers/accgyro_mpu6500.c b/src/main/drivers/accgyro_mpu6500.c index d4257c15f..295fd815a 100644 --- a/src/main/drivers/accgyro_mpu6500.c +++ b/src/main/drivers/accgyro_mpu6500.c @@ -34,6 +34,11 @@ #include "accgyro_mpu.h" #include "accgyro_mpu6500.h" +void mpu6500AccInit(accDev_t *acc) +{ + acc->acc_1G = 512 * 4; +} + bool mpu6500AccDetect(accDev_t *acc) { if (mpuDetectionResult.sensor != MPU_65xx_I2C) { @@ -46,27 +51,6 @@ bool mpu6500AccDetect(accDev_t *acc) return true; } -bool mpu6500GyroDetect(gyroDev_t *gyro) -{ - if (mpuDetectionResult.sensor != MPU_65xx_I2C) { - return false; - } - - gyro->init = mpu6500GyroInit; - gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; - - // 16.4 dps/lsb scalefactor - gyro->scale = 1.0f / 16.4f; - - return true; -} - -void mpu6500AccInit(accDev_t *acc) -{ - acc->acc_1G = 512 * 4; -} - void mpu6500GyroInit(gyroDev_t *gyro) { mpuGyroInit(gyro); @@ -101,3 +85,19 @@ void mpu6500GyroInit(gyroDev_t *gyro) #endif delay(15); } + +bool mpu6500GyroDetect(gyroDev_t *gyro) +{ + if (mpuDetectionResult.sensor != MPU_65xx_I2C) { + return false; + } + + gyro->init = mpu6500GyroInit; + gyro->read = mpuGyroRead; + gyro->intStatus = checkMPUDataReady; + + // 16.4 dps/lsb scalefactor + gyro->scale = 1.0f / 16.4f; + + return true; +} diff --git a/src/main/drivers/accgyro_spi_icm20689.c b/src/main/drivers/accgyro_spi_icm20689.c index 95d94fccc..af432735b 100644 --- a/src/main/drivers/accgyro_spi_icm20689.c +++ b/src/main/drivers/accgyro_spi_icm20689.c @@ -107,6 +107,11 @@ bool icm20689SpiDetect(void) } +void icm20689AccInit(accDev_t *acc) +{ + acc->acc_1G = 512 * 4; +} + bool icm20689SpiAccDetect(accDev_t *acc) { if (mpuDetectionResult.sensor != ICM_20689_SPI) { @@ -119,27 +124,6 @@ bool icm20689SpiAccDetect(accDev_t *acc) return true; } -bool icm20689SpiGyroDetect(gyroDev_t *gyro) -{ - if (mpuDetectionResult.sensor != ICM_20689_SPI) { - return false; - } - - gyro->init = icm20689GyroInit; - gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; - - // 16.4 dps/lsb scalefactor - gyro->scale = 1.0f / 16.4f; - - return true; -} - -void icm20689AccInit(accDev_t *acc) -{ - acc->acc_1G = 512 * 4; -} - void icm20689GyroInit(gyroDev_t *gyro) { mpuGyroInit(gyro); @@ -174,5 +158,20 @@ void icm20689GyroInit(gyroDev_t *gyro) #endif spiSetDivisor(ICM20689_SPI_INSTANCE, SPI_CLOCK_STANDARD); - +} + +bool icm20689SpiGyroDetect(gyroDev_t *gyro) +{ + if (mpuDetectionResult.sensor != ICM_20689_SPI) { + return false; + } + + gyro->init = icm20689GyroInit; + gyro->read = mpuGyroRead; + gyro->intStatus = checkMPUDataReady; + + // 16.4 dps/lsb scalefactor + gyro->scale = 1.0f / 16.4f; + + return true; } From 73655b627ea842388272e292e334627a71a2462a Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sun, 11 Dec 2016 11:27:57 +0000 Subject: [PATCH 27/30] Reenabled minimal verbosity for NAZE, since builds failing --- src/main/target/NAZE/target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/target/NAZE/target.h b/src/main/target/NAZE/target.h index 14290c6a4..2272a5552 100644 --- a/src/main/target/NAZE/target.h +++ b/src/main/target/NAZE/target.h @@ -21,7 +21,7 @@ #define USE_HARDWARE_REVISION_DETECTION #define TARGET_BUS_INIT -//#define CLI_MINIMAL_VERBOSITY +#define CLI_MINIMAL_VERBOSITY #define BOARD_HAS_VOLTAGE_DIVIDER From 7f4617b676cfd6a34ca32679d2771b7eb1ae0a45 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sun, 11 Dec 2016 10:40:51 +0000 Subject: [PATCH 28/30] Renamed MPU functions to have mpu prefix --- src/main/drivers/accgyro_mpu.c | 4 ++-- src/main/drivers/accgyro_mpu.h | 6 +++--- src/main/drivers/accgyro_mpu3050.c | 2 +- src/main/drivers/accgyro_mpu6050.c | 2 +- src/main/drivers/accgyro_mpu6500.c | 2 +- src/main/drivers/accgyro_spi_icm20689.c | 2 +- src/main/drivers/accgyro_spi_mpu6000.c | 2 +- src/main/drivers/accgyro_spi_mpu6500.c | 2 +- src/main/drivers/accgyro_spi_mpu9250.c | 2 +- src/main/sensors/initialisation.c | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/drivers/accgyro_mpu.c b/src/main/drivers/accgyro_mpu.c index 3f59e2fb9..7c87b8fdd 100644 --- a/src/main/drivers/accgyro_mpu.c +++ b/src/main/drivers/accgyro_mpu.c @@ -75,7 +75,7 @@ static const extiConfig_t *mpuIntExtiConfig = NULL; #define MPU_INQUIRY_MASK 0x7E -mpuDetectionResult_t *detectMpu(const extiConfig_t *configToUse) +mpuDetectionResult_t *mpuDetect(const extiConfig_t *configToUse) { memset(&mpuDetectionResult, 0, sizeof(mpuDetectionResult)); memset(&mpuConfiguration, 0, sizeof(mpuConfiguration)); @@ -334,7 +334,7 @@ void mpuGyroInit(gyroDev_t *gyro) mpuIntExtiInit(gyro); } -bool checkMPUDataReady(gyroDev_t* gyro) +bool mpuCheckDataReady(gyroDev_t* gyro) { bool ret; if (gyro->dataReady) { diff --git a/src/main/drivers/accgyro_mpu.h b/src/main/drivers/accgyro_mpu.h index 2eafe89f0..cb97af5ce 100644 --- a/src/main/drivers/accgyro_mpu.h +++ b/src/main/drivers/accgyro_mpu.h @@ -183,10 +183,10 @@ typedef struct mpuDetectionResult_s { extern mpuDetectionResult_t mpuDetectionResult; -void configureMPUDataReadyInterruptHandling(void); +void mpuConfigureDataReadyInterruptHandling(void); struct gyroDev_s; void mpuGyroInit(struct gyroDev_s *gyro); bool mpuAccRead(int16_t *accData); bool mpuGyroRead(struct gyroDev_s *gyro); -mpuDetectionResult_t *detectMpu(const extiConfig_t *configToUse); -bool checkMPUDataReady(struct gyroDev_s *gyro); +mpuDetectionResult_t *mpuDetect(const extiConfig_t *configToUse); +bool mpuCheckDataReady(struct gyroDev_s *gyro); diff --git a/src/main/drivers/accgyro_mpu3050.c b/src/main/drivers/accgyro_mpu3050.c index 800c128c3..fe4692c20 100644 --- a/src/main/drivers/accgyro_mpu3050.c +++ b/src/main/drivers/accgyro_mpu3050.c @@ -82,7 +82,7 @@ bool mpu3050Detect(gyroDev_t *gyro) gyro->init = mpu3050Init; gyro->read = mpuGyroRead; gyro->temperature = mpu3050ReadTemperature; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/accgyro_mpu6050.c b/src/main/drivers/accgyro_mpu6050.c index eb57bc801..35d475a3a 100644 --- a/src/main/drivers/accgyro_mpu6050.c +++ b/src/main/drivers/accgyro_mpu6050.c @@ -106,7 +106,7 @@ bool mpu6050GyroDetect(gyroDev_t *gyro) } gyro->init = mpu6050GyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/accgyro_mpu6500.c b/src/main/drivers/accgyro_mpu6500.c index 295fd815a..a5254ba59 100644 --- a/src/main/drivers/accgyro_mpu6500.c +++ b/src/main/drivers/accgyro_mpu6500.c @@ -94,7 +94,7 @@ bool mpu6500GyroDetect(gyroDev_t *gyro) gyro->init = mpu6500GyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/accgyro_spi_icm20689.c b/src/main/drivers/accgyro_spi_icm20689.c index af432735b..286e2171e 100644 --- a/src/main/drivers/accgyro_spi_icm20689.c +++ b/src/main/drivers/accgyro_spi_icm20689.c @@ -168,7 +168,7 @@ bool icm20689SpiGyroDetect(gyroDev_t *gyro) gyro->init = icm20689GyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/accgyro_spi_mpu6000.c b/src/main/drivers/accgyro_spi_mpu6000.c index 2f0fe9443..67192ecef 100644 --- a/src/main/drivers/accgyro_spi_mpu6000.c +++ b/src/main/drivers/accgyro_spi_mpu6000.c @@ -274,7 +274,7 @@ bool mpu6000SpiGyroDetect(gyroDev_t *gyro) gyro->init = mpu6000SpiGyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/accgyro_spi_mpu6500.c b/src/main/drivers/accgyro_spi_mpu6500.c index b14a9ca93..a6a19f7ad 100755 --- a/src/main/drivers/accgyro_spi_mpu6500.c +++ b/src/main/drivers/accgyro_spi_mpu6500.c @@ -134,7 +134,7 @@ bool mpu6500SpiGyroDetect(gyroDev_t *gyro) gyro->init = mpu6500SpiGyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/drivers/accgyro_spi_mpu9250.c b/src/main/drivers/accgyro_spi_mpu9250.c index 81415fac1..8e9253a71 100644 --- a/src/main/drivers/accgyro_spi_mpu9250.c +++ b/src/main/drivers/accgyro_spi_mpu9250.c @@ -229,7 +229,7 @@ bool mpu9250SpiGyroDetect(gyroDev_t *gyro) gyro->init = mpu9250SpiGyroInit; gyro->read = mpuGyroRead; - gyro->intStatus = checkMPUDataReady; + gyro->intStatus = mpuCheckDataReady; // 16.4 dps/lsb scalefactor gyro->scale = 1.0f / 16.4f; diff --git a/src/main/sensors/initialisation.c b/src/main/sensors/initialisation.c index 4e43b50ba..341ca113e 100755 --- a/src/main/sensors/initialisation.c +++ b/src/main/sensors/initialisation.c @@ -91,7 +91,7 @@ bool sensorsAutodetect(const gyroConfig_t *gyroConfig, const extiConfig_t *extiConfig = selectMPUIntExtiConfig(); - mpuDetectionResult_t *mpuDetectionResult = detectMpu(extiConfig); + mpuDetectionResult_t *mpuDetectionResult = mpuDetect(extiConfig); UNUSED(mpuDetectionResult); #endif From 78d0e00b356b84db356a8e6ff78551b09419b7f5 Mon Sep 17 00:00:00 2001 From: Michael Jakob Date: Sun, 11 Dec 2016 15:10:28 +0100 Subject: [PATCH 29/30] AlienFlight documentation update --- src/main/target/ALIENFLIGHTF1/AlienFlight.md | 3 ++- src/main/target/ALIENFLIGHTF3/AlienFlight.md | 3 ++- src/main/target/ALIENFLIGHTF4/AlienFlight.md | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/target/ALIENFLIGHTF1/AlienFlight.md b/src/main/target/ALIENFLIGHTF1/AlienFlight.md index 3510b52c1..4c33df568 100644 --- a/src/main/target/ALIENFLIGHTF1/AlienFlight.md +++ b/src/main/target/ALIENFLIGHTF1/AlienFlight.md @@ -2,9 +2,10 @@ AlienWii is now AlienFlight. This targets supports various variants of brushed and brushless flight controllers. The designs for them are released partially for public use at: +http://www.alienflight.com http://www.alienflightng.com -The legacy designs are available at: +AlienFlight Classic and F3 Eagle files are available at: https://github.com/MJ666/Flight-Controllers diff --git a/src/main/target/ALIENFLIGHTF3/AlienFlight.md b/src/main/target/ALIENFLIGHTF3/AlienFlight.md index 3510b52c1..4c33df568 100644 --- a/src/main/target/ALIENFLIGHTF3/AlienFlight.md +++ b/src/main/target/ALIENFLIGHTF3/AlienFlight.md @@ -2,9 +2,10 @@ AlienWii is now AlienFlight. This targets supports various variants of brushed and brushless flight controllers. The designs for them are released partially for public use at: +http://www.alienflight.com http://www.alienflightng.com -The legacy designs are available at: +AlienFlight Classic and F3 Eagle files are available at: https://github.com/MJ666/Flight-Controllers diff --git a/src/main/target/ALIENFLIGHTF4/AlienFlight.md b/src/main/target/ALIENFLIGHTF4/AlienFlight.md index 3510b52c1..4c33df568 100644 --- a/src/main/target/ALIENFLIGHTF4/AlienFlight.md +++ b/src/main/target/ALIENFLIGHTF4/AlienFlight.md @@ -2,9 +2,10 @@ AlienWii is now AlienFlight. This targets supports various variants of brushed and brushless flight controllers. The designs for them are released partially for public use at: +http://www.alienflight.com http://www.alienflightng.com -The legacy designs are available at: +AlienFlight Classic and F3 Eagle files are available at: https://github.com/MJ666/Flight-Controllers From c59525216a86b67e141bb70bc36c9a6572041f8a Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sun, 11 Dec 2016 18:55:38 +0000 Subject: [PATCH 30/30] Fixed NUCLEOF7 target build --- src/main/target/NUCLEOF7/target.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/target/NUCLEOF7/target.mk b/src/main/target/NUCLEOF7/target.mk index 3be893c11..f1e20157b 100644 --- a/src/main/target/NUCLEOF7/target.mk +++ b/src/main/target/NUCLEOF7/target.mk @@ -2,8 +2,11 @@ F7X6XG_TARGETS += $(TARGET) FEATURES += SDCARD VCP TARGET_SRC = \ + drivers/accgyro_fake.c \ drivers/accgyro_mpu6050.c \ + drivers/barometer_fake.c \ drivers/barometer_ms5611.c \ + drivers/compass_fake.c \ drivers/compass_hmc5883l.c \ drivers/light_ws2811strip.c \ drivers/light_ws2811strip_hal.c