drv_pwm.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_PWM_H_
  13. #define _DRV_PWM_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef enum
  21. {
  22. LGP_PER_125MS,
  23. LGP_PER_250MS,
  24. LGP_PER_500MS,
  25. LGP_PER_1000MS,
  26. LGP_PER_1500MS,
  27. LGP_PER_2000MS,
  28. LGP_PER_2500MS,
  29. LGP_PER_3000MS,
  30. } drvLpgPer_t;
  31. typedef enum
  32. {
  33. LGP_ONTIME_UNDEFINE,
  34. LGP_ONTIME_15_6MS,
  35. LGP_ONTIME_31_2MS,
  36. LGP_ONTIME_46_8MS,
  37. LGP_ONTIME_62MS,
  38. LGP_ONTIME_78MS,
  39. LGP_ONTIME_94MS,
  40. LGP_ONTIME_110MS,
  41. LGP_ONTIME_125MS,
  42. LGP_ONTIME_140MS,
  43. LGP_ONTIME_156MS,
  44. LGP_ONTIME_172MS,
  45. LGP_ONTIME_188MS,
  46. LGP_ONTIME_200MS,
  47. LGP_ONTIME_218MS,
  48. LGP_ONTIME_234MS
  49. } drvLpgOntime_t;
  50. typedef enum
  51. {
  52. PWL_ID_0,
  53. PWL_ID_1
  54. } drvPwlId_t;
  55. typedef struct drvPwm drvPwm_t;
  56. /**
  57. * @brief This function can acquire a pwm structure
  58. * @param name pwm name,such as DRV_NAME_PWM1
  59. * @return
  60. * - NULL if fail
  61. * - other success
  62. */
  63. drvPwm_t *drvPwmAcquire(uint32_t name);
  64. /**
  65. * @brief This functiton set pwt period count and clk prescaler
  66. * output_clk = 200Mhz/(prescaler+1)/(prescaler*8 + 1)
  67. * **notice** : now clk_lock must be set,otherwise the clock will switch between
  68. * 26M and 200M.In this case , system will not sleep.
  69. * @param d pwm structure
  70. * @param period_count period load data,must less than 2047.if period_count is 0,
  71. * pwt can't work.
  72. * @param prescaler pwm clock prescaler,clk = 200Mhz/(prescaler+1)
  73. * @param duty duty must less than 1023,duty/period_count is the duty
  74. * ratio.duty can't be 0 or pwt will stop.
  75. */
  76. void drvPwtSetPeriodDuty(drvPwm_t *d, uint8_t clk_div, uint32_t pwm_count, uint32_t duty);
  77. /**
  78. * @brief pwt output start
  79. * @param d pwm structure
  80. * @return
  81. * - false if fail
  82. * - true success
  83. */
  84. bool drvPwtStart(drvPwm_t *d);
  85. /**
  86. * @brief This function stop pwl output
  87. * @param d pwm structure
  88. * @return
  89. * - false if fail
  90. * - true success
  91. */
  92. bool drvPwtStop(drvPwm_t *d);
  93. /**
  94. * @brief This function makes the lpg modul output
  95. @param d pwm structure
  96. * @param period lpg period ,from 125ms to 3s
  97. * @param ontime lpg on time ,from 15.6ms to 234ms
  98. * @return
  99. * - false if fail
  100. * - true success
  101. */
  102. bool drvLgpStart(drvPwm_t *d, drvLpgPer_t period, drvLpgOntime_t ontime);
  103. /**
  104. * @brief This function stop the lpg modul output
  105. * @param d pwm structure
  106. * @return
  107. * - false if fail
  108. * - true success
  109. */
  110. bool drvLgpStop(drvPwm_t *d);
  111. /**
  112. * @brief set the averge on time for selected PWL output,
  113. * thus, the intergrated output represents a certain luminosity level
  114. * @param d pwm structure
  115. * @param pwl_id pwl0 and pwl1
  116. * @param level 0 will force the pwl output to 0 while a value
  117. * of 0xff will force the output to 1.
  118. * @return
  119. * - false if fail
  120. * - true success
  121. */
  122. bool drvPwlStart(drvPwm_t *d, drvPwlId_t pwl_id, uint8_t level);
  123. /**
  124. * @brief This function stop the pwl modul output
  125. * @param d pwm structure
  126. * @param pwl_id pwl0 and pwl1
  127. * @return
  128. * - false if fail
  129. * - true success
  130. */
  131. bool drvPwlStop(drvPwm_t *d, drvPwlId_t pwl_id);
  132. /**
  133. * @brief This function release pwm controller
  134. * @param d pwm structure
  135. */
  136. void drvPwmRelease(drvPwm_t *d);
  137. #endif