diff --git a/flight/CopterControl/System/pios_board.c b/flight/CopterControl/System/pios_board.c
index d512ae989..455946958 100644
--- a/flight/CopterControl/System/pios_board.c
+++ b/flight/CopterControl/System/pios_board.c
@@ -923,6 +923,8 @@ void PIOS_Board_Init(void) {
TaskMonitorInitialize();
/* Configure the main IO port */
+ uint8_t hwsettings_DSMxBind;
+ HwSettingsDSMxBindGet(&hwsettings_DSMxBind);
uint8_t hwsettings_cc_mainport;
HwSettingsCC_MainPortGet(&hwsettings_cc_mainport);
@@ -991,7 +993,7 @@ void PIOS_Board_Init(void) {
}
uint32_t pios_spektrum_id;
- if (PIOS_SPEKTRUM_Init(&pios_spektrum_id, &pios_spektrum_main_cfg, &pios_usart_com_driver, pios_usart_spektrum_id, false)) {
+ if (PIOS_SPEKTRUM_Init(&pios_spektrum_id, &pios_spektrum_main_cfg, &pios_usart_com_driver, pios_usart_spektrum_id, 0)) {
PIOS_Assert(0);
}
}
@@ -1053,7 +1055,7 @@ void PIOS_Board_Init(void) {
}
uint32_t pios_spektrum_id;
- if (PIOS_SPEKTRUM_Init(&pios_spektrum_id, &pios_spektrum_flexi_cfg, &pios_usart_com_driver, pios_usart_spektrum_id, false)) {
+ if (PIOS_SPEKTRUM_Init(&pios_spektrum_id, &pios_spektrum_flexi_cfg, &pios_usart_com_driver, pios_usart_spektrum_id, hwsettings_DSMxBind)) {
PIOS_Assert(0);
}
}
diff --git a/flight/PiOS/STM32F10x/pios_spektrum.c b/flight/PiOS/STM32F10x/pios_spektrum.c
index 8b0f38c6b..2d57d9900 100644
--- a/flight/PiOS/STM32F10x/pios_spektrum.c
+++ b/flight/PiOS/STM32F10x/pios_spektrum.c
@@ -8,7 +8,6 @@
*
* @file pios_spektrum.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
- * Parts by Thorsten Klose (tk@midibox.org) (tk@midibox.org)
* @brief USART commands. Inits USARTs, controls USARTs & Interrupt handlers. (STM32 dependent)
* @see The GNU Public License (GPL) Version 3
*
@@ -59,7 +58,7 @@ uint8_t sync_of = 0;
uint16_t supv_timer=0;
static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id);
-static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg);
+static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg, uint8_t bind);
static int32_t PIOS_SPEKTRUM_Decode(uint8_t b);
static uint16_t PIOS_SPEKTRUM_RxInCallback(uint32_t context, uint8_t * buf, uint16_t buf_len, uint16_t * headroom, bool * need_yield)
@@ -85,11 +84,11 @@ static uint16_t PIOS_SPEKTRUM_RxInCallback(uint32_t context, uint8_t * buf, uint
/**
* Bind and Initialise Spektrum satellite receiver
*/
-int32_t PIOS_SPEKTRUM_Init(uint32_t * spektrum_id, const struct pios_spektrum_cfg *cfg, const struct pios_com_driver * driver, uint32_t lower_id, bool bind)
+int32_t PIOS_SPEKTRUM_Init(uint32_t * spektrum_id, const struct pios_spektrum_cfg *cfg, const struct pios_com_driver * driver, uint32_t lower_id, uint8_t bind)
{
// TODO: need setting flag for bind on next powerup
if (bind) {
- PIOS_SPEKTRUM_Bind(cfg);
+ PIOS_SPEKTRUM_Bind(cfg,bind);
}
(driver->bind_rx_cb)(lower_id, PIOS_SPEKTRUM_RxInCallback, 0);
@@ -121,9 +120,15 @@ static int32_t PIOS_SPEKTRUM_Get(uint32_t rcvr_id, uint8_t channel)
* \output true Successful bind
* \output false Bind failed
*/
-static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg)
+static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg, uint8_t bind)
{
-#define BIND_PULSES 5
+ GPIO_InitTypeDef GPIO_InitStructure;
+ GPIO_InitStructure.GPIO_Pin = cfg->bind.init.GPIO_Pin;
+ GPIO_InitStructure.GPIO_Speed = cfg->bind.init.GPIO_Speed;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
+
+ /* just to limit bind pulses */
+ bind=(bind<=10)?bind:10;
GPIO_Init(cfg->bind.gpio, &cfg->bind.init);
/* RX line, set high */
@@ -132,7 +137,7 @@ static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg)
/* on CC works upto 140ms, I guess bind window is around 20-140ms after powerup */
PIOS_DELAY_WaitmS(60);
- for (int i = 0; i < BIND_PULSES ; i++) {
+ for (int i = 0; i < bind ; i++) {
/* RX line, drive low for 120us */
GPIO_ResetBits(cfg->bind.gpio, cfg->bind.init.GPIO_Pin);
PIOS_DELAY_WaituS(120);
@@ -141,6 +146,7 @@ static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg)
PIOS_DELAY_WaituS(120);
}
/* RX line, set input and wait for data, PIOS_SPEKTRUM_Init */
+ GPIO_Init(cfg->bind.gpio, &GPIO_InitStructure);
return true;
}
@@ -172,9 +178,10 @@ static int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
CaptureValue[7]=b;
}
#endif
- /* Known sync bytes, 0x01, 0x02, 0x12 */
+ /* Known sync bytes, 0x01, 0x02, 0x12, 0xb2 */
+ /* 0xb2 DX8 3bind pulses only */
if (bytecount == 2) {
- if (b == 0x01) {
+ if ((b == 0x01) || (b == 0xb2)) {
datalength=0; // 10bit
//frames=1;
sync = 1;
@@ -234,17 +241,17 @@ static int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
*@brief clears the channel values
*/
static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id) {
- /* 125hz */
+ /* 625hz */
supv_timer++;
- if(supv_timer > 5) {
+ if(supv_timer > 4) {
/* sync between frames */
sync = 0;
bytecount = 0;
prev_byte = 0xFF;
frame_error = 0;
sync_of++;
- /* watchdog activated after 100ms silence */
- if (sync_of > 12) {
+ /* watchdog activated after 200ms silence */
+ if (sync_of > 30) {
/* signal lost */
sync_of = 0;
for (int i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) {
diff --git a/flight/PiOS/inc/pios_spektrum_priv.h b/flight/PiOS/inc/pios_spektrum_priv.h
index 2d31a8027..ffd224e40 100644
--- a/flight/PiOS/inc/pios_spektrum_priv.h
+++ b/flight/PiOS/inc/pios_spektrum_priv.h
@@ -42,7 +42,7 @@ struct pios_spektrum_cfg {
extern const struct pios_rcvr_driver pios_spektrum_rcvr_driver;
-extern int32_t PIOS_SPEKTRUM_Init(uint32_t * spektrum_id, const struct pios_spektrum_cfg *cfg, const struct pios_com_driver * driver, uint32_t lower_id, bool bind);
+extern int32_t PIOS_SPEKTRUM_Init(uint32_t * spektrum_id, const struct pios_spektrum_cfg *cfg, const struct pios_com_driver * driver, uint32_t lower_id, uint8_t bind);
#endif /* PIOS_PWM_PRIV_H */
diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml
index 63c2a745a..2d6f440d7 100644
--- a/shared/uavobjectdefinition/hwsettings.xml
+++ b/shared/uavobjectdefinition/hwsettings.xml
@@ -4,6 +4,7 @@
+