mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 04:45:24 +03:00
CC3D / NAZE - Adding support for hardware controlled inverter for use by
SBUS RX.
This commit is contained in:
parent
f08760634e
commit
4d9a672d9c
8 changed files with 103 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -184,6 +184,7 @@ NAZE_SRC = startup_stm32f10x_md_gcc.S \
|
||||||
drivers/bus_i2c_stm32f10x.c \
|
drivers/bus_i2c_stm32f10x.c \
|
||||||
drivers/compass_hmc5883l.c \
|
drivers/compass_hmc5883l.c \
|
||||||
drivers/gpio_stm32f10x.c \
|
drivers/gpio_stm32f10x.c \
|
||||||
|
drivers/inverter.c \
|
||||||
drivers/light_led_stm32f10x.c \
|
drivers/light_led_stm32f10x.c \
|
||||||
drivers/light_ws2811strip.c \
|
drivers/light_ws2811strip.c \
|
||||||
drivers/light_ws2811strip_stm32f10x.c \
|
drivers/light_ws2811strip_stm32f10x.c \
|
||||||
|
@ -252,6 +253,7 @@ CC3D_SRC = startup_stm32f10x_md_gcc.S \
|
||||||
drivers/bus_i2c_stm32f10x.c \
|
drivers/bus_i2c_stm32f10x.c \
|
||||||
drivers/bus_spi.c \
|
drivers/bus_spi.c \
|
||||||
drivers/gpio_stm32f10x.c \
|
drivers/gpio_stm32f10x.c \
|
||||||
|
drivers/inverter.c \
|
||||||
drivers/light_led_stm32f10x.c \
|
drivers/light_led_stm32f10x.c \
|
||||||
drivers/light_ws2811strip.c \
|
drivers/light_ws2811strip.c \
|
||||||
drivers/light_ws2811strip_stm32f10x.c \
|
drivers/light_ws2811strip_stm32f10x.c \
|
||||||
|
|
43
src/main/drivers/inverter.c
Normal file
43
src/main/drivers/inverter.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Cleanflight.
|
||||||
|
*
|
||||||
|
* Cleanflight is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#include "gpio.h"
|
||||||
|
|
||||||
|
#include "inverter.h"
|
||||||
|
|
||||||
|
void initInverter(void)
|
||||||
|
{
|
||||||
|
#ifdef INVERTER
|
||||||
|
struct {
|
||||||
|
GPIO_TypeDef *gpio;
|
||||||
|
gpio_config_t cfg;
|
||||||
|
} gpio_setup = {
|
||||||
|
.gpio = INVERTER_GPIO,
|
||||||
|
.cfg = { INVERTER_PIN, Mode_Out_OD, Speed_2MHz }
|
||||||
|
};
|
||||||
|
|
||||||
|
RCC_APB2PeriphClockCmd(INVERTER_PERIPHERAL, ENABLE);
|
||||||
|
|
||||||
|
gpioInit(gpio_setup.gpio, &gpio_setup.cfg);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
29
src/main/drivers/inverter.h
Normal file
29
src/main/drivers/inverter.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Cleanflight.
|
||||||
|
*
|
||||||
|
* Cleanflight is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef INVERTER
|
||||||
|
#define INVERTER_OFF digitalLo(INVERTER_GPIO, INVERTER_PIN);
|
||||||
|
#define INVERTER_ON digitalHi(INVERTER_GPIO, INVERTER_PIN);
|
||||||
|
#else
|
||||||
|
#define INVERTER_OFF ;
|
||||||
|
#define INVERTER_ON ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void initInverter(void);
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
|
|
||||||
#include "build_config.h"
|
#include "build_config.h"
|
||||||
|
|
||||||
|
#include "gpio.h"
|
||||||
|
#include "inverter.h"
|
||||||
|
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "serial_uart.h"
|
#include "serial_uart.h"
|
||||||
|
|
||||||
|
@ -64,6 +67,13 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback,
|
||||||
|
|
||||||
uartPort_t *s = NULL;
|
uartPort_t *s = NULL;
|
||||||
|
|
||||||
|
#ifdef INVERTER
|
||||||
|
if (inversion == SERIAL_INVERTED && USARTx == INVERTER_USART) {
|
||||||
|
// Enable hardware inverter if available.
|
||||||
|
INVERTER_ON;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (USARTx == USART1) {
|
if (USARTx == USART1) {
|
||||||
s = serialUSART1(baudRate, mode);
|
s = serialUSART1(baudRate, mode);
|
||||||
} else if (USARTx == USART2) {
|
} else if (USARTx == USART2) {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "light_led.h"
|
#include "light_led.h"
|
||||||
#include "sound_beeper.h"
|
#include "sound_beeper.h"
|
||||||
|
#include "inverter.h"
|
||||||
#include "bus_i2c.h"
|
#include "bus_i2c.h"
|
||||||
#include "bus_spi.h"
|
#include "bus_spi.h"
|
||||||
|
|
||||||
|
@ -112,6 +113,7 @@ void systemInit(bool overclock)
|
||||||
|
|
||||||
ledInit();
|
ledInit();
|
||||||
beeperInit();
|
beeperInit();
|
||||||
|
initInverter();
|
||||||
|
|
||||||
// Init cycle counter
|
// Init cycle counter
|
||||||
cycleCounterInit();
|
cycleCounterInit();
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
|
|
||||||
#include "drivers/system.h"
|
#include "drivers/system.h"
|
||||||
|
|
||||||
|
#include "drivers/gpio.h"
|
||||||
|
#include "drivers/inverter.h"
|
||||||
|
|
||||||
#include "drivers/serial.h"
|
#include "drivers/serial.h"
|
||||||
#include "drivers/serial_uart.h"
|
#include "drivers/serial_uart.h"
|
||||||
#include "io/serial.h"
|
#include "io/serial.h"
|
||||||
|
@ -57,7 +60,8 @@ void sbusUpdateSerialRxFunctionConstraint(functionConstraint_t *functionConstrai
|
||||||
bool sbusInit(rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig, rcReadRawDataPtr *callback)
|
bool sbusInit(rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig, rcReadRawDataPtr *callback)
|
||||||
{
|
{
|
||||||
int b;
|
int b;
|
||||||
sBusPort = openSerialPort(FUNCTION_SERIAL_RX, sbusDataReceive, SBUS_BAUDRATE, (portMode_t)(MODE_RX | MODE_SBUS), SERIAL_NOT_INVERTED);
|
|
||||||
|
sBusPort = openSerialPort(FUNCTION_SERIAL_RX, sbusDataReceive, SBUS_BAUDRATE, (portMode_t)(MODE_RX | MODE_SBUS), SERIAL_INVERTED);
|
||||||
|
|
||||||
for (b = 0; b < SBUS_MAX_CHANNEL; b++)
|
for (b = 0; b < SBUS_MAX_CHANNEL; b++)
|
||||||
sbusChannelData[b] = 2 * (rxConfig->midrc - SBUS_OFFSET);
|
sbusChannelData[b] = 2 * (rxConfig->midrc - SBUS_OFFSET);
|
||||||
|
|
|
@ -20,8 +20,14 @@
|
||||||
#define LED0_PERIPHERAL RCC_APB2Periph_GPIOB
|
#define LED0_PERIPHERAL RCC_APB2Periph_GPIOB
|
||||||
#define LED0
|
#define LED0
|
||||||
|
|
||||||
|
#define INVERTER_PIN Pin_2 // PB2 (BOOT1) used as inverter select GPIO
|
||||||
|
#define INVERTER_GPIO GPIOB
|
||||||
|
#define INVERTER_PERIPHERAL RCC_APB2Periph_GPIOB
|
||||||
|
#define INVERTER_USART USART1
|
||||||
|
|
||||||
#define ACC
|
#define ACC
|
||||||
#define GYRO
|
#define GYRO
|
||||||
|
#define INVERTER
|
||||||
|
|
||||||
// #define SOFT_I2C // enable to test software i2c
|
// #define SOFT_I2C // enable to test software i2c
|
||||||
// #define SOFT_I2C_PB1011 // If SOFT_I2C is enabled above, need to define pinout as well (I2C1 = PB67, I2C2 = PB1011)
|
// #define SOFT_I2C_PB1011 // If SOFT_I2C is enabled above, need to define pinout as well (I2C1 = PB67, I2C2 = PB1011)
|
||||||
|
|
|
@ -32,6 +32,11 @@
|
||||||
#define BARO_GPIO GPIOC
|
#define BARO_GPIO GPIOC
|
||||||
#define BARO_PIN Pin_13
|
#define BARO_PIN Pin_13
|
||||||
|
|
||||||
|
#define INVERTER_PIN Pin_2 // PB2 (BOOT1) abused as inverter select GPIO
|
||||||
|
#define INVERTER_GPIO GPIOB
|
||||||
|
#define INVERTER_PERIPHERAL RCC_APB2Periph_GPIOB
|
||||||
|
#define INVERTER_USART USART2
|
||||||
|
|
||||||
#define GYRO
|
#define GYRO
|
||||||
#define ACC
|
#define ACC
|
||||||
#define MAG
|
#define MAG
|
||||||
|
@ -40,6 +45,7 @@
|
||||||
#define BEEPER
|
#define BEEPER
|
||||||
#define LED0
|
#define LED0
|
||||||
#define LED1
|
#define LED1
|
||||||
|
#define INVERTER
|
||||||
|
|
||||||
#define I2C_DEVICE (I2CDEV_2)
|
#define I2C_DEVICE (I2CDEV_2)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue