diff --git a/make/source.mk b/make/source.mk
index 04de19c25d..c248b3b36a 100644
--- a/make/source.mk
+++ b/make/source.mk
@@ -31,6 +31,7 @@ COMMON_SRC = \
drivers/mco.c \
drivers/motor.c \
drivers/pinio.c \
+ drivers/pin_pull_up_down.c \
drivers/resource.c \
drivers/rcc.c \
drivers/serial.c \
diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c
index 3dcdc6ec90..ff44d91d44 100644
--- a/src/main/cli/cli.c
+++ b/src/main/cli/cli.c
@@ -137,6 +137,7 @@ bool cliMode = false;
#include "pg/mco.h"
#include "pg/motor.h"
#include "pg/pinio.h"
+#include "pg/pin_pull_up_down.h"
#include "pg/pg.h"
#include "pg/pg_ids.h"
#include "pg/rx.h"
@@ -4913,6 +4914,10 @@ const cliResourceValue_t resourceTable[] = {
DEFS( OWNER_VTX_DATA, PG_VTX_IO_CONFIG, vtxIOConfig_t, dataTag ),
DEFS( OWNER_VTX_CLK, PG_VTX_IO_CONFIG, vtxIOConfig_t, clockTag ),
#endif
+#ifdef USE_PIN_PULL_UP_DOWN
+ DEFA( OWNER_PULLUP, PG_PULLUP_CONFIG, pinPullUpDownConfig_t, ioTag, PIN_PULL_UP_DOWN_COUNT ),
+ DEFA( OWNER_PULLDOWN, PG_PULLDOWN_CONFIG, pinPullUpDownConfig_t, ioTag, PIN_PULL_UP_DOWN_COUNT ),
+#endif
};
#undef DEFS
diff --git a/src/main/drivers/pin_pull_up_down.c b/src/main/drivers/pin_pull_up_down.c
new file mode 100644
index 0000000000..021ac91e0c
--- /dev/null
+++ b/src/main/drivers/pin_pull_up_down.c
@@ -0,0 +1,57 @@
+/*
+ * 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 .
+ */
+
+#include
+
+#include "platform.h"
+
+#ifdef USE_PIN_PULL_UP_DOWN
+
+#include "build/debug.h"
+#include "drivers/io.h"
+#include "pg/pin_pull_up_down.h"
+#include "pin_pull_up_down.h"
+
+
+static void initPin(const pinPullUpDownConfig_t* config, resourceOwner_e owner, uint8_t index)
+{
+ IO_t io = IOGetByTag(config->ioTag);
+ if (!io) {
+ return;
+ }
+
+ IOInit(io, owner, RESOURCE_INDEX(index));
+
+ if (owner == OWNER_PULLUP) {
+ IOConfigGPIO(io, IOCFG_IPU);
+ } else if (owner == OWNER_PULLDOWN) {
+ IOConfigGPIO(io, IOCFG_IPD);
+ }
+}
+
+void pinPullupPulldownInit()
+{
+ for (uint8_t i = 0; i < PIN_PULL_UP_DOWN_COUNT; i++) {
+ initPin(pinPullupConfig(i), OWNER_PULLUP, i);
+ initPin(pinPulldownConfig(i), OWNER_PULLDOWN, i);
+ }
+}
+
+#endif
diff --git a/src/main/drivers/pin_pull_up_down.h b/src/main/drivers/pin_pull_up_down.h
new file mode 100644
index 0000000000..36a458c5db
--- /dev/null
+++ b/src/main/drivers/pin_pull_up_down.h
@@ -0,0 +1,31 @@
+/*
+ * 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 .
+ */
+
+#pragma once
+
+#include
+
+#ifndef PIN_PULL_UP_DOWN_COUNT
+#define PIN_PULL_UP_DOWN_COUNT 4
+#endif
+
+struct pinPullUpDownConfig_s;
+
+void pinPullupPulldownInit();
diff --git a/src/main/drivers/resource.c b/src/main/drivers/resource.c
index d9e09bb002..c4c9a460c2 100644
--- a/src/main/drivers/resource.c
+++ b/src/main/drivers/resource.c
@@ -105,4 +105,6 @@ const char * const ownerNames[OWNER_TOTAL_COUNT] = {
"QSPI_BK2IO3",
"QSPI_BK2CS",
"BARO_XCLR",
+ "PULLUP",
+ "PULLDOWN"
};
diff --git a/src/main/drivers/resource.h b/src/main/drivers/resource.h
index 98226a903b..c8c9c31d8c 100644
--- a/src/main/drivers/resource.h
+++ b/src/main/drivers/resource.h
@@ -103,6 +103,8 @@ typedef enum {
OWNER_QUADSPI_BK2IO3,
OWNER_QUADSPI_BK2CS,
OWNER_BARO_XCLR,
+ OWNER_PULLUP,
+ OWNER_PULLDOWN,
OWNER_TOTAL_COUNT
} resourceOwner_e;
diff --git a/src/main/fc/init.c b/src/main/fc/init.c
index df9fc34d95..f8370bd10c 100644
--- a/src/main/fc/init.c
+++ b/src/main/fc/init.c
@@ -59,6 +59,7 @@
#include "drivers/mco.h"
#include "drivers/nvic.h"
#include "drivers/persistent.h"
+#include "drivers/pin_pull_up_down.h"
#include "drivers/pwm_esc_detect.h"
#include "drivers/pwm_output.h"
#include "drivers/rx/rx_pwm.h"
@@ -140,6 +141,7 @@
#include "pg/motor.h"
#include "pg/pinio.h"
#include "pg/piniobox.h"
+#include "pg/pin_pull_up_down.h"
#include "pg/pg.h"
#include "pg/rx.h"
#include "pg/rx_spi.h"
@@ -694,6 +696,10 @@ void init(void)
pinioInit(pinioConfig());
#endif
+#ifdef USE_PIN_PULL_UP_DOWN
+ pinPullupPulldownInit();
+#endif
+
#ifdef USE_PINIOBOX
pinioBoxInit(pinioBoxConfig());
#endif
diff --git a/src/main/pg/pg_ids.h b/src/main/pg/pg_ids.h
index 66a084d100..a5a21c33f8 100644
--- a/src/main/pg/pg_ids.h
+++ b/src/main/pg/pg_ids.h
@@ -147,7 +147,9 @@
#define PG_QUADSPI_CONFIG 548
#define PG_TIMER_UP_CONFIG 549 // used to store dmaopt for TIMx_UP channel
#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)
diff --git a/src/main/pg/pin_pull_up_down.c b/src/main/pg/pin_pull_up_down.c
new file mode 100644
index 0000000000..7cf7b8968c
--- /dev/null
+++ b/src/main/pg/pin_pull_up_down.c
@@ -0,0 +1,49 @@
+/*
+ * 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 .
+ */
+
+#include "platform.h"
+
+#ifdef USE_PIN_PULL_UP_DOWN
+
+#include "drivers/io.h"
+#include "pg/pg_ids.h"
+#include "pin_pull_up_down.h"
+
+static void resetPullUpDownConfig(pinPullUpDownConfig_t* config)
+{
+ for (uint8_t i = 0; i < PIN_PULL_UP_DOWN_COUNT; i++) {
+ config[i].ioTag = IO_TAG(NONE);
+ }
+}
+
+PG_REGISTER_ARRAY_WITH_RESET_FN(pinPullUpDownConfig_t, PIN_PULL_UP_DOWN_COUNT, pinPullupConfig, PG_PULLUP_CONFIG, 0);
+
+void pgResetFn_pinPullupConfig(pinPullUpDownConfig_t *config)
+{
+ resetPullUpDownConfig(config);
+}
+
+PG_REGISTER_ARRAY_WITH_RESET_FN(pinPullUpDownConfig_t, PIN_PULL_UP_DOWN_COUNT, pinPulldownConfig, PG_PULLDOWN_CONFIG, 0);
+
+void pgResetFn_pinPulldownConfig(pinPullUpDownConfig_t *config)
+{
+ resetPullUpDownConfig(config);
+}
+#endif
diff --git a/src/main/pg/pin_pull_up_down.h b/src/main/pg/pin_pull_up_down.h
new file mode 100644
index 0000000000..9d542dc5a9
--- /dev/null
+++ b/src/main/pg/pin_pull_up_down.h
@@ -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 .
+ */
+
+#pragma once
+
+#include "drivers/io_types.h"
+#include "drivers/pin_pull_up_down.h"
+#include "pg/pg.h"
+
+typedef struct pinPullUpDownConfig_s {
+ ioTag_t ioTag;
+} pinPullUpDownConfig_t;
+
+PG_DECLARE_ARRAY(pinPullUpDownConfig_t, PIN_PULL_UP_DOWN_COUNT, pinPullupConfig);
+PG_DECLARE_ARRAY(pinPullUpDownConfig_t, PIN_PULL_UP_DOWN_COUNT, pinPulldownConfig);
diff --git a/src/main/target/common_pre.h b/src/main/target/common_pre.h
index 7633e7c55c..5a662b0c8a 100644
--- a/src/main/target/common_pre.h
+++ b/src/main/target/common_pre.h
@@ -280,6 +280,7 @@
#define USE_SPEKTRUM_VTX_CONTROL
#define USE_SPEKTRUM_VTX_TELEMETRY
#define USE_SPEKTRUM_CMS_TELEMETRY
+#define USE_PIN_PULL_UP_DOWN
#endif
#endif