mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
Merged in Oblivium/librepilot/LP-477_iBus_on_receiver_port (pull request #383)
LP-477 iBus on (revo) receiver port & iBus packet structure descriptions
This commit is contained in:
commit
f48fdf82c5
@ -1,7 +1,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pios_ibus.c
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016-2017.
|
||||
* dRonin, http://dRonin.org/, Copyright (C) 2016
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
@ -33,11 +33,39 @@
|
||||
|
||||
#ifdef PIOS_INCLUDE_IBUS
|
||||
|
||||
// 1 sync byte, 1 unknown byte, 10x channels (uint16_t), 8 unknown bytes, 2 crc bytes
|
||||
#define PIOS_IBUS_BUFLEN (1 + 1 + PIOS_IBUS_NUM_INPUTS * 2 + 8 + 2)
|
||||
#define PIOS_IBUS_SYNCBYTE 0x20
|
||||
/*
|
||||
iBus packet format learned from: https://bitbucket.org/daveborthwick/ibus_pic12f1572
|
||||
|
||||
An iBus packet consists of:
|
||||
- the total packet length (1 byte)
|
||||
- command / type field (1 byte)
|
||||
- sequence of 16-bit (little endian) variables (2 bytes each)
|
||||
- checksum (2 bytes)
|
||||
|
||||
The most common packet length is 0x20 = 32 bytes
|
||||
A packet of this type has enough room to transport data for 14 channels.
|
||||
|
||||
The command / type field tells you the meaning of the next variables.
|
||||
This field is set to 0x40 for RC command channels.
|
||||
We must verify this field to be 0x40 so we can be sure that the next fields
|
||||
can be interpreted as RC command channels.
|
||||
|
||||
The checksum equals 0xFFFF minus the sum of all previous bytes in the packet.
|
||||
|
||||
*/
|
||||
|
||||
// 1 length byte, 1 type byte, 10x channels (uint16_t), 4 extra channels (unint16_t), 2 crc bytes
|
||||
// We only decode the first 10 channels at this time.
|
||||
#define PIOS_IBUS_BUFLEN (1 + 1 + PIOS_IBUS_NUM_INPUTS * 2 + (14 - PIOS_IBUS_NUM_INPUTS) * 2 + 2)
|
||||
#define PIOS_IBUS_SYNCBYTE 0x20 // sync on the packet length byte
|
||||
#define PIOS_IBUS_TYPEBYTE 0x40
|
||||
#define PIOS_IBUS_MAGIC 0x84fd9a39
|
||||
|
||||
// make sure to always allocate sufficient bufferspace:
|
||||
#if (PIOS_IBUS_SYNCBYTE != PIOS_IBUS_BUFLEN)
|
||||
#error PIOS_IBUS_BUFLEN must be updated to match the expected packet length
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief IBus receiver driver internal state data
|
||||
*/
|
||||
@ -182,9 +210,16 @@ static uint16_t PIOS_IBUS_Receive(uint32_t context, uint8_t *buf, uint16_t buf_l
|
||||
}
|
||||
|
||||
for (int i = 0; i < buf_len; i++) {
|
||||
// byte 0: sync byte (packet length) should match:
|
||||
if (ibus_dev->buf_pos == 0 && buf[i] != PIOS_IBUS_SYNCBYTE) {
|
||||
continue;
|
||||
}
|
||||
// byte 1: type field should match:
|
||||
if (ibus_dev->buf_pos == 1 && buf[i] != PIOS_IBUS_TYPEBYTE) {
|
||||
// not the correct type of data, restart from byte 0
|
||||
ibus_dev->buf_pos = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
ibus_dev->rx_buf[ibus_dev->buf_pos++] = buf[i];
|
||||
if (ibus_dev->buf_pos <= PIOS_IBUS_BUFLEN - 2) {
|
||||
@ -238,10 +273,12 @@ static void PIOS_IBUS_Supervisor(uint32_t context)
|
||||
|
||||
PIOS_Assert(PIOS_IBUS_Validate(ibus_dev));
|
||||
|
||||
// clear rx buffer after 4.8 ms without input
|
||||
if (++ibus_dev->rx_timer > 3) {
|
||||
PIOS_IBUS_ResetBuffer(ibus_dev);
|
||||
}
|
||||
|
||||
// mark all channels invalid after 51.2 ms without valid data
|
||||
if (++ibus_dev->failsafe_timer > 32) {
|
||||
PIOS_IBUS_SetAllChannels(ibus_dev, PIOS_RCVR_TIMEOUT);
|
||||
}
|
||||
|
@ -1218,6 +1218,37 @@ static const struct pios_usart_cfg pios_usart_ibus_flexi_cfg = {
|
||||
},
|
||||
};
|
||||
|
||||
static const struct pios_usart_cfg pios_usart_ibus_rcvr_cfg = {
|
||||
.regs = USART6,
|
||||
.remap = GPIO_AF_USART6,
|
||||
.init = {
|
||||
.USART_BaudRate = 115200,
|
||||
.USART_WordLength = USART_WordLength_8b,
|
||||
.USART_Parity = USART_Parity_No,
|
||||
.USART_StopBits = USART_StopBits_1,
|
||||
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||
.USART_Mode = USART_Mode_Rx,
|
||||
},
|
||||
.irq = {
|
||||
.init = {
|
||||
.NVIC_IRQChannel = USART6_IRQn,
|
||||
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||
.NVIC_IRQChannelSubPriority = 0,
|
||||
.NVIC_IRQChannelCmd = ENABLE,
|
||||
},
|
||||
},
|
||||
.rx = {
|
||||
.gpio = GPIOC,
|
||||
.init = {
|
||||
.GPIO_Pin = GPIO_Pin_7,
|
||||
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_IBUS */
|
||||
|
||||
#if defined(PIOS_INCLUDE_EXBUS)
|
||||
|
@ -1109,6 +1109,11 @@ void PIOS_Board_Init(void)
|
||||
case HWSETTINGS_RM_RCVRPORT_PPMGPS:
|
||||
PIOS_Board_configure_com(&pios_usart_rcvrport_cfg, PIOS_COM_GPS_RX_BUF_LEN, PIOS_COM_GPS_TX_BUF_LEN, &pios_usart_com_driver, &pios_com_gps_id);
|
||||
break;
|
||||
case HWSETTINGS_RM_RCVRPORT_IBUS:
|
||||
#if defined(PIOS_INCLUDE_IBUS)
|
||||
PIOS_Board_configure_ibus(&pios_usart_ibus_rcvr_cfg);
|
||||
#endif /* PIOS_INCLUDE_IBUS */
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_GCSRCVR)
|
||||
|
@ -11,9 +11,9 @@
|
||||
<field name="RV_TelemetryPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,ComAux,ComBridge,MSP,MAVLink" defaultvalue="Telemetry"/>
|
||||
<field name="RV_GPSPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,ComAux,ComBridge,MSP,MAVLink" defaultvalue="GPS"/>
|
||||
|
||||
<field name="RM_RcvrPort" units="function" type="enum" elements="1" options="Disabled,PWM,PPM,PPM+PWM,PPM+Outputs,PPM+Telemetry,PPM+DebugConsole,PPM+ComBridge,PPM+MSP,PPM+MAVLink,PPM+GPS,Outputs,Telemetry,DebugConsole,ComBridge,MSP,MAVLink,GPS"
|
||||
<field name="RM_RcvrPort" units="function" type="enum" elements="1" options="Disabled,PWM,PPM,PPM+PWM,PPM+Outputs,PPM+Telemetry,PPM+DebugConsole,PPM+ComBridge,PPM+MSP,PPM+MAVLink,PPM+GPS,Outputs,Telemetry,DebugConsole,ComBridge,MSP,MAVLink,GPS,IBus"
|
||||
defaultvalue="PWM"
|
||||
limits="%0905NE:PPM+PWM:PPM+Telemetry:PPM+DebugConsole:PPM+ComBridge:PPM+MSP:PPM+MAVLink:PPM+GPS:Telemetry:DebugConsole:ComBridge:MSP:MAVLink:GPS;"/>
|
||||
limits="%0905NE:PPM+PWM:PPM+Telemetry:PPM+DebugConsole:PPM+ComBridge:PPM+MSP:PPM+MAVLink:PPM+GPS:Telemetry:DebugConsole:ComBridge:MSP:MAVLink:GPS:IBus;"/>
|
||||
<field name="RM_MainPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,S.Bus,DSM,DebugConsole,ComBridge,OsdHk,MSP,MAVLink" defaultvalue="Disabled"/>
|
||||
<field name="RM_FlexiPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,I2C,DSM,EX.Bus,HoTT SUMD,HoTT SUMH,SRXL,IBus,DebugConsole,ComBridge,OsdHk,MSP,MAVLink" defaultvalue="Disabled"/>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user