mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Add resource option to configure pin as pullup or pulldown input
all pins are initialized to pullup inputs per default. With resource PULLDOWN 1 PIN it is possible to reconfigure the pin so it is a PULLDOWN input. With this it's possible to prevent certain errors on some boards that have multiple pins connected with an inverter and the pullup flows back via the inverter and pulls other pins low (see #7849)
This commit is contained in:
parent
811eeea542
commit
cc9687a2bf
11 changed files with 193 additions and 1 deletions
|
@ -31,6 +31,7 @@ COMMON_SRC = \
|
||||||
drivers/mco.c \
|
drivers/mco.c \
|
||||||
drivers/motor.c \
|
drivers/motor.c \
|
||||||
drivers/pinio.c \
|
drivers/pinio.c \
|
||||||
|
drivers/pin_up_down.c \
|
||||||
drivers/resource.c \
|
drivers/resource.c \
|
||||||
drivers/rcc.c \
|
drivers/rcc.c \
|
||||||
drivers/serial.c \
|
drivers/serial.c \
|
||||||
|
|
|
@ -149,6 +149,7 @@ bool cliMode = false;
|
||||||
#include "pg/timerup.h"
|
#include "pg/timerup.h"
|
||||||
#include "pg/usb.h"
|
#include "pg/usb.h"
|
||||||
#include "pg/vtx_table.h"
|
#include "pg/vtx_table.h"
|
||||||
|
#include "pg/pin_up_down.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
#include "rx/spektrum.h"
|
#include "rx/spektrum.h"
|
||||||
|
@ -4913,6 +4914,10 @@ const cliResourceValue_t resourceTable[] = {
|
||||||
DEFS( OWNER_VTX_DATA, PG_VTX_IO_CONFIG, vtxIOConfig_t, dataTag ),
|
DEFS( OWNER_VTX_DATA, PG_VTX_IO_CONFIG, vtxIOConfig_t, dataTag ),
|
||||||
DEFS( OWNER_VTX_CLK, PG_VTX_IO_CONFIG, vtxIOConfig_t, clockTag ),
|
DEFS( OWNER_VTX_CLK, PG_VTX_IO_CONFIG, vtxIOConfig_t, clockTag ),
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_PIN_UP_DOWN
|
||||||
|
DEFA( OWNER_PULLUP, PG_PULLUP_CONFIG, pinUpDownConfig_t, ioTag, PIN_UP_DOWN_COUNT ),
|
||||||
|
DEFA( OWNER_PULLDOWN, PG_PULLDOWN_CONFIG, pinUpDownConfig_t, ioTag, PIN_UP_DOWN_COUNT ),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef DEFS
|
#undef DEFS
|
||||||
|
|
62
src/main/drivers/pin_up_down.c
Normal file
62
src/main/drivers/pin_up_down.c
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* This file is part of 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)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight and Betaflight are distributed in the hope that they
|
||||||
|
* 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 this software.
|
||||||
|
*
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#ifdef USE_PIN_UP_DOWN
|
||||||
|
|
||||||
|
#include "build/debug.h"
|
||||||
|
|
||||||
|
#include "pg/pin_up_down.h"
|
||||||
|
|
||||||
|
#include "drivers/io.h"
|
||||||
|
|
||||||
|
static void initPins(const pinUpDownConfig_t * config, resourceOwner_e owner)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < PIN_UP_DOWN_COUNT; i++) {
|
||||||
|
IO_t io = IOGetByTag(config->ioTag[i]);
|
||||||
|
|
||||||
|
if (!io) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
IOInit(io, OWNER_PINIO, RESOURCE_INDEX(i));
|
||||||
|
|
||||||
|
if (owner == OWNER_PULLUP) {
|
||||||
|
IOConfigGPIO(io, IOCFG_IPU);
|
||||||
|
} else if (owner == OWNER_PULLDOWN) {
|
||||||
|
IOConfigGPIO(io, IOCFG_IPD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pinPullupInit(const pinUpDownConfig_t * pullupConfig)
|
||||||
|
{
|
||||||
|
initPins(pullupConfig, OWNER_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pinPulldownInit(const pinUpDownConfig_t * pulldownConfig)
|
||||||
|
{
|
||||||
|
initPins(pulldownConfig, OWNER_PULLDOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
32
src/main/drivers/pin_up_down.h
Normal file
32
src/main/drivers/pin_up_down.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* This file is part of 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)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight and Betaflight are distributed in the hope that they
|
||||||
|
* 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 this software.
|
||||||
|
*
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifndef PIN_UP_DOWN_COUNT
|
||||||
|
#define PIN_UP_DOWN_COUNT 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct pinUpDownConfig_s;
|
||||||
|
|
||||||
|
void pinPullupInit(const struct pinUpDownConfig_s *pinUpDownConfig);
|
||||||
|
void pinPulldownInit(const struct pinUpDownConfig_s *pinUpDownConfig);
|
|
@ -105,4 +105,6 @@ const char * const ownerNames[OWNER_TOTAL_COUNT] = {
|
||||||
"QSPI_BK2IO3",
|
"QSPI_BK2IO3",
|
||||||
"QSPI_BK2CS",
|
"QSPI_BK2CS",
|
||||||
"BARO_XCLR",
|
"BARO_XCLR",
|
||||||
|
"PULLUP",
|
||||||
|
"PULLDOWN"
|
||||||
};
|
};
|
||||||
|
|
|
@ -103,6 +103,8 @@ typedef enum {
|
||||||
OWNER_QUADSPI_BK2IO3,
|
OWNER_QUADSPI_BK2IO3,
|
||||||
OWNER_QUADSPI_BK2CS,
|
OWNER_QUADSPI_BK2CS,
|
||||||
OWNER_BARO_XCLR,
|
OWNER_BARO_XCLR,
|
||||||
|
OWNER_PULLUP,
|
||||||
|
OWNER_PULLDOWN,
|
||||||
OWNER_TOTAL_COUNT
|
OWNER_TOTAL_COUNT
|
||||||
} resourceOwner_e;
|
} resourceOwner_e;
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
#include "drivers/vtx_common.h"
|
#include "drivers/vtx_common.h"
|
||||||
#include "drivers/vtx_rtc6705.h"
|
#include "drivers/vtx_rtc6705.h"
|
||||||
#include "drivers/vtx_table.h"
|
#include "drivers/vtx_table.h"
|
||||||
|
#include "drivers/pin_up_down.h"
|
||||||
|
|
||||||
#include "fc/board_info.h"
|
#include "fc/board_info.h"
|
||||||
#include "fc/config.h"
|
#include "fc/config.h"
|
||||||
|
@ -147,6 +148,7 @@
|
||||||
#include "pg/sdcard.h"
|
#include "pg/sdcard.h"
|
||||||
#include "pg/vcd.h"
|
#include "pg/vcd.h"
|
||||||
#include "pg/vtx_io.h"
|
#include "pg/vtx_io.h"
|
||||||
|
#include "pg/pin_up_down.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
#include "rx/rx_spi.h"
|
#include "rx/rx_spi.h"
|
||||||
|
@ -694,6 +696,11 @@ void init(void)
|
||||||
pinioInit(pinioConfig());
|
pinioInit(pinioConfig());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_PIN_UP_DOWN
|
||||||
|
pinPullupInit(pinPullupConfig());
|
||||||
|
pinPulldownInit(pinPulldownConfig());
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_PINIOBOX
|
#ifdef USE_PINIOBOX
|
||||||
pinioBoxInit(pinioBoxConfig());
|
pinioBoxInit(pinioBoxConfig());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -147,7 +147,9 @@
|
||||||
#define PG_QUADSPI_CONFIG 548
|
#define PG_QUADSPI_CONFIG 548
|
||||||
#define PG_TIMER_UP_CONFIG 549 // used to store dmaopt for TIMx_UP channel
|
#define PG_TIMER_UP_CONFIG 549 // used to store dmaopt for TIMx_UP channel
|
||||||
#define PG_SDIO_PIN_CONFIG 550
|
#define PG_SDIO_PIN_CONFIG 550
|
||||||
#define PG_BETAFLIGHT_END 550
|
#define PG_PULLUP_CONFIG 551
|
||||||
|
#define PG_PULLDOWN_CONFIG 552
|
||||||
|
#define PG_BETAFLIGHT_END 552
|
||||||
|
|
||||||
|
|
||||||
// OSD configuration (subject to change)
|
// OSD configuration (subject to change)
|
||||||
|
|
45
src/main/pg/pin_up_down.c
Normal file
45
src/main/pg/pin_up_down.c
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* This file is part of 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)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight and Betaflight are distributed in the hope that they
|
||||||
|
* 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 this software.
|
||||||
|
*
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#ifdef USE_PINIO
|
||||||
|
|
||||||
|
#include "pg/pg_ids.h"
|
||||||
|
#include "pin_up_down.h"
|
||||||
|
#include "drivers/io.h"
|
||||||
|
|
||||||
|
PG_REGISTER_WITH_RESET_TEMPLATE(pinUpDownConfig_t, pinPullupConfig, PG_PULLUP_CONFIG, 0);
|
||||||
|
PG_REGISTER_WITH_RESET_TEMPLATE(pinUpDownConfig_t, pinPulldownConfig, PG_PULLDOWN_CONFIG, 0);
|
||||||
|
|
||||||
|
PG_RESET_TEMPLATE(pinUpDownConfig_t, pinPullupConfig,
|
||||||
|
.ioTag = {
|
||||||
|
IO_TAG(NONE),
|
||||||
|
IO_TAG(NONE),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
PG_RESET_TEMPLATE(pinUpDownConfig_t, pinPulldownConfig,
|
||||||
|
.ioTag = {
|
||||||
|
IO_TAG(NONE),
|
||||||
|
IO_TAG(NONE),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
#endif
|
33
src/main/pg/pin_up_down.h
Normal file
33
src/main/pg/pin_up_down.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* This file is part of 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)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight and Betaflight are distributed in the hope that they
|
||||||
|
* 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 this software.
|
||||||
|
*
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../drivers/pin_up_down.h"
|
||||||
|
|
||||||
|
#include "pg/pg.h"
|
||||||
|
#include "drivers/io_types.h"
|
||||||
|
|
||||||
|
typedef struct pinUpDownConfig_s {
|
||||||
|
ioTag_t ioTag[PIN_UP_DOWN_COUNT];
|
||||||
|
} pinUpDownConfig_t;
|
||||||
|
|
||||||
|
PG_DECLARE(pinUpDownConfig_t, pinPullupConfig);
|
||||||
|
PG_DECLARE(pinUpDownConfig_t, pinPulldownConfig);
|
|
@ -264,6 +264,7 @@
|
||||||
#define USE_HUFFMAN
|
#define USE_HUFFMAN
|
||||||
#define USE_PINIO
|
#define USE_PINIO
|
||||||
#define USE_PINIOBOX
|
#define USE_PINIOBOX
|
||||||
|
#define USE_PIN_UP_DOWN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ((FLASH_SIZE > 256) || (FEATURE_CUT_LEVEL < 3))
|
#if ((FLASH_SIZE > 256) || (FEATURE_CUT_LEVEL < 3))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue