1 /* Copyright 2015-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_GPIO_H
18 #define IOTJS_MODULE_GPIO_H
21 #include "iotjs_def.h"
22 #include "iotjs_objectwrap.h"
23 #include "iotjs_reqwrap.h"
54 } iotjs_gpio_reqdata_t;
57 // This Gpio class provides interfaces for GPIO operation.
59 iotjs_jobjectwrap_t jobjectwrap;
61 GpioDirection direction;
63 } IOTJS_VALIDATED_STRUCT(iotjs_gpio_t);
67 iotjs_reqwrap_t reqwrap;
69 iotjs_gpio_reqdata_t req_data;
70 iotjs_gpio_t* gpio_instance;
71 } IOTJS_VALIDATED_STRUCT(iotjs_gpio_reqwrap_t);
74 #define THIS iotjs_gpio_reqwrap_t* gpio_reqwrap
76 iotjs_gpio_reqwrap_t* iotjs_gpio_reqwrap_from_request(uv_work_t* req);
77 iotjs_gpio_reqdata_t* iotjs_gpio_reqwrap_data(THIS);
79 iotjs_gpio_t* iotjs_gpio_instance_from_reqwrap(THIS);
84 #define GPIO_WORKER_INIT() \
85 iotjs_gpio_reqwrap_t* req_wrap = iotjs_gpio_reqwrap_from_request(work_req); \
86 iotjs_gpio_reqdata_t* req_data = iotjs_gpio_reqwrap_data(req_wrap); \
87 iotjs_gpio_t* gpio = iotjs_gpio_instance_from_reqwrap(req_wrap); \
88 IOTJS_VALIDATED_STRUCT_METHOD(iotjs_gpio_t, gpio);
91 void iotjs_gpio_open_worker(uv_work_t* work_req);
92 void iotjs_gpio_write_worker(uv_work_t* work_req);
93 void iotjs_gpio_read_worker(uv_work_t* work_req);
94 void iotjs_gpio_close_worker(uv_work_t* work_req);
95 bool iotjs_gpio_write(int32_t pin, bool value);
96 int iotjs_gpio_read(int32_t pin);
97 bool iotjs_gpio_close(int32_t pin);
99 #endif /* IOTJS_MODULE_GPIO_H */