1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2017-09-06     ��Ϊ��       first version
9  */
10 
11 
12 // Ӳ��i2c�ӿڵ�ͷ�ļ�
13 
14 #ifndef __OPENLOONGSON_I2C_H
15 #define __OPENLOONGSON_I2C_H
16 
17 
18 
19 // I2C��ʱ��Ƶ��
20 #define LS1C_I2C_CLOCK_DEFAULT              (100000)  // Hz. Ĭ��Ƶ��
21 #define LS1C_I2C_CLOCK_MAX                  (400000)  // Hz, max 400 Kbits/sec
22 
23 
24 // I2Cģ����
25 typedef enum
26 {
27     LS1C_I2C_0 = 0,
28     LS1C_I2C_1,
29     LS1C_I2C_2
30 }ls1c_i2c_t;
31 
32 
33 // I2C���ݴ��䷽��
34 typedef enum
35 {
36     LS1C_I2C_DIRECTION_WRITE = 0,       // ������ӻ�д��Ϣ
37     LS1C_I2C_DIRECTION_READ,            // ������ӻ�����Ϣ
38 }ls1c_i2c_direction_t;
39 
40 
41 // Ӳ��I2C��Ϣ
42 typedef struct
43 {
44     ls1c_i2c_t I2Cx;                    // i2cģ����
45     unsigned long clock;                // i2cʱ��Ƶ�ʣ���λhz
46 }ls1c_i2c_info_t;
47 
48 
49 // I2CӦ��
50 typedef enum
51 {
52     LS1C_I2C_ACK = 0,                   // �յ�Ӧ��
53     LS1C_I2C_NACK = 1,                  // û�յ�Ӧ��
54 }ls1c_i2c_ack_t;
55 
56 
57 // ��������ֵ
58 typedef enum
59 {
60     LS1C_I2C_RET_OK = 0,                // OK
61     LS1C_I2C_RET_TIMEOUT,               // ��ʱ
62 }ls1c_i2c_ret_t;
63 
64 
65 
66 /*
67  * ��ʼ��ָ��i2cģ��
68  * @i2c_info_p ij��i2cģ�����Ϣ
69  */
70 void i2c_init(ls1c_i2c_info_t *i2c_info_p);
71 
72 
73 /*
74  * (�ٷ���һ���ֽ�����֮��)���մӻ����͵�ACK�ź�
75  * @i2c_info_p i2cģ����Ϣ
76  * @ret LS1C_I2C_ACK or LS1C_I2C_NACK
77  */
78 ls1c_i2c_ack_t i2c_receive_ack(ls1c_i2c_info_t *i2c_info_p);
79 
80 
81 /*
82  * ��������
83  * @i2c_info_p i2cģ����Ϣ
84  * @buf ���ݻ���
85  * @len ���������ݵij���
86  */
87 ls1c_i2c_ret_t i2c_receive_data(ls1c_i2c_info_t *i2c_info_p, unsigned char *buf, int len);
88 
89 
90 
91 /*
92  * ����START�źź͵�ַ
93  * @i2c_info_p i2cģ����Ϣ
94  * @slave_addr �ӻ���ַ
95  * @direction ���ݴ��䷽��(����д)
96  */
97 ls1c_i2c_ret_t i2c_send_start_and_addr(ls1c_i2c_info_t *i2c_info_p,
98                                        unsigned char slave_addr,
99                                        ls1c_i2c_direction_t direction);
100 
101 
102 /*
103  * ��������
104  * @i2c_info_p i2cģ����Ϣ
105  * @data �����͵�����
106  * @len ���������ݵij���
107  */
108 ls1c_i2c_ret_t i2c_send_data(ls1c_i2c_info_t *i2c_info_p, unsigned char *data, int len);
109 
110 
111 /*
112  * ����STOP�ź�
113  * @i2c_info_p i2cģ����Ϣ
114  */
115 void i2c_send_stop(ls1c_i2c_info_t *i2c_info_p);
116 
117 
118 
119 #endif
120 
121