From 0e4684e8282aaf0886a868646b18edd20436df8e Mon Sep 17 00:00:00 2001 From: jflyper Date: Mon, 23 Apr 2018 21:44:40 +0900 Subject: [PATCH] Serial port function mask initializer as a config helper --- make/source.mk | 1 + src/main/target/OMNIBUSF4/config.c | 16 +++++++++--- src/main/target/OMNIBUSF7/config.c | 17 +++++++------ src/main/target/SPRACINGF3NEO/config.c | 13 +++++++--- .../target/{OMNIBUSF7/config.c => config_helper.c} | 29 +++++++++------------- .../target/{OMNIBUSF7/config.c => config_helper.h} | 23 ++++++----------- 6 files changed, 52 insertions(+), 47 deletions(-) copy src/main/target/{OMNIBUSF7/config.c => config_helper.c} (57%) copy src/main/target/{OMNIBUSF7/config.c => config_helper.h} (63%) diff --git a/make/source.mk b/make/source.mk index b940201cc..68fe36929 100644 --- a/make/source.mk +++ b/make/source.mk @@ -84,6 +84,7 @@ COMMON_SRC = \ sensors/battery.c \ sensors/current.c \ sensors/voltage.c \ + target/config_helper.c \ OSD_SLAVE_SRC = \ io/displayport_max7456.c \ diff --git a/src/main/target/OMNIBUSF4/config.c b/src/main/target/OMNIBUSF4/config.c index 4e33cc0ea..35c3dc41c 100644 --- a/src/main/target/OMNIBUSF4/config.c +++ b/src/main/target/OMNIBUSF4/config.c @@ -24,11 +24,22 @@ #ifdef USE_TARGET_CONFIG +#include "config_helper.h" + #include "io/serial.h" #include "pg/max7456.h" #include "pg/pg.h" +#ifdef EXUAVF4PRO +static targetSerialPortFunction_t targetSerialPortFunction[] = { + { 0, FUNCTION_TELEMETRY_SMARTPORT }, + { 2, FUNCTION_VTX_TRAMP }, + { 3, FUNCTION_RCDEVICE }, + { 5, FUNCTION_RX_SERIAL }, +}; +#endif + void targetConfiguration(void) { #ifdef OMNIBUSF4BASE @@ -37,10 +48,7 @@ void targetConfiguration(void) #endif #ifdef EXUAVF4PRO - serialConfigMutable()->portConfigs[1].functionMask = FUNCTION_TELEMETRY_SMARTPORT; - serialConfigMutable()->portConfigs[2].functionMask = FUNCTION_VTX_TRAMP; - serialConfigMutable()->portConfigs[3].functionMask = FUNCTION_RCDEVICE; - serialConfigMutable()->portConfigs[4].functionMask = FUNCTION_RX_SERIAL; + targetSerialPortFunctionConfig(targetSerialPortFunction, ARRAYLEN(targetSerialPortFunction)); #endif } #endif diff --git a/src/main/target/OMNIBUSF7/config.c b/src/main/target/OMNIBUSF7/config.c index de97012a6..41c49f45b 100644 --- a/src/main/target/OMNIBUSF7/config.c +++ b/src/main/target/OMNIBUSF7/config.c @@ -24,16 +24,19 @@ #ifdef USE_TARGET_CONFIG +#include "config_helper.h" + #include "io/serial.h" -void targetConfiguration(void) -{ -// OMNIBUS F7 V2 has an option to connect UART7_RX to ESC telemetry +static targetSerialPortFunction_t targetSerialPortFunction[] = { #if defined(OMNIBUSF7V2) && defined(ESC_SENSOR_UART) - serialPortConfig_t *serialEscSensorUartConfig = serialFindPortConfiguration(ESC_SENSOR_UART); - if (serialEscSensorUartConfig) { - serialEscSensorUartConfig->functionMask = FUNCTION_ESC_SENSOR; - } + // OMNIBUS F7 V2 has an option to connect UART7_RX to ESC telemetry + { ESC_SENSOR_UART, FUNCTION_ESC_SENSOR }, #endif +}; + +void targetConfiguration(void) +{ + targetSerialPortFunctionConfig(targetSerialPortFunction, ARRAYLEN(targetSerialPortFunction)); } #endif diff --git a/src/main/target/SPRACINGF3NEO/config.c b/src/main/target/SPRACINGF3NEO/config.c index 579b96daf..27ae12904 100644 --- a/src/main/target/SPRACINGF3NEO/config.c +++ b/src/main/target/SPRACINGF3NEO/config.c @@ -49,13 +49,20 @@ #include "fc/config.h" #ifdef USE_TARGET_CONFIG + +#include "config_helper.h" + +static targetSerialPortFunction_t targetSerialPortFunction[] = { + { 0, FUNCTION_MSP }, + { TELEMETRY_UART, TELEMETRY_PROVIDER_DEFAULT }, + { GPS_UART, FUNCTION_GPS }, +}; + void targetConfiguration(void) { barometerConfigMutable()->baro_hardware = BARO_DEFAULT; compassConfigMutable()->mag_hardware = MAG_DEFAULT; - serialConfigMutable()->portConfigs[1].functionMask = FUNCTION_MSP; // So Bluetooth users don't have to change anything. - serialConfigMutable()->portConfigs[findSerialPortIndexByIdentifier(TELEMETRY_UART)].functionMask = TELEMETRY_PROVIDER_DEFAULT; - serialConfigMutable()->portConfigs[findSerialPortIndexByIdentifier(GPS_UART)].functionMask = FUNCTION_GPS; + targetSerialPortFunctionConfig(targetSerialPortFunction, ARRAYLEN(targetSerialPortFunction)); telemetryConfigMutable()->halfDuplex = true; } #endif diff --git a/src/main/target/OMNIBUSF7/config.c b/src/main/target/config_helper.c similarity index 57% copy from src/main/target/OMNIBUSF7/config.c copy to src/main/target/config_helper.c index de97012a6..e863efe2f 100644 --- a/src/main/target/OMNIBUSF7/config.c +++ b/src/main/target/config_helper.c @@ -1,14 +1,14 @@ /* * This file is part of Cleanflight and Betaflight. * - * Cleanflight and Betaflight are free software: you can redistribute - * this software and/or modify this software 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) + * Cleanflight and Betaflight are free software: you can redistribute + * this software and/or modify this software 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 and Betaflight are distributed in the hope that they - * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * 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. * @@ -17,23 +17,18 @@ * * If not, see . */ -#include -#include -#include +#include "config_helper.h" #ifdef USE_TARGET_CONFIG -#include "io/serial.h" - -void targetConfiguration(void) +void targetSerialPortFunctionConfig(targetSerialPortFunction_t *config, size_t count) { -// OMNIBUS F7 V2 has an option to connect UART7_RX to ESC telemetry -#if defined(OMNIBUSF7V2) && defined(ESC_SENSOR_UART) - serialPortConfig_t *serialEscSensorUartConfig = serialFindPortConfiguration(ESC_SENSOR_UART); - if (serialEscSensorUartConfig) { - serialEscSensorUartConfig->functionMask = FUNCTION_ESC_SENSOR; + for (size_t i = 0 ; i < count ; i++) { + int index = findSerialPortIndexByIdentifier(config[i].identifier); + if (index >= 0) { + serialConfigMutable()->portConfigs[index].functionMask = config[i].function; + } } -#endif } #endif diff --git a/src/main/target/OMNIBUSF7/config.c b/src/main/target/config_helper.h similarity index 63% copy from src/main/target/OMNIBUSF7/config.c copy to src/main/target/config_helper.h index de97012a6..7d1f4f921 100644 --- a/src/main/target/OMNIBUSF7/config.c +++ b/src/main/target/config_helper.h @@ -17,23 +17,14 @@ * * If not, see . */ -#include -#include -#include - -#ifdef USE_TARGET_CONFIG +#pragma once #include "io/serial.h" -void targetConfiguration(void) -{ -// OMNIBUS F7 V2 has an option to connect UART7_RX to ESC telemetry -#if defined(OMNIBUSF7V2) && defined(ESC_SENSOR_UART) - serialPortConfig_t *serialEscSensorUartConfig = serialFindPortConfiguration(ESC_SENSOR_UART); - if (serialEscSensorUartConfig) { - serialEscSensorUartConfig->functionMask = FUNCTION_ESC_SENSOR; - } -#endif -} -#endif +typedef struct targetSerialPortFunction_s { + serialPortIdentifier_e identifier; + serialPortFunction_e function; +} targetSerialPortFunction_t; + +void targetSerialPortFunctionConfig(targetSerialPortFunction_t *config, size_t count); -- 2.11.4.GIT