usbtoi2c2 2.0.0.0
usbtoi2c2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef USBTOI2C2_H
29#define USBTOI2C2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define USBTOI2C2_CMD_SOFT_RESET 0x06
74#define USBTOI2C2_CMD_FLUSH_DATA 0x0E
75
81#define USBTOI2C2_GENERAL_CALL_ADDRESS 0x00
82#define USBTOI2C2_DEVICE_SLAVE_ADDRESS 0x22
83
84 // usbtoi2c2_set
85
100#define USBTOI2C2_MAP_MIKROBUS( cfg, mikrobus ) \
101 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
102 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
103 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
104 cfg.tx_ind = MIKROBUS( mikrobus, MIKROBUS_AN ); \
105 cfg.rx_ind = MIKROBUS( mikrobus, MIKROBUS_INT )
106
107 // usbtoi2c2_map
108 // usbtoi2c2
109
114typedef struct
115{
116 // Output pins
117 digital_out_t rst;
119 // Input pins
120 digital_in_t tx_ind;
121 digital_in_t rx_ind;
123 // Modules
124 i2c_master_t i2c;
126 // I2C slave address
130
135typedef struct
136{
137 pin_name_t scl;
138 pin_name_t sda;
140 pin_name_t rst;
142 pin_name_t tx_ind;
143 pin_name_t rx_ind;
145 uint32_t i2c_speed;
146 uint8_t i2c_address;
149
160
177
193
208
221err_t usbtoi2c2_write_data ( usbtoi2c2_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
222
235err_t usbtoi2c2_read_data ( usbtoi2c2_t *ctx, uint8_t *rx_buf, uint8_t rx_len );
236
246
258
270
271#ifdef __cplusplus
272}
273#endif
274#endif // USBTOI2C2_H
275
276 // usbtoi2c2
277
278// ------------------------------------------------------------------------ END
err_t usbtoi2c2_init(usbtoi2c2_t *ctx, usbtoi2c2_cfg_t *cfg)
USB to I2C 2 initialization function.
err_t usbtoi2c2_write_data(usbtoi2c2_t *ctx, uint8_t *tx_buf, uint8_t tx_len)
USB to I2C 2 write data function.
err_t usbtoi2c2_read_data(usbtoi2c2_t *ctx, uint8_t *rx_buf, uint8_t rx_len)
USB to I2C 2 read data function.
void usbtoi2c2_cfg_setup(usbtoi2c2_cfg_t *cfg)
USB to I2C 2 configuration object setup function.
err_t usbtoi2c2_flush_data(usbtoi2c2_t *ctx)
USB to I2C 2 flush data function.
void usbtoi2c2_reset_device(usbtoi2c2_t *ctx)
USB to I2C 2 reset device function.
err_t usbtoi2c2_default_cfg(usbtoi2c2_t *ctx)
USB to I2C 2 default configuration function.
err_t usbtoi2c2_soft_reset(usbtoi2c2_t *ctx)
USB to I2C 2 soft reset function.
USB to I2C 2 Click configuration object.
Definition usbtoi2c2.h:136
pin_name_t tx_ind
Definition usbtoi2c2.h:142
pin_name_t rx_ind
Definition usbtoi2c2.h:143
uint32_t i2c_speed
Definition usbtoi2c2.h:145
pin_name_t scl
Definition usbtoi2c2.h:137
pin_name_t sda
Definition usbtoi2c2.h:138
pin_name_t rst
Definition usbtoi2c2.h:140
uint8_t i2c_address
Definition usbtoi2c2.h:146
USB to I2C 2 Click context object.
Definition usbtoi2c2.h:115
digital_in_t tx_ind
Definition usbtoi2c2.h:120
digital_in_t rx_ind
Definition usbtoi2c2.h:121
i2c_master_t i2c
Definition usbtoi2c2.h:124
digital_out_t rst
Definition usbtoi2c2.h:117
uint8_t slave_address
Definition usbtoi2c2.h:127
usbtoi2c2_return_value_t
USB to I2C 2 Click return value data.
Definition usbtoi2c2.h:155
@ USBTOI2C2_OK
Definition usbtoi2c2.h:156
@ USBTOI2C2_ERROR
Definition usbtoi2c2.h:157