expand19  2.1.0.0
expand19.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 EXPAND19_H
29 #define EXPAND19_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 EXPAND19_REG_INPUT_PORT 0x00
74 #define EXPAND19_REG_OUTPUT_PORT 0x01
75 #define EXPAND19_REG_POLARITY_INV 0x02
76 #define EXPAND19_REG_CONFIG 0x03
77 #define EXPAND19_REG_OUTPUT_DRIVE_0 0x40
78 #define EXPAND19_REG_OUTPUT_DRIVE_1 0x41
79 #define EXPAND19_REG_INPUT_LATCH 0x42
80 #define EXPAND19_REG_PULL_ENABLE 0x43
81 #define EXPAND19_REG_PULL_SELECTION 0x44
82 #define EXPAND19_REG_INT_MASK 0x45
83 #define EXPAND19_REG_INT_STATUS 0x46
84 #define EXPAND19_REG_OUTPUT_PORT_CONFIG 0x4F
85  // expand19_reg
87 
102 #define EXPAND19_NO_PIN_MASK 0x00
103 #define EXPAND19_PIN_0_MASK 0x01
104 #define EXPAND19_PIN_1_MASK 0x02
105 #define EXPAND19_PIN_2_MASK 0x04
106 #define EXPAND19_PIN_3_MASK 0x08
107 #define EXPAND19_PIN_4_MASK 0x10
108 #define EXPAND19_PIN_5_MASK 0x20
109 #define EXPAND19_PIN_6_MASK 0x40
110 #define EXPAND19_PIN_7_MASK 0x80
111 #define EXPAND19_ALL_PINS_MASK 0xFF
112 
117 #define EXPAND19_OUTPUT_DIRECTION 0x00
118 #define EXPAND19_INPUT_DIRECTION 0x01
119 
124 #define EXPAND19_PIN_LOW_LEVEL 0x00
125 #define EXPAND19_PIN_HIGH_LEVEL 0x01
126 
132 #define EXPAND19_DEVICE_ADDRESS_A1A0_00 0x70
133 #define EXPAND19_DEVICE_ADDRESS_A1A0_01 0x71
134 #define EXPAND19_DEVICE_ADDRESS_A1A0_10 0x72
135 #define EXPAND19_DEVICE_ADDRESS_A1A0_11 0x73
136  // expand19_set
138 
153 #define EXPAND19_MAP_MIKROBUS( cfg, mikrobus ) \
154  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
155  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
156  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
157  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
158  // expand19_map // expand19
161 
166 typedef struct
167 {
168  // Output pins
169  digital_out_t rst;
171  // Input pins
172  digital_in_t int_pin;
174  // Modules
175  i2c_master_t i2c;
177  // I2C slave address
178  uint8_t slave_address;
180 } expand19_t;
181 
186 typedef struct
187 {
188  pin_name_t scl;
189  pin_name_t sda;
191  pin_name_t rst;
192  pin_name_t int_pin;
194  uint32_t i2c_speed;
195  uint8_t i2c_address;
198 
203 typedef enum
204 {
206  EXPAND19_ERROR = -1
207 
209 
226 
241 
255 
268 err_t expand19_write_register ( expand19_t *ctx, uint8_t reg, uint8_t data_in );
269 
282 err_t expand19_read_register ( expand19_t *ctx, uint8_t reg, uint8_t *data_out );
283 
293 void expand19_set_rst_pin ( expand19_t *ctx, uint8_t state );
294 
304 
314 
328 err_t expand19_set_pin_direction ( expand19_t *ctx, uint8_t direction, uint8_t pin_mask );
329 
342 err_t expand19_set_all_pins_direction ( expand19_t *ctx, uint8_t direction );
343 
355 err_t expand19_set_all_pins_value ( expand19_t *ctx, uint8_t set_mask );
356 
369 err_t expand19_set_pin_value ( expand19_t *ctx, uint8_t clr_mask, uint8_t set_mask );
370 
382 err_t expand19_read_port_value ( expand19_t *ctx, uint8_t *data_out );
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 #endif // EXPAND19_H
388  // expand19
390 
391 // ------------------------------------------------------------------------ END
expand19_get_int_pin
uint8_t expand19_get_int_pin(expand19_t *ctx)
Expand 19 get INT pin function.
expand19_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand19.h:195
expand19_cfg_t::int_pin
pin_name_t int_pin
Definition: expand19.h:192
expand19_cfg_setup
void expand19_cfg_setup(expand19_cfg_t *cfg)
Expand 19 configuration object setup function.
EXPAND19_OK
@ EXPAND19_OK
Definition: expand19.h:205
expand19_set_rst_pin
void expand19_set_rst_pin(expand19_t *ctx, uint8_t state)
Expand 19 set RST pin function.
expand19_reset_device
void expand19_reset_device(expand19_t *ctx)
Expand 19 reset device function.
expand19_default_cfg
err_t expand19_default_cfg(expand19_t *ctx)
Expand 19 default configuration function.
expand19_cfg_t::sda
pin_name_t sda
Definition: expand19.h:189
expand19_set_all_pins_value
err_t expand19_set_all_pins_value(expand19_t *ctx, uint8_t set_mask)
Expand 19 set all pins value function.
expand19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand19.h:194
expand19_set_pin_direction
err_t expand19_set_pin_direction(expand19_t *ctx, uint8_t direction, uint8_t pin_mask)
Expand 19 set pin direction function.
expand19_set_pin_value
err_t expand19_set_pin_value(expand19_t *ctx, uint8_t clr_mask, uint8_t set_mask)
Expand 19 set pin value function.
expand19_write_register
err_t expand19_write_register(expand19_t *ctx, uint8_t reg, uint8_t data_in)
Expand 19 write register function.
expand19_read_port_value
err_t expand19_read_port_value(expand19_t *ctx, uint8_t *data_out)
Expand 19 read port value function.
expand19_read_register
err_t expand19_read_register(expand19_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 19 read register function.
expand19_cfg_t::rst
pin_name_t rst
Definition: expand19.h:191
expand19_set_all_pins_direction
err_t expand19_set_all_pins_direction(expand19_t *ctx, uint8_t direction)
Expand 19 set all pins direction function.
expand19_t::slave_address
uint8_t slave_address
Definition: expand19.h:178
expand19_cfg_t
Expand 19 Click configuration object.
Definition: expand19.h:187
expand19_return_value_t
expand19_return_value_t
Expand 19 Click return value data.
Definition: expand19.h:204
expand19_t::rst
digital_out_t rst
Definition: expand19.h:169
EXPAND19_ERROR
@ EXPAND19_ERROR
Definition: expand19.h:206
expand19_t::i2c
i2c_master_t i2c
Definition: expand19.h:175
expand19_t::int_pin
digital_in_t int_pin
Definition: expand19.h:172
expand19_init
err_t expand19_init(expand19_t *ctx, expand19_cfg_t *cfg)
Expand 19 initialization function.
expand19_cfg_t::scl
pin_name_t scl
Definition: expand19.h:188
expand19_t
Expand 19 Click context object.
Definition: expand19.h:167