mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 11:29:58 +03:00
some whitespace and formatting cleanups on the last commit.
also changed GPIO_GetInputDataBit to use proper digitalIn() api git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@424 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
parent
28d5927836
commit
fa810e907a
1 changed files with 13 additions and 17 deletions
|
@ -17,7 +17,7 @@ void onSerialTimer(uint8_t portIndex, uint16_t capture);
|
||||||
|
|
||||||
uint8_t readRxSignal(softSerial_t *softSerial)
|
uint8_t readRxSignal(softSerial_t *softSerial)
|
||||||
{
|
{
|
||||||
return GPIO_ReadInputDataBit(softSerial->rxTimerHardware->gpio, softSerial->rxTimerHardware->pin);
|
return digitalIn(softSerial->rxTimerHardware->gpio, softSerial->rxTimerHardware->pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTxSignal(softSerial_t *softSerial, uint8_t state)
|
void setTxSignal(softSerial_t *softSerial, uint8_t state)
|
||||||
|
@ -53,7 +53,7 @@ void startSerialTimer(softSerial_t *softSerial)
|
||||||
TIM_Cmd(softSerial->rxTimerHardware->tim, ENABLE);
|
TIM_Cmd(softSerial->rxTimerHardware->tim, ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void softSerialGPIOConfig(GPIO_TypeDef *gpio, uint32_t pin, GPIO_Mode mode)
|
static void softSerialGPIOConfig(GPIO_TypeDef *gpio, uint16_t pin, GPIO_Mode mode)
|
||||||
{
|
{
|
||||||
gpio_config_t cfg;
|
gpio_config_t cfg;
|
||||||
|
|
||||||
|
@ -121,8 +121,7 @@ void setupSoftSerial1(uint32_t baud)
|
||||||
|
|
||||||
void updateBufferIndex(softSerial_t *softSerial)
|
void updateBufferIndex(softSerial_t *softSerial)
|
||||||
{
|
{
|
||||||
if (softSerial->port.rxBufferTail >= softSerial->port.rxBufferSize - 1)
|
if (softSerial->port.rxBufferTail >= softSerial->port.rxBufferSize - 1) {
|
||||||
{
|
|
||||||
softSerial->port.rxBufferTail = 0; //cycling the buffer
|
softSerial->port.rxBufferTail = 0; //cycling the buffer
|
||||||
} else {
|
} else {
|
||||||
softSerial->port.rxBufferTail++;
|
softSerial->port.rxBufferTail++;
|
||||||
|
@ -152,9 +151,10 @@ void searchForStartBit(softSerial_t *softSerial)
|
||||||
|
|
||||||
void searchForStopBit(softSerial_t *softSerial)
|
void searchForStopBit(softSerial_t *softSerial)
|
||||||
{
|
{
|
||||||
|
char rxSignal;
|
||||||
softSerial->timerRxCounter = 1;
|
softSerial->timerRxCounter = 1;
|
||||||
|
|
||||||
char rxSignal = readRxSignal(softSerial);
|
rxSignal = readRxSignal(softSerial);
|
||||||
if (rxSignal != 1) {
|
if (rxSignal != 1) {
|
||||||
// not found
|
// not found
|
||||||
return;
|
return;
|
||||||
|
@ -189,14 +189,13 @@ void processRxState(softSerial_t *softSerial)
|
||||||
|
|
||||||
if (--softSerial->timerRxCounter > 0) {
|
if (--softSerial->timerRxCounter > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (softSerial->isSearchingForStartBit) {
|
if (softSerial->isSearchingForStartBit) {
|
||||||
searchForStartBit(softSerial);
|
searchForStartBit(softSerial);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (softSerial->isSearchingForStopBit) {
|
if (softSerial->isSearchingForStopBit) {
|
||||||
searchForStopBit(softSerial);
|
searchForStopBit(softSerial);
|
||||||
return;
|
return;
|
||||||
|
@ -211,16 +210,15 @@ void processTxState(softSerial_t *softSerial)
|
||||||
char mask;
|
char mask;
|
||||||
|
|
||||||
if (!softSerial->isTransmittingData) {
|
if (!softSerial->isTransmittingData) {
|
||||||
|
char byteToSend;
|
||||||
if (isSoftSerialTransmitBufferEmpty((serialPort_t *)softSerial)) {
|
if (isSoftSerialTransmitBufferEmpty((serialPort_t *)softSerial)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// data to send
|
// data to send
|
||||||
|
byteToSend = softSerial->port.txBuffer[softSerial->port.txBufferTail++];
|
||||||
char byteToSend = softSerial->port.txBuffer[softSerial->port.txBufferTail++];
|
|
||||||
if (softSerial->port.txBufferTail >= softSerial->port.txBufferSize) {
|
if (softSerial->port.txBufferTail >= softSerial->port.txBufferSize) {
|
||||||
softSerial->port.txBufferTail = 0;
|
softSerial->port.txBufferTail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// build internal buffer, start bit(1) + data bits + stop bit(0)
|
// build internal buffer, start bit(1) + data bits + stop bit(0)
|
||||||
|
@ -257,12 +255,12 @@ void onSerialTimer(uint8_t portIndex, uint16_t capture)
|
||||||
|
|
||||||
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance)
|
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance)
|
||||||
{
|
{
|
||||||
|
int availableBytes;
|
||||||
softSerial_t *softSerial = (softSerial_t *)instance;
|
softSerial_t *softSerial = (softSerial_t *)instance;
|
||||||
if (softSerial->port.rxBufferTail == softSerial->port.rxBufferHead) {
|
if (softSerial->port.rxBufferTail == softSerial->port.rxBufferHead) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int availableBytes;
|
|
||||||
if (softSerial->port.rxBufferTail > softSerial->port.rxBufferHead) {
|
if (softSerial->port.rxBufferTail > softSerial->port.rxBufferHead) {
|
||||||
availableBytes = softSerial->port.rxBufferTail - softSerial->port.rxBufferHead;
|
availableBytes = softSerial->port.rxBufferTail - softSerial->port.rxBufferHead;
|
||||||
} else {
|
} else {
|
||||||
|
@ -282,11 +280,12 @@ static void moveHeadToNextByte(softSerial_t *softSerial)
|
||||||
|
|
||||||
uint8_t softSerialReadByte(serialPort_t *instance)
|
uint8_t softSerialReadByte(serialPort_t *instance)
|
||||||
{
|
{
|
||||||
|
char b;
|
||||||
if (softSerialTotalBytesWaiting(instance) == 0) {
|
if (softSerialTotalBytesWaiting(instance) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char b = instance->rxBuffer[instance->rxBufferHead];
|
b = instance->rxBuffer[instance->rxBufferHead];
|
||||||
|
|
||||||
moveHeadToNextByte((softSerial_t *)instance);
|
moveHeadToNextByte((softSerial_t *)instance);
|
||||||
return b;
|
return b;
|
||||||
|
@ -296,7 +295,6 @@ void softSerialWriteByte(serialPort_t *s, uint8_t ch)
|
||||||
{
|
{
|
||||||
s->txBuffer[s->txBufferHead] = ch;
|
s->txBuffer[s->txBufferHead] = ch;
|
||||||
s->txBufferHead = (s->txBufferHead + 1) % s->txBufferSize;
|
s->txBufferHead = (s->txBufferHead + 1) % s->txBufferSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void softSerialSetBaudRate(serialPort_t *s, uint32_t baudRate)
|
void softSerialSetBaudRate(serialPort_t *s, uint32_t baudRate)
|
||||||
|
@ -309,9 +307,8 @@ bool isSoftSerialTransmitBufferEmpty(serialPort_t *instance)
|
||||||
return instance->txBufferHead == instance->txBufferTail;
|
return instance->txBufferHead == instance->txBufferTail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const struct serialPortVTable softSerialVTable[] = {
|
const struct serialPortVTable softSerialVTable[] = {
|
||||||
{
|
{
|
||||||
softSerialWriteByte,
|
softSerialWriteByte,
|
||||||
softSerialTotalBytesWaiting,
|
softSerialTotalBytesWaiting,
|
||||||
softSerialReadByte,
|
softSerialReadByte,
|
||||||
|
@ -319,4 +316,3 @@ const struct serialPortVTable softSerialVTable[] = {
|
||||||
isSoftSerialTransmitBufferEmpty
|
isSoftSerialTransmitBufferEmpty
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue