i2cextend  2.0.0.0
i2cextend.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 I2CEXTEND_H
29 #define I2CEXTEND_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 I2CEXTEND_REG_CONFIG 0x00
60 #define I2CEXTEND_REG_STATUS 0x01
61 #define I2CEXTEND_REG_EVENT 0x02
62 #define I2CEXTEND_REG_ALERT_EN 0x03
63 #define I2CEXTEND_REG_FAULT 0x04
64 #define I2CEXTEND_REG_SCRATCH 0x05
65 #define I2CEXTEND_REG_ADDR_TRANS 0x06
66 #define I2CEXTEND_REG_CTRL 0x07
67 
72 #define C6DOFIMU11_REG_WHO_AM_I 0x00
73 #define C6DOFIMU11_REG_CNTL2 0x3A
74 #define C6DOFIMU11_REG_INC3 0x2C
75 #define C6DOFIMU11_REG_ACCEL_XOUT_L 0x0A
76 #define C6DOFIMU11_REG_ACCEL_YOUT_L 0x0C
77 #define C6DOFIMU11_REG_ACCEL_ZOUT_L 0x0E
78 #define C6DOFIMU11_REG_MAG_XOUT_L 0x10
79 #define C6DOFIMU11_REG_MAG_YOUT_L 0x12
80 #define C6DOFIMU11_REG_MAG_ZOUT_L 0x14
81  // i2cextend_reg
83 
98 #define I2CEXTEND_CONFIG_INTR_MODE_BIT_MASK 0x01
99 #define I2CEXTEND_CONFIG_INTR_MODE_SET_ALERT_PIN 0x00
100 #define I2CEXTEND_CONFIG_INTR_MODE_IGNORE_ARA 0x01
101 #define I2CEXTEND_CONFIG_CTRL_SEL_BIT_MASK 0x02
102 #define I2CEXTEND_CONFIG_CTRL_SEL_MIRRORED_RMT_OUT 0x00
103 #define I2CEXTEND_CONFIG_CTRL_SEL_USE_REG_CTRL_VAL 0x02
104 
109 #define I2CEXTEND_ALERT_EN_LINK_GOOD_DISABLE 0x00
110 #define I2CEXTEND_ALERT_EN_LINK_GOOD 0x01
111 #define I2CEXTEND_ALERT_EN_LINK_LOST_DISABLE 0x00
112 #define I2CEXTEND_ALERT_EN_LINK_LOST 0x02
113 #define I2CEXTEND_ALERT_EN_FAULT_DISABLE 0x00
114 #define I2CEXTEND_ALERT_EN_FAULT 0x04
115 
120 #define I2CEXTEND_CTRL_SEL_L 0x00
121 #define I2CEXTEND_CTRL_SEL_H 0x01
122 
127 #define I2CEXTEND_PIN_STATE_LOW 0x00
128 #define I2CEXTEND_PIN_STATE_HIGH 0x01
129 
134 #define C6DOFIMU11_CNTL2_TEMP_EN_STANDBY_MODE 0x00
135 #define C6DOFIMU11_CNTL2_MAG_EN_STANDBY_MODE 0x00
136 #define C6DOFIMU11_CNTL2_ACCEL_EN_STANDBY_MODE 0x00
137 #define C6DOFIMU11_INC3_IEL2_FIFO_TRIG 0x20
138 #define C6DOFIMU11_INC3_IEL1_FIFO_TRIG 0x02
139 #define C6DOFIMU11_CNTL2_ACCEL_EN_OPERATING_MODE 0x01
140 #define C6DOFIMU11_CNTL2_GSEL_8G 0x00
141 #define C6DOFIMU11_CNTL2_RES_MAX2 0x0C
142 #define C6DOFIMU11_CNTL2_MAG_EN_OPERATING_MODE 0x02
143 #define C6DOFIMU11_WHO_AM_I_WIA_ID 0x2D
144 
150 #define I2CEXTEND_I2C_SLAVE_ADDR_0 0x3E
151 #define I2CEXTEND_I2C_SLAVE_ADDR_1 0x3F
152 #define I2CEXTEND_I2C_SLAVE_ADDR_2 0x76
153 #define I2CEXTEND_I2C_SLAVE_ADDR_3 0x77
154 
160 #define C6DOFIMU11_I2C_SLAVE_ADDRESS_GND 0x0E
161 #define C6DOFIMU11_I2C_SLAVE_ADDRESS_VCC 0x0F
162  // i2cextend_set
164 
179 #define I2CEXTEND_MAP_MIKROBUS( cfg, mikrobus ) \
180  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
181  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
182  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
183  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
184  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
185  // i2cextend_map // i2cextend
188 
193 typedef struct
194 {
195  // Output pins
196  digital_out_t cs;
197  digital_out_t rst;
199  // Input pins
200  digital_in_t int_pin;
202  // Modules
203  i2c_master_t i2c;
205  // I2C slave address
206  uint8_t slave_address;
208 } i2cextend_t;
209 
214 typedef struct
215 {
216  pin_name_t scl;
217  pin_name_t sda;
219  pin_name_t cs;
220  pin_name_t rst;
221  pin_name_t int_pin;
223  uint32_t i2c_speed;
224  uint8_t i2c_address;
227 
232 typedef struct
233 {
234  uint8_t nlink;
235  uint8_t nalert;
236  uint8_t ext_nalert;
237  uint8_t speed_idx;
239 
244 typedef struct
245 {
247  uint8_t link_fault;
248  uint8_t ext_i2c_fault;
251 
256 typedef enum
257 {
259  I2CEXTEND_ERROR = -1
260 
262 
279 
295 
307 void i2cextend_generic_write ( i2cextend_t *ctx, uint8_t reg, uint8_t tx_data );
308 
319 uint8_t i2cextend_generic_read ( i2cextend_t *ctx, uint8_t reg );
320 
333 void i2cextend_rmt_write ( i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg, uint8_t tx_data );
334 
346 uint8_t i2cextend_rmt_read ( i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg );
347 
361 void i2cextend_rmt_multi_write ( i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
362 
376 void i2cextend_rmt_multi_read ( i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
377 
388 void i2cextend_set_config ( i2cextend_t *ctx, uint8_t intr_mode, uint8_t ctrl_sel );
389 
400 
412 void i2cextend_enable_alerts ( i2cextend_t *ctx, uint8_t link_good, uint8_t link_lost, uint8_t fault );
413 
424 
434 
446 void i2cextend_set_out_slave_address ( i2cextend_t *ctx, uint8_t out_slave_address );
447 
457 void i2cextend_set_out_ctrl ( i2cextend_t *ctx, uint8_t out_ctrl );
458 
468 void i2cextend_set_rst ( i2cextend_t *ctx, uint8_t en_rst );
469 
479 void i2cextend_set_cs ( i2cextend_t *ctx, uint8_t en_cs );
480 
490 
491 #ifdef __cplusplus
492 }
493 #endif
494 #endif // I2CEXTEND_H
495  // i2cextend
497 
498 // ------------------------------------------------------------------------ END
i2cextend_status_data_t
I2C Extend Click status data.
Definition: i2cextend.h:233
i2cextend_t::int_pin
digital_in_t int_pin
Definition: i2cextend.h:200
i2cextend_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2cextend.h:223
i2cextend_rmt_multi_read
void i2cextend_rmt_multi_read(i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
Generic multi read data in Remote Mode function.
i2cextend_set_config
void i2cextend_set_config(i2cextend_t *ctx, uint8_t intr_mode, uint8_t ctrl_sel)
Set the configuration function.
i2cextend_set_cs
void i2cextend_set_cs(i2cextend_t *ctx, uint8_t en_cs)
Set CS pin state function.
i2cextend_cfg_t::cs
pin_name_t cs
Definition: i2cextend.h:219
i2cextend_fault_data_t::tx_buf_overflow
uint8_t tx_buf_overflow
Definition: i2cextend.h:249
i2cextend_rmt_read
uint8_t i2cextend_rmt_read(i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg)
Generic read data in Remote Mode function.
i2cextend_status_data_t::nalert
uint8_t nalert
Definition: i2cextend.h:235
i2cextend_init
err_t i2cextend_init(i2cextend_t *ctx, i2cextend_cfg_t *cfg)
I2C Extend initialization function.
i2cextend_rmt_write
void i2cextend_rmt_write(i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg, uint8_t tx_data)
Generic write data in Remote Mode function.
i2cextend_cfg_t::int_pin
pin_name_t int_pin
Definition: i2cextend.h:221
i2cextend_rmt_multi_write
void i2cextend_rmt_multi_write(i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes)
Generic multi write data in Remote Mode function.
i2cextend_status
void i2cextend_status(i2cextend_t *ctx, i2cextend_status_data_t *status_data)
Check the status function.
i2cextend_return_value_t
i2cextend_return_value_t
I2C Extend Click return value data.
Definition: i2cextend.h:257
i2cextend_status_data_t::nlink
uint8_t nlink
Definition: i2cextend.h:234
i2cextend_cfg_t::sda
pin_name_t sda
Definition: i2cextend.h:217
i2cextend_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2cextend.h:224
i2cextend_t::i2c
i2c_master_t i2c
Definition: i2cextend.h:203
i2cextend_cfg_t
I2C Extend Click configuration object.
Definition: i2cextend.h:215
i2cextend_generic_read
uint8_t i2cextend_generic_read(i2cextend_t *ctx, uint8_t reg)
Generic read data function.
i2cextend_t::rst
digital_out_t rst
Definition: i2cextend.h:197
i2cextend_cfg_t::rst
pin_name_t rst
Definition: i2cextend.h:220
i2cextend_enable_alerts
void i2cextend_enable_alerts(i2cextend_t *ctx, uint8_t link_good, uint8_t link_lost, uint8_t fault)
Set enable alerts function.
i2cextend_set_out_slave_address
void i2cextend_set_out_slave_address(i2cextend_t *ctx, uint8_t out_slave_address)
Set out slave address function.
i2cextend_fault_data_t::i2c_write_fault
uint8_t i2c_write_fault
Definition: i2cextend.h:246
i2cextend_status_data_t::ext_nalert
uint8_t ext_nalert
Definition: i2cextend.h:236
i2cextend_t::slave_address
uint8_t slave_address
Definition: i2cextend.h:206
i2cextend_get_scratch
uint8_t i2cextend_get_scratch(i2cextend_t *ctx)
Get scratch function.
i2cextend_fault_data_t
I2C Extend Click fault data.
Definition: i2cextend.h:245
i2cextend_check_int
uint8_t i2cextend_check_int(i2cextend_t *ctx)
Check interrupt ststus function.
i2cextend_set_out_ctrl
void i2cextend_set_out_ctrl(i2cextend_t *ctx, uint8_t out_ctrl)
Set out CTRL function.
i2cextend_t
I2C Extend Click context object.
Definition: i2cextend.h:194
i2cextend_cfg_t::scl
pin_name_t scl
Definition: i2cextend.h:216
i2cextend_generic_write
void i2cextend_generic_write(i2cextend_t *ctx, uint8_t reg, uint8_t tx_data)
Generic write data function.
I2CEXTEND_ERROR
@ I2CEXTEND_ERROR
Definition: i2cextend.h:259
i2cextend_cfg_setup
void i2cextend_cfg_setup(i2cextend_cfg_t *cfg)
I2C Extend configuration object setup function.
i2cextend_status_data_t::speed_idx
uint8_t speed_idx
Definition: i2cextend.h:237
i2cextend_set_rst
void i2cextend_set_rst(i2cextend_t *ctx, uint8_t en_rst)
Set RTS pin state function.
I2CEXTEND_OK
@ I2CEXTEND_OK
Definition: i2cextend.h:258
i2cextend_fault_data_t::ext_i2c_fault
uint8_t ext_i2c_fault
Definition: i2cextend.h:248
i2cextend_t::cs
digital_out_t cs
Definition: i2cextend.h:196
i2cextend_fault_data_t::link_fault
uint8_t link_fault
Definition: i2cextend.h:247
i2cextend_fault
void i2cextend_fault(i2cextend_t *ctx, i2cextend_fault_data_t *fault_data)
Check the fault state function.