Merge remote-tracking branch 'multiwii/master'
Conflicts: src/main.c src/mw.h
This commit is contained in:
commit
9014a0a20f
|
@ -139,6 +139,8 @@
|
|||
<RestoreFunctions>0</RestoreFunctions>
|
||||
<RestoreToolbox>1</RestoreToolbox>
|
||||
<RestoreTracepoints>0</RestoreTracepoints>
|
||||
<RestoreTracepoints>1</RestoreTracepoints>
|
||||
<RestoreTracepoints>1</RestoreTracepoints>
|
||||
</Target>
|
||||
<RunDebugAfterBuild>0</RunDebugAfterBuild>
|
||||
<TargetSelection>1</TargetSelection>
|
||||
|
@ -353,6 +355,8 @@
|
|||
<wLevel>2</wLevel>
|
||||
<uThumb>0</uThumb>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<uC99>0</uC99>
|
||||
<useXO>0</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls>--c99 --gnu</MiscControls>
|
||||
<Define>STM32F10X_MD,USE_STDPERIPH_DRIVER</Define>
|
||||
|
@ -369,6 +373,7 @@
|
|||
<SwStkChk>0</SwStkChk>
|
||||
<NoWarn>0</NoWarn>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<useXO>0</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -385,6 +390,7 @@
|
|||
<useFile>0</useFile>
|
||||
<TextAddressRange>0x08000000</TextAddressRange>
|
||||
<DataAddressRange>0x20000000</DataAddressRange>
|
||||
<pXoBase></pXoBase>
|
||||
<ScatterFile></ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
|
@ -579,6 +585,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -625,6 +633,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -726,6 +736,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -742,6 +754,7 @@
|
|||
<SwStkChk>2</SwStkChk>
|
||||
<NoWarn>2</NoWarn>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -843,6 +856,7 @@
|
|||
<SwStkChk>2</SwStkChk>
|
||||
<NoWarn>2</NoWarn>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -1000,6 +1014,8 @@
|
|||
<RestoreFunctions>0</RestoreFunctions>
|
||||
<RestoreToolbox>1</RestoreToolbox>
|
||||
<RestoreTracepoints>0</RestoreTracepoints>
|
||||
<RestoreTracepoints>1</RestoreTracepoints>
|
||||
<RestoreTracepoints>1</RestoreTracepoints>
|
||||
</Target>
|
||||
<RunDebugAfterBuild>0</RunDebugAfterBuild>
|
||||
<TargetSelection>1</TargetSelection>
|
||||
|
@ -1214,6 +1230,8 @@
|
|||
<wLevel>2</wLevel>
|
||||
<uThumb>0</uThumb>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<uC99>0</uC99>
|
||||
<useXO>0</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls>--c99 --gnu</MiscControls>
|
||||
<Define>STM32F10X_MD,USE_STDPERIPH_DRIVER</Define>
|
||||
|
@ -1230,6 +1248,7 @@
|
|||
<SwStkChk>0</SwStkChk>
|
||||
<NoWarn>0</NoWarn>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<useXO>0</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -1246,6 +1265,7 @@
|
|||
<useFile>0</useFile>
|
||||
<TextAddressRange>0x08000000</TextAddressRange>
|
||||
<DataAddressRange>0x20000000</DataAddressRange>
|
||||
<pXoBase></pXoBase>
|
||||
<ScatterFile></ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
|
@ -1440,6 +1460,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -1486,6 +1508,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -1647,6 +1671,7 @@
|
|||
<SwStkChk>2</SwStkChk>
|
||||
<NoWarn>2</NoWarn>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -1804,6 +1829,8 @@
|
|||
<RestoreFunctions>0</RestoreFunctions>
|
||||
<RestoreToolbox>1</RestoreToolbox>
|
||||
<RestoreTracepoints>0</RestoreTracepoints>
|
||||
<RestoreTracepoints>1</RestoreTracepoints>
|
||||
<RestoreTracepoints>1</RestoreTracepoints>
|
||||
</Target>
|
||||
<RunDebugAfterBuild>0</RunDebugAfterBuild>
|
||||
<TargetSelection>1</TargetSelection>
|
||||
|
@ -2018,6 +2045,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>0</uThumb>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<uC99>0</uC99>
|
||||
<useXO>0</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define>STM32F10X_MD,USE_STDPERIPH_DRIVER,FY90Q</Define>
|
||||
|
@ -2034,6 +2063,7 @@
|
|||
<SwStkChk>0</SwStkChk>
|
||||
<NoWarn>0</NoWarn>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<useXO>0</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2050,6 +2080,7 @@
|
|||
<useFile>0</useFile>
|
||||
<TextAddressRange>0x08000000</TextAddressRange>
|
||||
<DataAddressRange>0x20000000</DataAddressRange>
|
||||
<pXoBase></pXoBase>
|
||||
<ScatterFile></ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
|
@ -2189,6 +2220,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2235,6 +2268,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2281,6 +2316,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2327,6 +2364,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2378,6 +2417,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2424,6 +2465,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2480,6 +2523,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2526,6 +2571,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2637,6 +2684,8 @@
|
|||
<wLevel>0</wLevel>
|
||||
<uThumb>2</uThumb>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<uC99>2</uC99>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2653,6 +2702,7 @@
|
|||
<SwStkChk>2</SwStkChk>
|
||||
<NoWarn>2</NoWarn>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
@ -2749,6 +2799,7 @@
|
|||
<SwStkChk>2</SwStkChk>
|
||||
<NoWarn>2</NoWarn>
|
||||
<uSurpInc>2</uSurpInc>
|
||||
<useXO>2</useXO>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
|
|
6717
obj/baseflight.hex
6717
obj/baseflight.hex
File diff suppressed because it is too large
Load Diff
12
src/cli.c
12
src/cli.c
|
@ -125,11 +125,13 @@ const clivalue_t valueTable[] = {
|
|||
{ "retarded_arm", VAR_UINT8, &mcfg.retarded_arm, 0, 1 },
|
||||
{ "flaps_speed", VAR_UINT8, &mcfg.flaps_speed, 0, 100 },
|
||||
{ "fixedwing_althold_dir", VAR_INT8, &mcfg.fixedwing_althold_dir, -1, 1 },
|
||||
{ "reboot_character", VAR_UINT8, &mcfg.reboot_character, 48, 126 },
|
||||
{ "serial_baudrate", VAR_UINT32, &mcfg.serial_baudrate, 1200, 115200 },
|
||||
{ "softserial_baudrate", VAR_UINT32, &mcfg.softserial_baudrate, 9600, 19200 },
|
||||
{ "softserial_inverted", VAR_UINT8, &mcfg.softserial_inverted, 0, 1 },
|
||||
{ "softserial_baudrate", VAR_UINT32, &mcfg.softserial_baudrate, 1200, 19200 },
|
||||
{ "softserial_1_inverted", VAR_UINT8, &mcfg.softserial_1_inverted, 0, 1 },
|
||||
{ "softserial_2_inverted", VAR_UINT8, &mcfg.softserial_2_inverted, 0, 1 },
|
||||
{ "gps_type", VAR_UINT8, &mcfg.gps_type, 0, 3 },
|
||||
{ "gps_baudrate", VAR_INT8, &mcfg.gps_baudrate, -1, 4 },
|
||||
{ "gps_baudrate", VAR_INT8, &mcfg.gps_baudrate, 0, 4 },
|
||||
{ "serialrx_type", VAR_UINT8, &mcfg.serialrx_type, 0, 3 },
|
||||
{ "telemetry_softserial", VAR_UINT8, &mcfg.telemetry_softserial, 0, 1 },
|
||||
{ "telemetry_switch", VAR_UINT8, &mcfg.telemetry_switch, 0, 1 },
|
||||
|
@ -834,12 +836,12 @@ static void cliSave(char *cmdline)
|
|||
static void cliPrint(const char *str)
|
||||
{
|
||||
while (*str)
|
||||
uartWrite(core.mainport, *(str++));
|
||||
serialWrite(core.mainport, *(str++));
|
||||
}
|
||||
|
||||
static void cliWrite(uint8_t ch)
|
||||
{
|
||||
uartWrite(core.mainport, ch);
|
||||
serialWrite(core.mainport, ch);
|
||||
}
|
||||
|
||||
static void cliPrintVar(const clivalue_t *var, uint32_t full)
|
||||
|
|
|
@ -13,7 +13,7 @@ master_t mcfg; // master config struct with data independent from profiles
|
|||
config_t cfg; // profile config struct
|
||||
const char rcChannelLetters[] = "AERT1234";
|
||||
|
||||
static const uint8_t EEPROM_CONF_VERSION = 58;
|
||||
static const uint8_t EEPROM_CONF_VERSION = 60;
|
||||
static uint32_t enabledSensors = 0;
|
||||
static void resetConf(void);
|
||||
|
||||
|
@ -216,7 +216,8 @@ static void resetConf(void)
|
|||
// serial (USART1) baudrate
|
||||
mcfg.serial_baudrate = 115200;
|
||||
mcfg.softserial_baudrate = 19200;
|
||||
mcfg.softserial_inverted = 0;
|
||||
mcfg.softserial_1_inverted = 0;
|
||||
mcfg.softserial_2_inverted = 0;
|
||||
mcfg.looptime = 3500;
|
||||
mcfg.rssi_aux_channel = 0;
|
||||
|
||||
|
@ -307,6 +308,9 @@ static void resetConf(void)
|
|||
cfg.nav_speed_max = 300;
|
||||
cfg.ap_mode = 40;
|
||||
|
||||
// control stuff
|
||||
mcfg.reboot_character = 'R';
|
||||
|
||||
// custom mixer. clear by defaults.
|
||||
for (i = 0; i < MAX_MOTORS; i++)
|
||||
mcfg.customMixer[i].throttle = 0.0f;
|
||||
|
|
|
@ -236,7 +236,7 @@ static pwmPortData_t *pwmInConfig(uint8_t port, timerCCCallbackPtr callback, uin
|
|||
pwmGPIOConfig(timerHardwarePtr->gpio, timerHardwarePtr->pin, Mode_IPD);
|
||||
pwmICConfig(timerHardwarePtr->tim, timerHardwarePtr->channel, TIM_ICPolarity_Rising);
|
||||
|
||||
timerInConfig(timerHardwarePtr, 0xFFFF, PWM_TIMER_MHZ);
|
||||
timerConfigure(timerHardwarePtr, 0xFFFF, PWM_TIMER_MHZ);
|
||||
configureTimerCaptureCompareInterrupt(timerHardwarePtr, port, callback);
|
||||
|
||||
return p;
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
#include "board.h"
|
||||
|
||||
// There needs to be a table of timerMhz per baud rate so the system can set the timer correctly.
|
||||
// See http://www.wormfood.net/avrbaudcalc.php?postbitrate=19200&postclock=72
|
||||
// Currently defaulting to 3Mhz to support 19200.
|
||||
#define SOFT_SERIAL_TIMER_MHZ 3
|
||||
#define SOFT_SERIAL_1_TIMER_RX_HARDWARE 4
|
||||
#define SOFT_SERIAL_1_TIMER_TX_HARDWARE 5
|
||||
#define SOFT_SERIAL_2_TIMER_RX_HARDWARE 6
|
||||
#define SOFT_SERIAL_2_TIMER_TX_HARDWARE 7
|
||||
|
||||
#define RX_TOTAL_BITS 8
|
||||
#define RX_TOTAL_BITS 10
|
||||
#define TX_TOTAL_BITS 10
|
||||
|
||||
#define MAX_SOFTSERIAL_PORTS 2
|
||||
softSerial_t softSerialPorts[MAX_SOFTSERIAL_PORTS];
|
||||
|
||||
|
||||
void onSerialTimer(uint8_t portIndex, uint16_t capture);
|
||||
void onSerialRxPinChange(uint8_t portIndex, uint16_t capture);
|
||||
|
||||
uint8_t readRxSignal(softSerial_t *softSerial)
|
||||
{
|
||||
|
@ -72,13 +73,51 @@ void serialInputPortConfig(const timerHardware_t *timerHardwarePtr)
|
|||
softSerialGPIOConfig(timerHardwarePtr->gpio, timerHardwarePtr->pin, Mode_IPU);
|
||||
}
|
||||
|
||||
#define TICKS_PER_BIT 3
|
||||
|
||||
void serialTimerConfig(const timerHardware_t *timerHardwarePtr, uint32_t baud, uint8_t reference, timerCCCallbackPtr callback)
|
||||
bool isTimerPeriodTooLarge(uint32_t timerPeriod)
|
||||
{
|
||||
uint16_t timerPeriod = (SOFT_SERIAL_TIMER_MHZ * 1000000) / (baud * TICKS_PER_BIT);
|
||||
timerInConfig(timerHardwarePtr, timerPeriod, SOFT_SERIAL_TIMER_MHZ);
|
||||
configureTimerCaptureCompareInterrupt(timerHardwarePtr, reference, callback);
|
||||
return timerPeriod > 0xFFFF;
|
||||
}
|
||||
|
||||
void serialTimerTxConfig(const timerHardware_t *timerHardwarePtr, uint8_t reference, uint32_t baud)
|
||||
{
|
||||
uint32_t clock = SystemCoreClock;
|
||||
uint32_t timerPeriod;
|
||||
do {
|
||||
timerPeriod = clock / baud;
|
||||
if (isTimerPeriodTooLarge(timerPeriod)) {
|
||||
if (clock > 1) {
|
||||
clock = clock / 2;
|
||||
} else {
|
||||
// TODO unable to continue, unable to determine clock and timerPeriods for the given baud
|
||||
}
|
||||
|
||||
}
|
||||
} while (isTimerPeriodTooLarge(timerPeriod));
|
||||
|
||||
uint8_t mhz = SystemCoreClock / 1000000;
|
||||
timerConfigure(timerHardwarePtr, timerPeriod, mhz);
|
||||
configureTimerCaptureCompareInterrupt(timerHardwarePtr, reference, onSerialTimer);
|
||||
}
|
||||
|
||||
void serialICConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t polarity)
|
||||
{
|
||||
TIM_ICInitTypeDef TIM_ICInitStructure;
|
||||
|
||||
TIM_ICStructInit(&TIM_ICInitStructure);
|
||||
TIM_ICInitStructure.TIM_Channel = channel;
|
||||
TIM_ICInitStructure.TIM_ICPolarity = polarity;
|
||||
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
|
||||
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
|
||||
TIM_ICInitStructure.TIM_ICFilter = 0x0;
|
||||
|
||||
TIM_ICInit(tim, &TIM_ICInitStructure);
|
||||
}
|
||||
|
||||
void serialTimerRxConfig(const timerHardware_t *timerHardwarePtr, uint8_t reference)
|
||||
{
|
||||
// start bit is a FALLING signal
|
||||
serialICConfig(timerHardwarePtr->tim, timerHardwarePtr->channel, TIM_ICPolarity_Falling);
|
||||
configureTimerCaptureCompareInterrupt(timerHardwarePtr, reference, onSerialRxPinChange);
|
||||
}
|
||||
|
||||
void serialOutputPortConfig(const timerHardware_t *timerHardwarePtr)
|
||||
|
@ -86,18 +125,10 @@ void serialOutputPortConfig(const timerHardware_t *timerHardwarePtr)
|
|||
softSerialGPIOConfig(timerHardwarePtr->gpio, timerHardwarePtr->pin, Mode_Out_PP);
|
||||
}
|
||||
|
||||
void setupSoftSerial1(uint32_t baud, uint8_t inverted)
|
||||
void initialiseSoftSerial(softSerial_t *softSerial, uint8_t portIndex, uint32_t baud, uint8_t inverted)
|
||||
{
|
||||
int portIndex = 0;
|
||||
softSerial_t *softSerial = &(softSerialPorts[portIndex]);
|
||||
|
||||
softSerial->port.vTable = softSerialVTable;
|
||||
softSerial->port.mode = MODE_RXTX;
|
||||
softSerial->port.baudRate = baud;
|
||||
softSerial->isInverted = inverted;
|
||||
|
||||
softSerial->rxTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_RX_HARDWARE]);
|
||||
softSerial->txTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_TX_HARDWARE]);
|
||||
|
||||
softSerial->port.rxBufferSize = SOFT_SERIAL_BUFFER_SIZE;
|
||||
softSerial->port.rxBuffer = softSerial->rxBuffer;
|
||||
|
@ -110,20 +141,56 @@ void setupSoftSerial1(uint32_t baud, uint8_t inverted)
|
|||
softSerial->port.txBufferHead = 0;
|
||||
|
||||
softSerial->isTransmittingData = false;
|
||||
|
||||
softSerial->isSearchingForStartBit = true;
|
||||
softSerial->isSearchingForStopBit = false;
|
||||
softSerial->rxBitIndex = 0;
|
||||
|
||||
softSerial->timerRxCounter = 1;
|
||||
|
||||
serialInputPortConfig(softSerial->rxTimerHardware);
|
||||
serialOutputPortConfig(softSerial->txTimerHardware);
|
||||
serialInputPortConfig(softSerial->rxTimerHardware);
|
||||
|
||||
setTxSignal(softSerial, 1);
|
||||
setTxSignal(softSerial, ENABLE);
|
||||
delay(50);
|
||||
|
||||
serialTimerConfig(softSerial->rxTimerHardware, baud, portIndex, onSerialTimer);
|
||||
serialTimerTxConfig(softSerial->txTimerHardware, portIndex, baud);
|
||||
serialTimerRxConfig(softSerial->rxTimerHardware, portIndex);
|
||||
}
|
||||
|
||||
typedef struct softSerialConfiguration_s {
|
||||
uint32_t sharedBaudRate;
|
||||
bool primaryPortInitialised;
|
||||
} softSerialConfiguration_t;
|
||||
|
||||
softSerialConfiguration_t softSerialConfiguration = {
|
||||
0,
|
||||
false
|
||||
};
|
||||
|
||||
void setupSoftSerialPrimary(uint32_t baud, uint8_t inverted)
|
||||
{
|
||||
uint8_t portIndex = 0;
|
||||
softSerial_t *softSerial = &(softSerialPorts[portIndex]);
|
||||
|
||||
softSerial->rxTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_RX_HARDWARE]);
|
||||
softSerial->txTimerHardware = &(timerHardware[SOFT_SERIAL_1_TIMER_TX_HARDWARE]);
|
||||
|
||||
initialiseSoftSerial(softSerial, portIndex, baud, inverted);
|
||||
|
||||
softSerialConfiguration.sharedBaudRate = baud;
|
||||
softSerialConfiguration.primaryPortInitialised = true;
|
||||
}
|
||||
|
||||
void setupSoftSerialSecondary(uint8_t inverted)
|
||||
{
|
||||
int portIndex = 1;
|
||||
softSerial_t *softSerial = &(softSerialPorts[portIndex]);
|
||||
|
||||
softSerial->rxTimerHardware = &(timerHardware[SOFT_SERIAL_2_TIMER_RX_HARDWARE]);
|
||||
softSerial->txTimerHardware = &(timerHardware[SOFT_SERIAL_2_TIMER_TX_HARDWARE]);
|
||||
|
||||
initialiseSoftSerial(softSerial, portIndex, softSerialConfiguration.sharedBaudRate, inverted);
|
||||
}
|
||||
|
||||
|
||||
void updateBufferIndex(softSerial_t *softSerial)
|
||||
{
|
||||
if (softSerial->port.rxBufferTail >= softSerial->port.rxBufferSize - 1) {
|
||||
|
@ -135,81 +202,6 @@ void updateBufferIndex(softSerial_t *softSerial)
|
|||
|
||||
/*********************************************/
|
||||
|
||||
void searchForStartBit(softSerial_t *softSerial)
|
||||
{
|
||||
char rxSignal = readRxSignal(softSerial);
|
||||
if (rxSignal == 1) {
|
||||
// start bit not found
|
||||
softSerial->timerRxCounter = 1; // process on next timer event
|
||||
return;
|
||||
}
|
||||
|
||||
// timer is aligned to falling signal of start bit.
|
||||
// three ticks per bit.
|
||||
|
||||
softSerial->isSearchingForStartBit = false;
|
||||
softSerial->internalRxBuffer = 0;
|
||||
softSerial->timerRxCounter = TICKS_PER_BIT + 1; // align to middle of next bit
|
||||
softSerial->bitsLeftToReceive = RX_TOTAL_BITS;
|
||||
softSerial->rxBitSelectionMask = 1;
|
||||
}
|
||||
|
||||
void searchForStopBit(softSerial_t *softSerial)
|
||||
{
|
||||
char rxSignal;
|
||||
softSerial->timerRxCounter = 1;
|
||||
|
||||
rxSignal = readRxSignal(softSerial);
|
||||
if (rxSignal != 1) {
|
||||
// not found
|
||||
return;
|
||||
}
|
||||
|
||||
softSerial->isSearchingForStopBit = false;
|
||||
softSerial->isSearchingForStartBit = true;
|
||||
softSerial->internalRxBuffer &= 0xFF;
|
||||
|
||||
softSerial->port.rxBuffer[softSerial->port.rxBufferTail] = softSerial->internalRxBuffer;
|
||||
updateBufferIndex(softSerial);
|
||||
}
|
||||
|
||||
void readDataBit(softSerial_t *softSerial)
|
||||
{
|
||||
softSerial->timerRxCounter = TICKS_PER_BIT; // keep aligned to middle of bit
|
||||
|
||||
char rxSignal = readRxSignal(softSerial);
|
||||
if (rxSignal) {
|
||||
softSerial->internalRxBuffer |= softSerial->rxBitSelectionMask;
|
||||
}
|
||||
softSerial->rxBitSelectionMask <<= 1;
|
||||
if (--softSerial->bitsLeftToReceive <= 0) {
|
||||
softSerial->isSearchingForStopBit = true;
|
||||
softSerial->timerRxCounter = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void processRxState(softSerial_t *softSerial)
|
||||
{
|
||||
//digitalToggle(softSerial->txTimerHardware->gpio, softSerial->txTimerHardware->pin);
|
||||
|
||||
if (--softSerial->timerRxCounter > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (softSerial->isSearchingForStartBit) {
|
||||
searchForStartBit(softSerial);
|
||||
return;
|
||||
}
|
||||
|
||||
if (softSerial->isSearchingForStopBit) {
|
||||
searchForStopBit(softSerial);
|
||||
return;
|
||||
}
|
||||
|
||||
readDataBit(softSerial);
|
||||
}
|
||||
|
||||
|
||||
void processTxState(softSerial_t *softSerial)
|
||||
{
|
||||
char mask;
|
||||
|
@ -229,26 +221,72 @@ void processTxState(softSerial_t *softSerial)
|
|||
// build internal buffer, start bit(1) + data bits + stop bit(0)
|
||||
softSerial->internalTxBuffer = (1 << (TX_TOTAL_BITS - 1)) | (byteToSend << 1);
|
||||
softSerial->bitsLeftToTransmit = TX_TOTAL_BITS;
|
||||
|
||||
// start immediately
|
||||
softSerial->timerTxCounter = 1;
|
||||
softSerial->isTransmittingData = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (--softSerial->timerTxCounter <= 0) {
|
||||
mask = softSerial->internalTxBuffer & 1;
|
||||
softSerial->internalTxBuffer >>= 1;
|
||||
mask = softSerial->internalTxBuffer & 1;
|
||||
softSerial->internalTxBuffer >>= 1;
|
||||
|
||||
setTxSignal(softSerial, mask);
|
||||
setTxSignal(softSerial, mask);
|
||||
|
||||
softSerial->timerTxCounter = TICKS_PER_BIT;
|
||||
if (--softSerial->bitsLeftToTransmit <= 0) {
|
||||
softSerial->isTransmittingData = false;
|
||||
if (--softSerial->bitsLeftToTransmit <= 0) {
|
||||
softSerial->isTransmittingData = false;
|
||||
}
|
||||
}
|
||||
|
||||
enum {
|
||||
FALLING,
|
||||
RISING
|
||||
};
|
||||
|
||||
void applyChangedBits(softSerial_t *softSerial)
|
||||
{
|
||||
if (softSerial->rxPinMode == FALLING) {
|
||||
uint8_t bitToSet;
|
||||
for (bitToSet = softSerial->rxLastRiseAtBitIndex; bitToSet < softSerial->rxBitIndex ; bitToSet++) {
|
||||
softSerial->internalRxBuffer |= 1 << bitToSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void prepareForNextRxByte(softSerial_t *softSerial)
|
||||
{
|
||||
// prepare for next byte
|
||||
softSerial->rxBitIndex = 0;
|
||||
softSerial->isSearchingForStartBit = true;
|
||||
if (softSerial->rxPinMode == RISING) {
|
||||
softSerial->rxPinMode = FALLING;
|
||||
serialICConfig(softSerial->rxTimerHardware->tim, softSerial->rxTimerHardware->channel, TIM_ICPolarity_Falling);
|
||||
}
|
||||
}
|
||||
|
||||
void extractAndStoreRxByte(softSerial_t *softSerial)
|
||||
{
|
||||
uint8_t rxByte = (softSerial->internalRxBuffer >> 1) & 0xFF;
|
||||
softSerial->port.rxBuffer[softSerial->port.rxBufferTail] = rxByte;
|
||||
updateBufferIndex(softSerial);
|
||||
}
|
||||
|
||||
void processRxState(softSerial_t *softSerial)
|
||||
{
|
||||
if (softSerial->isSearchingForStartBit) {
|
||||
return;
|
||||
}
|
||||
|
||||
softSerial->rxBitIndex++;
|
||||
|
||||
if (softSerial->rxBitIndex == RX_TOTAL_BITS - 1) {
|
||||
applyChangedBits(softSerial);
|
||||
return;
|
||||
}
|
||||
|
||||
if (softSerial->rxBitIndex == RX_TOTAL_BITS) {
|
||||
extractAndStoreRxByte(softSerial);
|
||||
prepareForNextRxByte(softSerial);
|
||||
}
|
||||
}
|
||||
|
||||
void onSerialTimer(uint8_t portIndex, uint16_t capture)
|
||||
{
|
||||
softSerial_t *softSerial = &(softSerialPorts[portIndex]);
|
||||
|
@ -257,6 +295,36 @@ void onSerialTimer(uint8_t portIndex, uint16_t capture)
|
|||
processRxState(softSerial);
|
||||
}
|
||||
|
||||
void onSerialRxPinChange(uint8_t portIndex, uint16_t capture)
|
||||
{
|
||||
softSerial_t *softSerial = &(softSerialPorts[portIndex]);
|
||||
|
||||
if (softSerial->isSearchingForStartBit) {
|
||||
TIM_SetCounter(softSerial->rxTimerHardware->tim, 0); // synchronise bit counter
|
||||
serialICConfig(softSerial->rxTimerHardware->tim, softSerial->rxTimerHardware->channel, TIM_ICPolarity_Rising);
|
||||
softSerial->rxPinMode = RISING;
|
||||
|
||||
softSerial->rxBitIndex = 0;
|
||||
softSerial->rxLastRiseAtBitIndex = 0;
|
||||
softSerial->internalRxBuffer = 0;
|
||||
softSerial->isSearchingForStartBit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (softSerial->rxPinMode == RISING) {
|
||||
softSerial->rxLastRiseAtBitIndex = softSerial->rxBitIndex;
|
||||
}
|
||||
|
||||
applyChangedBits(softSerial);
|
||||
|
||||
if (softSerial->rxPinMode == FALLING) {
|
||||
softSerial->rxPinMode = RISING;
|
||||
serialICConfig(softSerial->rxTimerHardware->tim, softSerial->rxTimerHardware->channel, TIM_ICPolarity_Rising);
|
||||
} else {
|
||||
softSerial->rxPinMode = FALLING;
|
||||
serialICConfig(softSerial->rxTimerHardware->tim, softSerial->rxTimerHardware->channel, TIM_ICPolarity_Falling);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t softSerialTotalBytesWaiting(serialPort_t *instance)
|
||||
{
|
||||
|
|
|
@ -18,16 +18,16 @@ typedef struct softSerial_s {
|
|||
const timerHardware_t *txTimerHardware;
|
||||
volatile uint8_t txBuffer[SOFT_SERIAL_BUFFER_SIZE];
|
||||
|
||||
uint8_t isSearchingForStopBit;
|
||||
uint8_t rxBitSelectionMask;
|
||||
uint8_t isSearchingForStartBit;
|
||||
uint8_t rxBitIndex;
|
||||
uint8_t rxLastRiseAtBitIndex;
|
||||
uint8_t rxPinMode;
|
||||
|
||||
uint8_t isTransmittingData;
|
||||
uint8_t timerRxCounter;
|
||||
uint8_t timerTxCounter;
|
||||
uint8_t bitsLeftToReceive;
|
||||
uint8_t bitsLeftToTransmit;
|
||||
uint16_t internalRxBuffer; // excluding start/stop bits
|
||||
|
||||
uint16_t internalTxBuffer; // includes start and stop bits
|
||||
uint16_t internalRxBuffer; // includes start and stop bits
|
||||
|
||||
uint8_t isInverted;
|
||||
} softSerial_t;
|
||||
|
@ -37,7 +37,8 @@ extern softSerial_t softSerialPorts[];
|
|||
|
||||
extern const struct serialPortVTable softSerialVTable[];
|
||||
|
||||
void setupSoftSerial1(uint32_t baud, uint8_t inverted);
|
||||
void setupSoftSerialPrimary(uint32_t baud, uint8_t inverted);
|
||||
void setupSoftSerialSecondary(uint8_t inverted);
|
||||
|
||||
// serialPort API
|
||||
void softSerialWriteByte(serialPort_t *instance, uint8_t ch);
|
||||
|
|
|
@ -134,7 +134,7 @@ void configureTimerCaptureCompareInterrupt(const timerHardware_t *timerHardwareP
|
|||
configureTimerInputCaptureCompareChannel(timerHardwarePtr->tim, timerHardwarePtr->channel);
|
||||
}
|
||||
|
||||
void timerNVICConfig(uint8_t irq)
|
||||
void timerNVICConfigure(uint8_t irq)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
|
@ -145,23 +145,28 @@ void timerNVICConfig(uint8_t irq)
|
|||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
void configTimeBase(TIM_TypeDef *tim, uint32_t period, uint8_t mhz)
|
||||
void configTimeBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz)
|
||||
{
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||||
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = period - 1;
|
||||
TIM_TimeBaseStructure.TIM_Period = period - 1; // AKA TIMx_ARR
|
||||
|
||||
// "The counter clock frequency (CK_CNT) is equal to f CK_PSC / (PSC[15:0] + 1)." - STM32F10x Reference Manual 14.4.11
|
||||
// Thus for 1Mhz: 72000000 / 1000000 = 72, 72 - 1 = 71 = TIM_Prescaler
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / ((uint32_t)mhz * 1000000)) - 1;
|
||||
|
||||
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure);
|
||||
}
|
||||
|
||||
void timerInConfig(const timerHardware_t *timerHardwarePtr, uint32_t period, uint8_t mhz)
|
||||
void timerConfigure(const timerHardware_t *timerHardwarePtr, uint16_t period, uint8_t mhz)
|
||||
{
|
||||
configTimeBase(timerHardwarePtr->tim, period, mhz);
|
||||
TIM_Cmd(timerHardwarePtr->tim, ENABLE);
|
||||
timerNVICConfig(timerHardwarePtr->irq);
|
||||
timerNVICConfigure(timerHardwarePtr->irq);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ typedef struct {
|
|||
|
||||
extern const timerHardware_t timerHardware[];
|
||||
|
||||
void configTimeBase(TIM_TypeDef *tim, uint32_t period, uint8_t mhz);
|
||||
void timerInConfig(const timerHardware_t *timerHardwarePtr, uint32_t period, uint8_t mhz);
|
||||
void timerNVICConfig(uint8_t irq);
|
||||
void configTimeBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz);
|
||||
void timerConfigure(const timerHardware_t *timerHardwarePtr, uint16_t period, uint8_t mhz);
|
||||
void timerNVICConfigure(uint8_t irq);
|
||||
|
||||
void configureTimerInputCaptureCompareChannel(TIM_TypeDef *tim, const uint8_t channel);
|
||||
void configureTimerCaptureCompareInterrupt(const timerHardware_t *timerHardwarePtr, uint8_t reference, timerCCCallbackPtr *callback);
|
||||
|
|
39
src/main.c
39
src/main.c
|
@ -31,9 +31,9 @@ int main(void)
|
|||
drv_pwm_config_t pwm_params;
|
||||
drv_adc_config_t adc_params;
|
||||
#ifdef SOFTSERIAL_LOOPBACK
|
||||
serialPort_t* loopbackPort = NULL;
|
||||
serialPort_t* loopbackPort1 = NULL;
|
||||
serialPort_t* loopbackPort2 = NULL;
|
||||
#endif
|
||||
|
||||
systemInit();
|
||||
#ifdef USE_LAME_PRINTF
|
||||
init_printf(NULL, _putc);
|
||||
|
@ -113,9 +113,6 @@ int main(void)
|
|||
} else { // spektrum and GPS are mutually exclusive
|
||||
// Optional GPS - available in both PPM and PWM input mode, in PWM input, reduces number of available channels by 2.
|
||||
// gpsInit will return if FEATURE_GPS is not enabled.
|
||||
// Sanity check below - protocols other than NMEA do not support baud rate autodetection
|
||||
if (mcfg.gps_type > 0 && mcfg.gps_baudrate < 0)
|
||||
mcfg.gps_baudrate = 0;
|
||||
gpsInit(mcfg.gps_baudrate);
|
||||
}
|
||||
#ifdef SONAR
|
||||
|
@ -150,11 +147,19 @@ int main(void)
|
|||
serialInit(mcfg.serial_baudrate);
|
||||
|
||||
if (feature(FEATURE_SOFTSERIAL)) {
|
||||
setupSoftSerial1(mcfg.softserial_baudrate, mcfg.softserial_inverted);
|
||||
//mcfg.softserial_baudrate = 19200; // Uncomment to override config value
|
||||
|
||||
setupSoftSerialPrimary(mcfg.softserial_baudrate, mcfg.softserial_1_inverted);
|
||||
setupSoftSerialSecondary(mcfg.softserial_2_inverted);
|
||||
|
||||
#ifdef SOFTSERIAL_LOOPBACK
|
||||
loopbackPort = (serialPort_t*)&(softSerialPorts[0]);
|
||||
serialPrint(loopbackPort, "LOOPBACK ENABLED\r\n");
|
||||
loopbackPort1 = (serialPort_t*)&(softSerialPorts[0]);
|
||||
serialPrint(loopbackPort1, "SOFTSERIAL 1 - LOOPBACK ENABLED\r\n");
|
||||
|
||||
loopbackPort2 = (serialPort_t*)&(softSerialPorts[1]);
|
||||
serialPrint(loopbackPort2, "SOFTSERIAL 2 - LOOPBACK ENABLED\r\n");
|
||||
#endif
|
||||
//core.mainport = (serialPort_t*)&(softSerialPorts[0]); // Uncomment to switch the main port to use softserial.
|
||||
}
|
||||
|
||||
if (feature(FEATURE_TELEMETRY))
|
||||
|
@ -171,11 +176,19 @@ int main(void)
|
|||
while (1) {
|
||||
loop();
|
||||
#ifdef SOFTSERIAL_LOOPBACK
|
||||
if (loopbackPort) {
|
||||
while (serialTotalBytesWaiting(loopbackPort)) {
|
||||
|
||||
uint8_t b = serialRead(loopbackPort);
|
||||
serialWrite(loopbackPort, b);
|
||||
if (loopbackPort1) {
|
||||
while (serialTotalBytesWaiting(loopbackPort1)) {
|
||||
uint8_t b = serialRead(loopbackPort1);
|
||||
serialWrite(loopbackPort1, b);
|
||||
//serialWrite(core.mainport, 0x01);
|
||||
//serialWrite(core.mainport, b);
|
||||
};
|
||||
}
|
||||
if (loopbackPort2) {
|
||||
while (serialTotalBytesWaiting(loopbackPort2)) {
|
||||
uint8_t b = serialRead(loopbackPort2);
|
||||
serialWrite(loopbackPort1, b);
|
||||
//serialWrite(core.mainport, 0x02);
|
||||
//serialWrite(core.mainport, b);
|
||||
};
|
||||
}
|
||||
|
|
8
src/mw.h
8
src/mw.h
|
@ -272,17 +272,19 @@ typedef struct master_t {
|
|||
|
||||
// gps-related stuff
|
||||
uint8_t gps_type; // Type of GPS hardware. 0: NMEA 1: UBX 2: MTK NMEA 3: MTK Binary
|
||||
int8_t gps_baudrate; // GPS baudrate, -1: autodetect (NMEA only), 0: 115200, 1: 57600, 2: 38400, 3: 19200, 4: 9600
|
||||
int8_t gps_baudrate; // GPS baudrate, 0: 115200, 1: 57600, 2: 38400, 3: 19200, 4: 9600. NMEA will cycle through these until valid data is received
|
||||
|
||||
uint32_t serial_baudrate;
|
||||
|
||||
uint32_t softserial_baudrate;
|
||||
uint8_t softserial_inverted; // use inverted softserial input and output signals
|
||||
uint32_t softserial_baudrate; // shared by both soft serial ports
|
||||
uint8_t softserial_1_inverted; // use inverted softserial input and output signals on port 1
|
||||
uint8_t softserial_2_inverted; // use inverted softserial input and output signals on port 2
|
||||
|
||||
uint8_t telemetry_softserial; // Serial to use for Telemetry. 0:USART1, 1:SoftSerial1 (Enable FEATURE_SOFTSERIAL first)
|
||||
uint8_t telemetry_switch; // Use aux channel to change serial output & baudrate( MSP / Telemetry ). It disables automatic switching to Telemetry when armed.
|
||||
config_t profile[3]; // 3 separate profiles
|
||||
uint8_t current_profile; // currently loaded profile
|
||||
uint8_t reboot_character; // which byte is used to reboot. Default 'R', could be changed carefully to something else.
|
||||
|
||||
uint8_t magic_ef; // magic number, should be 0xEF
|
||||
uint8_t chk; // XOR checksum
|
||||
|
|
|
@ -22,7 +22,7 @@ void sbusInit(rcReadRawDataPtr *callback)
|
|||
int b;
|
||||
for (b = 0; b < SBUS_MAX_CHANNEL; b ++)
|
||||
sbusChannelData[b] = 2 * (mcfg.midrc - SBUS_OFFSET);
|
||||
core.rcvrport = uartOpen(USART2, sbusDataReceive, 100000, MODE_RX | MODE_SBUS);
|
||||
core.rcvrport = uartOpen(USART2, sbusDataReceive, 100000, (portMode_t)(MODE_RX | MODE_SBUS));
|
||||
if (callback)
|
||||
*callback = sbusReadRawRC;
|
||||
core.numRCChannels = SBUS_MAX_CHANNEL;
|
||||
|
|
12
src/serial.c
12
src/serial.c
|
@ -632,14 +632,10 @@ static void evaluateCommand(void)
|
|||
// evaluate all other incoming serial data
|
||||
static void evaluateOtherData(uint8_t sr)
|
||||
{
|
||||
switch (sr) {
|
||||
case '#':
|
||||
cliProcess();
|
||||
break;
|
||||
case 'R':
|
||||
systemReset(true); // reboot to bootloader
|
||||
break;
|
||||
}
|
||||
if (sr == '#')
|
||||
cliProcess();
|
||||
else if (sr == mcfg.reboot_character)
|
||||
systemReset(true); // reboot to bootloader
|
||||
}
|
||||
|
||||
void serialCom(void)
|
||||
|
|
Loading…
Reference in New Issue