Skip to content

Commit

Permalink
Merge remote-tracking branch 'betaflight/master' into betaflight-master
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra committed Sep 21, 2017
2 parents 107ecbc + b6efa8c commit 6d7beb3
Show file tree
Hide file tree
Showing 132 changed files with 2,886 additions and 948 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ stm32.mak
# artefacts for CLion
/cmake-build-debug/
/CMakeLists.txt

.vagrant
ubuntu*.log
4 changes: 4 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Vagrant.configure(2) do |config|

config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-interval", 10000]
v.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust", 100]
v.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore", 1]
v.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
end

# Enable provisioning with a shell script. Additional provisioners such as
Expand Down
1 change: 0 additions & 1 deletion make/mcu/SITL.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ MCU_EXCLUDES = \
drivers/dma.c \
drivers/pwm_output.c \
drivers/timer.c \
drivers/light_led.c \
drivers/system.c \
drivers/rcc.c \
drivers/serial_escserial.c \
Expand Down
1 change: 1 addition & 0 deletions make/source.mk
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ FC_SRC = \
telemetry/smartport.c \
telemetry/ltm.c \
telemetry/mavlink.c \
telemetry/msp_shared.c \
telemetry/ibus.c \
telemetry/ibus_shared.c \
sensors/esc_sensor.c \
Expand Down
5 changes: 1 addition & 4 deletions src/main/blackbox/blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,6 @@ typedef struct blackboxSlowState_s {
bool rxFlightChannelsValid;
} __attribute__((__packed__)) blackboxSlowState_t; // We pack this struct so that padding doesn't interfere with memcmp()

//From mixer.c:
extern float motorOutputHigh, motorOutputLow;

//From rc_controls.c
extern boxBitmask_t rcModeActivationMask;

Expand Down Expand Up @@ -1702,7 +1699,7 @@ void blackboxInit(void)
// by default p_denom is 32 and a P-frame is written every 1ms
// if p_denom is zero then no P-frames are logged
if (blackboxConfig()->p_denom == 0) {
blackboxPInterval = 0;
blackboxPInterval = 0; // blackboxPInterval not used when p_denom is zero, so just set it to zero
} else if (blackboxConfig()->p_denom > blackboxIInterval && blackboxIInterval >= 32) {
blackboxPInterval = 1;
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/main/build/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ extern const char* const buildDate; // "MMM DD YYYY" MMM = Jan/Feb/...

#define BUILD_TIME_LENGTH 8
extern const char* const buildTime; // "HH:MM:SS"

#define MSP_API_VERSION_STRING STR(API_VERSION_MAJOR) "." STR(API_VERSION_MINOR)
75 changes: 75 additions & 0 deletions src/main/cms/cms_menu_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,77 @@ static CMS_Menu cmsx_menuFilterPerProfile = {
.entries = cmsx_menuFilterPerProfileEntries,
};

#ifdef USE_COPY_PROFILE_CMS_MENU

static uint8_t cmsx_dstPidProfile;
static uint8_t cmsx_dstControlRateProfile;

static const char * const cmsx_ProfileNames[] = {
"-",
"1",
"2",
"3"
};

static OSD_TAB_t cmsx_PidProfileTable = { &cmsx_dstPidProfile, 3, cmsx_ProfileNames };
static OSD_TAB_t cmsx_ControlRateProfileTable = { &cmsx_dstControlRateProfile, 3, cmsx_ProfileNames };

static long cmsx_menuCopyProfile_onEnter(void)
{
cmsx_dstPidProfile = 0;
cmsx_dstControlRateProfile = 0;

return 0;
}

static long cmsx_CopyPidProfile(displayPort_t *pDisplay, const void *ptr)
{
UNUSED(pDisplay);
UNUSED(ptr);

if (cmsx_dstPidProfile > 0) {
pidCopyProfile(cmsx_dstPidProfile - 1, getCurrentPidProfileIndex());
}

return 0;
}

static long cmsx_CopyControlRateProfile(displayPort_t *pDisplay, const void *ptr)
{
UNUSED(pDisplay);
UNUSED(ptr);

if (cmsx_dstControlRateProfile > 0) {
copyControlRateProfile(cmsx_dstControlRateProfile - 1, getCurrentControlRateProfileIndex());
}

return 0;
}

static OSD_Entry cmsx_menuCopyProfileEntries[] =
{
{ "-- COPY PROFILE --", OME_Label, NULL, NULL, 0},

{ "CPY PID PROF TO", OME_TAB, NULL, &cmsx_PidProfileTable, 0 },
{ "COPY PP", OME_Funcall, cmsx_CopyPidProfile, NULL, 0 },
{ "CPY RATE PROF TO", OME_TAB, NULL, &cmsx_ControlRateProfileTable, 0 },
{ "COPY RP", OME_Funcall, cmsx_CopyControlRateProfile, NULL, 0 },

{ "BACK", OME_Back, NULL, NULL, 0 },
{ NULL, OME_END, NULL, NULL, 0 }
};

CMS_Menu cmsx_menuCopyProfile = {
.GUARD_text = "XCPY",
.GUARD_type = OME_MENU,
.onEnter = cmsx_menuCopyProfile_onEnter,
.onExit = NULL,
.onGlobalExit = NULL,
.entries = cmsx_menuCopyProfileEntries,
};

#endif

static OSD_Entry cmsx_menuImuEntries[] =
{
{ "-- IMU --", OME_Label, NULL, NULL, 0},
Expand All @@ -404,6 +475,9 @@ static OSD_Entry cmsx_menuImuEntries[] =
{"RATE", OME_Submenu, cmsMenuChange, &cmsx_menuRateProfile, 0},

{"FILT GLB", OME_Submenu, cmsMenuChange, &cmsx_menuFilterGlobal, 0},
#ifdef USE_COPY_PROFILE_CMS_MENU
{"COPY PROF", OME_Submenu, cmsMenuChange, &cmsx_menuCopyProfile, 0},
#endif

{"BACK", OME_Back, NULL, NULL, 0},
{NULL, OME_END, NULL, NULL, 0}
Expand All @@ -417,4 +491,5 @@ CMS_Menu cmsx_menuImu = {
.onGlobalExit = NULL,
.entries = cmsx_menuImuEntries,
};

#endif // CMS
2 changes: 1 addition & 1 deletion src/main/cms/cms_menu_vtx_smartaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "platform.h"

#ifdef CMS
#if defined(CMS) && defined(VTX_SMARTAUDIO)

#include "common/printf.h"
#include "common/utils.h"
Expand Down
3 changes: 2 additions & 1 deletion src/main/cms/cms_menu_vtx_tramp.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

#include "platform.h"

#ifdef CMS
#if defined(CMS) && defined(VTX_TRAMP)

#include "common/printf.h"
#include "common/utils.h"

Expand Down
22 changes: 22 additions & 0 deletions src/main/common/crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,25 @@ void crc8_dvb_s2_sbuf_append(sbuf_t *dst, uint8_t *start)
}
sbufWriteU8(dst, crc);
}

