rt_drv_pwm.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2006-2018, 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. struct rt_pwm_configuration
  19. {
  20. rt_uint32_t channel; /* 0-n */
  21. rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */
  22. rt_uint32_t pulse; /* unit:ns (pulse<=period) */
  23. };
  24. struct rt_device_pwm;
  25. struct rt_pwm_ops
  26. {
  27. rt_err_t (*control)(struct rt_device_pwm *device, int cmd, void *arg);
  28. };
  29. struct rt_device_pwm
  30. {
  31. struct rt_device parent;
  32. const struct rt_pwm_ops *ops;
  33. };
  34. 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);
  35. rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel);
  36. rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel);
  37. rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse);
  38. #endif /* __DRV_PWM_H_INCLUDE__ */