From a5b428ae4ff24244cc531b4d34796bc99fe73c90 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Fri, 16 Jun 2017 23:02:07 +1200 Subject: [PATCH 01/25] Added support for array variables to CLI. --- src/main/fc/cli.c | 192 +++++++++++++++++++++++++++-------------- src/main/fc/settings.h | 34 ++++---- 2 files changed, 145 insertions(+), 81 deletions(-) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index b2adcfbbee..6431bc50d3 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -293,33 +293,44 @@ static void cliPrintLinef(const char *format, ...) static void printValuePointer(const clivalue_t *var, const void *valuePointer, bool full) { - int value = 0; + if ((var->type & VALUE_MODE_MASK) == MODE_ARRAY) { + for (int i = 0; i < var->config.array.length; i++) { + uint8_t value = ((uint8_t *)valuePointer)[i]; - switch (var->type & VALUE_TYPE_MASK) { - case VAR_UINT8: - value = *(uint8_t *)valuePointer; - break; - - case VAR_INT8: - value = *(int8_t *)valuePointer; - break; - - case VAR_UINT16: - case VAR_INT16: - value = *(int16_t *)valuePointer; - break; - } - - switch(var->type & VALUE_MODE_MASK) { - case MODE_DIRECT: - cliPrintf("%d", value); - if (full) { - cliPrintf(" %d %d", var->config.minmax.min, var->config.minmax.max); + cliPrintf("%d", value); + if (i < var->config.array.length - 1) { + cliPrint(", "); + } + } + } else { + int value = 0; + + switch (var->type & VALUE_TYPE_MASK) { + case VAR_UINT8: + value = *(uint8_t *)valuePointer; + break; + + case VAR_INT8: + value = *(int8_t *)valuePointer; + break; + + case VAR_UINT16: + case VAR_INT16: + value = *(int16_t *)valuePointer; + break; + } + + switch(var->type & VALUE_MODE_MASK) { + case MODE_DIRECT: + cliPrintf("%d", value); + if (full) { + cliPrintf(" %d %d", var->config.minmax.min, var->config.minmax.max); + } + break; + case MODE_LOOKUP: + cliPrint(lookupTables[var->config.lookup.tableIndex].values[value]); + break; } - break; - case MODE_LOOKUP: - cliPrint(lookupTables[var->config.lookup.tableIndex].values[value]); - break; } } @@ -377,14 +388,15 @@ static void dumpPgValue(const clivalue_t *value, uint8_t dumpMask) const char *defaultFormat = "#set %s = "; const int valueOffset = getValueOffset(value); const bool equalsDefault = valuePtrEqualsDefault(value->type, pg->copy + valueOffset, pg->address + valueOffset); + if (((dumpMask & DO_DIFF) == 0) || !equalsDefault) { if (dumpMask & SHOW_DEFAULTS && !equalsDefault) { cliPrintf(defaultFormat, value->name); - printValuePointer(value, (uint8_t*)pg->address + valueOffset, 0); + printValuePointer(value, (uint8_t*)pg->address + valueOffset, false); cliPrintLinefeed(); } cliPrintf(format, value->name); - printValuePointer(value, pg->copy + valueOffset, 0); + printValuePointer(value, pg->copy + valueOffset, false); cliPrintLinefeed(); } } @@ -424,26 +436,31 @@ static void cliPrintVarRange(const clivalue_t *var) } cliPrintLinefeed(); } + break; + case (MODE_ARRAY): { + cliPrintLinef("Array length: %d", var->config.array.length); + } + break; } } -static void cliSetVar(const clivalue_t *var, const cliVar_t value) +static void cliSetVar(const clivalue_t *var, const int16_t value) { void *ptr = getValuePointer(var); switch (var->type & VALUE_TYPE_MASK) { case VAR_UINT8: - *(uint8_t *)ptr = value.uint8; + *(uint8_t *)ptr = value; break; case VAR_INT8: - *(int8_t *)ptr = value.int8; + *(int8_t *)ptr = value; break; case VAR_UINT16: case VAR_INT16: - *(int16_t *)ptr = value.int16; + *(int16_t *)ptr = value; break; } } @@ -2507,18 +2524,34 @@ static void cliGet(char *cmdline) cliPrintLine("Invalid name"); } +static char *skipSpace(char *buffer) +{ + while (*(buffer) == ' ') { + buffer++; + } + + return buffer; +} + +static uint8_t getWordLength(char *bufBegin, char *bufEnd) +{ + while (*(bufEnd - 1) == ' ') { + bufEnd--; + } + + return bufEnd - bufBegin; +} + static void cliSet(char *cmdline) { - uint32_t len; - const clivalue_t *val; - char *eqptr = NULL; - - len = strlen(cmdline); + const uint32_t len = strlen(cmdline); + char *eqptr; if (len == 0 || (len == 1 && cmdline[0] == '*')) { cliPrintLine("Current settings: "); + for (uint32_t i = 0; i < valueTableEntryCount; i++) { - val = &valueTable[i]; + const clivalue_t *val = &valueTable[i]; cliPrintf("%s = ", valueTable[i].name); cliPrintVar(val, len); // when len is 1 (when * is passed as argument), it will print min/max values as well, for gui cliPrintLinefeed(); @@ -2526,52 +2559,81 @@ static void cliSet(char *cmdline) } else if ((eqptr = strstr(cmdline, "=")) != NULL) { // has equals - char *lastNonSpaceCharacter = eqptr; - while (*(lastNonSpaceCharacter - 1) == ' ') { - lastNonSpaceCharacter--; - } - uint8_t variableNameLength = lastNonSpaceCharacter - cmdline; + uint8_t variableNameLength = getWordLength(cmdline, eqptr); // skip the '=' and any ' ' characters eqptr++; - while (*(eqptr) == ' ') { - eqptr++; - } + eqptr = skipSpace(eqptr); for (uint32_t i = 0; i < valueTableEntryCount; i++) { - val = &valueTable[i]; + const clivalue_t *val = &valueTable[i]; // ensure exact match when setting to prevent setting variables with shorter names if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0 && variableNameLength == strlen(valueTable[i].name)) { - bool changeValue = false; - cliVar_t value = { .int16 = 0 }; + bool valueChanged = false; + int16_t value = 0; switch (valueTable[i].type & VALUE_MODE_MASK) { case MODE_DIRECT: { - value.int16 = atoi(eqptr); + int16_t value = atoi(eqptr); - if (value.int16 >= valueTable[i].config.minmax.min && value.int16 <= valueTable[i].config.minmax.max) { - changeValue = true; - } + if (value >= valueTable[i].config.minmax.min && value <= valueTable[i].config.minmax.max) { + cliSetVar(val, value); + valueChanged = true; } - break; + } + + break; case MODE_LOOKUP: { - const lookupTableEntry_t *tableEntry = &lookupTables[valueTable[i].config.lookup.tableIndex]; - bool matched = false; - for (uint32_t tableValueIndex = 0; tableValueIndex < tableEntry->valueCount && !matched; tableValueIndex++) { - matched = strcasecmp(tableEntry->values[tableValueIndex], eqptr) == 0; + const lookupTableEntry_t *tableEntry = &lookupTables[valueTable[i].config.lookup.tableIndex]; + bool matched = false; + for (uint32_t tableValueIndex = 0; tableValueIndex < tableEntry->valueCount && !matched; tableValueIndex++) { + matched = strcasecmp(tableEntry->values[tableValueIndex], eqptr) == 0; - if (matched) { - value.int16 = tableValueIndex; - changeValue = true; - } + if (matched) { + value = tableValueIndex; + + cliSetVar(val, value); + valueChanged = true; } } - break; + } + + break; + case MODE_ARRAY: { + const uint8_t arrayLength = valueTable[i].config.array.length; + char *valPtr = eqptr; + uint8_t array[256]; + char curVal[4]; + for (int i = 0; i < arrayLength; i++) { + valPtr = skipSpace(valPtr); + char *valEnd = strstr(valPtr, ","); + if ((valEnd != NULL) && (i < arrayLength - 1)) { + uint8_t varLength = getWordLength(valPtr, valEnd); + if (varLength <= 3) { + strncpy(curVal, valPtr, getWordLength(valPtr, valEnd)); + curVal[varLength] = '\0'; + array[i] = (uint8_t)atoi((const char *)curVal); + valPtr = valEnd + 1; + } else { + break; + } + } else if ((valEnd == NULL) && (i == arrayLength - 1)) { + array[i] = atoi(valPtr); + + uint8_t *ptr = getValuePointer(val); + memcpy(ptr, array, arrayLength); + valueChanged = true; + } else { + break; + } + } + } + + break; + } - if (changeValue) { - cliSetVar(val, value); - + if (valueChanged) { cliPrintf("%s set to ", valueTable[i].name); cliPrintVar(val, 0); } else { diff --git a/src/main/fc/settings.h b/src/main/fc/settings.h index 62ceb04775..52ddb0a3f5 100644 --- a/src/main/fc/settings.h +++ b/src/main/fc/settings.h @@ -69,34 +69,31 @@ typedef struct lookupTableEntry_s { #define VALUE_TYPE_OFFSET 0 -#define VALUE_SECTION_OFFSET 4 -#define VALUE_MODE_OFFSET 6 +#define VALUE_SECTION_OFFSET 2 +#define VALUE_MODE_OFFSET 4 typedef enum { - // value type, bits 0-3 + // value type, bits 0-1 VAR_UINT8 = (0 << VALUE_TYPE_OFFSET), VAR_INT8 = (1 << VALUE_TYPE_OFFSET), VAR_UINT16 = (2 << VALUE_TYPE_OFFSET), VAR_INT16 = (3 << VALUE_TYPE_OFFSET), - // value section, bits 4-5 + // value section, bits 2-3 MASTER_VALUE = (0 << VALUE_SECTION_OFFSET), PROFILE_VALUE = (1 << VALUE_SECTION_OFFSET), - PROFILE_RATE_VALUE = (2 << VALUE_SECTION_OFFSET), // 0x20 - // value mode - MODE_DIRECT = (0 << VALUE_MODE_OFFSET), // 0x40 - MODE_LOOKUP = (1 << VALUE_MODE_OFFSET) // 0x80 + PROFILE_RATE_VALUE = (2 << VALUE_SECTION_OFFSET), + + // value mode, bits 4-5 + MODE_DIRECT = (0 << VALUE_MODE_OFFSET), + MODE_LOOKUP = (1 << VALUE_MODE_OFFSET), + MODE_ARRAY = (2 << VALUE_MODE_OFFSET) } cliValueFlag_e; -#define VALUE_TYPE_MASK (0x0F) -#define VALUE_SECTION_MASK (0x30) -#define VALUE_MODE_MASK (0xC0) -typedef union { - int8_t int8; - uint8_t uint8; - int16_t int16; -} cliVar_t; +#define VALUE_TYPE_MASK (0x03) +#define VALUE_SECTION_MASK (0x0c) +#define VALUE_MODE_MASK (0x30) typedef struct cliMinMaxConfig_s { const int16_t min; @@ -107,9 +104,14 @@ typedef struct cliLookupTableConfig_s { const lookupTableIndex_e tableIndex; } cliLookupTableConfig_t; +typedef struct cliArrayLengthConfig_s { + const uint8_t length; +} cliArrayLengthConfig_t; + typedef union { cliLookupTableConfig_t lookup; cliMinMaxConfig_t minmax; + cliArrayLengthConfig_t array; } cliValueConfig_t; typedef struct { From 41668fa702e9935a822caa8d1f407c3d3a6635d8 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 18 Jun 2017 19:17:20 +1200 Subject: [PATCH 02/25] Added visual beeper to OSD. --- src/main/cms/cms_menu_osd.c | 2 +- src/main/fc/settings.c | 2 +- src/main/io/osd.c | 40 ++++++++++++++++++++++--------------- src/main/io/osd.h | 2 +- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index bca4df0538..2a811bc7b3 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -137,7 +137,7 @@ OSD_Entry menuOsdActiveElemsEntries[] = {"YAW PID", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_YAW_PIDS], 0}, {"PROFILES", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PIDRATE_PROFILE], 0}, {"DEBUG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_DEBUG], 0}, - {"BATT WARN", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_MAIN_BATT_WARNING], 0}, + {"WARNINGS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_WARNINGS], 0}, {"DISARMED", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_DISARMED], 0}, {"PIT ANG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PITCH_ANGLE], 0}, {"ROL ANG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_ROLL_ANGLE], 0}, diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index 6907ab8058..1d51349f06 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -652,7 +652,7 @@ const clivalue_t valueTable[] = { { "osd_debug_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_DEBUG]) }, { "osd_power_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_POWER]) }, { "osd_pidrate_profile_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_PIDRATE_PROFILE]) }, - { "osd_battery_warning_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_MAIN_BATT_WARNING]) }, + { "osd_warnings_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_WARNINGS]) }, { "osd_avg_cell_voltage_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_AVG_CELL_VOLTAGE]) }, { "osd_pit_ang_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_PITCH_ANGLE]) }, { "osd_rol_ang_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ROLL_ANGLE]) }, diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 88d12a18d7..d52eda0ece 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -58,6 +58,7 @@ #include "drivers/vtx_common.h" #include "io/asyncfatfs/asyncfatfs.h" +#include "io/beeper.h" #include "io/flashfs.h" #include "io/gps.h" #include "io/osd.h" @@ -95,7 +96,8 @@ // Blink control -bool blinkState = true; +static bool blinkState = true; +static bool showVisualBeeper = false; static uint32_t blinkBits[(OSD_ITEM_COUNT + 31)/32]; #define SET_BLINK(item) (blinkBits[(item) / 32] |= (1 << ((item) % 32))) @@ -518,7 +520,7 @@ static void osdDrawSingleElement(uint8_t item) break; } - case OSD_MAIN_BATT_WARNING: + case OSD_WARNINGS: switch(getBatteryState()) { case BATTERY_WARNING: tfp_sprintf(buff, "LOW BATTERY"); @@ -529,7 +531,13 @@ static void osdDrawSingleElement(uint8_t item) break; default: - return; + if (showVisualBeeper) { + tfp_sprintf(buff, " * * * *"); + } else { + return; + } + break; + } break; @@ -613,7 +621,7 @@ static void osdDrawSingleElement(uint8_t item) displayWrite(osdDisplayPort, elemPosX + elemOffsetX, elemPosY, buff); } -void osdDrawElements(void) +static void osdDrawElements(void) { displayClearScreen(osdDisplayPort); @@ -621,13 +629,6 @@ void osdDrawElements(void) if (IS_RC_MODE_ACTIVE(BOXOSD)) return; -#if 0 - if (currentElement) - osdDrawElementPositioningHelp(); -#else - if (false) - ; -#endif #ifdef CMS else if (sensors(SENSOR_ACC) || displayIsGrabbed(osdDisplayPort)) #else @@ -654,7 +655,7 @@ void osdDrawElements(void) osdDrawSingleElement(OSD_YAW_PIDS); osdDrawSingleElement(OSD_POWER); osdDrawSingleElement(OSD_PIDRATE_PROFILE); - osdDrawSingleElement(OSD_MAIN_BATT_WARNING); + osdDrawSingleElement(OSD_WARNINGS); osdDrawSingleElement(OSD_AVG_CELL_VOLTAGE); osdDrawSingleElement(OSD_DEBUG); osdDrawSingleElement(OSD_PITCH_ANGLE); @@ -706,7 +707,7 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig) osdConfig->item_pos[OSD_YAW_PIDS] = OSD_POS(7, 15) | VISIBLE_FLAG; osdConfig->item_pos[OSD_POWER] = OSD_POS(1, 10) | VISIBLE_FLAG; osdConfig->item_pos[OSD_PIDRATE_PROFILE] = OSD_POS(25, 10) | VISIBLE_FLAG; - osdConfig->item_pos[OSD_MAIN_BATT_WARNING] = OSD_POS(9, 10) | VISIBLE_FLAG; + osdConfig->item_pos[OSD_WARNINGS] = OSD_POS(9, 10) | VISIBLE_FLAG; osdConfig->item_pos[OSD_AVG_CELL_VOLTAGE] = OSD_POS(12, 2) | VISIBLE_FLAG; osdConfig->item_pos[OSD_DEBUG] = OSD_POS(1, 0) | VISIBLE_FLAG; osdConfig->item_pos[OSD_PITCH_ANGLE] = OSD_POS(1, 8) | VISIBLE_FLAG; @@ -802,12 +803,12 @@ void osdUpdateAlarms(void) CLR_BLINK(OSD_RSSI_VALUE); if (getBatteryState() == BATTERY_OK) { + CLR_BLINK(OSD_WARNINGS); CLR_BLINK(OSD_MAIN_BATT_VOLTAGE); - CLR_BLINK(OSD_MAIN_BATT_WARNING); CLR_BLINK(OSD_AVG_CELL_VOLTAGE); } else { + SET_BLINK(OSD_WARNINGS); SET_BLINK(OSD_MAIN_BATT_VOLTAGE); - SET_BLINK(OSD_MAIN_BATT_WARNING); SET_BLINK(OSD_AVG_CELL_VOLTAGE); } @@ -839,7 +840,7 @@ void osdResetAlarms(void) { CLR_BLINK(OSD_RSSI_VALUE); CLR_BLINK(OSD_MAIN_BATT_VOLTAGE); - CLR_BLINK(OSD_MAIN_BATT_WARNING); + CLR_BLINK(OSD_WARNINGS); CLR_BLINK(OSD_GPS_SATS); CLR_BLINK(OSD_FLYTIME); CLR_BLINK(OSD_MAH_DRAWN); @@ -1083,6 +1084,11 @@ static void osdRefresh(timeUs_t currentTimeUs) void osdUpdate(timeUs_t currentTimeUs) { static uint32_t counter = 0; + + if (isBeeperOn()) { + showVisualBeeper = true; + } + #ifdef MAX7456_DMA_CHANNEL_TX // don't touch buffers if DMA transaction is in progress if (displayIsTransferInProgress(osdDisplayPort)) { @@ -1108,6 +1114,8 @@ void osdUpdate(timeUs_t currentTimeUs) if (counter++ % DRAW_FREQ_DENOM == 0) { osdRefresh(currentTimeUs); + + showVisualBeeper = false; } else { // rest of time redraw screen 10 chars per idle so it doesn't lock the main idle displayDrawScreen(osdDisplayPort); } diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 90ef5eb0bd..45dd6ea95a 100755 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -48,7 +48,7 @@ typedef enum { OSD_YAW_PIDS, OSD_POWER, OSD_PIDRATE_PROFILE, - OSD_MAIN_BATT_WARNING, + OSD_WARNINGS, OSD_AVG_CELL_VOLTAGE, OSD_GPS_LON, OSD_GPS_LAT, From f65249e137032cb20f686383b7eaa765842ff5cf Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Mon, 19 Jun 2017 08:05:13 +1200 Subject: [PATCH 03/25] Increased buffer size. --- src/main/fc/cli.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 6431bc50d3..e790a64138 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -124,10 +124,20 @@ extern uint8_t __config_end; static serialPort_t *cliPort; -static bufWriter_t *cliWriter; -static uint8_t cliWriteBuffer[sizeof(*cliWriter) + 128]; -static char cliBuffer[64]; +#ifdef STM32F1 +#define CLI_IN_BUFFER_SIZE 128 +#define CLI_OUT_BUFFER_SIZE 64 +#else +// Space required to set array parameters +#define CLI_IN_BUFFER_SIZE 256 +#define CLI_OUT_BUFFER_SIZE 256 +#endif + +static bufWriter_t *cliWriter; +static uint8_t cliWriteBuffer[sizeof(*cliWriter) + CLI_IN_BUFFER_SIZE]; + +static char cliBuffer[CLI_OUT_BUFFER_SIZE]; static uint32_t bufferIndex = 0; static bool configIsInCopy = false; @@ -299,7 +309,7 @@ static void printValuePointer(const clivalue_t *var, const void *valuePointer, b cliPrintf("%d", value); if (i < var->config.array.length - 1) { - cliPrint(", "); + cliPrint(","); } } } else { From 64d92963e167a7029f36a735043833034eb5f42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Rosin=CC=81ski?= Date: Sat, 17 Jun 2017 13:56:51 +0200 Subject: [PATCH 04/25] braces style corrected. --- src/main/io/osd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 88d12a18d7..5d759e0685 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -681,6 +681,13 @@ void osdDrawElements(void) osdDrawSingleElement(OSD_HOME_DIR); } #endif // GPS + +#ifdef USE_ESC_SENSOR + if (feature(FEATURE_ESC_SENSOR)) { + osdDrawSingleElement(OSD_ESC_TMP); + osdDrawSingleElement(OSD_ESC_RPM); + } +#endif } void pgResetFn_osdConfig(osdConfig_t *osdConfig) From 57e85ea0616835c7807835448838e698df11c99c Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Sun, 18 Jun 2017 16:56:57 +0100 Subject: [PATCH 05/25] Merge branch 'rosek86-master' --- src/main/fc/settings.c | 2 ++ src/main/io/osd.c | 23 +++++++++++++++++++++++ src/main/io/osd.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index 6907ab8058..776c6e6ae6 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -661,6 +661,8 @@ const clivalue_t valueTable[] = { { "osd_disarmed_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_DISARMED]) }, { "osd_nheading_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_NUMERICAL_HEADING]) }, { "osd_nvario_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_NUMERICAL_VARIO]) }, + { "osd_esc_tmp_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_TMP]) }, + { "osd_esc_rpm_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_RPM]) }, { "osd_stat_max_spd", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats[OSD_STAT_MAX_SPEED])}, { "osd_stat_max_dist", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats[OSD_STAT_MAX_DISTANCE])}, diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 5d759e0685..08a219696c 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -79,6 +79,7 @@ #include "sensors/barometer.h" #include "sensors/battery.h" #include "sensors/sensors.h" +#include "sensors/esc_sensor.h" #ifdef USE_HARDWARE_REVISION_DETECTION #include "hardware_revision.h" @@ -154,6 +155,10 @@ static const char compassBar[] = { PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 0); +#ifdef USE_ESC_SENSOR +static escSensorData_t *escData; +#endif + /** * Gets the correct altitude symbol for the current unit system */ @@ -605,6 +610,16 @@ static void osdDrawSingleElement(uint8_t item) tfp_sprintf(buff, "%c%01d.%01d", directionSymbol, abs(verticalSpeed / 100), abs((verticalSpeed % 100) / 10)); break; } +#ifdef USE_ESC_SENSOR + case OSD_ESC_TMP: + buff[0] = SYM_TEMP_C; + tfp_sprintf(buff + 1, "%d", escData == NULL ? 0 : escData->temperature); + break; + + case OSD_ESC_RPM: + tfp_sprintf(buff, "%d", escData == NULL ? 0 : escData->rpm); + break; +#endif default: return; @@ -728,6 +743,8 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig) osdConfig->item_pos[OSD_DISARMED] = OSD_POS(10, 4) | VISIBLE_FLAG; osdConfig->item_pos[OSD_NUMERICAL_HEADING] = OSD_POS(23, 9) | VISIBLE_FLAG; osdConfig->item_pos[OSD_NUMERICAL_VARIO] = OSD_POS(23, 8) | VISIBLE_FLAG; + osdConfig->item_pos[OSD_ESC_TMP] = OSD_POS(18, 2) | VISIBLE_FLAG; + osdConfig->item_pos[OSD_ESC_RPM] = OSD_POS(19, 2) | VISIBLE_FLAG; osdConfig->enabled_stats[OSD_STAT_MAX_SPEED] = true; osdConfig->enabled_stats[OSD_STAT_MIN_BATTERY] = true; @@ -1071,6 +1088,12 @@ static void osdRefresh(timeUs_t currentTimeUs) blinkState = (currentTimeUs / 200000) % 2; +#ifdef USE_ESC_SENSOR + if (feature(FEATURE_ESC_SENSOR)) { + escData = getEscSensorData(ESC_SENSOR_COMBINED); + } +#endif + #ifdef CMS if (!displayIsGrabbed(osdDisplayPort)) { osdUpdateAlarms(); diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 90ef5eb0bd..5d4dbae52b 100755 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -63,6 +63,8 @@ typedef enum { OSD_NUMERICAL_HEADING, OSD_NUMERICAL_VARIO, OSD_COMPASS_BAR, + OSD_ESC_TMP, + OSD_ESC_RPM, OSD_ITEM_COUNT // MUST BE LAST } osd_items_e; From a01a48337d052b4d7c7280b466c4da1c6abc242f Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Mon, 19 Jun 2017 08:03:48 +0200 Subject: [PATCH 06/25] Add proshot to cli --- src/main/fc/settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index a8bfe6772d..47c39339a5 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -226,7 +226,7 @@ static const char * const lookupTableSuperExpoYaw[] = { static const char * const lookupTablePwmProtocol[] = { "OFF", "ONESHOT125", "ONESHOT42", "MULTISHOT", "BRUSHED", #ifdef USE_DSHOT - "DSHOT150", "DSHOT300", "DSHOT600", "DSHOT1200" + "DSHOT150", "DSHOT300", "DSHOT600", "DSHOT1200", "PWM_TYPE_PROSHOT1000" #endif }; From b21877438e24fe67cfc7b49ba65025836f9727e8 Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Wed, 8 Mar 2017 01:19:40 +0100 Subject: [PATCH 07/25] Convert motor values at the final stage // Increase resolution --- src/main/blackbox/blackbox.c | 7 ++++-- src/main/drivers/pwm_output.c | 28 ++++++++++++------------ src/main/drivers/pwm_output.h | 10 ++++----- src/main/drivers/pwm_output_dshot.c | 12 ++++++---- src/main/drivers/pwm_output_dshot_hal.c | 12 ++++++---- src/main/flight/mixer.c | 29 +++++++++++++------------ src/main/flight/mixer.h | 8 +++---- src/main/target/COLIBRI_RACE/i2c_bst.c | 2 +- src/main/target/SITL/target.c | 4 ++-- 9 files changed, 62 insertions(+), 50 deletions(-) diff --git a/src/main/blackbox/blackbox.c b/src/main/blackbox/blackbox.c index e0fcfee6b7..40cf9c3bad 100644 --- a/src/main/blackbox/blackbox.c +++ b/src/main/blackbox/blackbox.c @@ -323,7 +323,7 @@ typedef struct blackboxSlowState_s { } __attribute__((__packed__)) blackboxSlowState_t; // We pack this struct so that padding doesn't interfere with memcmp() //From mixer.c: -extern uint16_t motorOutputHigh, motorOutputLow; +extern float motorOutputHigh, motorOutputLow; //From rc_controls.c extern boxBitmask_t rcModeActivationMask; @@ -1188,6 +1188,9 @@ static bool sendFieldDefinition(char mainFrameChar, char deltaFrameChar, const v */ static bool blackboxWriteSysinfo(void) { + const uint16_t motorOutputLowInt = lrintf(motorOutputLow); + const uint16_t motorOutputHighInt = lrintf(motorOutputHigh); + // Make sure we have enough room in the buffer for our longest line (as of this writing, the "Firmware date" line) if (blackboxDeviceReserveBufferSpace(64) != BLACKBOX_RESERVE_SUCCESS) { return false; @@ -1203,7 +1206,7 @@ static bool blackboxWriteSysinfo(void) BLACKBOX_PRINT_HEADER_LINE("minthrottle", "%d", motorConfig()->minthrottle); BLACKBOX_PRINT_HEADER_LINE("maxthrottle", "%d", motorConfig()->maxthrottle); BLACKBOX_PRINT_HEADER_LINE("gyro_scale","0x%x", castFloatBytesToInt(1.0f)); - BLACKBOX_PRINT_HEADER_LINE("motorOutput", "%d,%d", motorOutputLow,motorOutputHigh); + BLACKBOX_PRINT_HEADER_LINE("motorOutput", "%d,%d", motorOutputLowInt,motorOutputHighInt); BLACKBOX_PRINT_HEADER_LINE("acc_1G", "%u", acc.dev.acc_1G); BLACKBOX_PRINT_HEADER_LINE_CUSTOM( diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 82bcc7a40e..a7da53c8b4 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -125,38 +125,38 @@ static void pwmOutConfig(pwmOutputPort_t *port, const timerHardware_t *timerHard *port->ccr = 0; } -static void pwmWriteUnused(uint8_t index, uint16_t value) +static void pwmWriteUnused(uint8_t index, float value) { UNUSED(index); UNUSED(value); } -static void pwmWriteBrushed(uint8_t index, uint16_t value) +static void pwmWriteBrushed(uint8_t index, float value) { - *motors[index].ccr = (value - 1000) * motors[index].period / 1000; + *motors[index].ccr = lrintf((value - 1000) * motors[index].period / 1000); } -static void pwmWriteStandard(uint8_t index, uint16_t value) +static void pwmWriteStandard(uint8_t index, float value) { - *motors[index].ccr = value; + *motors[index].ccr = lrintf(value); } -static void pwmWriteOneShot125(uint8_t index, uint16_t value) +static void pwmWriteOneShot125(uint8_t index, float value) { - *motors[index].ccr = lrintf((float)(value * ONESHOT125_TIMER_MHZ/8.0f)); + *motors[index].ccr = lrintf(value * ONESHOT125_TIMER_MHZ/8.0f); } -static void pwmWriteOneShot42(uint8_t index, uint16_t value) +static void pwmWriteOneShot42(uint8_t index, float value) { - *motors[index].ccr = lrintf((float)(value * ONESHOT42_TIMER_MHZ/24.0f)); + *motors[index].ccr = lrintf(value * ONESHOT42_TIMER_MHZ/24.0f); } -static void pwmWriteMultiShot(uint8_t index, uint16_t value) +static void pwmWriteMultiShot(uint8_t index, float value) { - *motors[index].ccr = lrintf(((float)(value-1000) * MULTISHOT_20US_MULT) + MULTISHOT_5US_PW); + *motors[index].ccr = lrintf(((value-1000) * MULTISHOT_20US_MULT) + MULTISHOT_5US_PW); } -void pwmWriteMotor(uint8_t index, uint16_t value) +void pwmWriteMotor(uint8_t index, float value) { if (pwmMotorsEnabled) { pwmWritePtr(index, value); @@ -374,10 +374,10 @@ void pwmWriteDshotCommand(uint8_t index, uint8_t command) #endif #ifdef USE_SERVOS -void pwmWriteServo(uint8_t index, uint16_t value) +void pwmWriteServo(uint8_t index, float value) { if (index < MAX_SUPPORTED_SERVOS && servos[index].ccr) { - *servos[index].ccr = value; + *servos[index].ccr = lrintf(value); } } diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index e87014a62a..1c3e792a49 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -131,7 +131,7 @@ motorDmaOutput_t *getMotorDmaOutput(uint8_t index); extern bool pwmMotorsEnabled; struct timerHardware_s; -typedef void(*pwmWriteFuncPtr)(uint8_t index, uint16_t value); // function pointer used to write motors +typedef void(*pwmWriteFuncPtr)(uint8_t index, float value); // function pointer used to write motors typedef void(*pwmCompleteWriteFuncPtr)(uint8_t motorCount); // function pointer used after motors are written typedef struct { @@ -167,8 +167,8 @@ void pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIn #ifdef USE_DSHOT uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType); void pwmWriteDshotCommand(uint8_t index, uint8_t command); -void pwmWriteProShot(uint8_t index, uint16_t value); -void pwmWriteDshot(uint8_t index, uint16_t value); +void pwmWriteProShot(uint8_t index, float value); +void pwmWriteDshot(uint8_t index, float value); void pwmDigitalMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output); void pwmCompleteDigitalMotorUpdate(uint8_t motorCount); #endif @@ -179,11 +179,11 @@ void pwmToggleBeeper(void); void beeperPwmInit(IO_t io, uint16_t frequency); #endif -void pwmWriteMotor(uint8_t index, uint16_t value); +void pwmWriteMotor(uint8_t index, float value); void pwmShutdownPulsesForAllMotors(uint8_t motorCount); void pwmCompleteMotorUpdate(uint8_t motorCount); -void pwmWriteServo(uint8_t index, uint16_t value); +void pwmWriteServo(uint8_t index, float value); pwmOutputPort_t *pwmGetMotors(void); bool pwmIsSynced(void); diff --git a/src/main/drivers/pwm_output_dshot.c b/src/main/drivers/pwm_output_dshot.c index 35fbad1ecd..c75ac74a03 100644 --- a/src/main/drivers/pwm_output_dshot.c +++ b/src/main/drivers/pwm_output_dshot.c @@ -54,15 +54,17 @@ uint8_t getTimerIndex(TIM_TypeDef *timer) return dmaMotorTimerCount-1; } -void pwmWriteDshot(uint8_t index, uint16_t value) +void pwmWriteDshot(uint8_t index, float value) { + const uint16_t digitalValue = lrintf(value); + motorDmaOutput_t * const motor = &dmaMotors[index]; if (!motor->timerHardware || !motor->timerHardware->dmaRef) { return; } - uint16_t packet = (value << 1) | (motor->requestTelemetry ? 1 : 0); + uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0); motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row // compute checksum @@ -85,15 +87,17 @@ void pwmWriteDshot(uint8_t index, uint16_t value) DMA_Cmd(motor->timerHardware->dmaRef, ENABLE); } -void pwmWriteProShot(uint8_t index, uint16_t value) +void pwmWriteProShot(uint8_t index, float value) { + const uint16_t digitalValue = lrintf(value); + motorDmaOutput_t * const motor = &dmaMotors[index]; if (!motor->timerHardware || !motor->timerHardware->dmaRef) { return; } - uint16_t packet = (value << 1) | (motor->requestTelemetry ? 1 : 0); + uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0); motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row // compute checksum diff --git a/src/main/drivers/pwm_output_dshot_hal.c b/src/main/drivers/pwm_output_dshot_hal.c index c1a1137f39..c2ff4737e1 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -49,15 +49,17 @@ uint8_t getTimerIndex(TIM_TypeDef *timer) return dmaMotorTimerCount - 1; } -void pwmWriteDshot(uint8_t index, uint16_t value) +void pwmWriteDshot(uint8_t index, float value) { + const uint16_t digitalValue = lrintf(value); + motorDmaOutput_t * const motor = &dmaMotors[index]; if (!motor->timerHardware || !motor->timerHardware->dmaRef) { return; } - uint16_t packet = (value << 1) | (motor->requestTelemetry ? 1 : 0); + uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0); motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row // compute checksum @@ -89,15 +91,17 @@ void pwmWriteDshot(uint8_t index, uint16_t value) } } -void pwmWriteProShot(uint8_t index, uint16_t value) +void pwmWriteProShot(uint8_t index, float value) { + const uint16_t digitalValue = lrintf(value); + motorDmaOutput_t * const motor = &dmaMotors[index]; if (!motor->timerHardware || !motor->timerHardware->dmaRef) { return; } - uint16_t packet = (value << 1) | (motor->requestTelemetry ? 1 : 0); + uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0); motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row // compute checksum diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index f5fcd647e5..818b2e9fb8 100755 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -114,8 +114,8 @@ PG_REGISTER_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, customMotorMixer, PG_MOTOR static uint8_t motorCount; static float motorMixRange; -int16_t motor[MAX_SUPPORTED_MOTORS]; -int16_t motor_disarmed[MAX_SUPPORTED_MOTORS]; +float motor[MAX_SUPPORTED_MOTORS]; +float motor_disarmed[MAX_SUPPORTED_MOTORS]; mixerMode_e currentMixerMode; static motorMixer_t currentMixer[MAX_SUPPORTED_MOTORS]; @@ -312,8 +312,8 @@ const mixer_t mixers[] = { }; #endif // !USE_QUAD_MIXER_ONLY -static uint16_t disarmMotorOutput, deadbandMotor3dHigh, deadbandMotor3dLow; -uint16_t motorOutputHigh, motorOutputLow; +static float disarmMotorOutput, deadbandMotor3dHigh, deadbandMotor3dLow; +float motorOutputHigh, motorOutputLow; static float rcCommandThrottleRange, rcCommandThrottleRange3dLow, rcCommandThrottleRange3dHigh; uint8_t getMotorCount() @@ -352,17 +352,18 @@ bool isMotorProtocolDshot(void) { #endif } -// Add here scaled ESC outputs for digital protol +// All PWM motor scaling is done to standard PWM range of 1000-2000 for easier tick conversion with legacy code / configurator +// DSHOT scaling is done to the actual dshot range void initEscEndpoints(void) { #ifdef USE_DSHOT if (isMotorProtocolDshot()) { disarmMotorOutput = DSHOT_DISARM_COMMAND; if (feature(FEATURE_3D)) - motorOutputLow = DSHOT_MIN_THROTTLE + lrintf(((DSHOT_3D_DEADBAND_LOW - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue)); + motorOutputLow = DSHOT_MIN_THROTTLE + ((DSHOT_3D_DEADBAND_LOW - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue); else - motorOutputLow = DSHOT_MIN_THROTTLE + lrintf(((DSHOT_MAX_THROTTLE - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue)); + motorOutputLow = DSHOT_MIN_THROTTLE + ((DSHOT_MAX_THROTTLE - DSHOT_MIN_THROTTLE) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue); motorOutputHigh = DSHOT_MAX_THROTTLE; - deadbandMotor3dHigh = DSHOT_3D_DEADBAND_HIGH + lrintf(((DSHOT_MAX_THROTTLE - DSHOT_3D_DEADBAND_HIGH) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue)); // TODO - Not working yet !! Mixer requires some throttle rescaling changes + deadbandMotor3dHigh = DSHOT_3D_DEADBAND_HIGH + ((DSHOT_MAX_THROTTLE - DSHOT_3D_DEADBAND_HIGH) / 100.0f) * CONVERT_PARAMETER_TO_PERCENT(motorConfig()->digitalIdleOffsetValue); // TODO - Not working yet !! Mixer requires some throttle rescaling changes deadbandMotor3dLow = DSHOT_3D_DEADBAND_LOW; } else #endif @@ -509,7 +510,7 @@ void mixTable(pidProfile_t *pidProfile) // Scale roll/pitch/yaw uniformly to fit within throttle range // Initial mixer concept by bdoiron74 reused and optimized for Air Mode float throttle = 0, currentThrottleInputRange = 0; - uint16_t motorOutputMin, motorOutputMax; + float motorOutputMin, motorOutputMax; static uint16_t throttlePrevious = 0; // Store the last throttle direction for deadband transitions bool mixerInversion = false; @@ -608,7 +609,7 @@ void mixTable(pidProfile_t *pidProfile) // Now add in the desired throttle, but keep in a range that doesn't clip adjusted // roll/pitch/yaw. This could move throttle down, but also up for those low throttle flips. for (uint32_t i = 0; i < motorCount; i++) { - float motorOutput = motorOutputMin + lrintf(motorOutputRange * (motorMix[i] + (throttle * currentMixer[i].throttle))); + float motorOutput = motorOutputMin + motorOutputRange * (motorMix[i] + (throttle * currentMixer[i].throttle)); // Dshot works exactly opposite in lower 3D section. if (mixerInversion) { @@ -642,7 +643,7 @@ void mixTable(pidProfile_t *pidProfile) } } -uint16_t convertExternalToMotor(uint16_t externalValue) +float convertExternalToMotor(uint16_t externalValue) { uint16_t motorValue = externalValue; #ifdef USE_DSHOT @@ -661,12 +662,12 @@ uint16_t convertExternalToMotor(uint16_t externalValue) } #endif - return motorValue; + return (float)motorValue; } -uint16_t convertMotorToExternal(uint16_t motorValue) +uint16_t convertMotorToExternal(float motorValue) { - uint16_t externalValue = motorValue; + uint16_t externalValue = lrintf(motorValue); #ifdef USE_DSHOT if (isMotorProtocolDshot()) { if (feature(FEATURE_3D) && motorValue >= DSHOT_MIN_THROTTLE && motorValue <= DSHOT_3D_DEADBAND_LOW) { diff --git a/src/main/flight/mixer.h b/src/main/flight/mixer.h index 51733d31e7..665b39fd25 100644 --- a/src/main/flight/mixer.h +++ b/src/main/flight/mixer.h @@ -118,8 +118,8 @@ PG_DECLARE(motorConfig_t, motorConfig); #define CHANNEL_FORWARDING_DISABLED (uint8_t)0xFF extern const mixer_t mixers[]; -extern int16_t motor[MAX_SUPPORTED_MOTORS]; -extern int16_t motor_disarmed[MAX_SUPPORTED_MOTORS]; +extern float motor[MAX_SUPPORTED_MOTORS]; +extern float motor_disarmed[MAX_SUPPORTED_MOTORS]; struct rxConfig_s; uint8_t getMotorCount(); @@ -141,5 +141,5 @@ void stopMotors(void); void stopPwmAllMotors(void); bool isMotorProtocolDshot(void); -uint16_t convertExternalToMotor(uint16_t externalValue); -uint16_t convertMotorToExternal(uint16_t motorValue); +float convertExternalToMotor(uint16_t externalValue); +uint16_t convertMotorToExternal(float motorValue); diff --git a/src/main/target/COLIBRI_RACE/i2c_bst.c b/src/main/target/COLIBRI_RACE/i2c_bst.c index 34a62f3849..9da520de11 100644 --- a/src/main/target/COLIBRI_RACE/i2c_bst.c +++ b/src/main/target/COLIBRI_RACE/i2c_bst.c @@ -139,7 +139,7 @@ static uint8_t activeBoxIds[CHECKBOX_ITEM_COUNT]; // this is the number of filled indexes in above array static uint8_t activeBoxIdCount = 0; // from mixer.c -extern int16_t motor_disarmed[MAX_SUPPORTED_MOTORS]; +extern float motor_disarmed[MAX_SUPPORTED_MOTORS]; // cause reboot after BST processing complete static bool isRebootScheduled = false; diff --git a/src/main/target/SITL/target.c b/src/main/target/SITL/target.c index c233dafa7c..bb0d756b00 100644 --- a/src/main/target/SITL/target.c +++ b/src/main/target/SITL/target.c @@ -392,7 +392,7 @@ pwmOutputPort_t *pwmGetMotors(void) { bool pwmAreMotorsEnabled(void) { return pwmMotorsEnabled; } -void pwmWriteMotor(uint8_t index, uint16_t value) { +void pwmWriteMotor(uint8_t index, float value) { motorsPwm[index] = value - idlePulse; } void pwmShutdownPulsesForAllMotors(uint8_t motorCount) { @@ -419,7 +419,7 @@ void pwmCompleteMotorUpdate(uint8_t motorCount) { udpSend(&pwmLink, &pwmPkt, sizeof(servo_packet)); // printf("[pwm]%u:%u,%u,%u,%u\n", idlePulse, motorsPwm[0], motorsPwm[1], motorsPwm[2], motorsPwm[3]); } -void pwmWriteServo(uint8_t index, uint16_t value) { +void pwmWriteServo(uint8_t index, float value) { servosPwm[index] = value; } From d51d66f8f1488e6adc1904002f0267b32892bb5f Mon Sep 17 00:00:00 2001 From: jflyper Date: Tue, 20 Jun 2017 09:45:46 +0900 Subject: [PATCH 08/25] Use cached value instead of RCC->CSR --- src/main/drivers/system_stm32f10x.c | 2 +- src/main/drivers/system_stm32f30x.c | 2 +- src/main/drivers/system_stm32f4xx.c | 4 ++-- src/main/drivers/system_stm32f7xx.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/drivers/system_stm32f10x.c b/src/main/drivers/system_stm32f10x.c index b6f2d423e0..536023fd27 100644 --- a/src/main/drivers/system_stm32f10x.c +++ b/src/main/drivers/system_stm32f10x.c @@ -83,7 +83,7 @@ void systemInit(void) // Turn on clocks for stuff we use RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); - // cache RCC->CSR value to use it in isMPUSoftreset() and others + // cache RCC->CSR value to use it in isMPUSoftReset() and others cachedRccCsrValue = RCC->CSR; RCC_ClearFlag(); diff --git a/src/main/drivers/system_stm32f30x.c b/src/main/drivers/system_stm32f30x.c index a00abdfba0..f3a349706a 100644 --- a/src/main/drivers/system_stm32f30x.c +++ b/src/main/drivers/system_stm32f30x.c @@ -90,7 +90,7 @@ void systemInit(void) // Configure NVIC preempt/priority groups NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING); - // cache RCC->CSR value to use it in isMPUSoftreset() and others + // cache RCC->CSR value to use it in isMPUSoftReset() and others cachedRccCsrValue = RCC->CSR; RCC_ClearFlag(); diff --git a/src/main/drivers/system_stm32f4xx.c b/src/main/drivers/system_stm32f4xx.c index de32333124..5b7e155640 100644 --- a/src/main/drivers/system_stm32f4xx.c +++ b/src/main/drivers/system_stm32f4xx.c @@ -152,7 +152,7 @@ void enableGPIOPowerUsageAndNoiseReductions(void) bool isMPUSoftReset(void) { - if (RCC->CSR & RCC_CSR_SFTRSTF) + if (cachedRccCsrValue & RCC_CSR_SFTRSTF) return true; else return false; @@ -167,7 +167,7 @@ void systemInit(void) // Configure NVIC preempt/priority groups NVIC_PriorityGroupConfig(NVIC_PRIORITY_GROUPING); - // cache RCC->CSR value to use it in isMPUSoftreset() and others + // cache RCC->CSR value to use it in isMPUSoftReset() and others cachedRccCsrValue = RCC->CSR; /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */ diff --git a/src/main/drivers/system_stm32f7xx.c b/src/main/drivers/system_stm32f7xx.c index db4f9085ea..bfe8039dde 100644 --- a/src/main/drivers/system_stm32f7xx.c +++ b/src/main/drivers/system_stm32f7xx.c @@ -149,7 +149,7 @@ void enableGPIOPowerUsageAndNoiseReductions(void) bool isMPUSoftReset(void) { - if (RCC->CSR & RCC_CSR_SFTRSTF) + if (cachedRccCsrValue & RCC_CSR_SFTRSTF) return true; else return false; @@ -164,7 +164,7 @@ void systemInit(void) // Configure NVIC preempt/priority groups HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITY_GROUPING); - // cache RCC->CSR value to use it in isMPUSoftreset() and others + // cache RCC->CSR value to use it in isMPUSoftReset() and others cachedRccCsrValue = RCC->CSR; /* Accounts for OP Bootloader, set the Vector Table base address as specified in .ld file */ From 1a082d5c7e38afa5dc3932e3d141c9c655823b97 Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Tue, 20 Jun 2017 11:18:58 +0200 Subject: [PATCH 09/25] Change cli naming for proshot --- src/main/fc/settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index 34172f259e..f316e5c92b 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -228,7 +228,7 @@ static const char * const lookupTableSuperExpoYaw[] = { static const char * const lookupTablePwmProtocol[] = { "OFF", "ONESHOT125", "ONESHOT42", "MULTISHOT", "BRUSHED", #ifdef USE_DSHOT - "DSHOT150", "DSHOT300", "DSHOT600", "DSHOT1200", "PWM_TYPE_PROSHOT1000" + "DSHOT150", "DSHOT300", "DSHOT600", "DSHOT1200", "PROSHOT1000" #endif }; From 682d4d40142c24d3391e8fe76fe3c747af0b665f Mon Sep 17 00:00:00 2001 From: jflyper Date: Tue, 20 Jun 2017 19:23:32 +0900 Subject: [PATCH 10/25] Preset CS lines for SPI devices initial high --- Makefile | 5 ++- src/main/drivers/accgyro/accgyro_spi_bmi160.c | 1 + .../drivers/accgyro/accgyro_spi_icm20689.c | 1 + .../drivers/accgyro/accgyro_spi_mpu6000.c | 1 + .../drivers/accgyro/accgyro_spi_mpu6500.c | 1 + src/main/drivers/bus_spi.c | 25 +++-------- src/main/drivers/bus_spi.h | 2 +- src/main/drivers/bus_spi_config.c | 36 ++++++++++++++++ src/main/drivers/bus_spi_hal.c | 24 +++-------- src/main/drivers/max7456.c | 1 + src/main/fc/fc_init.c | 43 +++++++++++++++++++ src/main/target/CJMCU/initialisation.c | 3 ++ src/main/target/NAZE/initialisation.c | 3 ++ 13 files changed, 105 insertions(+), 41 deletions(-) create mode 100644 src/main/drivers/bus_spi_config.c diff --git a/Makefile b/Makefile index e2b76957ed..5abbd9ff7a 100644 --- a/Makefile +++ b/Makefile @@ -680,6 +680,7 @@ COMMON_SRC = \ drivers/bus_i2c_config.c \ drivers/bus_i2c_soft.c \ drivers/bus_spi.c \ + drivers/bus_spi_config.c \ drivers/bus_spi_soft.c \ drivers/buttons.c \ drivers/display.c \ @@ -898,6 +899,7 @@ SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \ SIZE_OPTIMISED_SRC := $(SIZE_OPTIMISED_SRC) \ drivers/bus_i2c_config.c \ + drivers/bus_spi_config.c \ drivers/serial_escserial.c \ drivers/serial_pinconfig.c \ drivers/serial_uart_init.c \ @@ -1023,9 +1025,10 @@ F7EXCLUDES = drivers/bus_spi.c \ SITLEXCLUDES = \ drivers/adc.c \ - drivers/bus_spi.c \ drivers/bus_i2c.c \ drivers/bus_i2c_config.c \ + drivers/bus_spi.c \ + drivers/bus_spi_config.c \ drivers/dma.c \ drivers/pwm_output.c \ drivers/timer.c \ diff --git a/src/main/drivers/accgyro/accgyro_spi_bmi160.c b/src/main/drivers/accgyro/accgyro_spi_bmi160.c index 3852fa34dd..835ab25b2f 100644 --- a/src/main/drivers/accgyro/accgyro_spi_bmi160.c +++ b/src/main/drivers/accgyro/accgyro_spi_bmi160.c @@ -103,6 +103,7 @@ bool bmi160Detect(const busDevice_t *bus) return true; IOInit(bus->spi.csnPin, OWNER_MPU_CS, 0); IOConfigGPIO(bus->spi.csnPin, SPI_IO_CS_CFG); + IOHi(bus->spi.csnPin); spiSetDivisor(BMI160_SPI_INSTANCE, BMI160_SPI_DIVISOR); diff --git a/src/main/drivers/accgyro/accgyro_spi_icm20689.c b/src/main/drivers/accgyro/accgyro_spi_icm20689.c index 9764f61732..cb73bf4311 100644 --- a/src/main/drivers/accgyro/accgyro_spi_icm20689.c +++ b/src/main/drivers/accgyro/accgyro_spi_icm20689.c @@ -69,6 +69,7 @@ static void icm20689SpiInit(const busDevice_t *bus) IOInit(bus->spi.csnPin, OWNER_MPU_CS, 0); IOConfigGPIO(bus->spi.csnPin, SPI_IO_CS_CFG); + IOHi(bus->spi.csnPin); spiSetDivisor(ICM20689_SPI_INSTANCE, SPI_CLOCK_STANDARD); diff --git a/src/main/drivers/accgyro/accgyro_spi_mpu6000.c b/src/main/drivers/accgyro/accgyro_spi_mpu6000.c index fd9455a55e..3ce84e4a50 100644 --- a/src/main/drivers/accgyro/accgyro_spi_mpu6000.c +++ b/src/main/drivers/accgyro/accgyro_spi_mpu6000.c @@ -155,6 +155,7 @@ bool mpu6000SpiDetect(const busDevice_t *bus) IOInit(bus->spi.csnPin, OWNER_MPU_CS, 0); IOConfigGPIO(bus->spi.csnPin, SPI_IO_CS_CFG); + IOHi(bus->spi.csnPin); spiSetDivisor(MPU6000_SPI_INSTANCE, SPI_CLOCK_INITIALIZATON); diff --git a/src/main/drivers/accgyro/accgyro_spi_mpu6500.c b/src/main/drivers/accgyro/accgyro_spi_mpu6500.c index e477c3a047..1afecf509a 100755 --- a/src/main/drivers/accgyro/accgyro_spi_mpu6500.c +++ b/src/main/drivers/accgyro/accgyro_spi_mpu6500.c @@ -77,6 +77,7 @@ static void mpu6500SpiInit(const busDevice_t *bus) IOInit(bus->spi.csnPin, OWNER_MPU_CS, 0); IOConfigGPIO(bus->spi.csnPin, SPI_IO_CS_CFG); + IOHi(bus->spi.csnPin); spiSetDivisor(MPU6500_SPI_INSTANCE, SPI_CLOCK_FAST); diff --git a/src/main/drivers/bus_spi.c b/src/main/drivers/bus_spi.c index b5aae9eca2..eb0c2fdbc6 100644 --- a/src/main/drivers/bus_spi.c +++ b/src/main/drivers/bus_spi.c @@ -72,14 +72,14 @@ static spiDevice_t spiHardwareMap[] = { #if defined(STM32F1) - { .dev = SPI1, .nss = IO_TAG(SPI1_NSS_PIN), .sck = IO_TAG(SPI1_SCK_PIN), .miso = IO_TAG(SPI1_MISO_PIN), .mosi = IO_TAG(SPI1_MOSI_PIN), .rcc = RCC_APB2(SPI1), .af = 0, false }, - { .dev = SPI2, .nss = IO_TAG(SPI2_NSS_PIN), .sck = IO_TAG(SPI2_SCK_PIN), .miso = IO_TAG(SPI2_MISO_PIN), .mosi = IO_TAG(SPI2_MOSI_PIN), .rcc = RCC_APB1(SPI2), .af = 0, false }, + { .dev = SPI1, .sck = IO_TAG(SPI1_SCK_PIN), .miso = IO_TAG(SPI1_MISO_PIN), .mosi = IO_TAG(SPI1_MOSI_PIN), .rcc = RCC_APB2(SPI1), .af = 0, false }, + { .dev = SPI2, .sck = IO_TAG(SPI2_SCK_PIN), .miso = IO_TAG(SPI2_MISO_PIN), .mosi = IO_TAG(SPI2_MOSI_PIN), .rcc = RCC_APB1(SPI2), .af = 0, false }, #else - { .dev = SPI1, .nss = IO_TAG(SPI1_NSS_PIN), .sck = IO_TAG(SPI1_SCK_PIN), .miso = IO_TAG(SPI1_MISO_PIN), .mosi = IO_TAG(SPI1_MOSI_PIN), .rcc = RCC_APB2(SPI1), .af = GPIO_AF_SPI1, false }, - { .dev = SPI2, .nss = IO_TAG(SPI2_NSS_PIN), .sck = IO_TAG(SPI2_SCK_PIN), .miso = IO_TAG(SPI2_MISO_PIN), .mosi = IO_TAG(SPI2_MOSI_PIN), .rcc = RCC_APB1(SPI2), .af = GPIO_AF_SPI2, false }, + { .dev = SPI1, .sck = IO_TAG(SPI1_SCK_PIN), .miso = IO_TAG(SPI1_MISO_PIN), .mosi = IO_TAG(SPI1_MOSI_PIN), .rcc = RCC_APB2(SPI1), .af = GPIO_AF_SPI1, false }, + { .dev = SPI2, .sck = IO_TAG(SPI2_SCK_PIN), .miso = IO_TAG(SPI2_MISO_PIN), .mosi = IO_TAG(SPI2_MOSI_PIN), .rcc = RCC_APB1(SPI2), .af = GPIO_AF_SPI2, false }, #endif #if defined(STM32F3) || defined(STM32F4) - { .dev = SPI3, .nss = IO_TAG(SPI3_NSS_PIN), .sck = IO_TAG(SPI3_SCK_PIN), .miso = IO_TAG(SPI3_MISO_PIN), .mosi = IO_TAG(SPI3_MOSI_PIN), .rcc = RCC_APB1(SPI3), .af = GPIO_AF_SPI3, false } + { .dev = SPI3, .sck = IO_TAG(SPI3_SCK_PIN), .miso = IO_TAG(SPI3_MISO_PIN), .mosi = IO_TAG(SPI3_MOSI_PIN), .rcc = RCC_APB1(SPI3), .af = GPIO_AF_SPI3, false } #endif }; @@ -124,21 +124,11 @@ void spiInitDevice(SPIDevice device) IOConfigGPIOAF(IOGetByTag(spi->sck), SPI_IO_AF_CFG, spi->af); IOConfigGPIOAF(IOGetByTag(spi->miso), SPI_IO_AF_CFG, spi->af); IOConfigGPIOAF(IOGetByTag(spi->mosi), SPI_IO_AF_CFG, spi->af); - - if (spi->nss) { - IOInit(IOGetByTag(spi->nss), OWNER_SPI_CS, RESOURCE_INDEX(device)); - IOConfigGPIOAF(IOGetByTag(spi->nss), SPI_IO_CS_CFG, spi->af); - } #endif #if defined(STM32F10X) IOConfigGPIO(IOGetByTag(spi->sck), SPI_IO_AF_SCK_CFG); IOConfigGPIO(IOGetByTag(spi->miso), SPI_IO_AF_MISO_CFG); IOConfigGPIO(IOGetByTag(spi->mosi), SPI_IO_AF_MOSI_CFG); - - if (spi->nss) { - IOInit(IOGetByTag(spi->nss), OWNER_SPI_CS, RESOURCE_INDEX(device)); - IOConfigGPIO(IOGetByTag(spi->nss), SPI_IO_CS_CFG); - } #endif // Init SPI hardware @@ -168,11 +158,6 @@ void spiInitDevice(SPIDevice device) SPI_Init(spi->dev, &spiInit); SPI_Cmd(spi->dev, ENABLE); - - if (spi->nss) { - // Drive NSS high to disable connected SPI device. - IOHi(IOGetByTag(spi->nss)); - } } bool spiInit(SPIDevice device) diff --git a/src/main/drivers/bus_spi.h b/src/main/drivers/bus_spi.h index 4b0bbf22e8..9803ae77d9 100644 --- a/src/main/drivers/bus_spi.h +++ b/src/main/drivers/bus_spi.h @@ -71,7 +71,6 @@ typedef enum SPIDevice { typedef struct SPIDevice_s { SPI_TypeDef *dev; - ioTag_t nss; ioTag_t sck; ioTag_t mosi; ioTag_t miso; @@ -86,6 +85,7 @@ typedef struct SPIDevice_s { #endif } spiDevice_t; +void spiPreInitCs(ioTag_t iotag); bool spiInit(SPIDevice device); void spiSetDivisor(SPI_TypeDef *instance, uint16_t divisor); uint8_t spiTransferByte(SPI_TypeDef *instance, uint8_t in); diff --git a/src/main/drivers/bus_spi_config.c b/src/main/drivers/bus_spi_config.c new file mode 100644 index 0000000000..0bef12dd59 --- /dev/null +++ b/src/main/drivers/bus_spi_config.c @@ -0,0 +1,36 @@ +/* + * 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 . + */ + +#include +#include + +#include + +#include "drivers/bus_spi.h" +#include "drivers/io.h" + +// Bring a pin for possible CS line to pull-up state in preparation for +// sequential initialization by relevant drivers. +// Note that the pin is set to input for safety at this point. + +void spiPreInitCs(ioTag_t iotag) +{ + IO_t io = IOGetByTag(iotag); + if (io) { + IOConfigGPIO(io, IOCFG_IPU); + } +} diff --git a/src/main/drivers/bus_spi_hal.c b/src/main/drivers/bus_spi_hal.c index 598559e66b..e33b943214 100644 --- a/src/main/drivers/bus_spi_hal.c +++ b/src/main/drivers/bus_spi_hal.c @@ -70,10 +70,10 @@ static spiDevice_t spiHardwareMap[] = { - { .dev = SPI1, .nss = IO_TAG(SPI1_NSS_PIN), .sck = IO_TAG(SPI1_SCK_PIN), .miso = IO_TAG(SPI1_MISO_PIN), .mosi = IO_TAG(SPI1_MOSI_PIN), .rcc = RCC_APB2(SPI1), .af = GPIO_AF5_SPI1, .leadingEdge = false, .dmaIrqHandler = DMA2_ST3_HANDLER }, - { .dev = SPI2, .nss = IO_TAG(SPI2_NSS_PIN), .sck = IO_TAG(SPI2_SCK_PIN), .miso = IO_TAG(SPI2_MISO_PIN), .mosi = IO_TAG(SPI2_MOSI_PIN), .rcc = RCC_APB1(SPI2), .af = GPIO_AF5_SPI2, .leadingEdge = false, .dmaIrqHandler = DMA1_ST4_HANDLER }, - { .dev = SPI3, .nss = IO_TAG(SPI3_NSS_PIN), .sck = IO_TAG(SPI3_SCK_PIN), .miso = IO_TAG(SPI3_MISO_PIN), .mosi = IO_TAG(SPI3_MOSI_PIN), .rcc = RCC_APB1(SPI3), .af = GPIO_AF6_SPI3, .leadingEdge = false, .dmaIrqHandler = DMA1_ST7_HANDLER }, - { .dev = SPI4, .nss = IO_TAG(SPI4_NSS_PIN), .sck = IO_TAG(SPI4_SCK_PIN), .miso = IO_TAG(SPI4_MISO_PIN), .mosi = IO_TAG(SPI4_MOSI_PIN), .rcc = RCC_APB2(SPI4), .af = GPIO_AF5_SPI4, .leadingEdge = false, .dmaIrqHandler = DMA2_ST1_HANDLER } + { .dev = SPI1, .sck = IO_TAG(SPI1_SCK_PIN), .miso = IO_TAG(SPI1_MISO_PIN), .mosi = IO_TAG(SPI1_MOSI_PIN), .rcc = RCC_APB2(SPI1), .af = GPIO_AF5_SPI1, .leadingEdge = false, .dmaIrqHandler = DMA2_ST3_HANDLER }, + { .dev = SPI2, .sck = IO_TAG(SPI2_SCK_PIN), .miso = IO_TAG(SPI2_MISO_PIN), .mosi = IO_TAG(SPI2_MOSI_PIN), .rcc = RCC_APB1(SPI2), .af = GPIO_AF5_SPI2, .leadingEdge = false, .dmaIrqHandler = DMA1_ST4_HANDLER }, + { .dev = SPI3, .sck = IO_TAG(SPI3_SCK_PIN), .miso = IO_TAG(SPI3_MISO_PIN), .mosi = IO_TAG(SPI3_MOSI_PIN), .rcc = RCC_APB1(SPI3), .af = GPIO_AF6_SPI3, .leadingEdge = false, .dmaIrqHandler = DMA1_ST7_HANDLER }, + { .dev = SPI4, .sck = IO_TAG(SPI4_SCK_PIN), .miso = IO_TAG(SPI4_MISO_PIN), .mosi = IO_TAG(SPI4_MOSI_PIN), .rcc = RCC_APB2(SPI4), .af = GPIO_AF5_SPI4, .leadingEdge = false, .dmaIrqHandler = DMA2_ST1_HANDLER } }; SPIDevice spiDeviceByInstance(SPI_TypeDef *instance) @@ -159,21 +159,11 @@ void spiInitDevice(SPIDevice device) IOConfigGPIOAF(IOGetByTag(spi->sck), SPI_IO_AF_SCK_CFG_HIGH, spi->af); IOConfigGPIOAF(IOGetByTag(spi->miso), SPI_IO_AF_MISO_CFG, spi->af); IOConfigGPIOAF(IOGetByTag(spi->mosi), SPI_IO_AF_CFG, spi->af); - - if (spi->nss) { - IOInit(IOGetByTag(spi->nss), OWNER_SPI_CS, RESOURCE_INDEX(device)); - IOConfigGPIO(IOGetByTag(spi->nss), SPI_IO_CS_CFG); - } #endif #if defined(STM32F10X) IOConfigGPIO(IOGetByTag(spi->sck), SPI_IO_AF_SCK_CFG); IOConfigGPIO(IOGetByTag(spi->miso), SPI_IO_AF_MISO_CFG); IOConfigGPIO(IOGetByTag(spi->mosi), SPI_IO_AF_MOSI_CFG); - - if (spi->nss) { - IOInit(IOGetByTag(spi->nss), OWNER_SPI_CS, RESOURCE_INDEX(device)); - IOConfigGPIO(IOGetByTag(spi->nss), SPI_IO_CS_CFG); - } #endif spiHardwareMap[device].hspi.Instance = spi->dev; // Init SPI hardware @@ -198,11 +188,7 @@ void spiInitDevice(SPIDevice device) spiHardwareMap[device].hspi.Init.CLKPhase = SPI_PHASE_2EDGE; } - if (HAL_SPI_Init(&spiHardwareMap[device].hspi) == HAL_OK) - { - if (spi->nss) { - IOHi(IOGetByTag(spi->nss)); - } + if (HAL_SPI_Init(&spiHardwareMap[device].hspi) == HAL_OK) { } } diff --git a/src/main/drivers/max7456.c b/src/main/drivers/max7456.c index 11c69fe268..3ba0c60983 100644 --- a/src/main/drivers/max7456.c +++ b/src/main/drivers/max7456.c @@ -397,6 +397,7 @@ void max7456Init(const vcdProfile_t *pVcdProfile) #endif IOInit(max7456CsPin, OWNER_OSD_CS, 0); IOConfigGPIO(max7456CsPin, SPI_IO_CS_CFG); + IOHi(max7456CsPin); spiSetDivisor(MAX7456_SPI_INSTANCE, SPI_CLOCK_STANDARD); // force soft reset on Max7456 diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index 53a72e11e2..0b2c5f069a 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -184,6 +184,46 @@ static IO_t busSwitchResetPin = IO_NONE; } #endif +#ifdef USE_SPI +// Pre-initialize all CS pins to input with pull-up. +// It's sad that we can't do this with an initialized array, +// since we will be taking care of configurable CS pins shortly. + +void spiPreInit(void) +{ +#ifdef USE_ACC_SPI_MPU6000 + spiPreInitCs(IO_TAG(MPU6000_CS_PIN)); +#endif +#ifdef USE_ACC_SPI_MPU6500 + spiPreInitCs(IO_TAG(MPU6500_CS_PIN)); +#endif +#ifdef USE_GYRO_SPI_MPU9250 + spiPreInitCs(IO_TAG(MPU9250_CS_PIN)); +#endif +#ifdef USE_GYRO_SPI_ICM20689 + spiPreInitCs(IO_TAG(ICM20689_CS_PIN)); +#endif +#ifdef USE_ACCGYRO_BMI160 + spiPreInitCs(IO_TAG(BMI160_CS_PIN)); +#endif +#ifdef USE_MAX7456 + spiPreInitCs(IO_TAG(MAX7456_SPI_CS_PIN)); +#endif +#ifdef USE_SDCARD + spiPreInitCs(IO_TAG(SDCARD_SPI_CS_PIN)); +#endif +#ifdef USE_BARO_SPI_BMP280 + spiPreInitCs(IO_TAG(BMP280_CS_PIN)); +#endif +#ifdef RTC6705_CS_PIN // XXX VTX_RTC6705? Should use USE_ format. + spiPreInitCs(IO_TAG(RTC6705_CS_PIN)); +#endif +#ifdef M25P16_CS_PIN // XXX Should use USE_ format. + spiPreInitCs(IO_TAG(M25P16_CS_PIN)); +#endif +} +#endif + void init(void) { #ifdef USE_HAL_DRIVER @@ -349,6 +389,9 @@ void init(void) #else #ifdef USE_SPI + // Initialize CS lines and keep them high + spiPreInit(); + #ifdef USE_SPI_DEVICE_1 spiInit(SPIDEV_1); #endif diff --git a/src/main/target/CJMCU/initialisation.c b/src/main/target/CJMCU/initialisation.c index 01986ce33e..4f6b7ecbe3 100644 --- a/src/main/target/CJMCU/initialisation.c +++ b/src/main/target/CJMCU/initialisation.c @@ -24,9 +24,12 @@ #include "drivers/bus_spi.h" #include "io/serial.h" +extern void spiPreInit(void); // XXX In fc/fc_init.c + void targetBusInit(void) { #if defined(USE_SPI) && defined(USE_SPI_DEVICE_1) + spiPreInit(); spiInit(SPIDEV_1); #endif diff --git a/src/main/target/NAZE/initialisation.c b/src/main/target/NAZE/initialisation.c index 6f30d32602..c6b37d0544 100644 --- a/src/main/target/NAZE/initialisation.c +++ b/src/main/target/NAZE/initialisation.c @@ -25,9 +25,12 @@ #include "io/serial.h" #include "hardware_revision.h" +extern void spiPreInit(void); // XXX In fc/fc_init.c + void targetBusInit(void) { #ifdef USE_SPI + spiPreInit(); #ifdef USE_SPI_DEVICE_2 spiInit(SPIDEV_2); #endif From 559079ff312dafcc727be5ee5ee00e8f5ff465ea Mon Sep 17 00:00:00 2001 From: mikeller Date: Tue, 20 Jun 2017 01:33:22 +1200 Subject: [PATCH 11/25] Fixup Dshot / Proshot implementation. --- src/main/drivers/pwm_output.c | 64 +++++++++++++++++++--- src/main/drivers/pwm_output.h | 11 +++- src/main/drivers/pwm_output_dshot.c | 61 ++------------------- src/main/drivers/pwm_output_dshot_hal.c | 72 +++---------------------- src/main/flight/mixer.c | 1 + 5 files changed, 78 insertions(+), 131 deletions(-) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index a7da53c8b4..de9126c8f1 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -31,12 +31,14 @@ #define MULTISHOT_5US_PW (MULTISHOT_TIMER_MHZ * 5) #define MULTISHOT_20US_MULT (MULTISHOT_TIMER_MHZ * 20 / 1000.0f) -#define DSHOT_MAX_COMMAND 47 - static pwmWriteFuncPtr pwmWritePtr; static pwmOutputPort_t motors[MAX_SUPPORTED_MOTORS]; static pwmCompleteWriteFuncPtr pwmCompleteWritePtr = NULL; +#ifdef USE_DSHOT +loadDmaBufferFuncPtr loadDmaBufferPtr; +#endif + #ifdef USE_SERVOS static pwmOutputPort_t servos[MAX_SUPPORTED_SERVOS]; #endif @@ -47,6 +49,7 @@ static uint16_t freqBeep=0; #endif bool pwmMotorsEnabled = false; +bool isDigital = false; static void pwmOCConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t value, uint8_t output) { @@ -156,6 +159,33 @@ static void pwmWriteMultiShot(uint8_t index, float value) *motors[index].ccr = lrintf(((value-1000) * MULTISHOT_20US_MULT) + MULTISHOT_5US_PW); } +#ifdef USE_DSHOT +static void pwmWriteDigital(uint8_t index, float value) +{ + pwmWriteDigitalInt(index, lrintf(value)); +} + +static uint8_t loadDmaBufferDshot(motorDmaOutput_t *const motor, uint16_t packet) +{ + for (int i = 0; i < 16; i++) { + motor->dmaBuffer[i] = (packet & 0x8000) ? MOTOR_BIT_1 : MOTOR_BIT_0; // MSB first + packet <<= 1; + } + + return DSHOT_DMA_BUFFER_SIZE; +} + +static uint8_t loadDmaBufferProshot(motorDmaOutput_t *const motor, uint16_t packet) +{ + for (int i = 0; i < 4; i++) { + motor->dmaBuffer[i] = PROSHOT_BASE_SYMBOL + ((packet & 0xF000) >> 12) * PROSHOT_BIT_WIDTH; // Most significant nibble first + packet <<= 4; // Shift 4 bits + } + + return PROSHOT_DMA_BUFFER_SIZE; +} +#endif + void pwmWriteMotor(uint8_t index, float value) { if (pwmMotorsEnabled) { @@ -218,7 +248,6 @@ void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8 uint32_t timerMhzCounter = 0; bool useUnsyncedPwm = motorConfig->useUnsyncedPwm; - bool isDigital = false; switch (motorConfig->motorPwmProtocol) { default: @@ -248,7 +277,8 @@ void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8 break; #ifdef USE_DSHOT case PWM_TYPE_PROSHOT1000: - pwmWritePtr = pwmWriteProShot; + pwmWritePtr = pwmWriteDigital; + loadDmaBufferPtr = loadDmaBufferProshot; pwmCompleteWritePtr = pwmCompleteDigitalMotorUpdate; isDigital = true; break; @@ -256,7 +286,8 @@ void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8 case PWM_TYPE_DSHOT600: case PWM_TYPE_DSHOT300: case PWM_TYPE_DSHOT150: - pwmWritePtr = pwmWriteDshot; + pwmWritePtr = pwmWriteDigital; + loadDmaBufferPtr = loadDmaBufferDshot; pwmCompleteWritePtr = pwmCompleteDigitalMotorUpdate; isDigital = true; break; @@ -343,7 +374,7 @@ uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType) void pwmWriteDshotCommand(uint8_t index, uint8_t command) { - if (command <= DSHOT_MAX_COMMAND) { + if (isDigital && (command <= DSHOT_MAX_COMMAND)) { motorDmaOutput_t *const motor = getMotorDmaOutput(index); unsigned repeats; @@ -364,13 +395,32 @@ void pwmWriteDshotCommand(uint8_t index, uint8_t command) for (; repeats; repeats--) { motor->requestTelemetry = true; - pwmWritePtr(index, command); + pwmWriteDigitalInt(index, command); pwmCompleteMotorUpdate(0); delay(1); } } } + +uint16_t prepareDshotPacket(motorDmaOutput_t *const motor, const uint16_t value) +{ + uint16_t packet = (value << 1) | (motor->requestTelemetry ? 1 : 0); + motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row + + // compute checksum + int csum = 0; + int csum_data = packet; + for (int i = 0; i < 3; i++) { + csum ^= csum_data; // xor data by nibbles + csum_data >>= 4; + } + csum &= 0xf; + // append checksum + packet = (packet << 4) | csum; + + return packet; +} #endif #ifdef USE_SERVOS diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index 1c3e792a49..dd8e642eb4 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -28,6 +28,8 @@ #define MAX_SUPPORTED_SERVOS 8 #endif +#define DSHOT_MAX_COMMAND 47 + typedef enum { DSHOT_CMD_MOTOR_STOP = 0, DSHOT_CMD_BEEP1, @@ -165,10 +167,15 @@ void servoDevInit(const servoDevConfig_t *servoDevConfig); void pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse); #ifdef USE_DSHOT +typedef uint8_t(*loadDmaBufferFuncPtr)(motorDmaOutput_t *const motor, uint16_t packet); // function pointer used to encode a digital motor value into the DMA buffer representation + +uint16_t prepareDshotPacket(motorDmaOutput_t *const motor, uint16_t value); + +extern loadDmaBufferFuncPtr loadDmaBufferPtr; + uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType); void pwmWriteDshotCommand(uint8_t index, uint8_t command); -void pwmWriteProShot(uint8_t index, float value); -void pwmWriteDshot(uint8_t index, float value); +void pwmWriteDigitalInt(uint8_t index, uint16_t value); void pwmDigitalMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output); void pwmCompleteDigitalMotorUpdate(uint8_t motorCount); #endif diff --git a/src/main/drivers/pwm_output_dshot.c b/src/main/drivers/pwm_output_dshot.c index c75ac74a03..5a18ae0623 100644 --- a/src/main/drivers/pwm_output_dshot.c +++ b/src/main/drivers/pwm_output_dshot.c @@ -54,70 +54,19 @@ uint8_t getTimerIndex(TIM_TypeDef *timer) return dmaMotorTimerCount-1; } -void pwmWriteDshot(uint8_t index, float value) +void pwmWriteDigitalInt(uint8_t index, uint16_t value) { - const uint16_t digitalValue = lrintf(value); - - motorDmaOutput_t * const motor = &dmaMotors[index]; + motorDmaOutput_t *const motor = &dmaMotors[index]; if (!motor->timerHardware || !motor->timerHardware->dmaRef) { return; } - uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0); - motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row + uint16_t packet = prepareDshotPacket(motor, value); - // compute checksum - int csum = 0; - int csum_data = packet; - for (int i = 0; i < 3; i++) { - csum ^= csum_data; // xor data by nibbles - csum_data >>= 4; - } - csum &= 0xf; - // append checksum - packet = (packet << 4) | csum; - // generate pulses for whole packet - for (int i = 0; i < 16; i++) { - motor->dmaBuffer[i] = (packet & 0x8000) ? MOTOR_BIT_1 : MOTOR_BIT_0; // MSB first - packet <<= 1; - } + uint8_t bufferSize = loadDmaBufferPtr(motor, packet); - DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, DSHOT_DMA_BUFFER_SIZE); - DMA_Cmd(motor->timerHardware->dmaRef, ENABLE); -} - -void pwmWriteProShot(uint8_t index, float value) -{ - const uint16_t digitalValue = lrintf(value); - - motorDmaOutput_t * const motor = &dmaMotors[index]; - - if (!motor->timerHardware || !motor->timerHardware->dmaRef) { - return; - } - - uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0); - motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row - - // compute checksum - int csum = 0; - int csum_data = packet; - for (int i = 0; i < 3; i++) { - csum ^= csum_data; // xor data by nibbles - csum_data >>= 4; - } - csum &= 0xf; - // append checksum - packet = (packet << 4) | csum; - - // generate pulses for Proshot - for (int i = 0; i < 4; i++) { - motor->dmaBuffer[i] = PROSHOT_BASE_SYMBOL + ((packet & 0xF000) >> 12) * PROSHOT_BIT_WIDTH; // Most significant nibble first - packet <<= 4; // Shift 4 bits - } - - DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, PROSHOT_DMA_BUFFER_SIZE); + DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, bufferSize); DMA_Cmd(motor->timerHardware->dmaRef, ENABLE); } diff --git a/src/main/drivers/pwm_output_dshot_hal.c b/src/main/drivers/pwm_output_dshot_hal.c index c2ff4737e1..a80c944290 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -49,85 +49,25 @@ uint8_t getTimerIndex(TIM_TypeDef *timer) return dmaMotorTimerCount - 1; } -void pwmWriteDshot(uint8_t index, float value) +void pwmWriteDigitalInt(uint8_t index, uint16_t value) { - const uint16_t digitalValue = lrintf(value); - - motorDmaOutput_t * const motor = &dmaMotors[index]; + motorDmaOutput_t *const motor = &dmaMotors[index]; if (!motor->timerHardware || !motor->timerHardware->dmaRef) { return; } - uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0); - motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row + uint16_t packet = prepareDshotPacket(motor, value); - // compute checksum - int csum = 0; - int csum_data = packet; - for (int i = 0; i < 3; i++) { - csum ^= csum_data; // xor data by nibbles - csum_data >>= 4; - } - csum &= 0xf; - // append checksum - packet = (packet << 4) | csum; - // generate pulses for whole packet - for (int i = 0; i < 16; i++) { - motor->dmaBuffer[i] = (packet & 0x8000) ? MOTOR_BIT_1 : MOTOR_BIT_0; // MSB first - packet <<= 1; - } + uint8_t bufferSize = loadDmaBufferPtr(motor, packet); if (motor->timerHardware->output & TIMER_OUTPUT_N_CHANNEL) { - if (HAL_TIMEx_PWMN_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, DSHOT_DMA_BUFFER_SIZE) != HAL_OK) { + if (HAL_TIMEx_PWMN_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, bufferSize) != HAL_OK) { /* Starting PWM generation Error */ return; } } else { - if (HAL_TIM_PWM_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, DSHOT_DMA_BUFFER_SIZE) != HAL_OK) { - /* Starting PWM generation Error */ - return; - } - } -} - -void pwmWriteProShot(uint8_t index, float value) -{ - const uint16_t digitalValue = lrintf(value); - - motorDmaOutput_t * const motor = &dmaMotors[index]; - - if (!motor->timerHardware || !motor->timerHardware->dmaRef) { - return; - } - - uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0); - motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row - - // compute checksum - int csum = 0; - int csum_data = packet; - for (int i = 0; i < 3; i++) { - csum ^= csum_data; // xor data by nibbles - csum_data >>= 4; - } - csum &= 0xf; - // append checksum - packet = (packet << 4) | csum; - - // generate pulses for Proshot - for (int i = 0; i < 4; i++) { - motor->dmaBuffer[i] = PROSHOT_BASE_SYMBOL + ((packet & 0xF000) >> 12) * PROSHOT_BIT_WIDTH; // Most significant nibble first - packet <<= 4; // Shift 4 bits - } - - if (motor->timerHardware->output & TIMER_OUTPUT_N_CHANNEL) { - if (HAL_TIMEx_PWMN_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, PROSHOT_DMA_BUFFER_SIZE) != HAL_OK) { - /* Starting PWM generation Error */ - return; - } - } else { - if (HAL_TIM_PWM_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, PROSHOT_DMA_BUFFER_SIZE) != HAL_OK) { + if (HAL_TIM_PWM_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, bufferSize) != HAL_OK) { /* Starting PWM generation Error */ return; } diff --git a/src/main/flight/mixer.c b/src/main/flight/mixer.c index 818b2e9fb8..fa3382475a 100755 --- a/src/main/flight/mixer.c +++ b/src/main/flight/mixer.c @@ -339,6 +339,7 @@ bool mixerIsOutputSaturated(int axis, float errorRate) bool isMotorProtocolDshot(void) { #ifdef USE_DSHOT switch(motorConfig()->dev.motorPwmProtocol) { + case PWM_TYPE_PROSHOT1000: case PWM_TYPE_DSHOT1200: case PWM_TYPE_DSHOT600: case PWM_TYPE_DSHOT300: From 76869eb3dd38f2e2e2a5aa106ed1117901b6312b Mon Sep 17 00:00:00 2001 From: mikeller Date: Wed, 21 Jun 2017 00:20:46 +1200 Subject: [PATCH 12/25] Changed function pointer semantics. --- src/main/drivers/pwm_output.c | 40 ++++++++++++------------- src/main/drivers/pwm_output.h | 8 ++--- src/main/drivers/pwm_output_dshot.c | 2 +- src/main/drivers/pwm_output_dshot_hal.c | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index de9126c8f1..2325890609 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -31,12 +31,12 @@ #define MULTISHOT_5US_PW (MULTISHOT_TIMER_MHZ * 5) #define MULTISHOT_20US_MULT (MULTISHOT_TIMER_MHZ * 20 / 1000.0f) -static pwmWriteFuncPtr pwmWritePtr; +static pwmWriteFunc *pwmWrite; static pwmOutputPort_t motors[MAX_SUPPORTED_MOTORS]; -static pwmCompleteWriteFuncPtr pwmCompleteWritePtr = NULL; +static pwmCompleteWriteFunc *pwmCompleteWrite = NULL; #ifdef USE_DSHOT -loadDmaBufferFuncPtr loadDmaBufferPtr; +loadDmaBufferFunc *loadDmaBuffer; #endif #ifdef USE_SERVOS @@ -189,7 +189,7 @@ static uint8_t loadDmaBufferProshot(motorDmaOutput_t *const motor, uint16_t pack void pwmWriteMotor(uint8_t index, float value) { if (pwmMotorsEnabled) { - pwmWritePtr(index, value); + pwmWrite(index, value); } } @@ -212,7 +212,7 @@ void pwmDisableMotors(void) void pwmEnableMotors(void) { /* check motors can be enabled */ - pwmMotorsEnabled = (pwmWritePtr != pwmWriteUnused); + pwmMotorsEnabled = (pwmWrite != &pwmWriteUnused); } bool pwmAreMotorsEnabled(void) @@ -239,7 +239,7 @@ static void pwmCompleteOneshotMotorUpdate(uint8_t motorCount) void pwmCompleteMotorUpdate(uint8_t motorCount) { - pwmCompleteWritePtr(motorCount); + pwmCompleteWrite(motorCount); } void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount) @@ -253,49 +253,49 @@ void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8 default: case PWM_TYPE_ONESHOT125: timerMhzCounter = ONESHOT125_TIMER_MHZ; - pwmWritePtr = pwmWriteOneShot125; + pwmWrite = &pwmWriteOneShot125; break; case PWM_TYPE_ONESHOT42: timerMhzCounter = ONESHOT42_TIMER_MHZ; - pwmWritePtr = pwmWriteOneShot42; + pwmWrite = &pwmWriteOneShot42; break; case PWM_TYPE_MULTISHOT: timerMhzCounter = MULTISHOT_TIMER_MHZ; - pwmWritePtr = pwmWriteMultiShot; + pwmWrite = &pwmWriteMultiShot; break; case PWM_TYPE_BRUSHED: timerMhzCounter = PWM_BRUSHED_TIMER_MHZ; - pwmWritePtr = pwmWriteBrushed; + pwmWrite = &pwmWriteBrushed; useUnsyncedPwm = true; idlePulse = 0; break; case PWM_TYPE_STANDARD: timerMhzCounter = PWM_TIMER_MHZ; - pwmWritePtr = pwmWriteStandard; + pwmWrite = &pwmWriteStandard; useUnsyncedPwm = true; idlePulse = 0; break; #ifdef USE_DSHOT case PWM_TYPE_PROSHOT1000: - pwmWritePtr = pwmWriteDigital; - loadDmaBufferPtr = loadDmaBufferProshot; - pwmCompleteWritePtr = pwmCompleteDigitalMotorUpdate; + pwmWrite = &pwmWriteDigital; + loadDmaBuffer = &loadDmaBufferProshot; + pwmCompleteWrite = &pwmCompleteDigitalMotorUpdate; isDigital = true; break; case PWM_TYPE_DSHOT1200: case PWM_TYPE_DSHOT600: case PWM_TYPE_DSHOT300: case PWM_TYPE_DSHOT150: - pwmWritePtr = pwmWriteDigital; - loadDmaBufferPtr = loadDmaBufferDshot; - pwmCompleteWritePtr = pwmCompleteDigitalMotorUpdate; + pwmWrite = &pwmWriteDigital; + loadDmaBuffer = &loadDmaBufferDshot; + pwmCompleteWrite = &pwmCompleteDigitalMotorUpdate; isDigital = true; break; #endif } if (!isDigital) { - pwmCompleteWritePtr = useUnsyncedPwm ? pwmCompleteWriteUnused : pwmCompleteOneshotMotorUpdate; + pwmCompleteWrite = useUnsyncedPwm ? &pwmCompleteWriteUnused : &pwmCompleteOneshotMotorUpdate; } for (int motorIndex = 0; motorIndex < MAX_SUPPORTED_MOTORS && motorIndex < motorCount; motorIndex++) { @@ -304,8 +304,8 @@ void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8 if (timerHardware == NULL) { /* not enough motors initialised for the mixer or a break in the motors */ - pwmWritePtr = pwmWriteUnused; - pwmCompleteWritePtr = pwmCompleteWriteUnused; + pwmWrite = &pwmWriteUnused; + pwmCompleteWrite = &pwmCompleteWriteUnused; /* TODO: block arming and add reason system cannot arm */ return; } diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index dd8e642eb4..16d7f37c36 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -133,8 +133,8 @@ motorDmaOutput_t *getMotorDmaOutput(uint8_t index); extern bool pwmMotorsEnabled; struct timerHardware_s; -typedef void(*pwmWriteFuncPtr)(uint8_t index, float value); // function pointer used to write motors -typedef void(*pwmCompleteWriteFuncPtr)(uint8_t motorCount); // function pointer used after motors are written +typedef void pwmWriteFunc(uint8_t index, float value); // function pointer used to write motors +typedef void pwmCompleteWriteFunc(uint8_t motorCount); // function pointer used after motors are written typedef struct { volatile timCCR_t *ccr; @@ -167,11 +167,11 @@ void servoDevInit(const servoDevConfig_t *servoDevConfig); void pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse); #ifdef USE_DSHOT -typedef uint8_t(*loadDmaBufferFuncPtr)(motorDmaOutput_t *const motor, uint16_t packet); // function pointer used to encode a digital motor value into the DMA buffer representation +typedef uint8_t loadDmaBufferFunc(motorDmaOutput_t *const motor, uint16_t packet); // function pointer used to encode a digital motor value into the DMA buffer representation uint16_t prepareDshotPacket(motorDmaOutput_t *const motor, uint16_t value); -extern loadDmaBufferFuncPtr loadDmaBufferPtr; +extern loadDmaBufferFunc *loadDmaBuffer; uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType); void pwmWriteDshotCommand(uint8_t index, uint8_t command); diff --git a/src/main/drivers/pwm_output_dshot.c b/src/main/drivers/pwm_output_dshot.c index 5a18ae0623..2c97bc0ef4 100644 --- a/src/main/drivers/pwm_output_dshot.c +++ b/src/main/drivers/pwm_output_dshot.c @@ -64,7 +64,7 @@ void pwmWriteDigitalInt(uint8_t index, uint16_t value) uint16_t packet = prepareDshotPacket(motor, value); - uint8_t bufferSize = loadDmaBufferPtr(motor, packet); + uint8_t bufferSize = loadDmaBuffer(motor, packet); DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, bufferSize); DMA_Cmd(motor->timerHardware->dmaRef, ENABLE); diff --git a/src/main/drivers/pwm_output_dshot_hal.c b/src/main/drivers/pwm_output_dshot_hal.c index a80c944290..de270044bc 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -59,7 +59,7 @@ void pwmWriteDigitalInt(uint8_t index, uint16_t value) uint16_t packet = prepareDshotPacket(motor, value); - uint8_t bufferSize = loadDmaBufferPtr(motor, packet); + uint8_t bufferSize = loadDmaBuffer(motor, packet); if (motor->timerHardware->output & TIMER_OUTPUT_N_CHANNEL) { if (HAL_TIMEx_PWMN_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, bufferSize) != HAL_OK) { From 1cda1b44ab1cdbf92383b0068b0de997431c8028 Mon Sep 17 00:00:00 2001 From: jflyper Date: Tue, 20 Jun 2017 22:20:59 +0900 Subject: [PATCH 13/25] Created OWNER_SPI_PREINIT --- src/main/drivers/bus_spi_config.c | 1 + src/main/drivers/resource.c | 3 ++- src/main/drivers/resource.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/bus_spi_config.c b/src/main/drivers/bus_spi_config.c index 0bef12dd59..68643797ff 100644 --- a/src/main/drivers/bus_spi_config.c +++ b/src/main/drivers/bus_spi_config.c @@ -31,6 +31,7 @@ void spiPreInitCs(ioTag_t iotag) { IO_t io = IOGetByTag(iotag); if (io) { + IOInit(io, OWNER_SPI_PREINIT, 0); IOConfigGPIO(io, IOCFG_IPU); } } diff --git a/src/main/drivers/resource.c b/src/main/drivers/resource.c index 06ede3fdf9..40b9911b28 100644 --- a/src/main/drivers/resource.c +++ b/src/main/drivers/resource.c @@ -61,6 +61,7 @@ const char * const ownerNames[OWNER_TOTAL_COUNT] = { "LED_STRIP", "TRANSPONDER", "VTX", - "COMPASS_CS" + "COMPASS_CS", + "SPI_PREINIT", }; diff --git a/src/main/drivers/resource.h b/src/main/drivers/resource.h index f91aa682e7..871300bd70 100644 --- a/src/main/drivers/resource.h +++ b/src/main/drivers/resource.h @@ -62,6 +62,7 @@ typedef enum { OWNER_TRANSPONDER, OWNER_VTX, OWNER_COMPASS_CS, + OWNER_SPI_PREINIT, OWNER_TOTAL_COUNT } resourceOwner_e; From 8a03089569c4f2299489fc2f70bcd8f59bd14e58 Mon Sep 17 00:00:00 2001 From: jflyper Date: Wed, 21 Jun 2017 00:12:41 +0900 Subject: [PATCH 14/25] More SPI devices --- src/main/fc/fc_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index 0b2c5f069a..af4e6b60a4 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -206,6 +206,9 @@ void spiPreInit(void) #ifdef USE_ACCGYRO_BMI160 spiPreInitCs(IO_TAG(BMI160_CS_PIN)); #endif +#ifdef USE_GYRO_L3GD20 + spiPreInitCs(IO_TAG(L3GD20_CS_PIN)); +#endif #ifdef USE_MAX7456 spiPreInitCs(IO_TAG(MAX7456_SPI_CS_PIN)); #endif @@ -215,6 +218,15 @@ void spiPreInit(void) #ifdef USE_BARO_SPI_BMP280 spiPreInitCs(IO_TAG(BMP280_CS_PIN)); #endif +#ifdef USE_BARO_SPI_MS5611 + spiPreInitCs(IO_TAG(MS5611_CS_PIN)); +#endif +#ifdef USE_MAG_SPI_HMC5883 + spiPreInitCs(IO_TAG(HMC5883_CS_PIN)); +#endif +#ifdef USE_MAG_SPI_AK8963 + spiPreInitCs(IO_TAG(AK8963_CS_PIN)); +#endif #ifdef RTC6705_CS_PIN // XXX VTX_RTC6705? Should use USE_ format. spiPreInitCs(IO_TAG(RTC6705_CS_PIN)); #endif From 7d2c27821328d1e45144edf690bba84f0e4aa594 Mon Sep 17 00:00:00 2001 From: Cheng Lin Date: Tue, 20 Jun 2017 11:57:24 -0400 Subject: [PATCH 15/25] ADD ICM-20602 support for CLRACINGF7 --- src/main/target/CLRACINGF7/target.c | 14 +++++++------- src/main/target/CLRACINGF7/target.h | 23 ++++++++++++++++++++--- src/main/target/CLRACINGF7/target.mk | 4 ++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/main/target/CLRACINGF7/target.c b/src/main/target/CLRACINGF7/target.c index 1ff2591a00..710a85c900 100644 --- a/src/main/target/CLRACINGF7/target.c +++ b/src/main/target/CLRACINGF7/target.c @@ -30,14 +30,14 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { DEF_TIM(TIM4, CH3, PB8, TIM_USE_PPM, TIMER_INPUT_ENABLED, 0), // PPM -DMA1_ST7 - DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 1), // PWM1 - DMA1_ST6 - DEF_TIM(TIM8, CH3, PC8, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 1), // PWM2 - DMA2_ST2 - DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0), // PWM3 - DMA1_ST1 - DEF_TIM(TIM3, CH4, PC9, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0), // PWM4 - DMA1_ST2 - DEF_TIM(TIM1, CH1, PA8, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 2), // PWM5 - DMA2_ST3 - DEF_TIM(TIM4, CH1, PB6, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0), // PWM6 - DMA1_ST0 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 1), // PWM1 - DMA1_ST6 D(1, 7, 3),D(1, 6, 3) + DEF_TIM(TIM8, CH3, PC8, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 1), // PWM2 - DMA2_ST2 D(2, 4, 7),D(2, 2, 0) + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0), // PWM3 - DMA1_ST1 D(1, 1, 3) + DEF_TIM(TIM3, CH4, PC9, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0), // PWM4 - DMA1_ST2 D(1, 2, 5) + DEF_TIM(TIM1, CH1, PA8, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 2), // PWM5 - DMA2_ST3 D(2, 6, 0),D(2, 1, 6),D(2, 3, 6) + DEF_TIM(TIM4, CH1, PB6, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0), // PWM6 - DMA1_ST0 D(1, 0, 2) - DEF_TIM(TIM1, CH3N, PB1, TIM_USE_MOTOR | TIM_USE_LED, TIMER_OUTPUT_ENABLED | TIMER_OUTPUT_INVERTED, 0), // S5_OUT - DMA2_ST6 + DEF_TIM(TIM1, CH3N, PB1, TIM_USE_MOTOR | TIM_USE_LED, TIMER_OUTPUT_ENABLED | TIMER_OUTPUT_INVERTED, 0), // S5_OUT - DMA2_ST6 D(2, 6, 0),D(2, 6, 6) }; diff --git a/src/main/target/CLRACINGF7/target.h b/src/main/target/CLRACINGF7/target.h index 62ab3fe003..09f6c9ec7b 100644 --- a/src/main/target/CLRACINGF7/target.h +++ b/src/main/target/CLRACINGF7/target.h @@ -42,11 +42,28 @@ #define USE_ACC_SPI_MPU6000 #define GYRO #define USE_GYRO_SPI_MPU6000 + #define GYRO_MPU6000_ALIGN CW0_DEG #define ACC_MPU6000_ALIGN CW0_DEG #define MPU6000_CS_PIN PA4 #define MPU6000_SPI_INSTANCE SPI1 +// ICM-20602 +#define USE_ACC_MPU6500 +#define USE_ACC_SPI_MPU6500 +#define USE_GYRO_MPU6500 +#define USE_GYRO_SPI_MPU6500 + +#define ACC_MPU6500_ALIGN CW0_DEG +#define GYRO_MPU6500_ALIGN CW0_DEG +#define MPU6500_CS_PIN SPI1_NSS_PIN +#define MPU6500_SPI_INSTANCE SPI1 + +// MPU interrupts +#define USE_EXTI +#define MPU_INT_EXTI PC4 +#define USE_MPU_DATA_READY_SIGNAL + #define OSD #define USE_MAX7456 #define MAX7456_SPI_INSTANCE SPI3 @@ -64,8 +81,8 @@ #define SDCARD_SPI_FULL_SPEED_CLOCK_DIVIDER 8 // 27MHz #define SDCARD_DMA_CHANNEL_TX DMA1_Stream4 -#define SDCARD_DMA_CHANNEL_TX_COMPLETE_FLAG DMA_FLAG_TCIF1_5 -#define SDCARD_DMA_CLK RCC_AHB1Periph_DMA2 +#define SDCARD_DMA_CHANNEL_TX_COMPLETE_FLAG DMA_FLAG_TCIF1_4 +#define SDCARD_DMA_CLK RCC_AHB1Periph_DMA1 #define SDCARD_DMA_CHANNEL DMA_CHANNEL_0 #define USE_VCP @@ -116,7 +133,7 @@ #define CURRENT_METER_ADC_PIN PC1 #define VBAT_ADC_PIN PC2 #define RSSI_ADC_PIN PC3 -#define CURRENT_METER_SCALE_DEFAULT 250 // 3/120A = 25mv/A +#define CURRENT_METER_SCALE_DEFAULT 250 // 3.3/120A = 25mv/A // LED strip configuration. #define LED_STRIP diff --git a/src/main/target/CLRACINGF7/target.mk b/src/main/target/CLRACINGF7/target.mk index 719339dc72..ab85a4ba98 100644 --- a/src/main/target/CLRACINGF7/target.mk +++ b/src/main/target/CLRACINGF7/target.mk @@ -1,8 +1,12 @@ F7X2RE_TARGETS += $(TARGET) FEATURES += SDCARD VCP TARGET_SRC = \ + drivers/accgyro/accgyro_mpu.c \ drivers/accgyro/accgyro_spi_icm20689.c\ + drivers/accgyro/accgyro_mpu6500.c \ + drivers/accgyro/accgyro_spi_mpu6500.c \ drivers/accgyro/accgyro_spi_mpu6000.c \ drivers/light_ws2811strip.c \ drivers/light_ws2811strip_hal.c \ drivers/max7456.c + From a2718a91cd198d8e3ee447890891886f5145e6d2 Mon Sep 17 00:00:00 2001 From: jflyper Date: Wed, 21 Jun 2017 03:12:05 +0900 Subject: [PATCH 16/25] Even more devices (RX_SPI and RX_NRF24) --- src/main/fc/fc_init.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index af4e6b60a4..0423605cb1 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -233,6 +233,12 @@ void spiPreInit(void) #ifdef M25P16_CS_PIN // XXX Should use USE_ format. spiPreInitCs(IO_TAG(M25P16_CS_PIN)); #endif +#ifdef USE_RX_NRF24 + spiPreInitCs(IO_TAG(RX_CE_PIN)); +#endif +#if defined(USE_RX_SPI) && !defined(USE_RX_SOFTSPI) + spiPreInitCs(IO_TAG(RX_NSS_PIN)); +#endif } #endif From 5ba8d39ad8170b798123c8936787d20f42ac88a0 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Wed, 21 Jun 2017 10:45:06 +0100 Subject: [PATCH 17/25] Fixes broken if-else from 41668fa --- src/main/io/osd.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 675ec10630..c06a5202a3 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -644,12 +644,7 @@ static void osdDrawElements(void) if (IS_RC_MODE_ACTIVE(BOXOSD)) return; -#ifdef CMS - else if (sensors(SENSOR_ACC) || displayIsGrabbed(osdDisplayPort)) -#else - else if (sensors(SENSOR_ACC)) -#endif - { + if (sensors(SENSOR_ACC)) { osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON); } @@ -683,12 +678,7 @@ static void osdDrawElements(void) osdDrawSingleElement(OSD_COMPASS_BAR); #ifdef GPS -#ifdef CMS - if (sensors(SENSOR_GPS) || displayIsGrabbed(osdDisplayPort)) -#else - if (sensors(SENSOR_GPS)) -#endif - { + if (sensors(SENSOR_GPS)) { osdDrawSingleElement(OSD_GPS_SATS); osdDrawSingleElement(OSD_GPS_SPEED); osdDrawSingleElement(OSD_GPS_LAT); From 858d910d07784706618bab9b0f66db352302275b Mon Sep 17 00:00:00 2001 From: jflyper Date: Wed, 21 Jun 2017 17:53:18 +0900 Subject: [PATCH 18/25] Make I2C bus for OLED display configurable --- src/main/config/parameter_group_ids.h | 3 ++- src/main/drivers/bus_i2c.h | 7 +++++++ src/main/drivers/display_ug2864hsweg01.c | 25 +++++++++++++++++++----- src/main/drivers/display_ug2864hsweg01.h | 9 +++++++++ src/main/fc/settings.c | 5 +++++ 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main/config/parameter_group_ids.h b/src/main/config/parameter_group_ids.h index e4b0bb3f59..e7949d38b7 100644 --- a/src/main/config/parameter_group_ids.h +++ b/src/main/config/parameter_group_ids.h @@ -107,7 +107,8 @@ #define PG_SONAR_CONFIG 516 #define PG_ESC_SENSOR_CONFIG 517 #define PG_I2C_CONFIG 518 -#define PG_BETAFLIGHT_END 518 +#define PG_OLED_DISPLAY_CONFIG 519 +#define PG_BETAFLIGHT_END 519 // OSD configuration (subject to change) diff --git a/src/main/drivers/bus_i2c.h b/src/main/drivers/bus_i2c.h index bd27125994..d92a390b32 100644 --- a/src/main/drivers/bus_i2c.h +++ b/src/main/drivers/bus_i2c.h @@ -45,6 +45,13 @@ typedef enum I2CDevice { #define I2CDEV_COUNT 4 #endif +// Macro to convert CLI bus number to I2CDevice. +#define I2C_CFG_TO_DEV(x) ((x) - 1) + +// I2C device address range in 8-bit address mode +#define I2C_ADDR8_MIN 8 +#define I2C_ADDR8_MAX 119 + typedef struct i2cConfig_s { ioTag_t ioTagScl[I2CDEV_COUNT]; ioTag_t ioTagSda[I2CDEV_COUNT]; diff --git a/src/main/drivers/display_ug2864hsweg01.c b/src/main/drivers/display_ug2864hsweg01.c index b9ac8528e5..fd0c617c49 100644 --- a/src/main/drivers/display_ug2864hsweg01.c +++ b/src/main/drivers/display_ug2864hsweg01.c @@ -24,16 +24,31 @@ #include "display_ug2864hsweg01.h" +#include "config/parameter_group.h" +#include "config/parameter_group_ids.h" + #ifdef USE_I2C_OLED_DISPLAY #if !defined(OLED_I2C_INSTANCE) #if defined(I2C_DEVICE) #define OLED_I2C_INSTANCE I2C_DEVICE #else -#define OLED_I2C_INSTANCE I2C_NONE +#define OLED_I2C_INSTANCE I2CINVALID #endif #endif +#define OLED_address 0x3C // OLED at address 0x3C in 7bit + +PG_REGISTER_WITH_RESET_TEMPLATE(oledDisplayConfig_t, oledDisplayConfig, PG_OLED_DISPLAY_CONFIG, 0); + +PG_RESET_TEMPLATE(oledDisplayConfig_t, oledDisplayConfig, + .bus = OLED_I2C_INSTANCE, + .address = OLED_address, +); + +static I2CDevice i2cBus = I2CINVALID; // XXX Protect against direct call to i2cWrite and i2cRead +static uint8_t i2cAddress; + #define INVERSE_CHAR_FORMAT 0x7f // 0b01111111 #define NORMAL_CHAR_FORMAT 0x00 // 0b00000000 @@ -176,16 +191,14 @@ static const uint8_t multiWiiFont[][5] = { // Refer to "Times New Roman" Font Da { 0x7A, 0x7E, 0x7E, 0x7E, 0x7A }, // (131) - 0x00C8 Vertical Bargraph - 6 (full) }; -#define OLED_address 0x3C // OLED at address 0x3C in 7bit - static bool i2c_OLED_send_cmd(uint8_t command) { - return i2cWrite(OLED_I2C_INSTANCE, OLED_address, 0x80, command); + return i2cWrite(i2cBus, i2cAddress, 0x80, command); } static bool i2c_OLED_send_byte(uint8_t val) { - return i2cWrite(OLED_I2C_INSTANCE, OLED_address, 0x40, val); + return i2cWrite(i2cBus, i2cAddress, 0x40, val); } void i2c_OLED_clear_display(void) @@ -257,6 +270,8 @@ void i2c_OLED_send_string(const char *string) */ bool ug2864hsweg01InitI2C(void) { + i2cBus = I2C_CFG_TO_DEV(oledDisplayConfig()->bus); + i2cAddress = oledDisplayConfig()->address; // Set display OFF if (!i2c_OLED_send_cmd(0xAE)) { diff --git a/src/main/drivers/display_ug2864hsweg01.h b/src/main/drivers/display_ug2864hsweg01.h index 3a51eab7a5..5b5e0620c7 100644 --- a/src/main/drivers/display_ug2864hsweg01.h +++ b/src/main/drivers/display_ug2864hsweg01.h @@ -17,6 +17,15 @@ #pragma once +#include "drivers/bus_i2c.h" + +typedef struct oledDisplayConfig_s { + I2CDevice bus; + uint8_t address; +} oledDisplayConfig_t; + +PG_DECLARE(oledDisplayConfig_t, oledDisplayConfig); + #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index f316e5c92b..5ef33138bd 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -37,6 +37,7 @@ #include "config/parameter_group_ids.h" #include "drivers/light_led.h" +#include "drivers/display_ug2864hsweg01.h" #include "fc/config.h" #include "fc/controlrate_profile.h" @@ -719,6 +720,10 @@ const clivalue_t valueTable[] = { { "esc_sensor_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_ESC_SENSOR_CONFIG, offsetof(escSensorConfig_t, halfDuplex) }, #endif { "led_inversion", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, ((1 << STATUS_LED_NUMBER) - 1) }, PG_STATUS_LED_CONFIG, offsetof(statusLedConfig_t, inversion) }, +#ifdef USE_I2C_OLED_DISPLAY + { "oled_display_i2c_bus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2CDEV_COUNT }, PG_OLED_DISPLAY_CONFIG, offsetof(oledDisplayConfig_t, bus) }, + { "oled_display_i2c_addr", VAR_UINT8 | MASTER_VALUE, .config.minmax = { I2C_ADDR8_MIN, I2C_ADDR8_MAX }, PG_OLED_DISPLAY_CONFIG, offsetof(oledDisplayConfig_t, bus) }, +#endif }; const uint16_t valueTableEntryCount = ARRAYLEN(valueTable); From cb8c20107ed42244c7a59aa64f10f9bfb0f57c84 Mon Sep 17 00:00:00 2001 From: Bryce Johnson Date: Wed, 21 Jun 2017 14:30:26 -0500 Subject: [PATCH 19/25] explicit initialization for reverse motors --- src/main/fc/fc_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/fc/fc_core.c b/src/main/fc/fc_core.c index 5685bf7bb7..2a7ec85ce1 100644 --- a/src/main/fc/fc_core.c +++ b/src/main/fc/fc_core.c @@ -107,7 +107,7 @@ int16_t magHold; int16_t headFreeModeHold; uint8_t motorControlEnable = false; -static bool reverseMotors; +static bool reverseMotors = false; static uint32_t disarmAt; // Time of automatic disarm when "Don't spin the motors when armed" is enabled and auto_disarm_delay is nonzero bool isRXDataNew; From 53eb07c56a3efc7772bf3bc91d0d3dcb5545262f Mon Sep 17 00:00:00 2001 From: Shang2017 Date: Thu, 22 Jun 2017 19:07:48 +0800 Subject: [PATCH 20/25] remove config of hmc5883 and ms5611 (#3260) * Add frsky f3 directory * add F4 * ADD F4 CONFIG.C * restore rx.c and fix some issues * restore Makefile * restore Makefile * 1.USE DEF_TIM in target.c 2.remove unneeded include and config items in xonfig.c 3.adjusted indentation in all of the files. * solve the whitespace issue in taget.c and config.c In FRSKYF3/target.h remove the line UNDEF USE_I2C * Fixed tabbing. * remove config of mag and ms5611 * test * remove white space * Add Baro config * rebase and remove Mag and MS5611 --- src/main/target/FRSKYF4/target.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/target/FRSKYF4/target.h b/src/main/target/FRSKYF4/target.h index 26b83a916e..7369bf4f62 100644 --- a/src/main/target/FRSKYF4/target.h +++ b/src/main/target/FRSKYF4/target.h @@ -41,13 +41,7 @@ #define MPU_INT_EXTI PC4 #define USE_MPU_DATA_READY_SIGNAL -//#define MAG -//#define USE_MAG_HMC5883 -//#define MAG_HMC5883_ALIGN CW90_DEG - #define BARO -//#define USE_BARO_MS5611 - #define USE_BARO_BMP280 #define USE_BARO_SPI_BMP280 #define BMP280_SPI_INSTANCE SPI3 From 2b2894a96f49e625b5730aceffafa8ef10296bc6 Mon Sep 17 00:00:00 2001 From: mikeller Date: Fri, 23 Jun 2017 00:43:45 +1200 Subject: [PATCH 21/25] Fixed CLI buffer defines. --- src/main/fc/cli.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index 718007bd10..3508b89d63 100755 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -128,17 +128,16 @@ static serialPort_t *cliPort; #ifdef STM32F1 #define CLI_IN_BUFFER_SIZE 128 -#define CLI_OUT_BUFFER_SIZE 64 #else // Space required to set array parameters #define CLI_IN_BUFFER_SIZE 256 -#define CLI_OUT_BUFFER_SIZE 256 #endif +#define CLI_OUT_BUFFER_SIZE 64 static bufWriter_t *cliWriter; -static uint8_t cliWriteBuffer[sizeof(*cliWriter) + CLI_IN_BUFFER_SIZE]; +static uint8_t cliWriteBuffer[sizeof(*cliWriter) + CLI_OUT_BUFFER_SIZE]; -static char cliBuffer[CLI_OUT_BUFFER_SIZE]; +static char cliBuffer[CLI_IN_BUFFER_SIZE]; static uint32_t bufferIndex = 0; static bool configIsInCopy = false; From 5845f96c1e7940eae2bda76fe61bac28623a607b Mon Sep 17 00:00:00 2001 From: jflyper Date: Thu, 22 Jun 2017 23:15:45 +0900 Subject: [PATCH 22/25] RX_CE_PIN doesn't need to be initialized --- src/main/fc/fc_init.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index 0423605cb1..a5d9efcd92 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -233,9 +233,6 @@ void spiPreInit(void) #ifdef M25P16_CS_PIN // XXX Should use USE_ format. spiPreInitCs(IO_TAG(M25P16_CS_PIN)); #endif -#ifdef USE_RX_NRF24 - spiPreInitCs(IO_TAG(RX_CE_PIN)); -#endif #if defined(USE_RX_SPI) && !defined(USE_RX_SOFTSPI) spiPreInitCs(IO_TAG(RX_NSS_PIN)); #endif From 88495cf7f9903771496693b9c4a8d4aefaac125f Mon Sep 17 00:00:00 2001 From: Faduf Date: Thu, 22 Jun 2017 20:18:27 +0200 Subject: [PATCH 23/25] Correction for PPM support --- src/main/target/YUPIF4/target.c | 6 +++--- src/main/target/YUPIF4/target.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/target/YUPIF4/target.c b/src/main/target/YUPIF4/target.c index 8f1ab8b62e..8f7f49277d 100644 --- a/src/main/target/YUPIF4/target.c +++ b/src/main/target/YUPIF4/target.c @@ -25,13 +25,13 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { - DEF_TIM(TIM8, CH2, PC7, TIM_USE_PPM, TIMER_INPUT_ENABLED, 0 ), // PPM IN + DEF_TIM(TIM8, CH3, PC8, TIM_USE_PPM, TIMER_INPUT_ENABLED, 0 ), // PPM IN DEF_TIM(TIM5, CH1, PA0, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0 ), // S1_OUT - DMA1_ST2 DEF_TIM(TIM5, CH2, PA1, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0 ), // S2_OUT - DMA1_ST4 DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0 ), // S3_OUT - DMA1_ST1 DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 1 ), // S4_OUT - DMA1_ST6 DEF_TIM(TIM3, CH3, PB0, TIM_USE_MOTOR | TIM_USE_LED, TIMER_OUTPUT_ENABLED, 0 ), // S5_OUT - DMA1_ST7 - DEF_TIM(TIM3, CH4, PB1, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0 ), // S6_OUT - DMA1_ST2 - DEF_TIM(TIM8, CH4, PC9, TIM_USE_BEEPER, TIMER_OUTPUT_ENABLED, 0 ), // BEEPER PWM + DEF_TIM(TIM4, CH2, PB7, TIM_USE_MOTOR, TIMER_OUTPUT_ENABLED, 0 ), // S6_OUT - DMA1_ST2 + DEF_TIM(TIM3, CH4, PC9, TIM_USE_BEEPER, TIMER_OUTPUT_ENABLED, 0 ), // BEEPER PWM }; diff --git a/src/main/target/YUPIF4/target.h b/src/main/target/YUPIF4/target.h index bcb65b557c..9ab590d7c4 100644 --- a/src/main/target/YUPIF4/target.h +++ b/src/main/target/YUPIF4/target.h @@ -149,4 +149,4 @@ #define TARGET_IO_PORTD (BIT(2)) #define USABLE_TIMER_CHANNEL_COUNT 8 -#define USED_TIMERS (TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(8)) +#define USED_TIMERS (TIM_N(2) | TIM_N(3) | TIM_N(4) | TIM_N(5) | TIM_N(8)) From 32fa109a64ee4463938fe1d41df86714a0e5ede7 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Thu, 22 Jun 2017 19:31:16 +0100 Subject: [PATCH 24/25] Merge pull request #2852 from azolyoung/add-runcam-split-support Add runcam split support --- Makefile | 1 + src/main/fc/fc_init.c | 6 + src/main/fc/fc_msp.c | 9 + src/main/fc/fc_tasks.c | 10 + src/main/fc/rc_modes.h | 3 + src/main/io/rcsplit.c | 163 ++++++++++ src/main/io/rcsplit.h | 56 ++++ src/main/io/serial.h | 1 + src/main/scheduler/scheduler.h | 4 + src/main/target/common_fc_pre.h | 2 + src/test/Makefile | 9 + src/test/unit/rc_controls_unittest.cc | 21 +- src/test/unit/rcsplit_unittest.cc | 431 ++++++++++++++++++++++++++ 13 files changed, 706 insertions(+), 10 deletions(-) create mode 100644 src/main/io/rcsplit.c create mode 100644 src/main/io/rcsplit.h create mode 100644 src/test/unit/rcsplit_unittest.cc diff --git a/Makefile b/Makefile index 5d4c39945f..27c5cb5e64 100644 --- a/Makefile +++ b/Makefile @@ -711,6 +711,7 @@ COMMON_SRC = \ io/serial.c \ io/statusindicator.c \ io/transponder_ir.c \ + io/rcsplit.c \ msp/msp_serial.c \ scheduler/scheduler.c \ sensors/battery.c \ diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index b3794a5b79..9082e0dde7 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -124,6 +124,7 @@ #include "flight/pid.h" #include "flight/servos.h" +#include "io/rcsplit.h" #ifdef USE_HARDWARE_REVISION_DETECTION #include "hardware_revision.h" @@ -636,5 +637,10 @@ void init(void) #else fcTasksInit(); #endif + +#ifdef USE_RCSPLIT + rcSplitInit(); +#endif // USE_RCSPLIT + systemState |= SYSTEM_STATE_READY; } diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 28f6ea4258..ce8a74520d 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -153,6 +153,9 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT] = { { BOX3DDISABLESWITCH, "DISABLE 3D SWITCH", 29}, { BOXFPVANGLEMIX, "FPV ANGLE MIX", 30}, { BOXBLACKBOXERASE, "BLACKBOX ERASE (>30s)", 31 }, + { BOXCAMERA1, "CAMERA CONTROL 1", 32}, + { BOXCAMERA2, "CAMERA CONTROL 2", 33}, + { BOXCAMERA3, "CAMERA CONTROL 3", 34 }, }; // mask of enabled IDs, calculated on startup based on enabled features. boxId_e is used as bit index @@ -420,6 +423,12 @@ void initActiveBoxIds(void) } #endif +#ifdef USE_RCSPLIT + BME(BOXCAMERA1); + BME(BOXCAMERA2); + BME(BOXCAMERA3); +#endif + #undef BME // check that all enabled IDs are in boxes array (check may be skipped when using findBoxById() functions) for (boxId_e boxId = 0; boxId < CHECKBOX_ITEM_COUNT; boxId++) diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 4bfd4ec84e..0131892928 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -84,6 +84,7 @@ #include "telemetry/telemetry.h" #include "io/osd_slave.h" +#include "io/rcsplit.h" #ifdef USE_BST void taskBstMasterProcess(timeUs_t currentTimeUs); @@ -594,5 +595,14 @@ cfTask_t cfTasks[TASK_COUNT] = { .staticPriority = TASK_PRIORITY_IDLE, }, #endif + +#ifdef USE_RCSPLIT + [TASK_RCSPLIT] = { + .taskName = "RCSPLIT", + .taskFunc = rcSplitProcess, + .desiredPeriod = TASK_PERIOD_HZ(10), // 10 Hz, 100ms + .staticPriority = TASK_PRIORITY_MEDIUM, + }, +#endif #endif }; diff --git a/src/main/fc/rc_modes.h b/src/main/fc/rc_modes.h index 2b0d223786..17c35f7e22 100644 --- a/src/main/fc/rc_modes.h +++ b/src/main/fc/rc_modes.h @@ -54,6 +54,9 @@ typedef enum { BOX3DDISABLESWITCH, BOXFPVANGLEMIX, BOXBLACKBOXERASE, + BOXCAMERA1, + BOXCAMERA2, + BOXCAMERA3, CHECKBOX_ITEM_COUNT } boxId_e; diff --git a/src/main/io/rcsplit.c b/src/main/io/rcsplit.c new file mode 100644 index 0000000000..e9533bed6d --- /dev/null +++ b/src/main/io/rcsplit.c @@ -0,0 +1,163 @@ +/* + * 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 . + */ + +#include +#include +#include +#include + +#include + +#include "common/utils.h" + +#include "config/parameter_group.h" +#include "config/parameter_group_ids.h" + +#include "fc/rc_controls.h" + +#include "io/beeper.h" +#include "io/serial.h" + +#include "scheduler/scheduler.h" + +#include "drivers/serial.h" + +#include "io/rcsplit.h" + +// communicate with camera device variables +serialPort_t *rcSplitSerialPort = NULL; +rcsplit_switch_state_t switchStates[BOXCAMERA3 - BOXCAMERA1 + 1]; +rcsplit_state_e cameraState = RCSPLIT_STATE_UNKNOWN; + +static uint8_t crc_high_first(uint8_t *ptr, uint8_t len) +{ + uint8_t i; + uint8_t crc=0x00; + while (len--) { + crc ^= *ptr++; + for (i=8; i>0; --i) { + if (crc & 0x80) + crc = (crc << 1) ^ 0x31; + else + crc = (crc << 1); + } + } + return (crc); +} + +static void sendCtrlCommand(rcsplit_ctrl_argument_e argument) +{ + if (!rcSplitSerialPort) + return ; + + uint8_t uart_buffer[5] = {0}; + uint8_t crc = 0; + + uart_buffer[0] = RCSPLIT_PACKET_HEADER; + uart_buffer[1] = RCSPLIT_PACKET_CMD_CTRL; + uart_buffer[2] = argument; + uart_buffer[3] = RCSPLIT_PACKET_TAIL; + crc = crc_high_first(uart_buffer, 4); + + // build up a full request [header]+[command]+[argument]+[crc]+[tail] + uart_buffer[3] = crc; + uart_buffer[4] = RCSPLIT_PACKET_TAIL; + + // write to device + serialWriteBuf(rcSplitSerialPort, uart_buffer, 5); +} + +static void rcSplitProcessMode() +{ + // if the device not ready, do not handle any mode change event + if (RCSPLIT_STATE_IS_READY != cameraState) + return ; + + for (boxId_e i = BOXCAMERA1; i <= BOXCAMERA3; i++) { + uint8_t switchIndex = i - BOXCAMERA1; + if (IS_RC_MODE_ACTIVE(i)) { + // check last state of this mode, if it's true, then ignore it. + // Here is a logic to make a toggle control for this mode + if (switchStates[switchIndex].isActivated) { + continue; + } + + uint8_t argument = RCSPLIT_CTRL_ARGU_INVALID; + switch (i) { + case BOXCAMERA1: + argument = RCSPLIT_CTRL_ARGU_WIFI_BTN; + break; + case BOXCAMERA2: + argument = RCSPLIT_CTRL_ARGU_POWER_BTN; + break; + case BOXCAMERA3: + argument = RCSPLIT_CTRL_ARGU_CHANGE_MODE; + break; + default: + argument = RCSPLIT_CTRL_ARGU_INVALID; + break; + } + + if (argument != RCSPLIT_CTRL_ARGU_INVALID) { + sendCtrlCommand(argument); + switchStates[switchIndex].isActivated = true; + } + } else { + switchStates[switchIndex].isActivated = false; + } + } +} + +bool rcSplitInit(void) +{ + // found the port config with FUNCTION_RUNCAM_SPLIT_CONTROL + // User must set some UART inteface with RunCam Split at peripherals column in Ports tab + serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_RCSPLIT); + if (portConfig) { + rcSplitSerialPort = openSerialPort(portConfig->identifier, FUNCTION_RCSPLIT, NULL, 115200, MODE_RXTX, 0); + } + + if (!rcSplitSerialPort) { + return false; + } + + // set init value to true, to avoid the action auto run when the flight board start and the switch is on. + for (boxId_e i = BOXCAMERA1; i <= BOXCAMERA3; i++) { + uint8_t switchIndex = i - BOXCAMERA1; + switchStates[switchIndex].boxId = 1 << i; + switchStates[switchIndex].isActivated = true; + } + + cameraState = RCSPLIT_STATE_IS_READY; + +#ifdef USE_RCSPLIT + setTaskEnabled(TASK_RCSPLIT, true); +#endif + + return true; +} + +void rcSplitProcess(timeUs_t currentTimeUs) +{ + UNUSED(currentTimeUs); + + if (rcSplitSerialPort == NULL) + return ; + + // process rcsplit custom mode if has any changed + rcSplitProcessMode(); +} diff --git a/src/main/io/rcsplit.h b/src/main/io/rcsplit.h new file mode 100644 index 0000000000..6900700eee --- /dev/null +++ b/src/main/io/rcsplit.h @@ -0,0 +1,56 @@ +/* + * 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 . + */ + +#pragma once + +#include +#include "common/time.h" +#include "fc/fc_msp.h" + +typedef struct { + uint8_t boxId; + bool isActivated; +} rcsplit_switch_state_t; + +typedef enum { + RCSPLIT_STATE_UNKNOWN = 0, + RCSPLIT_STATE_INITIALIZING, + RCSPLIT_STATE_IS_READY, +} rcsplit_state_e; + +// packet header and tail +#define RCSPLIT_PACKET_HEADER 0x55 +#define RCSPLIT_PACKET_CMD_CTRL 0x01 +#define RCSPLIT_PACKET_TAIL 0xaa + + +// the commands of RunCam Split serial protocol +typedef enum { + RCSPLIT_CTRL_ARGU_INVALID = 0x0, + RCSPLIT_CTRL_ARGU_WIFI_BTN = 0x1, + RCSPLIT_CTRL_ARGU_POWER_BTN = 0x2, + RCSPLIT_CTRL_ARGU_CHANGE_MODE = 0x3, + RCSPLIT_CTRL_ARGU_WHO_ARE_YOU = 0xFF, +} rcsplit_ctrl_argument_e; + +bool rcSplitInit(void); +void rcSplitProcess(timeUs_t currentTimeUs); + +// only for unit test +extern rcsplit_state_e cameraState; +extern serialPort_t *rcSplitSerialPort; +extern rcsplit_switch_state_t switchStates[BOXCAMERA3 - BOXCAMERA1 + 1]; diff --git a/src/main/io/serial.h b/src/main/io/serial.h index e7fb4d4c63..5d0009d1b3 100644 --- a/src/main/io/serial.h +++ b/src/main/io/serial.h @@ -44,6 +44,7 @@ typedef enum { FUNCTION_VTX_SMARTAUDIO = (1 << 11), // 2048 FUNCTION_TELEMETRY_IBUS = (1 << 12), // 4096 FUNCTION_VTX_TRAMP = (1 << 13), // 8192 + FUNCTION_RCSPLIT = (1 << 14), // 16384 } serialPortFunction_e; typedef enum { diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index 7f819b6df6..f943d950cb 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -111,6 +111,10 @@ typedef enum { TASK_VTXCTRL, #endif +#ifdef USE_RCSPLIT + TASK_RCSPLIT, +#endif + /* Count of real tasks */ TASK_COUNT, diff --git a/src/main/target/common_fc_pre.h b/src/main/target/common_fc_pre.h index 9db23d8599..534e788507 100644 --- a/src/main/target/common_fc_pre.h +++ b/src/main/target/common_fc_pre.h @@ -130,3 +130,5 @@ #define USE_UNCOMMON_MIXERS #endif + +#define USE_RCSPLIT diff --git a/src/test/Makefile b/src/test/Makefile index 6a02179fdd..c97ed18723 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -185,6 +185,15 @@ type_conversion_unittest_SRC := \ ws2811_unittest_SRC := \ $(USER_DIR)/drivers/light_ws2811strip.c +rcsplit_unittest_SRC := \ + $(USER_DIR)/common/bitarray.c \ + $(USER_DIR)/fc/rc_modes.c \ + $(USER_DIR)/io/rcsplit.c + +rcsplit_unitest_DEFINES := \ + USE_UART3 \ + USE_RCSPLIT \ + # Please tweak the following variable definitions as needed by your # project, except GTEST_HEADERS, which you can use in your own targets # but shouldn't modify. diff --git a/src/test/unit/rc_controls_unittest.cc b/src/test/unit/rc_controls_unittest.cc index 415f9deb1c..5cf1c57e6b 100644 --- a/src/test/unit/rc_controls_unittest.cc +++ b/src/test/unit/rc_controls_unittest.cc @@ -25,6 +25,7 @@ extern "C" { #include "common/maths.h" #include "common/axis.h" + #include "common/bitarray.h" #include "config/parameter_group.h" #include "config/parameter_group_ids.h" @@ -156,14 +157,14 @@ TEST_F(RcControlsModesTest, updateActivatedModesUsingValidAuxConfigurationAndRXV rcData[AUX7] = 950; // value equal to range step upper boundary should not activate the mode // and - uint32_t expectedMask = 0; - expectedMask |= (1 << 0); - expectedMask |= (1 << 1); - expectedMask |= (1 << 2); - expectedMask |= (1 << 3); - expectedMask |= (1 << 4); - expectedMask |= (1 << 5); - expectedMask |= (0 << 6); + boxBitmask_t activeBoxIds; + memset(&activeBoxIds, 0, sizeof(boxBitmask_t)); + bitArraySet(&activeBoxIds, 0); + bitArraySet(&activeBoxIds, 1); + bitArraySet(&activeBoxIds, 2); + bitArraySet(&activeBoxIds, 3); + bitArraySet(&activeBoxIds, 4); + bitArraySet(&activeBoxIds, 5); // when updateActivatedModes(); @@ -171,9 +172,9 @@ TEST_F(RcControlsModesTest, updateActivatedModesUsingValidAuxConfigurationAndRXV // then for (int index = 0; index < CHECKBOX_ITEM_COUNT; index++) { #ifdef DEBUG_RC_CONTROLS - printf("iteration: %d\n", index); + printf("iteration: %d, %d\n", index, (bool)(bitArrayGet(&activeBoxIds, index))); #endif - EXPECT_EQ((bool)(expectedMask & (1 << index)), IS_RC_MODE_ACTIVE((boxId_e)index)); + EXPECT_EQ((bool)(bitArrayGet(&activeBoxIds, index)), IS_RC_MODE_ACTIVE((boxId_e)index)); } } diff --git a/src/test/unit/rcsplit_unittest.cc b/src/test/unit/rcsplit_unittest.cc new file mode 100644 index 0000000000..67be33ae78 --- /dev/null +++ b/src/test/unit/rcsplit_unittest.cc @@ -0,0 +1,431 @@ +/* + * 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 . + */ + + +#include "gtest/gtest.h" + +extern "C" { + #include + #include + #include + + #include "platform.h" + + #include "common/utils.h" + #include "common/maths.h" + #include "common/bitarray.h" + + #include "config/parameter_group.h" + #include "config/parameter_group_ids.h" + + #include "fc/rc_controls.h" + #include "fc/rc_modes.h" + + + #include "io/beeper.h" + #include "io/serial.h" + + #include "scheduler/scheduler.h" + #include "drivers/serial.h" + #include "io/rcsplit.h" + + #include "rx/rx.h" + + int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT]; // interval [1000;2000] + + rcsplit_state_e unitTestRCsplitState() + { + return cameraState; + } + + bool unitTestIsSwitchActivited(boxId_e boxId) + { + uint8_t adjustBoxID = boxId - BOXCAMERA1; + rcsplit_switch_state_t switchState = switchStates[adjustBoxID]; + return switchState.isActivated; + } + + void unitTestResetRCSplit() + { + rcSplitSerialPort = NULL; + cameraState = RCSPLIT_STATE_UNKNOWN; + } +} + +typedef struct testData_s { + bool isRunCamSplitPortConfigurated; + bool isRunCamSplitOpenPortSupported; + int8_t maxTimesOfRespDataAvailable; + bool isAllowBufferReadWrite; +} testData_t; + +static testData_t testData; + +TEST(RCSplitTest, TestRCSplitInitWithoutPortConfigurated) +{ + memset(&testData, 0, sizeof(testData)); + unitTestResetRCSplit(); + bool result = rcSplitInit(); + EXPECT_EQ(false, result); + EXPECT_EQ(RCSPLIT_STATE_UNKNOWN, unitTestRCsplitState()); +} + +TEST(RCSplitTest, TestRCSplitInitWithoutOpenPortConfigurated) +{ + memset(&testData, 0, sizeof(testData)); + unitTestResetRCSplit(); + testData.isRunCamSplitOpenPortSupported = false; + testData.isRunCamSplitPortConfigurated = true; + + bool result = rcSplitInit(); + EXPECT_EQ(false, result); + EXPECT_EQ(RCSPLIT_STATE_UNKNOWN, unitTestRCsplitState()); +} + +TEST(RCSplitTest, TestRCSplitInit) +{ + memset(&testData, 0, sizeof(testData)); + unitTestResetRCSplit(); + testData.isRunCamSplitOpenPortSupported = true; + testData.isRunCamSplitPortConfigurated = true; + + bool result = rcSplitInit(); + EXPECT_EQ(true, result); + EXPECT_EQ(RCSPLIT_STATE_IS_READY, unitTestRCsplitState()); +} + +TEST(RCSplitTest, TestRecvWhoAreYouResponse) +{ + memset(&testData, 0, sizeof(testData)); + unitTestResetRCSplit(); + testData.isRunCamSplitOpenPortSupported = true; + testData.isRunCamSplitPortConfigurated = true; + + bool result = rcSplitInit(); + EXPECT_EQ(true, result); + + // here will generate a number in [6-255], it's make the serialRxBytesWaiting() and serialRead() run at least 5 times, + // so the "who are you response" will full received, and cause the state change to RCSPLIT_STATE_IS_READY; + int8_t randNum = rand() % 127 + 6; + testData.maxTimesOfRespDataAvailable = randNum; + rcSplitProcess((timeUs_t)0); + + EXPECT_EQ(RCSPLIT_STATE_IS_READY, unitTestRCsplitState()); +} + +TEST(RCSplitTest, TestWifiModeChangeWithDeviceUnready) +{ + memset(&testData, 0, sizeof(testData)); + unitTestResetRCSplit(); + testData.isRunCamSplitOpenPortSupported = true; + testData.isRunCamSplitPortConfigurated = true; + testData.maxTimesOfRespDataAvailable = 0; + + bool result = rcSplitInit(); + EXPECT_EQ(true, result); + + // bind aux1, aux2, aux3 channel to wifi button, power button and change mode + for (uint8_t i = 0; i <= (BOXCAMERA3 - BOXCAMERA1); i++) { + memset(modeActivationConditionsMutable(i), 0, sizeof(modeActivationCondition_t)); + } + + // bind aux1 to wifi button with range [900,1600] + modeActivationConditionsMutable(0)->auxChannelIndex = 0; + modeActivationConditionsMutable(0)->modeId = BOXCAMERA1; + modeActivationConditionsMutable(0)->range.startStep = CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MIN); + modeActivationConditionsMutable(0)->range.endStep = CHANNEL_VALUE_TO_STEP(1600); + + // bind aux2 to power button with range [1900, 2100] + modeActivationConditionsMutable(1)->auxChannelIndex = 1; + modeActivationConditionsMutable(1)->modeId = BOXCAMERA2; + modeActivationConditionsMutable(1)->range.startStep = CHANNEL_VALUE_TO_STEP(1900); + modeActivationConditionsMutable(1)->range.endStep = CHANNEL_VALUE_TO_STEP(2100); + + // bind aux3 to change mode with range [1300, 1600] + modeActivationConditionsMutable(2)->auxChannelIndex = 2; + modeActivationConditionsMutable(2)->modeId = BOXCAMERA3; + modeActivationConditionsMutable(2)->range.startStep = CHANNEL_VALUE_TO_STEP(1300); + modeActivationConditionsMutable(2)->range.endStep = CHANNEL_VALUE_TO_STEP(1600); + + // make the binded mode inactive + rcData[modeActivationConditions(0)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1800; + rcData[modeActivationConditions(1)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 900; + rcData[modeActivationConditions(2)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 900; + + updateActivatedModes(); + + // runn process loop + rcSplitProcess(0); + + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA1)); + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA2)); + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA3)); +} + +TEST(RCSplitTest, TestWifiModeChangeWithDeviceReady) +{ + memset(&testData, 0, sizeof(testData)); + unitTestResetRCSplit(); + testData.isRunCamSplitOpenPortSupported = true; + testData.isRunCamSplitPortConfigurated = true; + testData.maxTimesOfRespDataAvailable = 0; + + bool result = rcSplitInit(); + EXPECT_EQ(true, result); + + // bind aux1, aux2, aux3 channel to wifi button, power button and change mode + for (uint8_t i = 0; i <= BOXCAMERA3 - BOXCAMERA1; i++) { + memset(modeActivationConditionsMutable(i), 0, sizeof(modeActivationCondition_t)); + } + + + // bind aux1 to wifi button with range [900,1600] + modeActivationConditionsMutable(0)->auxChannelIndex = 0; + modeActivationConditionsMutable(0)->modeId = BOXCAMERA1; + modeActivationConditionsMutable(0)->range.startStep = CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MIN); + modeActivationConditionsMutable(0)->range.endStep = CHANNEL_VALUE_TO_STEP(1600); + + // bind aux2 to power button with range [1900, 2100] + modeActivationConditionsMutable(1)->auxChannelIndex = 1; + modeActivationConditionsMutable(1)->modeId = BOXCAMERA2; + modeActivationConditionsMutable(1)->range.startStep = CHANNEL_VALUE_TO_STEP(1900); + modeActivationConditionsMutable(1)->range.endStep = CHANNEL_VALUE_TO_STEP(2100); + + // bind aux3 to change mode with range [1300, 1600] + modeActivationConditionsMutable(2)->auxChannelIndex = 2; + modeActivationConditionsMutable(2)->modeId = BOXCAMERA3; + modeActivationConditionsMutable(2)->range.startStep = CHANNEL_VALUE_TO_STEP(1900); + modeActivationConditionsMutable(2)->range.endStep = CHANNEL_VALUE_TO_STEP(2100); + + rcData[modeActivationConditions(0)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1700; + rcData[modeActivationConditions(1)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 2000; + rcData[modeActivationConditions(2)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1700; + + updateActivatedModes(); + + // runn process loop + int8_t randNum = rand() % 127 + 6; + testData.maxTimesOfRespDataAvailable = randNum; + rcSplitProcess((timeUs_t)0); + + EXPECT_EQ(RCSPLIT_STATE_IS_READY, unitTestRCsplitState()); + + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA1)); + EXPECT_EQ(true, unitTestIsSwitchActivited(BOXCAMERA2)); + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA3)); +} + +TEST(RCSplitTest, TestWifiModeChangeCombine) +{ + memset(&testData, 0, sizeof(testData)); + unitTestResetRCSplit(); + testData.isRunCamSplitOpenPortSupported = true; + testData.isRunCamSplitPortConfigurated = true; + testData.maxTimesOfRespDataAvailable = 0; + + bool result = rcSplitInit(); + EXPECT_EQ(true, result); + + // bind aux1, aux2, aux3 channel to wifi button, power button and change mode + for (uint8_t i = 0; i <= BOXCAMERA3 - BOXCAMERA1; i++) { + memset(modeActivationConditionsMutable(i), 0, sizeof(modeActivationCondition_t)); + } + + + // bind aux1 to wifi button with range [900,1600] + modeActivationConditionsMutable(0)->auxChannelIndex = 0; + modeActivationConditionsMutable(0)->modeId = BOXCAMERA1; + modeActivationConditionsMutable(0)->range.startStep = CHANNEL_VALUE_TO_STEP(CHANNEL_RANGE_MIN); + modeActivationConditionsMutable(0)->range.endStep = CHANNEL_VALUE_TO_STEP(1600); + + // bind aux2 to power button with range [1900, 2100] + modeActivationConditionsMutable(1)->auxChannelIndex = 1; + modeActivationConditionsMutable(1)->modeId = BOXCAMERA2; + modeActivationConditionsMutable(1)->range.startStep = CHANNEL_VALUE_TO_STEP(1900); + modeActivationConditionsMutable(1)->range.endStep = CHANNEL_VALUE_TO_STEP(2100); + + // bind aux3 to change mode with range [1300, 1600] + modeActivationConditionsMutable(2)->auxChannelIndex = 2; + modeActivationConditionsMutable(2)->modeId = BOXCAMERA3; + modeActivationConditionsMutable(2)->range.startStep = CHANNEL_VALUE_TO_STEP(1900); + modeActivationConditionsMutable(2)->range.endStep = CHANNEL_VALUE_TO_STEP(2100); + + // // make the binded mode inactive + rcData[modeActivationConditions(0)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1700; + rcData[modeActivationConditions(1)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 2000; + rcData[modeActivationConditions(2)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1700; + updateActivatedModes(); + + // runn process loop + int8_t randNum = rand() % 127 + 6; + testData.maxTimesOfRespDataAvailable = randNum; + rcSplitProcess((timeUs_t)0); + + EXPECT_EQ(RCSPLIT_STATE_IS_READY, unitTestRCsplitState()); + + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA1)); + EXPECT_EQ(true, unitTestIsSwitchActivited(BOXCAMERA2)); + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA3)); + + + // // make the binded mode inactive + rcData[modeActivationConditions(0)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1500; + rcData[modeActivationConditions(1)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1300; + rcData[modeActivationConditions(2)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1900; + updateActivatedModes(); + rcSplitProcess((timeUs_t)0); + EXPECT_EQ(true, unitTestIsSwitchActivited(BOXCAMERA1)); + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA2)); + EXPECT_EQ(true, unitTestIsSwitchActivited(BOXCAMERA3)); + + + rcData[modeActivationConditions(2)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 1899; + updateActivatedModes(); + rcSplitProcess((timeUs_t)0); + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA3)); + + rcData[modeActivationConditions(1)->auxChannelIndex + NON_AUX_CHANNEL_COUNT] = 2001; + updateActivatedModes(); + rcSplitProcess((timeUs_t)0); + EXPECT_EQ(true, unitTestIsSwitchActivited(BOXCAMERA1)); + EXPECT_EQ(true, unitTestIsSwitchActivited(BOXCAMERA2)); + EXPECT_EQ(false, unitTestIsSwitchActivited(BOXCAMERA3)); +} + +extern "C" { + serialPort_t *openSerialPort(serialPortIdentifier_e identifier, serialPortFunction_e functionMask, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode, portOptions_t options) + { + UNUSED(identifier); + UNUSED(functionMask); + UNUSED(baudRate); + UNUSED(callback); + UNUSED(mode); + UNUSED(options); + + if (testData.isRunCamSplitOpenPortSupported) { + static serialPort_t s; + s.vTable = NULL; + + // common serial initialisation code should move to serialPort::init() + s.rxBufferHead = s.rxBufferTail = 0; + s.txBufferHead = s.txBufferTail = 0; + s.rxBufferSize = 0; + s.txBufferSize = 0; + s.rxBuffer = s.rxBuffer; + s.txBuffer = s.txBuffer; + + // callback works for IRQ-based RX ONLY + s.rxCallback = NULL; + s.baudRate = 0; + + return (serialPort_t *)&s; + } + + return NULL; + } + + serialPortConfig_t *findSerialPortConfig(serialPortFunction_e function) + { + UNUSED(function); + if (testData.isRunCamSplitPortConfigurated) { + static serialPortConfig_t portConfig; + + portConfig.identifier = SERIAL_PORT_USART3; + portConfig.msp_baudrateIndex = BAUD_115200; + portConfig.gps_baudrateIndex = BAUD_57600; + portConfig.telemetry_baudrateIndex = BAUD_AUTO; + portConfig.blackbox_baudrateIndex = BAUD_115200; + portConfig.functionMask = FUNCTION_MSP; + + return &portConfig; + } + + return NULL; + } + + uint32_t serialRxBytesWaiting(const serialPort_t *instance) + { + UNUSED(instance); + + testData.maxTimesOfRespDataAvailable--; + if (testData.maxTimesOfRespDataAvailable > 0) { + return 1; + } + + return 0; + } + + uint8_t serialRead(serialPort_t *instance) + { + UNUSED(instance); + + if (testData.maxTimesOfRespDataAvailable > 0) { + static uint8_t i = 0; + static uint8_t buffer[] = { 0x55, 0x01, 0xFF, 0xad, 0xaa }; + + if (i >= 5) { + i = 0; + } + + return buffer[i++]; + } + + return 0; + } + + void sbufWriteString(sbuf_t *dst, const char *string) + { + UNUSED(dst); UNUSED(string); + + if (testData.isAllowBufferReadWrite) { + sbufWriteData(dst, string, strlen(string)); + } + } + void sbufWriteU8(sbuf_t *dst, uint8_t val) + { + UNUSED(dst); UNUSED(val); + + if (testData.isAllowBufferReadWrite) { + *dst->ptr++ = val; + } + } + + void sbufWriteData(sbuf_t *dst, const void *data, int len) + { + UNUSED(dst); UNUSED(data); UNUSED(len); + + if (testData.isAllowBufferReadWrite) { + memcpy(dst->ptr, data, len); + dst->ptr += len; + + } + } + + // modifies streambuf so that written data are prepared for reading + void sbufSwitchToReader(sbuf_t *buf, uint8_t *base) + { + UNUSED(buf); UNUSED(base); + + if (testData.isAllowBufferReadWrite) { + buf->end = buf->ptr; + buf->ptr = base; + } + } + + bool feature(uint32_t) { return false;} + void serialWriteBuf(serialPort_t *instance, const uint8_t *data, int count) { UNUSED(instance); UNUSED(data); UNUSED(count); } +} \ No newline at end of file From 20260aa8e2af32ca23a53cf0c9b43f22bba1c33e Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Fri, 23 Jun 2017 20:17:00 +1200 Subject: [PATCH 25/25] Revert "Configurable OLED display bus and address" --- src/main/config/parameter_group_ids.h | 3 +-- src/main/drivers/bus_i2c.h | 7 ------- src/main/drivers/display_ug2864hsweg01.c | 25 +++++------------------- src/main/drivers/display_ug2864hsweg01.h | 9 --------- src/main/fc/settings.c | 5 ----- 5 files changed, 6 insertions(+), 43 deletions(-) diff --git a/src/main/config/parameter_group_ids.h b/src/main/config/parameter_group_ids.h index e7949d38b7..e4b0bb3f59 100644 --- a/src/main/config/parameter_group_ids.h +++ b/src/main/config/parameter_group_ids.h @@ -107,8 +107,7 @@ #define PG_SONAR_CONFIG 516 #define PG_ESC_SENSOR_CONFIG 517 #define PG_I2C_CONFIG 518 -#define PG_OLED_DISPLAY_CONFIG 519 -#define PG_BETAFLIGHT_END 519 +#define PG_BETAFLIGHT_END 518 // OSD configuration (subject to change) diff --git a/src/main/drivers/bus_i2c.h b/src/main/drivers/bus_i2c.h index d92a390b32..bd27125994 100644 --- a/src/main/drivers/bus_i2c.h +++ b/src/main/drivers/bus_i2c.h @@ -45,13 +45,6 @@ typedef enum I2CDevice { #define I2CDEV_COUNT 4 #endif -// Macro to convert CLI bus number to I2CDevice. -#define I2C_CFG_TO_DEV(x) ((x) - 1) - -// I2C device address range in 8-bit address mode -#define I2C_ADDR8_MIN 8 -#define I2C_ADDR8_MAX 119 - typedef struct i2cConfig_s { ioTag_t ioTagScl[I2CDEV_COUNT]; ioTag_t ioTagSda[I2CDEV_COUNT]; diff --git a/src/main/drivers/display_ug2864hsweg01.c b/src/main/drivers/display_ug2864hsweg01.c index fd0c617c49..b9ac8528e5 100644 --- a/src/main/drivers/display_ug2864hsweg01.c +++ b/src/main/drivers/display_ug2864hsweg01.c @@ -24,31 +24,16 @@ #include "display_ug2864hsweg01.h" -#include "config/parameter_group.h" -#include "config/parameter_group_ids.h" - #ifdef USE_I2C_OLED_DISPLAY #if !defined(OLED_I2C_INSTANCE) #if defined(I2C_DEVICE) #define OLED_I2C_INSTANCE I2C_DEVICE #else -#define OLED_I2C_INSTANCE I2CINVALID +#define OLED_I2C_INSTANCE I2C_NONE #endif #endif -#define OLED_address 0x3C // OLED at address 0x3C in 7bit - -PG_REGISTER_WITH_RESET_TEMPLATE(oledDisplayConfig_t, oledDisplayConfig, PG_OLED_DISPLAY_CONFIG, 0); - -PG_RESET_TEMPLATE(oledDisplayConfig_t, oledDisplayConfig, - .bus = OLED_I2C_INSTANCE, - .address = OLED_address, -); - -static I2CDevice i2cBus = I2CINVALID; // XXX Protect against direct call to i2cWrite and i2cRead -static uint8_t i2cAddress; - #define INVERSE_CHAR_FORMAT 0x7f // 0b01111111 #define NORMAL_CHAR_FORMAT 0x00 // 0b00000000 @@ -191,14 +176,16 @@ static const uint8_t multiWiiFont[][5] = { // Refer to "Times New Roman" Font Da { 0x7A, 0x7E, 0x7E, 0x7E, 0x7A }, // (131) - 0x00C8 Vertical Bargraph - 6 (full) }; +#define OLED_address 0x3C // OLED at address 0x3C in 7bit + static bool i2c_OLED_send_cmd(uint8_t command) { - return i2cWrite(i2cBus, i2cAddress, 0x80, command); + return i2cWrite(OLED_I2C_INSTANCE, OLED_address, 0x80, command); } static bool i2c_OLED_send_byte(uint8_t val) { - return i2cWrite(i2cBus, i2cAddress, 0x40, val); + return i2cWrite(OLED_I2C_INSTANCE, OLED_address, 0x40, val); } void i2c_OLED_clear_display(void) @@ -270,8 +257,6 @@ void i2c_OLED_send_string(const char *string) */ bool ug2864hsweg01InitI2C(void) { - i2cBus = I2C_CFG_TO_DEV(oledDisplayConfig()->bus); - i2cAddress = oledDisplayConfig()->address; // Set display OFF if (!i2c_OLED_send_cmd(0xAE)) { diff --git a/src/main/drivers/display_ug2864hsweg01.h b/src/main/drivers/display_ug2864hsweg01.h index 5b5e0620c7..3a51eab7a5 100644 --- a/src/main/drivers/display_ug2864hsweg01.h +++ b/src/main/drivers/display_ug2864hsweg01.h @@ -17,15 +17,6 @@ #pragma once -#include "drivers/bus_i2c.h" - -typedef struct oledDisplayConfig_s { - I2CDevice bus; - uint8_t address; -} oledDisplayConfig_t; - -PG_DECLARE(oledDisplayConfig_t, oledDisplayConfig); - #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index 5ef33138bd..f316e5c92b 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -37,7 +37,6 @@ #include "config/parameter_group_ids.h" #include "drivers/light_led.h" -#include "drivers/display_ug2864hsweg01.h" #include "fc/config.h" #include "fc/controlrate_profile.h" @@ -720,10 +719,6 @@ const clivalue_t valueTable[] = { { "esc_sensor_halfduplex", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_ESC_SENSOR_CONFIG, offsetof(escSensorConfig_t, halfDuplex) }, #endif { "led_inversion", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, ((1 << STATUS_LED_NUMBER) - 1) }, PG_STATUS_LED_CONFIG, offsetof(statusLedConfig_t, inversion) }, -#ifdef USE_I2C_OLED_DISPLAY - { "oled_display_i2c_bus", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, I2CDEV_COUNT }, PG_OLED_DISPLAY_CONFIG, offsetof(oledDisplayConfig_t, bus) }, - { "oled_display_i2c_addr", VAR_UINT8 | MASTER_VALUE, .config.minmax = { I2C_ADDR8_MIN, I2C_ADDR8_MAX }, PG_OLED_DISPLAY_CONFIG, offsetof(oledDisplayConfig_t, bus) }, -#endif }; const uint16_t valueTableEntryCount = ARRAYLEN(valueTable);