mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-21 01:07:18 +08:00
修复了pwm互补输出的一些bug,并在finsh中添加使用说明 (#6191)
* Fix the bug of complementary output
This commit is contained in:
parent
c6c8201bd4
commit
32ed7dcfd2
@ -17,6 +17,17 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_PWM1
|
||||
#ifndef PWM1_CONFIG
|
||||
#define PWM1_CONFIG \
|
||||
{ \
|
||||
.tim_handle.Instance = TIM1, \
|
||||
.name = "pwm1", \
|
||||
.channel = 0 \
|
||||
}
|
||||
#endif /* PWM1_CONFIG */
|
||||
#endif /* BSP_USING_PWM1 */
|
||||
|
||||
#ifdef BSP_USING_PWM2
|
||||
#ifndef PWM2_CONFIG
|
||||
#define PWM2_CONFIG \
|
||||
|
File diff suppressed because one or more lines are too long
@ -12,35 +12,38 @@ Mcu.Family=STM32F4
|
||||
Mcu.IP0=ADC1
|
||||
Mcu.IP1=NVIC
|
||||
Mcu.IP2=RCC
|
||||
Mcu.IP3=SPI1
|
||||
Mcu.IP4=SYS
|
||||
Mcu.IP3=SYS
|
||||
Mcu.IP4=TIM1
|
||||
Mcu.IP5=TIM2
|
||||
Mcu.IP6=TIM3
|
||||
Mcu.IP7=TIM11
|
||||
Mcu.IP8=USART2
|
||||
Mcu.IPNb=9
|
||||
Mcu.IP7=TIM4
|
||||
Mcu.IP8=TIM11
|
||||
Mcu.IP9=USART2
|
||||
Mcu.IPNb=10
|
||||
Mcu.Name=STM32F401R(D-E)Tx
|
||||
Mcu.Package=LQFP64
|
||||
Mcu.Pin0=PC14-OSC32_IN
|
||||
Mcu.Pin1=PC15-OSC32_OUT
|
||||
Mcu.Pin10=PA4
|
||||
Mcu.Pin11=PA5
|
||||
Mcu.Pin12=PA6
|
||||
Mcu.Pin13=PA7
|
||||
Mcu.Pin14=PB0
|
||||
Mcu.Pin15=PB10
|
||||
Mcu.Pin16=PC7
|
||||
Mcu.Pin17=PA13
|
||||
Mcu.Pin18=PA14
|
||||
Mcu.Pin19=PB3
|
||||
Mcu.Pin11=PA7
|
||||
Mcu.Pin12=PB0
|
||||
Mcu.Pin13=PB10
|
||||
Mcu.Pin14=PC7
|
||||
Mcu.Pin15=PA8
|
||||
Mcu.Pin16=PA13
|
||||
Mcu.Pin17=PA14
|
||||
Mcu.Pin18=PB3
|
||||
Mcu.Pin19=PB4
|
||||
Mcu.Pin2=PH0 - OSC_IN
|
||||
Mcu.Pin20=PB4
|
||||
Mcu.Pin20=PB6
|
||||
Mcu.Pin21=VP_ADC1_TempSens_Input
|
||||
Mcu.Pin22=VP_ADC1_Vref_Input
|
||||
Mcu.Pin23=VP_SYS_VS_Systick
|
||||
Mcu.Pin24=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin25=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin26=VP_TIM11_VS_ClockSourceINT
|
||||
Mcu.Pin24=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin25=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin26=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin27=VP_TIM4_VS_ClockSourceINT
|
||||
Mcu.Pin28=VP_TIM11_VS_ClockSourceINT
|
||||
Mcu.Pin3=PH1 - OSC_OUT
|
||||
Mcu.Pin4=PC0
|
||||
Mcu.Pin5=PC1
|
||||
@ -48,7 +51,7 @@ Mcu.Pin6=PA0-WKUP
|
||||
Mcu.Pin7=PA1
|
||||
Mcu.Pin8=PA2
|
||||
Mcu.Pin9=PA3
|
||||
Mcu.PinsNb=27
|
||||
Mcu.PinsNb=29
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F401RETx
|
||||
@ -85,13 +88,9 @@ PA3.Mode=Asynchronous
|
||||
PA3.Signal=USART2_RX
|
||||
PA4.Locked=true
|
||||
PA4.Signal=ADCx_IN4
|
||||
PA5.Locked=true
|
||||
PA5.Mode=Full_Duplex_Master
|
||||
PA5.Signal=SPI1_SCK
|
||||
PA6.Mode=Full_Duplex_Master
|
||||
PA6.Signal=SPI1_MISO
|
||||
PA7.Mode=Full_Duplex_Master
|
||||
PA7.Signal=SPI1_MOSI
|
||||
PA7.Mode=Output Compare1 CH1 CH1N
|
||||
PA7.Signal=TIM1_CH1N
|
||||
PA8.Signal=S_TIM1_CH1
|
||||
PB0.Locked=true
|
||||
PB0.Signal=ADCx_IN8
|
||||
PB10.Locked=true
|
||||
@ -100,6 +99,7 @@ PB3.Locked=true
|
||||
PB3.Signal=S_TIM2_CH2
|
||||
PB4.Locked=true
|
||||
PB4.Signal=S_TIM3_CH1
|
||||
PB6.Signal=S_TIM4_CH1
|
||||
PC0.Locked=true
|
||||
PC0.Signal=ADCx_IN10
|
||||
PC1.Locked=true
|
||||
@ -183,6 +183,8 @@ SH.ADCx_IN4.0=ADC1_IN4,IN4
|
||||
SH.ADCx_IN4.ConfNb=1
|
||||
SH.ADCx_IN8.0=ADC1_IN8,IN8
|
||||
SH.ADCx_IN8.ConfNb=1
|
||||
SH.S_TIM1_CH1.0=TIM1_CH1,Output Compare1 CH1 CH1N
|
||||
SH.S_TIM1_CH1.ConfNb=1
|
||||
SH.S_TIM2_CH2.0=TIM2_CH2,PWM Generation2 CH2
|
||||
SH.S_TIM2_CH2.ConfNb=1
|
||||
SH.S_TIM2_CH3.0=TIM2_CH3,PWM Generation3 CH3
|
||||
@ -191,16 +193,18 @@ SH.S_TIM3_CH1.0=TIM3_CH1,PWM Generation1 CH1
|
||||
SH.S_TIM3_CH1.ConfNb=1
|
||||
SH.S_TIM3_CH2.0=TIM3_CH2,PWM Generation2 CH2
|
||||
SH.S_TIM3_CH2.ConfNb=1
|
||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction
|
||||
SPI1.Mode=SPI_MODE_MASTER
|
||||
SPI1.VirtualType=VM_MASTER
|
||||
SH.S_TIM4_CH1.0=TIM4_CH1,PWM Generation1 CH1
|
||||
SH.S_TIM4_CH1.ConfNb=1
|
||||
TIM1.Channel-Output\ Compare1\ CH1\ CH1N=TIM_CHANNEL_1
|
||||
TIM1.IPParameters=Channel-Output Compare1 CH1 CH1N
|
||||
TIM2.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||
TIM2.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
|
||||
TIM2.IPParameters=Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3
|
||||
TIM3.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||
TIM3.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||
TIM3.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2
|
||||
TIM4.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||
TIM4.IPParameters=Channel-PWM Generation1 CH1
|
||||
USART2.IPParameters=VirtualMode
|
||||
USART2.VirtualMode=VM_ASYNC
|
||||
VP_ADC1_TempSens_Input.Mode=IN-TempSens
|
||||
@ -211,8 +215,12 @@ VP_SYS_VS_Systick.Mode=SysTick
|
||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||
VP_TIM11_VS_ClockSourceINT.Mode=Enable_Timer
|
||||
VP_TIM11_VS_ClockSourceINT.Signal=TIM11_VS_ClockSourceINT
|
||||
VP_TIM1_VS_ClockSourceINT.Mode=Internal
|
||||
VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT
|
||||
VP_TIM2_VS_ClockSourceINT.Mode=Internal
|
||||
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
|
||||
VP_TIM3_VS_ClockSourceINT.Mode=Internal
|
||||
VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT
|
||||
VP_TIM4_VS_ClockSourceINT.Mode=Internal
|
||||
VP_TIM4_VS_ClockSourceINT.Signal=TIM4_VS_ClockSourceINT
|
||||
board=custom
|
||||
|
@ -62,7 +62,7 @@
|
||||
/* #define HAL_SAI_MODULE_ENABLED */
|
||||
/* #define HAL_SD_MODULE_ENABLED */
|
||||
/* #define HAL_MMC_MODULE_ENABLED */
|
||||
#define HAL_SPI_MODULE_ENABLED
|
||||
/* #define HAL_SPI_MODULE_ENABLED */
|
||||
#define HAL_TIM_MODULE_ENABLED
|
||||
#define HAL_UART_MODULE_ENABLED
|
||||
/* #define HAL_USART_MODULE_ENABLED */
|
||||
|
@ -80,7 +80,7 @@
|
||||
/* USER CODE END 0 */
|
||||
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
||||
/**
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
@ -186,73 +186,6 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hspi: SPI handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(hspi->Instance==SPI1)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_MspInit 0 */
|
||||
|
||||
/* USER CODE END SPI1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**SPI1 GPIO Configuration
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspInit 1 */
|
||||
|
||||
/* USER CODE END SPI1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hspi: SPI handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
||||
{
|
||||
if(hspi->Instance==SPI1)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END SPI1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_SPI1_CLK_DISABLE();
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END SPI1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM_Base MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
@ -261,7 +194,18 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
||||
*/
|
||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
||||
{
|
||||
if(htim_base->Instance==TIM2)
|
||||
if(htim_base->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN TIM1_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspInit 1 */
|
||||
}
|
||||
else if(htim_base->Instance==TIM2)
|
||||
{
|
||||
/* USER CODE BEGIN TIM2_MspInit 0 */
|
||||
|
||||
@ -283,6 +227,17 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
||||
|
||||
/* USER CODE END TIM3_MspInit 1 */
|
||||
}
|
||||
else if(htim_base->Instance==TIM4)
|
||||
{
|
||||
/* USER CODE BEGIN TIM4_MspInit 0 */
|
||||
|
||||
/* USER CODE END TIM4_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM4_CLK_ENABLE();
|
||||
/* USER CODE BEGIN TIM4_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM4_MspInit 1 */
|
||||
}
|
||||
else if(htim_base->Instance==TIM11)
|
||||
{
|
||||
/* USER CODE BEGIN TIM11_MspInit 0 */
|
||||
@ -300,11 +255,33 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(htim->Instance==TIM2)
|
||||
if(htim->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspPostInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspPostInit 0 */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**TIM1 GPIO Configuration
|
||||
PA7 ------> TIM1_CH1N
|
||||
PA8 ------> TIM1_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN TIM1_MspPostInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspPostInit 1 */
|
||||
}
|
||||
else if(htim->Instance==TIM2)
|
||||
{
|
||||
/* USER CODE BEGIN TIM2_MspPostInit 0 */
|
||||
|
||||
/* USER CODE END TIM2_MspPostInit 0 */
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**TIM2 GPIO Configuration
|
||||
PB10 ------> TIM2_CH3
|
||||
@ -351,6 +328,27 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
|
||||
|
||||
/* USER CODE END TIM3_MspPostInit 1 */
|
||||
}
|
||||
else if(htim->Instance==TIM4)
|
||||
{
|
||||
/* USER CODE BEGIN TIM4_MspPostInit 0 */
|
||||
|
||||
/* USER CODE END TIM4_MspPostInit 0 */
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**TIM4 GPIO Configuration
|
||||
PB6 ------> TIM4_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN TIM4_MspPostInit 1 */
|
||||
|
||||
/* USER CODE END TIM4_MspPostInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
@ -361,7 +359,18 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
|
||||
*/
|
||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
||||
{
|
||||
if(htim_base->Instance==TIM2)
|
||||
if(htim_base->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM1_CLK_DISABLE();
|
||||
/* USER CODE BEGIN TIM1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspDeInit 1 */
|
||||
}
|
||||
else if(htim_base->Instance==TIM2)
|
||||
{
|
||||
/* USER CODE BEGIN TIM2_MspDeInit 0 */
|
||||
|
||||
@ -383,6 +392,17 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
||||
|
||||
/* USER CODE END TIM3_MspDeInit 1 */
|
||||
}
|
||||
else if(htim_base->Instance==TIM4)
|
||||
{
|
||||
/* USER CODE BEGIN TIM4_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END TIM4_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM4_CLK_DISABLE();
|
||||
/* USER CODE BEGIN TIM4_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM4_MspDeInit 1 */
|
||||
}
|
||||
else if(htim_base->Instance==TIM11)
|
||||
{
|
||||
/* USER CODE BEGIN TIM11_MspDeInit 0 */
|
||||
|
@ -22,12 +22,16 @@ menu "Onboard Peripheral Drivers"
|
||||
select BSP_USING_ADC
|
||||
select BSP_USING_ADC1
|
||||
select BSP_USING_PWM
|
||||
select BSP_USING_PWM1
|
||||
select BSP_USING_PWM1_CH1
|
||||
select BSP_USING_PWM2
|
||||
select BSP_USING_PWM2_CH2
|
||||
select BSP_USING_PWM2_CH3
|
||||
select BSP_USING_PWM3
|
||||
select BSP_USING_PWM3_CH1
|
||||
select BSP_USING_PWM3_CH2
|
||||
select BSP_USING_PWM4
|
||||
select BSP_USING_PWM4_CH1
|
||||
select BSP_USING_I2C
|
||||
select BSP_USING_I2C1
|
||||
imply RTDUINO_USING_SERVO
|
||||
@ -86,6 +90,15 @@ menu "On-chip Peripheral Drivers"
|
||||
select RT_USING_PWM
|
||||
|
||||
if BSP_USING_PWM
|
||||
menuconfig BSP_USING_PWM1
|
||||
bool "Enable timer1 output PWM"
|
||||
default n
|
||||
if BSP_USING_PWM1
|
||||
config BSP_USING_PWM1_CH1
|
||||
bool "Enable PWM1 channel1"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_PWM2
|
||||
bool "Enable timer2 output PWM"
|
||||
default n
|
||||
@ -111,6 +124,15 @@ menu "On-chip Peripheral Drivers"
|
||||
bool "Enable PWM3 channel2"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_PWM4
|
||||
bool "Enable timer4 output PWM"
|
||||
default n
|
||||
if BSP_USING_PWM4
|
||||
config BSP_USING_PWM4_CH1
|
||||
bool "Enable PWM4 channel1"
|
||||
default n
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
|
@ -7,6 +7,7 @@
|
||||
* Date Author Notes
|
||||
* 2018-05-07 aozima the first version
|
||||
* 2022-05-14 Stanley Lwin add pwm function
|
||||
* 2022-07-25 liYony fix complementary outputs and add usage information in finsh
|
||||
*/
|
||||
|
||||
#include <rtdevice.h>
|
||||
@ -37,7 +38,7 @@ static rt_size_t _pwm_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_
|
||||
rt_uint32_t *pulse = (rt_uint32_t *)buffer;
|
||||
struct rt_pwm_configuration configuration = {0};
|
||||
|
||||
configuration.channel = pos;
|
||||
configuration.channel = (pos > 0) ? (pos) : (-pos);
|
||||
|
||||
if (pwm->ops->control)
|
||||
{
|
||||
@ -65,7 +66,7 @@ static rt_size_t _pwm_write(rt_device_t dev, rt_off_t pos, const void *buffer, r
|
||||
rt_uint32_t *pulse = (rt_uint32_t *)buffer;
|
||||
struct rt_pwm_configuration configuration = {0};
|
||||
|
||||
configuration.channel = pos;
|
||||
configuration.channel = (pos > 0) ? (pos) : (-pos);
|
||||
|
||||
if (pwm->ops->control)
|
||||
{
|
||||
@ -169,7 +170,7 @@ rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t perio
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
configuration.channel = channel;
|
||||
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
||||
configuration.period = period;
|
||||
configuration.pulse = pulse;
|
||||
result = rt_device_control(&device->parent, PWM_CMD_SET, &configuration);
|
||||
@ -187,7 +188,7 @@ rt_err_t rt_pwm_set_period(struct rt_device_pwm *device, int channel, rt_uint32_
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
configuration.channel = channel;
|
||||
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
||||
configuration.period = period;
|
||||
result = rt_device_control(&device->parent, PWM_CMD_SET_PERIOD, &configuration);
|
||||
|
||||
@ -204,7 +205,7 @@ rt_err_t rt_pwm_set_pulse(struct rt_device_pwm *device, int channel, rt_uint32_t
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
configuration.channel = channel;
|
||||
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
||||
configuration.pulse = pulse;
|
||||
result = rt_device_control(&device->parent, PWM_CMD_SET_PULSE, &configuration);
|
||||
|
||||
@ -249,7 +250,7 @@ static int pwm(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("pwm probe <device name> - probe pwm by name\n");
|
||||
rt_kprintf("pwm probe <device name> - probe pwm by name\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -269,9 +270,11 @@ static int pwm(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("pwm enable <channel> - enable pwm channel\n");
|
||||
rt_kprintf("pwm enable <channel> - enable pwm channel\n");
|
||||
rt_kprintf(" e.g. MSH >pwm enable 1 - PWM_CH1 nomal\n");
|
||||
rt_kprintf(" e.g. MSH >pwm enable -1 - PWM_CH1N complememtary\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(!strcmp(argv[1], "disable"))
|
||||
{
|
||||
if(argc == 3)
|
||||
@ -280,7 +283,7 @@ static int pwm(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("pwm disable <channel> - disable pwm channel\n");
|
||||
rt_kprintf("pwm disable <channel> - disable pwm channel\n");
|
||||
}
|
||||
}
|
||||
else if(!strcmp(argv[1], "get"))
|
||||
@ -315,18 +318,18 @@ static int pwm(int argc, char **argv)
|
||||
|
||||
else
|
||||
{
|
||||
rt_kprintf("pwm get <channel> - get pwm channel info\n");
|
||||
rt_kprintf("pwm get <channel> - get pwm channel info\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("Usage: \n");
|
||||
rt_kprintf("pwm probe <device name> - probe pwm by name\n");
|
||||
rt_kprintf("pwm enable <channel> - enable pwm channel\n");
|
||||
rt_kprintf("pwm disable <channel>- disable pwm channel\n");
|
||||
rt_kprintf("pwm get <channel> - get pwm channel info\n");
|
||||
rt_kprintf("pwm set <channel> <period> <pulse> - set pwm channel info\n");
|
||||
rt_kprintf("pwm probe <device name> - probe pwm by name\n");
|
||||
rt_kprintf("pwm enable <channel> - enable pwm channel\n");
|
||||
rt_kprintf("pwm disable <channel> - disable pwm channel\n");
|
||||
rt_kprintf("pwm get <channel> - get pwm channel info\n");
|
||||
rt_kprintf("pwm set <channel> <period> <pulse> - set pwm channel info\n");
|
||||
|
||||
result = - RT_ERROR;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user