mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-10-02 12:23:17 +08:00
Eachine Trashcan support (#2540)
Co-authored-by: Open UAS <> Co-authored-by: Tom van Dijk <tomvand@users.noreply.github.com>
This commit is contained in:
co-authored by
Open UAS
Tom van Dijk
parent
94b1c3d24f
commit
1cc01d4653
@@ -65,6 +65,7 @@ paparazzi.sublime-workspace
|
||||
/conf/maps.xml
|
||||
/conf/gps/ublox_conf
|
||||
!/conf/simulator/gazebo/**/*.config
|
||||
/conf/tools/blacklisted
|
||||
|
||||
# /doc/pprz_algebra/
|
||||
/doc/pprz_algebra/headfile.log
|
||||
|
||||
@@ -51,6 +51,7 @@ ifdef DFU_PRODUCT
|
||||
DFU_PRODUCT_CMD = --product=$(DFU_PRODUCT)
|
||||
endif
|
||||
upload: $(OBJDIR)/$(TARGET).bin
|
||||
$(DFU_PRE_UPLOAD_CMD)
|
||||
@echo "Using stm32 mem dfu loader"
|
||||
$(PYTHON) $(PAPARAZZI_SRC)/sw/tools/dfu/stm32_mem.py $(DFU_PRODUCT_CMD) $(DFU_ADDR_CMD) $^
|
||||
|
||||
@@ -72,6 +73,7 @@ DFUSE_VERIFY_ADDRESS = $(DFU_ADDR):$(DFU_SIZE)
|
||||
endif
|
||||
|
||||
upload: $(OBJDIR)/$(TARGET).bin
|
||||
$(DFU_UTIL_PRE_UPLOAD_CMD)
|
||||
@echo "Using dfu-util at $(DFU_ADDR)"
|
||||
$(Q)dfu-util -d 0483:df11 -c 1 -i 0 -a 0 -s $(DFU_ADDR) -D $^
|
||||
ifeq ($(VERIFY),1)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,61 @@
|
||||
# Hey Emacs, this is a -*- makefile -*-
|
||||
#
|
||||
# crazybee_f4_1.0.makefile
|
||||
#
|
||||
# Take a look at https://www.openuas.org/ airframes for example
|
||||
|
||||
# Board is a crazybee F4 v1.0
|
||||
BOARD=crazybee_f4
|
||||
BOARD_VERSION=1.0
|
||||
BOARD_CFG=\"boards/crazybee_f4_1.0.h\"
|
||||
|
||||
ARCH=stm32
|
||||
ARCH_L=f4
|
||||
ARCH_DIR=stm32
|
||||
SRC_ARCH=arch/$(ARCH_DIR)
|
||||
$(TARGET).ARCHDIR = $(ARCH)
|
||||
$(TARGET).LDSCRIPT=$(SRC_ARCH)/crazybee_f4_1.0.ld
|
||||
|
||||
HARD_FLOAT=yes
|
||||
|
||||
# Default flash mode is the STM32 DFU bootloader
|
||||
# Theoreticlly possible are also SWD and JTAG_BMP
|
||||
# But no simple physical connectors to the board...
|
||||
# So... DFU it will be ...
|
||||
FLASH_MODE?=DFU-UTIL
|
||||
|
||||
#idVendor=0483, idProduct=5740
|
||||
#USB device strings: Mfr=1, Product=2, SerialNumber=3
|
||||
#Product: Product: CrazyBee F4 (x)
|
||||
#Manufacturer: Betaflight
|
||||
#SerialNumber: 0x8000000
|
||||
|
||||
#TIP: ttyACM0: USB ACM device
|
||||
|
||||
#
|
||||
# Default on PCB LED configuration
|
||||
#
|
||||
RADIO_CONTROL_LED ?= none
|
||||
BARO_LED ?= none
|
||||
AHRS_ALIGNER_LED ?= none
|
||||
GPS_LED ?= none
|
||||
SYS_TIME_LED ?= 1
|
||||
|
||||
#
|
||||
# Default UART configuration (RC receiver, telemetry modem, GPS)
|
||||
#
|
||||
RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT ?= UART2
|
||||
RADIO_CONTROL_SBUS_PORT ?= UART2
|
||||
|
||||
MODEM_PORT ?= UART1
|
||||
MODEM_BAUD ?= B115200
|
||||
|
||||
#
|
||||
# GPS via I2C just as Baro and Magneto... sparec amount of uart ports left on this board
|
||||
# If one starts using a build in RX on SPI Bus then TX1/RX1 can be used.
|
||||
#
|
||||
# default actuator configuration
|
||||
#
|
||||
# you can use different actuators by adding a configure option to your firmware section
|
||||
# and by setting the correct "driver" attribute in servo section
|
||||
ACTUATORS ?= actuators_pwm
|
||||
@@ -197,4 +197,15 @@
|
||||
settings_modules="modules/ahrs_int_cmpl_quat.xml modules/guidance_hybrid.xml modules/stabilization_indi_simple.xml modules/nav_basic_rotorcraft.xml modules/guidance_rotorcraft.xml modules/gps.xml modules/imu_common.xml modules/gps_ubx_ucenter.xml"
|
||||
gui_color="blue"
|
||||
/>
|
||||
<aircraft
|
||||
name="trashcan"
|
||||
ac_id="1"
|
||||
airframe="airframes/examples/trashcan.xml"
|
||||
radio="radios/FrSky_Taranis_X9Dplus_TAERMK.xml"
|
||||
telemetry="telemetry/default_rotorcraft_slow.xml"
|
||||
flight_plan="flight_plans/dummy.xml"
|
||||
settings="settings/rotorcraft_basic.xml"
|
||||
settings_modules="[modules/gps.xml] [modules/ahrs_float_cmpl_quat.xml] [modules/ins_extended.xml] [modules/stabilization_int_quat.xml] [modules/nav_basic_rotorcraft.xml] [modules/guidance_rotorcraft.xml] [modules/imu_common.xml] modules/radio_control_cc2500_frsky.xml"
|
||||
gui_color="blue"
|
||||
/>
|
||||
</conf>
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
<board name="openpilot_revo.*"/>
|
||||
<board name="chimera_.*"/>
|
||||
<board name="tawaki_.*"/>
|
||||
<board name="crazybee_f4_.*"/>
|
||||
<board name="crazyflie_.*"/>
|
||||
</boards>
|
||||
</mode>
|
||||
@@ -76,6 +77,7 @@
|
||||
<board name="openpilot_revo.*"/>
|
||||
<board name="chimera_.*"/>
|
||||
<board name="tawaki_.*"/>
|
||||
<board name="crazybee_f4_.*"/>
|
||||
<board name="crazyflie_.*"/>
|
||||
</boards>
|
||||
</mode>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="dfu_command" task="datalink"><!-- task="datalink" to run before telemetry_transparent_usb -->
|
||||
<doc>
|
||||
<description>
|
||||
THIS MODULE MUST BE PLACED ABOVE ANY USB SERIAL CONSUMERS IN THE AIRFRAME!
|
||||
|
||||
Read USB serial for dfu command. Send '#\n', 'bl\n' to reset to DFU mode.
|
||||
The same command works with betaflight (tested with 4.1.1), allowing
|
||||
paparazzi to be uploaded directly to these boards.
|
||||
|
||||
The dfu command is automatically sent when uploading with DFU or DFU-UTIL
|
||||
(see configure below).
|
||||
</description>
|
||||
</doc>
|
||||
<header>
|
||||
<file name="dfu_command.h"/>
|
||||
</header>
|
||||
<event fun="dfu_command_event()"/>
|
||||
<makefile target="!fbw|sim|nps|hitl">
|
||||
<configure name="SERIAL_TTY" default="/dev/ttyACM0"/>
|
||||
<configure name="DFU_PRE_UPLOAD_CMD" default="@(printf '\043\012' > $(SERIAL_TTY) && sleep 1 && printf 'bl\012' > $(SERIAL_TTY) && sleep 1) || echo 'Warning: DFU command failed!'"/>
|
||||
<configure name="DFU_UTIL_PRE_UPLOAD_CMD" default="@(printf '\043\012' > $(SERIAL_TTY) && sleep 1 && printf 'bl\012' > $(SERIAL_TTY) && sleep 1) || echo 'Warning: DFU command failed!'"/>
|
||||
<define name="USE_USB_SERIAL"/>
|
||||
<file name="dfu_command.c"/>
|
||||
<file_arch name="usb_ser_hw.c" dir="."/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="radio_control_cc2500_frsky" dir="radio_control/cc2500_frsky">
|
||||
<doc>
|
||||
<description>
|
||||
Software implementation of Frsky radio control protocol for onboard CC2500 receiver.
|
||||
</description>
|
||||
<configure name="CC2500_SPI_DEV" value="SPIx" description="SPI device"/>
|
||||
<configure name="CC2500_SPI_SLAVE_IDX" value="2" description="SPI slave index"/>
|
||||
<define name="CC2500_GDO0_GPIO" value="GPIOC" description="GDO0 GPIO port"/>
|
||||
<define name="CC2500_GDO0_PIN" value="GPIO14" description="GDO0 GPIO pin"/>
|
||||
<define name="CC2500_RX_LED" value="LED_2|(undefined)" description="FrSky RX LED"/>
|
||||
<define name="CC2500_BIND_BUTTON" value="BIND_BUTTON|(undefined)" description="GPIO button used to enter bind mode"/>
|
||||
<define name="CC2500_RX_SPI_PROTOCOL" value="RX_SPI_FRSKY_X_LBT (default)|RX_SPI_FRSKY_X|RX_SPI_FRSKY_D" description="RX protocol"/>
|
||||
<define name="CC2500_AUTOBIND" value="FALSE" description="Enter BIND mode at startup"/>
|
||||
<define name="CC2500_TELEMETRY_SENSORS" value="(SENSOR_VOLTAGE | SENSOR_CURRENT | SENSOR_FUEL | SENSOR_ALTITUDE | SENSOR_VARIO)" description="List of sensors to send over FrSky telemetry (set to SENSOR_NONE) to disable."/>
|
||||
</doc>
|
||||
<settings>
|
||||
<dl_settings>
|
||||
<dl_settings NAME="cc2500_frsky">
|
||||
<dl_setting var="cc2500_settings_persistent.bindVars" min="1" step="1" max="1" values="READ_ONLY" shortname="bindVars" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[0]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData0" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[1]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData1" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[2]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData2" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[3]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData3" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[4]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData4" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[5]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData5" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[6]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData6" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[7]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData7" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[8]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData8" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[9]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData9" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[10]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData10" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[11]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData11" persistent="true" type="uint32"/>
|
||||
<dl_setting var="cc2500_settings_persistent.bindHopData[12]" min="1" step="1" max="1" values="READ_ONLY" shortname="bindHopData12" persistent="true" type="uint32"/>
|
||||
</dl_settings>
|
||||
</dl_settings>
|
||||
</settings>
|
||||
<header>
|
||||
<file name="cc2500.h" dir="peripherals"/>
|
||||
<file name="cc2500_paparazzi.h" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_settings.h" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
</header>
|
||||
<init fun="cc2500_init()"/>
|
||||
<makefile target="ap|fbw|sim|nps">
|
||||
<define name="RADIO_CONTROL_TYPE_H" value="subsystems/radio_control/cc2500_frsky/cc2500_paparazzi.h" type="string"/>
|
||||
<configure name="CC2500_SPI_DEV" default="SPI3" case="upper|lower"/>
|
||||
<configure name="CC2500_SPI_SLAVE_IDX" default="2"/>
|
||||
</makefile>
|
||||
<makefile target="ap|fbw">
|
||||
<define name="RADIO_CONTROL"/>
|
||||
<define name="USE_$(CC2500_SPI_DEV)"/>
|
||||
<define name="USE_SPI_SLAVE$(CC2500_SPI_SLAVE_IDX)"/>
|
||||
<define name="CC2500_SPI_DEV" value="$(CC2500_SPI_DEV_LOWER)"/>
|
||||
<define name="CC2500_SPI_SLAVE_IDX" value="$(CC2500_SPI_SLAVE_IDX)"/>
|
||||
<file name="radio_control.c" dir="subsystems"/>
|
||||
<file name="cc2500.c" dir="peripherals"/>
|
||||
<file name="cc2500_paparazzi.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_settings.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_compat.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_common.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_rx.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_rx_spi.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_rx_spi_common.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_frsky_shared.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_frsky_x.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<file name="cc2500_smartport.c" dir="subsystems/radio_control/cc2500_frsky"/>
|
||||
<raw>
|
||||
include $(CFG_SHARED)/spi_master.makefile
|
||||
</raw>
|
||||
</makefile>
|
||||
</module>
|
||||
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="telemetry_transparent_frsky_x" dir="datalink" task="datalink">
|
||||
<doc>
|
||||
<description>
|
||||
Telemetry using pprzlink protocol over FrSky X SmartPort serial link
|
||||
|
||||
Downlink messages are sent on dataID 0x5015.
|
||||
Uplink is not implemented yet.
|
||||
|
||||
Use the sw/tools/opentx-lua/sp2ser.lua script to receive these messages
|
||||
on the TX and forward them to the USB port. The 'datalink' script can
|
||||
read the pprzlink stream as a regular serial port.
|
||||
|
||||
The data rate is very limited (max ~160 bytes/s). The limitation comes
|
||||
from the FrSky X protocol which can send at most 4 bytes of telemetry
|
||||
every 9ms. Set CC2500_TELEMETRY_SENSORS (from radio_control_cc2500_frsky)
|
||||
to SENSOR_NONE to maximize pprzlink throughput. Use a suitable telemetry
|
||||
conf for this low data rate.
|
||||
</description>
|
||||
</doc>
|
||||
<autoload name="telemetry" type="nps"/>
|
||||
<autoload name="telemetry" type="sim"/>
|
||||
<header>
|
||||
<file name="pprz_dl.h"/>
|
||||
<file name="frsky_x.h" dir="subsystems/datalink"/>
|
||||
</header>
|
||||
<init fun="datalink_frsky_x_init()"/>
|
||||
<init fun="pprz_dl_init()"/>
|
||||
<event fun="pprz_dl_event()"/>
|
||||
<makefile>
|
||||
<file name="frsky_x.c" dir="subsystems/datalink"/>
|
||||
</makefile>
|
||||
|
||||
<makefile target="!fbw|sim|nps|hitl">
|
||||
<define name="DOWNLINK"/>
|
||||
<define name="PERIODIC_TELEMETRY"/>
|
||||
<define name="USE_FRSKY_X_SERIAL"/>
|
||||
<define name="DOWNLINK_DEVICE" value="frsky_x_serial"/>
|
||||
<define name="PPRZ_UART" value="frsky_x_serial"/>
|
||||
<define name="DOWNLINK_TRANSPORT" value="pprz_tp"/>
|
||||
<define name="DATALINK" value="PPRZ"/>
|
||||
<file name="pprz_dl.c"/>
|
||||
<file name="downlink.c" dir="subsystems/datalink"/>
|
||||
<file name="datalink.c" dir="subsystems/datalink"/>
|
||||
<file name="telemetry.c" dir="subsystems/datalink"/>
|
||||
<file name="pprz_transport.c" dir="pprzlink/src"/>
|
||||
<file name="frsky_x.c" dir="subsystems/datalink"/>
|
||||
</makefile>
|
||||
<makefile target="ap" firmware="fixedwing">
|
||||
<file name="fixedwing_datalink.c" dir="$(SRC_FIRMWARE)"/>
|
||||
<file name="ap_downlink.c" dir="$(SRC_FIRMWARE)"/>
|
||||
</makefile>
|
||||
<makefile target="ap|fbw" firmware="fixedwing">
|
||||
<file name="fbw_downlink.c" dir="$(SRC_FIRMWARE)"/>
|
||||
</makefile>
|
||||
<makefile target="ap" firmware="rotorcraft">
|
||||
<file name="rotorcraft_datalink.c" dir="$(SRC_FIRMWARE)"/>
|
||||
<file name="rotorcraft_telemetry.c" dir="$(SRC_FIRMWARE)"/>
|
||||
</makefile>
|
||||
<makefile target="ap" firmware="rover">
|
||||
<file name="rover_datalink.c" dir="$(SRC_FIRMWARE)"/>
|
||||
<file name="rover_telemetry.c" dir="$(SRC_FIRMWARE)"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE radio SYSTEM "radio.dtd">
|
||||
<radio name="FrSky Taranis X9Dplus TAERMK" data_min="988" data_max="2012" sync_min="6000" sync_max="18000" pulse_type="NEGATIVE">
|
||||
<channel ctl="LeftStickVertical" function="THROTTLE" min="988" neutral="988" max="2012" average="0"/>
|
||||
<channel ctl="RightStickHorizontal" function="ROLL" min="988" neutral="1500" max="2012" average="0"/>
|
||||
<channel ctl="RightStickVertical" function="PITCH" min="988" neutral="1500" max="2012" average="0"/>
|
||||
<channel ctl="LeftStickHorizontal" function="YAW" min="988" neutral="1500" max="2012" average="0"/>
|
||||
<channel ctl="ModeSwitch" function="MODE" min="2012" neutral="1500" max="988" average="0"/>
|
||||
<channel ctl="KillSwitch" function="KILL_SWITCH" min="2012" neutral="1500" max="988" average="0"/>
|
||||
</radio>
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Hey Emacs, this is a -*- makefile -*-
|
||||
*
|
||||
* Copyright (C) 2019 PPRZ team
|
||||
*
|
||||
* This file is part of Paparazzi.
|
||||
*
|
||||
* Paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* Paparazzi 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 Paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Linker script for Crazybee F4 (STM32F411CEU6), 512K FLASH flash, 128K RAM). */
|
||||
|
||||
/* FIXME: values possibly not correct
|
||||
/* Define memory regions. */
|
||||
MEMORY
|
||||
{
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
/* Reserving 16kb flash (512-16=496) for persistent settings. */
|
||||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 496K
|
||||
|
||||
}
|
||||
|
||||
/* Include the common ld script. */
|
||||
INCLUDE libopencm3_stm32f4.ld
|
||||
/* INCLUDE cortex-m-generic.ld */
|
||||
@@ -36,6 +36,8 @@
|
||||
#include <libopencm3/stm32/timer.h>
|
||||
#include <libopencm3/stm32/flash.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/stm32/rtc.h>
|
||||
#include <libopencm3/stm32/pwr.h>
|
||||
|
||||
#include "std.h"
|
||||
|
||||
@@ -165,8 +167,55 @@ void rcc_clock_setup_in_hse_24mhz_out_24mhz_pprz(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SYSTEM_MEMORY_BASE
|
||||
void reset_to_dfu(void) {
|
||||
// Request DFU at boot (init_dfu)
|
||||
pwr_disable_backup_domain_write_protect();
|
||||
RTC_BKPXR(0) = 0xFF;
|
||||
pwr_enable_backup_domain_write_protect();
|
||||
// Reset
|
||||
scb_reset_system();
|
||||
}
|
||||
|
||||
typedef void resetHandler_t(void);
|
||||
|
||||
typedef struct isrVector_s {
|
||||
volatile uint32_t stackEnd;
|
||||
resetHandler_t *resetHandler;
|
||||
} isrVector_t;
|
||||
|
||||
static isrVector_t *system_isr_vector_table_base = (isrVector_t *) SYSTEM_MEMORY_BASE; // Find in ST AN2606. Defined in board header.
|
||||
|
||||
static void init_dfu(void) {
|
||||
/* Reset to DFU if requested */
|
||||
rcc_periph_clock_enable(RCC_RTC);
|
||||
rcc_periph_clock_enable(RCC_PWR);
|
||||
if (RTC_BKPXR(0) == 0xFF) {
|
||||
// DFU request
|
||||
// 0. Reset request
|
||||
pwr_disable_backup_domain_write_protect();
|
||||
RTC_BKPXR(0) = 0x00;
|
||||
pwr_enable_backup_domain_write_protect();
|
||||
// 1. Set MSP to system_isr_vector_table_base.stackEnd
|
||||
// (betaflight system_stm32f4xx.c::75)
|
||||
// (betaflight cmsis_armcc.h::226
|
||||
register uint32_t __regMainStackPointer __asm("msp") __attribute__((unused)); // Note: declared unused to suppress gcc warning, not actually unused!
|
||||
__regMainStackPointer = system_isr_vector_table_base->stackEnd; // = topOfMainStack;
|
||||
// 2. system_isr_vector_table_base.resetHandler() (betaflight system_stm32f4xx.c::76)
|
||||
system_isr_vector_table_base->resetHandler();
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
#endif // SYSTEM_MEMORY_BASE
|
||||
|
||||
|
||||
void mcu_arch_init(void)
|
||||
{
|
||||
#ifdef SYSTEM_MEMORY_BASE
|
||||
init_dfu();
|
||||
#endif
|
||||
|
||||
#if LUFTBOOT
|
||||
PRINT_CONFIG_MSG("We are running luftboot, the interrupt vector is being relocated.")
|
||||
#if defined STM32F4
|
||||
@@ -222,7 +271,6 @@ void mcu_arch_init(void)
|
||||
* FIXME is it really needed ?
|
||||
*/
|
||||
scb_set_priority_grouping(SCB_AIRCR_PRIGROUP_NOGROUP_SUB16);
|
||||
|
||||
}
|
||||
|
||||
#if defined(STM32F1)
|
||||
|
||||
@@ -31,8 +31,14 @@
|
||||
|
||||
#include "std.h"
|
||||
|
||||
#include BOARD_CONFIG
|
||||
|
||||
extern void mcu_arch_init(void);
|
||||
|
||||
#ifdef SYSTEM_MEMORY_BASE
|
||||
extern void reset_to_dfu(void);
|
||||
#endif
|
||||
|
||||
|
||||
/* should probably not be here
|
||||
* a couple of macros to use the rev instruction
|
||||
|
||||
@@ -64,6 +64,7 @@ static fifo_t rxfifo;
|
||||
void fifo_init(fifo_t *fifo, uint8_t *buf);
|
||||
bool fifo_put(fifo_t *fifo, uint8_t c);
|
||||
bool fifo_get(fifo_t *fifo, uint8_t *pc);
|
||||
bool fifo_peek(fifo_t *fifo, uint8_t *pc, uint8_t ofs);
|
||||
int fifo_avail(fifo_t *fifo);
|
||||
int fifo_free(fifo_t *fifo);
|
||||
int tx_timeout; // tmp work around for usbd_ep_stall_get from, this function does not always seem to work
|
||||
@@ -374,6 +375,15 @@ int fifo_free(fifo_t *fifo)
|
||||
return (VCOM_FIFO_SIZE - 1 - fifo_avail(fifo));
|
||||
}
|
||||
|
||||
bool fifo_peek(fifo_t *fifo, uint8_t *pc, uint8_t ofs) {
|
||||
if (fifo_avail(fifo) < ofs + 1) {
|
||||
return false;
|
||||
}
|
||||
int index = (fifo->tail + ofs) % VCOM_FIFO_SIZE;
|
||||
*pc = fifo->buf[index];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes one character to VCOM port fifo.
|
||||
@@ -420,6 +430,19 @@ int VCOM_getchar(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads one character from VCOM port without removing it from the queue
|
||||
* @param ofs position to read
|
||||
* @returns character read, or -1 if character could not be read
|
||||
*/
|
||||
int VCOM_peekchar(int ofs)
|
||||
{
|
||||
static int result = 0;
|
||||
uint8_t c;
|
||||
result = fifo_peek(&rxfifo, &c, ofs) ? c : -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if buffer free in VCOM buffer
|
||||
* @returns TRUE if len bytes are free
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -42,6 +42,7 @@ extern struct usb_serial_periph usb_serial;
|
||||
void VCOM_init(void);
|
||||
int VCOM_putchar(int c);
|
||||
int VCOM_getchar(void);
|
||||
int VCOM_peekchar(int ofs);
|
||||
bool VCOM_check_free_space(uint16_t len);
|
||||
int VCOM_check_available(void);
|
||||
void VCOM_set_linecoding(uint8_t mode);
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
#if USE_USB_SERIAL
|
||||
#include "mcu_periph/usb_serial.h"
|
||||
#endif
|
||||
#if USE_FRSKY_X_SERIAL
|
||||
#include "subsystems/datalink/frsky_x.h"
|
||||
#endif
|
||||
#if USE_UDP
|
||||
#include "mcu_periph/udp.h"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) Tom van Dijk
|
||||
*
|
||||
* This file is part of paparazzi
|
||||
*
|
||||
* paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file "modules/dfu_command/dfu_command.c"
|
||||
* @author Tom van Dijk
|
||||
* Read USB serial for dfu command
|
||||
*
|
||||
* The reset_to_dfu() function needs to be implemented for the
|
||||
* architecture in use. (sw/airborne/arch/.../mcu_arch.c)
|
||||
*/
|
||||
|
||||
#include "modules/dfu_command/dfu_command.h"
|
||||
|
||||
#include "mcu_arch.h"
|
||||
|
||||
static const char dfu_command_str[] = "#\nbl\n"; // Note: same command resets betaflight to DFU
|
||||
static int dfu_command_state = 0;
|
||||
|
||||
void dfu_command_event(void) {
|
||||
// Search fifo for command string
|
||||
for (int i = 0; i < VCOM_check_available(); ++i) {
|
||||
if (VCOM_peekchar(i) == dfu_command_str[dfu_command_state]) {
|
||||
dfu_command_state++;
|
||||
if (dfu_command_str[dfu_command_state] == '\0') { // end of command string
|
||||
reset_to_dfu();
|
||||
}
|
||||
} else {
|
||||
dfu_command_state = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent fifo blocking if bytes are not consumed by other process
|
||||
if (!VCOM_check_free_space(1)) {
|
||||
while (VCOM_check_available()) {
|
||||
VCOM_getchar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) Tom van Dijk
|
||||
*
|
||||
* This file is part of paparazzi
|
||||
*
|
||||
* paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file "modules/dfu_command/dfu_command.h"
|
||||
* @author Tom van Dijk
|
||||
* Read USB serial for dfu command
|
||||
*/
|
||||
|
||||
#ifndef DFU_COMMAND_H
|
||||
#define DFU_COMMAND_H
|
||||
|
||||
#include "mcu_periph/usb_serial.h"
|
||||
|
||||
void dfu_command_event(void);
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "subsystems/radio_control/cc2500_frsky/cc2500_smartport.h"
|
||||
#include "subsystems/datalink/frsky_x.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct frsky_x_serial_periph frsky_x_serial;
|
||||
|
||||
|
||||
/* Serial device */
|
||||
// Based on usb_ser_hw.c
|
||||
// Generic fifo implementation
|
||||
static void fifo_init(fifo_t *fifo, uint8_t *buf, size_t size);
|
||||
static bool fifo_put(fifo_t *fifo, uint8_t c);
|
||||
static bool fifo_get(fifo_t *fifo, uint8_t *pc);
|
||||
static int fifo_avail(fifo_t *fifo);
|
||||
static int fifo_free(fifo_t *fifo);
|
||||
|
||||
static void fifo_init(fifo_t *fifo, uint8_t *buf, size_t size) {
|
||||
fifo->head = 0;
|
||||
fifo->tail = 0;
|
||||
fifo->buf = buf;
|
||||
fifo->size = size;
|
||||
}
|
||||
|
||||
static bool fifo_put(fifo_t *fifo, uint8_t c) {
|
||||
int next;
|
||||
|
||||
// check if FIFO has room
|
||||
next = (fifo->head + 1) % fifo->size;
|
||||
if (next == fifo->tail) {
|
||||
// full
|
||||
return false;
|
||||
}
|
||||
|
||||
fifo->buf[fifo->head] = c;
|
||||
fifo->head = next;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fifo_get(fifo_t *fifo, uint8_t *pc) {
|
||||
int next;
|
||||
|
||||
// check if FIFO has data
|
||||
if (fifo->head == fifo->tail) {
|
||||
return false;
|
||||
}
|
||||
|
||||
next = (fifo->tail + 1) % fifo->size;
|
||||
|
||||
*pc = fifo->buf[fifo->tail];
|
||||
fifo->tail = next;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int fifo_avail(fifo_t *fifo) {
|
||||
return (fifo->size + fifo->head - fifo->tail) % fifo->size;
|
||||
}
|
||||
|
||||
static int fifo_free(fifo_t *fifo) {
|
||||
return (fifo->size - 1 - fifo_avail(fifo));
|
||||
}
|
||||
|
||||
|
||||
// Serial device functions
|
||||
static int frsky_x_serial_check_free_space(void *p, long *fd, uint16_t len);
|
||||
static void frsky_x_serial_put_byte(void *p, long fd, uint8_t c);
|
||||
static void frsky_x_serial_put_buffer(void *p, long fd, const uint8_t *data, uint16_t len);
|
||||
static void frsky_x_serial_send_message(void *p, long fd);
|
||||
static int frsky_x_serial_char_available(void *p);
|
||||
static uint8_t frsky_x_serial_get_byte(void *p);
|
||||
|
||||
static int frsky_x_serial_check_free_space(void *p, long *fd, uint16_t len) {
|
||||
(void) fd;
|
||||
return (fifo_free(&((struct frsky_x_serial_periph *)p)->downlink_fifo) >= len ? true : false);
|
||||
}
|
||||
|
||||
static void frsky_x_serial_put_byte(void *p, long fd, uint8_t c) {
|
||||
(void) fd;
|
||||
fifo_put(&((struct frsky_x_serial_periph *)p)->downlink_fifo, c);
|
||||
}
|
||||
|
||||
static void frsky_x_serial_put_buffer(void *p, long fd, const uint8_t *data, uint16_t len) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
frsky_x_serial_put_byte(p, fd, data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void frsky_x_serial_send_message(void *p, long fd) {
|
||||
(void) p;
|
||||
(void) fd;
|
||||
/* Do nothing, handled by smartPortDownlink_cb */
|
||||
}
|
||||
|
||||
static int frsky_x_serial_char_available(void *p) {
|
||||
return fifo_avail(&((struct frsky_x_serial_periph *)p)->uplink_fifo);
|
||||
}
|
||||
|
||||
static uint8_t frsky_x_serial_get_byte(void *p) {
|
||||
uint8_t byte;
|
||||
fifo_get(&((struct frsky_x_serial_periph *)p)->uplink_fifo, &byte);
|
||||
return byte;
|
||||
}
|
||||
|
||||
|
||||
/* SmartPort sensor */
|
||||
static bool smartPortDownlink_cb(uint32_t *data) {
|
||||
if (fifo_avail(&frsky_x_serial.downlink_fifo) >= 4) {
|
||||
uint8_t data_u8[4];
|
||||
fifo_get(&frsky_x_serial.downlink_fifo, data_u8 + 0);
|
||||
fifo_get(&frsky_x_serial.downlink_fifo, data_u8 + 1);
|
||||
fifo_get(&frsky_x_serial.downlink_fifo, data_u8 + 2);
|
||||
fifo_get(&frsky_x_serial.downlink_fifo, data_u8 + 3);
|
||||
*data =
|
||||
(data_u8[0] << 24) |
|
||||
(data_u8[1] << 16) |
|
||||
(data_u8[2] << 8) |
|
||||
(data_u8[3]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void smartPortUplink_cb(smartPortPayload_t *payload) {
|
||||
uint8_t shift = 24;
|
||||
for (uint8_t i = 0; i < payload->frameId; ++i) {
|
||||
fifo_put(&frsky_x_serial.uplink_fifo, (uint8_t)((payload->data >> shift) & 0xFF));
|
||||
shift -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void datalink_frsky_x_init(void) {
|
||||
/* Set up link device */
|
||||
fifo_init(&frsky_x_serial.downlink_fifo, frsky_x_serial.downlink_buf, DOWNLINK_BUFFER_SIZE);
|
||||
fifo_init(&frsky_x_serial.uplink_fifo, frsky_x_serial.uplink_buf, UPLINK_BUFFER_SIZE);
|
||||
frsky_x_serial.device.periph = (void *)(&frsky_x_serial);
|
||||
frsky_x_serial.device.check_free_space = frsky_x_serial_check_free_space;
|
||||
frsky_x_serial.device.put_byte = frsky_x_serial_put_byte;
|
||||
frsky_x_serial.device.put_buffer = frsky_x_serial_put_buffer;
|
||||
frsky_x_serial.device.send_message = frsky_x_serial_send_message;
|
||||
frsky_x_serial.device.char_available = frsky_x_serial_char_available;
|
||||
frsky_x_serial.device.get_byte = frsky_x_serial_get_byte;
|
||||
|
||||
/* Attach to SmartPort hooks */
|
||||
smartPortDownlink = smartPortDownlink_cb;
|
||||
smartPortUplink = smartPortUplink_cb;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef DATALINK_FRSKY_X_H
|
||||
#define DATALINK_FRSKY_X_H
|
||||
|
||||
#include "pprzlink/pprzlink_device.h"
|
||||
|
||||
#define DOWNLINK_BUFFER_SIZE 512
|
||||
#define UPLINK_BUFFER_SIZE 512
|
||||
|
||||
typedef struct {
|
||||
int head;
|
||||
int tail;
|
||||
uint8_t *buf;
|
||||
size_t size;
|
||||
} fifo_t;
|
||||
|
||||
struct frsky_x_serial_periph {
|
||||
/** Generic device interface */
|
||||
struct link_device device;
|
||||
/* Downlink fifo */
|
||||
fifo_t downlink_fifo;
|
||||
uint8_t downlink_buf[DOWNLINK_BUFFER_SIZE];
|
||||
/* Uplink fifo */
|
||||
fifo_t uplink_fifo;
|
||||
uint8_t uplink_buf[UPLINK_BUFFER_SIZE];
|
||||
};
|
||||
extern struct frsky_x_serial_periph frsky_x_serial;
|
||||
|
||||
void datalink_frsky_x_init(void);
|
||||
|
||||
#endif // DATALINK_FRSKY_X_H
|
||||
@@ -0,0 +1,180 @@
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
#include "peripherals/cc2500.h"
|
||||
#include "cc2500_settings.h"
|
||||
#include "cc2500_common.h"
|
||||
#include "cc2500_rx.h"
|
||||
|
||||
// betaflight/src/main/rx/cc2500_common.c @ 50bbe0b
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
//#include "platform.h"
|
||||
|
||||
#if defined(USE_RX_FRSKY_SPI) || defined(USE_RX_SFHSS_SPI)
|
||||
|
||||
//#include "common/maths.h"
|
||||
//
|
||||
//#include "drivers/io.h"
|
||||
//#include "drivers/rx/rx_cc2500.h"
|
||||
//#include "drivers/time.h"
|
||||
//
|
||||
//#include "fc/config.h"
|
||||
//
|
||||
//#include "pg/pg.h"
|
||||
//#include "pg/pg_ids.h"
|
||||
//#include "pg/rx.h"
|
||||
//#include "pg/rx_spi.h"
|
||||
//#include "pg/rx_spi_cc2500.h"
|
||||
//
|
||||
//#include "rx/rx.h"
|
||||
//#include "rx/rx_spi.h"
|
||||
//
|
||||
//#include "cc2500_common.h"
|
||||
|
||||
static IO_t gdoPin;
|
||||
#if defined(USE_RX_CC2500_SPI_PA_LNA)
|
||||
static IO_t txEnPin;
|
||||
static IO_t rxLnaEnPin;
|
||||
#if defined(USE_RX_CC2500_SPI_DIVERSITY)
|
||||
static IO_t antSelPin;
|
||||
#endif
|
||||
#endif
|
||||
static int16_t rssiDbm;
|
||||
|
||||
uint16_t cc2500getRssiDbm(void)
|
||||
{
|
||||
return rssiDbm;
|
||||
}
|
||||
|
||||
void cc2500setRssiDbm(uint8_t value)
|
||||
{
|
||||
if (value >= 128) {
|
||||
rssiDbm = ((((uint16_t)value) * 18) >> 5) - 82;
|
||||
} else {
|
||||
rssiDbm = ((((uint16_t)value) * 18) >> 5) + 65;
|
||||
}
|
||||
|
||||
setRssi(rssiDbm << 3, RSSI_SOURCE_RX_PROTOCOL);
|
||||
}
|
||||
|
||||
bool cc2500getGdo(void)
|
||||
{
|
||||
return IORead(gdoPin);
|
||||
}
|
||||
|
||||
#if defined(USE_RX_CC2500_SPI_PA_LNA) && defined(USE_RX_CC2500_SPI_DIVERSITY)
|
||||
void cc2500switchAntennae(void)
|
||||
{
|
||||
static bool alternativeAntennaSelected = true;
|
||||
|
||||
if (antSelPin) {
|
||||
if (alternativeAntennaSelected) {
|
||||
IOLo(antSelPin);
|
||||
} else {
|
||||
IOHi(antSelPin);
|
||||
}
|
||||
alternativeAntennaSelected = !alternativeAntennaSelected;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(USE_RX_CC2500_SPI_PA_LNA)
|
||||
void cc2500TxEnable(void)
|
||||
{
|
||||
if (txEnPin) {
|
||||
IOHi(txEnPin);
|
||||
}
|
||||
}
|
||||
|
||||
void cc2500TxDisable(void)
|
||||
{
|
||||
if (txEnPin) {
|
||||
IOLo(txEnPin);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool cc2500SpiDetect(void)
|
||||
{
|
||||
const uint8_t chipPartNum = cc2500ReadReg(CC2500_30_PARTNUM | CC2500_READ_BURST); //CC2500 read registers chip part num
|
||||
const uint8_t chipVersion = cc2500ReadReg(CC2500_31_VERSION | CC2500_READ_BURST); //CC2500 read registers chip version
|
||||
if (chipPartNum == 0x80 && chipVersion == 0x03) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cc2500SpiInit(void)
|
||||
{
|
||||
if (rxCc2500SpiConfig()->chipDetectEnabled && !cc2500SpiDetect()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// gpio init here
|
||||
gdoPin = IOGetByTag(rxSpiConfig()->extiIoTag);
|
||||
|
||||
if (!gdoPin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IOInit(gdoPin, OWNER_RX_SPI_EXTI, 0);
|
||||
IOConfigGPIO(gdoPin, IOCFG_IN_FLOATING);
|
||||
#if defined(USE_RX_CC2500_SPI_PA_LNA)
|
||||
if (rxCc2500SpiConfig()->lnaEnIoTag) {
|
||||
rxLnaEnPin = IOGetByTag(rxCc2500SpiConfig()->lnaEnIoTag);
|
||||
IOInit(rxLnaEnPin, OWNER_RX_SPI_CC2500_LNA_EN, 0);
|
||||
IOConfigGPIO(rxLnaEnPin, IOCFG_OUT_PP);
|
||||
|
||||
IOHi(rxLnaEnPin); // always on at the moment
|
||||
}
|
||||
if (rxCc2500SpiConfig()->txEnIoTag) {
|
||||
txEnPin = IOGetByTag(rxCc2500SpiConfig()->txEnIoTag);
|
||||
IOInit(txEnPin, OWNER_RX_SPI_CC2500_TX_EN, 0);
|
||||
IOConfigGPIO(txEnPin, IOCFG_OUT_PP);
|
||||
} else {
|
||||
txEnPin = IO_NONE;
|
||||
}
|
||||
#if defined(USE_RX_CC2500_SPI_DIVERSITY)
|
||||
if (rxCc2500SpiConfig()->antSelIoTag) {
|
||||
antSelPin = IOGetByTag(rxCc2500SpiConfig()->antSelIoTag);
|
||||
IOInit(antSelPin, OWNER_RX_SPI_CC2500_ANT_SEL, 0);
|
||||
IOConfigGPIO(antSelPin, IOCFG_OUT_PP);
|
||||
|
||||
IOHi(antSelPin);
|
||||
} else {
|
||||
antSelPin = IO_NONE;
|
||||
}
|
||||
#endif
|
||||
#endif // USE_RX_CC2500_SPI_PA_LNA
|
||||
|
||||
#if defined(USE_RX_CC2500_SPI_PA_LNA)
|
||||
cc2500TxDisable();
|
||||
#endif // USE_RX_CC2500_SPI_PA_LNA
|
||||
|
||||
if (rssiSource == RSSI_SOURCE_NONE) {
|
||||
rssiSource = RSSI_SOURCE_RX_PROTOCOL;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
#include "cc2500_rx_spi.h"
|
||||
|
||||
// betaflight/src/main/rx/cc2500_common.h @ 50bbe0b on Jul 1
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include "rx/rx_spi.h"
|
||||
|
||||
uint16_t cc2500getRssiDbm(void);
|
||||
void cc2500setRssiDbm(uint8_t value);
|
||||
bool cc2500getGdo(void);
|
||||
#if defined(USE_RX_CC2500_SPI_PA_LNA) && defined(USE_RX_CC2500_SPI_DIVERSITY)
|
||||
void cc2500switchAntennae(void);
|
||||
#endif
|
||||
#if defined(USE_RX_CC2500_SPI_PA_LNA)
|
||||
void cc2500TxEnable(void);
|
||||
void cc2500TxDisable(void);
|
||||
#endif
|
||||
bool cc2500SpiInit(void);
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||
*
|
||||
* This code is based on the betaflight cc2500 and FrskyX implementation.
|
||||
* https://github.com/betaflight/betaflight
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
#include "state.h"
|
||||
#include "mcu_periph/adc.h"
|
||||
#include "mcu_periph/gpio.h"
|
||||
#include "mcu_periph/sys_time.h"
|
||||
#include "subsystems/electrical.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
// (unknown):
|
||||
struct attitude_t bf_attitude = { { 0, 0, 0 } }; // Dummy values
|
||||
|
||||
|
||||
// main/config/config.h:
|
||||
struct pidProfile_s *currentPidProfile; // Dummy values
|
||||
|
||||
|
||||
// main/config/feature.h:
|
||||
bool bf_featureIsEnabled(const uint32_t mask) {
|
||||
uint32_t features = FEATURE_RX_SPI | FEATURE_TELEMETRY;
|
||||
return features & mask;
|
||||
}
|
||||
|
||||
|
||||
// main/common/filters.h:
|
||||
#define M_PI_FLOAT 3.14159265358979323846f
|
||||
float pt1FilterGain(float f_cut, float dT)
|
||||
{
|
||||
float RC = 1 / ( 2 * M_PI_FLOAT * f_cut);
|
||||
return dT / (RC + dT);
|
||||
}
|
||||
|
||||
void pt1FilterInit(pt1Filter_t *filter, float k) {
|
||||
filter->state = 0.0f;
|
||||
filter->k = k;
|
||||
}
|
||||
|
||||
void pt1FilterUpdateCutoff(pt1Filter_t *filter, float k) {
|
||||
filter->k = k;
|
||||
}
|
||||
|
||||
float pt1FilterApply(pt1Filter_t *filter, float input) {
|
||||
filter->state = filter->state + filter->k * (input - filter->state);
|
||||
return filter->state;
|
||||
}
|
||||
|
||||
|
||||
// main/drivers/time.h:
|
||||
void bf_delayMicroseconds(timeUs_t us) {
|
||||
sys_time_usleep(us);
|
||||
}
|
||||
|
||||
void bf_delay(timeMs_t ms) {
|
||||
bf_delayMicroseconds(ms * 1000);
|
||||
}
|
||||
|
||||
timeUs_t bf_micros(void) {
|
||||
return get_sys_time_usec();
|
||||
}
|
||||
|
||||
timeMs_t bf_millis(void) {
|
||||
return get_sys_time_msec();
|
||||
}
|
||||
|
||||
|
||||
// main/drivers/adc.h:
|
||||
uint16_t bf_adcGetChannel(uint8_t channel) {
|
||||
(void) channel;
|
||||
// Return current, as voltage is already reported by getLegacyBatteryVoltage
|
||||
return (uint16_t)(electrical.current * 10000.0); // Assumed in 0.1mA
|
||||
}
|
||||
|
||||
|
||||
// main/drivers/rx_spi.h:
|
||||
bool bf_rxSpiDeviceInit(void) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// main/drivers/io.h:
|
||||
IO_t bf_IOGetByTag(ioTag_t io) {
|
||||
return (IO_t)io;
|
||||
}
|
||||
|
||||
void bf_IOInit(IO_t io, uint8_t owner, uint8_t index) {
|
||||
(void) io;
|
||||
(void) owner;
|
||||
(void) index;
|
||||
}
|
||||
|
||||
void bf_IOConfigGPIO(IO_t io, enum ioconfig_t cfg) {
|
||||
if (!io) return;
|
||||
switch(cfg) {
|
||||
case IOCFG_OUT_PP:
|
||||
gpio_setup_output(io->port, io->pin);
|
||||
break;
|
||||
case IOCFG_IN_FLOATING:
|
||||
gpio_setup_input(io->port, io->pin);
|
||||
break;
|
||||
case IOCFG_IPU:
|
||||
gpio_setup_input_pullup(io->port, io->pin);
|
||||
break;
|
||||
default:
|
||||
assert("Invalid IO config" == NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool bf_IORead(IO_t gpio) {
|
||||
if (!gpio) return 0;
|
||||
return gpio_get(gpio->port, gpio->pin);
|
||||
}
|
||||
|
||||
void bf_IOHi(IO_t io) {
|
||||
if (!io) return;
|
||||
io->hi(io->port, io->pin);
|
||||
}
|
||||
|
||||
void bf_IOLo(IO_t io) {
|
||||
if (!io) return;
|
||||
io->lo(io->port, io->pin);
|
||||
}
|
||||
|
||||
void bf_IOToggle(IO_t io) {
|
||||
if (!io) return;
|
||||
gpio_toggle(io->port, io->pin);
|
||||
}
|
||||
|
||||
|
||||
// main/fc/controlrate_profile.h:
|
||||
controlRateConfig_t *currentControlRateProfile; // Dummy values
|
||||
|
||||
|
||||
// main/flight/position.h:
|
||||
int32_t bf_getEstimatedAltitudeCm(void) {
|
||||
return (int32_t)(stateGetPositionEnu_f()->z * 100.0);
|
||||
}
|
||||
|
||||
int16_t bf_getEstimatedVario(void) {
|
||||
return (int16_t)(stateGetSpeedEnu_f()->z * 100.0);
|
||||
}
|
||||
|
||||
|
||||
// main/sensors/battery.h
|
||||
bool bf_isBatteryVoltageConfigured(void) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
uint16_t bf_getLegacyBatteryVoltage(void) {
|
||||
return (uint16_t)((electrical.vsupply * 100.0 + 5) / 10.0); // ???
|
||||
}
|
||||
|
||||
uint16_t bf_getBatteryVoltage(void) {
|
||||
return (uint16_t)(electrical.vsupply * 100.0); // 0.01V
|
||||
}
|
||||
|
||||
uint8_t bf_getBatteryCellCount(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool bf_isAmperageConfigured(void) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int32_t bf_getAmperage(void) {
|
||||
return (int32_t)(electrical.current * 100.0);
|
||||
}
|
||||
|
||||
int32_t bf_getMAhDrawn(void) {
|
||||
return (int32_t)(electrical.charge * 1000.0);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
#include "cc2500_compat.h"
|
||||
#include "cc2500_settings.h"
|
||||
|
||||
// betaflight/src/main/rx/cc2500_frsky_common.h @ 766c90b
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include "rx/rx_spi.h"
|
||||
|
||||
bool frSkySpiInit(const rxSpiConfig_t *rxSpiConfig, rxRuntimeConfig_t *rxRuntimeConfig);
|
||||
rx_spi_received_e frSkySpiDataReceived(uint8_t *packet);
|
||||
rx_spi_received_e frSkySpiProcessFrame(uint8_t *packet);
|
||||
void frSkySpiSetRcData(uint16_t *rcData, const uint8_t *payload);
|
||||
@@ -0,0 +1,20 @@
|
||||
/* TODO PLACEHOLDER CODE! */
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
#define RC_CHANNEL_COUNT_FRSKY_D 8
|
||||
|
||||
static rx_spi_received_e frSkyDHandlePacket(uint8_t * const packet, uint8_t * const protocolState) {
|
||||
(void) packet;
|
||||
(void) protocolState;
|
||||
return RX_SPI_RECEIVED_NONE;
|
||||
}
|
||||
|
||||
static void frSkyDSetRcData(uint16_t *rcData, const uint8_t *payload) {
|
||||
(void) rcData;
|
||||
(void) payload;
|
||||
return;
|
||||
}
|
||||
|
||||
static void frSkyDInit(void) {
|
||||
return;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
||||
// betaflight/src/main/rx/cc2500_frsky_shared.h @ cb66ee0
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include "rx/rx_spi.h"
|
||||
|
||||
#define MAX_MISSING_PKT 100
|
||||
|
||||
#define DEBUG_DATA_ERROR_COUNT 0
|
||||
#define DEBUG_DATA_MISSING_PACKETS 1
|
||||
#define DEBUG_DATA_BAD_FRAME 2
|
||||
|
||||
|
||||
#define SYNC_DELAY_MAX 9000
|
||||
|
||||
#define MAX_MISSING_PKT 100
|
||||
|
||||
enum {
|
||||
STATE_INIT = 0,
|
||||
STATE_BIND,
|
||||
STATE_BIND_TUNING,
|
||||
STATE_BIND_BINDING1,
|
||||
STATE_BIND_BINDING2,
|
||||
STATE_BIND_COMPLETE,
|
||||
STATE_STARTING,
|
||||
STATE_UPDATE,
|
||||
STATE_DATA,
|
||||
STATE_TELEMETRY,
|
||||
STATE_RESUME,
|
||||
};
|
||||
|
||||
extern uint8_t listLength;
|
||||
extern uint32_t missingPackets;
|
||||
extern timeDelta_t timeoutUs;
|
||||
|
||||
void initialiseData(bool inBindState);
|
||||
|
||||
void nextChannel(uint8_t skip);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
// betaflight/src/main/rx/cc2500_frsky_x.h @ 766c90b
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include "rx/rx.h"
|
||||
//#include "rx/rx_spi.h"
|
||||
|
||||
#define RC_CHANNEL_COUNT_FRSKY_X 16
|
||||
|
||||
void frSkyXSetRcData(uint16_t *rcData, const uint8_t *payload);
|
||||
|
||||
void frSkyXInit(const rx_spi_protocol_e spiProtocol);
|
||||
rx_spi_received_e frSkyXHandlePacket(uint8_t * const packet, uint8_t * const protocolState);
|
||||
rx_spi_received_e frSkyXProcessFrame(uint8_t * const packet);
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "cc2500_paparazzi.h"
|
||||
|
||||
#include "subsystems/radio_control.h"
|
||||
#include "peripherals/cc2500.h"
|
||||
#include "cc2500_common.h"
|
||||
#include "cc2500_frsky_common.h"
|
||||
#include "cc2500_settings.h"
|
||||
#include "cc2500_rx.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
static uint16_t frsky_raw[RADIO_CTL_NB];
|
||||
|
||||
|
||||
#if PERIODIC_TELEMETRY
|
||||
#include "subsystems/datalink/telemetry.h"
|
||||
|
||||
static void send_cc2500_ppm(struct transport_tx *trans, struct link_device *dev)
|
||||
{
|
||||
pprz_msg_send_PPM(trans, dev, AC_ID,
|
||||
&radio_control.frame_rate,
|
||||
(sizeof(frsky_raw) / sizeof(frsky_raw[0])),
|
||||
frsky_raw);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void radio_control_impl_init(void) {
|
||||
cc2500_settings_init();
|
||||
cc2500_init();
|
||||
cc2500Reset();
|
||||
rxInit();
|
||||
#if PERIODIC_TELEMETRY
|
||||
register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_PPM, send_cc2500_ppm);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void radio_control_impl_event(void (* _received_frame_handler)(void)) {
|
||||
if (rxRuntimeConfig.rcFrameStatusFn(&rxRuntimeConfig) & RX_FRAME_COMPLETE) {
|
||||
rxRuntimeConfig.rcProcessFrameFn(&rxRuntimeConfig);
|
||||
radio_control.frame_cpt++;
|
||||
radio_control.time_since_last_frame = 0;
|
||||
if (radio_control.radio_ok_cpt > 0) {
|
||||
radio_control.radio_ok_cpt--;
|
||||
} else {
|
||||
radio_control.status = RC_OK;
|
||||
for (int i = 0; i < RADIO_CONTROL_NB_CHANNEL; ++i) {
|
||||
frsky_raw[i] = rxRuntimeConfig.rcReadRawFn(&rxRuntimeConfig, i);
|
||||
}
|
||||
NormalizePpmIIR(frsky_raw, radio_control);
|
||||
_received_frame_handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef RADIO_CONTROL_CC2500_PAPARAZZI_H
|
||||
#define RADIO_CONTROL_CC2500_PAPARAZZI_H
|
||||
|
||||
#define RC_PPM_TICKS_OF_USEC(_x) (_x)
|
||||
#define RC_PPM_SIGNED_TICKS_OF_USEC(_x) (_x)
|
||||
#define USEC_OF_RC_PPM_TICKS(_x) (_x)
|
||||
|
||||
#include "generated/airframe.h"
|
||||
#include "generated/radio.h"
|
||||
|
||||
#ifndef RADIO_CONTROL_NB_CHANNEL
|
||||
#define RADIO_CONTROL_NB_CHANNEL RADIO_CTL_NB
|
||||
#endif
|
||||
|
||||
extern void radio_control_impl_event(void (* _received_frame_handler)(void));
|
||||
#define RadioControlEvent(_received_frame_handler) radio_control_impl_event(_received_frame_handler)
|
||||
|
||||
|
||||
#endif // RADIO_CONTROL_CC2500_PAPARAZZI_H
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
#include "cc2500_settings.h"
|
||||
#include "cc2500_rx.h"
|
||||
|
||||
// betaflight/src/main/rx/rx_spi.h @ 766c90b
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include "pg/rx.h"
|
||||
//#include "rx/rx.h"
|
||||
//#include "pg/rx_spi.h"
|
||||
|
||||
// Used in MSP. Append at end.
|
||||
typedef enum {
|
||||
RX_SPI_NRF24_V202_250K = 0,
|
||||
RX_SPI_NRF24_V202_1M,
|
||||
RX_SPI_NRF24_SYMA_X,
|
||||
RX_SPI_NRF24_SYMA_X5C,
|
||||
RX_SPI_NRF24_CX10,
|
||||
RX_SPI_NRF24_CX10A,
|
||||
RX_SPI_NRF24_H8_3D,
|
||||
RX_SPI_NRF24_INAV,
|
||||
RX_SPI_FRSKY_D,
|
||||
RX_SPI_FRSKY_X,
|
||||
RX_SPI_A7105_FLYSKY,
|
||||
RX_SPI_A7105_FLYSKY_2A,
|
||||
RX_SPI_NRF24_KN,
|
||||
RX_SPI_SFHSS,
|
||||
RX_SPI_CYRF6936_DSM,
|
||||
RX_SPI_FRSKY_X_LBT,
|
||||
RX_SPI_PROTOCOL_COUNT
|
||||
} rx_spi_protocol_e;
|
||||
|
||||
typedef enum {
|
||||
RX_SPI_RECEIVED_NONE = 0,
|
||||
RX_SPI_RECEIVED_BIND = (1 << 0),
|
||||
RX_SPI_RECEIVED_DATA = (1 << 1),
|
||||
RX_SPI_ROCESSING_REQUIRED = (1 << 2),
|
||||
} rx_spi_received_e;
|
||||
|
||||
// RC channels in AETR order
|
||||
typedef enum {
|
||||
RC_SPI_ROLL = 0,
|
||||
RC_SPI_PITCH,
|
||||
RC_SPI_THROTTLE,
|
||||
RC_SPI_YAW,
|
||||
RC_SPI_AUX1,
|
||||
RC_SPI_AUX2,
|
||||
RC_SPI_AUX3,
|
||||
RC_SPI_AUX4,
|
||||
RC_SPI_AUX5,
|
||||
RC_SPI_AUX6,
|
||||
RC_SPI_AUX7,
|
||||
RC_SPI_AUX8,
|
||||
RC_SPI_AUX9,
|
||||
RC_SPI_AUX10,
|
||||
RC_SPI_AUX11,
|
||||
RC_SPI_AUX12,
|
||||
RC_SPI_AUX13,
|
||||
RC_SPI_AUX14
|
||||
} rc_spi_aetr_e;
|
||||
|
||||
// RC channels as used by deviation
|
||||
#define RC_CHANNEL_RATE RC_SPI_AUX1
|
||||
#define RC_CHANNEL_FLIP RC_SPI_AUX2
|
||||
#define RC_CHANNEL_PICTURE RC_SPI_AUX3
|
||||
#define RC_CHANNEL_VIDEO RC_SPI_AUX4
|
||||
#define RC_CHANNEL_HEADLESS RC_SPI_AUX5
|
||||
#define RC_CHANNEL_RTH RC_SPI_AUX6 // return to home
|
||||
|
||||
bool rxSpiInit(const rxSpiConfig_t *rxSpiConfig, rxRuntimeConfig_t *rxRuntimeConfig);
|
||||
@@ -0,0 +1,148 @@
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
#include "cc2500_rx_spi_common.h"
|
||||
|
||||
// betaflight/src/main/rx/rx_spi_common.c @ afb2bf5
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//#include "platform.h"
|
||||
|
||||
#ifdef USE_RX_SPI
|
||||
|
||||
//#include "drivers/io.h"
|
||||
//#include "drivers/time.h"
|
||||
//#include "rx/rx_spi_common.h"
|
||||
//#include "rx/rx_spi.h"
|
||||
|
||||
static IO_t ledPin;
|
||||
static bool ledInversion = false;
|
||||
|
||||
static IO_t bindPin;
|
||||
static bool bindRequested;
|
||||
static bool lastBindPinStatus;
|
||||
|
||||
void rxSpiCommonIOInit(const rxSpiConfig_t *rxSpiConfig)
|
||||
{
|
||||
if (rxSpiConfig->ledIoTag) {
|
||||
ledPin = IOGetByTag(rxSpiConfig->ledIoTag);
|
||||
IOInit(ledPin, OWNER_LED, 0);
|
||||
IOConfigGPIO(ledPin, IOCFG_OUT_PP);
|
||||
ledInversion = rxSpiConfig->ledInversion;
|
||||
rxSpiLedOff();
|
||||
} else {
|
||||
ledPin = IO_NONE;
|
||||
}
|
||||
|
||||
if (rxSpiConfig->bindIoTag) {
|
||||
bindPin = IOGetByTag(rxSpiConfig->bindIoTag);
|
||||
IOInit(bindPin, OWNER_RX_SPI_BIND, 0);
|
||||
IOConfigGPIO(bindPin, IOCFG_IPU);
|
||||
lastBindPinStatus = IORead(bindPin);
|
||||
} else {
|
||||
bindPin = IO_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void rxSpiLedOn(void)
|
||||
{
|
||||
if (ledPin) {
|
||||
ledInversion ? IOLo(ledPin) : IOHi(ledPin);
|
||||
}
|
||||
}
|
||||
|
||||
void rxSpiLedOff(void)
|
||||
{
|
||||
if (ledPin) {
|
||||
ledInversion ? IOHi(ledPin) : IOLo(ledPin);
|
||||
}
|
||||
}
|
||||
|
||||
void rxSpiLedToggle(void)
|
||||
{
|
||||
if (ledPin) {
|
||||
IOToggle(ledPin);
|
||||
}
|
||||
}
|
||||
|
||||
void rxSpiLedBlink(timeMs_t blinkMs)
|
||||
{
|
||||
static timeMs_t ledBlinkMs = 0;
|
||||
|
||||
if ((ledBlinkMs + blinkMs) > millis()) {
|
||||
return;
|
||||
}
|
||||
ledBlinkMs = millis();
|
||||
|
||||
rxSpiLedToggle();
|
||||
}
|
||||
|
||||
void rxSpiLedBlinkRxLoss(rx_spi_received_e result)
|
||||
{
|
||||
static uint16_t rxLossCount = 0;
|
||||
|
||||
if (ledPin) {
|
||||
if (result == RX_SPI_RECEIVED_DATA) {
|
||||
rxLossCount = 0;
|
||||
rxSpiLedOn();
|
||||
} else {
|
||||
if (rxLossCount < RX_LOSS_COUNT) {
|
||||
rxLossCount++;
|
||||
} else {
|
||||
rxSpiLedBlink(INTERVAL_RX_LOSS_MS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rxSpiLedBlinkBind(void)
|
||||
{
|
||||
rxSpiLedBlink(INTERVAL_RX_BIND_MS);
|
||||
}
|
||||
|
||||
void rxSpiBind(void)
|
||||
{
|
||||
bindRequested = true;
|
||||
}
|
||||
|
||||
bool rxSpiCheckBindRequested(bool reset)
|
||||
{
|
||||
if (bindPin) {
|
||||
bool bindPinStatus = IORead(bindPin);
|
||||
if (lastBindPinStatus && !bindPinStatus) {
|
||||
bindRequested = true;
|
||||
}
|
||||
lastBindPinStatus = bindPinStatus;
|
||||
}
|
||||
|
||||
if (!bindRequested) {
|
||||
return false;
|
||||
} else {
|
||||
if (reset) {
|
||||
bindRequested = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
#include "cc2500_rx_spi.h"
|
||||
|
||||
// betaflight/src/main/rx/rx_spi_common.h @ c88a5a3
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//#include "rx/rx_spi.h"
|
||||
|
||||
#define INTERVAL_RX_LOSS_MS 1000
|
||||
#define INTERVAL_RX_BIND_MS 250
|
||||
#define RX_LOSS_COUNT 1000
|
||||
|
||||
void rxSpiCommonIOInit(const rxSpiConfig_t *rxSpiConfig);
|
||||
|
||||
void rxSpiLedOn(void);
|
||||
void rxSpiLedOff(void);
|
||||
void rxSpiLedToggle(void);
|
||||
void rxSpiLedBlink(timeMs_t blinkMs);
|
||||
void rxSpiLedBlinkRxLoss(rx_spi_received_e result);
|
||||
void rxSpiLedBlinkBind(void);
|
||||
|
||||
void rxSpiBind(void);
|
||||
bool rxSpiCheckBindRequested(bool reset);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Tom van Dijk <tomvand@users.noreply.github.com>
|
||||
*
|
||||
* This code is based on the betaflight cc2500 and FrskyX implementation.
|
||||
* https://github.com/betaflight/betaflight
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi 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 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef RADIO_CONTROL_CC2500_SETTINGS_H
|
||||
#define RADIO_CONTROL_CC2500_SETTINGS_H
|
||||
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Paparazzi settings */
|
||||
void cc2500_settings_init(void);
|
||||
|
||||
struct cc2500_settings_persistent_s {
|
||||
uint32_t bindVars;
|
||||
uint32_t bindHopData[13];
|
||||
};
|
||||
extern struct cc2500_settings_persistent_s cc2500_settings_persistent;
|
||||
|
||||
|
||||
/* betaflight settings API */
|
||||
// main/config/config.h:
|
||||
void bf_writeEEPROM(void);
|
||||
#define writeEEPROM() bf_writeEEPROM()
|
||||
|
||||
|
||||
// main/pg/rx.h:
|
||||
#define FRAME_ERR_RESAMPLE_US 100000
|
||||
|
||||
#define GET_FRAME_ERR_LPF_FREQUENCY(period) (1 / (period / 10.0f))
|
||||
|
||||
typedef struct rxConfig_s {
|
||||
// uint8_t rcmap[RX_MAPPABLE_CHANNEL_COUNT]; // mapping of radio channels to internal RPYTA+ order
|
||||
uint8_t serialrx_provider; // type of UART-based receiver (0 = spek 10, 1 = spek 11, 2 = sbus). Must be enabled by FEATURE_RX_SERIAL first.
|
||||
// uint8_t serialrx_inverted; // invert the serial RX protocol compared to it's default setting
|
||||
// uint8_t halfDuplex; // allow rx to operate in half duplex mode on F4, ignored for F1 and F3.
|
||||
// ioTag_t spektrum_bind_pin_override_ioTag;
|
||||
// ioTag_t spektrum_bind_plug_ioTag;
|
||||
// uint8_t spektrum_sat_bind; // number of bind pulses for Spektrum satellite receivers
|
||||
// uint8_t spektrum_sat_bind_autoreset; // whenever we will reset (exit) binding mode after hard reboot
|
||||
uint8_t rssi_channel;
|
||||
// uint8_t rssi_scale;
|
||||
// uint8_t rssi_invert;
|
||||
uint16_t midrc; // Some radios have not a neutral point centered on 1500. can be changed here
|
||||
// uint16_t mincheck; // minimum rc end
|
||||
// uint16_t maxcheck; // maximum rc end
|
||||
// uint8_t rcInterpolation;
|
||||
// uint8_t rcInterpolationChannels;
|
||||
// uint8_t rcInterpolationInterval;
|
||||
// uint8_t fpvCamAngleDegrees; // Camera angle to be scaled into rc commands
|
||||
// uint8_t airModeActivateThreshold; // Throttle setpoint percent where airmode gets activated
|
||||
//
|
||||
// uint16_t rx_min_usec;
|
||||
// uint16_t rx_max_usec;
|
||||
uint8_t max_aux_channel;
|
||||
// uint8_t rssi_src_frame_errors; // true to use frame drop flags in the rx protocol
|
||||
// int8_t rssi_offset; // offset applied to the RSSI value before it is returned
|
||||
// uint8_t rc_smoothing_type; // Determines the smoothing algorithm to use: INTERPOLATION or FILTER
|
||||
// uint8_t rc_smoothing_input_cutoff; // Filter cutoff frequency for the input filter (0 = auto)
|
||||
// uint8_t rc_smoothing_derivative_cutoff; // Filter cutoff frequency for the setpoint weight derivative filter (0 = auto)
|
||||
// uint8_t rc_smoothing_debug_axis; // Axis to log as debug values when debug_mode = RC_SMOOTHING
|
||||
// uint8_t rc_smoothing_input_type; // Input filter type (0 = PT1, 1 = BIQUAD)
|
||||
// uint8_t rc_smoothing_derivative_type; // Derivative filter type (0 = OFF, 1 = PT1, 2 = BIQUAD)
|
||||
// uint8_t rc_smoothing_auto_factor; // Used to adjust the "smoothness" determined by the auto cutoff calculations
|
||||
uint8_t rssi_src_frame_lpf_period; // Period of the cutoff frequency for the source frame RSSI filter (in 0.1 s)
|
||||
//
|
||||
// uint8_t srxl2_unit_id; // Spektrum SRXL2 RX unit id
|
||||
// uint8_t srxl2_baud_fast; // Select Spektrum SRXL2 fast baud rate
|
||||
// uint8_t sbus_baud_fast; // Select SBus fast baud rate
|
||||
} rxConfig_t;
|
||||
|
||||
const rxConfig_t* rxConfig(void);
|
||||
|
||||
// main/pg/rx_spi.h:
|
||||
typedef struct rxSpiConfig_s {
|
||||
// RX protocol
|
||||
uint8_t rx_spi_protocol; // type of SPI RX protocol
|
||||
// // nrf24: 0 = v202 250kbps. (Must be enabled by FEATURE_RX_NRF24 first.)
|
||||
// uint32_t rx_spi_id;
|
||||
// uint8_t rx_spi_rf_channel_count;
|
||||
//
|
||||
// // SPI Bus
|
||||
// ioTag_t csnTag;
|
||||
// uint8_t spibus;
|
||||
//
|
||||
ioTag_t bindIoTag;
|
||||
ioTag_t ledIoTag;
|
||||
uint8_t ledInversion;
|
||||
|
||||
ioTag_t extiIoTag;
|
||||
} rxSpiConfig_t;
|
||||
|
||||
const rxSpiConfig_t* rxSpiConfig(void);
|
||||
|
||||
|
||||
// main/pg/rx_spi_cc2500.h:
|
||||
typedef enum {
|
||||
FRSKY_SPI_A1_SOURCE_VBAT = 0,
|
||||
FRSKY_SPI_A1_SOURCE_EXTADC,
|
||||
FRSKY_SPI_A1_SOURCE_CONST
|
||||
} frSkySpiA1Source_e;
|
||||
|
||||
typedef struct rxCc2500SpiConfig_s {
|
||||
uint8_t autoBind;
|
||||
uint8_t bindTxId[2];
|
||||
int8_t bindOffset;
|
||||
uint8_t bindHopData[50];
|
||||
uint8_t rxNum;
|
||||
uint8_t a1Source;
|
||||
uint8_t chipDetectEnabled;
|
||||
// ioTag_t txEnIoTag;
|
||||
// ioTag_t lnaEnIoTag;
|
||||
// ioTag_t antSelIoTag;
|
||||
} rxCc2500SpiConfig_t;
|
||||
|
||||
const rxCc2500SpiConfig_t* rxCc2500SpiConfig(void);
|
||||
rxCc2500SpiConfig_t* rxCc2500SpiConfigMutable(void);
|
||||
|
||||
|
||||
// main/telemetry/telemetry.h:
|
||||
typedef struct telemetryConfig_s {
|
||||
// int16_t gpsNoFixLatitude;
|
||||
// int16_t gpsNoFixLongitude;
|
||||
// uint8_t telemetry_inverted;
|
||||
// uint8_t halfDuplex;
|
||||
// frskyGpsCoordFormat_e frsky_coordinate_format;
|
||||
// frskyUnit_e frsky_unit;
|
||||
// uint8_t frsky_vfas_precision;
|
||||
// uint8_t hottAlarmSoundInterval;
|
||||
uint8_t pidValuesAsTelemetry;
|
||||
uint8_t report_cell_voltage;
|
||||
// uint8_t flysky_sensors[IBUS_SENSOR_COUNT];
|
||||
// uint16_t mavlink_mah_as_heading_divisor;
|
||||
// uint32_t disabledSensors; // bit flags
|
||||
} telemetryConfig_t;
|
||||
|
||||
const telemetryConfig_t* telemetryConfig(void);
|
||||
|
||||
typedef enum {
|
||||
SENSOR_VOLTAGE = 1 << 0,
|
||||
SENSOR_CURRENT = 1 << 1,
|
||||
SENSOR_FUEL = 1 << 2,
|
||||
SENSOR_MODE = 1 << 3,
|
||||
SENSOR_ACC_X = 1 << 4,
|
||||
SENSOR_ACC_Y = 1 << 5,
|
||||
SENSOR_ACC_Z = 1 << 6,
|
||||
SENSOR_PITCH = 1 << 7,
|
||||
SENSOR_ROLL = 1 << 8,
|
||||
SENSOR_HEADING = 1 << 9,
|
||||
SENSOR_ALTITUDE = 1 << 10,
|
||||
SENSOR_VARIO = 1 << 11,
|
||||
SENSOR_LAT_LONG = 1 << 12,
|
||||
SENSOR_GROUND_SPEED = 1 << 13,
|
||||
SENSOR_DISTANCE = 1 << 14,
|
||||
ESC_SENSOR_CURRENT = 1 << 15,
|
||||
ESC_SENSOR_VOLTAGE = 1 << 16,
|
||||
ESC_SENSOR_RPM = 1 << 17,
|
||||
ESC_SENSOR_TEMPERATURE = 1 << 18,
|
||||
ESC_SENSOR_ALL = ESC_SENSOR_CURRENT \
|
||||
| ESC_SENSOR_VOLTAGE \
|
||||
| ESC_SENSOR_RPM \
|
||||
| ESC_SENSOR_TEMPERATURE,
|
||||
SENSOR_TEMPERATURE = 1 << 19,
|
||||
SENSOR_ALL = (1 << 20) - 1,
|
||||
} sensor_e;
|
||||
#define SENSOR_NONE 0
|
||||
|
||||
bool telemetryIsSensorEnabled(sensor_e sensor);
|
||||
|
||||
|
||||
#endif // RADIO_CONTROL_CC2500_SETTINGS_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,97 @@
|
||||
#include "cc2500_compat.h"
|
||||
|
||||
/* SmartPort downlink hook
|
||||
* Called from smartport telemetry loop.
|
||||
* Write telemetry stream to 'data'.
|
||||
* Return 'true' if data is written.
|
||||
*/
|
||||
typedef bool smartPortDownlinkFn(uint32_t *data);
|
||||
extern smartPortDownlinkFn *smartPortDownlink;
|
||||
|
||||
/* SmartPort uplink hook
|
||||
* Called from processSmartPortTelemetry
|
||||
*/
|
||||
struct smartPortPayload_s;
|
||||
typedef void smartPortUplinkFn(struct smartPortPayload_s *payload);
|
||||
extern smartPortUplinkFn *smartPortUplink;
|
||||
|
||||
// CAUTION: LARGE PARTS OF THIS FILE ARE COMMENTED OUT!
|
||||
// betaflight/src/main/telemetry/smartport.h @ 41492e1
|
||||
/*
|
||||
* This file is part of Cleanflight and Betaflight.
|
||||
*
|
||||
* Cleanflight and Betaflight are free software. You can redistribute
|
||||
* this software and/or modify this software 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 and Betaflight are distributed in the hope that they
|
||||
* 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 this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* smartport.h
|
||||
*
|
||||
* Created on: 25 October 2014
|
||||
* Author: Frank26080115
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//#define SMARTPORT_MSP_TX_BUF_SIZE 256
|
||||
//#define SMARTPORT_MSP_RX_BUF_SIZE 64
|
||||
|
||||
enum
|
||||
{
|
||||
FSSP_START_STOP = 0x7E,
|
||||
|
||||
FSSP_DLE = 0x7D,
|
||||
FSSP_DLE_XOR = 0x20,
|
||||
|
||||
FSSP_DATA_FRAME = 0x10,
|
||||
FSSP_MSPC_FRAME_SMARTPORT = 0x30, // MSP client frame
|
||||
FSSP_MSPC_FRAME_FPORT = 0x31, // MSP client frame
|
||||
FSSP_MSPS_FRAME = 0x32, // MSP server frame
|
||||
|
||||
// ID of sensor. Must be something that is polled by FrSky RX
|
||||
FSSP_SENSOR_ID1 = 0x1B,
|
||||
FSSP_SENSOR_ID2 = 0x0D,
|
||||
FSSP_SENSOR_ID3 = 0x34,
|
||||
FSSP_SENSOR_ID4 = 0x67
|
||||
// there are 32 ID's polled by smartport master
|
||||
// remaining 3 bits are crc (according to comments in openTx code)
|
||||
};
|
||||
|
||||
typedef struct smartPortPayload_s {
|
||||
uint8_t frameId;
|
||||
uint16_t valueId;
|
||||
uint32_t data;
|
||||
} __attribute__((packed)) smartPortPayload_t;
|
||||
|
||||
typedef void smartPortWriteFrameFn(const smartPortPayload_t *payload);
|
||||
typedef bool smartPortCheckQueueEmptyFn(void);
|
||||
|
||||
//bool initSmartPortTelemetry(void);
|
||||
//void checkSmartPortTelemetryState(void);
|
||||
bool initSmartPortTelemetryExternal(smartPortWriteFrameFn *smartPortWriteFrameExternal);
|
||||
|
||||
//void handleSmartPortTelemetry(void);
|
||||
void processSmartPortTelemetry(smartPortPayload_t *payload, volatile bool *hasRequest, const uint32_t *requestTimeout);
|
||||
|
||||
smartPortPayload_t *smartPortDataReceive(uint16_t c, bool *clearToSend, smartPortCheckQueueEmptyFn *checkQueueEmpty, bool withChecksum);
|
||||
|
||||
//struct serialPort_s;
|
||||
//void smartPortWriteFrameSerial(const smartPortPayload_t *payload, struct serialPort_s *port, uint16_t checksum);
|
||||
//void smartPortSendByte(uint8_t c, uint16_t *checksum, struct serialPort_s *port);
|
||||
//bool smartPortPayloadContainsMSP(const smartPortPayload_t *payload);
|
||||
@@ -0,0 +1,73 @@
|
||||
-- SmartPort to serial bridge
|
||||
-- TELEMETRY SCRIPT
|
||||
--
|
||||
-- Requires opentx compilation flags -DLUA=YES -DUSB_SERIAL=YES -DCLI=NO
|
||||
--
|
||||
-- On TX, set hardware USB mode to serial
|
||||
-- Add this script as telemetry script to your model
|
||||
|
||||
local downlink_str = ""
|
||||
local uplink_str = ""
|
||||
|
||||
local function init_func()
|
||||
end
|
||||
|
||||
local function downlink_bg()
|
||||
local sensorId, frameId, dataId, value = sportTelemetryPop()
|
||||
while frameId do
|
||||
if dataId == 0x5015 then
|
||||
local value0 = math.floor(value / 16777216) % 256
|
||||
local value1 = math.floor(value / 65536) % 256
|
||||
local value2 = math.floor(value / 256) % 256
|
||||
local value3 = value % 256
|
||||
serialWrite(string.char(value0) .. string.char(value1) .. string.char(value2) .. string.char(value3))
|
||||
downlink_str = string.format("0x %X %X %X %X", value0, value1, value2, value3)
|
||||
end
|
||||
sensorId, frameId, dataId, value = sportTelemetryPop()
|
||||
end
|
||||
end
|
||||
|
||||
local uplink_buf = ""
|
||||
local function uplink_bg()
|
||||
if string.len(uplink_buf) < 4 then
|
||||
-- Grab new/more data from the serial line
|
||||
local new_bytes = serialRead(4 - string.len(uplink_buf))
|
||||
uplink_buf = uplink_buf .. new_bytes
|
||||
end
|
||||
if string.len(uplink_buf) > 0 then
|
||||
-- Data ready to transmit
|
||||
local sensorId = 0x0D -- see smartport.c::smartPortDataReceive
|
||||
local frameId = string.len(uplink_buf)
|
||||
local dataId = 0x5016
|
||||
local value = 0
|
||||
local byte = 16777216
|
||||
for i=1,string.len(uplink_buf) do
|
||||
value = value + byte * string.byte(uplink_buf, i)
|
||||
byte = byte / 256
|
||||
end
|
||||
-- DEBUG
|
||||
-- frameId = 2
|
||||
-- value = 0xABCDEF12
|
||||
-- DEBUG
|
||||
local ret = sportTelemetryPush(sensorId, frameId, dataId, value)
|
||||
if ret then
|
||||
-- Uplink successful, signal that new data can be read
|
||||
uplink_buf = ""
|
||||
uplink_str = string.format("0x%X (%s)", value, frameId)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function bg_func()
|
||||
downlink_bg()
|
||||
uplink_bg()
|
||||
end
|
||||
|
||||
local function run_func(event)
|
||||
lcd.clear()
|
||||
lcd.drawText(1, 1, "sp2ser is running...")
|
||||
lcd.drawText(1, 11, "Downlink: '" .. downlink_str .. "'")
|
||||
lcd.drawText(1, 21, "Uplink: '" .. uplink_str .. "'")
|
||||
end
|
||||
|
||||
return {run = run_func, background = bg_func, init = init_func}
|
||||
Reference in New Issue
Block a user