Merge pull request #8723 from schugabe/pin_up_down_config
Add resource option to configure unused pins as pulldown
This commit is contained in:
commit
d331aed726
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef PIN_PULL_UP_DOWN_COUNT
|
||||
#define PIN_PULL_UP_DOWN_COUNT 4
|
||||
#endif
|
||||
|
||||
struct pinPullUpDownConfig_s;
|
||||
|
||||
void pinPullupPulldownInit();
|
|
@ -105,4 +105,6 @@ const char * const ownerNames[OWNER_TOTAL_COUNT] = {
|
|||
"QSPI_BK2IO3",
|
||||
"QSPI_BK2CS",
|
||||
"BARO_XCLR",
|
||||
"PULLUP",
|
||||
"PULLDOWN"
|
||||
};
|
||||
|
|
|
@ -103,6 +103,8 @@ typedef enum {
|
|||
OWNER_QUADSPI_BK2IO3,
|
||||
OWNER_QUADSPI_BK2CS,
|
||||
OWNER_BARO_XCLR,
|
||||
OWNER_PULLUP,
|
||||
OWNER_PULLDOWN,
|
||||
OWNER_TOTAL_COUNT
|
||||
} resourceOwner_e;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
|
@ -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 "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);
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue