1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
| /**
| * @file dev_pwm.c
| * @author your name (you@domain.com)
| * @brief
| * @version 0.1
| * @date 2023-04-05
| *
| * @copyright Copyright (c) 2023
| *
| */
|
| #include <string.h>
| #include "dev_pwm.h"
| #include "ems_assert.h"
|
| #ifdef __cplusplus
| extern "C" {
| #endif
|
| EMS_TAG("EMS_PWM")
|
| /* private variables -------------------------------------------------------- */
| static ems_ops_t _obj_ops =
| {
| .open = NULL,
| .close = NULL,
| .read = NULL,
| .write = NULL,
| };
|
| /**
| * @brief
| *
| * @param me
| * @param name
| * @param ops
| * @param user_data
| */
| void ems_pwm_register(ems_pwm_t * const me,
| const char *name,
| const ems_pwm_ops_t *ops,
| void *user_data)
| {
| ems_assert(me != NULL);
| ems_assert(name != NULL);
| ems_assert(ops != NULL);
|
| ems_obj_attr_t attr =
| {
| .user_data = user_data,
| .standlone = true,
| .type = EMS_OBJ_PWM,
| };
|
| ems_register(&me->super, name, &_obj_ops, &attr);
|
| me->ops = ops;
| me->duty_ratio = 0;
| me->ops->init(me);
| }
|
| /**
| * @brief
| *
| * @param me
| * @param duty_ratio
| */
| void ems_pwm_set_duty(ems_object_t * const me, uint8_t duty_ratio)
| {
| ems_assert(me != NULL);
| ems_assert(duty_ratio <= 100);
| ems_assert(me->attr.type == EMS_OBJ_PWM);
|
| ems_pwm_t *pwm = (ems_pwm_t *)me;
| if (duty_ratio != pwm->duty_ratio)
| {
| pwm->ops->set_duty(pwm, duty_ratio);
| pwm->duty_ratio = duty_ratio;
| }
| }
|
| #ifdef __cplusplus
| }
| #endif
|
|