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_I2C_H
18 #define IOTJS_MODULE_I2C_H
20 #include "iotjs_def.h"
21 #include "iotjs_objectwrap.h"
22 #include "iotjs_reqwrap.h"
24 #if defined(__NUTTX__)
25 #include <nuttx/i2c/i2c_master.h>
44 kI2cErrReadBlock = -3,
50 #if defined(__linux__) || defined(__APPLE__)
51 iotjs_string_t device;
52 #elif defined(__NUTTX__)
63 } iotjs_i2c_reqdata_t;
66 // This I2c class provides interfaces for I2C operation.
68 #if defined(__NUTTX__)
69 struct i2c_master_s* i2c_master;
70 struct i2c_config_s config;
72 iotjs_jobjectwrap_t jobjectwrap;
73 } IOTJS_VALIDATED_STRUCT(iotjs_i2c_t);
77 iotjs_reqwrap_t reqwrap;
79 iotjs_i2c_reqdata_t req_data;
80 iotjs_i2c_t* i2c_data;
81 } IOTJS_VALIDATED_STRUCT(iotjs_i2c_reqwrap_t);
84 iotjs_i2c_t* iotjs_i2c_create(const iotjs_jval_t* ji2c);
85 iotjs_i2c_t* iotjs_i2c_instance_from_jval(const iotjs_jval_t* ji2c);
87 #define THIS iotjs_i2c_reqwrap_t* i2c_reqwrap
88 iotjs_i2c_reqwrap_t* iotjs_i2c_reqwrap_create(const iotjs_jval_t* jcallback,
89 const iotjs_jval_t* ji2c,
91 void iotjs_i2c_reqwrap_dispatched(THIS);
92 uv_work_t* iotjs_i2c_reqwrap_req(THIS);
93 const iotjs_jval_t* iotjs_i2c_reqwrap_jcallback(THIS);
94 iotjs_i2c_reqwrap_t* iotjs_i2c_reqwrap_from_request(uv_work_t* req);
95 iotjs_i2c_reqdata_t* iotjs_i2c_reqwrap_data(THIS);
96 iotjs_i2c_t* iotjs_i2c_instance_from_reqwrap(THIS);
100 void I2cSetAddress(iotjs_i2c_t* i2c, uint8_t address);
101 void OpenWorker(uv_work_t* work_req);
102 void I2cClose(iotjs_i2c_t* i2c);
103 void WriteWorker(uv_work_t* work_req);
104 void WriteByteWorker(uv_work_t* work_req);
105 void WriteBlockWorker(uv_work_t* work_req);
106 void ReadWorker(uv_work_t* work_req);
107 void ReadByteWorker(uv_work_t* work_req);
108 void ReadBlockWorker(uv_work_t* work_req);
111 #endif /* IOTJS_MODULE_I2C_H */