expand12  2.0.0.0
expand12.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 EXPAND12_H
29 #define EXPAND12_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 EXPAND12_REG_NOP 0x00
70 #define EXPAND12_REG_CONFIG 0x04
71 #define EXPAND12_REG_TRANSITION_DETECT_MASK 0x06
72 #define EXPAND12_REG_RESERVED 0x07
73 #define EXPAND12_REG_CONFIG_P7_4 0x09
74 #define EXPAND12_REG_CONFIG_P11_8 0x0A
75 #define EXPAND12_REG_CONFIG_P15_12 0x0B
76 #define EXPAND12_REG_CONFIG_P19_16 0x0C
77 #define EXPAND12_REG_CONFIG_P23_20 0x0D
78 #define EXPAND12_REG_CONFIG_P27_24 0x0E
79 #define EXPAND12_REG_CONFIG_P31_28 0x0F
80 #define EXPAND12_REG_P0 0x20
81 #define EXPAND12_REG_P1 0x21
82 #define EXPAND12_REG_P2 0x22
83 #define EXPAND12_REG_P3 0x23
84 #define EXPAND12_REG_P4 0x24
85 #define EXPAND12_REG_P5 0x25
86 #define EXPAND12_REG_P6 0x26
87 #define EXPAND12_REG_P7 0x27
88 #define EXPAND12_REG_P8 0x28
89 #define EXPAND12_REG_P9 0x29
90 #define EXPAND12_REG_P10 0x2A
91 #define EXPAND12_REG_P11 0x2B
92 #define EXPAND12_REG_P12 0x2C
93 #define EXPAND12_REG_P13 0x2D
94 #define EXPAND12_REG_P14 0x2E
95 #define EXPAND12_REG_P15 0x2F
96 #define EXPAND12_REG_P16 0x30
97 #define EXPAND12_REG_P17 0x31
98 #define EXPAND12_REG_P18 0x32
99 #define EXPAND12_REG_P19 0x33
100 #define EXPAND12_REG_P20 0x34
101 #define EXPAND12_REG_P21 0x35
102 #define EXPAND12_REG_P22 0x36
103 #define EXPAND12_REG_P23 0x37
104 #define EXPAND12_REG_P24 0x38
105 #define EXPAND12_REG_P25 0x39
106 #define EXPAND12_REG_P26 0x3A
107 #define EXPAND12_REG_P27 0x3B
108 #define EXPAND12_REG_P28 0x3C
109 #define EXPAND12_REG_P29 0x3D
110 #define EXPAND12_REG_P30 0x3E
111 #define EXPAND12_REG_P31 0x3F
112 #define EXPAND12_REG_P4_7 0x40
113 #define EXPAND12_REG_P4_8 0x41
114 #define EXPAND12_REG_P4_9 0x42
115 #define EXPAND12_REG_P4_10 0x43
116 #define EXPAND12_REG_P4_11 0x44
117 #define EXPAND12_REG_P5_12 0x45
118 #define EXPAND12_REG_P6_13 0x46
119 #define EXPAND12_REG_P7_14 0x47
120 #define EXPAND12_REG_P8_15 0x48
121 #define EXPAND12_REG_P9_16 0x49
122 #define EXPAND12_REG_P10_17 0x4A
123 #define EXPAND12_REG_P11_18 0x4B
124 #define EXPAND12_REG_P12_19 0x4C
125 #define EXPAND12_REG_P13_20 0x4D
126 #define EXPAND12_REG_P14_21 0x4E
127 #define EXPAND12_REG_P15_22 0x4F
128 #define EXPAND12_REG_P16_23 0x50
129 #define EXPAND12_REG_P17_24 0x51
130 #define EXPAND12_REG_P18_25 0x52
131 #define EXPAND12_REG_P19_26 0x53
132 #define EXPAND12_REG_P20_27 0x54
133 #define EXPAND12_REG_P21_28 0x55
134 #define EXPAND12_REG_P22_29 0x56
135 #define EXPAND12_REG_P23_30 0x57
136 #define EXPAND12_REG_P24_31 0x58
137 #define EXPAND12_REG_P25_31 0x59
138 #define EXPAND12_REG_P26_31 0x5A
139 #define EXPAND12_REG_P27_31 0x5B
140 #define EXPAND12_REG_P28_31 0x5C
141 #define EXPAND12_REG_P29_31 0x5D
142 #define EXPAND12_REG_P30_31 0x5E
143 #define EXPAND12_REG_P31_ONLY 0x5F
144  // expand12_reg
146 
161 #define EXPAND12_PIN_4 0x00
162 #define EXPAND12_PIN_5 0x01
163 #define EXPAND12_PIN_6 0x02
164 #define EXPAND12_PIN_7 0x03
165 #define EXPAND12_PIN_8 0x04
166 #define EXPAND12_PIN_9 0x05
167 #define EXPAND12_PIN_10 0x06
168 #define EXPAND12_PIN_11 0x07
169 #define EXPAND12_PIN_12 0x08
170 #define EXPAND12_PIN_13 0x09
171 #define EXPAND12_PIN_14 0x0A
172 #define EXPAND12_PIN_15 0x0B
173 #define EXPAND12_PIN_16 0x0C
174 #define EXPAND12_PIN_17 0x0D
175 #define EXPAND12_PIN_18 0x0E
176 #define EXPAND12_PIN_19 0x0F
177 #define EXPAND12_PIN_20 0x10
178 #define EXPAND12_PIN_21 0x11
179 #define EXPAND12_PIN_22 0x12
180 #define EXPAND12_PIN_23 0x13
181 #define EXPAND12_PIN_24 0x14
182 #define EXPAND12_PIN_25 0x15
183 #define EXPAND12_PIN_26 0x16
184 #define EXPAND12_PIN_27 0x17
185 #define EXPAND12_PIN_28 0x18
186 #define EXPAND12_PIN_29 0x19
187 #define EXPAND12_PIN_30 0x1A
188 #define EXPAND12_PIN_31 0x1B
189 #define EXPAND12_ALL_PINS 0xFF
190 #define EXPAND12_NO_PINS 0x00
191 #define EXPAND12_PORT_4_7 0x00
192 #define EXPAND12_PORT_8_15 0x01
193 #define EXPAND12_PORT_16_23 0x02
194 #define EXPAND12_PORT_24_31 0x03
195 
200 #define EXPAND12_DIR_OUTPUT 0x01
201 #define EXPAND12_DIR_INPUT 0x02
202 #define EXPAND12_DIR_INPUT_WITH_PULLUP 0x03
203 
208 #define EXPAND12_OPMODE_SHUTDOWN 0x00
209 #define EXPAND12_OPMODE_NORMAL 0x01
210 
215 #define EXPAND12_PIN_LOW_LEVEL 0x00
216 #define EXPAND12_PIN_HIGH_LEVEL 0x01
217 
223 #define EXPAND12_SET_DEV_ADDR_A1A0_00 0x40
224 #define EXPAND12_SET_DEV_ADDR_A1A0_01 0x41
225 #define EXPAND12_SET_DEV_ADDR_A1A0_10 0x44
226 #define EXPAND12_SET_DEV_ADDR_A1A0_11 0x45
227  // expand12_set
229 
244 #define EXPAND12_MAP_MIKROBUS( cfg, mikrobus ) \
245  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
246  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
247  // expand12_map // expand12
250 
255 typedef struct
256 {
257  // Modules
258  i2c_master_t i2c;
260  // I2C slave address
261  uint8_t slave_address;
263 } expand12_t;
264 
269 typedef struct
270 {
271  pin_name_t scl;
272  pin_name_t sda;
274  uint32_t i2c_speed;
275  uint8_t i2c_address;
278 
283 typedef enum
284 {
286  EXPAND12_ERROR = -1
287 
289 
306 
322 
337 
353 err_t expand12_generic_write ( expand12_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
354 
370 err_t expand12_generic_read ( expand12_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
371 
386 err_t expand12_write_register ( expand12_t *ctx, uint8_t reg, uint8_t data_in );
387 
402 err_t expand12_read_register ( expand12_t *ctx, uint8_t reg, uint8_t *data_out );
403 
417 err_t expand12_set_operating_mode ( expand12_t *ctx, uint8_t state );
418 
434 err_t expand12_set_pin_direction ( expand12_t *ctx, uint8_t pin, uint8_t direction );
435 
454 err_t expand12_set_port_direction ( expand12_t *ctx, uint8_t port, uint8_t direction );
455 
470 err_t expand12_set_all_pins_direction ( expand12_t *ctx, uint8_t direction );
471 
486 err_t expand12_set_pin_value ( expand12_t *ctx, uint8_t pin, uint8_t pin_value );
487 
505 err_t expand12_set_port_value ( expand12_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
506 
520 err_t expand12_set_all_pins_value ( expand12_t *ctx, uint8_t pin_value );
521 
536 err_t expand12_read_pin_value ( expand12_t *ctx, uint8_t pin, uint8_t *pin_value );
537 
554 err_t expand12_read_port_value ( expand12_t *ctx, uint8_t port, uint8_t *port_value );
555 
568 err_t expand12_read_all_pins_value ( expand12_t *ctx, uint32_t *pins_value );
569 
570 #ifdef __cplusplus
571 }
572 #endif
573 #endif // EXPAND12_H
574  // expand12
576 
577 // ------------------------------------------------------------------------ END
expand12_set_operating_mode
err_t expand12_set_operating_mode(expand12_t *ctx, uint8_t state)
Expand 12 set operating mode function.
expand12_cfg_setup
void expand12_cfg_setup(expand12_cfg_t *cfg)
Expand 12 configuration object setup function.
expand12_generic_read
err_t expand12_generic_read(expand12_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Expand 12 I2C reading function.
expand12_set_all_pins_value
err_t expand12_set_all_pins_value(expand12_t *ctx, uint8_t pin_value)
Expand 12 set all pins value function.
expand12_set_pin_value
err_t expand12_set_pin_value(expand12_t *ctx, uint8_t pin, uint8_t pin_value)
Expand 12 set pin value function.
expand12_write_register
err_t expand12_write_register(expand12_t *ctx, uint8_t reg, uint8_t data_in)
Expand 12 write register function.
expand12_t::slave_address
uint8_t slave_address
Definition: expand12.h:261
expand12_init
err_t expand12_init(expand12_t *ctx, expand12_cfg_t *cfg)
Expand 12 initialization function.
expand12_t
Expand 12 Click context object.
Definition: expand12.h:256
expand12_generic_write
err_t expand12_generic_write(expand12_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Expand 12 I2C writing function.
expand12_read_port_value
err_t expand12_read_port_value(expand12_t *ctx, uint8_t port, uint8_t *port_value)
Expand 12 read port value function.
expand12_set_pin_direction
err_t expand12_set_pin_direction(expand12_t *ctx, uint8_t pin, uint8_t direction)
Expand 12 set pin direction function.
expand12_t::i2c
i2c_master_t i2c
Definition: expand12.h:258
expand12_set_all_pins_direction
err_t expand12_set_all_pins_direction(expand12_t *ctx, uint8_t direction)
Expand 12 set all pins direction function.
EXPAND12_OK
@ EXPAND12_OK
Definition: expand12.h:285
expand12_set_port_value
err_t expand12_set_port_value(expand12_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask)
Expand 12 set port value function.
expand12_read_all_pins_value
err_t expand12_read_all_pins_value(expand12_t *ctx, uint32_t *pins_value)
Expand 12 read all pins value function.
expand12_read_pin_value
err_t expand12_read_pin_value(expand12_t *ctx, uint8_t pin, uint8_t *pin_value)
Expand 12 read pin value function.
expand12_return_value_t
expand12_return_value_t
Expand 12 Click return value data.
Definition: expand12.h:284
expand12_cfg_t::sda
pin_name_t sda
Definition: expand12.h:272
expand12_read_register
err_t expand12_read_register(expand12_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 12 read register function.
expand12_set_port_direction
err_t expand12_set_port_direction(expand12_t *ctx, uint8_t port, uint8_t direction)
Expand 12 set port direction function.
expand12_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand12.h:275
expand12_cfg_t
Expand 12 Click configuration object.
Definition: expand12.h:270
EXPAND12_ERROR
@ EXPAND12_ERROR
Definition: expand12.h:286
expand12_cfg_t::scl
pin_name_t scl
Definition: expand12.h:271
expand12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand12.h:274
expand12_default_cfg
err_t expand12_default_cfg(expand12_t *ctx)
Expand 12 default configuration function.