expand16  2.1.0.0
expand16.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 EXPAND16_H
29 #define EXPAND16_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 EXPAND16_REG_DEV_ID_AND_CTRL 0x01
74 #define EXPAND16_REG_IO_DIRECTION 0x03
75 #define EXPAND16_REG_OUTPUT_STATE 0x05
76 #define EXPAND16_REG_OUTPUT_HIGH_Z 0x07
77 #define EXPAND16_REG_INPUT_DEF_STATE 0x09
78 #define EXPAND16_REG_PULL_ENABLE 0x0B
79 #define EXPAND16_REG_PULL_DOWN_UP 0x0D
80 #define EXPAND16_REG_INPUT_STATE 0x0F
81 #define EXPAND16_REG_INTERRUPT_MASK 0x11
82 #define EXPAND16_REG_INTERRUPT_STATUS 0x13
83  // expand16_reg
85 
100 #define EXPAND16_PIN_MASK_NONE 0x00
101 #define EXPAND16_PIN_MASK_GPIO_0 0x01
102 #define EXPAND16_PIN_MASK_GPIO_1 0x02
103 #define EXPAND16_PIN_MASK_GPIO_2 0x04
104 #define EXPAND16_PIN_MASK_GPIO_3 0x08
105 #define EXPAND16_PIN_MASK_GPIO_4 0x10
106 #define EXPAND16_PIN_MASK_GPIO_5 0x20
107 #define EXPAND16_PIN_MASK_GPIO_6 0x40
108 #define EXPAND16_PIN_MASK_GPIO_7 0x80
109 #define EXPAND16_PIN_MASK_ALL 0xFF
110 
115 #define EXPAND16_SW_RESET_CMD 0x01
116 
121 #define EXPAND16_DEVICE_ID 0xA0
122 #define EXPAND16_DEVICE_ID_MASK 0xE0
123 
128 #define EXPAND16_PIN_STATE_HIGH 0x01
129 #define EXPAND16_PIN_STATE_LOW 0x00
130 
136 #define EXPAND16_DEVICE_ADDRESS_GND 0x43
137 #define EXPAND16_DEVICE_ADDRESS_VCC 0x44
138  // expand16_set
140 
155 #define EXPAND16_MAP_MIKROBUS( cfg, mikrobus ) \
156  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
157  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
158  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
159  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
160  // expand16_map // expand16
163 
168 typedef struct
169 {
170  // Output pins
171  digital_out_t rst;
173  // Input pins
174  digital_in_t int_pin;
176  // Modules
177  i2c_master_t i2c;
179  // I2C slave address
180  uint8_t slave_address;
182 } expand16_t;
183 
188 typedef struct
189 {
190  pin_name_t scl;
191  pin_name_t sda;
193  pin_name_t rst;
194  pin_name_t int_pin;
196  uint32_t i2c_speed;
197  uint8_t i2c_address;
200 
205 typedef enum
206 {
208  EXPAND16_ERROR = -1
209 
211 
228 
243 
257 
272 err_t expand16_generic_write ( expand16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
273 
288 err_t expand16_generic_read ( expand16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
289 
299 void expand16_set_rst_pin ( expand16_t *ctx, uint8_t pin_state );
300 
310 
320 
333 err_t expand16_write_reg ( expand16_t *ctx, uint8_t reg, uint8_t data_in );
334 
347 err_t expand16_read_reg ( expand16_t *ctx, uint8_t reg, uint8_t *data_out );
348 
361 err_t expand16_set_io_dir ( expand16_t *ctx, uint8_t input_pins, uint8_t output_pins );
362 
375 err_t expand16_set_output_state ( expand16_t *ctx, uint8_t clr_mask, uint8_t set_mask );
376 
377 #ifdef __cplusplus
378 }
379 #endif
380 #endif // EXPAND16_H
381  // expand16
383 
384 // ------------------------------------------------------------------------ END
expand16_write_reg
err_t expand16_write_reg(expand16_t *ctx, uint8_t reg, uint8_t data_in)
Expand 16 register write function.
expand16_t::i2c
i2c_master_t i2c
Definition: expand16.h:177
expand16_default_cfg
err_t expand16_default_cfg(expand16_t *ctx)
Expand 16 default configuration function.
expand16_init
err_t expand16_init(expand16_t *ctx, expand16_cfg_t *cfg)
Expand 16 initialization function.
expand16_cfg_setup
void expand16_cfg_setup(expand16_cfg_t *cfg)
Expand 16 configuration object setup function.
expand16_generic_read
err_t expand16_generic_read(expand16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Expand 16 I2C reading function.
expand16_return_value_t
expand16_return_value_t
Expand 16 Click return value data.
Definition: expand16.h:206
expand16_set_output_state
err_t expand16_set_output_state(expand16_t *ctx, uint8_t clr_mask, uint8_t set_mask)
Expand 16 set output pins state function.
EXPAND16_ERROR
@ EXPAND16_ERROR
Definition: expand16.h:208
expand16_cfg_t::int_pin
pin_name_t int_pin
Definition: expand16.h:194
expand16_hw_reset
void expand16_hw_reset(expand16_t *ctx)
Expand 16 Hardware reset function.
expand16_cfg_t::rst
pin_name_t rst
Definition: expand16.h:193
expand16_cfg_t::sda
pin_name_t sda
Definition: expand16.h:191
expand16_generic_write
err_t expand16_generic_write(expand16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Expand 16 I2C writing function.
expand16_cfg_t
Expand 16 Click configuration object.
Definition: expand16.h:189
expand16_t::slave_address
uint8_t slave_address
Definition: expand16.h:180
expand16_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand16.h:197
expand16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand16.h:196
expand16_cfg_t::scl
pin_name_t scl
Definition: expand16.h:190
expand16_read_reg
err_t expand16_read_reg(expand16_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 16 register read function.
EXPAND16_OK
@ EXPAND16_OK
Definition: expand16.h:207
expand16_t
Expand 16 Click context object.
Definition: expand16.h:169
expand16_set_rst_pin
void expand16_set_rst_pin(expand16_t *ctx, uint8_t pin_state)
Expand 16 set RST pin state function.
expand16_t::rst
digital_out_t rst
Definition: expand16.h:171
expand16_set_io_dir
err_t expand16_set_io_dir(expand16_t *ctx, uint8_t input_pins, uint8_t output_pins)
Expand 16 set pin input or output direction function.
expand16_t::int_pin
digital_in_t int_pin
Definition: expand16.h:174
expand16_get_int_pin
uint8_t expand16_get_int_pin(expand16_t *ctx)
Expand 16 get INT pin function.