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
32 extern "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  // 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  // usbtoi2c2_map // usbtoi2c2
109 
114 typedef 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
127  uint8_t slave_address;
129 } usbtoi2c2_t;
130 
135 typedef 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 
154 typedef enum
155 {
157  USBTOI2C2_ERROR = -1
158 
160 
177 
193 
208 
221 err_t usbtoi2c2_write_data ( usbtoi2c2_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
222 
235 err_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  // usbtoi2c2
277 
278 // ------------------------------------------------------------------------ END
usbtoi2c2_return_value_t
usbtoi2c2_return_value_t
USB to I2C 2 Click return value data.
Definition: usbtoi2c2.h:155
usbtoi2c2_cfg_t::tx_ind
pin_name_t tx_ind
Definition: usbtoi2c2.h:142
usbtoi2c2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: usbtoi2c2.h:145
usbtoi2c2_flush_data
err_t usbtoi2c2_flush_data(usbtoi2c2_t *ctx)
USB to I2C 2 flush data function.
usbtoi2c2_cfg_setup
void usbtoi2c2_cfg_setup(usbtoi2c2_cfg_t *cfg)
USB to I2C 2 configuration object setup function.
usbtoi2c2_default_cfg
err_t usbtoi2c2_default_cfg(usbtoi2c2_t *ctx)
USB to I2C 2 default configuration function.
usbtoi2c2_soft_reset
err_t usbtoi2c2_soft_reset(usbtoi2c2_t *ctx)
USB to I2C 2 soft reset function.
usbtoi2c2_t
USB to I2C 2 Click context object.
Definition: usbtoi2c2.h:115
usbtoi2c2_cfg_t
USB to I2C 2 Click configuration object.
Definition: usbtoi2c2.h:136
usbtoi2c2_write_data
err_t usbtoi2c2_write_data(usbtoi2c2_t *ctx, uint8_t *tx_buf, uint8_t tx_len)
USB to I2C 2 write data function.
usbtoi2c2_reset_device
void usbtoi2c2_reset_device(usbtoi2c2_t *ctx)
USB to I2C 2 reset device function.
usbtoi2c2_t::i2c
i2c_master_t i2c
Definition: usbtoi2c2.h:124
usbtoi2c2_cfg_t::rst
pin_name_t rst
Definition: usbtoi2c2.h:140
usbtoi2c2_cfg_t::i2c_address
uint8_t i2c_address
Definition: usbtoi2c2.h:146
usbtoi2c2_read_data
err_t usbtoi2c2_read_data(usbtoi2c2_t *ctx, uint8_t *rx_buf, uint8_t rx_len)
USB to I2C 2 read data function.
usbtoi2c2_t::rx_ind
digital_in_t rx_ind
Definition: usbtoi2c2.h:121
usbtoi2c2_t::rst
digital_out_t rst
Definition: usbtoi2c2.h:117
usbtoi2c2_cfg_t::rx_ind
pin_name_t rx_ind
Definition: usbtoi2c2.h:143
usbtoi2c2_cfg_t::sda
pin_name_t sda
Definition: usbtoi2c2.h:138
usbtoi2c2_t::tx_ind
digital_in_t tx_ind
Definition: usbtoi2c2.h:120
usbtoi2c2_t::slave_address
uint8_t slave_address
Definition: usbtoi2c2.h:127
USBTOI2C2_OK
@ USBTOI2C2_OK
Definition: usbtoi2c2.h:156
usbtoi2c2_cfg_t::scl
pin_name_t scl
Definition: usbtoi2c2.h:137
USBTOI2C2_ERROR
@ USBTOI2C2_ERROR
Definition: usbtoi2c2.h:157
usbtoi2c2_init
err_t usbtoi2c2_init(usbtoi2c2_t *ctx, usbtoi2c2_cfg_t *cfg)
USB to I2C 2 initialization function.