yc11xx_pwm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright 2016, yichip Semiconductor(shenzhen office)
  3. * All Rights Reserved.
  4. *
  5. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor;
  6. * the contents of this file may not be disclosed to third parties, copied
  7. * or duplicated in any form, in whole or in part, without the prior
  8. * written permission of Yichip Semiconductor.
  9. */
  10. /**
  11. *@file pwm.h
  12. *@brief PWM support for application.
  13. */
  14. #ifndef _PWM_H_
  15. #define _PWM_H_
  16. #include <stdio.h>
  17. #include "yc11xx.h"
  18. #include "ycdef.h"
  19. /**
  20. *@brief PWM register base.
  21. */
  22. #define PWM_BASE CORE_PWM0_PCNT
  23. #define CORE_PWM_PCNT(x) (CORE_PWM0_PCNT+x*0x5)
  24. #define CORE_PWM_NCNT(x) (CORE_PWM0_NCNT+x*0x5)
  25. #define CORE_PWM_CTRL(x) (CORE_PWM0_CTRL+x*0x5)
  26. /**
  27. * @brief pwm clock enable enumeration
  28. */
  29. typedef enum
  30. {
  31. PWMCLK_ENABLE = 0,
  32. PWMCLK_DISABLE = 0x20
  33. } PWM_ClkSwitchDef;
  34. #define IS_PWM_ClkSwitchDef(clk_switch) (clk_switch == PWMCLK_ENABLE || PWMCLK_DISABLE)
  35. /**
  36. *@brief PWM channel enumeration.
  37. */
  38. typedef enum
  39. {
  40. PWM_CHANNEL_0 = 0,
  41. PWM_CHANNEL_1,
  42. PWM_CHANNEL_2,
  43. PWM_CHANNEL_3,
  44. PWM_CHANNEL_4,
  45. PWM_CHANNEL_5,
  46. PWM_CHANNEL_6,
  47. PWM_CHANNEL_7
  48. }PWM_ChxTypeDef;
  49. #define IS_PWM_ChxTypeDef(Channel) ((Channel == PWM_CHANNEL_0)||\
  50. (Channel == PWM_CHANNEL_1) ||\
  51. (Channel == PWM_CHANNEL_2) ||\
  52. (Channel == PWM_CHANNEL_3) ||\
  53. (Channel == PWM_CHANNEL_4) ||\
  54. (Channel == PWM_CHANNEL_5) ||\
  55. (Channel == PWM_CHANNEL_6) ||\
  56. (Channel == PWM_CHANNEL_7))
  57. /**
  58. * @brief PWM CLK DIV enumeration
  59. */
  60. typedef enum
  61. {
  62. PWM_CLK_DIVISION_0 = 0x0,
  63. PWM_CLK_DIVISION_1 = 0x1,
  64. PWM_CLK_DIVISION_2 = 0x2,
  65. PWM_CLK_DIVISION_3 = 0x3,
  66. PWM_CLK_DIVISION_4 = 0x4,
  67. PWM_CLK_DIVISION_5 = 0x5,
  68. PWM_CLK_DIVISION_6 = 0x6,
  69. PWM_CLK_DIVISION_7 = 0x7
  70. }PWM_ClkdivDef;
  71. #define IS_CLK_DIVISION(div) ((div == PWM_CLK_DIVISION_0)||\
  72. (div == PWM_CLK_DIVISION_1) ||\
  73. (div == PWM_CLK_DIVISION_2) ||\
  74. (div == PWM_CLK_DIVISION_3) ||\
  75. (div == PWM_CLK_DIVISION_4) ||\
  76. (div == PWM_CLK_DIVISION_5) ||\
  77. (div == PWM_CLK_DIVISION_6) ||\
  78. (div == PWM_CLK_DIVISION_7))
  79. /**
  80. * @brief PWM start output enumeration
  81. */
  82. typedef enum
  83. {
  84. OutputLow = 0,
  85. OutputHigh = 0x10
  86. } START_TypeDef;
  87. #define IS_PWM_START(LEVEL) (LEVEL == OutputLow || LEVEL == OutputHigh)
  88. /**
  89. * @brief pwm enable enumeration
  90. */
  91. typedef enum
  92. {
  93. PWM_DISENABLE = 0,
  94. PWM_ENABLE = 0x20
  95. } PWM_SwitchDef;
  96. #define IS_PWM_SWITCH(SWITCH) (SWITCH == PWM_DISENABLE || SWITCH == PWM_ENABLE)
  97. /**
  98. * @brief PWM CTRL Structure definition
  99. */
  100. typedef struct
  101. {
  102. PWM_ClkdivDef clk_div;
  103. START_TypeDef StartLevel;
  104. PWM_SwitchDef pwm_switch;
  105. }PWM_CtrlDef;
  106. /**
  107. * @brief PWM Init Structure definition
  108. */
  109. typedef struct
  110. {
  111. GPIO_NUM pwm_gpio;
  112. PWM_ChxTypeDef PWM_Channel;
  113. uint16_t LowLevelPeriod;
  114. uint16_t HighLevelPeriod;
  115. PWM_CtrlDef pwm_ctrl;
  116. }PWM_InitTypeDef;
  117. #define IS_PERIOD_VALUE(x) (x<=0xffff)
  118. #define IS_PWM_GPIO(gpio) ((gpio >= 0) && (gpio <= 0x1f))
  119. void PWM_ClockSwitch(PWM_ClkSwitchDef PWM_ClkSwitch);
  120. /**
  121. * @brief set PWM HIGH pulse and low pulse count
  122. * @param pwm_channel choose PWM_CHANNEL from PWM_CHANNEL_0 - PWM_CHANNEL_7
  123. * @param pcnt high pulse count
  124. * @param ncnt low pulse count
  125. */
  126. void PWM_setcnt(PWM_ChxTypeDef pwm_channel,uint16_t pcnt,uint16_t ncnt);
  127. /**
  128. * @brief set PWM open or close
  129. * @param pwm_channel choose PWM_CHANNEL from PWM_CHANNEL_0 - PWM_CHANNEL_7
  130. * @param SWITCH PWM_ENABLE or PWM_DISENABLE
  131. */
  132. void PWM_SWITCH(PWM_ChxTypeDef pwm_channel,PWM_SwitchDef SWITCH);
  133. /**
  134. * @brief PWM config
  135. * @param gpio choose the gpio as pwm channel
  136. * @param pcnt high count
  137. * @param ncnt low count
  138. * @param val
  139. */
  140. void PWM_Init(PWM_InitTypeDef* PWM_InitStruct);
  141. #endif