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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define USBTOI2C2_CMD_SOFT_RESET 0x06
60 #define USBTOI2C2_CMD_FLUSH_DATA 0x0E
61 
67 #define USBTOI2C2_GENERAL_CALL_ADDRESS 0x00
68 #define USBTOI2C2_DEVICE_SLAVE_ADDRESS 0x22
69  // usbtoi2c2_set
71 
86 #define USBTOI2C2_MAP_MIKROBUS( cfg, mikrobus ) \
87  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
88  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
89  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
90  cfg.tx_ind = MIKROBUS( mikrobus, MIKROBUS_AN ); \
91  cfg.rx_ind = MIKROBUS( mikrobus, MIKROBUS_INT )
92  // usbtoi2c2_map // usbtoi2c2
95 
100 typedef struct
101 {
102  // Output pins
103  digital_out_t rst;
105  // Input pins
106  digital_in_t tx_ind;
107  digital_in_t rx_ind;
109  // Modules
110  i2c_master_t i2c;
112  // I2C slave address
113  uint8_t slave_address;
115 } usbtoi2c2_t;
116 
121 typedef struct
122 {
123  pin_name_t scl;
124  pin_name_t sda;
126  pin_name_t rst;
128  pin_name_t tx_ind;
129  pin_name_t rx_ind;
131  uint32_t i2c_speed;
132  uint8_t i2c_address;
135 
140 typedef enum
141 {
143  USBTOI2C2_ERROR = -1
144 
146 
163 
179 
194 
207 err_t usbtoi2c2_write_data ( usbtoi2c2_t *ctx, uint8_t *tx_buf, uint8_t tx_len );
208 
221 err_t usbtoi2c2_read_data ( usbtoi2c2_t *ctx, uint8_t *rx_buf, uint8_t rx_len );
222 
232 
244 
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 #endif // USBTOI2C2_H
261  // usbtoi2c2
263 
264 // ------------------------------------------------------------------------ END
usbtoi2c2_return_value_t
usbtoi2c2_return_value_t
USB to I2C 2 Click return value data.
Definition: usbtoi2c2.h:141
usbtoi2c2_cfg_t::tx_ind
pin_name_t tx_ind
Definition: usbtoi2c2.h:128
usbtoi2c2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: usbtoi2c2.h:131
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:101
usbtoi2c2_cfg_t
USB to I2C 2 Click configuration object.
Definition: usbtoi2c2.h:122
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:110
usbtoi2c2_cfg_t::rst
pin_name_t rst
Definition: usbtoi2c2.h:126
usbtoi2c2_cfg_t::i2c_address
uint8_t i2c_address
Definition: usbtoi2c2.h:132
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:107
usbtoi2c2_t::rst
digital_out_t rst
Definition: usbtoi2c2.h:103
usbtoi2c2_cfg_t::rx_ind
pin_name_t rx_ind
Definition: usbtoi2c2.h:129
usbtoi2c2_cfg_t::sda
pin_name_t sda
Definition: usbtoi2c2.h:124
usbtoi2c2_t::tx_ind
digital_in_t tx_ind
Definition: usbtoi2c2.h:106
usbtoi2c2_t::slave_address
uint8_t slave_address
Definition: usbtoi2c2.h:113
USBTOI2C2_OK
@ USBTOI2C2_OK
Definition: usbtoi2c2.h:142
usbtoi2c2_cfg_t::scl
pin_name_t scl
Definition: usbtoi2c2.h:123
USBTOI2C2_ERROR
@ USBTOI2C2_ERROR
Definition: usbtoi2c2.h:143
usbtoi2c2_init
err_t usbtoi2c2_init(usbtoi2c2_t *ctx, usbtoi2c2_cfg_t *cfg)
USB to I2C 2 initialization function.