expand13  2.0.0.0
expand13.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 EXPAND13_H
29 #define EXPAND13_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 EXPAND13_NO_PIN_MASK 0x00
70 #define EXPAND13_PIN_0_MASK 0x01
71 #define EXPAND13_PIN_1_MASK 0x02
72 #define EXPAND13_PIN_2_MASK 0x04
73 #define EXPAND13_PIN_3_MASK 0x08
74 #define EXPAND13_PIN_4_MASK 0x10
75 #define EXPAND13_PIN_5_MASK 0x20
76 #define EXPAND13_PIN_6_MASK 0x40
77 #define EXPAND13_PIN_7_MASK 0x80
78 #define EXPAND13_ALL_PINS_MASK 0xFF
79 
84 #define EXPAND13_PORT_0 0x00
85 #define EXPAND13_PORT_1 0x01
86 #define EXPAND13_PORT_2 0x02
87 #define EXPAND13_PORT_3 0x03
88 #define EXPAND13_PORT_4 0x04
89 #define EXPAND13_PORT_5 0x05
90 
96 #define EXPAND13_SET_DEV_ADDR_A2A1A0_000 0x20
97 #define EXPAND13_SET_DEV_ADDR_A2A1A0_001 0x21
98 #define EXPAND13_SET_DEV_ADDR_A2A1A0_010 0x22
99 #define EXPAND13_SET_DEV_ADDR_A2A1A0_011 0x23
100 #define EXPAND13_SET_DEV_ADDR_A2A1A0_100 0x24
101 #define EXPAND13_SET_DEV_ADDR_A2A1A0_101 0x25
102 #define EXPAND13_SET_DEV_ADDR_A2A1A0_110 0x26
103 #define EXPAND13_SET_DEV_ADDR_A2A1A0_111 0x27
104  // expand13_set
106 
121 #define EXPAND13_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
124  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
125  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
126  // expand13_map // expand13
129 
134 typedef struct
135 {
136  // Output pins
137  digital_out_t rst;
139  // Input pins
140  digital_in_t int_pin;
142  // Modules
143  i2c_master_t i2c;
145  // I2C slave address
146  uint8_t slave_address;
148 } expand13_t;
149 
154 typedef struct
155 {
156  pin_name_t scl;
157  pin_name_t sda;
159  pin_name_t rst;
160  pin_name_t int_pin;
162  uint32_t i2c_speed;
163  uint8_t i2c_address;
166 
171 typedef enum
172 {
174  EXPAND13_ERROR = -1
175 
177 
194 
210 
220 
230 
240 
253 err_t expand13_write_all_ports ( expand13_t *ctx, uint8_t *ports );
254 
267 err_t expand13_read_all_ports ( expand13_t *ctx, uint8_t *ports );
268 
288 err_t expand13_set_port_value ( expand13_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
289 
308 err_t expand13_read_port_value ( expand13_t *ctx, uint8_t port, uint8_t *data_out );
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 #endif // EXPAND13_H
314  // expand13
316 
317 // ------------------------------------------------------------------------ END
expand13_return_value_t
expand13_return_value_t
Expand 13 Click return value data.
Definition: expand13.h:172
expand13_read_port_value
err_t expand13_read_port_value(expand13_t *ctx, uint8_t port, uint8_t *data_out)
Expand 13 read port value function.
expand13_t
Expand 13 Click context object.
Definition: expand13.h:135
expand13_t::int_pin
digital_in_t int_pin
Definition: expand13.h:140
expand13_t::rst
digital_out_t rst
Definition: expand13.h:137
expand13_t::slave_address
uint8_t slave_address
Definition: expand13.h:146
expand13_t::i2c
i2c_master_t i2c
Definition: expand13.h:143
EXPAND13_OK
@ EXPAND13_OK
Definition: expand13.h:173
expand13_cfg_t::rst
pin_name_t rst
Definition: expand13.h:159
expand13_init
err_t expand13_init(expand13_t *ctx, expand13_cfg_t *cfg)
Expand 13 initialization function.
expand13_cfg_t::scl
pin_name_t scl
Definition: expand13.h:156
expand13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand13.h:162
expand13_set_port_value
err_t expand13_set_port_value(expand13_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask)
Expand 13 set port value function.
expand13_cfg_t::int_pin
pin_name_t int_pin
Definition: expand13.h:160
expand13_cfg_t::sda
pin_name_t sda
Definition: expand13.h:157
expand13_disable_device
void expand13_disable_device(expand13_t *ctx)
Expand 13 disable device function.
expand13_enable_device
void expand13_enable_device(expand13_t *ctx)
Expand 13 enable device function.
expand13_read_all_ports
err_t expand13_read_all_ports(expand13_t *ctx, uint8_t *ports)
Expand 13 read all ports function.
expand13_cfg_setup
void expand13_cfg_setup(expand13_cfg_t *cfg)
Expand 13 configuration object setup function.
EXPAND13_ERROR
@ EXPAND13_ERROR
Definition: expand13.h:174
expand13_write_all_ports
err_t expand13_write_all_ports(expand13_t *ctx, uint8_t *ports)
Expand 13 write all ports function.
expand13_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand13.h:163
expand13_cfg_t
Expand 13 Click configuration object.
Definition: expand13.h:155
expand13_get_int_pin
uint8_t expand13_get_int_pin(expand13_t *ctx)
Expand 13 get int pin function.