pwmout_api.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /** \addtogroup hal */
  2. /** @{*/
  3. /* mbed Microcontroller Library
  4. * Copyright (c) 2006-2013 ARM Limited
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef MBED_PWMOUT_API_H
  19. #define MBED_PWMOUT_API_H
  20. #include "device.h"
  21. #if DEVICE_PWMOUT
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /** Pwmout hal structure. pwmout_s is declared in the target's hal
  26. */
  27. typedef struct pwmout_s pwmout_t;
  28. /**
  29. * \defgroup hal_pwmout Pwmout hal functions
  30. * @{
  31. */
  32. /** Initialize the pwm out peripheral and configure the pin
  33. *
  34. * @param obj The pwmout object to initialize
  35. * @param pin The pwmout pin to initialize
  36. */
  37. void pwmout_init(pwmout_t *obj, PinName pin);
  38. /** Deinitialize the pwmout object
  39. *
  40. * @param obj The pwmout object
  41. */
  42. void pwmout_free(pwmout_t *obj);
  43. /** Set the output duty-cycle in range <0.0f, 1.0f>
  44. *
  45. * Value 0.0f represents 0 percentage, 1.0f represents 100 percent.
  46. * @param obj The pwmout object
  47. * @param percent The floating-point percentage number
  48. */
  49. void pwmout_write(pwmout_t *obj, float percent);
  50. /** Read the current float-point output duty-cycle
  51. *
  52. * @param obj The pwmout object
  53. * @return A floating-point output duty-cycle
  54. */
  55. float pwmout_read(pwmout_t *obj);
  56. /** Set the PWM period specified in seconds, keeping the duty cycle the same
  57. *
  58. * Periods smaller than microseconds (the lowest resolution) are set to zero.
  59. * @param obj The pwmout object
  60. * @param seconds The floating-point seconds period
  61. */
  62. void pwmout_period(pwmout_t *obj, float seconds);
  63. /** Set the PWM period specified in miliseconds, keeping the duty cycle the same
  64. *
  65. * @param obj The pwmout object
  66. * @param ms The milisecond period
  67. */
  68. void pwmout_period_ms(pwmout_t *obj, int ms);
  69. /** Set the PWM period specified in microseconds, keeping the duty cycle the same
  70. *
  71. * @param obj The pwmout object
  72. * @param us The microsecond period
  73. */
  74. void pwmout_period_us(pwmout_t *obj, int us);
  75. /** Set the PWM pulsewidth specified in seconds, keeping the period the same.
  76. *
  77. * @param obj The pwmout object
  78. * @param seconds The floating-point pulsewidth in seconds
  79. */
  80. void pwmout_pulsewidth(pwmout_t *obj, float seconds);
  81. /** Set the PWM pulsewidth specified in miliseconds, keeping the period the same.
  82. *
  83. * @param obj The pwmout object
  84. * @param ms The floating-point pulsewidth in miliseconds
  85. */
  86. void pwmout_pulsewidth_ms(pwmout_t *obj, int ms);
  87. /** Set the PWM pulsewidth specified in microseconds, keeping the period the same.
  88. *
  89. * @param obj The pwmout object
  90. * @param us The floating-point pulsewidth in microseconds
  91. */
  92. void pwmout_pulsewidth_us(pwmout_t *obj, int us);
  93. /**@}*/
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif
  98. #endif
  99. /** @}*/