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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define EXPAND14_REG_INPUT_PORT_0 0x00
70 #define EXPAND14_REG_INPUT_PORT_1 0x01
71 #define EXPAND14_REG_OUTPUT_PORT_0 0x02
72 #define EXPAND14_REG_OUTPUT_PORT_1 0x03
73 #define EXPAND14_REG_POLARITY_INV_PORT_0 0x04
74 #define EXPAND14_REG_POLARITY_INV_PORT_1 0x05
75 #define EXPAND14_REG_CONFIG_PORT_0 0x06
76 #define EXPAND14_REG_CONFIG_PORT_1 0x07
77  // expand14_reg
79 
94 #define EXPAND14_NO_PIN_MASK 0x00
95 #define EXPAND14_PIN_0_MASK 0x01
96 #define EXPAND14_PIN_1_MASK 0x02
97 #define EXPAND14_PIN_2_MASK 0x04
98 #define EXPAND14_PIN_3_MASK 0x08
99 #define EXPAND14_PIN_4_MASK 0x10
100 #define EXPAND14_PIN_5_MASK 0x20
101 #define EXPAND14_PIN_6_MASK 0x40
102 #define EXPAND14_PIN_7_MASK 0x80
103 #define EXPAND14_ALL_PINS_MASK 0xFF
104 
109 #define EXPAND14_PORT_0 0x00
110 #define EXPAND14_PORT_1 0x01
111 
116 #define EXPAND14_OUTPUT_DIRECTION 0x00
117 #define EXPAND14_INPUT_DIRECTION 0x01
118 
123 #define EXPAND14_PIN_LOW_LEVEL 0x00
124 #define EXPAND14_PIN_HIGH_LEVEL 0x01
125 
131 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_000 0x20
132 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_001 0x21
133 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_010 0x22
134 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_011 0x23
135 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_100 0x24
136 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_101 0x25
137 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_110 0x26
138 #define EXPAND14_DEVICE_ADDRESS_A2A1A0_111 0x27
139  // expand14_set
141 
156 #define EXPAND14_MAP_MIKROBUS( cfg, mikrobus ) \
157  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
158  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
159  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
160  // expand14_map // expand14
163 
168 typedef struct
169 {
170  // Input pins
171  digital_in_t int_pin;
173  // Modules
174  i2c_master_t i2c;
176  // I2C slave address
177  uint8_t slave_address;
179 } expand14_t;
180 
185 typedef struct
186 {
187  pin_name_t scl;
188  pin_name_t sda;
190  pin_name_t int_pin;
192  uint32_t i2c_speed;
193  uint8_t i2c_address;
196 
201 typedef enum
202 {
204  EXPAND14_ERROR = -1
205 
207 
224 
239 
253 
268 err_t expand14_generic_write ( expand14_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
269 
284 err_t expand14_generic_read ( expand14_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
285 
298 err_t expand14_write_register ( expand14_t *ctx, uint8_t reg, uint8_t data_in );
299 
312 err_t expand14_read_register ( expand14_t *ctx, uint8_t reg, uint8_t *data_out );
313 
329 err_t expand14_set_pin_direction ( expand14_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask );
330 
343 err_t expand14_set_all_pins_direction ( expand14_t *ctx, uint8_t direction );
344 
356 err_t expand14_set_all_pins_value ( expand14_t *ctx, uint8_t set_mask );
357 
372 err_t expand14_set_pin_value ( expand14_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
373 
387 err_t expand14_read_port_value ( expand14_t *ctx, uint8_t port, uint8_t *data_out );
388 
398 
399 #ifdef __cplusplus
400 }
401 #endif
402 #endif // EXPAND14_H
403  // expand14
405 
406 // ------------------------------------------------------------------------ END
expand14_cfg_t::sda
pin_name_t sda
Definition: expand14.h:188
expand14_return_value_t
expand14_return_value_t
Expand 14 Click return value data.
Definition: expand14.h:202
expand14_t
Expand 14 Click context object.
Definition: expand14.h:169
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:187
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:204
EXPAND14_OK
@ EXPAND14_OK
Definition: expand14.h:203
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:174
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:171
expand14_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand14.h:193
expand14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand14.h:192
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:186
expand14_t::slave_address
uint8_t slave_address
Definition: expand14.h:177
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:190
expand14_default_cfg
err_t expand14_default_cfg(expand14_t *ctx)
Expand 14 default configuration function.