expand17  2.1.0.0
expand17.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 EXPAND17_H
29 #define EXPAND17_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 EXPAND17_REG_INPUT_PORT 0x00
74 #define EXPAND17_REG_OUTPUT_PORT 0x01
75 #define EXPAND17_REG_POLARITY_INVERSION 0x02
76 #define EXPAND17_REG_CONFIGURATION 0x03
77 #define EXPAND17_REG_OUTPUT_STRENGTH_0 0x40
78 #define EXPAND17_REG_OUTPUT_STRENGTH_1 0x41
79 #define EXPAND17_REG_INPUT_LATCH 0x42
80 #define EXPAND17_REG_PULL_UP_DOWN_EN 0x43
81 #define EXPAND17_REG_PULL_UP_DOWN_SELECT 0x44
82 #define EXPAND17_REG_INTERRUPT_MASK 0x45
83 #define EXPAND17_REG_INTERRUPT_STATUS 0x46
84 #define EXPAND17_REG_OUTPUT_PORT_CFG 0x4F
85  // expand17_reg
87 
102 #define EXPAND17_IO_1_PIN_MASK 0x01
103 #define EXPAND17_IO_2_PIN_MASK 0x02
104 #define EXPAND17_IO_3_PIN_MASK 0x04
105 #define EXPAND17_IO_4_PIN_MASK 0x08
106 #define EXPAND17_IO_5_PIN_MASK 0x10
107 #define EXPAND17_IO_6_PIN_MASK 0x20
108 #define EXPAND17_IO_7_PIN_MASK 0x40
109 #define EXPAND17_IO_8_PIN_MASK 0x80
110 #define EXPAND17_ALL_IO_PIN_MASK 0xFF
111 #define EXPAND17_NO_IO_PIN_MASK 0x00
112 
117 #define EXPAND17_OUTPUT_STRENGTH_FULL 0x03
118 #define EXPAND17_OUTPUT_STRENGTH_3_QUARTERS 0x02
119 #define EXPAND17_OUTPUT_STRENGTH_HALF 0x01
120 #define EXPAND17_OUTPUT_STRENGTH_1_QUARTER 0x00
121 
126 #define EXPAND17_PORT_PUSH_PULL 0x00
127 #define EXPAND17_PORT_OPEN_DRAIN 0x01
128 
133 #define EXPAND17_PIN_STATE_HIGH 0x01
134 #define EXPAND17_PIN_STATE_LOW 0x00
135 
141 #define EXPAND17_DEVICE_ADDRESS_0 0x20
142 #define EXPAND17_DEVICE_ADDRESS_1 0x21
143  // expand17_set
145 
160 #define EXPAND17_MAP_MIKROBUS( cfg, mikrobus ) \
161  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
162  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
163  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
164  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
165  // expand17_map // expand17
168 
173 typedef struct
174 {
175  // Output pins
176  digital_out_t rst;
178  // Input pins
179  digital_in_t int_pin;
181  // Modules
182  i2c_master_t i2c;
184  // I2C slave address
185  uint8_t slave_address;
187 } expand17_t;
188 
193 typedef struct
194 {
195  pin_name_t scl;
196  pin_name_t sda;
198  pin_name_t rst;
199  pin_name_t int_pin;
201  uint32_t i2c_speed;
202  uint8_t i2c_address;
205 
210 typedef enum
211 {
213  EXPAND17_ERROR = -1
214 
216 
233 
248 
262 
277 err_t expand17_generic_write ( expand17_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
278 
293 err_t expand17_generic_read ( expand17_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
294 
305 void expand17_set_rst_pin ( expand17_t *ctx, uint8_t pin_state );
306 
317 
328 
341 err_t expand17_set_io_dir ( expand17_t *ctx, uint8_t input_pins, uint8_t output_pins );
342 
355 err_t expand17_set_output_state ( expand17_t *ctx, uint8_t clr_mask, uint8_t set_mask );
356 
368 err_t expand17_get_input_state ( expand17_t *ctx, uint8_t *input_state );
369 
370 #ifdef __cplusplus
371 }
372 #endif
373 #endif // EXPAND17_H
374  // expand17
376 
377 // ------------------------------------------------------------------------ END
expand17_t
Expand 17 Click context object.
Definition: expand17.h:174
expand17_t::i2c
i2c_master_t i2c
Definition: expand17.h:182
expand17_cfg_setup
void expand17_cfg_setup(expand17_cfg_t *cfg)
Expand 17 configuration object setup function.
expand17_cfg_t::rst
pin_name_t rst
Definition: expand17.h:198
expand17_init
err_t expand17_init(expand17_t *ctx, expand17_cfg_t *cfg)
Expand 17 initialization function.
expand17_set_io_dir
err_t expand17_set_io_dir(expand17_t *ctx, uint8_t input_pins, uint8_t output_pins)
Expand 17 set pin input or output direction function.
expand17_generic_read
err_t expand17_generic_read(expand17_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Expand 17 I2C reading function.
expand17_default_cfg
err_t expand17_default_cfg(expand17_t *ctx)
Expand 17 default configuration function.
EXPAND17_OK
@ EXPAND17_OK
Definition: expand17.h:212
expand17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand17.h:201
expand17_return_value_t
expand17_return_value_t
Expand 17 Click return value data.
Definition: expand17.h:211
expand17_t::slave_address
uint8_t slave_address
Definition: expand17.h:185
expand17_cfg_t::int_pin
pin_name_t int_pin
Definition: expand17.h:199
expand17_get_input_state
err_t expand17_get_input_state(expand17_t *ctx, uint8_t *input_state)
Expand 17 get input pins state function.
EXPAND17_ERROR
@ EXPAND17_ERROR
Definition: expand17.h:213
expand17_get_int_pin
uint8_t expand17_get_int_pin(expand17_t *ctx)
Expand 17 get interrupt pin state function.
expand17_hw_reset
void expand17_hw_reset(expand17_t *ctx)
Expand 17 hardware reset function.
expand17_cfg_t::scl
pin_name_t scl
Definition: expand17.h:195
expand17_set_output_state
err_t expand17_set_output_state(expand17_t *ctx, uint8_t clr_mask, uint8_t set_mask)
Expand 17 set output pins state function.
expand17_cfg_t::sda
pin_name_t sda
Definition: expand17.h:196
expand17_t::rst
digital_out_t rst
Definition: expand17.h:176
expand17_set_rst_pin
void expand17_set_rst_pin(expand17_t *ctx, uint8_t pin_state)
Expand 17 set reset pin state function.
expand17_cfg_t
Expand 17 Click configuration object.
Definition: expand17.h:194
expand17_generic_write
err_t expand17_generic_write(expand17_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Expand 17 I2C writing function.
expand17_t::int_pin
digital_in_t int_pin
Definition: expand17.h:179
expand17_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand17.h:202