px4_micro_hal: add PX4_MAKE_GPIO_INPUT and PX4_MAKE_GPIO_OUTPUT

Instead of using macros defined in the board config.
This commit is contained in:
Beat Küng 2020-01-03 10:21:10 +01:00 committed by David Sidrane
parent 685be9b3d1
commit 418262a131
5 changed files with 21 additions and 10 deletions

View File

@ -38,6 +38,7 @@
*/
#include <drivers/drv_adc.h>
#include <px4_arch/adc.h>
#include <px4_platform_common/micro_hal.h>
#include <px4_platform_common/px4_config.h>
#include <px4_platform/board_determine_hw_info.h>
#include <stdio.h>
@ -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 */

View File

@ -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

View File

@ -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

View File

@ -39,6 +39,7 @@
#include <drivers/drv_adc.h>
#include <px4_arch/adc.h>
#include <px4_platform_common/micro_hal.h>
#include <px4_platform_common/px4_config.h>
#include <px4_platform/board_determine_hw_info.h>
#include <stdio.h>
@ -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 */

View File

@ -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