expand14  2.0.0.0
expand14.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 EXPAND14_H
29 #define EXPAND14_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 EXPAND14_REG_INPUT_PORT_0 0x00
60 #define EXPAND14_REG_INPUT_PORT_1 0x01
61 #define EXPAND14_REG_OUTPUT_PORT_0 0x02
62 #define EXPAND14_REG_OUTPUT_PORT_1 0x03
63 #define EXPAND14_REG_POLARITY_INV_PORT_0 0x04
64 #define EXPAND14_REG_POLARITY_INV_PORT_1 0x05
65 #define EXPAND14_REG_CONFIG_PORT_0 0x06
66 #define EXPAND14_REG_CONFIG_PORT_1 0x07
67  // expand14_reg
69 
84 #define EXPAND14_NO_PIN_MASK 0x00
85 #define EXPAND14_PIN_0_MASK 0x01
86 #define EXPAND14_PIN_1_MASK 0x02
87 #define EXPAND14_PIN_2_MASK 0x04
88 #define EXPAND14_PIN_3_MASK 0x08
89 #define EXPAND14_PIN_4_MASK 0x10
90 #define EXPAND14_PIN_5_MASK 0x20
91 #define EXPAND14_PIN_6_MASK 0x40
92 #define EXPAND14_PIN_7_MASK 0x80
93 #define EXPAND14_ALL_PINS_MASK 0xFF
94 
99 #define EXPAND14_PORT_0 0x00
100 #define EXPAND14_PORT_1 0x01
101 
106 #define EXPAND14_OUTPUT_DIRECTION 0x00
107 #define EXPAND14_INPUT_DIRECTION 0x01
108 
113 #define EXPAND14_PIN_LOW_LEVEL 0x00
114 #define EXPAND14_PIN_HIGH_LEVEL 0x01
115 
121 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_000 0x20
122 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_001 0x21
123 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_010 0x22
124 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_011 0x23
125 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_100 0x24
126 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_101 0x25
127 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_110 0x26
128 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_111 0x27
129  // expand14_set
131 
146 #define EXPAND14_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
148  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
149  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
150  // expand14_map // expand14
153 
158 typedef struct
159 {
160  // Input pins
161  digital_in_t int_pin;
163  // Modules
164  i2c_master_t i2c;
166  // I2C slave address
167  uint8_t slave_address;
169 } expand14_t;
170 
175 typedef struct
176 {
177  pin_name_t scl;
178  pin_name_t sda;
180  pin_name_t int_pin;
182  uint32_t i2c_speed;
183  uint8_t i2c_address;
186 
191 typedef enum
192 {
194  EXPAND14_ERROR = -1
195 
197 
214 
229 
243 
258 err_t expand14_generic_write ( expand14_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
259 
274 err_t expand14_generic_read ( expand14_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
275 
288 err_t expand14_write_register ( expand14_t *ctx, uint8_t reg, uint8_t data_in );
289 
302 err_t expand14_read_register ( expand14_t *ctx, uint8_t reg, uint8_t *data_out );
303 
319 err_t expand14_set_pin_direction ( expand14_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask );
320 
333 err_t expand14_set_all_pins_direction ( expand14_t *ctx, uint8_t direction );
334 
346 err_t expand14_set_all_pins_value ( expand14_t *ctx, uint8_t set_mask );
347 
362 err_t expand14_set_pin_value ( expand14_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
363 
377 err_t expand14_read_port_value ( expand14_t *ctx, uint8_t port, uint8_t *data_out );
378 
388 
389 #ifdef __cplusplus
390 }
391 #endif
392 #endif // EXPAND14_H
393  // expand14
395 
396 // ------------------------------------------------------------------------ END
expand14_cfg_t::sda
pin_name_t sda
Definition: expand14.h:178
expand14_return_value_t
expand14_return_value_t
Expand 14 Click return value data.
Definition: expand14.h:192
expand14_t
Expand 14 Click context object.
Definition: expand14.h:159
expand14_get_int_pin
uint8_t expand14_get_int_pin(expand14_t *ctx)
Expand 14 get INT pin function.
expand14_cfg_t::scl
pin_name_t scl
Definition: expand14.h:177
expand14_set_all_pins_value
err_t expand14_set_all_pins_value(expand14_t *ctx, uint8_t set_mask)
Expand 14 set all pins value function.
expand14_cfg_setup
void expand14_cfg_setup(expand14_cfg_t *cfg)
Expand 14 configuration object setup function.
expand14_init
err_t expand14_init(expand14_t *ctx, expand14_cfg_t *cfg)
Expand 14 initialization function.
expand14_write_register
err_t expand14_write_register(expand14_t *ctx, uint8_t reg, uint8_t data_in)
Expand 14 write register function.
EXPAND14_ERROR
@ EXPAND14_ERROR
Definition: expand14.h:194
EXPAND14_OK
@ EXPAND14_OK
Definition: expand14.h:193
expand14_read_port_value
err_t expand14_read_port_value(expand14_t *ctx, uint8_t port, uint8_t *data_out)
Expand 14 read port value function.
expand14_generic_read
err_t expand14_generic_read(expand14_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Expand 14 I2C reading function.
expand14_t::i2c
i2c_master_t i2c
Definition: expand14.h:164
expand14_read_register
err_t expand14_read_register(expand14_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 14 read register function.
expand14_t::int_pin
digital_in_t int_pin
Definition: expand14.h:161
expand14_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand14.h:183
expand14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand14.h:182
expand14_set_all_pins_direction
err_t expand14_set_all_pins_direction(expand14_t *ctx, uint8_t direction)
Expand 14 set all pins direction function.
expand14_generic_write
err_t expand14_generic_write(expand14_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Expand 14 I2C writing function.
expand14_set_pin_value
err_t expand14_set_pin_value(expand14_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask)
Expand 14 set pin value function.
expand14_cfg_t
Expand 14 Click configuration object.
Definition: expand14.h:176
expand14_t::slave_address
uint8_t slave_address
Definition: expand14.h:167
expand14_set_pin_direction
err_t expand14_set_pin_direction(expand14_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask)
Expand 14 set pin direction function.
expand14_cfg_t::int_pin
pin_name_t int_pin
Definition: expand14.h:180
expand14_default_cfg
err_t expand14_default_cfg(expand14_t *ctx)
Expand 14 default configuration function.