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 
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 EXPAND13_NO_PIN_MASK 0x00
74 #define EXPAND13_PIN_0_MASK 0x01
75 #define EXPAND13_PIN_1_MASK 0x02
76 #define EXPAND13_PIN_2_MASK 0x04
77 #define EXPAND13_PIN_3_MASK 0x08
78 #define EXPAND13_PIN_4_MASK 0x10
79 #define EXPAND13_PIN_5_MASK 0x20
80 #define EXPAND13_PIN_6_MASK 0x40
81 #define EXPAND13_PIN_7_MASK 0x80
82 #define EXPAND13_ALL_PINS_MASK 0xFF
83 
88 #define EXPAND13_PORT_0 0x00
89 #define EXPAND13_PORT_1 0x01
90 #define EXPAND13_PORT_2 0x02
91 #define EXPAND13_PORT_3 0x03
92 #define EXPAND13_PORT_4 0x04
93 #define EXPAND13_PORT_5 0x05
94 
100 #define EXPAND13_SET_DEV_ADDR_A2A1A0_000 0x20
101 #define EXPAND13_SET_DEV_ADDR_A2A1A0_001 0x21
102 #define EXPAND13_SET_DEV_ADDR_A2A1A0_010 0x22
103 #define EXPAND13_SET_DEV_ADDR_A2A1A0_011 0x23
104 #define EXPAND13_SET_DEV_ADDR_A2A1A0_100 0x24
105 #define EXPAND13_SET_DEV_ADDR_A2A1A0_101 0x25
106 #define EXPAND13_SET_DEV_ADDR_A2A1A0_110 0x26
107 #define EXPAND13_SET_DEV_ADDR_A2A1A0_111 0x27
108  // expand13_set
110 
125 #define EXPAND13_MAP_MIKROBUS( cfg, mikrobus ) \
126  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
127  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
128  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
129  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
130  // expand13_map // expand13
133 
138 typedef struct
139 {
140  // Output pins
141  digital_out_t rst;
143  // Input pins
144  digital_in_t int_pin;
146  // Modules
147  i2c_master_t i2c;
149  // I2C slave address
150  uint8_t slave_address;
152 } expand13_t;
153 
158 typedef struct
159 {
160  pin_name_t scl;
161  pin_name_t sda;
163  pin_name_t rst;
164  pin_name_t int_pin;
166  uint32_t i2c_speed;
167  uint8_t i2c_address;
170 
175 typedef enum
176 {
178  EXPAND13_ERROR = -1
179 
181 
198 
214 
224 
234 
244 
257 err_t expand13_write_all_ports ( expand13_t *ctx, uint8_t *ports );
258 
271 err_t expand13_read_all_ports ( expand13_t *ctx, uint8_t *ports );
272 
292 err_t expand13_set_port_value ( expand13_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
293 
312 err_t expand13_read_port_value ( expand13_t *ctx, uint8_t port, uint8_t *data_out );
313 
314 #ifdef __cplusplus
315 }
316 #endif
317 #endif // EXPAND13_H
318  // expand13
320 
321 // ------------------------------------------------------------------------ END
expand13_return_value_t
expand13_return_value_t
Expand 13 Click return value data.
Definition: expand13.h:176
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:139
expand13_t::int_pin
digital_in_t int_pin
Definition: expand13.h:144
expand13_t::rst
digital_out_t rst
Definition: expand13.h:141
expand13_t::slave_address
uint8_t slave_address
Definition: expand13.h:150
expand13_t::i2c
i2c_master_t i2c
Definition: expand13.h:147
EXPAND13_OK
@ EXPAND13_OK
Definition: expand13.h:177
expand13_cfg_t::rst
pin_name_t rst
Definition: expand13.h:163
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:160
expand13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand13.h:166
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:164
expand13_cfg_t::sda
pin_name_t sda
Definition: expand13.h:161
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:178
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:167
expand13_cfg_t
Expand 13 Click configuration object.
Definition: expand13.h:159
expand13_get_int_pin
uint8_t expand13_get_int_pin(expand13_t *ctx)
Expand 13 get int pin function.