expand10  2.0.0.0
expand10.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 EXPAND10_H
29 #define EXPAND10_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 EXPAND10_REG_INPUT_P0 0x00
74 #define EXPAND10_REG_INPUT_P1 0x01
75 #define EXPAND10_REG_INPUT_P2 0x02
76 #define EXPAND10_REG_OUTPUT_P0 0x04
77 #define EXPAND10_REG_OUTPUT_P1 0x05
78 #define EXPAND10_REG_OUTPUT_P2 0x06
79 #define EXPAND10_REG_POLARITY_INV_P0 0x08
80 #define EXPAND10_REG_POLARITY_INV_P1 0x09
81 #define EXPAND10_REG_POLARITY_INV_P2 0x0A
82 #define EXPAND10_REG_CONFIG_P0 0x0C
83 #define EXPAND10_REG_CONFIG_P1 0x0D
84 #define EXPAND10_REG_CONFIG_P2 0x0E
85 #define EXPAND10_REG_OUTPUT_DRIVE_P0A 0x40
86 #define EXPAND10_REG_OUTPUT_DRIVE_P0B 0x41
87 #define EXPAND10_REG_OUTPUT_DRIVE_P1A 0x42
88 #define EXPAND10_REG_OUTPUT_DRIVE_P1B 0x43
89 #define EXPAND10_REG_OUTPUT_DRIVE_P2A 0x44
90 #define EXPAND10_REG_OUTPUT_DRIVE_P2B 0x45
91 #define EXPAND10_REG_INPUT_LAT_P0 0x48
92 #define EXPAND10_REG_INPUT_LAT_P1 0x49
93 #define EXPAND10_REG_INPUT_LAT_P2 0x4A
94 #define EXPAND10_REG_PULL_ENABLE_P0 0x4C
95 #define EXPAND10_REG_PULL_ENABLE_P1 0x4D
96 #define EXPAND10_REG_PULL_ENABLE_P2 0x4E
97 #define EXPAND10_REG_PULL_SELECTION_P0 0x50
98 #define EXPAND10_REG_PULL_SELECTION_P1 0x51
99 #define EXPAND10_REG_PULL_SELECTION_P2 0x52
100 #define EXPAND10_REG_INT_MASK_P0 0x54
101 #define EXPAND10_REG_INT_MASK_P1 0x55
102 #define EXPAND10_REG_INT_MASK_P2 0x56
103 #define EXPAND10_REG_INT_STATUS_P0 0x58
104 #define EXPAND10_REG_INT_STATUS_P1 0x59
105 #define EXPAND10_REG_INT_STATUS_P2 0x5A
106 #define EXPAND10_REG_OUTPUT_PORT_CONFIG 0x5C
107 #define EXPAND10_REG_INT_EDGE_P0A 0x60
108 #define EXPAND10_REG_INT_EDGE_P0B 0x61
109 #define EXPAND10_REG_INT_EDGE_P1A 0x62
110 #define EXPAND10_REG_INT_EDGE_P1B 0x63
111 #define EXPAND10_REG_INT_EDGE_P2A 0x64
112 #define EXPAND10_REG_INT_EDGE_P2B 0x65
113 #define EXPAND10_REG_INT_CLEAR_P0 0x68
114 #define EXPAND10_REG_INT_CLEAR_P1 0x69
115 #define EXPAND10_REG_INT_CLEAR_P2 0x6A
116 #define EXPAND10_REG_INPUT_STATUS_P0 0x6C
117 #define EXPAND10_REG_INPUT_STATUS_P1 0x6D
118 #define EXPAND10_REG_INPUT_STATUS_P2 0x6E
119 #define EXPAND10_REG_PIN_OUTPUT_P0_CONFIG 0x70
120 #define EXPAND10_REG_PIN_OUTPUT_P1_CONFIG 0x71
121 #define EXPAND10_REG_PIN_OUTPUT_P2_CONFIG 0x72
122 #define EXPAND10_REG_SWITCH_DEBOUNCE_EN_0 0x74
123 #define EXPAND10_REG_SWITCH_DEBOUNCE_EN_1 0x75
124 #define EXPAND10_REG_SWITCH_DEBOUNCE_CNT 0x76
125  // expand10_reg
127 
142 #define EXPAND10_NO_PIN_MASK 0x00
143 #define EXPAND10_PIN_0_MASK 0x01
144 #define EXPAND10_PIN_1_MASK 0x02
145 #define EXPAND10_PIN_2_MASK 0x04
146 #define EXPAND10_PIN_3_MASK 0x08
147 #define EXPAND10_PIN_4_MASK 0x10
148 #define EXPAND10_PIN_5_MASK 0x20
149 #define EXPAND10_PIN_6_MASK 0x40
150 #define EXPAND10_PIN_7_MASK 0x80
151 #define EXPAND10_ALL_PINS_MASK 0xFF
152 
157 #define EXPAND10_PORT_0 0x00
158 #define EXPAND10_PORT_1 0x01
159 #define EXPAND10_PORT_2 0x02
160 
165 #define EXPAND10_OUTPUT_DIRECTION 0x00
166 #define EXPAND10_INPUT_DIRECTION 0x01
167 
172 #define EXPAND10_PIN_LOW_LEVEL 0x00
173 #define EXPAND10_PIN_HIGH_LEVEL 0x01
174 
179 #define EXPAND10_AUTO_INCREMENT_BIT 0x80
180 
185 #define EXPAND10_DEVICE_ID 0x000830
186 
191 #define EXPAND10_SOFTWARE_RESET 0x06
192 
197 #define EXPAND10_GEN_CALL_ADDR 0x00
198 #define EXPAND10_DEV_ID_ADDR 0x7C
199 
205 #define EXPAND10_SET_DEV_ADDR_0 0x22
206 #define EXPAND10_SET_DEV_ADDR_1 0x23
207  // expand10_set
209 
224 #define EXPAND10_MAP_MIKROBUS( cfg, mikrobus ) \
225  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
226  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
227  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
228  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
229  // expand10_map // expand10
232 
237 typedef struct
238 {
239  // Output pins
240  digital_out_t rst;
242  // Input pins
243  digital_in_t int_pin;
245  // Modules
246  i2c_master_t i2c;
248  // I2C slave address
249  uint8_t slave_address;
251 } expand10_t;
252 
257 typedef struct
258 {
259  pin_name_t scl;
260  pin_name_t sda;
262  pin_name_t rst;
263  pin_name_t int_pin;
265  uint32_t i2c_speed;
266  uint8_t i2c_address;
269 
274 typedef enum
275 {
277  EXPAND10_ERROR = -1
278 
280 
297 
313 
328 
344 err_t expand10_generic_write ( expand10_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
345 
361 err_t expand10_generic_read ( expand10_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
362 
372 void expand10_set_rst_pin ( expand10_t *ctx, uint8_t logic_level );
373 
383 
397 err_t expand10_write_register ( expand10_t *ctx, uint8_t reg, uint8_t data_in );
398 
412 err_t expand10_read_register ( expand10_t *ctx, uint8_t reg, uint8_t *data_out );
413 
426 
439 
457 err_t expand10_set_pin_direction ( expand10_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask );
458 
472 err_t expand10_set_all_pins_direction ( expand10_t *ctx, uint8_t direction );
473 
486 err_t expand10_set_all_pins_value ( expand10_t *ctx, uint8_t set_mask );
487 
504 err_t expand10_set_pin_value ( expand10_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
505 
521 err_t expand10_read_port_value ( expand10_t *ctx, uint8_t port, uint8_t *data_out );
522 
523 #ifdef __cplusplus
524 }
525 #endif
526 #endif // EXPAND10_H
527  // expand10
529 
530 // ------------------------------------------------------------------------ END
expand10_set_pin_direction
err_t expand10_set_pin_direction(expand10_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask)
Expand 10 set pin direction function.
expand10_t
Expand 10 Click context object.
Definition: expand10.h:238
expand10_software_reset
err_t expand10_software_reset(expand10_t *ctx)
Expand 10 software reset function.
expand10_cfg_setup
void expand10_cfg_setup(expand10_cfg_t *cfg)
Expand 10 configuration object setup function.
expand10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand10.h:265
expand10_generic_read
err_t expand10_generic_read(expand10_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Expand 10 I2C reading function.
EXPAND10_OK
@ EXPAND10_OK
Definition: expand10.h:276
expand10_write_register
err_t expand10_write_register(expand10_t *ctx, uint8_t reg, uint8_t data_in)
Expand 10 write register function.
expand10_set_all_pins_direction
err_t expand10_set_all_pins_direction(expand10_t *ctx, uint8_t direction)
Expand 10 set all pins direction function.
expand10_return_value_t
expand10_return_value_t
Expand 10 Click return value data.
Definition: expand10.h:275
expand10_cfg_t::sda
pin_name_t sda
Definition: expand10.h:260
expand10_default_cfg
err_t expand10_default_cfg(expand10_t *ctx)
Expand 10 default configuration function.
expand10_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand10.h:266
expand10_cfg_t::scl
pin_name_t scl
Definition: expand10.h:259
expand10_check_device_id
err_t expand10_check_device_id(expand10_t *ctx)
Expand 10 check device ID function.
expand10_set_pin_value
err_t expand10_set_pin_value(expand10_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask)
Expand 10 set pin value function.
expand10_cfg_t::int_pin
pin_name_t int_pin
Definition: expand10.h:263
expand10_set_all_pins_value
err_t expand10_set_all_pins_value(expand10_t *ctx, uint8_t set_mask)
Expand 10 set all pins value function.
expand10_generic_write
err_t expand10_generic_write(expand10_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Expand 10 I2C writing function.
expand10_cfg_t::rst
pin_name_t rst
Definition: expand10.h:262
expand10_set_rst_pin
void expand10_set_rst_pin(expand10_t *ctx, uint8_t logic_level)
Expand 10 set RST pin function.
expand10_t::slave_address
uint8_t slave_address
Definition: expand10.h:249
expand10_t::i2c
i2c_master_t i2c
Definition: expand10.h:246
expand10_t::rst
digital_out_t rst
Definition: expand10.h:240
expand10_t::int_pin
digital_in_t int_pin
Definition: expand10.h:243
expand10_read_port_value
err_t expand10_read_port_value(expand10_t *ctx, uint8_t port, uint8_t *data_out)
Expand 10 read port value function.
expand10_init
err_t expand10_init(expand10_t *ctx, expand10_cfg_t *cfg)
Expand 10 initialization function.
expand10_cfg_t
Expand 10 Click configuration object.
Definition: expand10.h:258
EXPAND10_ERROR
@ EXPAND10_ERROR
Definition: expand10.h:277
expand10_get_int_pin
uint8_t expand10_get_int_pin(expand10_t *ctx)
Expand 10 get INT pin function.
expand10_read_register
err_t expand10_read_register(expand10_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 10 read register function.