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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define USBTOI2C2_CMD_SOFT_RESET 0x06
70 #define USBTOI2C2_CMD_FLUSH_DATA 0x0E
71 
77 #define USBTOI2C2_GENERAL_CALL_ADDRESS 0x00
78 #define USBTOI2C2_DEVICE_SLAVE_ADDRESS 0x22
79  // usbtoi2c2_set
81 
96 #define USBTOI2C2_MAP_MIKROBUS( cfg, mikrobus ) \
97  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
98  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
99  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
100  cfg.tx_ind = MIKROBUS( mikrobus, MIKROBUS_AN ); \
101  cfg.rx_ind = MIKROBUS( mikrobus, MIKROBUS_INT )
102  // usbtoi2c2_map // usbtoi2c2
105 
110 typedef struct
111 {
112  // Output pins
113  digital_out_t rst;
115  // Input pins
116  digital_in_t tx_ind;
117  digital_in_t rx_ind;
119  // Modules
120  i2c_master_t i2c;
122  // I2C slave address
123  uint8_t slave_address;
125 } usbtoi2c2_t;
126 
131 typedef struct
132 {
133  pin_name_t scl;
134  pin_name_t sda;
136  pin_name_t rst;
138  pin_name_t tx_ind;
139  pin_name_t rx_ind;
141  uint32_t i2c_speed;
142  uint8_t i2c_address;
145 
150 typedef enum
151 {
153  USBTOI2C2_ERROR = -1
154 
156 
173 
189 
204 
217 err_t usbtoi2c2_write_data ( usbtoi2c2_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
218 
231 err_t usbtoi2c2_read_data ( usbtoi2c2_t *ctx, uint8_t *rx_buf, uint8_t rx_len );
232 
242 
254 
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 #endif // USBTOI2C2_H
271  // usbtoi2c2
273 
274 // ------------------------------------------------------------------------ END
usbtoi2c2_return_value_t
usbtoi2c2_return_value_t
USB to I2C 2 Click return value data.
Definition: usbtoi2c2.h:151
usbtoi2c2_cfg_t::tx_ind
pin_name_t tx_ind
Definition: usbtoi2c2.h:138
usbtoi2c2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: usbtoi2c2.h:141
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:111
usbtoi2c2_cfg_t
USB to I2C 2 Click configuration object.
Definition: usbtoi2c2.h:132
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:120
usbtoi2c2_cfg_t::rst
pin_name_t rst
Definition: usbtoi2c2.h:136
usbtoi2c2_cfg_t::i2c_address
uint8_t i2c_address
Definition: usbtoi2c2.h:142
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:117
usbtoi2c2_t::rst
digital_out_t rst
Definition: usbtoi2c2.h:113
usbtoi2c2_cfg_t::rx_ind
pin_name_t rx_ind
Definition: usbtoi2c2.h:139
usbtoi2c2_cfg_t::sda
pin_name_t sda
Definition: usbtoi2c2.h:134
usbtoi2c2_t::tx_ind
digital_in_t tx_ind
Definition: usbtoi2c2.h:116
usbtoi2c2_t::slave_address
uint8_t slave_address
Definition: usbtoi2c2.h:123
USBTOI2C2_OK
@ USBTOI2C2_OK
Definition: usbtoi2c2.h:152
usbtoi2c2_cfg_t::scl
pin_name_t scl
Definition: usbtoi2c2.h:133
USBTOI2C2_ERROR
@ USBTOI2C2_ERROR
Definition: usbtoi2c2.h:153
usbtoi2c2_init
err_t usbtoi2c2_init(usbtoi2c2_t *ctx, usbtoi2c2_cfg_t *cfg)
USB to I2C 2 initialization function.