From 418262a131f7155acaef3f46192c3c22b7110a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 3 Jan 2020 10:21:10 +0100 Subject: [PATCH] px4_micro_hal: add PX4_MAKE_GPIO_INPUT and PX4_MAKE_GPIO_OUTPUT Instead of using macros defined in the board config. --- .../px4/nxp/imxrt/board_hw_info/board_hw_rev_ver.c | 11 ++++++----- .../src/px4/nxp/k66/include/px4_arch/micro_hal.h | 4 ++++ .../src/px4/nxp/rt106x/include/px4_arch/micro_hal.h | 2 ++ .../stm/stm32_common/board_hw_info/board_hw_rev_ver.c | 11 ++++++----- .../px4/stm/stm32_common/include/px4_arch/micro_hal.h | 3 +++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/platforms/nuttx/src/px4/nxp/imxrt/board_hw_info/board_hw_rev_ver.c b/platforms/nuttx/src/px4/nxp/imxrt/board_hw_info/board_hw_rev_ver.c index 1ee7f75a44..f0097cb967 100644 --- a/platforms/nuttx/src/px4/nxp/imxrt/board_hw_info/board_hw_rev_ver.c +++ b/platforms/nuttx/src/px4/nxp/imxrt/board_hw_info/board_hw_rev_ver.c @@ -38,6 +38,7 @@ */ #include #include +#include #include #include #include @@ -155,29 +156,29 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc /* Turn the drive lines to digital inputs with No pull up */ - imxrt_config_gpio(_MK_GPIO_INPUT(gpio_drive) & ~IOMUX_PULL_MASK); + imxrt_config_gpio(PX4_MAKE_GPIO_INPUT(gpio_drive) & ~IOMUX_PULL_MASK); /* Turn the sense lines to digital outputs LOW */ - imxrt_config_gpio(_MK_GPIO_OUTPUT(gpio_sense)); + imxrt_config_gpio(PX4_MAKE_GPIO_OUTPUT(gpio_sense)); up_udelay(100); /* About 10 TC assuming 485 K */ /* Read Drive lines while sense are driven low */ - int low = imxrt_gpio_read(_MK_GPIO_INPUT(gpio_drive)); + int low = imxrt_gpio_read(PX4_MAKE_GPIO_INPUT(gpio_drive)); /* Write the sense lines HIGH */ - imxrt_gpio_write(_MK_GPIO_OUTPUT(gpio_sense), 1); + imxrt_gpio_write(PX4_MAKE_GPIO_OUTPUT(gpio_sense), 1); up_udelay(100); /* About 10 TC assuming 485 K */ /* Read Drive lines while sense are driven high */ - int high = imxrt_gpio_read(_MK_GPIO_INPUT(gpio_drive)); + int high = imxrt_gpio_read(PX4_MAKE_GPIO_INPUT(gpio_drive)); /* restore the pins to ANALOG */ diff --git a/platforms/nuttx/src/px4/nxp/k66/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/nxp/k66/include/px4_arch/micro_hal.h index 33930f5235..b641d07819 100644 --- a/platforms/nuttx/src/px4/nxp/k66/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/nxp/k66/include/px4_arch/micro_hal.h @@ -109,4 +109,8 @@ __BEGIN_DECLS #define px4_arch_gpiosetevent(pinset,r,f,e,fp,a) kinetis_gpiosetevent(pinset,r,f,e,fp,a) +#define _PX4_MAKE_GPIO(pin_ftmx, io) ((((uint32_t)(pin_ftmx)) & ~(_PIN_MODE_MASK | _PIN_OPTIONS_MASK)) |(io)) +#define PX4_MAKE_GPIO_INPUT(gpio) _PX4_MAKE_GPIO(gpio, GPIO_PULLUP) +#define PX4_MAKE_GPIO_OUTPUT(gpio) _PX4_MAKE_GPIO(gpio, GPIO_HIGHDRIVE) + __END_DECLS diff --git a/platforms/nuttx/src/px4/nxp/rt106x/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/nxp/rt106x/include/px4_arch/micro_hal.h index 311d8490e0..104fc79757 100644 --- a/platforms/nuttx/src/px4/nxp/rt106x/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/nxp/rt106x/include/px4_arch/micro_hal.h @@ -105,5 +105,7 @@ __BEGIN_DECLS #define px4_arch_gpiosetevent(pinset,r,f,e,fp,a) imxrt_gpiosetevent(pinset,r,f,e,fp,a) +#define PX4_MAKE_GPIO_INPUT(gpio) (((gpio) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT | IOMUX_SCHMITT_TRIGGER | IOMUX_PULL_UP_47K | IOMUX_DRIVE_HIZ)) +#define PX4_MAKE_GPIO_OUTPUT(gpio) (((gpio) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_OUTPUT | GPIO_OUTPUT_ZERO | IOMUX_CMOS_OUTPUT | IOMUX_PULL_KEEP | IOMUX_DRIVE_33OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_FAST)) __END_DECLS diff --git a/platforms/nuttx/src/px4/stm/stm32_common/board_hw_info/board_hw_rev_ver.c b/platforms/nuttx/src/px4/stm/stm32_common/board_hw_info/board_hw_rev_ver.c index 89fb547df4..74311b530b 100644 --- a/platforms/nuttx/src/px4/stm/stm32_common/board_hw_info/board_hw_rev_ver.c +++ b/platforms/nuttx/src/px4/stm/stm32_common/board_hw_info/board_hw_rev_ver.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -156,29 +157,29 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc /* Turn the drive lines to digital inputs with No pull up */ - stm32_configgpio(_MK_GPIO_INPUT(gpio_drive) & ~GPIO_PUPD_MASK); + stm32_configgpio(PX4_MAKE_GPIO_INPUT(gpio_drive) & ~GPIO_PUPD_MASK); /* Turn the sense lines to digital outputs LOW */ - stm32_configgpio(_MK_GPIO_OUTPUT(gpio_sense)); + stm32_configgpio(PX4_MAKE_GPIO_OUTPUT(gpio_sense)); up_udelay(100); /* About 10 TC assuming 485 K */ /* Read Drive lines while sense are driven low */ - int low = stm32_gpioread(_MK_GPIO_INPUT(gpio_drive)); + int low = stm32_gpioread(PX4_MAKE_GPIO_INPUT(gpio_drive)); /* Write the sense lines HIGH */ - stm32_gpiowrite(_MK_GPIO_OUTPUT(gpio_sense), 1); + stm32_gpiowrite(PX4_MAKE_GPIO_OUTPUT(gpio_sense), 1); up_udelay(100); /* About 10 TC assuming 485 K */ /* Read Drive lines while sense are driven high */ - int high = stm32_gpioread(_MK_GPIO_INPUT(gpio_drive)); + int high = stm32_gpioread(PX4_MAKE_GPIO_INPUT(gpio_drive)); /* restore the pins to ANALOG */ diff --git a/platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/micro_hal.h b/platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/micro_hal.h index 6b1bb58216..582c43fc7f 100644 --- a/platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/micro_hal.h +++ b/platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/micro_hal.h @@ -102,4 +102,7 @@ __BEGIN_DECLS #define px4_arch_gpiowrite(pinset, value) stm32_gpiowrite(pinset, value) #define px4_arch_gpiosetevent(pinset,r,f,e,fp,a) stm32_gpiosetevent(pinset,r,f,e,fp,a) +#define PX4_MAKE_GPIO_INPUT(gpio) (((gpio) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT|GPIO_PULLUP)) +#define PX4_MAKE_GPIO_OUTPUT(gpio) (((gpio) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR)) + __END_DECLS