MAX32665 SDK Documentation  0.2
Software Development Kit Overview and API Documentation
i2c.h
1 
6 /* ****************************************************************************
7  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
23  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Except as contained in this notice, the name of Maxim Integrated
28  * Products, Inc. shall not be used except as stated in the Maxim Integrated
29  * Products, Inc. Branding Policy.
30  *
31  * The mere transfer of this software does not imply any licenses
32  * of trade secrets, proprietary technology, copyrights, patents,
33  * trademarks, maskwork rights, or any other form of intellectual
34  * property whatsoever. Maxim Integrated Products, Inc. retains all
35  * ownership rights.
36  *
37  * $Date: 2019-07-01 10:18:20 -0500 (Mon, 01 Jul 2019) $
38  * $Revision: 44374 $
39  *
40  *************************************************************************** */
41 
42 #ifndef _I2C_H_
43 #define _I2C_H_
44 
45 #include <stdint.h>
46 #include "i2c_regs.h"
47 #include "mxc_sys.h"
48 
55 /***** Definitions *****/
56 
58 typedef enum {
59  I2C_STD_MODE = 100000,
60  I2C_FAST_MODE = 400000,
61  I2C_FASTPLUS_MODE = 1000000,
62  I2C_HS_MODE = 3400000
63 } i2c_speed_t;
64 
65 //State for Master
66 typedef enum {
67  I2C_STATE_READING = 0,
68  I2C_STATE_WRITING = 1
69 } i2c_state_t;
70 
71 // @brief Enable/Disable TXFIFO Autoflush mode
72 typedef enum {
73  I2C_AUTOFLUSH_ENABLE = 0,
74  I2C_AUTOFLUSH_DISABLE = 1
75 } i2c_autoflush_disable_t;
76 
77 // @brief I2C Transaction request.
78 typedef struct i2c_req i2c_req_t;
79 struct i2c_req {
80 
81  uint8_t addr;
87  const uint8_t *tx_data;
88  uint8_t *rx_data;
89  unsigned tx_len;
90  unsigned rx_len;
91  unsigned tx_num;
92  unsigned rx_num;
93  i2c_state_t state;
94 
99  int restart;
105  i2c_autoflush_disable_t sw_autoflush_disable;
106 
112  void (*callback)(i2c_req_t*, int);
113 };
114 
115 /***** Function Prototypes *****/
116 
125 int I2C_Init(mxc_i2c_regs_t * i2c, i2c_speed_t i2cspeed, const sys_cfg_i2c_t* sys_cfg);
126 
133 int I2C_Shutdown(mxc_i2c_regs_t *i2c);
134 
150 int I2C_MasterWrite(mxc_i2c_regs_t *i2c, uint8_t addr, const uint8_t* data, int len, int restart);
151 
166 int I2C_MasterRead(mxc_i2c_regs_t *i2c, uint8_t addr, uint8_t* data, int len, int restart);
167 
185 int I2C_Slave(mxc_i2c_regs_t *i2c, uint8_t addr, const uint8_t* read_data,
186  int read_len, uint8_t* write_data, int write_len, int* tx_num,
187  int* rx_num, i2c_autoflush_disable_t sw_autoflush_disable);
188 
195 int I2C_MasterAsync(mxc_i2c_regs_t *i2c, i2c_req_t *req);
196 
203 int I2C_SlaveAsync(mxc_i2c_regs_t *i2c, i2c_req_t *req);
212 void I2C_Handler(mxc_i2c_regs_t *i2c);
213 
218 void I2C_DrainRX(mxc_i2c_regs_t *i2c);
219 
224 void I2C_DrainTX(mxc_i2c_regs_t *i2c);
225 
230 int I2C_AbortAsync(i2c_req_t *req);
231 
240 int I2C_SetTimeout(mxc_i2c_regs_t *i2c, int us);
241 
249 #endif /* _I2C_H_ */
void I2C_DrainTX(mxc_i2c_regs_t *i2c)
Drain all of the data in the TXFIFO.
uint8_t addr
Definition: i2c.h:81
uint8_t * rx_data
Data for master read/slave write.
Definition: i2c.h:88
int I2C_SlaveAsync(mxc_i2c_regs_t *i2c, i2c_req_t *req)
Slave Read and Write Asynchronous.
int I2C_Init(mxc_i2c_regs_t *i2c, i2c_speed_t i2cspeed, const sys_cfg_i2c_t *sys_cfg)
Initialize and enable I2C.
void I2C_DrainRX(mxc_i2c_regs_t *i2c)
Drain all of the data in the RXFIFO.
int I2C_Shutdown(mxc_i2c_regs_t *i2c)
Shutdown I2C module.
const uint8_t * tx_data
Data for mater write/slave read.
Definition: i2c.h:87
i2c_state_t state
Read or Write.
Definition: i2c.h:93
void I2C_ClearTimeout(mxc_i2c_regs_t *i2c)
clear and disable timeout
int I2C_MasterAsync(mxc_i2c_regs_t *i2c, i2c_req_t *req)
Master Read and Write Asynchronous.
unsigned rx_num
Number of rx bytes sent.
Definition: i2c.h:92
int I2C_Slave(mxc_i2c_regs_t *i2c, uint8_t addr, const uint8_t *read_data, int read_len, uint8_t *write_data, int write_len, int *tx_num, int *rx_num, i2c_autoflush_disable_t sw_autoflush_disable)
Slave read data.
int I2C_MasterRead(mxc_i2c_regs_t *i2c, uint8_t addr, uint8_t *data, int len, int restart)
Master read data.
i2c_speed_t
I2C Speed Modes.
Definition: i2c.h:58
Structure type to access the I2C Registers.
Definition: i2c_regs.h:88
400KHz Bus Speed
Definition: i2c.h:60
int restart
Definition: i2c.h:99
void I2C_Handler(mxc_i2c_regs_t *i2c)
I2C interrupt handler.
1MHz Bus Speed
Definition: i2c.h:61
i2c_autoflush_disable_t sw_autoflush_disable
Enable/Disable autoflush.
Definition: i2c.h:105
unsigned tx_num
Number of tx bytes sent.
Definition: i2c.h:91
unsigned tx_len
Length of tx data.
Definition: i2c.h:89
Definition: i2c.h:79
int I2C_AbortAsync(i2c_req_t *req)
Abort Async request based on the request you want to abort.
unsigned rx_len
Length of rx.
Definition: i2c.h:90
void(* callback)(i2c_req_t *, int)
Callback for asynchronous request.
Definition: i2c.h:112
int I2C_MasterWrite(mxc_i2c_regs_t *i2c, uint8_t addr, const uint8_t *data, int len, int restart)
Master write data.
3.4MHz Bus Speed
Definition: i2c.h:62
int I2C_SetTimeout(mxc_i2c_regs_t *i2c, int us)
Enable and Set Timeout.
100KHz Bus Speed
Definition: i2c.h:59