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
32extern "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 EXPAND11_REG_INPUT_PORT 0x00
74#define EXPAND11_REG_OUTPUT_PORT 0x01
75#define EXPAND11_REG_POLARITY_INV 0x02
76#define EXPAND11_REG_CONFIG 0x03
77#define EXPAND11_REG_SPECIAL_FUNC 0x50
78
79 // expand11_reg
80
95#define EXPAND11_NO_PIN_MASK 0x00
96#define EXPAND11_PIN_0_MASK 0x01
97#define EXPAND11_PIN_1_MASK 0x02
98#define EXPAND11_PIN_2_MASK 0x04
99#define EXPAND11_PIN_3_MASK 0x08
100#define EXPAND11_ALL_PINS_MASK 0x0F
101
106#define EXPAND11_OUTPUT_DIRECTION 0x00
107#define EXPAND11_INPUT_DIRECTION 0x01
108
113#define EXPAND11_POLARITY_NO_INV 0x00
114#define EXPAND11_POLARITY_INV 0x01
115
120#define EXPAND11_SPECIAL_FUNC_P3_AS_INT 0x80
121#define EXPAND11_SPECIAL_FUNC_PU_DISABLED 0x40
122
127#define EXPAND11_P3_AS_P3 0x00
128#define EXPAND11_P3_AS_INT 0x01
129
135#define EXPAND11_DEVICE_ADDRESS 0x41
136
137 // expand11_set
138
153#define EXPAND11_MAP_MIKROBUS( cfg, mikrobus ) \
154 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
155 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
156 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
157
158 // expand11_map
159 // expand11
160
165typedef struct
166{
167 // Input pins
168 digital_in_t int_pin;
170 // Modules
171 i2c_master_t i2c;
173 // I2C slave address
176} expand11_t;
177
182typedef struct
183{
184 pin_name_t scl;
185 pin_name_t sda;
187 pin_name_t int_pin;
189 uint32_t i2c_speed;
190 uint8_t i2c_address;
193
198typedef enum
199{
201 EXPAND11_ERROR = -1
202
204
221
236
250
263err_t expand11_write_register ( expand11_t *ctx, uint8_t reg, uint8_t data_in );
264
277err_t expand11_read_register ( expand11_t *ctx, uint8_t reg, uint8_t *data_out );
278
292err_t expand11_set_pin_direction ( expand11_t *ctx, uint8_t direction, uint8_t pin_mask );
293
306err_t expand11_set_all_pins_direction ( expand11_t *ctx, uint8_t direction );
307
321err_t expand11_set_pin_polarity ( expand11_t *ctx, uint8_t polarity, uint8_t pin_mask );
322
335err_t expand11_set_all_pins_polarity ( expand11_t *ctx, uint8_t polarity );
336
349err_t expand11_set_pin_value ( expand11_t *ctx, uint8_t clr_mask, uint8_t set_mask );
350
362err_t expand11_set_all_pins_value ( expand11_t *ctx, uint8_t set_mask );
363
375err_t expand11_read_port_value ( expand11_t *ctx, uint8_t *data_out );
376
389err_t expand11_set_p3_function ( expand11_t *ctx, uint8_t p3_func );
390
402
414
424
425#ifdef __cplusplus
426}
427#endif
428#endif // EXPAND11_H
429
430 // expand11
431
432// ------------------------------------------------------------------------ END
expand11_return_value_t
Expand 11 Click return value data.
Definition expand11.h:199
@ EXPAND11_OK
Definition expand11.h:200
@ EXPAND11_ERROR
Definition expand11.h:201
err_t expand11_write_register(expand11_t *ctx, uint8_t reg, uint8_t data_in)
Expand 11 write register function.
err_t expand11_disable_pull_up(expand11_t *ctx)
Expand 11 disable pull up function.
uint8_t expand11_get_int_pin(expand11_t *ctx)
Expand 11 get int pin function.
err_t expand11_set_all_pins_polarity(expand11_t *ctx, uint8_t polarity)
Expand 11 set all pins polarity function.
err_t expand11_set_pin_value(expand11_t *ctx, uint8_t clr_mask, uint8_t set_mask)
Expand 11 set pin value function.
void expand11_cfg_setup(expand11_cfg_t *cfg)
Expand 11 configuration object setup function.
err_t expand11_read_register(expand11_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 11 read register function.
err_t expand11_set_pin_direction(expand11_t *ctx, uint8_t direction, uint8_t pin_mask)
Expand 11 set pin direction function.
err_t expand11_enable_pull_up(expand11_t *ctx)
Expand 11 enable pull up function.
err_t expand11_set_all_pins_direction(expand11_t *ctx, uint8_t direction)
Expand 11 set all pins direction function.
err_t expand11_set_p3_function(expand11_t *ctx, uint8_t p3_func)
Expand 11 set p3 function function.
err_t expand11_init(expand11_t *ctx, expand11_cfg_t *cfg)
Expand 11 initialization function.
err_t expand11_read_port_value(expand11_t *ctx, uint8_t *data_out)
Expand 11 read port value function.
err_t expand11_set_pin_polarity(expand11_t *ctx, uint8_t polarity, uint8_t pin_mask)
Expand 11 set pin polarity function.
err_t expand11_default_cfg(expand11_t *ctx)
Expand 11 default configuration function.
err_t expand11_set_all_pins_value(expand11_t *ctx, uint8_t set_mask)
Expand 11 set all pins value function.
Expand 11 Click configuration object.
Definition expand11.h:183
uint32_t i2c_speed
Definition expand11.h:189
pin_name_t scl
Definition expand11.h:184
pin_name_t int_pin
Definition expand11.h:187
pin_name_t sda
Definition expand11.h:185
uint8_t i2c_address
Definition expand11.h:190
Expand 11 Click context object.
Definition expand11.h:166
digital_in_t int_pin
Definition expand11.h:168
i2c_master_t i2c
Definition expand11.h:171
uint8_t slave_address
Definition expand11.h:174