WXK
2024-12-16 78e84fcf264afd731cd66c807d9fcb690fe12126
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**************************************************************************//**
* @file     pan_hal_pwm.h
* @version  V0.0.0
* $Revision: 1 $
* $Date:    23/09/10 $
* @brief    Panchip series PWM (Pulse Width Modulation) HAL header file.
* @note     Copyright (C) 2023 Panchip Technology Corp. All rights reserved.
*****************************************************************************/
 
#ifndef __PAN_HAL_PWM_H
#define __PAN_HAL_PWM_H
#include "pan_hal_def.h"
 
/**
 * @brief PWM HAL Interface
 * @defgroup pwm_hal_interface Pwm HAL Interface
 * @{
 */
 
/**
 * @brief Enumeration of PWM channel identifiers.
 *
 * These values represent different PWM channels available.
 */
typedef enum
{
    PWM0_CH0,
    PWM0_CH1,
    PWM0_CH2,
    PWM0_CH3,
    PWM0_CH4,
    PWM0_CH5,
    PWM0_CH6,
    PWM0_CH7,
} PWM_ChId;
 
/**
 * @brief Enumeration of PWM operating modes.
 *
 * These values define different PWM operating modes.
 */
typedef enum
{
    PWM_MODE_INDEPENDENT   = 0x00,  /*!< Independent mode */
    PWM_MODE_COMPLEMENTARY = 0x01,  /*!< Complementary mode */
    PWM_MODE_SYNCHRONIZED  = 0x10,  /*!< Synchronized mode */
    PWM_MODE_GROUP = 0X100          /*!< Group mode */
} PWM_ModeOpt;
 
/**
 * @brief Structure defining PWM initialization parameters.
 *
 * This structure holds the parameters required to initialize a PWM channel.
 */
typedef struct
{
    uint32_t frequency;                /*!< PWM frequency in Hz */
    uint32_t dutyCycle;                /*!< Initial duty cycle value */
    PWM_OperateTypeDef operateType; /*!< PWM operating type */
    PWM_ModeOpt mode;                 /*!< PWM operating mode */
    bool inverter;                     /*!< Inverter control */
    bool lowPowerEn;                   /*!< PWM clk source select */
} PWM_InitOpt;
 
 
 
/**
 * @brief it is a macro maping gpio to pwm
 * @param port  @example P0
 * @param bit   @example 3
 * @param chId  {PWM_CH0, PWM_CH1, PWM_CH2, PWM_CH3, PWM_CH4, PWM_CH5, PWM_CH6, PWM_CH7}
 * @example HAL_PWM_PinConfiguration(P0, 3, PWM_CH2), means configurating P03 as PWM0 Channel 2
 */
#define HAL_PWM_PinConfiguration(port, bit, chId)   \
            (SYS->port##_MFP = (SYS->port##_MFP & ~SYS_MFP_##port##bit##_Msk) | SYS_MFP_##port##bit##_##chId)
 
/**
 * @brief Initialize a PWM channel with the specified configuration.
 *
 * @param ChID     PWM channel ID to initialize.
 * @param InitObj  Configuration parameters for PWM initialization.
 *
 * This function initializes a PWM channel with the provided configuration.
 */
int HAL_PWM_Init(PWM_ChId chId, PWM_InitOpt *pInitObj);
 
/**
 * @brief DeInitialize a PWM channel.
 *
 * @param ChID   PWM channel ID to deinitialize.
 */
void HAL_PWM_DeInit(uint32_t handle);
 
/**
 * @brief Start a PWM channel.
 *
 * @param ChID   PWM channel ID to start.
 *
 * This function enables the output of the specified PWM channel and starts its operation.
 */
void HAL_PWM_Start(uint32_t handle);
 
/**
 * @brief Stop a PWM channel.
 *
 * @param ChID   PWM channel ID to stop.
 * @param force  Flag to force stop the channel.
 *
 * This function stops the specified PWM channel's operation. If 'force' is true, it forcefully stops the channel.
 * Otherwise, it stops the channel gracefully.
 */
void HAL_PWM_Stop(uint32_t handle, bool force);
 
/**
 * @brief Stop a PWM channel.
 *
 * @param ChID   PWM channel ID to stop.
 * @param force  Flag to force stop the channel.
 *
 * This function stops the specified PWM channel's operation. If 'force' is true, it forcefully stops the channel.
 * Otherwise, it stops the channel gracefully.
 */
void HAL_PWM_SetFreqAndDuty(uint32_t handle, uint32_t frequency, uint32_t dutyCycle);
 
/** @} */ // end of group
#endif /* __PAN_HAL_PWM_H */