From e2f3065205a4a17e5ebe9f0040e0eddef5889171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 13 Jan 2020 16:29:25 +0100 Subject: [PATCH] nxp/fmurt1062-v1: use hw description methods for timer configuration --- boards/nxp/fmurt1062-v1/src/CMakeLists.txt | 4 +- boards/nxp/fmurt1062-v1/src/board_config.h | 68 --------- boards/nxp/fmurt1062-v1/src/init.c | 8 +- .../src/{timer_config.c => timer_config.cpp} | 139 +++--------------- 4 files changed, 25 insertions(+), 194 deletions(-) rename boards/nxp/fmurt1062-v1/src/{timer_config.c => timer_config.cpp} (56%) diff --git a/boards/nxp/fmurt1062-v1/src/CMakeLists.txt b/boards/nxp/fmurt1062-v1/src/CMakeLists.txt index 53afd8fbe49b..a0831d9edcba 100644 --- a/boards/nxp/fmurt1062-v1/src/CMakeLists.txt +++ b/boards/nxp/fmurt1062-v1/src/CMakeLists.txt @@ -39,7 +39,7 @@ px4_add_library(drivers_board led.c sdhc.c spi.cpp - timer_config.c + timer_config.cpp usb.c manifest.c imxrt_flexspi_nor_boot.c @@ -54,4 +54,4 @@ target_link_libraries(drivers_board nuttx_arch # sdio nuttx_drivers # sdio px4_layer -) \ No newline at end of file +) diff --git a/boards/nxp/fmurt1062-v1/src/board_config.h b/boards/nxp/fmurt1062-v1/src/board_config.h index a37991c56877..79c1429bf6f7 100644 --- a/boards/nxp/fmurt1062-v1/src/board_config.h +++ b/boards/nxp/fmurt1062-v1/src/board_config.h @@ -326,30 +326,7 @@ #define BOARD_INDICATE_ARMED_STATE(on_armed) px4_arch_configgpio((on_armed) ? GPIO_nARMED : GPIO_nARMED_INIT) /* PWM - * - * 8 PWM outputs are configured. - * - * Pins: - * - * FMU_CH1 : GPIO_B0_06 GPIO2 Pin 6 FLEXPWM2_PWMA0 - * FMU_CH2 : GPIO_EMC_08 GPIO4 Pin 8 FLEXPWM2_PWMA1 - * FMU_CH3 : GPIO_EMC_10 GPIO4 Pin 10 FLEXPWM2_PWMA2 - * FMU_CH4 : GPIO_AD_B0_09 GPIO1 Pin 9 FLEXPWM2_PWMA3 - * FMU_CH5 : GPIO_EMC_33 GPIO3 Pin 19 FLEXPWM3_PWMA2 - * FMU_CH6 : GPIO_EMC_30 GPIO4 Pin 30 FLEXPWM3_PWMB0 - * FMU_CH7 : GPIO_EMC_04 GPIO4 Pin 4 FLEXPWM4_PWMA2 - * FMU_CH8 : GPIO_EMC_01 GPIO4 Pin 1 FLEXPWM4_PWMB0 - * */ -#define PWM_IOMUX (IOMUX_CMOS_OUTPUT | IOMUX_PULL_NONE | IOMUX_DRIVE_50OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_FAST) -#define PIN_FLEXPWM2_PWMA00 /* P2:6 GPIO_B0_06 PWM2 A0 FMU1 */ (PWM_IOMUX | GPIO_FLEXPWM2_PWMA00_2) -#define PIN_FLEXPWM2_PWMA01 /* P4:8 GPIO_EMC_08 PWM2 A1 FMU2 */ (PWM_IOMUX | GPIO_FLEXPWM2_PWMA01_1) -#define PIN_FLEXPWM2_PWMA02 /* P4:10 GPIO_EMC_10 PWM2 A2 FMU3 */ (PWM_IOMUX | GPIO_FLEXPWM2_PWMA02_1) -#define PIN_FLEXPWM2_PWMA03 /* P1:9 GPIO_AD_B0_09 PWM2 A3 FMU4 */ (PWM_IOMUX | GPIO_FLEXPWM2_PWMA03_2) -#define PIN_FLEXPWM3_PWMA02 /* P3:19 GPIO_EMC_33 PWM3 A2 FMU5 */ (PWM_IOMUX | GPIO_FLEXPWM3_PWMA02_1) -#define PIN_FLEXPWM3_PWMB00 /* P4:30 GPIO_EMC_30 PWM3 B0 FMU6 */ (PWM_IOMUX | GPIO_FLEXPWM3_PWMB00_1) -#define PIN_FLEXPWM4_PWMA02 /* P4:4 GPIO_EMC_04 PWM4 A2 FMU7 */ (PWM_IOMUX | GPIO_FLEXPWM4_PWMA02_2) -#define PIN_FLEXPWM4_PWMB00 /* P4:1 GPIO_EMC_01 PWM4 B0 FMU8 */ (PWM_IOMUX | GPIO_FLEXPWM4_PWMB00_1) #define DIRECT_PWM_OUTPUT_CHANNELS 8 @@ -368,38 +345,6 @@ */ -/* User GPIOs - * - * GPIO- - * Define as GPIO input / GPIO outputs - */ - -#define FMU_INPUT_IOMUX (IOMUX_SCHMITT_TRIGGER | IOMUX_PULL_UP_47K | IOMUX_DRIVE_HIZ) - -#define _MK_GPIO_INPUT(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT | FMU_INPUT_IOMUX)) - -#define GPIO_GPIO0_INPUT /* P2:6 GPIO_B0_06 PWM2 A0 FMU1 */ (GPIO_PORT2 | GPIO_PIN6 | GPIO_INPUT | FMU_INPUT_IOMUX) -#define GPIO_GPIO1_INPUT /* P4:8 GPIO_EMC_08 PWM2 A1 FMU2 */ (GPIO_PORT4 | GPIO_PIN8 | GPIO_INPUT | FMU_INPUT_IOMUX) -#define GPIO_GPIO2_INPUT /* P4:10 GPIO_EMC_10 PWM2 A2 FMU3 */ (GPIO_PORT4 | GPIO_PIN10 | GPIO_INPUT | FMU_INPUT_IOMUX) -#define GPIO_GPIO3_INPUT /* P1:9 GPIO_AD_B0_09 PWM2 A3 FMU4 */ (GPIO_PORT1 | GPIO_PIN9 | GPIO_INPUT | FMU_INPUT_IOMUX) -#define GPIO_GPIO4_INPUT /* P3:19 GPIO_EMC_33 PWM3 A2 FMU5 */ (GPIO_PORT3 | GPIO_PIN19 | GPIO_INPUT | FMU_INPUT_IOMUX) -#define GPIO_GPIO5_INPUT /* P4:30 GPIO_EMC_30 PWM3 B0 FMU6 */ (GPIO_PORT4 | GPIO_PIN30 | GPIO_INPUT | FMU_INPUT_IOMUX) -#define GPIO_GPIO6_INPUT /* P4:4 GPIO_EMC_04 PWM4 A2 FMU7 */ (GPIO_PORT4 | GPIO_PIN4 | GPIO_INPUT | FMU_INPUT_IOMUX) -#define GPIO_GPIO7_INPUT /* P4:1 GPIO_EMC_01 PWM4 B0 FMU8 */ (GPIO_PORT4 | GPIO_PIN1 | GPIO_INPUT | FMU_INPUT_IOMUX) - -#define FMU_OUTPUT_IOMUX (IOMUX_CMOS_OUTPUT | IOMUX_PULL_KEEP | IOMUX_DRIVE_33OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_FAST) - -#define _MK_GPIO_OUTPUT(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX)) - -#define GPIO_GPIO0_OUTPUT /* P2:6 GPIO_B0_06 PWM2 A0 FMU1 */ (GPIO_PORT2 | GPIO_PIN6 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX) -#define GPIO_GPIO1_OUTPUT /* P4:8 GPIO_EMC_08 PWM2 A1 FMU2 */ (GPIO_PORT4 | GPIO_PIN8 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX) -#define GPIO_GPIO2_OUTPUT /* P4:10 GPIO_EMC_10 PWM2 A2 FMU3 */ (GPIO_PORT4 | GPIO_PIN10 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX) -#define GPIO_GPIO3_OUTPUT /* P1:9 GPIO_AD_B0_09 PWM2 A3 FMU4 */ (GPIO_PORT1 | GPIO_PIN9 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX) -#define GPIO_GPIO4_OUTPUT /* P3:19 GPIO_EMC_33 PWM3 A2 FMU5 */ (GPIO_PORT3 | GPIO_PIN19 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX) -#define GPIO_GPIO5_OUTPUT /* P4:30 GPIO_EMC_30 PWM3 B0 FMU6 */ (GPIO_PORT4 | GPIO_PIN30 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX) -#define GPIO_GPIO6_OUTPUT /* P4:4 GPIO_EMC_04 PWM4 A2 FMU7 */ (GPIO_PORT4 | GPIO_PIN4 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX) -#define GPIO_GPIO7_OUTPUT /* P4:1 GPIO_EMC_01 PWM4 B0 FMU8 */ (GPIO_PORT4 | GPIO_PIN1 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | FMU_OUTPUT_IOMUX) - /* Power supply control and monitoring GPIOs */ #define GENERAL_INPUT_IOMUX (IOMUX_CMOS_INPUT | IOMUX_PULL_UP_47K | IOMUX_DRIVE_HIZ) @@ -545,19 +490,6 @@ #define BOARD_HAS_ON_RESET 1 -/* The list of GPIO that will be initialized */ - -#define PX4_GPIO_PWM_INIT_LIST { \ - GPIO_GPIO7_INPUT, \ - GPIO_GPIO6_INPUT, \ - GPIO_GPIO5_INPUT, \ - GPIO_GPIO4_INPUT, \ - GPIO_GPIO3_INPUT, \ - GPIO_GPIO2_INPUT, \ - GPIO_GPIO1_INPUT, \ - GPIO_GPIO0_INPUT, \ - } - #define PX4_GPIO_INIT_LIST { \ GPIO_nARMED_INIT, \ PX4_ADC_GPIO, \ diff --git a/boards/nxp/fmurt1062-v1/src/init.c b/boards/nxp/fmurt1062-v1/src/init.c index 4db3dfaf634a..11290f30f6eb 100644 --- a/boards/nxp/fmurt1062-v1/src/init.c +++ b/boards/nxp/fmurt1062-v1/src/init.c @@ -73,6 +73,7 @@ #include #include #include +#include #include #include #include @@ -135,10 +136,9 @@ __EXPORT void board_peripheral_reset(int ms) __EXPORT void board_on_reset(int status) { - /* configure the GPIO pins to outputs and keep them low */ - - const uint32_t gpio[] = PX4_GPIO_PWM_INIT_LIST; - px4_gpio_init(gpio, arraySize(gpio)); + for (int i = 0; i < DIRECT_PWM_OUTPUT_CHANNELS; ++i) { + px4_arch_configgpio(PX4_MAKE_GPIO_INPUT(io_timer_channel_get_gpio_output(i))); + } if (status >= 0) { up_mdelay(6); diff --git a/boards/nxp/fmurt1062-v1/src/timer_config.c b/boards/nxp/fmurt1062-v1/src/timer_config.cpp similarity index 56% rename from boards/nxp/fmurt1062-v1/src/timer_config.c rename to boards/nxp/fmurt1062-v1/src/timer_config.cpp index 43e50a46640f..f14f66fb2b5c 100644 --- a/boards/nxp/fmurt1062-v1/src/timer_config.c +++ b/boards/nxp/fmurt1062-v1/src/timer_config.cpp @@ -31,14 +31,6 @@ * ****************************************************************************/ -/* - * @file timer_config.c - * - * Configuration data for the imxrt pwm_servo, input capture and pwm input driver. - * - * Note that these arrays must always be fully-sized. - */ - // TODO:Stubbed out for now #include @@ -52,7 +44,7 @@ #include "imxrt_periphclks.h" #include -#include +#include #include "board_config.h" @@ -83,127 +75,34 @@ #define rDMA REG(IMXRT_TMR_DMA_OFFSET) #define rENBL REG(IMXRT_TMR_ENBL_OFFSET) -__EXPORT const io_timers_t io_timers[MAX_IO_TIMERS] = { - { - .base = IMXRT_FLEXPWM2_BASE, - }, - { - .base = IMXRT_FLEXPWM3_BASE, - }, - { - .base = IMXRT_FLEXPWM4_BASE, - }, +constexpr io_timers_t io_timers[MAX_IO_TIMERS] = { + initIOPWM(PWM::FlexPWM2), + initIOPWM(PWM::FlexPWM3), + initIOPWM(PWM::FlexPWM4), }; -__EXPORT const io_timers_channel_mapping_t io_timers_channel_mapping = { - .element = { - { - .first_channel_index = 0, - .channel_count = 4, - }, - { - .first_channel_index = 4, - .channel_count = 2, - }, - { - .first_channel_index = 6, - .channel_count = 2, - } - } +constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = { + initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule0}, IOMUX::Pad::GPIO_B0_06), + initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule1}, IOMUX::Pad::GPIO_EMC_08), + initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_10), + initIOTimerChannel(io_timers, {PWM::PWM2_PWM_A, PWM::Submodule3}, IOMUX::Pad::GPIO_AD_B0_09), + initIOTimerChannel(io_timers, {PWM::PWM3_PWM_A, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_33), + initIOTimerChannel(io_timers, {PWM::PWM3_PWM_B, PWM::Submodule0}, IOMUX::Pad::GPIO_EMC_30), + initIOTimerChannel(io_timers, {PWM::PWM4_PWM_A, PWM::Submodule2}, IOMUX::Pad::GPIO_EMC_04), + initIOTimerChannel(io_timers, {PWM::PWM4_PWM_B, PWM::Submodule0}, IOMUX::Pad::GPIO_EMC_01), }; -__EXPORT const timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = { - { - /* FMU_CH1 : GPIO_B0_06 GPIO2 Pin 6 FLEXPWM2_PWMA0 */ - .gpio_out = PIN_FLEXPWM2_PWMA00, - .gpio_portpin = GPIO_PORT2 | GPIO_PIN6, - .timer_index = 0, - .val_offset = PWMA_VAL, - .sub_module = SM0, - .sub_module_bits = MCTRL_LDOK(1 << SM0), - - }, - { - /* FMU_CH2 : GPIO_EMC_08 GPIO4 Pin 8 FLEXPWM2_PWMA1 */ - .gpio_out = PIN_FLEXPWM2_PWMA01, - .gpio_portpin = GPIO_PORT4 | GPIO_PIN8, - .timer_index = 0, - .val_offset = PWMA_VAL, - .sub_module = SM1, - .sub_module_bits = MCTRL_LDOK(1 << SM1), - - }, - { - /* FMU_CH3 : GPIO_EMC_10 GPIO4 Pin 10 FLEXPWM2_PWMA2 */ - .gpio_out = PIN_FLEXPWM2_PWMA02, - .gpio_portpin = GPIO_PORT4 | GPIO_PIN10, - .timer_index = 0, - .val_offset = PWMA_VAL, - .sub_module = SM2, - .sub_module_bits = MCTRL_LDOK(1 << SM2), - - }, - { - /* FMU_CH4 : GPIO_AD_B0_09 GPIO1 Pin 9 FLEXPWM2_PWMA3 */ - .gpio_out = PIN_FLEXPWM2_PWMA03, - .gpio_portpin = GPIO_PORT1 | GPIO_PIN9, - .timer_index = 0, - .val_offset = PWMA_VAL, - .sub_module = SM3, - .sub_module_bits = MCTRL_LDOK(1 << SM3), - }, - - { - /* FMU_CH5 : GPIO_EMC_33 GPIO3 Pin 19 FLEXPWM3_PWMA2 */ - .gpio_out = PIN_FLEXPWM3_PWMA02, - .gpio_portpin = GPIO_PORT3 | GPIO_PIN19, - .timer_index = 1, - .val_offset = PWMA_VAL, - .sub_module = SM2, - .sub_module_bits = MCTRL_LDOK(1 << SM2), - }, - { - /* FMU_CH6 : GPIO_EMC_30 GPIO4 Pin 30 FLEXPWM3_PWMB0 */ - .gpio_out = PIN_FLEXPWM3_PWMB00, - .gpio_portpin = GPIO_PORT4 | GPIO_PIN30, - .timer_index = 1, - .val_offset = PWMB_VAL, - .sub_module = SM0, - .sub_module_bits = MCTRL_LDOK(1 << SM0), - - }, - - { - /* FMU_CH7 : GPIO_EMC_04 GPIO4 Pin 4 FLEXPWM4_PWMA2 */ - .gpio_out = PIN_FLEXPWM4_PWMA02, - .gpio_portpin = GPIO_PORT4 | GPIO_PIN4, - .timer_index = 2, - .val_offset = PWMA_VAL, - .sub_module = SM2, - .sub_module_bits = MCTRL_LDOK(1 << SM2), - - }, - { - /* FMU_CH8 : GPIO_EMC_01 GPIO4 Pin 1 FLEXPWM4_PWMB0 */ - .gpio_out = PIN_FLEXPWM4_PWMB00, - .gpio_portpin = GPIO_PORT4 | GPIO_PIN1, - .timer_index = 2, - .val_offset = PWMB_VAL, - .sub_module = SM0, - .sub_module_bits = MCTRL_LDOK(1 << SM0), - - }, - -}; +constexpr io_timers_channel_mapping_t io_timers_channel_mapping = + initIOTimerChannelMapping(io_timers, timer_io_channels); -__EXPORT const struct io_timers_t led_pwm_timers[MAX_LED_TIMERS] = { +constexpr io_timers_t led_pwm_timers[MAX_LED_TIMERS] = { }; -__EXPORT const struct timer_io_channels_t led_pwm_channels[MAX_TIMER_LED_CHANNELS] = { +constexpr timer_io_channels_t led_pwm_channels[MAX_TIMER_LED_CHANNELS] = { }; -__EXPORT void fmurt1062_timer_initialize(void) +void fmurt1062_timer_initialize(void) { /* We must configure Qtimer 3 as the IPG divide by to yield 16 Mhz * and deliver that clock to the eFlexPWM234 via XBAR