From 6557b161aa73c6ad7fc03cf0dee894f227f37872 Mon Sep 17 00:00:00 2001 From: jflyper Date: Sat, 3 Feb 2018 11:18:18 +0900 Subject: [PATCH 1/2] Add box to pinio monitor/mapper --- make/source.mk | 2 ++ src/main/drivers/pinio.h | 2 ++ src/main/fc/fc_init.c | 6 ++++ src/main/fc/fc_tasks.c | 13 +++++++++ src/main/fc/rc_modes.h | 4 +++ src/main/interface/msp_box.c | 23 +++++++++++++++ src/main/interface/msp_box.h | 1 + src/main/interface/settings.c | 1 + src/main/io/piniobox.c | 52 +++++++++++++++++++++++++++++++++ src/main/io/piniobox.h | 21 +++++++++++++ src/main/pg/pg_ids.h | 3 +- src/main/pg/piniobox.c | 31 ++++++++++++++++++++ src/main/pg/piniobox.h | 30 +++++++++++++++++++ src/main/scheduler/scheduler.h | 4 +++ src/main/target/common_fc_pre.h | 1 + 15 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 src/main/io/piniobox.c create mode 100644 src/main/io/piniobox.h create mode 100644 src/main/pg/piniobox.c create mode 100644 src/main/pg/piniobox.h diff --git a/make/source.mk b/make/source.mk index 4196f9f93b..f7d0fc3041 100644 --- a/make/source.mk +++ b/make/source.mk @@ -57,6 +57,7 @@ COMMON_SRC = \ interface/msp.c \ interface/msp_box.c \ io/beeper.c \ + io/piniobox.c \ io/serial.c \ io/statusindicator.c \ io/transponder_ir.c \ @@ -69,6 +70,7 @@ COMMON_SRC = \ pg/dashboard.c \ pg/max7456.c \ pg/pinio.c \ + pg/piniobox.c \ pg/pg.c \ pg/rx_pwm.c \ pg/sdcard.c \ diff --git a/src/main/drivers/pinio.h b/src/main/drivers/pinio.h index 8ad9b5302b..6e9cd33883 100644 --- a/src/main/drivers/pinio.h +++ b/src/main/drivers/pinio.h @@ -17,6 +17,8 @@ #pragma once +#include + #ifndef PINIO_COUNT #define PINIO_COUNT 4 #endif diff --git a/src/main/fc/fc_init.c b/src/main/fc/fc_init.c index ce6e73eb3e..dfdd0b7c68 100644 --- a/src/main/fc/fc_init.c +++ b/src/main/fc/fc_init.c @@ -88,6 +88,7 @@ #include "pg/bus_spi.h" #include "pg/flash.h" #include "pg/pinio.h" +#include "pg/piniobox.h" #include "pg/pg.h" #include "pg/rx_pwm.h" #include "pg/sdcard.h" @@ -113,6 +114,7 @@ #include "io/transponder_ir.h" #include "io/osd.h" #include "io/osd_slave.h" +#include "io/piniobox.h" #include "io/displayport_msp.h" #include "io/vtx.h" #include "io/vtx_rtc6705.h" @@ -538,6 +540,10 @@ void init(void) pinioInit(pinioConfig()); #endif +#ifdef USE_PINIOBOX + pinioBoxInit(pinioBoxConfig()); +#endif + LED1_ON; LED0_OFF; LED2_OFF; diff --git a/src/main/fc/fc_tasks.c b/src/main/fc/fc_tasks.c index 7eb07fc7f6..339b272bf2 100644 --- a/src/main/fc/fc_tasks.c +++ b/src/main/fc/fc_tasks.c @@ -60,6 +60,7 @@ #include "io/ledstrip.h" #include "io/osd.h" #include "io/osd_slave.h" +#include "io/piniobox.h" #include "io/serial.h" #include "io/transponder_ir.h" #include "io/vtx_tramp.h" // Will be gone @@ -305,6 +306,9 @@ void fcTasksInit(void) #ifdef USE_ADC_INTERNAL setTaskEnabled(TASK_ADC_INTERNAL, true); #endif +#ifdef USE_PINIOBOX + setTaskEnabled(TASK_PINIOBOX, true); +#endif #ifdef USE_CMS #ifdef USE_MSP_DISPLAYPORT setTaskEnabled(TASK_CMS, true); @@ -585,5 +589,14 @@ cfTask_t cfTasks[TASK_COUNT] = { .staticPriority = TASK_PRIORITY_IDLE }, #endif + +#ifdef USE_PINIOBOX + [TASK_PINIOBOX] = { + .taskName = "PINIOBOX", + .taskFunc = pinioBoxUpdate, + .desiredPeriod = TASK_PERIOD_HZ(20), + .staticPriority = TASK_PRIORITY_IDLE + }, +#endif #endif }; diff --git a/src/main/fc/rc_modes.h b/src/main/fc/rc_modes.h index 534a4454f6..12b2966f24 100644 --- a/src/main/fc/rc_modes.h +++ b/src/main/fc/rc_modes.h @@ -67,6 +67,10 @@ typedef enum { BOXBEEPGPSCOUNT, BOX3DONASWITCH, BOXVTXPITMODE, + BOXUSER1, + BOXUSER2, + BOXUSER3, + BOXUSER4, CHECKBOX_ITEM_COUNT } boxId_e; diff --git a/src/main/interface/msp_box.c b/src/main/interface/msp_box.c index 9ed2f7d5bc..d515af525c 100644 --- a/src/main/interface/msp_box.c +++ b/src/main/interface/msp_box.c @@ -38,6 +38,8 @@ #include "telemetry/telemetry.h" +#include "pg/piniobox.h" + #ifndef USE_OSD_SLAVE // permanent IDs must uniquely identify BOX meaning, DO NOT REUSE THEM! @@ -82,6 +84,10 @@ static const box_t boxes[CHECKBOX_ITEM_COUNT] = { { BOXBEEPGPSCOUNT, "BEEP GPS SATELLITE COUNT", 37 }, { BOX3DONASWITCH, "3D ON A SWITCH", 38 }, { BOXVTXPITMODE, "VTX PIT MODE", 39 }, + { BOXUSER1, "USER1", 40 }, + { BOXUSER2, "USER2", 41 }, + { BOXUSER3, "USER3", 42 }, + { BOXUSER4, "USER4", 43 }, }; // mask of enabled IDs, calculated on startup based on enabled features. boxId_e is used as bit index @@ -260,6 +266,23 @@ void initActiveBoxIds(void) BME(BOXVTXPITMODE); #endif +#ifdef USE_PINIOBOX + // Turn BOXUSERx only if pinioBox facility monitors them, as the facility is the only BOXUSERx observer. + // Note that pinioBoxConfig can be set to monitor any box. + for (int i = 0; i < PINIO_COUNT; i++) { + switch(pinioBoxConfig()->boxId[i]) { + case BOXUSER1: + case BOXUSER2: + case BOXUSER3: + case BOXUSER4: + BME(pinioBoxConfig()->boxId[i]); + break; + default: + break; + } + } +#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/interface/msp_box.h b/src/main/interface/msp_box.h index 3cd5d927c3..711f6ccb0c 100644 --- a/src/main/interface/msp_box.h +++ b/src/main/interface/msp_box.h @@ -36,3 +36,4 @@ void serializeBoxPermanentIdFn(struct sbuf_s *dst, const box_t *box); typedef void serializeBoxFn(struct sbuf_s *dst, const box_t *box); void serializeBoxReply(struct sbuf_s *dst, int page, serializeBoxFn *serializeBox); void initActiveBoxIds(void); +bool getBoxIdState(boxId_e boxid); diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index d660db9ae2..71cf397b7c 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -869,6 +869,7 @@ const clivalue_t valueTable[] = { // PG_PINIO_CONFIG #ifdef USE_PINIO { "pinio_config", VAR_UINT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIO_CONFIG, offsetof(pinioConfig_t, config) }, + { "piniobox_config", VAR_INT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIOBOX_CONFIG, offsetof(pinioBoxConfig_t, boxId) }, #endif }; diff --git a/src/main/io/piniobox.c b/src/main/io/piniobox.c new file mode 100644 index 0000000000..88930cf89e --- /dev/null +++ b/src/main/io/piniobox.c @@ -0,0 +1,52 @@ +/* + * 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 + +#ifdef USE_PINIOBOX + +#include "build/debug.h" + +#include "common/utils.h" +#include "common/time.h" + +#include "interface/msp_box.h" + +#include "pg/pinio.h" +#include "pg/piniobox.h" + +#include "piniobox.h" + +static const pinioBoxConfig_t *config; + +void pinioBoxInit(const pinioBoxConfig_t *pinioBoxConfig) +{ + config = pinioBoxConfig; +} + +void pinioBoxUpdate(timeUs_t currentTimeUs) +{ + UNUSED(currentTimeUs); + + for (int i = 0; i < PINIO_COUNT; i++) { + pinioSet(i, getBoxIdState(config->boxId[i])); + } +} + +#endif diff --git a/src/main/io/piniobox.h b/src/main/io/piniobox.h new file mode 100644 index 0000000000..d30ce4fb8e --- /dev/null +++ b/src/main/io/piniobox.h @@ -0,0 +1,21 @@ +/* + * 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 "pg/piniobox.h" + +void pinioBoxInit(const pinioBoxConfig_t *pinioBoxConfig); +void pinioBoxUpdate(timeUs_t currentTimeUs); diff --git a/src/main/pg/pg_ids.h b/src/main/pg/pg_ids.h index 589ef1fda3..ddc101accb 100644 --- a/src/main/pg/pg_ids.h +++ b/src/main/pg/pg_ids.h @@ -120,7 +120,8 @@ #define PG_RANGEFINDER_CONFIG 527 // iNav #define PG_TRICOPTER_CONFIG 528 #define PG_PINIO_CONFIG 529 -#define PG_BETAFLIGHT_END 529 +#define PG_PINIOBOX_CONFIG 530 +#define PG_BETAFLIGHT_END 530 // OSD configuration (subject to change) diff --git a/src/main/pg/piniobox.c b/src/main/pg/piniobox.c new file mode 100644 index 0000000000..b4ccf4de1d --- /dev/null +++ b/src/main/pg/piniobox.c @@ -0,0 +1,31 @@ +/* + * 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 "platform.h" + +#ifdef USE_PINIOBOX + +#include "pg/pg_ids.h" +#include "piniobox.h" +#include "drivers/io.h" + +PG_REGISTER_WITH_RESET_TEMPLATE(pinioBoxConfig_t, pinioBoxConfig, PG_PINIOBOX_CONFIG, 0); + +PG_RESET_TEMPLATE(pinioBoxConfig_t, pinioBoxConfig, + { BOXNONE, BOXNONE, BOXNONE, BOXNONE } +); +#endif diff --git a/src/main/pg/piniobox.h b/src/main/pg/piniobox.h new file mode 100644 index 0000000000..5782afda21 --- /dev/null +++ b/src/main/pg/piniobox.h @@ -0,0 +1,30 @@ +/* + * 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/pinio.h" +#include "fc/rc_modes.h" +#include "pg/pg.h" + +typedef struct pinioBoxConfig_s { + int8_t boxId[PINIO_COUNT]; +} pinioBoxConfig_t; + +PG_DECLARE(pinioBoxConfig_t, pinioBoxConfig); + +#define BOXNONE (-1) diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index e7e20cc4f3..b6f24a8dbb 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -127,6 +127,10 @@ typedef enum { TASK_ADC_INTERNAL, #endif +#ifdef USE_PINIOBOX + TASK_PINIOBOX, +#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 c9f10ef58d..b35535bb5b 100644 --- a/src/main/target/common_fc_pre.h +++ b/src/main/target/common_fc_pre.h @@ -138,6 +138,7 @@ #define USE_OSD #define USE_OSD_OVER_MSP_DISPLAYPORT #define USE_PINIO +#define USE_PINIOBOX #define USE_RCDEVICE #define USE_RTC_TIME #define USE_RX_MSP From 45c5d376938f1a4bbabc7d83c4bcda01c91bca82 Mon Sep 17 00:00:00 2001 From: jflyper Date: Mon, 12 Feb 2018 15:57:15 +0900 Subject: [PATCH 2/2] Use permanentId for config, convert to boxId_e at init --- src/main/interface/settings.c | 5 ++++- src/main/io/piniobox.c | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/interface/settings.c b/src/main/interface/settings.c index 71cf397b7c..c69dfc3fa4 100644 --- a/src/main/interface/settings.c +++ b/src/main/interface/settings.c @@ -70,6 +70,7 @@ #include "pg/pg.h" #include "pg/pg_ids.h" #include "pg/pinio.h" +#include "pg/piniobox.h" #include "pg/rx_pwm.h" #include "pg/sdcard.h" #include "pg/vcd.h" @@ -869,7 +870,9 @@ const clivalue_t valueTable[] = { // PG_PINIO_CONFIG #ifdef USE_PINIO { "pinio_config", VAR_UINT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIO_CONFIG, offsetof(pinioConfig_t, config) }, - { "piniobox_config", VAR_INT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIOBOX_CONFIG, offsetof(pinioBoxConfig_t, boxId) }, +#ifdef USE_PINIOBOX + { "pinio_box", VAR_INT8 | MASTER_VALUE | MODE_ARRAY, .config.array.length = PINIO_COUNT, PG_PINIOBOX_CONFIG, offsetof(pinioBoxConfig_t, boxId) }, +#endif #endif }; diff --git a/src/main/io/piniobox.c b/src/main/io/piniobox.c index 88930cf89e..eb1349ff1c 100644 --- a/src/main/io/piniobox.c +++ b/src/main/io/piniobox.c @@ -33,11 +33,22 @@ #include "piniobox.h" -static const pinioBoxConfig_t *config; +static pinioBoxConfig_t pinioBoxRuntimeConfig; void pinioBoxInit(const pinioBoxConfig_t *pinioBoxConfig) { - config = pinioBoxConfig; + // Convert permanentId to boxId_e + + pinioBoxRuntimeConfig = *pinioBoxConfig; + + for (int i = 0; i < PINIO_COUNT; i++) { + if (pinioBoxRuntimeConfig.boxId[i] >= 0) { + const box_t *box = findBoxByPermanentId(pinioBoxRuntimeConfig.boxId[i]); + if (box) { + pinioBoxRuntimeConfig.boxId[i] = box->boxId; + } + } + } } void pinioBoxUpdate(timeUs_t currentTimeUs) @@ -45,7 +56,9 @@ void pinioBoxUpdate(timeUs_t currentTimeUs) UNUSED(currentTimeUs); for (int i = 0; i < PINIO_COUNT; i++) { - pinioSet(i, getBoxIdState(config->boxId[i])); + if (pinioBoxRuntimeConfig.boxId[i] >= 0) { + pinioSet(i, getBoxIdState(pinioBoxRuntimeConfig.boxId[i])); + } } }