• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved.
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
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include "iot_errno.h"
17 #include "iot_i2c.h"
18 #include "lz_hardware.h"
19 
20 #define TEST_ID 0
21 I2cBusIo i2c = {
22     .scl =  {
23         .gpio = GPIO0_PA1,
24         .func = MUX_FUNC3,
25         .type = PULL_NONE,
26         .drv = DRIVE_KEEP,
27         .dir = LZGPIO_DIR_KEEP,
28         .val = LZGPIO_LEVEL_KEEP
29     },
30     .sda =  {
31         .gpio = GPIO0_PA0,
32         .func = MUX_FUNC3,
33         .type = PULL_NONE,
34         .drv = DRIVE_KEEP,
35         .dir = LZGPIO_DIR_KEEP,
36         .val = LZGPIO_LEVEL_KEEP
37     },
38     .id = FUNC_ID_I2C0,
39     .mode = FUNC_MODE_M2,
40 };
41 
IoTI2cWrite(unsigned int id,unsigned short deviceAddr,const unsigned char * data,unsigned int dataLen)42 unsigned int IoTI2cWrite(unsigned int id, unsigned short deviceAddr, const unsigned char *data, unsigned int dataLen)
43 {
44     return LzI2cWrite(TEST_ID, deviceAddr, data, dataLen);
45 }
46 
IoTI2cRead(unsigned int id,unsigned short deviceAddr,unsigned char * data,unsigned int dataLen)47 unsigned int IoTI2cRead(unsigned int id, unsigned short deviceAddr, unsigned char *data, unsigned int dataLen)
48 {
49     return LzI2cRead(TEST_ID, deviceAddr, data, dataLen);
50 }
51 
IoTI2cInit(unsigned int id,unsigned int baudrate)52 unsigned int IoTI2cInit(unsigned int id, unsigned int baudrate)
53 {
54     unsigned int ret = 0;
55 
56     ret = I2cIoInit(i2c);
57     if (ret != 0) {
58         return ret;
59     }
60     return LzI2cInit(TEST_ID, baudrate);
61 }
62 
IoTI2cDeinit(unsigned int id)63 unsigned int IoTI2cDeinit(unsigned int id)
64 {
65     return LzI2cDeinit(TEST_ID);
66 }
67 
IoTI2cSetBaudrate(unsigned int id,unsigned int baudrate)68 unsigned int IoTI2cSetBaudrate(unsigned int id, unsigned int baudrate)
69 {
70     return LzI2cSetFreq(TEST_ID, baudrate);
71 }
72