pwm driver hal'd
This commit is contained in:
@@ -8,12 +8,12 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#if 0
|
||||
#include "../../../driver/include/stm32f4_pwm.h"
|
||||
#include "pwm.h"
|
||||
#endif
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
#include "pwm.h"
|
||||
#include "stm32f4_pwm.h"
|
||||
|
||||
#include "uart.h"
|
||||
#include "stm32f4_uart.h"
|
||||
#include "ringbuffer.h"
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "stm32f4_gpio.h"
|
||||
#include "driver.h"
|
||||
|
||||
#if 0
|
||||
// GPIO_D12
|
||||
static const GPIO_InitTypeDef port_cfg_d12 = {
|
||||
.Pin = GPIO_PIN_12,
|
||||
@@ -48,7 +49,7 @@ static const struct driver gpio_d12 = {
|
||||
DRIVER_TYPE_GPIO,
|
||||
&__gpio_d12,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// SYSTEM TICK
|
||||
static const enum stm32_sys_tick_time_base stm23_sys_tick_time_base =
|
||||
@@ -65,46 +66,47 @@ static const struct loki_timer timer_1 = {
|
||||
.fp = &timer_fp
|
||||
};
|
||||
|
||||
#if 0
|
||||
// PWM CHANNEL 4
|
||||
/* apb1 clock = 84MHz */
|
||||
/* period_reg = src_clk / presc / cnt_clk */
|
||||
/* 4199 = 84MHZ / (0 + 1) / 20kHz - 1 */
|
||||
static const TIM_TimeBaseInitTypeDef timer_4_cfg = {
|
||||
.TIM_RepetitionCounter = 0x0000,
|
||||
.TIM_Prescaler = 0,
|
||||
.TIM_ClockDivision = TIM_CKD_DIV1,
|
||||
.TIM_CounterMode = TIM_CounterMode_Up,
|
||||
.TIM_Period = 4199
|
||||
static TIM_HandleTypeDef tim4_handle = {
|
||||
.Instance = TIM4,
|
||||
.Init.Prescaler = 0,
|
||||
.Init.CounterMode = TIM_COUNTERMODE_UP,
|
||||
.Init.Period = 4199,
|
||||
.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1,
|
||||
.Init.RepetitionCounter = 0,
|
||||
};
|
||||
|
||||
static const TIM_OCInitTypeDef t4_output_compare_cfg = {
|
||||
.TIM_OutputNState = TIM_OutputNState_Disable,
|
||||
.TIM_OCNPolarity = TIM_OCPolarity_High,
|
||||
.TIM_OCIdleState = TIM_OCIdleState_Reset,
|
||||
.TIM_OCNIdleState = TIM_OCNIdleState_Set,
|
||||
.TIM_OCMode = TIM_OCMode_PWM1,
|
||||
.TIM_OCPolarity = TIM_OCPolarity_High,
|
||||
.TIM_OutputState = TIM_OutputState_Enable,
|
||||
.TIM_Pulse = 0,
|
||||
static TIM_OC_InitTypeDef t4_output_compare_cfg = {
|
||||
.OCMode = TIM_OCMODE_PWM1,
|
||||
.Pulse = 0,
|
||||
.OCPolarity = TIM_OCPOLARITY_HIGH,
|
||||
.OCNPolarity = TIM_OCNPOLARITY_HIGH,
|
||||
.OCFastMode = TIM_OCFAST_DISABLE,
|
||||
.OCIdleState = TIM_OCIDLESTATE_SET,
|
||||
.OCNIdleState = TIM_OCNIDLESTATE_SET
|
||||
};
|
||||
|
||||
static const GPIO_InitTypeDef port_cfg_D15 = {
|
||||
.GPIO_Pin = GPIO_Pin_15,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP,
|
||||
.GPIO_Speed = GPIO_Speed_100MHz,
|
||||
.Pin = GPIO_PIN_15,
|
||||
.Mode = GPIO_MODE_AF_PP,
|
||||
.Speed = GPIO_SPEED_FREQ_HIGH,
|
||||
.Pull = GPIO_PULLUP,
|
||||
.Alternate = GPIO_AF2_TIM4,
|
||||
};
|
||||
|
||||
static const struct stm32f4_gpio t4c4_gpio = {
|
||||
.port = GPIOD,
|
||||
.pin = &port_cfg_D15,
|
||||
};
|
||||
|
||||
static struct stm32f4_pwm str32f4_pwm_4 = {
|
||||
.timer = TIM4,
|
||||
.timer_cfg = &timer_4_cfg,
|
||||
.pwm_gpio = &t4c4_gpio,
|
||||
.timer_handle = &tim4_handle,
|
||||
.output_compare_cfg = &t4_output_compare_cfg,
|
||||
.port = GPIOD,
|
||||
.pin_src = GPIO_PinSource15,
|
||||
.port_cfg = &port_cfg_D15,
|
||||
.channel = channel_4,
|
||||
.channel = TIM_CHANNEL_4,
|
||||
};
|
||||
|
||||
static const struct pwm pwm_ch4 = {
|
||||
@@ -120,25 +122,25 @@ const struct driver pwm_4 = {
|
||||
DRIVER_TYPE_PWM,
|
||||
&pwm_ch4,
|
||||
};
|
||||
#endif
|
||||
#if 0
|
||||
|
||||
// PWM Channel 3
|
||||
static const GPIO_InitTypeDef port_cfg_D14 = {
|
||||
.GPIO_Pin = GPIO_Pin_14,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP,
|
||||
.GPIO_Speed = GPIO_Speed_100MHz,
|
||||
.Pin = GPIO_PIN_14,
|
||||
.Mode = GPIO_MODE_AF_PP,
|
||||
.Speed = GPIO_SPEED_FREQ_HIGH,
|
||||
.Pull = GPIO_PULLUP,
|
||||
.Alternate = GPIO_AF2_TIM4,
|
||||
};
|
||||
static const struct stm32f4_gpio stm32f4_pwm_t4c3_gpio = {
|
||||
.port = GPIOD,
|
||||
.pin = &port_cfg_D14,
|
||||
};
|
||||
|
||||
static struct stm32f4_pwm str32f4_pwm_3 = {
|
||||
.timer = TIM4,
|
||||
.timer_cfg = &timer_4_cfg,
|
||||
.pwm_gpio = &stm32f4_pwm_t4c3_gpio,
|
||||
.timer_handle = &tim4_handle,
|
||||
.output_compare_cfg = &t4_output_compare_cfg,
|
||||
.port = GPIOD,
|
||||
.pin_src = GPIO_PinSource14,
|
||||
.port_cfg = &port_cfg_D14,
|
||||
.channel = channel_3,
|
||||
.channel = TIM_CHANNEL_3,
|
||||
};
|
||||
|
||||
static const struct pwm pwm_ch3 = {
|
||||
@@ -154,25 +156,25 @@ const struct driver pwm_3 = {
|
||||
DRIVER_TYPE_PWM,
|
||||
&pwm_ch3,
|
||||
};
|
||||
#endif
|
||||
#if 0
|
||||
|
||||
// PWM Channel 2
|
||||
static const GPIO_InitTypeDef port_cfg_D13 = {
|
||||
.GPIO_Pin = GPIO_Pin_13,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP,
|
||||
.GPIO_Speed = GPIO_Speed_100MHz,
|
||||
.Pin = GPIO_PIN_13,
|
||||
.Mode = GPIO_MODE_AF_PP,
|
||||
.Speed = GPIO_SPEED_FREQ_HIGH,
|
||||
.Pull = GPIO_PULLUP,
|
||||
.Alternate = GPIO_AF2_TIM4,
|
||||
};
|
||||
static const struct stm32f4_gpio stm32f4_pwm_t4c2_gpio = {
|
||||
.port = GPIOD,
|
||||
.pin = &port_cfg_D13,
|
||||
};
|
||||
|
||||
static struct stm32f4_pwm str32f4_pwm_2 = {
|
||||
.timer = TIM4,
|
||||
.timer_cfg = &timer_4_cfg,
|
||||
.pwm_gpio = &stm32f4_pwm_t4c2_gpio,
|
||||
.timer_handle = &tim4_handle,
|
||||
.output_compare_cfg = &t4_output_compare_cfg,
|
||||
.port = GPIOD,
|
||||
.pin_src = GPIO_PinSource13,
|
||||
.port_cfg = &port_cfg_D13,
|
||||
.channel = channel_2,
|
||||
.channel = TIM_CHANNEL_2,
|
||||
};
|
||||
|
||||
static const struct pwm pwm_ch2 = {
|
||||
@@ -188,25 +190,25 @@ const struct driver pwm_2 = {
|
||||
DRIVER_TYPE_PWM,
|
||||
&pwm_ch2,
|
||||
};
|
||||
#endif
|
||||
#if 0
|
||||
|
||||
// PWM Channel 1
|
||||
static const GPIO_InitTypeDef port_cfg_D12 = {
|
||||
.GPIO_Pin = GPIO_Pin_12,
|
||||
.GPIO_Mode = GPIO_Mode_AF,
|
||||
.GPIO_OType = GPIO_OType_PP,
|
||||
.GPIO_PuPd = GPIO_PuPd_UP,
|
||||
.GPIO_Speed = GPIO_Speed_100MHz,
|
||||
.Pin = GPIO_PIN_12,
|
||||
.Mode = GPIO_MODE_AF_PP,
|
||||
.Speed = GPIO_SPEED_FREQ_HIGH,
|
||||
.Pull = GPIO_PULLUP,
|
||||
.Alternate = GPIO_AF2_TIM4,
|
||||
};
|
||||
static const struct stm32f4_gpio stm32f4_pwm_t4c1_gpio = {
|
||||
.port = GPIOD,
|
||||
.pin = &port_cfg_D12,
|
||||
};
|
||||
|
||||
static struct stm32f4_pwm str32f4_pwm_1 = {
|
||||
.timer = TIM4,
|
||||
.timer_cfg = &timer_4_cfg,
|
||||
.pwm_gpio = &stm32f4_pwm_t4c1_gpio,
|
||||
.timer_handle = &tim4_handle,
|
||||
.output_compare_cfg = &t4_output_compare_cfg,
|
||||
.port = GPIOD,
|
||||
.pin_src = GPIO_PinSource12,
|
||||
.port_cfg = &port_cfg_D12,
|
||||
.channel = channel_1,
|
||||
.channel = TIM_CHANNEL_1,
|
||||
};
|
||||
|
||||
static const struct pwm pwm_ch1 = {
|
||||
@@ -222,7 +224,7 @@ const struct driver pwm_1 = {
|
||||
DRIVER_TYPE_PWM,
|
||||
&pwm_ch1,
|
||||
};
|
||||
#endif
|
||||
|
||||
// UART 1
|
||||
static const GPIO_InitTypeDef port_cfg_uart1 = {
|
||||
.Pin = GPIO_PIN_6 | GPIO_PIN_7,
|
||||
|
Reference in New Issue
Block a user