Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / io / piniobox.c
blob47e381341a37a0b965b2042060d80e37af091319
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdint.h>
23 #include "platform.h"
25 #ifdef USE_PINIOBOX
27 #include "build/debug.h"
29 #include "common/time.h"
30 #include "common/utils.h"
32 #include "msp/msp_box.h"
34 #include "pg/pinio.h"
35 #include "pg/piniobox.h"
37 #include "scheduler/scheduler.h"
39 #include "piniobox.h"
41 typedef struct pinioBoxRuntimeConfig_s {
42 uint8_t boxId[PINIO_COUNT];
43 } pinioBoxRuntimeConfig_t;
45 static pinioBoxRuntimeConfig_t pinioBoxRuntimeConfig;
47 void pinioBoxInit(const pinioBoxConfig_t *pinioBoxConfig)
49 // Convert permanentId to boxId_e
51 for (int i = 0; i < PINIO_COUNT; i++) {
52 const box_t *box = findBoxByPermanentId(pinioBoxConfig->permanentId[i]);
54 pinioBoxRuntimeConfig.boxId[i] = box ? box->boxId : BOXID_NONE;
58 void pinioBoxUpdate(timeUs_t currentTimeUs)
60 UNUSED(currentTimeUs);
62 for (int i = 0; i < PINIO_COUNT; i++) {
63 if (pinioBoxRuntimeConfig.boxId[i] != BOXID_NONE) {
64 pinioSet(i, getBoxIdState(pinioBoxRuntimeConfig.boxId[i]));
69 void pinioBoxTaskControl(void)
71 bool enableTask = false;
72 for (int i = 0; i < PINIO_COUNT; i++) {
73 if (pinioBoxRuntimeConfig.boxId[i] != BOXID_NONE && isModeActivationConditionPresent(pinioBoxRuntimeConfig.boxId[i])) {
74 enableTask = true;
75 break;
78 setTaskEnabled(TASK_PINIOBOX, enableTask);
80 #endif