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:
timecop@gmail.com 2013-10-01 00:25:56 +00:00
parent 28d5927836
commit fa810e907a
1 changed files with 13 additions and 17 deletions

View File

@ -17,7 +17,7 @@ void onSerialTimer(uint8_t portIndex, uint16_t capture);
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)
@ -53,7 +53,7 @@ void startSerialTimer(softSerial_t *softSerial)
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;
@ -121,8 +121,7 @@ void setupSoftSerial1(uint32_t baud)
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
} else {
softSerial->port.rxBufferTail++;
@ -152,9 +151,10 @@ void searchForStartBit(softSerial_t *softSerial)
void searchForStopBit(softSerial_t *softSerial)
{
char rxSignal;
softSerial->timerRxCounter = 1;
char rxSignal = readRxSignal(softSerial);
rxSignal = readRxSignal(softSerial);
if (rxSignal != 1) {
// not found
return;
@ -189,14 +189,13 @@ void processRxState(softSerial_t *softSerial)
if (--softSerial->timerRxCounter > 0) {
return;
}
}
if (softSerial->isSearchingForStartBit) {
searchForStartBit(softSerial);
return;
}
if (softSerial->isSearchingForStopBit) {
searchForStopBit(softSerial);
return;
@ -211,16 +210,15 @@ void processTxState(softSerial_t *softSerial)
char mask;
if (!softSerial->isTransmittingData) {
char byteToSend;
if (isSoftSerialTransmitBufferEmpty((serialPort_t *)softSerial)) {
return;
}
// data to send
char byteToSend = softSerial->port.txBuffer[softSerial->port.txBufferTail++];
byteToSend = softSerial->port.txBuffer[softSerial->port.txBufferTail++];
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)
@ -257,12 +255,12 @@ void onSerialTimer(uint8_t portIndex, uint16_t capture)
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance)
{
int availableBytes;
softSerial_t *softSerial = (softSerial_t *)instance;
if (softSerial->port.rxBufferTail == softSerial->port.rxBufferHead) {
return 0;
}
int availableBytes;
if (softSerial->port.rxBufferTail > softSerial->port.rxBufferHead) {
availableBytes = softSerial->port.rxBufferTail - softSerial->port.rxBufferHead;
} else {
@ -282,11 +280,12 @@ static void moveHeadToNextByte(softSerial_t *softSerial)
uint8_t softSerialReadByte(serialPort_t *instance)
{
char b;
if (softSerialTotalBytesWaiting(instance) == 0) {
return 0;
}
char b = instance->rxBuffer[instance->rxBufferHead];
b = instance->rxBuffer[instance->rxBufferHead];
moveHeadToNextByte((softSerial_t *)instance);
return b;
@ -296,7 +295,6 @@ void softSerialWriteByte(serialPort_t *s, uint8_t ch)
{
s->txBuffer[s->txBufferHead] = ch;
s->txBufferHead = (s->txBufferHead + 1) % s->txBufferSize;
}
void softSerialSetBaudRate(serialPort_t *s, uint32_t baudRate)
@ -309,9 +307,8 @@ bool isSoftSerialTransmitBufferEmpty(serialPort_t *instance)
return instance->txBufferHead == instance->txBufferTail;
}
const struct serialPortVTable softSerialVTable[] = {
{
{
softSerialWriteByte,
softSerialTotalBytesWaiting,
softSerialReadByte,
@ -319,4 +316,3 @@ const struct serialPortVTable softSerialVTable[] = {
isSoftSerialTransmitBufferEmpty
}
};