expand11  2.1.0.0
expand11.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 EXPAND11_H
29 #define EXPAND11_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 EXPAND11_REG_INPUT_PORT 0x00
60 #define EXPAND11_REG_OUTPUT_PORT 0x01
61 #define EXPAND11_REG_POLARITY_INV 0x02
62 #define EXPAND11_REG_CONFIG 0x03
63 #define EXPAND11_REG_SPECIAL_FUNC 0x50
64  // expand11_reg
66 
81 #define EXPAND11_NO_PIN_MASK 0x00
82 #define EXPAND11_PIN_0_MASK 0x01
83 #define EXPAND11_PIN_1_MASK 0x02
84 #define EXPAND11_PIN_2_MASK 0x04
85 #define EXPAND11_PIN_3_MASK 0x08
86 #define EXPAND11_ALL_PINS_MASK 0x0F
87 
92 #define EXPAND11_OUTPUT_DIRECTION 0x00
93 #define EXPAND11_INPUT_DIRECTION 0x01
94 
99 #define EXPAND11_POLARITY_NO_INV 0x00
100 #define EXPAND11_POLARITY_INV 0x01
101 
106 #define EXPAND11_SPECIAL_FUNC_P3_AS_INT 0x80
107 #define EXPAND11_SPECIAL_FUNC_PU_DISABLED 0x40
108 
113 #define EXPAND11_P3_AS_P3 0x00
114 #define EXPAND11_P3_AS_INT 0x01
115 
121 #define EXPAND11_DEVICE_ADDRESS 0x41
122  // expand11_set
124 
139 #define EXPAND11_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
141  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
142  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
143  // expand11_map // expand11
146 
151 typedef struct
152 {
153  // Input pins
154  digital_in_t int_pin;
156  // Modules
157  i2c_master_t i2c;
159  // I2C slave address
160  uint8_t slave_address;
162 } expand11_t;
163 
168 typedef struct
169 {
170  pin_name_t scl;
171  pin_name_t sda;
173  pin_name_t int_pin;
175  uint32_t i2c_speed;
176  uint8_t i2c_address;
179 
184 typedef enum
185 {
187  EXPAND11_ERROR = -1
188 
190 
207 
222 
236 
249 err_t expand11_write_register ( expand11_t *ctx, uint8_t reg, uint8_t data_in );
250 
263 err_t expand11_read_register ( expand11_t *ctx, uint8_t reg, uint8_t *data_out );
264 
278 err_t expand11_set_pin_direction ( expand11_t *ctx, uint8_t direction, uint8_t pin_mask );
279 
292 err_t expand11_set_all_pins_direction ( expand11_t *ctx, uint8_t direction );
293 
307 err_t expand11_set_pin_polarity ( expand11_t *ctx, uint8_t polarity, uint8_t pin_mask );
308 
321 err_t expand11_set_all_pins_polarity ( expand11_t *ctx, uint8_t polarity );
322 
335 err_t expand11_set_pin_value ( expand11_t *ctx, uint8_t clr_mask, uint8_t set_mask );
336 
348 err_t expand11_set_all_pins_value ( expand11_t *ctx, uint8_t set_mask );
349 
361 err_t expand11_read_port_value ( expand11_t *ctx, uint8_t *data_out );
362 
375 err_t expand11_set_p3_function ( expand11_t *ctx, uint8_t p3_func );
376 
388 
400 
410 
411 #ifdef __cplusplus
412 }
413 #endif
414 #endif // EXPAND11_H
415  // expand11
417 
418 // ------------------------------------------------------------------------ END
expand11_cfg_setup
void expand11_cfg_setup(expand11_cfg_t *cfg)
Expand 11 configuration object setup function.
expand11_cfg_t::scl
pin_name_t scl
Definition: expand11.h:170
expand11_cfg_t::int_pin
pin_name_t int_pin
Definition: expand11.h:173
expand11_set_pin_direction
err_t expand11_set_pin_direction(expand11_t *ctx, uint8_t direction, uint8_t pin_mask)
Expand 11 set pin direction function.
EXPAND11_OK
@ EXPAND11_OK
Definition: expand11.h:186
expand11_return_value_t
expand11_return_value_t
Expand 11 Click return value data.
Definition: expand11.h:185
expand11_t::slave_address
uint8_t slave_address
Definition: expand11.h:160
expand11_enable_pull_up
err_t expand11_enable_pull_up(expand11_t *ctx)
Expand 11 enable pull up function.
expand11_t::i2c
i2c_master_t i2c
Definition: expand11.h:157
expand11_t
Expand 11 Click context object.
Definition: expand11.h:152
EXPAND11_ERROR
@ EXPAND11_ERROR
Definition: expand11.h:187
expand11_init
err_t expand11_init(expand11_t *ctx, expand11_cfg_t *cfg)
Expand 11 initialization function.
expand11_get_int_pin
uint8_t expand11_get_int_pin(expand11_t *ctx)
Expand 11 get int pin function.
expand11_set_p3_function
err_t expand11_set_p3_function(expand11_t *ctx, uint8_t p3_func)
Expand 11 set p3 function function.
expand11_t::int_pin
digital_in_t int_pin
Definition: expand11.h:154
expand11_default_cfg
err_t expand11_default_cfg(expand11_t *ctx)
Expand 11 default configuration function.
expand11_cfg_t::sda
pin_name_t sda
Definition: expand11.h:171
expand11_read_register
err_t expand11_read_register(expand11_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 11 read register function.
expand11_set_pin_polarity
err_t expand11_set_pin_polarity(expand11_t *ctx, uint8_t polarity, uint8_t pin_mask)
Expand 11 set pin polarity function.
expand11_set_all_pins_direction
err_t expand11_set_all_pins_direction(expand11_t *ctx, uint8_t direction)
Expand 11 set all pins direction function.
expand11_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand11.h:176
expand11_set_pin_value
err_t expand11_set_pin_value(expand11_t *ctx, uint8_t clr_mask, uint8_t set_mask)
Expand 11 set pin value function.
expand11_write_register
err_t expand11_write_register(expand11_t *ctx, uint8_t reg, uint8_t data_in)
Expand 11 write register function.
expand11_set_all_pins_value
err_t expand11_set_all_pins_value(expand11_t *ctx, uint8_t set_mask)
Expand 11 set all pins value function.
expand11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand11.h:175
expand11_disable_pull_up
err_t expand11_disable_pull_up(expand11_t *ctx)
Expand 11 disable pull up function.
expand11_set_all_pins_polarity
err_t expand11_set_all_pins_polarity(expand11_t *ctx, uint8_t polarity)
Expand 11 set all pins polarity function.
expand11_cfg_t
Expand 11 Click configuration object.
Definition: expand11.h:169
expand11_read_port_value
err_t expand11_read_port_value(expand11_t *ctx, uint8_t *data_out)
Expand 11 read port value function.