1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #include <stdio.h>
5 #include <string.h>
6 #include <aos/errno.h>
7 #include "aos_hal_i2c.h"
8 
9 #define BUF_LEN 16
10 uint8_t buf[BUF_LEN];
11 
aos_hal_i2c_init(i2c_dev_t * i2c)12 int32_t aos_hal_i2c_init(i2c_dev_t *i2c)
13 {
14     if(NULL == i2c) {
15         printf("parameter is invalid!\n\r");
16         return -1;
17     }
18     memset(buf, 0, BUF_LEN);
19 
20     printf("[%s] freq = %d slave_addr = 0x%X\r\n",
21            __FUNCTION__, i2c->config.freq, i2c->config.dev_addr);
22     return 0;
23 }
24 
aos_hal_i2c_master_send(i2c_dev_t * i2c,uint16_t dev_addr,const uint8_t * data,uint16_t size,uint32_t timeout)25 int32_t aos_hal_i2c_master_send(i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data,
26                             uint16_t size, uint32_t timeout)
27 {
28     uint32_t i;
29     printf("[%s] \r\n", __FUNCTION__);
30 
31     for (i = 0; i < size; i++) {
32         buf[i] = data[i];
33         printf("[%d] 0x%x \r\n", i, buf[i]);
34     }
35     return 0;
36 }
37 
aos_hal_i2c_master_recv(i2c_dev_t * i2c,uint16_t dev_addr,uint8_t * data,uint16_t size,uint32_t timeout)38 int32_t aos_hal_i2c_master_recv(i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data,
39                             uint16_t size, uint32_t timeout)
40 {
41     uint32_t i;
42     printf("[%s] \r\n", __FUNCTION__);
43 
44     for (i = 0; i < size; i++) {
45         data[i] = buf[i];
46         printf("[%d] 0x%x \r\n", i, data[i]);
47     }
48     return 0;
49 }
50 
aos_hal_i2c_slave_send(i2c_dev_t * i2c,const uint8_t * data,uint16_t size,uint32_t timeout)51 int32_t aos_hal_i2c_slave_send(i2c_dev_t *i2c, const uint8_t *data, uint16_t size, uint32_t timeout)
52 {
53     printf("[%s] \r\n", __FUNCTION__);
54     return 0;
55 }
56 
aos_hal_i2c_slave_recv(i2c_dev_t * i2c,uint8_t * data,uint16_t size,uint32_t timeout)57 int32_t aos_hal_i2c_slave_recv(i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout)
58 {
59     printf("[%s] \r\n", __FUNCTION__);
60     return 0;
61 }
62 
aos_hal_i2c_mem_write(i2c_dev_t * i2c,uint16_t dev_addr,uint16_t mem_addr,uint16_t mem_addr_size,const uint8_t * data,uint16_t size,uint32_t timeout)63 int32_t aos_hal_i2c_mem_write(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr,
64                           uint16_t mem_addr_size, const uint8_t *data, uint16_t size,
65                           uint32_t timeout)
66 {
67     uint32_t i;
68 
69     printf("[%s] \r\n", __FUNCTION__);
70 
71     for (i = 0; i < size; i++) {
72         buf[i] = data[i];
73         printf("[%d] 0x%x \r\n", i, buf[i]);
74     }
75     return 0;
76 }
77 
aos_hal_i2c_mem_read(i2c_dev_t * i2c,uint16_t dev_addr,uint16_t mem_addr,uint16_t mem_addr_size,uint8_t * data,uint16_t size,uint32_t timeout)78 int32_t aos_hal_i2c_mem_read(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr,
79                          uint16_t mem_addr_size, uint8_t *data, uint16_t size,
80                          uint32_t timeout)
81 {
82     uint32_t i;
83 
84     printf("[%s] \r\n", __FUNCTION__);
85 
86     for (i = 0; i < size; i++) {
87         data[i] = buf[i];
88         printf("[%d] 0x%x \r\n", i, data[i]);
89     }
90 
91     return 0;
92 }
93 
aos_hal_i2c_finalize(i2c_dev_t * i2c)94 int32_t aos_hal_i2c_finalize(i2c_dev_t *i2c)
95 {
96     printf("[%s] \r\n", __FUNCTION__);
97     return 0;
98 }
99