uint8_t crc8_xor_update(uint8_t crc, const void *data, uint32_t length)
{
const uint8_t *p = (const uint8_t *)data;
const uint8_t *pend = p + length;

for (; p != pend; p++) {
crc ^= *p;
}
return crc;
}

void crc8_xor_sbuf_append(sbuf_t *dst, uint8_t *start)
{
uint8_t crc = 0;
const uint8_t *end = dst->ptr;
for (uint8_t *ptr = start; ptr < end; ++ptr) {
crc ^= *ptr;
}
sbufWriteU8(dst, crc);
}

5 changes: 4 additions & 1 deletion src/main/common/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

#pragma once

struct sbuf_s;

uint16_t crc16_ccitt(uint16_t crc, unsigned char a);
uint16_t crc16_ccitt_update(uint16_t crc, const void *data, uint32_t length);
uint8_t crc8_dvb_s2(uint8_t crc, unsigned char a);
uint8_t crc8_dvb_s2_update(uint8_t crc, const void *data, uint32_t length);
struct sbuf_s;
void crc8_dvb_s2_sbuf_append(struct sbuf_s *dst, uint8_t *start);
uint8_t crc8_xor_update(uint8_t crc, const void *data, uint32_t length);
void crc8_xor_sbuf_append(struct sbuf_s *dst, uint8_t *start);
9 changes: 6 additions & 3 deletions src/main/common/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ float firFilterLastInput(const firFilter_t *filter)

void firFilterDenoiseInit(firFilterDenoise_t *filter, uint8_t gyroSoftLpfHz, uint16_t targetLooptime)
{
memset(filter, 0, sizeof(firFilterDenoise_t));
filter->targetCount = constrain(lrintf((1.0f / (0.000001f * (float)targetLooptime)) / gyroSoftLpfHz), 1, MAX_FIR_DENOISE_WINDOW_SIZE);
}

