1 /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef IOTJS_MODULE_PWM_H
18 #define IOTJS_MODULE_PWM_H
20 #include "iotjs_def.h"
21 #include "iotjs_objectwrap.h"
22 #include "iotjs_reqwrap.h"
36 iotjs_jobjectwrap_t jobjectwrap;
38 #if defined(__linux__)
40 iotjs_string_t device;
41 #elif defined(__NUTTX__)
48 } IOTJS_VALIDATED_STRUCT(iotjs_pwm_t);
51 typedef bool (*pwm_func_ptr)(iotjs_pwm_t*);
58 } iotjs_pwm_reqdata_t;
62 iotjs_reqwrap_t reqwrap;
64 iotjs_pwm_reqdata_t req_data;
65 iotjs_pwm_t* pwm_instance;
66 } IOTJS_VALIDATED_STRUCT(iotjs_pwm_reqwrap_t);
69 #define THIS iotjs_pwm_reqwrap_t* pwm_reqwrap
71 iotjs_pwm_reqwrap_t* iotjs_pwm_reqwrap_from_request(uv_work_t* req);
72 iotjs_pwm_reqdata_t* iotjs_pwm_reqwrap_data(THIS);
74 iotjs_pwm_t* iotjs_pwm_instance_from_reqwrap(THIS);
79 #define PWM_WORKER_INIT \
80 iotjs_pwm_reqwrap_t* req_wrap = iotjs_pwm_reqwrap_from_request(work_req); \
81 iotjs_pwm_reqdata_t* req_data = iotjs_pwm_reqwrap_data(req_wrap); \
82 iotjs_pwm_t* pwm = iotjs_pwm_instance_from_reqwrap(req_wrap);
85 void iotjs_pwm_open_worker(uv_work_t* work_req);
87 bool iotjs_pwm_set_period(iotjs_pwm_t* pwm);
88 bool iotjs_pwm_set_dutycycle(iotjs_pwm_t* pwm);
89 bool iotjs_pwm_set_enable(iotjs_pwm_t* pwm);
90 bool iotjs_pwm_close(iotjs_pwm_t* pwm);
93 #endif /* IOTJS_MODULE_PWM_H */