From 9cb4f6b097c68c3a4d6205129f84302dbfda70c8 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sun, 24 Dec 2017 10:04:45 +1300 Subject: [PATCH] Moved parameter group for rx_pwm to `pg` directory. --- make/source.mk | 1 + src/main/drivers/rx_pwm.c | 10 +++--- src/main/drivers/rx_pwm.h | 15 +++----- src/main/fc/config.c | 38 -------------------- src/main/fc/config.h | 3 -- src/main/fc/fc_init.c | 5 +-- src/main/interface/cli.c | 6 ++-- src/main/interface/settings.c | 1 + src/main/pg/rx_pwm.c | 68 +++++++++++++++++++++++++++++++++++ src/main/pg/rx_pwm.h | 36 +++++++++++++++++++ 10 files changed, 121 insertions(+), 62 deletions(-) create mode 100644 src/main/pg/rx_pwm.c create mode 100644 src/main/pg/rx_pwm.h diff --git a/make/source.mk b/make/source.mk index 5bc8d2ee0..c68b6b5a4 100644 --- a/make/source.mk +++ b/make/source.mk @@ -64,6 +64,7 @@ COMMON_SRC = \ pg/bus_i2c.c \ pg/flash.c \ pg/max7456.c \ + pg/rx_pwm.c \ pg/pg.c \ scheduler/scheduler.c \ sensors/battery.c \ diff --git a/src/main/drivers/rx_pwm.c b/src/main/drivers/rx_pwm.c index f3c05084d..31eba0d42 100644 --- a/src/main/drivers/rx_pwm.c +++ b/src/main/drivers/rx_pwm.c @@ -27,15 +27,15 @@ #include "common/utils.h" -#include "drivers/nvic.h" #include "drivers/io.h" -#include "timer.h" +#include "drivers/nvic.h" +#include "drivers/pwm_output.h" +#include "drivers/timer.h" + +#include "pg/rx_pwm.h" -#include "pwm_output.h" #include "rx_pwm.h" -#include "flight/mixer.h" //!!TODO remove dependency on this - #define DEBUG_PPM_ISR #define PPM_CAPTURE_COUNT 12 diff --git a/src/main/drivers/rx_pwm.h b/src/main/drivers/rx_pwm.h index 0943af646..922b33435 100644 --- a/src/main/drivers/rx_pwm.h +++ b/src/main/drivers/rx_pwm.h @@ -27,17 +27,10 @@ typedef enum { #define PPM_RCVR_TIMEOUT 0 #define PWM_INPUT_PORT_COUNT 8 -typedef struct ppmConfig_s { - ioTag_t ioTag; -} ppmConfig_t; - -typedef struct pwmConfig_s { - ioTag_t ioTags[PWM_INPUT_PORT_COUNT]; - inputFilteringMode_e inputFilteringMode; -} pwmConfig_t; - -void ppmRxInit(const ppmConfig_t *ppmConfig); -void pwmRxInit(const pwmConfig_t *pwmConfig); +struct ppmConfig_s; +void ppmRxInit(const struct ppmConfig_s *ppmConfig); +struct pwmConfig_s; +void pwmRxInit(const struct pwmConfig_s *pwmConfig); uint16_t pwmRead(uint8_t channel); uint16_t ppmRead(uint8_t channel); diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 5a154e96c..e1b967df5 100644 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -49,7 +49,6 @@ #include "drivers/max7456.h" #include "drivers/pwm_esc_detect.h" #include "drivers/pwm_output.h" -#include "drivers/rx_pwm.h" #include "drivers/rx_spi.h" #include "drivers/sdcard.h" #include "drivers/sensor.h" @@ -144,13 +143,6 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig, #endif -#ifdef USE_PWM -PG_REGISTER_WITH_RESET_FN(pwmConfig_t, pwmConfig, PG_PWM_CONFIG, 0); -#endif -#ifdef USE_PPM -PG_REGISTER_WITH_RESET_FN(ppmConfig_t, ppmConfig, PG_PPM_CONFIG, 0); -#endif - #ifdef USE_SDCARD PG_REGISTER_WITH_RESET_TEMPLATE(sdcardConfig_t, sdcardConfig, PG_SDCARD_CONFIG, 0); @@ -162,36 +154,6 @@ PG_RESET_TEMPLATE(sdcardConfig_t, sdcardConfig, // no template required since defaults are zero PG_REGISTER(vcdProfile_t, vcdProfile, PG_VCD_CONFIG, 0); -#if defined(USE_PWM) || defined(USE_PPM) -void pgResetFn_ppmConfig(ppmConfig_t *ppmConfig) -{ -#ifdef PPM_PIN - ppmConfig->ioTag = IO_TAG(PPM_PIN); -#else - for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) { - if (timerHardware[i].usageFlags & TIM_USE_PPM) { - ppmConfig->ioTag = timerHardware[i].tag; - return; - } - } - - ppmConfig->ioTag = IO_TAG_NONE; -#endif -} - -void pgResetFn_pwmConfig(pwmConfig_t *pwmConfig) -{ - pwmConfig->inputFilteringMode = INPUT_FILTERING_DISABLED; - int inputIndex = 0; - for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT && inputIndex < PWM_INPUT_PORT_COUNT; i++) { - if (timerHardware[i].usageFlags & TIM_USE_PWM) { - pwmConfig->ioTags[inputIndex] = timerHardware[i].tag; - inputIndex++; - } - } -} -#endif - #ifdef SWAP_SERIAL_PORT_0_AND_1_DEFAULTS #define FIRST_PORT_INDEX 1 #define SECOND_PORT_INDEX 0 diff --git a/src/main/fc/config.h b/src/main/fc/config.h index 12c29f29f..6379e9121 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -23,7 +23,6 @@ #include "pg/pg.h" #include "drivers/flash.h" -#include "drivers/rx_pwm.h" #include "drivers/sdcard.h" #include "drivers/serial.h" #include "drivers/bus_i2c.h" @@ -84,8 +83,6 @@ typedef struct systemConfig_s { PG_DECLARE(pilotConfig_t, pilotConfig); PG_DECLARE(systemConfig_t, systemConfig); PG_DECLARE(beeperDevConfig_t, beeperDevConfig); -PG_DECLARE(ppmConfig_t, ppmConfig); -PG_DECLARE(pwmConfig_t, pwmConfig); PG_DECLARE(vcdProfile_t, vcdProfile); PG_DECLARE(sdcardConfig_t, sdcardConfig); diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index ff916233a..b1917d71e 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -30,8 +30,6 @@ #include "config/config_eeprom.h" #include "config/feature.h" -#include "pg/pg.h" -#include "pg/pg_ids.h" #include "cms/cms.h" #include "cms/cms_types.h" @@ -82,6 +80,9 @@ #include "pg/adc.h" #include "pg/bus_i2c.h" #include "pg/flash.h" +#include "pg/pg.h" +#include "pg/pg_ids.h" +#include "pg/rx_pwm.h" #include "rx/rx.h" #include "rx/rx_spi.h" diff --git a/src/main/interface/cli.c b/src/main/interface/cli.c index 578582231..e9a79ed93 100644 --- a/src/main/interface/cli.c +++ b/src/main/interface/cli.c @@ -66,7 +66,6 @@ extern uint8_t __config_end; #include "drivers/io.h" #include "drivers/io_impl.h" #include "drivers/inverter.h" -#include "drivers/rx_pwm.h" #include "drivers/sdcard.h" #include "drivers/sensor.h" #include "drivers/serial.h" @@ -117,11 +116,12 @@ extern uint8_t __config_end; #include "pg/adc.h" #include "pg/bus_i2c.h" +#include "pg/rx_pwm.h" #include "rx/rx.h" #include "rx/spektrum.h" -#include "../rx/cc2500_frsky_common.h" -#include "../rx/cc2500_frsky_x.h" +#include "rx/cc2500_frsky_common.h" +#include "rx/cc2500_frsky_x.h" #include "scheduler/scheduler.h" diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index cfc5ab651..f9c96fb7b 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -65,6 +65,7 @@ #include "pg/max7456.h" #include "pg/pg.h" #include "pg/pg_ids.h" +#include "pg/rx_pwm.h" #include "rx/rx.h" #include "rx/cc2500_frsky_common.h" diff --git a/src/main/pg/rx_pwm.c b/src/main/pg/rx_pwm.c new file mode 100644 index 000000000..a4cf3bcca --- /dev/null +++ b/src/main/pg/rx_pwm.c @@ -0,0 +1,68 @@ +/* + * 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 + +#if defined(USE_PWM) || defined(USE_PPM) + +#include "drivers/io.h" +#include "drivers/nvic.h" +#include "drivers/rx_pwm.h" +#include "drivers/timer.h" + +#include "pg/pg.h" +#include "pg/pg_ids.h" + +#include "rx_pwm.h" + +#ifdef USE_PWM +PG_REGISTER_WITH_RESET_FN(pwmConfig_t, pwmConfig, PG_PWM_CONFIG, 0); + +void pgResetFn_pwmConfig(pwmConfig_t *pwmConfig) +{ + pwmConfig->inputFilteringMode = INPUT_FILTERING_DISABLED; + int inputIndex = 0; + for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT && inputIndex < PWM_INPUT_PORT_COUNT; i++) { + if (timerHardware[i].usageFlags & TIM_USE_PWM) { + pwmConfig->ioTags[inputIndex] = timerHardware[i].tag; + inputIndex++; + } + } +} +#endif + +#ifdef USE_PPM +PG_REGISTER_WITH_RESET_FN(ppmConfig_t, ppmConfig, PG_PPM_CONFIG, 0); + +void pgResetFn_ppmConfig(ppmConfig_t *ppmConfig) +{ +#ifdef PPM_PIN + ppmConfig->ioTag = IO_TAG(PPM_PIN); +#else + for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) { + if (timerHardware[i].usageFlags & TIM_USE_PPM) { + ppmConfig->ioTag = timerHardware[i].tag; + return; + } + } + + ppmConfig->ioTag = IO_TAG_NONE; +#endif +} +#endif + +#endif diff --git a/src/main/pg/rx_pwm.h b/src/main/pg/rx_pwm.h new file mode 100644 index 000000000..ddaca6ed3 --- /dev/null +++ b/src/main/pg/rx_pwm.h @@ -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 . + */ + +#pragma once + +#include "drivers/io_types.h" +#include "drivers/rx_pwm.h" + +#include "pg/pg.h" + +typedef struct ppmConfig_s { + ioTag_t ioTag; +} ppmConfig_t; + +PG_DECLARE(ppmConfig_t, ppmConfig); + +typedef struct pwmConfig_s { + ioTag_t ioTags[PWM_INPUT_PORT_COUNT]; + inputFilteringMode_e inputFilteringMode; +} pwmConfig_t; + +PG_DECLARE(pwmConfig_t, pwmConfig);