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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define EXPAND12_REG_NOP 0x00
60 #define EXPAND12_REG_CONFIG 0x04
61 #define EXPAND12_REG_TRANSITION_DETECT_MASK 0x06
62 #define EXPAND12_REG_RESERVED 0x07
63 #define EXPAND12_REG_CONFIG_P7_4 0x09
64 #define EXPAND12_REG_CONFIG_P11_8 0x0A
65 #define EXPAND12_REG_CONFIG_P15_12 0x0B
66 #define EXPAND12_REG_CONFIG_P19_16 0x0C
67 #define EXPAND12_REG_CONFIG_P23_20 0x0D
68 #define EXPAND12_REG_CONFIG_P27_24 0x0E
69 #define EXPAND12_REG_CONFIG_P31_28 0x0F
70 #define EXPAND12_REG_P0 0x20
71 #define EXPAND12_REG_P1 0x21
72 #define EXPAND12_REG_P2 0x22
73 #define EXPAND12_REG_P3 0x23
74 #define EXPAND12_REG_P4 0x24
75 #define EXPAND12_REG_P5 0x25
76 #define EXPAND12_REG_P6 0x26
77 #define EXPAND12_REG_P7 0x27
78 #define EXPAND12_REG_P8 0x28
79 #define EXPAND12_REG_P9 0x29
80 #define EXPAND12_REG_P10 0x2A
81 #define EXPAND12_REG_P11 0x2B
82 #define EXPAND12_REG_P12 0x2C
83 #define EXPAND12_REG_P13 0x2D
84 #define EXPAND12_REG_P14 0x2E
85 #define EXPAND12_REG_P15 0x2F
86 #define EXPAND12_REG_P16 0x30
87 #define EXPAND12_REG_P17 0x31
88 #define EXPAND12_REG_P18 0x32
89 #define EXPAND12_REG_P19 0x33
90 #define EXPAND12_REG_P20 0x34
91 #define EXPAND12_REG_P21 0x35
92 #define EXPAND12_REG_P22 0x36
93 #define EXPAND12_REG_P23 0x37
94 #define EXPAND12_REG_P24 0x38
95 #define EXPAND12_REG_P25 0x39
96 #define EXPAND12_REG_P26 0x3A
97 #define EXPAND12_REG_P27 0x3B
98 #define EXPAND12_REG_P28 0x3C
99 #define EXPAND12_REG_P29 0x3D
100 #define EXPAND12_REG_P30 0x3E
101 #define EXPAND12_REG_P31 0x3F
102 #define EXPAND12_REG_P4_7 0x40
103 #define EXPAND12_REG_P4_8 0x41
104 #define EXPAND12_REG_P4_9 0x42
105 #define EXPAND12_REG_P4_10 0x43
106 #define EXPAND12_REG_P4_11 0x44
107 #define EXPAND12_REG_P5_12 0x45
108 #define EXPAND12_REG_P6_13 0x46
109 #define EXPAND12_REG_P7_14 0x47
110 #define EXPAND12_REG_P8_15 0x48
111 #define EXPAND12_REG_P9_16 0x49
112 #define EXPAND12_REG_P10_17 0x4A
113 #define EXPAND12_REG_P11_18 0x4B
114 #define EXPAND12_REG_P12_19 0x4C
115 #define EXPAND12_REG_P13_20 0x4D
116 #define EXPAND12_REG_P14_21 0x4E
117 #define EXPAND12_REG_P15_22 0x4F
118 #define EXPAND12_REG_P16_23 0x50
119 #define EXPAND12_REG_P17_24 0x51
120 #define EXPAND12_REG_P18_25 0x52
121 #define EXPAND12_REG_P19_26 0x53
122 #define EXPAND12_REG_P20_27 0x54
123 #define EXPAND12_REG_P21_28 0x55
124 #define EXPAND12_REG_P22_29 0x56
125 #define EXPAND12_REG_P23_30 0x57
126 #define EXPAND12_REG_P24_31 0x58
127 #define EXPAND12_REG_P25_31 0x59
128 #define EXPAND12_REG_P26_31 0x5A
129 #define EXPAND12_REG_P27_31 0x5B
130 #define EXPAND12_REG_P28_31 0x5C
131 #define EXPAND12_REG_P29_31 0x5D
132 #define EXPAND12_REG_P30_31 0x5E
133 #define EXPAND12_REG_P31_ONLY 0x5F
134  // expand12_reg
136 
151 #define EXPAND12_PIN_4 0x00
152 #define EXPAND12_PIN_5 0x01
153 #define EXPAND12_PIN_6 0x02
154 #define EXPAND12_PIN_7 0x03
155 #define EXPAND12_PIN_8 0x04
156 #define EXPAND12_PIN_9 0x05
157 #define EXPAND12_PIN_10 0x06
158 #define EXPAND12_PIN_11 0x07
159 #define EXPAND12_PIN_12 0x08
160 #define EXPAND12_PIN_13 0x09
161 #define EXPAND12_PIN_14 0x0A
162 #define EXPAND12_PIN_15 0x0B
163 #define EXPAND12_PIN_16 0x0C
164 #define EXPAND12_PIN_17 0x0D
165 #define EXPAND12_PIN_18 0x0E
166 #define EXPAND12_PIN_19 0x0F
167 #define EXPAND12_PIN_20 0x10
168 #define EXPAND12_PIN_21 0x11
169 #define EXPAND12_PIN_22 0x12
170 #define EXPAND12_PIN_23 0x13
171 #define EXPAND12_PIN_24 0x14
172 #define EXPAND12_PIN_25 0x15
173 #define EXPAND12_PIN_26 0x16
174 #define EXPAND12_PIN_27 0x17
175 #define EXPAND12_PIN_28 0x18
176 #define EXPAND12_PIN_29 0x19
177 #define EXPAND12_PIN_30 0x1A
178 #define EXPAND12_PIN_31 0x1B
179 #define EXPAND12_ALL_PINS 0xFF
180 #define EXPAND12_NO_PINS 0x00
181 #define EXPAND12_PORT_4_7 0x00
182 #define EXPAND12_PORT_8_15 0x01
183 #define EXPAND12_PORT_16_23 0x02
184 #define EXPAND12_PORT_24_31 0x03
185 
190 #define EXPAND12_DIR_OUTPUT 0x01
191 #define EXPAND12_DIR_INPUT 0x02
192 #define EXPAND12_DIR_INPUT_WITH_PULLUP 0x03
193 
198 #define EXPAND12_OPMODE_SHUTDOWN 0x00
199 #define EXPAND12_OPMODE_NORMAL 0x01
200 
205 #define EXPAND12_PIN_LOW_LEVEL 0x00
206 #define EXPAND12_PIN_HIGH_LEVEL 0x01
207 
213 #define EXPAND12_SET_DEV_ADDR_A1A0_00 0x40
214 #define EXPAND12_SET_DEV_ADDR_A1A0_01 0x41
215 #define EXPAND12_SET_DEV_ADDR_A1A0_10 0x44
216 #define EXPAND12_SET_DEV_ADDR_A1A0_11 0x45
217  // expand12_set
219 
234 #define EXPAND12_MAP_MIKROBUS( cfg, mikrobus ) \
235  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
236  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
237  // expand12_map // expand12
240 
245 typedef struct
246 {
247  // Modules
248  i2c_master_t i2c;
250  // I2C slave address
251  uint8_t slave_address;
253 } expand12_t;
254 
259 typedef struct
260 {
261  pin_name_t scl;
262  pin_name_t sda;
264  uint32_t i2c_speed;
265  uint8_t i2c_address;
268 
273 typedef enum
274 {
276  EXPAND12_ERROR = -1
277 
279 
296 
312 
327 
343 err_t expand12_generic_write ( expand12_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
344 
360 err_t expand12_generic_read ( expand12_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
361 
376 err_t expand12_write_register ( expand12_t *ctx, uint8_t reg, uint8_t data_in );
377 
392 err_t expand12_read_register ( expand12_t *ctx, uint8_t reg, uint8_t *data_out );
393 
407 err_t expand12_set_operating_mode ( expand12_t *ctx, uint8_t state );
408 
424 err_t expand12_set_pin_direction ( expand12_t *ctx, uint8_t pin, uint8_t direction );
425 
444 err_t expand12_set_port_direction ( expand12_t *ctx, uint8_t port, uint8_t direction );
445 
460 err_t expand12_set_all_pins_direction ( expand12_t *ctx, uint8_t direction );
461 
476 err_t expand12_set_pin_value ( expand12_t *ctx, uint8_t pin, uint8_t pin_value );
477 
495 err_t expand12_set_port_value ( expand12_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
496 
510 err_t expand12_set_all_pins_value ( expand12_t *ctx, uint8_t pin_value );
511 
526 err_t expand12_read_pin_value ( expand12_t *ctx, uint8_t pin, uint8_t *pin_value );
527 
544 err_t expand12_read_port_value ( expand12_t *ctx, uint8_t port, uint8_t *port_value );
545 
558 err_t expand12_read_all_pins_value ( expand12_t *ctx, uint32_t *pins_value );
559 
560 #ifdef __cplusplus
561 }
562 #endif
563 #endif // EXPAND12_H
564  // expand12
566 
567 // ------------------------------------------------------------------------ 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:251
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:246
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:248
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:275
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:274
expand12_cfg_t::sda
pin_name_t sda
Definition: expand12.h:262
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:265
expand12_cfg_t
Expand 12 Click configuration object.
Definition: expand12.h:260
EXPAND12_ERROR
@ EXPAND12_ERROR
Definition: expand12.h:276
expand12_cfg_t::scl
pin_name_t scl
Definition: expand12.h:261
expand12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand12.h:264
expand12_default_cfg
err_t expand12_default_cfg(expand12_t *ctx)
Expand 12 default configuration function.