mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 17:25:20 +03:00
Merge remote-tracking branch 'multiwii/master' into hott-telemetry
Conflicts: src/drv_softserial.c
This commit is contained in:
commit
171ab22fb7
2 changed files with 25 additions and 31 deletions
|
@ -203,50 +203,44 @@ void updateBufferIndex(softSerial_t *softSerial)
|
||||||
|
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
|
|
||||||
void prepareToSendNextByte(softSerial_t *softSerial)
|
|
||||||
{
|
|
||||||
char byteToSend;
|
|
||||||
|
|
||||||
if ((softSerial->port.mode & MODE_TX) == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSoftSerialTransmitBufferEmpty((serialPort_t *)softSerial)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// choose data to send and update pointer to next byte
|
|
||||||
byteToSend = softSerial->port.txBuffer[softSerial->port.txBufferTail++];
|
|
||||||
if (softSerial->port.txBufferTail >= softSerial->port.txBufferSize) {
|
|
||||||
softSerial->port.txBufferTail = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// build internal buffer, MSB = Stop Bit (1) + data bits (MSB to LSB) + start bit(0) LSB
|
|
||||||
softSerial->internalTxBuffer = (1 << (TX_TOTAL_BITS - 1)) | (byteToSend << 1);
|
|
||||||
softSerial->bitsLeftToTransmit = TX_TOTAL_BITS;
|
|
||||||
softSerial->isTransmittingData = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void processTxState(softSerial_t *softSerial)
|
void processTxState(softSerial_t *softSerial)
|
||||||
{
|
{
|
||||||
uint8_t mask;
|
uint8_t mask;
|
||||||
|
|
||||||
if (softSerial->isTransmittingData) {
|
if (!softSerial->isTransmittingData) {
|
||||||
|
char byteToSend;
|
||||||
|
if (isSoftSerialTransmitBufferEmpty((serialPort_t *)softSerial)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// data to send
|
||||||
|
byteToSend = softSerial->port.txBuffer[softSerial->port.txBufferTail++];
|
||||||
|
if (softSerial->port.txBufferTail >= softSerial->port.txBufferSize) {
|
||||||
|
softSerial->port.txBufferTail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// build internal buffer, MSB = Stop Bit (1) + data bits (MSB to LSB) + start bit(0) LSB
|
||||||
|
softSerial->internalTxBuffer = (1 << (TX_TOTAL_BITS - 1)) | (byteToSend << 1);
|
||||||
|
softSerial->bitsLeftToTransmit = TX_TOTAL_BITS;
|
||||||
|
softSerial->isTransmittingData = true;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (softSerial->bitsLeftToTransmit) {
|
||||||
mask = softSerial->internalTxBuffer & 1;
|
mask = softSerial->internalTxBuffer & 1;
|
||||||
softSerial->internalTxBuffer >>= 1;
|
softSerial->internalTxBuffer >>= 1;
|
||||||
|
|
||||||
setTxSignal(softSerial, mask);
|
setTxSignal(softSerial, mask);
|
||||||
|
softSerial->bitsLeftToTransmit--;
|
||||||
if (--softSerial->bitsLeftToTransmit <= 0) {
|
|
||||||
softSerial->isTransmittingData = false;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareToSendNextByte(softSerial);
|
softSerial->isTransmittingData = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TRAILING,
|
TRAILING,
|
||||||
LEADING
|
LEADING
|
||||||
|
|
|
@ -24,7 +24,7 @@ typedef struct softSerial_s {
|
||||||
uint8_t rxEdge;
|
uint8_t rxEdge;
|
||||||
|
|
||||||
uint8_t isTransmittingData;
|
uint8_t isTransmittingData;
|
||||||
uint8_t bitsLeftToTransmit;
|
int8_t bitsLeftToTransmit;
|
||||||
|
|
||||||
uint16_t internalTxBuffer; // includes start and stop bits
|
uint16_t internalTxBuffer; // includes start and stop bits
|
||||||
uint16_t internalRxBuffer; // includes start and stop bits
|
uint16_t internalRxBuffer; // includes start and stop bits
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue