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 
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 EXPAND14_REG_INPUT_PORT_0 0x00
74 #define EXPAND14_REG_INPUT_PORT_1 0x01
75 #define EXPAND14_REG_OUTPUT_PORT_0 0x02
76 #define EXPAND14_REG_OUTPUT_PORT_1 0x03
77 #define EXPAND14_REG_POLARITY_INV_PORT_0 0x04
78 #define EXPAND14_REG_POLARITY_INV_PORT_1 0x05
79 #define EXPAND14_REG_CONFIG_PORT_0 0x06
80 #define EXPAND14_REG_CONFIG_PORT_1 0x07
81  // expand14_reg
83 
98 #define EXPAND14_NO_PIN_MASK 0x00
99 #define EXPAND14_PIN_0_MASK 0x01
100 #define EXPAND14_PIN_1_MASK 0x02
101 #define EXPAND14_PIN_2_MASK 0x04
102 #define EXPAND14_PIN_3_MASK 0x08
103 #define EXPAND14_PIN_4_MASK 0x10
104 #define EXPAND14_PIN_5_MASK 0x20
105 #define EXPAND14_PIN_6_MASK 0x40
106 #define EXPAND14_PIN_7_MASK 0x80
107 #define EXPAND14_ALL_PINS_MASK 0xFF
108 
113 #define EXPAND14_PORT_0 0x00
114 #define EXPAND14_PORT_1 0x01
115 
120 #define EXPAND14_OUTPUT_DIRECTION 0x00
121 #define EXPAND14_INPUT_DIRECTION 0x01
122 
127 #define EXPAND14_PIN_LOW_LEVEL 0x00
128 #define EXPAND14_PIN_HIGH_LEVEL 0x01
129 
135 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_000 0x20
136 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_001 0x21
137 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_010 0x22
138 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_011 0x23
139 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_100 0x24
140 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_101 0x25
141 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_110 0x26
142 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_111 0x27
143  // expand14_set
145 
160 #define EXPAND14_MAP_MIKROBUS( cfg, mikrobus ) \
161  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
162  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
163  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
164  // expand14_map // expand14
167 
172 typedef struct
173 {
174  // Input pins
175  digital_in_t int_pin;
177  // Modules
178  i2c_master_t i2c;
180  // I2C slave address
181  uint8_t slave_address;
183 } expand14_t;
184 
189 typedef struct
190 {
191  pin_name_t scl;
192  pin_name_t sda;
194  pin_name_t int_pin;
196  uint32_t i2c_speed;
197  uint8_t i2c_address;
200 
205 typedef enum
206 {
208  EXPAND14_ERROR = -1
209 
211 
228 
243 
257 
272 err_t expand14_generic_write ( expand14_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
273 
288 err_t expand14_generic_read ( expand14_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
289 
302 err_t expand14_write_register ( expand14_t *ctx, uint8_t reg, uint8_t data_in );
303 
316 err_t expand14_read_register ( expand14_t *ctx, uint8_t reg, uint8_t *data_out );
317 
333 err_t expand14_set_pin_direction ( expand14_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask );
334 
347 err_t expand14_set_all_pins_direction ( expand14_t *ctx, uint8_t direction );
348 
360 err_t expand14_set_all_pins_value ( expand14_t *ctx, uint8_t set_mask );
361 
376 err_t expand14_set_pin_value ( expand14_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
377 
391 err_t expand14_read_port_value ( expand14_t *ctx, uint8_t port, uint8_t *data_out );
392 
402 
403 #ifdef __cplusplus
404 }
405 #endif
406 #endif // EXPAND14_H
407  // expand14
409 
410 // ------------------------------------------------------------------------ END
expand14_cfg_t::sda
pin_name_t sda
Definition: expand14.h:192
expand14_return_value_t
expand14_return_value_t
Expand 14 Click return value data.
Definition: expand14.h:206
expand14_t
Expand 14 Click context object.
Definition: expand14.h:173
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:191
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:208
EXPAND14_OK
@ EXPAND14_OK
Definition: expand14.h:207
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:178
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:175
expand14_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand14.h:197
expand14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand14.h:196
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:190
expand14_t::slave_address
uint8_t slave_address
Definition: expand14.h:181
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:194
expand14_default_cfg
err_t expand14_default_cfg(expand14_t *ctx)
Expand 14 default configuration function.