Expand All @@ -303,12 +304,14 @@ float firFilterDenoiseUpdate(firFilterDenoise_t *filter, float input)
{
filter->state[filter->index] = input;
filter->movingSum += filter->state[filter->index++];
if (filter->index == filter->targetCount)
if (filter->index == filter->targetCount) {
filter->index = 0;
}
filter->movingSum -= filter->state[filter->index];

if (filter->targetCount >= filter->filledCount)
if (filter->targetCount >= filter->filledCount) {
return filter->movingSum / filter->targetCount;
else
} else {
return filter->movingSum / ++filter->filledCount + 1;
}
}
2 changes: 1 addition & 1 deletion src/main/common/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef struct biquadFilter_s {
float x1, x2, y1, y2;
} biquadFilter_t;

typedef struct firFilterDenoise_s{
typedef struct firFilterDenoise_s {
int filledCount;
int targetCount;
int index;
Expand Down
18 changes: 18 additions & 0 deletions src/main/common/streambuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@

#include "streambuf.h"

sbuf_t *sbufInit(sbuf_t *sbuf, uint8_t *ptr, uint8_t *end)
{
sbuf->ptr = ptr;
sbuf->end = end;
return sbuf;
}

void sbufWriteU8(sbuf_t *dst, uint8_t val)
{
*dst->ptr++ = val;
Expand Down Expand Up @@ -54,6 +61,12 @@ void sbufWriteU32BigEndian(sbuf_t *dst, uint32_t val)
}


void sbufFill(sbuf_t *dst, uint8_t data, int len)
{
memset(dst->ptr, data, len);
dst->ptr += len;
}

void sbufWriteData(sbuf_t *dst, const void *data, int len)
{
memcpy(dst->ptr, data, len);
Expand All @@ -65,6 +78,11 @@ void sbufWriteString(sbuf_t *dst, const char *string)
sbufWriteData(dst, string, strlen(string));
}

void sbufWriteStringWithZeroTerminator(sbuf_t *dst, const char *string)
{
sbufWriteData(dst, string, strlen(string) + 1);
}

uint8_t sbufReadU8(sbuf_t *src)
{
return *src->ptr++;
Expand Down
7 changes: 5 additions & 2 deletions src/main/common/streambuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@
#include <stdint.h>

// simple buffer-based serializer/deserializer without implicit size check
// little-endian encoding implemneted now

typedef struct sbuf_s {
uint8_t *ptr; // data pointer must be first (sbuff_t* is equivalent to uint8_t **)
uint8_t *ptr; // data pointer must be first (sbuf_t* is equivalent to uint8_t **)
uint8_t *end;
} sbuf_t;

sbuf_t *sbufInit(sbuf_t *sbuf, uint8_t *ptr, uint8_t *end);

void sbufWriteU8(sbuf_t *dst, uint8_t val);
void sbufWriteU16(sbuf_t *dst, uint16_t val);
void sbufWriteU32(sbuf_t *dst, uint32_t val);
void sbufWriteU16BigEndian(sbuf_t *dst, uint16_t val);
void sbufWriteU32BigEndian(sbuf_t *dst, uint32_t val);
void sbufFill(sbuf_t *dst, uint8_t data, int len);
void sbufWriteData(sbuf_t *dst, const void *data, int len);
void sbufWriteString(sbuf_t *dst, const char *string);
void sbufWriteStringWithZeroTerminator(sbuf_t *dst, const char *string);

uint8_t sbufReadU8(sbuf_t *src);
uint16_t sbufReadU16(sbuf_t *src);
Expand Down
74 changes: 74 additions & 0 deletions src/main/common/string_light.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/

#include <limits.h>

#include "string_light.h"
#include "typeconversion.h"

int sl_isalnum(int c)
{
return sl_isdigit(c) || sl_isupper(c) || sl_islower(c);
}

int sl_isdigit(int c)
{
return (c >= '0' && c <= '9');
}

int sl_isupper(int c)
{
return (c >= 'A' && c <= 'Z');
}

int sl_islower(int c)
{
return (c >= 'a' && c <= 'z');
}

int sl_tolower(int c)
{
return sl_isupper(c) ? (c) - 'A' + 'a' : c;
}

int sl_toupper(int c)
{
return sl_islower(c) ? (c) - 'a' + 'A' : c;
}

int sl_strcasecmp(const char * s1, const char * s2)
{
return sl_strncasecmp(s1, s2, INT_MAX);
}

int sl_strncasecmp(const char * s1, const char * s2, int n)
{
const unsigned char * ucs1 = (const unsigned char *) s1;
const unsigned char * ucs2 = (const unsigned char *) s2;

int d = 0;

for ( ; n != 0; n--) {
const int c1 = sl_tolower(*ucs1++);
const int c2 = sl_tolower(*ucs2++);
if (((d = c1 - c2) != 0) || (c2 == '\0')) {
break;
}
}

return d;
}
Loading

0 comments on commit 6d7beb3

Please sign in to comment.