• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Winner Microelectronics 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 /****************************************************************************
17  * @file     wm_i2c.h
18  * @author
19  * @version
20  * @date
21  * @brief
22  * @copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
23  *****************************************************************************/
24 
25 #ifndef __WM_I2C_H
26 #define __WM_I2C_H
27 
28 #include "wm_regs.h"
29 #include "wm_type_def.h"
30 #include "wm_cpu.h"
31 #include "wm_irq.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef struct {
38     __IO uint32_t PRER_LO;
39     __IO uint32_t PRER_HI;
40     __IO uint32_t CTRL;
41     __O  uint32_t TX_RX;
42     __O  uint32_t CR_SR;
43     __I  uint32_t TXR;
44     __I  uint32_t CR;
45 }I2C_T;
46 #define I2C		((I2C_T *)(HR_I2C_BASE_ADDR))
47 
48 /**
49  * @defgroup Driver_APIs Driver APIs
50  * @brief Driver APIs
51  */
52 
53 /**
54  * @addtogroup Driver_APIs
55  * @{
56  */
57 
58 /**
59  * @defgroup I2C_Driver_APIs I2C Driver APIs
60  * @brief I2C driver APIs
61  */
62 
63 /**
64  * @addtogroup I2C_Driver_APIs
65  * @{
66  */
67 
68 /**
69  * @brief	Init the I2C module
70  * @param freq   I2C reference clock frequency in Hz that will be used
71  * @note
72  *   the value must be between 100k and 400k
73  */
74 void tls_i2c_init(u32 freq);
75 
76 /** I2C initialization mask */
77 #define  wm_i2c_int_mask(bl)   do { tls_bitband_write(HR_I2C_CTRL, 6, bl);}while (0)
78 
79 /**
80  * @brief	send stop signal
81  *
82  */
83 void tls_i2c_stop(void);
84 
85 /**
86  * @brief	Waiting for ack signal
87  * @retval
88  *	- \ref WM_FAILED
89  *	- \ref WM_SUCCESS
90  */
91 int tls_i2c_wait_ack(void);
92 
93 /**
94  * @brief	Writes the data to data register of I2C module
95  * when ifstart one the start signal will be sent followed by the data
96  * when ifstart zero only the data will be send
97  * @param[in] data	the data will be write to the data register of I2C module
98  * @param[in] ifstart	when one send start signal, when zero don't
99  * @retval
100  *
101  */
102 void tls_i2c_write_byte(u8 data, u8 ifstart);
103 
104 /**
105  * @brief	Get the data stored in data register of I2C module
106  * @param[in] ifack	when one send ack after reading the data register,when zero don't
107  * @param[in] ifstop	when one send stop signal after read, when zero do not send stop
108  * @retval
109  *	the received data
110  */
111 u8 tls_i2c_read_byte(u8 ifack, u8 ifstop);
112 
113 /**
114  * @brief          This function is used to register i2c transfer done callback function.
115  * @param[in]      done  is the i2c transfer done callback function.
116  * @retval         None
117  * @note           None
118  */
119 void wm_i2c_transfer_done_register(void (*done)(void));
120 
121 /**
122  * @brief	Start writing through int mode
123  * @param[in] devaddr	the device address
124  * @param[in] wordaddr when one send stop signal after read, when zero do not send stop
125  * @param[in] buf	the address point where data shoule be stored
126  * @param[in] len	the length of data will be received
127  * @retval
128  *	- \ref WM_FAILED
129  *	- \ref WM_SUCCESS
130  */
131 int wm_i2c_start_write_it(uint8_t devaddr, uint8_t wordaddr, uint8_t *buf, uint16_t len);
132 
133 /**
134  * @brief	Get the data stored in data register of I2C module
135  * @param[in] ifack	when one send ack after reading the data register,when zero don't
136  * @param[in] ifstop when one send stop signal after read, when zero do not send stop
137  * @retval	the received data
138  */
139 int wm_i2c_start_read_it(uint8_t devaddr, uint8_t wordaddr, uint8_t *buf, uint16_t len);
140 /**
141  * @}
142  */
143 
144 /**
145  * @}
146  */
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
152 #endif
153 
154 /*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/
155