drv_pwm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (c) 2006-2018, Synwit Technology Co.,Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-12-10 Zohar_Lee first version
  9. * 2020-07-10 lik rewrite
  10. */
  11. #ifndef __DRV_PWM_H__
  12. #define __DRV_PWM_H__
  13. #include "board.h"
  14. struct swm_pwm_cfg
  15. {
  16. const char *name;
  17. PWM_TypeDef *PWMx;
  18. PWM_InitStructure pwm_initstruct;
  19. };
  20. struct swm_pwm
  21. {
  22. struct swm_pwm_cfg *cfg;
  23. struct rt_device_pwm pwm_device;
  24. };
  25. #ifdef BSP_USING_PWM0
  26. #ifndef PWM0_CFG
  27. #define PWM0_CFG \
  28. { \
  29. .name = "pwm0", \
  30. .PWMx = PWM0, \
  31. .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
  32. .pwm_initstruct.mode = PWM_MODE_INDEP, \
  33. .pwm_initstruct.cycleA = 10000, \
  34. .pwm_initstruct.hdutyA = 5000, \
  35. .pwm_initstruct.initLevelA = 1, \
  36. .pwm_initstruct.cycleB = 10000, \
  37. .pwm_initstruct.hdutyB = 5000, \
  38. .pwm_initstruct.initLevelB = 1, \
  39. .pwm_initstruct.HEndAIEn = 0, \
  40. .pwm_initstruct.NCycleAIEn = 0, \
  41. .pwm_initstruct.HEndBIEn = 0, \
  42. .pwm_initstruct.NCycleBIEn = 0, \
  43. }
  44. #endif /* PWM0_CFG */
  45. #endif /* BSP_USING_PWM0 */
  46. #ifdef BSP_USING_PWM1
  47. #ifndef PWM1_CFG
  48. #define PWM1_CFG \
  49. { \
  50. .name = "pwm1", \
  51. .PWMx = PWM1, \
  52. .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
  53. .pwm_initstruct.mode = PWM_MODE_INDEP, \
  54. .pwm_initstruct.cycleA = 10000, \
  55. .pwm_initstruct.hdutyA = 5000, \
  56. .pwm_initstruct.initLevelA = 1, \
  57. .pwm_initstruct.cycleB = 10000, \
  58. .pwm_initstruct.hdutyB = 5000, \
  59. .pwm_initstruct.initLevelB = 1, \
  60. .pwm_initstruct.HEndAIEn = 0, \
  61. .pwm_initstruct.NCycleAIEn = 0, \
  62. .pwm_initstruct.HEndBIEn = 0, \
  63. .pwm_initstruct.NCycleBIEn = 0, \
  64. }
  65. #endif /* PWM1_CFG */
  66. #endif /* BSP_USING_PWM1 */
  67. #ifdef BSP_USING_PWM2
  68. #ifndef PWM2_CFG
  69. #define PWM2_CFG \
  70. { \
  71. .name = "pwm2", \
  72. .PWMx = PWM2, \
  73. .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
  74. .pwm_initstruct.mode = PWM_MODE_INDEP, \
  75. .pwm_initstruct.cycleA = 10000, \
  76. .pwm_initstruct.hdutyA = 5000, \
  77. .pwm_initstruct.initLevelA = 1, \
  78. .pwm_initstruct.cycleB = 10000, \
  79. .pwm_initstruct.hdutyB = 5000, \
  80. .pwm_initstruct.initLevelB = 1, \
  81. .pwm_initstruct.HEndAIEn = 0, \
  82. .pwm_initstruct.NCycleAIEn = 0, \
  83. .pwm_initstruct.HEndBIEn = 0, \
  84. .pwm_initstruct.NCycleBIEn = 0, \
  85. }
  86. #endif /* PWM2_CFG */
  87. #endif /* BSP_USING_PWM2 */
  88. #ifdef BSP_USING_PWM3
  89. #ifndef PWM3_CFG
  90. #define PWM3_CFG \
  91. { \
  92. .name = "pwm3", \
  93. .PWMx = PWM3, \
  94. .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
  95. .pwm_initstruct.mode = PWM_MODE_INDEP, \
  96. .pwm_initstruct.cycleA = 10000, \
  97. .pwm_initstruct.hdutyA = 5000, \
  98. .pwm_initstruct.initLevelA = 1, \
  99. .pwm_initstruct.cycleB = 10000, \
  100. .pwm_initstruct.hdutyB = 5000, \
  101. .pwm_initstruct.initLevelB = 1, \
  102. .pwm_initstruct.HEndAIEn = 0, \
  103. .pwm_initstruct.NCycleAIEn = 0, \
  104. .pwm_initstruct.HEndBIEn = 0, \
  105. .pwm_initstruct.NCycleBIEn = 0, \
  106. }
  107. #endif /* PWM3_CFG */
  108. #endif /* BSP_USING_PWM3 */
  109. #ifdef BSP_USING_PWM4
  110. #ifndef PWM4_CFG
  111. #define PWM4_CFG \
  112. { \
  113. .name = "pwm4", \
  114. .PWMx = PWM4, \
  115. .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
  116. .pwm_initstruct.mode = PWM_MODE_INDEP, \
  117. .pwm_initstruct.cycleA = 10000, \
  118. .pwm_initstruct.hdutyA = 5000, \
  119. .pwm_initstruct.initLevelA = 1, \
  120. .pwm_initstruct.cycleB = 10000, \
  121. .pwm_initstruct.hdutyB = 5000, \
  122. .pwm_initstruct.initLevelB = 1, \
  123. .pwm_initstruct.HEndAIEn = 0, \
  124. .pwm_initstruct.NCycleAIEn = 0, \
  125. .pwm_initstruct.HEndBIEn = 0, \
  126. .pwm_initstruct.NCycleBIEn = 0, \
  127. }
  128. #endif /* PWM4_CFG */
  129. #endif /* BSP_USING_PWM4 */
  130. #ifdef BSP_USING_PWM5
  131. #ifndef PWM5_CFG
  132. #define PWM5_CFG \
  133. { \
  134. .name = "pwm5", \
  135. .PWMx = PWM5, \
  136. .pwm_initstruct.clk_div = PWM_CLKDIV_8, \
  137. .pwm_initstruct.mode = PWM_MODE_INDEP, \
  138. .pwm_initstruct.cycleA = 10000, \
  139. .pwm_initstruct.hdutyA = 5000, \
  140. .pwm_initstruct.initLevelA = 1, \
  141. .pwm_initstruct.cycleB = 10000, \
  142. .pwm_initstruct.hdutyB = 5000, \
  143. .pwm_initstruct.initLevelB = 1, \
  144. .pwm_initstruct.HEndAIEn = 0, \
  145. .pwm_initstruct.NCycleAIEn = 0, \
  146. .pwm_initstruct.HEndBIEn = 0, \
  147. .pwm_initstruct.NCycleBIEn = 0, \
  148. }
  149. #endif /* PWM5_CFG */
  150. #endif /* BSP_USING_PWM5 */
  151. int rt_hw_pwm_init(void);
  152. #endif /* __DRV_PWM_H__ */