hc32f460_timer4_pwm.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_timer4_pwm.h
  11. **
  12. ** A detailed description is available at
  13. ** @link Timer4PwmGroup Timer4PWM description @endlink
  14. **
  15. ** - 2018-11-02 CDT First version for Device Driver Library of Timer4PWM.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_TIMER4_PWM_H__
  19. #define __HC32F460_TIMER4_PWM_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_TIMER4_PWM_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup Timer4PwmGroup Timer4 Pulse-Width Modulation(Timer4PWM)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /*******************************************************************************
  41. ** \brief Timer4 PWM channel enumeration
  42. **
  43. ******************************************************************************/
  44. typedef enum en_timer4_pwm_ch
  45. {
  46. Timer4PwmU = 0u, ///< Timer4 PWM couple channel: U
  47. Timer4PwmV = 1u, ///< Timer4 PWM couple channel: V
  48. Timer4PwmW = 2u, ///< Timer4 PWM couple channel: W
  49. } en_timer4_pwm_ch_t;
  50. /*******************************************************************************
  51. ** \brief Timer4 PWM operation mode enumeration
  52. **
  53. ******************************************************************************/
  54. typedef enum en_timer4_pwm_mode
  55. {
  56. PwmThroughMode = 0u, ///< through mode
  57. PwmDeadTimerMode = 1u, ///< Dead timer mode
  58. PwmDeadTimerFilterMode = 2u, ///< Dead timer filter mode
  59. } en_timer4_pwm_mode_t;
  60. /*******************************************************************************
  61. ** \brief Timer4 PWM DMOD bit setting enumeration
  62. **
  63. ******************************************************************************/
  64. typedef enum en_timer4_pwm_output_state
  65. {
  66. PwmHPwmLHold = 0u, ///< Output PWML and PWMH signals without changing the level
  67. PwmHPwmLReverse = 1u, ///< Output both PWML and PWMH signals reversed
  68. PwmHReversePwmLHold = 2u, ///< Output the PWMH signal reversed, outputs the PWML signal without changing the level.
  69. PwmHHoldPwmLReverse = 3u, ///< Output the PWMH signal without changing the level, Outputs the PWML signal reversed.
  70. } en_timer4_pwm_output_state_t;
  71. /*******************************************************************************
  72. ** \brief Timer4 PWM count clock prescaler enumeration
  73. **
  74. ******************************************************************************/
  75. typedef enum en_timer4_pwm_timer_clk_div
  76. {
  77. PwmPlckDiv1 = 0u, ///< PWM timer clock prescaler: None
  78. PwmPlckDiv2 = 1u, ///< PWM timer clock prescaler: 1/2
  79. PwmPlckDiv4 = 2u, ///< PWM timer clock prescaler: 1/4
  80. PwmPlckDiv8 = 3u, ///< PWM timer clock prescaler: 1/8
  81. PwmPlckDiv16 = 4u, ///< PWM timer clock prescaler: 1/16
  82. PwmPlckDiv32 = 5u, ///< PWM timer clock prescaler: 1/32
  83. PwmPlckDiv64 = 6u, ///< PWM timer clock prescaler: 1/64
  84. PwmPlckDiv128 = 7u, ///< PWM timer clock prescaler: 1/128
  85. } en_timer4_pwm_timer_clk_div_t;
  86. /*******************************************************************************
  87. ** \brief Timer4 PWM initialization configuration
  88. **
  89. ******************************************************************************/
  90. typedef struct stc_timer4_pwm_init
  91. {
  92. en_timer4_pwm_mode_t enMode; ///< Select PWM mode and this parameter can be a value of @ref en_timer4_pwm_mode_t
  93. en_timer4_pwm_timer_clk_div_t enClkDiv; ///< Clock division of PWM timer and this parameter can be a value of @ref en_timer4_pwm_timer_clk_div_t
  94. en_timer4_pwm_output_state_t enOutputState; ///< Polarity for PWMH and PWML signal output and this parameter can be a value of @ref en_timer4_pwm_output_state_t
  95. en_functional_state_t enRtIntMaskCmd; ///< Enable: Enable mask reload-timer interrupt, FALSE: don't mask reload-timer interrupt
  96. } stc_timer4_pwm_init_t;
  97. /*******************************************************************************
  98. * Global pre-processor symbols/macros ('#define')
  99. ******************************************************************************/
  100. /*******************************************************************************
  101. * Global variable definitions ('extern')
  102. ******************************************************************************/
  103. /*******************************************************************************
  104. * Global function prototypes (definition in C source)
  105. ******************************************************************************/
  106. en_result_t TIMER4_PWM_Init(M4_TMR4_TypeDef *TMR4x,
  107. en_timer4_pwm_ch_t enCh,
  108. const stc_timer4_pwm_init_t *pstcInitCfg);
  109. en_result_t TIMER4_PWM_DeInit(M4_TMR4_TypeDef *TMR4x,
  110. en_timer4_pwm_ch_t enCh);
  111. en_result_t TIMER4_PWM_StartTimer(M4_TMR4_TypeDef *TMR4x,
  112. en_timer4_pwm_ch_t enCh);
  113. en_result_t TIMER4_PWM_StopTimer(M4_TMR4_TypeDef *TMR4x,
  114. en_timer4_pwm_ch_t enCh);
  115. en_flag_status_t TIMER4_PWM_GetIrqFlag(M4_TMR4_TypeDef *TMR4x,
  116. en_timer4_pwm_ch_t enCh);
  117. en_result_t TIMER4_PWM_ClearIrqFlag(M4_TMR4_TypeDef *TMR4x,
  118. en_timer4_pwm_ch_t enCh);
  119. en_result_t TIMER4_PWM_WriteDeadRegionValue(M4_TMR4_TypeDef *TMR4x,
  120. en_timer4_pwm_ch_t enCh,
  121. uint16_t u16PDAR,
  122. uint16_t u16PDBR);
  123. en_result_t TIMER4_PWM_ReadDeadRegionValue(M4_TMR4_TypeDef *TMR4x,
  124. en_timer4_pwm_ch_t enCh,
  125. uint16_t* u16PDAR,
  126. uint16_t* u16PDBR);
  127. en_result_t TIMER4_PWM_SetFilterCountValue(M4_TMR4_TypeDef *TMR4x,
  128. en_timer4_pwm_ch_t enCh,
  129. uint16_t u16Count);
  130. //@} // Timer4PwmGroup
  131. #ifdef __cplusplus
  132. }
  133. #endif
  134. #endif /* DDL_TIMER4_PWM_ENABLE */
  135. #endif /* __HC32F460_TIMER4_PWM_H__ */
  136. /*******************************************************************************
  137. * EOF (not truncated)
  138. ******************************************************************************/