mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-29 08:34:06 +08:00
holybro/kakutef7: use hw description methods for timer configuration
This commit is contained in:
parent
ebbcc01f12
commit
d2254c2e44
@ -35,7 +35,7 @@ add_library(drivers_board
|
||||
init.c
|
||||
led.c
|
||||
spi.cpp
|
||||
timer_config.c
|
||||
timer_config.cpp
|
||||
usb.c
|
||||
)
|
||||
|
||||
|
||||
@ -139,36 +139,9 @@
|
||||
|
||||
/* PWM
|
||||
*/
|
||||
#define GPIO_TIM5_CH4OUT /* PA3 T5C4 PWM6 */ GPIO_TIM5_CH4OUT_1
|
||||
#define GPIO_TIM8_CH4OUT /* PC9 T8C4 PWM5 */ GPIO_TIM8_CH4OUT_1
|
||||
#define GPIO_TIM1_CH2OUT /* PE11 T1C2 PWM4 */ GPIO_TIM1_CH2OUT_2
|
||||
#define GPIO_TIM1_CH1OUT /* PE9 T1C1 PWM3 */ GPIO_TIM1_CH1OUT_2
|
||||
#define GPIO_TIM3_CH4OUT /* PB1 T3C4 PWM2 */ GPIO_TIM3_CH4OUT_1
|
||||
#define GPIO_TIM3_CH3OUT /* PB0 T3C3 PWM1 */ GPIO_TIM3_CH3OUT_1
|
||||
|
||||
#define DIRECT_PWM_OUTPUT_CHANNELS 6
|
||||
|
||||
#define GPIO_TIM5_CH4IN /* PA3 T5C4 PWM6 */ GPIO_TIM5_CH4IN_1
|
||||
#define GPIO_TIM8_CH4IN /* PC9 T8C4 PWM5 */ GPIO_TIM8_CH4IN_1
|
||||
#define GPIO_TIM1_CH2IN /* PE11 T1C2 PWM4 */ GPIO_TIM1_CH2IN_2
|
||||
#define GPIO_TIM1_CH1IN /* PE9 T1C1 PWM3 */ GPIO_TIM1_CH1IN_2
|
||||
#define GPIO_TIM3_CH4IN /* PB1 T3C4 PWM2 */ GPIO_TIM3_CH4IN_1
|
||||
#define GPIO_TIM3_CH3IN /* PB0 T3C3 PWM1 */ GPIO_TIM3_CH3IN_1
|
||||
|
||||
#define DIRECT_INPUT_TIMER_CHANNELS 6
|
||||
|
||||
/* User GPIOs
|
||||
*/
|
||||
|
||||
#define _MK_GPIO_INPUT(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT|GPIO_PULLDOWN))
|
||||
|
||||
#define GPIO_GPIO5_INPUT /* PWM6 */ _MK_GPIO_INPUT(GPIO_TIM5_CH4IN)
|
||||
#define GPIO_GPIO4_INPUT /* PWM5 */ _MK_GPIO_INPUT(GPIO_TIM8_CH4IN)
|
||||
#define GPIO_GPIO3_INPUT /* PWM4 */ _MK_GPIO_INPUT(GPIO_TIM1_CH2IN)
|
||||
#define GPIO_GPIO2_INPUT /* PWM3 */ _MK_GPIO_INPUT(GPIO_TIM1_CH1IN)
|
||||
#define GPIO_GPIO1_INPUT /* PWM2 */ _MK_GPIO_INPUT(GPIO_TIM3_CH4IN)
|
||||
#define GPIO_GPIO0_INPUT /* PWM1 */ _MK_GPIO_INPUT(GPIO_TIM3_CH3IN)
|
||||
|
||||
/* Tone alarm output */
|
||||
#define GPIO_TONE_ALARM_IDLE /* PD15 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTD|GPIO_PIN15)
|
||||
#define GPIO_TONE_ALARM_GPIO /* PD15 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN15)
|
||||
@ -197,17 +170,6 @@
|
||||
/* This board provides the board_on_reset interface */
|
||||
#define BOARD_HAS_ON_RESET 1
|
||||
|
||||
/* The list of GPIO that will be initialized */
|
||||
|
||||
#define PX4_GPIO_PWM_INIT_LIST { \
|
||||
GPIO_GPIO5_INPUT, \
|
||||
GPIO_GPIO4_INPUT, \
|
||||
GPIO_GPIO3_INPUT, \
|
||||
GPIO_GPIO2_INPUT, \
|
||||
GPIO_GPIO1_INPUT, \
|
||||
GPIO_GPIO0_INPUT, \
|
||||
}
|
||||
|
||||
#define PX4_GPIO_INIT_LIST { \
|
||||
PX4_ADC_GPIO, \
|
||||
GPIO_TONE_ALARM_IDLE, \
|
||||
|
||||
@ -64,6 +64,7 @@
|
||||
#include <arch/board/board.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
#include <px4_arch/io_timer.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <drivers/drv_board_led.h>
|
||||
#include <systemlib/px4_macros.h>
|
||||
@ -118,10 +119,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_as_pwm_input(i)));
|
||||
}
|
||||
|
||||
if (status >= 0) {
|
||||
up_mdelay(6);
|
||||
|
||||
@ -1,171 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2019 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file timer_config.c
|
||||
*
|
||||
* Configuration data for the stm32 pwm_servo, input capture and pwm input driver.
|
||||
*
|
||||
* Note that these arrays must always be fully-sized.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <chip.h>
|
||||
#include <stm32_gpio.h>
|
||||
#include <stm32_tim.h>
|
||||
|
||||
#include <drivers/drv_pwm_output.h>
|
||||
#include <px4_arch/io_timer.h>
|
||||
|
||||
#include "board_config.h"
|
||||
|
||||
__EXPORT const io_timers_t io_timers[MAX_IO_TIMERS] = {
|
||||
{
|
||||
.base = STM32_TIM3_BASE,
|
||||
.clock_register = STM32_RCC_APB1ENR,
|
||||
.clock_bit = RCC_APB1ENR_TIM3EN,
|
||||
.clock_freq = STM32_APB1_TIM3_CLKIN,
|
||||
.vectorno = STM32_IRQ_TIM3,
|
||||
.dshot = {
|
||||
.dma_base = STM32_DMA1_BASE,
|
||||
.dmamap = DMAMAP_TIM3_UP,
|
||||
}
|
||||
},
|
||||
{
|
||||
.base = STM32_TIM1_BASE,
|
||||
.clock_register = STM32_RCC_APB2ENR,
|
||||
.clock_bit = RCC_APB2ENR_TIM1EN,
|
||||
.clock_freq = STM32_APB2_TIM1_CLKIN,
|
||||
.vectorno = STM32_IRQ_TIM1CC,
|
||||
.dshot = {
|
||||
.dma_base = STM32_DMA2_BASE,
|
||||
.dmamap = DMAMAP_TIM1_UP,
|
||||
}
|
||||
},
|
||||
{
|
||||
.base = STM32_TIM8_BASE,
|
||||
.clock_register = STM32_RCC_APB2ENR,
|
||||
.clock_bit = RCC_APB2ENR_TIM8EN,
|
||||
.clock_freq = STM32_APB2_TIM8_CLKIN,
|
||||
.vectorno = STM32_IRQ_TIM8CC,
|
||||
.dshot = {
|
||||
.dma_base = STM32_DMA2_BASE,
|
||||
.dmamap = DMAMAP_TIM8_UP,
|
||||
}
|
||||
},
|
||||
{
|
||||
.base = STM32_TIM5_BASE,
|
||||
.clock_register = STM32_RCC_APB1ENR,
|
||||
.clock_bit = RCC_APB1ENR_TIM5EN,
|
||||
.clock_freq = STM32_APB1_TIM5_CLKIN,
|
||||
.vectorno = STM32_IRQ_TIM5,
|
||||
.dshot = {
|
||||
.dma_base = STM32_DMA1_BASE,
|
||||
.dmamap = DMAMAP_TIM5_UP_2,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
__EXPORT const io_timers_channel_mapping_t io_timers_channel_mapping = {
|
||||
.element = {
|
||||
{
|
||||
.first_channel_index = 0,
|
||||
.channel_count = 2,
|
||||
},
|
||||
{
|
||||
.first_channel_index = 2,
|
||||
.channel_count = 2,
|
||||
},
|
||||
{
|
||||
.first_channel_index = 4,
|
||||
.channel_count = 1,
|
||||
},
|
||||
{
|
||||
.first_channel_index = 5,
|
||||
.channel_count = 1,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
__EXPORT const timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
|
||||
{
|
||||
.gpio_out = GPIO_TIM3_CH3OUT,
|
||||
.gpio_in = GPIO_TIM3_CH3IN,
|
||||
.timer_index = 0,
|
||||
.timer_channel = 3,
|
||||
.ccr_offset = STM32_GTIM_CCR3_OFFSET,
|
||||
.masks = GTIM_SR_CC3IF | GTIM_SR_CC3OF
|
||||
},
|
||||
{
|
||||
.gpio_out = GPIO_TIM3_CH4OUT,
|
||||
.gpio_in = GPIO_TIM3_CH4IN,
|
||||
.timer_index = 0,
|
||||
.timer_channel = 4,
|
||||
.ccr_offset = STM32_GTIM_CCR4_OFFSET,
|
||||
.masks = GTIM_SR_CC4IF | GTIM_SR_CC4OF
|
||||
},
|
||||
{
|
||||
.gpio_out = GPIO_TIM1_CH1OUT,
|
||||
.gpio_in = GPIO_TIM1_CH1IN,
|
||||
.timer_index = 1,
|
||||
.timer_channel = 1,
|
||||
.ccr_offset = STM32_GTIM_CCR1_OFFSET,
|
||||
.masks = GTIM_SR_CC1IF | GTIM_SR_CC1OF
|
||||
},
|
||||
{
|
||||
.gpio_out = GPIO_TIM1_CH2OUT,
|
||||
.gpio_in = GPIO_TIM1_CH2IN,
|
||||
.timer_index = 1,
|
||||
.timer_channel = 2,
|
||||
.ccr_offset = STM32_GTIM_CCR2_OFFSET,
|
||||
.masks = GTIM_SR_CC2IF | GTIM_SR_CC2OF
|
||||
},
|
||||
{
|
||||
.gpio_out = GPIO_TIM8_CH4OUT,
|
||||
.gpio_in = GPIO_TIM8_CH4IN,
|
||||
.timer_index = 2,
|
||||
.timer_channel = 4,
|
||||
.ccr_offset = STM32_GTIM_CCR4_OFFSET,
|
||||
.masks = GTIM_SR_CC4IF | GTIM_SR_CC4OF
|
||||
},
|
||||
{
|
||||
.gpio_out = GPIO_TIM5_CH4OUT,
|
||||
.gpio_in = GPIO_TIM5_CH4IN,
|
||||
.timer_index = 3,
|
||||
.timer_channel = 4,
|
||||
.ccr_offset = STM32_GTIM_CCR4_OFFSET,
|
||||
.masks = GTIM_SR_CC4IF | GTIM_SR_CC4OF
|
||||
},
|
||||
};
|
||||
|
||||
54
boards/holybro/kakutef7/src/timer_config.cpp
Normal file
54
boards/holybro/kakutef7/src/timer_config.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2019 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <px4_arch/io_timer_hw_description.h>
|
||||
|
||||
constexpr io_timers_t io_timers[MAX_IO_TIMERS] = {
|
||||
initIOTimer(Timer::Timer3, DMA{DMA::Index1, DMA::Stream2, DMA::Channel5}),
|
||||
initIOTimer(Timer::Timer1, DMA{DMA::Index2, DMA::Stream5, DMA::Channel6}),
|
||||
initIOTimer(Timer::Timer8, DMA{DMA::Index2, DMA::Stream1, DMA::Channel7}),
|
||||
initIOTimer(Timer::Timer5, DMA{DMA::Index1, DMA::Stream6, DMA::Channel6}),
|
||||
};
|
||||
|
||||
constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
|
||||
initIOTimerChannel(io_timers, {Timer::Timer5, Timer::Channel4}, {GPIO::PortA, GPIO::Pin3}),
|
||||
initIOTimerChannel(io_timers, {Timer::Timer8, Timer::Channel4}, {GPIO::PortC, GPIO::Pin9}),
|
||||
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel2}, {GPIO::PortE, GPIO::Pin11}),
|
||||
initIOTimerChannel(io_timers, {Timer::Timer1, Timer::Channel1}, {GPIO::PortE, GPIO::Pin9}),
|
||||
initIOTimerChannel(io_timers, {Timer::Timer3, Timer::Channel4}, {GPIO::PortB, GPIO::Pin1}),
|
||||
initIOTimerChannel(io_timers, {Timer::Timer3, Timer::Channel3}, {GPIO::PortB, GPIO::Pin0}),
|
||||
};
|
||||
|
||||
constexpr io_timers_channel_mapping_t io_timers_channel_mapping =
|
||||
initIOTimerChannelMapping(io_timers, timer_io_channels);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user