pwm.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright 2018 Canaan Inc.
  2. *
  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. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _DRIVER_PWM_H
  16. #define _DRIVER_PWM_H
  17. #include <stddef.h>
  18. #include <stdint.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef enum _pwm_device_number
  23. {
  24. PWM_DEVICE_0,
  25. PWM_DEVICE_1,
  26. PWM_DEVICE_2,
  27. PWM_DEVICE_MAX,
  28. } pwm_device_number_t;
  29. typedef enum _pwm_channel_number
  30. {
  31. PWM_CHANNEL_0,
  32. PWM_CHANNEL_1,
  33. PWM_CHANNEL_2,
  34. PWM_CHANNEL_3,
  35. PWM_CHANNEL_MAX,
  36. } pwm_channel_number_t;
  37. /**
  38. * @brief Init pwm timer
  39. *
  40. * @param[in] timer timer
  41. */
  42. void pwm_init(pwm_device_number_t pwm_number);
  43. /**
  44. * @brief Enable timer
  45. *
  46. * @param[in] timer timer
  47. * @param[in] channel channel
  48. * @param[in] enable Enable or disable
  49. *
  50. */
  51. void pwm_set_enable(pwm_device_number_t pwm_number, pwm_channel_number_t channel, int enable);
  52. /**
  53. * @brief Set pwm duty
  54. *
  55. * @param[in] timer timer
  56. * @param[in] channel channel
  57. * @param[in] frequency pwm frequency
  58. * @param[in] duty duty
  59. *
  60. */
  61. double pwm_set_frequency(pwm_device_number_t pwm_number, pwm_channel_number_t channel, double frequency, double duty);
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif /* _DRIVER_PWM_H */