mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-04 13:55:40 +08:00
Added spektrum software bind pin reset feature
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="spektrum_soft_bind" dir="spektrum_soft_bind">
|
||||
<doc>
|
||||
<description>Puts Spektrum in binding mode through software</description>
|
||||
</doc>
|
||||
<settings target="ap">
|
||||
<dl_settings>
|
||||
<dl_settings name="Spektrum soft bind">
|
||||
<dl_setting MAX="1" MIN="0" STEP="1" VAR="bind_soft_value" values="FALSE|TRUE" shortname="Bind Spektrum" module="spektrum_soft_bind/spektrum_soft_bind" handler="click"/>
|
||||
</dl_settings>
|
||||
</dl_settings>
|
||||
</settings>
|
||||
<header >
|
||||
<file name="spektrum_soft_bind.h"/>
|
||||
</header>
|
||||
<init fun="spektrum_soft_bind_init()"/>
|
||||
<makefile target="ap">
|
||||
<file name="spektrum_soft_bind_ap.c"/>
|
||||
</makefile>
|
||||
<makefile target="fbw">
|
||||
<file name="spektrum_soft_bind_fbw.c"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ void mcu_init(void)
|
||||
led_init();
|
||||
#endif
|
||||
/* for now this means using spektrum */
|
||||
#if defined RADIO_CONTROL & defined RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT & defined RADIO_CONTROL_BIND_IMPL_FUNC
|
||||
#if defined RADIO_CONTROL & defined RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT & defined RADIO_CONTROL_BIND_IMPL_FUNC & defined SPEKTRUM_BIND_PIN_PORT
|
||||
RADIO_CONTROL_BIND_IMPL_FUNC();
|
||||
#endif
|
||||
#if USE_UART0
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) Kevin van Hecke
|
||||
*
|
||||
* 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/spektrum_soft_bind/spektrum_soft_bind.c"
|
||||
* @author Kevin van Hecke
|
||||
* Puts Spektrum in binding mode through software
|
||||
*/
|
||||
|
||||
#include "modules/spektrum_soft_bind/spektrum_soft_bind_fbw.h"
|
||||
|
||||
void spektrum_soft_bind_init() {}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) Kevin van Hecke
|
||||
*
|
||||
* 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/spektrum_soft_bind/spektrum_soft_bind.h"
|
||||
* @author Kevin van Hecke
|
||||
* Puts Spektrum in binding mode through software
|
||||
*/
|
||||
|
||||
#ifndef SPEKTRUM_SOFT_BIND_H
|
||||
#define SPEKTRUM_SOFT_BIND_H
|
||||
|
||||
#if defined FBW
|
||||
#include "modules/spektrum_soft_bind/spektrum_soft_bind_fbw.h"
|
||||
#else
|
||||
#include "modules/spektrum_soft_bind/spektrum_soft_bind_ap.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) Kevin van Hecke
|
||||
*
|
||||
* 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/spektrum_soft_bind/spektrum_soft_bind_ap.c"
|
||||
* @author Kevin van Hecke
|
||||
* Puts Spektrum in binding mode through software
|
||||
*/
|
||||
|
||||
#include "modules/spektrum_soft_bind/spektrum_soft_bind_ap.h"
|
||||
#include "subsystems/intermcu/intermcu_ap.h"
|
||||
#include "led.h"
|
||||
|
||||
void spektrum_soft_bind_init(void) {}
|
||||
|
||||
uint8_t bind_soft_value;
|
||||
void spektrum_soft_bind_click(uint8_t val __attribute__((unused)))
|
||||
{
|
||||
intermcu_send_spektrum_bind();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) Kevin van Hecke
|
||||
*
|
||||
* 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/spektrum_soft_bind/spektrum_soft_bind_ap.h"
|
||||
* @author Kevin van Hecke
|
||||
* Puts Spektrum in binding mode through software
|
||||
*/
|
||||
|
||||
#ifndef SPEKTRUM_AP_SOFT_BIND_H
|
||||
#define SPEKTRUM_AP_SOFT_BIND_H
|
||||
|
||||
#include "std.h"
|
||||
|
||||
extern void spektrum_soft_bind_init(void);
|
||||
extern void spektrum_soft_bind_click(uint8_t val);
|
||||
|
||||
extern uint8_t bind_soft_value;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) Kevin van Hecke
|
||||
*
|
||||
* 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/spektrum_soft_bind/spektrum_soft_bind_fbw.c"
|
||||
* @author Kevin van Hecke
|
||||
* Puts Spektrum in binding mode through software
|
||||
*/
|
||||
|
||||
#include "modules/spektrum_soft_bind/spektrum_soft_bind_fbw.h"
|
||||
#include "subsystems/intermcu/intermcu_fbw.h"
|
||||
#include "mcu.h"
|
||||
#include "subsystems/radio_control.h"
|
||||
#include "mcu_periph/sys_time_arch.h"
|
||||
|
||||
#include "led.h"
|
||||
#include "mcu_periph/gpio.h"
|
||||
|
||||
void spektrum_soft_bind_init(void)
|
||||
{
|
||||
gpio_setup_output(SPEKTRUM_POWER_PIN_PORT, SPEKTRUM_POWER_PIN);
|
||||
gpio_set(SPEKTRUM_POWER_PIN_PORT, SPEKTRUM_POWER_PIN);
|
||||
}
|
||||
|
||||
void received_spektrum_soft_bind(void)
|
||||
{
|
||||
|
||||
//power cycle the spektrum
|
||||
gpio_clear(SPEKTRUM_POWER_PIN_PORT, SPEKTRUM_POWER_PIN);
|
||||
sys_time_usleep(100000);
|
||||
gpio_set(SPEKTRUM_POWER_PIN_PORT, SPEKTRUM_POWER_PIN);
|
||||
|
||||
//put to bind mode
|
||||
RADIO_CONTROL_BIND_IMPL_FUNC(); //basically = radio_control_spektrum_try_bind()
|
||||
|
||||
SpektrumUartInit();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) Kevin van Hecke
|
||||
*
|
||||
* 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/spektrum_soft_bind/spektrum_soft_bind_fbw.h"
|
||||
* @author Kevin van Hecke
|
||||
* Puts Spektrum in binding mode through software
|
||||
*/
|
||||
|
||||
#ifndef SPEKTRUM_FBW_SOFT_BIND_H
|
||||
#define SPEKTRUM_FBW_SOFT_BIND_H
|
||||
#include "std.h"
|
||||
|
||||
extern void spektrum_soft_bind_init(void);
|
||||
extern void received_spektrum_soft_bind(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
#include "pprzlink/pprz_transport.h"
|
||||
#include "mcu_periph/uart.h"
|
||||
|
||||
#include "subsystems/datalink/telemetry.h"
|
||||
#include "subsystems/electrical.h"
|
||||
#include "autopilot.h"
|
||||
|
||||
#if COMMANDS_NB > 8
|
||||
#error "INTERMCU UART CAN ONLY SEND 8 COMMANDS OR THE UART WILL BE OVERFILLED"
|
||||
#endif
|
||||
@@ -70,6 +74,11 @@ void intermcu_set_actuators(pprz_t *command_values, uint8_t ap_mode __attribute_
|
||||
}
|
||||
}
|
||||
|
||||
void intermcu_send_spektrum_bind(void)
|
||||
{
|
||||
if (!disable_comm) {
|
||||
pprz_msg_send_IMCU_SPEKTRUM_SOFT_BIND(&(intermcu_transport.trans_tx), intermcu_device, INTERMCU_AP);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void intermcu_parse_msg(struct transport_rx *trans, void (*rc_frame_handler)(void))
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
void intermcu_set_actuators(pprz_t *command_values, uint8_t ap_mode);
|
||||
void RadioControlEvent(void (*frame_handler)(void));
|
||||
void intermcu_send_spektrum_bind(void);
|
||||
void disable_inter_comm(bool_t value);
|
||||
|
||||
/* We need radio defines for the Autopilot */
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "subsystems/radio_control.h"
|
||||
#include "mcu_periph/uart.h"
|
||||
#include "pprzlink/pprz_transport.h"
|
||||
#include "modules/spektrum_soft_bind/spektrum_soft_bind_fbw.h"
|
||||
|
||||
#ifdef BOARD_PX4IO
|
||||
#include "libopencm3/cm3/scb.h"
|
||||
@@ -97,6 +98,8 @@ static inline void intermcu_parse_msg(struct transport_rx *trans, void (*command
|
||||
uint8_t i;
|
||||
uint8_t size = DL_IMCU_COMMANDS_values_length(trans->payload);
|
||||
int16_t *new_commands = DL_IMCU_COMMANDS_values(trans->payload);
|
||||
uint8_t status = DL_IMCU_COMMANDS_status(trans->payload);
|
||||
autopilot_motors_on = status & 0x1;
|
||||
for (i = 0; i < size; i++) {
|
||||
intermcu_commands[i] = new_commands[i];
|
||||
}
|
||||
@@ -107,6 +110,11 @@ static inline void intermcu_parse_msg(struct transport_rx *trans, void (*command
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(SPEKTRUM_HAS_SOFT_BIND_PIN) //TODO: make subscribable module parser
|
||||
case DL_IMCU_SPEKTRUM_SOFT_BIND:
|
||||
received_spektrum_soft_bind();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -117,10 +125,15 @@ static inline void intermcu_parse_msg(struct transport_rx *trans, void (*command
|
||||
|
||||
void InterMcuEvent(void (*frame_handler)(void))
|
||||
{
|
||||
|
||||
/* Parse incoming bytes */
|
||||
if (intermcu_device->char_available(intermcu_device->periph)) {
|
||||
while (intermcu_device->char_available(intermcu_device->periph) && !intermcu_transport.trans_rx.msg_received) {
|
||||
parse_pprz(&intermcu_transport, intermcu_device->get_byte(intermcu_device->periph));
|
||||
unsigned char b = intermcu_device->get_byte(intermcu_device->periph);
|
||||
#ifdef BOARD_PX4IO
|
||||
checkPx4RebootCommand(b);
|
||||
#endif
|
||||
parse_pprz(&intermcu_transport, b);
|
||||
}
|
||||
|
||||
if (intermcu_transport.trans_rx.msg_received) {
|
||||
@@ -128,3 +141,44 @@ void InterMcuEvent(void (*frame_handler)(void))
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef BOARD_PX4IO
|
||||
static inline void checkPx4RebootCommand(unsigned char b)
|
||||
{
|
||||
if (!px4RebootTimeout) {
|
||||
|
||||
|
||||
if (sys_time_check_and_ack_timer(px4bl_tid)) {
|
||||
//time out the possibility to reboot to the px4 bootloader, to prevent unwanted restarts during flight
|
||||
px4RebootTimeout = true;
|
||||
sys_time_cancel_timer(px4bl_tid);
|
||||
return;
|
||||
}
|
||||
|
||||
LED_ON(SYS_TIME_LED);
|
||||
|
||||
if (b == px4RebootSequence[px4RebootSequenceCount]) {
|
||||
px4RebootSequenceCount++;
|
||||
} else {
|
||||
px4RebootSequenceCount = 0;
|
||||
}
|
||||
|
||||
if (px4RebootSequenceCount >= 6) { // 6 = length of rebootSequence + 1
|
||||
px4RebootSequenceCount = 0; // should not be necessary...
|
||||
|
||||
//send some magic back
|
||||
//this is the same as the Pixhawk IO code would send
|
||||
intermcu_device->put_byte(intermcu_device->periph, 0x00);
|
||||
intermcu_device->put_byte(intermcu_device->periph, 0xe5);
|
||||
intermcu_device->put_byte(intermcu_device->periph, 0x32);
|
||||
intermcu_device->put_byte(intermcu_device->periph, 0x0a);
|
||||
intermcu_device->put_byte(intermcu_device->periph,
|
||||
0x66); // dummy byte, seems to be necessary otherwise one byte is missing at the fmu side...
|
||||
|
||||
while (((struct uart_periph *)(intermcu_device->periph))->tx_running) {LED_TOGGLE(SYS_TIME_LED);} // tx_running is volatile now, so LED_TOGGLE not necessary anymore
|
||||
|
||||
LED_OFF(SYS_TIME_LED);
|
||||
scb_reset_system();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user