hal_pwm_lld.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_pwm_lld.h
  15. * @brief PLATFORM PWM subsystem low level driver header.
  16. *
  17. * @addtogroup PWM
  18. * @{
  19. */
  20. #ifndef HAL_PWM_LLD_H
  21. #define HAL_PWM_LLD_H
  22. #if (HAL_USE_PWM == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /**
  27. * @brief Number of PWM channels per PWM driver.
  28. */
  29. #define PWM_CHANNELS 4
  30. /*===========================================================================*/
  31. /* Driver pre-compile time settings. */
  32. /*===========================================================================*/
  33. /**
  34. * @name PLATFORM configuration options
  35. * @{
  36. */
  37. /**
  38. * @brief PWMD1 driver enable switch.
  39. * @details If set to @p TRUE the support for PWM1 is included.
  40. * @note The default is @p FALSE.
  41. */
  42. #if !defined(PLATFORM_PWM_USE_PWM1) || defined(__DOXYGEN__)
  43. #define PLATFORM_PWM_USE_PWM1 FALSE
  44. #endif
  45. /** @} */
  46. /*===========================================================================*/
  47. /* Configuration checks. */
  48. /*===========================================================================*/
  49. /*===========================================================================*/
  50. /* Driver data structures and types. */
  51. /*===========================================================================*/
  52. /**
  53. * @brief Type of a PWM mode.
  54. */
  55. typedef uint32_t pwmmode_t;
  56. /**
  57. * @brief Type of a PWM channel.
  58. */
  59. typedef uint8_t pwmchannel_t;
  60. /**
  61. * @brief Type of a channels mask.
  62. */
  63. typedef uint32_t pwmchnmsk_t;
  64. /**
  65. * @brief Type of a PWM counter.
  66. */
  67. typedef uint32_t pwmcnt_t;
  68. /**
  69. * @brief Type of a PWM driver channel configuration structure.
  70. */
  71. typedef struct {
  72. /**
  73. * @brief Channel active logic level.
  74. */
  75. pwmmode_t mode;
  76. /**
  77. * @brief Channel callback pointer.
  78. * @note This callback is invoked on the channel compare event. If set to
  79. * @p NULL then the callback is disabled.
  80. */
  81. pwmcallback_t callback;
  82. /* End of the mandatory fields.*/
  83. } PWMChannelConfig;
  84. /**
  85. * @brief Type of a PWM driver configuration structure.
  86. */
  87. typedef struct {
  88. /**
  89. * @brief Timer clock in Hz.
  90. * @note The low level can use assertions in order to catch invalid
  91. * frequency specifications.
  92. */
  93. uint32_t frequency;
  94. /**
  95. * @brief PWM period in ticks.
  96. * @note The low level can use assertions in order to catch invalid
  97. * period specifications.
  98. */
  99. pwmcnt_t period;
  100. /**
  101. * @brief Periodic callback pointer.
  102. * @note This callback is invoked on PWM counter reset. If set to
  103. * @p NULL then the callback is disabled.
  104. */
  105. pwmcallback_t callback;
  106. /**
  107. * @brief Channels configurations.
  108. */
  109. PWMChannelConfig channels[PWM_CHANNELS];
  110. /* End of the mandatory fields.*/
  111. } PWMConfig;
  112. /**
  113. * @brief Structure representing a PWM driver.
  114. */
  115. struct PWMDriver {
  116. /**
  117. * @brief Driver state.
  118. */
  119. pwmstate_t state;
  120. /**
  121. * @brief Current driver configuration data.
  122. */
  123. const PWMConfig *config;
  124. /**
  125. * @brief Current PWM period in ticks.
  126. */
  127. pwmcnt_t period;
  128. /**
  129. * @brief Mask of the enabled channels.
  130. */
  131. pwmchnmsk_t enabled;
  132. /**
  133. * @brief Number of channels in this instance.
  134. */
  135. pwmchannel_t channels;
  136. #if defined(PWM_DRIVER_EXT_FIELDS)
  137. PWM_DRIVER_EXT_FIELDS
  138. #endif
  139. /* End of the mandatory fields.*/
  140. };
  141. /*===========================================================================*/
  142. /* Driver macros. */
  143. /*===========================================================================*/
  144. /**
  145. * @brief Changes the period the PWM peripheral.
  146. * @details This function changes the period of a PWM unit that has already
  147. * been activated using @p pwmStart().
  148. * @pre The PWM unit must have been activated using @p pwmStart().
  149. * @post The PWM unit period is changed to the new value.
  150. * @note The function has effect at the next cycle start.
  151. * @note If a period is specified that is shorter than the pulse width
  152. * programmed in one of the channels then the behavior is not
  153. * guaranteed.
  154. *
  155. * @param[in] pwmp pointer to a @p PWMDriver object
  156. * @param[in] period new cycle time in ticks
  157. *
  158. * @notapi
  159. */
  160. #define pwm_lld_change_period(pwmp, period)
  161. /*===========================================================================*/
  162. /* External declarations. */
  163. /*===========================================================================*/
  164. #if (PLATFORM_PWM_USE_PWM1 == TRUE) && !defined(__DOXYGEN__)
  165. extern PWMDriver PWMD1;
  166. #endif
  167. #ifdef __cplusplus
  168. extern "C" {
  169. #endif
  170. void pwm_lld_init(void);
  171. void pwm_lld_start(PWMDriver *pwmp);
  172. void pwm_lld_stop(PWMDriver *pwmp);
  173. void pwm_lld_enable_channel(PWMDriver *pwmp,
  174. pwmchannel_t channel,
  175. pwmcnt_t width);
  176. void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel);
  177. void pwm_lld_enable_periodic_notification(PWMDriver *pwmp);
  178. void pwm_lld_disable_periodic_notification(PWMDriver *pwmp);
  179. void pwm_lld_enable_channel_notification(PWMDriver *pwmp,
  180. pwmchannel_t channel);
  181. void pwm_lld_disable_channel_notification(PWMDriver *pwmp,
  182. pwmchannel_t channel);
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif /* HAL_USE_PWM == TRUE */
  187. #endif /* HAL_PWM_LLD_H */
  188. /** @} */