Browse Source
synced code with multiwii 2.0 release
synced code with multiwii 2.0 release
split uart2 initialization inside drv_uart. added receive data callback to use either with GPS or spektrum satellite added spektrum satellite support, also freeing up 4 motor outputs for hexa/octo/camstab configurable acc lpf and gyro lpf via cli configurable (build-time) temperature lpf on baro. seems mostly useless. fixed a nice boner bug in mag code which ended up multiplying magADC twice with magCal data. fixed mpu3050 driver to allow configurable lpf, also broke other stuff in the process. considering moving this sort of stuff to "init" struct for sensor. pwm driver rewritten to fully disable pwm/ppm inputs (such as using spektrum satellite case) cleaned up double math in gps.c to use sinf/cosf etc removed TRUSTED_ACCZ since its useless anyway whitespace cleanup git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@130 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61master
timecop
13 years ago
23 changed files with 2884 additions and 2931 deletions
-
132baseflight.uvopt
-
10baseflight.uvproj
-
4958obj/baseflight.hex
-
11src/board.h
-
24src/cli.c
-
6src/config.c
-
6src/drv_adxl345.c
-
14src/drv_bmp085.c
-
21src/drv_hmc5883l.c
-
31src/drv_mpu3050.c
-
1src/drv_mpu3050.h
-
126src/drv_pwm.c
-
2src/drv_pwm.h
-
60src/drv_uart.c
-
1src/drv_uart.h
-
57src/gps.c
-
93src/imu.c
-
22src/main.c
-
8src/mixer.c
-
101src/mw.c
-
11src/mw.h
-
30src/sensors.c
-
90src/spektrum.c
4958
obj/baseflight.hex
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,3 +1,4 @@ |
|||
#pragma once |
|||
|
|||
bool mpu3050Detect(sensor_t *gyro); |
|||
void mpu3050Config(uint16_t lpf); |
@ -1,6 +1,6 @@ |
|||
#pragma once |
|||
|
|||
bool pwmInit(bool usePPM, bool useServos, bool useDigitalServos); // returns whether driver is asking to calibrate throttle or not |
|||
bool pwmInit(bool usePPM, bool pwmppmInput, bool useServos, bool useDigitalServos); // returns whether driver is asking to calibrate throttle or not |
|||
void pwmWrite(uint8_t channel, uint16_t value); |
|||
uint16_t pwmRead(uint8_t channel); |
|||
uint8_t pwmGetNumOutputChannels(void); |
@ -0,0 +1,90 @@ |
|||
#include "board.h" |
|||
#include "mw.h" |
|||
|
|||
// driver for spektrum satellite receiver / sbus using UART2 (freeing up more motor outputs for stuff) |
|||
|
|||
#define SPEK_MAX_CHANNEL 7 |
|||
#define SPEK_FRAME_SIZE 16 |
|||
static uint8_t spek_chan_shift; |
|||
static uint8_t spek_chan_mask; |
|||
static bool rcFrameComplete = false; |
|||
static bool spekDataIncoming = false; |
|||
volatile uint8_t spekFrame[SPEK_FRAME_SIZE]; |
|||
|
|||
static void spektrumDataReceive(uint16_t c); |
|||
|
|||
void spektrumInit(void) |
|||
{ |
|||
if (cfg.spektrum_hires) { |
|||
// 11 bit frames |
|||
spek_chan_shift = 3; |
|||
spek_chan_mask = 0x07; |
|||
} else { |
|||
// 10 bit frames |
|||
spek_chan_shift = 2; |
|||
spek_chan_mask = 0x03; |
|||
} |
|||
|
|||
uart2Init(115200, spektrumDataReceive); |
|||
} |
|||
|
|||
// UART2 Receive ISR callback |
|||
static void spektrumDataReceive(uint16_t c) |
|||
{ |
|||
uint32_t spekTime; |
|||
static uint32_t spekTimeLast, spekTimeInterval; |
|||
static uint8_t spekFramePosition; |
|||
|
|||
spekDataIncoming = true; |
|||
spekTime = micros(); |
|||
spekTimeInterval = spekTime - spekTimeLast; |
|||
spekTimeLast = spekTime; |
|||
if (spekTimeInterval > 5000) |
|||
spekFramePosition = 0; |
|||
spekFrame[spekFramePosition] = (uint8_t)c; |
|||
if (spekFramePosition == SPEK_FRAME_SIZE - 1) { |
|||
rcFrameComplete = true; |
|||
#if defined(FAILSAFE) |
|||
if(failsafeCnt > 20) |
|||
failsafeCnt -= 20; |
|||
else |
|||
failsafeCnt = 0; // clear FailSafe counter |
|||
#endif |
|||
} else { |
|||
spekFramePosition++; |
|||
} |
|||
} |
|||
|
|||
bool spektrumFrameComplete(void) |
|||
{ |
|||
return rcFrameComplete; |
|||
} |
|||
|
|||
static const uint8_t spekRcChannelMap[SPEK_MAX_CHANNEL] = {1, 2, 3, 0, 4, 5, 6}; |
|||
|
|||
uint16_t spektrumReadRawRC(uint8_t chan) |
|||
{ |
|||
uint16_t data; |
|||
static uint32_t spekChannelData[SPEK_MAX_CHANNEL]; |
|||
uint8_t b; |
|||
|
|||
if (rcFrameComplete) { |
|||
for (b = 3; b < SPEK_FRAME_SIZE; b += 2) { |
|||
uint8_t spekChannel = 0x0F & (spekFrame[b - 1] >> spek_chan_shift); |
|||
if (spekChannel < SPEK_MAX_CHANNEL) |
|||
spekChannelData[spekChannel] = ((uint32_t)(spekFrame[b - 1] & spek_chan_mask) << 8) + spekFrame[b]; |
|||
} |
|||
rcFrameComplete = false; |
|||
} |
|||
|
|||
if (chan >= SPEK_MAX_CHANNEL || !spekDataIncoming) { |
|||
data = 1500; |
|||
} else { |
|||
if (cfg.spektrum_hires) |
|||
data = 988 + (spekChannelData[spekRcChannelMap[chan]] >> 1); // 2048 mode |
|||
else |
|||
data = 988 + spekChannelData[spekRcChannelMap[chan]]; // 1024 mode |
|||
} |
|||
|
|||
return data; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue