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 
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 I2CEXTEND_REG_CONFIG 0x00
74 #define I2CEXTEND_REG_STATUS 0x01
75 #define I2CEXTEND_REG_EVENT 0x02
76 #define I2CEXTEND_REG_ALERT_EN 0x03
77 #define I2CEXTEND_REG_FAULT 0x04
78 #define I2CEXTEND_REG_SCRATCH 0x05
79 #define I2CEXTEND_REG_ADDR_TRANS 0x06
80 #define I2CEXTEND_REG_CTRL 0x07
81 
86 #define C6DOFIMU11_REG_WHO_AM_I 0x00
87 #define C6DOFIMU11_REG_CNTL2 0x3A
88 #define C6DOFIMU11_REG_INC3 0x2C
89 #define C6DOFIMU11_REG_ACCEL_XOUT_L 0x0A
90 #define C6DOFIMU11_REG_ACCEL_YOUT_L 0x0C
91 #define C6DOFIMU11_REG_ACCEL_ZOUT_L 0x0E
92 #define C6DOFIMU11_REG_MAG_XOUT_L 0x10
93 #define C6DOFIMU11_REG_MAG_YOUT_L 0x12
94 #define C6DOFIMU11_REG_MAG_ZOUT_L 0x14
95  // i2cextend_reg
97 
112 #define I2CEXTEND_CONFIG_INTR_MODE_BIT_MASK 0x01
113 #define I2CEXTEND_CONFIG_INTR_MODE_SET_ALERT_PIN 0x00
114 #define I2CEXTEND_CONFIG_INTR_MODE_IGNORE_ARA 0x01
115 #define I2CEXTEND_CONFIG_CTRL_SEL_BIT_MASK 0x02
116 #define I2CEXTEND_CONFIG_CTRL_SEL_MIRRORED_RMT_OUT 0x00
117 #define I2CEXTEND_CONFIG_CTRL_SEL_USE_REG_CTRL_VAL 0x02
118 
123 #define I2CEXTEND_ALERT_EN_LINK_GOOD_DISABLE 0x00
124 #define I2CEXTEND_ALERT_EN_LINK_GOOD 0x01
125 #define I2CEXTEND_ALERT_EN_LINK_LOST_DISABLE 0x00
126 #define I2CEXTEND_ALERT_EN_LINK_LOST 0x02
127 #define I2CEXTEND_ALERT_EN_FAULT_DISABLE 0x00
128 #define I2CEXTEND_ALERT_EN_FAULT 0x04
129 
134 #define I2CEXTEND_CTRL_SEL_L 0x00
135 #define I2CEXTEND_CTRL_SEL_H 0x01
136 
141 #define I2CEXTEND_PIN_STATE_LOW 0x00
142 #define I2CEXTEND_PIN_STATE_HIGH 0x01
143 
148 #define C6DOFIMU11_CNTL2_TEMP_EN_STANDBY_MODE 0x00
149 #define C6DOFIMU11_CNTL2_MAG_EN_STANDBY_MODE 0x00
150 #define C6DOFIMU11_CNTL2_ACCEL_EN_STANDBY_MODE 0x00
151 #define C6DOFIMU11_INC3_IEL2_FIFO_TRIG 0x20
152 #define C6DOFIMU11_INC3_IEL1_FIFO_TRIG 0x02
153 #define C6DOFIMU11_CNTL2_ACCEL_EN_OPERATING_MODE 0x01
154 #define C6DOFIMU11_CNTL2_GSEL_8G 0x00
155 #define C6DOFIMU11_CNTL2_RES_MAX2 0x0C
156 #define C6DOFIMU11_CNTL2_MAG_EN_OPERATING_MODE 0x02
157 #define C6DOFIMU11_WHO_AM_I_WIA_ID 0x2D
158 
164 #define I2CEXTEND_I2C_SLAVE_ADDR_0 0x3E
165 #define I2CEXTEND_I2C_SLAVE_ADDR_1 0x3F
166 #define I2CEXTEND_I2C_SLAVE_ADDR_2 0x76
167 #define I2CEXTEND_I2C_SLAVE_ADDR_3 0x77
168 
174 #define C6DOFIMU11_I2C_SLAVE_ADDRESS_GND 0x0E
175 #define C6DOFIMU11_I2C_SLAVE_ADDRESS_VCC 0x0F
176  // i2cextend_set
178 
193 #define I2CEXTEND_MAP_MIKROBUS( cfg, mikrobus ) \
194  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
195  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
196  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
197  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
198  cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
199  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
200  // i2cextend_map // i2cextend
203 
208 typedef struct
209 {
210  // Output pins
211  digital_out_t cs;
212  digital_out_t rst;
213  digital_out_t on;
215  // Input pins
216  digital_in_t int_pin;
218  // Modules
219  i2c_master_t i2c;
221  // I2C slave address
222  uint8_t slave_address;
224 } i2cextend_t;
225 
230 typedef struct
231 {
232  pin_name_t scl;
233  pin_name_t sda;
235  pin_name_t cs;
236  pin_name_t rst;
237  pin_name_t on;
238  pin_name_t int_pin;
240  uint32_t i2c_speed;
241  uint8_t i2c_address;
244 
249 typedef struct
250 {
251  uint8_t nlink;
252  uint8_t nalert;
253  uint8_t ext_nalert;
254  uint8_t speed_idx;
256 
261 typedef struct
262 {
264  uint8_t link_fault;
265  uint8_t ext_i2c_fault;
268 
273 typedef enum
274 {
276  I2CEXTEND_ERROR = -1
277 
279 
296 
312 
324 void i2cextend_generic_write ( i2cextend_t *ctx, uint8_t reg, uint8_t tx_data );
325 
336 uint8_t i2cextend_generic_read ( i2cextend_t *ctx, uint8_t reg );
337 
350 void i2cextend_rmt_write ( i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg, uint8_t tx_data );
351 
363 uint8_t i2cextend_rmt_read ( i2cextend_t *ctx, uint8_t rmt_slave_addr, uint8_t reg );
364 
378 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 );
379 
393 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 );
394 
405 void i2cextend_set_config ( i2cextend_t *ctx, uint8_t intr_mode, uint8_t ctrl_sel );
406 
417 
429 void i2cextend_enable_alerts ( i2cextend_t *ctx, uint8_t link_good, uint8_t link_lost, uint8_t fault );
430 
441 
451 
463 void i2cextend_set_out_slave_address ( i2cextend_t *ctx, uint8_t out_slave_address );
464 
474 void i2cextend_set_out_ctrl ( i2cextend_t *ctx, uint8_t out_ctrl );
475 
485 void i2cextend_set_rst ( i2cextend_t *ctx, uint8_t en_rst );
486 
496 void i2cextend_set_cs ( i2cextend_t *ctx, uint8_t en_cs );
497 
507 void i2cextend_set_on ( i2cextend_t *ctx, uint8_t on_state );
508 
518 
519 #ifdef __cplusplus
520 }
521 #endif
522 #endif // I2CEXTEND_H
523  // i2cextend
525 
526 // ------------------------------------------------------------------------ END
i2cextend_cfg_t::on
pin_name_t on
Definition: i2cextend.h:237
i2cextend_status_data_t
I2C Extend Click status data.
Definition: i2cextend.h:250
i2cextend_t::int_pin
digital_in_t int_pin
Definition: i2cextend.h:216
i2cextend_t::on
digital_out_t on
Definition: i2cextend.h:213
i2cextend_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2cextend.h:240
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:235
i2cextend_fault_data_t::tx_buf_overflow
uint8_t tx_buf_overflow
Definition: i2cextend.h:266
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:252
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:238
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:274
i2cextend_status_data_t::nlink
uint8_t nlink
Definition: i2cextend.h:251
i2cextend_cfg_t::sda
pin_name_t sda
Definition: i2cextend.h:233
i2cextend_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2cextend.h:241
i2cextend_t::i2c
i2c_master_t i2c
Definition: i2cextend.h:219
i2cextend_cfg_t
I2C Extend Click configuration object.
Definition: i2cextend.h:231
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:212
i2cextend_set_on
void i2cextend_set_on(i2cextend_t *ctx, uint8_t on_state)
Set ON pin state function.
i2cextend_cfg_t::rst
pin_name_t rst
Definition: i2cextend.h:236
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:263
i2cextend_status_data_t::ext_nalert
uint8_t ext_nalert
Definition: i2cextend.h:253
i2cextend_t::slave_address
uint8_t slave_address
Definition: i2cextend.h:222
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:262
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:209
i2cextend_cfg_t::scl
pin_name_t scl
Definition: i2cextend.h:232
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:276
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:254
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:275
i2cextend_fault_data_t::ext_i2c_fault
uint8_t ext_i2c_fault
Definition: i2cextend.h:265
i2cextend_t::cs
digital_out_t cs
Definition: i2cextend.h:211
i2cextend_fault_data_t::link_fault
uint8_t link_fault
Definition: i2cextend.h:264
i2cextend_fault
void i2cextend_fault(i2cextend_t *ctx, i2cextend_fault_data_t *fault_data)
Check the fault state function.