summaryrefslogtreecommitdiff
path: root/bsp/loongson/ls1cdev/libraries/ls1c_i2c.h
blob: 1fb1ef694135d6879ae6102a75ac24bc7c4e6e09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2017-09-06     ����       first version
 */


// Ӳ��i2c�ӿڵ�ͷ�ļ�

#ifndef __OPENLOONGSON_I2C_H
#define __OPENLOONGSON_I2C_H



// I2C��ʱ��Ƶ��
#define LS1C_I2C_CLOCK_DEFAULT              (100000)  // Hz. Ĭ��Ƶ��
#define LS1C_I2C_CLOCK_MAX                  (400000)  // Hz, max 400 Kbits/sec


// I2C���
typedef enum
{
    LS1C_I2C_0 = 0,
    LS1C_I2C_1,
    LS1C_I2C_2
}ls1c_i2c_t;


// I2C���ݴ��䷽��
typedef enum
{
    LS1C_I2C_DIRECTION_WRITE = 0,       // ������ӻ�д��Ϣ
    LS1C_I2C_DIRECTION_READ,            // ������ӻ�����Ϣ
}ls1c_i2c_direction_t;


// Ӳ��I2C��Ϣ
typedef struct
{
    ls1c_i2c_t I2Cx;                    // i2c���
    unsigned long clock;                // i2cʱ��Ƶ�ʣ���λhz
}ls1c_i2c_info_t;


// I2CӦ��
typedef enum
{
    LS1C_I2C_ACK = 0,                   // �յ�Ӧ��
    LS1C_I2C_NACK = 1,                  // û�յ�Ӧ��
}ls1c_i2c_ack_t;


// ��������ֵ
typedef enum
{
    LS1C_I2C_RET_OK = 0,                // OK
    LS1C_I2C_RET_TIMEOUT,               // ��ʱ
}ls1c_i2c_ret_t;



/*
 * ��ʼ��ָ��i2cģ��
 * @i2c_info_p ij��i2cģ�����Ϣ
 */
void i2c_init(ls1c_i2c_info_t *i2c_info_p);


/*
 * (�ٷ���һ���ֽ�����֮��)���մӻ����͵�ACK�ź�
 * @i2c_info_p i2cģ����Ϣ
 * @ret LS1C_I2C_ACK or LS1C_I2C_NACK
 */
ls1c_i2c_ack_t i2c_receive_ack(ls1c_i2c_info_t *i2c_info_p);


/*
 * ��������
 * @i2c_info_p i2cģ����Ϣ
 * @buf ���ݻ���
 * @len ���������ݵij���
 */
ls1c_i2c_ret_t i2c_receive_data(ls1c_i2c_info_t *i2c_info_p, unsigned char *buf, int len);



/*
 * ����START�źź͵�ַ
 * @i2c_info_p i2cģ����Ϣ
 * @slave_addr �ӻ���ַ
 * @direction ���ݴ��䷽��(����д)
 */
ls1c_i2c_ret_t i2c_send_start_and_addr(ls1c_i2c_info_t *i2c_info_p, 
                                       unsigned char slave_addr,
                                       ls1c_i2c_direction_t direction);


/*
 * ��������
 * @i2c_info_p i2cģ����Ϣ
 * @data �����͵�����
 * @len ���������ݵij���
 */
ls1c_i2c_ret_t i2c_send_data(ls1c_i2c_info_t *i2c_info_p, unsigned char *data, int len);


/*
 * ����STOP�ź�
 * @i2c_info_p i2cģ����Ϣ
 */
void i2c_send_stop(ls1c_i2c_info_t *i2c_info_p);



#endif