Skip to content

Commit

Permalink
drv_pwm 进行修改
Browse files Browse the repository at this point in the history
  • Loading branch information
LZerro authored and Rbb666 committed Sep 5, 2024
1 parent 3374254 commit 8c478ec
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 26 deletions.
52 changes: 27 additions & 25 deletions libraries/HAL_Drivers/drv_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,51 @@ struct ifx_pwm

static struct ifx_pwm ifx_pwm_obj[] =
{
#ifdef BSP_USING_PWM0_PORT0
#ifdef BSP_USING_PWM0_CH0_PORT0
PWM0_CH0_PORT0_CONFIG,
#endif

#ifdef BSP_USING_PWM0_PORT2
#ifdef BSP_USING_PWM0_CH2_PORT11_COMPL
PWM0_CH2_PORT11_COMPL_CONFIG,
#endif

#ifdef BSP_USING_PWM0_CH3_PORT11
PWM0_CH3_PORT11_CONFIG,
#endif

#ifdef BSP_USING_PWM0_CH4_PORT5_COMPL
PWM0_CH4_PORT5_COMPL_CONFIG,
#endif

#ifdef BSP_USING_PWM0_CH7_PORT2
PWM0_CH7_PORT2_CONFIG,
#endif

#ifdef BSP_USING_PWM0_PORT5
#ifdef BSP_USING_PWM0_CH7_PORT5
PWM0_CH7_PORT5_CONFIG,
#endif

#ifdef BSP_USING_PWM0_PORT7
#ifdef BSP_USING_PWM0_CH7_PORT5_COMPL
PWM0_CH7_PORT5_COMPL_CONFIG,
#endif

#ifdef BSP_USING_PWM0_CH7_PORT7
PWM0_CH7_PORT7_CONFIG,
#endif

#ifdef BSP_USING_PWM0_PORT9
#ifdef BSP_USING_PWM0_CH7_PORT9
PWM0_CH7_PORT9_CONFIG,
#endif

#ifdef BSP_USING_PWM0_PORT10
#ifdef BSP_USING_PWM0_CH7_PORT10
PWM0_CH7_PORT10_CONFIG,
#endif

#ifdef BSP_USING_PWM0_PORT12
#ifdef BSP_USING_PWM0_CH7_PORT12
PWM0_CH7_PORT12_CONFIG,
#endif

#ifdef BSP_USING_PWM0_PORT13
#ifdef BSP_USING_PWM0_CH7_PORT13
PWM0_CH3_PORT13_CONFIG,
#endif
};
Expand All @@ -73,26 +89,12 @@ static rt_err_t drv_pwm_enable(cyhal_pwm_t *htim, struct rt_pwm_configuration *c
{
if (!enable)
{
if (channel == 3)
{
htim->tcpwm.resource.channel_num = channel;
}
else if (channel == 7)
{
htim->tcpwm.resource.channel_num = channel;
}
htim->tcpwm.resource.channel_num = channel;
cyhal_pwm_stop(htim);
}
else
{
if (channel == 3)
{
htim->tcpwm.resource.channel_num = channel;
}
else if (channel == 7)
{
htim->tcpwm.resource.channel_num = channel;
}
htim->tcpwm.resource.channel_num = channel;
cyhal_pwm_start(htim);
}
}
Expand Down Expand Up @@ -217,7 +219,7 @@ static int rt_hw_pwm_init(void)
INIT_BOARD_EXPORT(rt_hw_pwm_init);

#define PWM_DEV_NAME "pwm0"
#define PWM_DEV_CHANNEL 7
#define PWM_DEV_CHANNEL 4

struct rt_device_pwm *pwm_dev;

Expand Down
38 changes: 37 additions & 1 deletion libraries/HAL_Drivers/drv_pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,34 @@ extern "C"
.channel = 0, \
.gpio = GET_PIN(0, 0), \
}
#endif /* PWM0_CH7_PORT2_CONFIG */
#endif /* PWM0_CH0_PORT2_CONFIG */

#ifndef PWM0_CH2_PORT11_COMPL_CONFIG
#define PWM0_CH2_PORT11_COMPL_CONFIG \
{ \
.name = "pwm0", \
.channel = 2, \
.gpio = GET_PIN(11, 3), \
}
#endif /*PWM0_CH2_PORT11_COMPL_CONFIG*/

#ifndef PWM0_CH3_PORT11_CONFIG
#define PWM0_CH3_PORT11_CONFIG \
{ \
.name = "pwm0", \
.channel = 3, \
.gpio = GET_PIN(11, 4), \
}
#endif /*PWM0_CH3_PORT11_CONFIG*/

#ifndef PWM0_CH4_PORT5_COMPL_CONFIG
#define PWM0_CH4_PORT5_COMPL_CONFIG \
{ \
.name = "pwm0", \
.channel = 4, \
.gpio = GET_PIN(5, 1), \
}
#endif /*PWM0_CH4_PORT5_COMPL_CONFIG*/

#ifndef PWM0_CH7_PORT2_CONFIG
#define PWM0_CH7_PORT2_CONFIG \
Expand All @@ -49,6 +76,15 @@ extern "C"
}
#endif /* PWM0_CH7_PORT5_CONFIG */

#ifndef PWM0_CH7_PORT5_COMPL_CONFIG
#define PWM0_CH7_PORT5_COMPL_CONFIG \
{ \
.name = "pwm0", \
.channel = 7, \
.gpio = GET_PIN(5, 7), \
}
#endif /*PWM0_CH7_PORT5_COMPL_CONFIG*/

#ifndef PWM0_CH7_PORT7_CONFIG
#define PWM0_CH7_PORT7_CONFIG \
{ \
Expand Down

0 comments on commit 8c478ec

Please sign in to comment.