1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-21 07:15:18 +03:00

1wire-pass-through-vcp

also changed uart 1wire-pass-through to avoid need of FC reboot after
exit.
This commit is contained in:
4712 2016-04-01 01:58:18 +02:00
parent 9d737474b8
commit 85dc6b59d2
26 changed files with 533 additions and 69 deletions

View file

@ -96,6 +96,9 @@
#ifdef USE_SERIAL_1WIRE
#include "io/serial_1wire.h"
#endif
#ifdef USE_SERIAL_1WIRE_VCP
#include "io/serial_1wire_vcp.h"
#endif
#ifdef USE_ESCSERIAL
#include "drivers/serial_escserial.h"
#endif
@ -1751,61 +1754,105 @@ static bool processInCommand(void)
// switch all motor lines HI
usb1WireInitialize();
// reply the count of ESC found
headSerialReply(1);
headSerialReply(2);
serialize8(escCount);
serialize8(currentPort->port->identifier);
// and come back right afterwards
// rem: App: Wait at least appx. 500 ms for BLHeli to jump into
// bootloader mode before try to connect any ESC
return true;
}
else {
} else if (i < escCount) {
// Check for channel number 0..ESC_COUNT-1
if (i < escCount) {
// because we do not come back after calling usb1WirePassthrough
// proceed with a success reply first
headSerialReply(0);
tailSerialReply();
// flush the transmit buffer
bufWriterFlush(writer);
// wait for all data to send
waitForSerialPortToFinishTransmitting(currentPort->port);
// Start to activate here
// motor 1 => index 0
// because we do not come back after calling usb1WirePassthrough
// proceed with a success reply first
headSerialReply(0);
tailSerialReply();
// flush the transmit buffer
bufWriterFlush(writer);
// wait for all data to send
waitForSerialPortToFinishTransmitting(currentPort->port);
// Start to activate here
// motor 1 => index 0
// search currentPort portIndex
/* next lines seems to be unnecessary, because the currentPort always point to the same mspPorts[portIndex]
uint8_t portIndex;
for (portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
if (currentPort == &mspPorts[portIndex]) {
break;
}
}
*/
mspReleasePortIfAllocated(mspSerialPort); // CloseSerialPort also marks currentPort as UNUSED_PORT
usb1WirePassthrough(i);
// Wait a bit more to let App read the 0 byte and switch baudrate
// 2ms will most likely do the job, but give some grace time
delay(10);
// rebuild/refill currentPort structure, does openSerialPort if marked UNUSED_PORT - used ports are skiped
mspAllocateSerialPorts(&masterConfig.serialConfig);
/* restore currentPort and mspSerialPort
setCurrentPort(&mspPorts[portIndex]); // not needed same index will be restored
*/
// former used MSP uart is active again
// restore MSP_SET_1WIRE as current command for correct headSerialReply(0)
currentPort->cmdMSP = MSP_SET_1WIRE;
} else {
// ESC channel higher than max. allowed
// rem: BLHeliSuite will not support more than 8
headSerialError(0);
// search currentPort portIndex
/* next lines seems to be unnecessary, because the currentPort always point to the same mspPorts[portIndex]
uint8_t portIndex;
for (portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
if (currentPort == &mspPorts[portIndex]) {
break;
}
}
*/
// *mspReleasePortIfAllocated(mspSerialPort); // CloseSerialPort also marks currentPort as UNUSED_PORT
usb1WirePassthrough(i);
// Wait a bit more to let App read the 0 byte and/or switch baudrate
// 2ms will most likely do the job, but give some grace time
delay(10);
// rebuild/refill currentPort structure, does openSerialPort if marked UNUSED_PORT - used ports are skiped
// *mspAllocateSerialPorts(&masterConfig.serialConfig);
/* restore currentPort and mspSerialPort
setCurrentPort(&mspPorts[portIndex]); // not needed same index will be restored
*/
// former used MSP uart is active again
// restore MSP_SET_1WIRE as current command for correct headSerialReply(0)
//currentPort->cmdMSP = MSP_SET_1WIRE;
} else if (i == 0xFE) {
usb1WireDeInitialize();
} else {
// ESC channel higher than max. allowed
headSerialError(0);
}
// proceed as usual with MSP commands
// and wait to switch to next channel
// rem: App needs to call MSP_BOOT to deinitialize Passthrough
break;
#endif
#ifdef USE_SERIAL_1WIRE_VCP
case MSP_SET_1WIRE:
// get channel number
i = read8();
// we do not give any data back, assume channel number is transmitted OK
if (i == 0xFF) {
// 0xFF -> preinitialize the Passthrough
// switch all motor lines HI
usb1WireInitializeVcp();
// reply the count of ESC found
headSerialReply(2);
serialize8(escCount);
serialize8(currentPort->port->identifier);
// and come back right afterwards
// rem: App: Wait at least appx. 500 ms for BLHeli to jump into
// bootloader mode before try to connect any ESC
return true;
} else if (i < escCount) {
// Check for channel number 0..ESC_COUNT-1
// because we do not come back after calling usb1WirePassthrough
// proceed with a success reply first
headSerialReply(0);
tailSerialReply();
// flush the transmit buffer
bufWriterFlush(writer);
// wait for all data to send
waitForSerialPortToFinishTransmitting(currentPort->port);
// Start to activate here
// motor 1 => index 0
usb1WirePassthroughVcp(currentPort, writer, i);
// Wait a bit more to let App switch baudrate
delay(10);
// former used MSP uart is still active
// proceed as usual with MSP commands
// and wait to switch to next channel
// rem: App needs to call MSP_BOOT to deinitialize Passthrough
// rem: App needs to call MSP_SET_1WIRE(0xFE) to deinitialize Passthrough
} else if (i == 0xFE) {
usb1WireDeInitializeVcp();
} else {
// ESC channel higher than max. allowed
headSerialError(0);
}
break;
break;
#endif
#ifdef USE_ESCSERIAL