rt_drv_pwm.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-07 aozima the first version
  9. */
  10. #ifndef __DRV_PWM_H_INCLUDE__
  11. #define __DRV_PWM_H_INCLUDE__
  12. #include <rtthread.h>
  13. #include <rtdevice.h>
  14. #define PWM_CMD_ENABLE (128 + 0)
  15. #define PWM_CMD_DISABLE (128 + 1)
  16. #define PWM_CMD_SET (128 + 2)
  17. #define PWM_CMD_GET (128 + 3)
  18. #define PWMN_CMD_ENABLE (128 + 4)
  19. #define PWMN_CMD_DISABLE (128 + 5)
  20. struct rt_pwm_configuration
  21. {
  22. rt_uint32_t channel; /* 0-n */
  23. rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */
  24. rt_uint32_t pulse; /* unit:ns (pulse<=period) */
  25. /*
  26. * RT_TRUE : The channel of pwm is complememtary.
  27. * RT_FALSE : The channel of pwm is nomal.
  28. */
  29. rt_bool_t complementary;
  30. };
  31. struct rt_device_pwm;
  32. struct rt_pwm_ops
  33. {
  34. rt_err_t (*control)(struct rt_device_pwm *device, int cmd, void *arg);
  35. };
  36. struct rt_device_pwm
  37. {
  38. struct rt_device parent;
  39. const struct rt_pwm_ops *ops;
  40. };
  41. rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, const struct rt_pwm_ops *ops, const void *user_data);
  42. rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel);
  43. rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel);
  44. rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse);
  45. #endif /* __DRV_PWM_H_INCLUDE__ */