i2c.h
Go to the documentation of this file.
1 /********************************************************************************************************
2  * @file i2c.h
3  *
4  * @brief This is the header file for TLSR8258
5  *
6  * @author Driver Group
7  * @date May 8, 2018
8  *
9  * @par Copyright (c) 2019, Telink Semiconductor (Shanghai) Co., Ltd.
10  * All rights reserved.
11  *
12  * The information contained herein is confidential property of Telink
13  * Semiconductor (Shanghai) Co., Ltd. and is available under the terms
14  * of Commercial License Agreement between Telink Semiconductor (Shanghai)
15  * Co., Ltd. and the licensee or the terms described here-in. This heading
16  * MUST NOT be removed from this file.
17  *
18  * Licensees are granted free, non-transferable use of the information in this
19  * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
20  * @par History:
21  * 1.initial release(DEC. 26 2018)
22  *
23  * @version A001
24  *
25  *******************************************************************************************************/
26 
27 #pragma once
28 
29 #ifndef I2C_H
30 #define I2C_H
31 #include "gpio.h"
32 
33 
34 #define I2C_SLAVE_DEVICE_NO_START_EN 0
35 
39 typedef enum {
45 
46 
70 typedef enum {
74 
75 
81 static inline void reset_i2c_moudle(void)
82 {
84  reg_rst0 &= (~FLD_RST0_I2C);
85 }
86 
92 static inline void i2c_set_id(unsigned char SlaveID)
93 {
94  reg_i2c_id = SlaveID; //slave address
95 }
96 
102 static inline void i2c_slave_mapping_mode_data_buffer_config(unsigned char * pMapBuf)
103 {
104  reg_i2c_slave_map_addrl = (unsigned char)(((unsigned int)pMapBuf & 0xff)); //
105  reg_i2c_slave_map_addrm = (unsigned char)(((unsigned int)pMapBuf>>8)&0xff);
107 }
113 void i2c_gpio_set(I2C_GPIO_GroupTypeDef i2c_pin_group);
114 
125 void i2c_master_init(unsigned char SlaveID, unsigned char DivClock);
126 
127 
136 void i2c_slave_init(unsigned char device_ID,I2C_SlaveMode mode,unsigned char * pMapBuf);
137 
138 
147 void i2c_write_byte(unsigned int Addr, unsigned int AddrLen, unsigned char Data);
148 
156 unsigned char i2c_read_byte(unsigned int Addr, unsigned int AddrLen);
157 
166 void i2c_write_series(unsigned int Addr, unsigned int AddrLen, unsigned char * dataBuf, int dataLen);
175 void i2c_read_series(unsigned int Addr, unsigned int AddrLen, unsigned char * dataBuf, int dataLen);
176 
177 #endif
178  //end of GP6
Definition: i2c.h:40
Definition: i2c.h:71
#define reg_i2c_id
Definition: register_8258.h:39
void i2c_gpio_set(I2C_GPIO_GroupTypeDef i2c_pin_group)
This function serves to select a pin port for I2C interface.
void i2c_read_series(unsigned int Addr, unsigned int AddrLen, unsigned char *dataBuf, int dataLen)
This function serves to read a packet of data from the specified address of slave device...
#define reg_i2c_slave_map_addrl
Definition: register_8258.h:80
static void i2c_slave_mapping_mode_data_buffer_config(unsigned char *pMapBuf)
This function servers to config i2c data buffer in slave mode.
Definition: i2c.h:102
static void reset_i2c_moudle(void)
This function reset I2C module.
Definition: i2c.h:81
Definition: i2c.h:72
void i2c_slave_init(unsigned char device_ID, I2C_SlaveMode mode, unsigned char *pMapBuf)
This function serves to set the ID and mode of slave device.
Definition: i2c.h:43
static void i2c_set_id(unsigned char SlaveID)
This function serves to set id of I2C module.
Definition: i2c.h:92
#define reg_i2c_slave_map_addrh
Definition: register_8258.h:82
Definition: i2c.h:41
void i2c_master_init(unsigned char SlaveID, unsigned char DivClock)
This function serves to set the id of slave device and the speed of I2C interface note: the param ID ...
unsigned char i2c_read_byte(unsigned int Addr, unsigned int AddrLen)
This function serves to read one byte from the slave device at the specified address.
I2C_GPIO_GroupTypeDef
select pin as SDA and SCL of i2c
Definition: i2c.h:39
#define reg_rst0
Definition: register_8258.h:143
#define reg_i2c_slave_map_addrm
Definition: register_8258.h:81
Definition: i2c.h:42
Definition: register_8258.h:146
I2C_SlaveMode
select i2c slave mode: DMA and MAPPING
Definition: i2c.h:70
void i2c_write_byte(unsigned int Addr, unsigned int AddrLen, unsigned char Data)
This function serves to write one byte to the slave device at the specified address.
void i2c_write_series(unsigned int Addr, unsigned int AddrLen, unsigned char *dataBuf, int dataLen)
This function serves to write a packet of data to the specified address of slave device.