mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 01:35:41 +03:00
INVERTED (S.PORT) working
This commit is contained in:
parent
9754e0d67b
commit
011dd6ff20
1 changed files with 35 additions and 68 deletions
|
@ -15,6 +15,11 @@
|
||||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cleanflight (or Baseflight): original
|
||||||
|
* jflyper: Mono-timer and single-wire half-duplex
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -108,67 +113,28 @@ static void setTxSignal(softSerial_t *softSerial, uint8_t state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// @ledvinap suggested the use of TIM_CCxCmd.
|
|
||||||
// XXX CCEnableBit: Compute CCxE bit.
|
|
||||||
// XXX (Note: timer.c:timerChICPolarity() uses "TIM_CCER_CC1P << timHw->channel".)
|
|
||||||
|
|
||||||
static uint32_t CCEnableBit(int channel)
|
|
||||||
{
|
|
||||||
uint32_t bit;
|
|
||||||
|
|
||||||
#if defined(STM32F7)
|
|
||||||
switch (channel) {
|
|
||||||
case TIM_CHANNEL_1:
|
|
||||||
bit = TIM_CCER_CC1E;
|
|
||||||
break;
|
|
||||||
case TIM_CHANNEL_2:
|
|
||||||
bit = TIM_CCER_CC2E;
|
|
||||||
break;
|
|
||||||
case TIM_CHANNEL_3:
|
|
||||||
bit = TIM_CCER_CC3E;
|
|
||||||
break;
|
|
||||||
case TIM_CHANNEL_4:
|
|
||||||
bit = TIM_CCER_CC4E;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
switch (channel) {
|
|
||||||
case TIM_Channel_1:
|
|
||||||
bit = TIM_CCER_CC1E;
|
|
||||||
break;
|
|
||||||
case TIM_Channel_2:
|
|
||||||
bit = TIM_CCER_CC2E;
|
|
||||||
break;
|
|
||||||
case TIM_Channel_3:
|
|
||||||
bit = TIM_CCER_CC3E;
|
|
||||||
break;
|
|
||||||
case TIM_Channel_4:
|
|
||||||
bit = TIM_CCER_CC4E;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return bit;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void serialInputPortActivate(softSerial_t *softSerial)
|
static void serialInputPortActivate(softSerial_t *softSerial)
|
||||||
{
|
{
|
||||||
softSerial->rxActive = true;
|
if (softSerial->port.options & SERIAL_INVERTED) {
|
||||||
#ifdef STM32F1
|
#ifdef STM32F1
|
||||||
IOConfigGPIO(softSerial->rxIO, IOCFG_IPU);
|
IOConfigGPIO(softSerial->rxIO, IOCFG_IPD);
|
||||||
#else
|
#else
|
||||||
IOConfigGPIO(softSerial->rxIO, IOCFG_AF_PP_UP);
|
IOConfigGPIO(softSerial->rxIO, IOCFG_AF_PP_PD);
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifdef STM32F1
|
||||||
|
IOConfigGPIO(softSerial->rxIO, IOCFG_IPU);
|
||||||
|
#else
|
||||||
|
IOConfigGPIO(softSerial->rxIO, IOCFG_AF_PP_UP);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
softSerial->rxActive = true;
|
||||||
softSerial->isSearchingForStartBit = true;
|
softSerial->isSearchingForStartBit = true;
|
||||||
softSerial->rxBitIndex = 0;
|
softSerial->rxBitIndex = 0;
|
||||||
|
|
||||||
// Enable input capture
|
// Enable input capture
|
||||||
|
|
||||||
// @ledvinap suggested the use of TIM_CCxCmd.
|
|
||||||
//softSerial->timerHardware->tim->CCER |= softSerial->ccEnableBit;
|
|
||||||
TIM_CCxCmd(softSerial->timerHardware->tim, softSerial->timerHardware->channel, TIM_CCx_Enable);
|
TIM_CCxCmd(softSerial->timerHardware->tim, softSerial->timerHardware->channel, TIM_CCx_Enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +142,6 @@ static void serialInputPortDeActivate(softSerial_t *softSerial)
|
||||||
{
|
{
|
||||||
// Disable input capture
|
// Disable input capture
|
||||||
|
|
||||||
// @ledvinap suggested the use of TIM_CCxCmd.
|
|
||||||
//softSerial->timerHardware->tim->CCER &= ~softSerial->ccEnableBit;
|
|
||||||
TIM_CCxCmd(softSerial->timerHardware->tim, softSerial->timerHardware->channel, TIM_CCx_Disable);
|
TIM_CCxCmd(softSerial->timerHardware->tim, softSerial->timerHardware->channel, TIM_CCx_Disable);
|
||||||
|
|
||||||
IOConfigGPIO(softSerial->rxIO, IOCFG_IN_FLOATING);
|
IOConfigGPIO(softSerial->rxIO, IOCFG_IN_FLOATING);
|
||||||
|
@ -222,6 +186,10 @@ static void serialTimerConfigureTimebase(const timerHardware_t *timerHardwarePtr
|
||||||
timerConfigure(timerHardwarePtr, timerPeriod, mhz);
|
timerConfigure(timerHardwarePtr, timerPeriod, mhz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// XXX This is almost identical to timerChConfigIC.
|
||||||
|
// XXX Expensive? Direct register manipulation?
|
||||||
|
|
||||||
static void serialICConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t polarity)
|
static void serialICConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t polarity)
|
||||||
{
|
{
|
||||||
TIM_ICInitTypeDef TIM_ICInitStructure;
|
TIM_ICInitTypeDef TIM_ICInitStructure;
|
||||||
|
@ -297,10 +265,6 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//softSerial->ccEnableBit = CCEnableBit(softSerial->timerHardware->channel);
|
|
||||||
|
|
||||||
//debug[2] = softSerial->ccEnableBit;
|
|
||||||
|
|
||||||
softSerial->port.vTable = &softSerialVTable;
|
softSerial->port.vTable = &softSerialVTable;
|
||||||
softSerial->port.baudRate = baud;
|
softSerial->port.baudRate = baud;
|
||||||
softSerial->port.mode = mode;
|
softSerial->port.mode = mode;
|
||||||
|
@ -351,11 +315,10 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb
|
||||||
return &softSerial->port;
|
return &softSerial->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Serial engines
|
* Serial Engine
|
||||||
//
|
*/
|
||||||
|
|
||||||
void processTxState(softSerial_t *softSerial)
|
void processTxState(softSerial_t *softSerial)
|
||||||
{
|
{
|
||||||
|
@ -486,7 +449,6 @@ void processRxState(softSerial_t *softSerial)
|
||||||
void onSerialTimerOverflow(timerOvrHandlerRec_t *cbRec, captureCompare_t capture)
|
void onSerialTimerOverflow(timerOvrHandlerRec_t *cbRec, captureCompare_t capture)
|
||||||
{
|
{
|
||||||
UNUSED(capture);
|
UNUSED(capture);
|
||||||
//debug[0]++;
|
|
||||||
|
|
||||||
softSerial_t *self = container_of(cbRec, softSerial_t, overCb);
|
softSerial_t *self = container_of(cbRec, softSerial_t, overCb);
|
||||||
|
|
||||||
|
@ -500,7 +462,6 @@ void onSerialTimerOverflow(timerOvrHandlerRec_t *cbRec, captureCompare_t capture
|
||||||
void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture)
|
void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture)
|
||||||
{
|
{
|
||||||
UNUSED(capture);
|
UNUSED(capture);
|
||||||
//debug[1]++;
|
|
||||||
|
|
||||||
softSerial_t *self = container_of(cbRec, softSerial_t, edgeCb);
|
softSerial_t *self = container_of(cbRec, softSerial_t, edgeCb);
|
||||||
bool inverted = self->port.options & SERIAL_INVERTED;
|
bool inverted = self->port.options & SERIAL_INVERTED;
|
||||||
|
@ -510,10 +471,15 @@ void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->isSearchingForStartBit) {
|
if (self->isSearchingForStartBit) {
|
||||||
// synchronise bit counter
|
// Synchronize the bit timing so that it will interrupt at the center
|
||||||
// FIXME this reduces functionality somewhat as receiving breaks concurrent transmission on all ports because
|
// of the bit period.
|
||||||
// the next callback to the onSerialTimer will happen too early causing transmission errors.
|
|
||||||
TIM_SetCounter(self->timerHardware->tim, self->timerHardware->tim->ARR / 2);
|
TIM_SetCounter(self->timerHardware->tim, self->timerHardware->tim->ARR / 2);
|
||||||
|
// For a mono-timer full duplex configuration, this may clobber the
|
||||||
|
// transmission because the next callback to the onSerialTimerOverflow
|
||||||
|
// will happen too early causing transmission errors.
|
||||||
|
// For a dual-timer configuration, there is no problem.
|
||||||
|
|
||||||
if ((self->timerMode != TIMER_MODE_DUAL) && self->isTransmittingData) {
|
if ((self->timerMode != TIMER_MODE_DUAL) && self->isTransmittingData) {
|
||||||
self->transmissionErrors++;
|
self->transmissionErrors++;
|
||||||
}
|
}
|
||||||
|
@ -543,9 +509,10 @@ void onSerialRxPinChange(timerCCHandlerRec_t *cbRec, captureCompare_t capture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Standard serial driver API
|
/*
|
||||||
//
|
* Standard serial driver API
|
||||||
|
*/
|
||||||
|
|
||||||
uint32_t softSerialRxBytesWaiting(const serialPort_t *instance)
|
uint32_t softSerialRxBytesWaiting(const serialPort_t *instance)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue