• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #include "iot_errno.h"
15 #include "iot_i2c.h"
16 
17 #include <stdbool.h>	//extra
18 
19 #include <driver/i2c.h>
20 
21 struct i2c_ctrl {
22 	unsigned int inited;
23 	unsigned int baudrate;
24 };
25 
26 #define I2C_NUM		2
27 
28 static struct i2c_ctrl i2c_ctrls[I2C_NUM] = {
29 	{0, I2C_BAUD_RATE_400KHZ},
30 	{0, I2C_BAUD_RATE_400KHZ},
31 };
32 
IoTI2cWrite(unsigned int id,unsigned short deviceAddr,const unsigned char * data,unsigned int dataLen)33 unsigned int IoTI2cWrite(unsigned int id, unsigned short deviceAddr, const unsigned char *data, unsigned int dataLen)
34 {
35 
36 	if (id > I2C_NUM)
37 		return IOT_FAILURE;
38 
39 	if ((deviceAddr == 0) || (data == NULL) || (dataLen == 0))
40 		return IOT_FAILURE;
41 
42 	if (!i2c_ctrls[id].inited)
43 		return IOT_FAILURE;
44 
45 	//bk_i2c_master_write
46 	return IOT_SUCCESS;
47 }
48 
IoTI2cRead(unsigned int id,unsigned short deviceAddr,unsigned char * data,unsigned int dataLen)49 unsigned int IoTI2cRead(unsigned int id, unsigned short deviceAddr, unsigned char *data, unsigned int dataLen)
50 {
51 	//bk_i2c_master_read
52 	return IOT_FAILURE;
53 }
54 
IoTI2cInit(unsigned int id,unsigned int baudrate)55 unsigned int IoTI2cInit(unsigned int id, unsigned int baudrate)
56 {
57 	return IOT_FAILURE;
58 }
59 
IoTI2cDeinit(unsigned int id)60 unsigned int IoTI2cDeinit(unsigned int id)
61 {
62 	return IOT_FAILURE;
63 }
64 
IoTI2cSetBaudrate(unsigned int id,unsigned int baudrate)65 unsigned int IoTI2cSetBaudrate(unsigned int id, unsigned int baudrate)
66 {
67 	return IOT_FAILURE;
68 }
69