xref: /nrf52832-nimble/rt-thread/components/drivers/include/drivers/rt_drv_pwm.h (revision 104654410c56c573564690304ae786df310c91fc)
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 
11 #ifndef __DRV_PWM_H_INCLUDE__
12 #define __DRV_PWM_H_INCLUDE__
13 
14 #include <rtthread.h>
15 #include <rtdevice.h>
16 
17 #define PWM_CMD_ENABLE      (128 + 0)
18 #define PWM_CMD_DISABLE     (128 + 1)
19 #define PWM_CMD_SET         (128 + 2)
20 #define PWM_CMD_GET         (128 + 3)
21 
22 struct rt_pwm_configuration
23 {
24     rt_uint32_t channel; /* 0-n */
25     rt_uint32_t period;  /* unit:ns 1ns~4.29s:1Ghz~0.23hz */
26     rt_uint32_t pulse;   /* unit:ns (pulse<=period) */
27 };
28 
29 struct rt_device_pwm;
30 struct rt_pwm_ops
31 {
32     rt_err_t (*control)(struct rt_device_pwm *device, int cmd, void *arg);
33 };
34 
35 struct rt_device_pwm
36 {
37     struct rt_device parent;
38     const struct rt_pwm_ops *ops;
39 };
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 
43 rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel);
44 rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel);
45 rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse);
46 
47 #endif /* __DRV_PWM_H_INCLUDE__ */
48