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 
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 EXPAND10_REG_INPUT_P0 0x00
70 #define EXPAND10_REG_INPUT_P1 0x01
71 #define EXPAND10_REG_INPUT_P2 0x02
72 #define EXPAND10_REG_OUTPUT_P0 0x04
73 #define EXPAND10_REG_OUTPUT_P1 0x05
74 #define EXPAND10_REG_OUTPUT_P2 0x06
75 #define EXPAND10_REG_POLARITY_INV_P0 0x08
76 #define EXPAND10_REG_POLARITY_INV_P1 0x09
77 #define EXPAND10_REG_POLARITY_INV_P2 0x0A
78 #define EXPAND10_REG_CONFIG_P0 0x0C
79 #define EXPAND10_REG_CONFIG_P1 0x0D
80 #define EXPAND10_REG_CONFIG_P2 0x0E
81 #define EXPAND10_REG_OUTPUT_DRIVE_P0A 0x40
82 #define EXPAND10_REG_OUTPUT_DRIVE_P0B 0x41
83 #define EXPAND10_REG_OUTPUT_DRIVE_P1A 0x42
84 #define EXPAND10_REG_OUTPUT_DRIVE_P1B 0x43
85 #define EXPAND10_REG_OUTPUT_DRIVE_P2A 0x44
86 #define EXPAND10_REG_OUTPUT_DRIVE_P2B 0x45
87 #define EXPAND10_REG_INPUT_LAT_P0 0x48
88 #define EXPAND10_REG_INPUT_LAT_P1 0x49
89 #define EXPAND10_REG_INPUT_LAT_P2 0x4A
90 #define EXPAND10_REG_PULL_ENABLE_P0 0x4C
91 #define EXPAND10_REG_PULL_ENABLE_P1 0x4D
92 #define EXPAND10_REG_PULL_ENABLE_P2 0x4E
93 #define EXPAND10_REG_PULL_SELECTION_P0 0x50
94 #define EXPAND10_REG_PULL_SELECTION_P1 0x51
95 #define EXPAND10_REG_PULL_SELECTION_P2 0x52
96 #define EXPAND10_REG_INT_MASK_P0 0x54
97 #define EXPAND10_REG_INT_MASK_P1 0x55
98 #define EXPAND10_REG_INT_MASK_P2 0x56
99 #define EXPAND10_REG_INT_STATUS_P0 0x58
100 #define EXPAND10_REG_INT_STATUS_P1 0x59
101 #define EXPAND10_REG_INT_STATUS_P2 0x5A
102 #define EXPAND10_REG_OUTPUT_PORT_CONFIG 0x5C
103 #define EXPAND10_REG_INT_EDGE_P0A 0x60
104 #define EXPAND10_REG_INT_EDGE_P0B 0x61
105 #define EXPAND10_REG_INT_EDGE_P1A 0x62
106 #define EXPAND10_REG_INT_EDGE_P1B 0x63
107 #define EXPAND10_REG_INT_EDGE_P2A 0x64
108 #define EXPAND10_REG_INT_EDGE_P2B 0x65
109 #define EXPAND10_REG_INT_CLEAR_P0 0x68
110 #define EXPAND10_REG_INT_CLEAR_P1 0x69
111 #define EXPAND10_REG_INT_CLEAR_P2 0x6A
112 #define EXPAND10_REG_INPUT_STATUS_P0 0x6C
113 #define EXPAND10_REG_INPUT_STATUS_P1 0x6D
114 #define EXPAND10_REG_INPUT_STATUS_P2 0x6E
115 #define EXPAND10_REG_PIN_OUTPUT_P0_CONFIG 0x70
116 #define EXPAND10_REG_PIN_OUTPUT_P1_CONFIG 0x71
117 #define EXPAND10_REG_PIN_OUTPUT_P2_CONFIG 0x72
118 #define EXPAND10_REG_SWITCH_DEBOUNCE_EN_0 0x74
119 #define EXPAND10_REG_SWITCH_DEBOUNCE_EN_1 0x75
120 #define EXPAND10_REG_SWITCH_DEBOUNCE_CNT 0x76
121  // expand10_reg
123 
138 #define EXPAND10_NO_PIN_MASK 0x00
139 #define EXPAND10_PIN_0_MASK 0x01
140 #define EXPAND10_PIN_1_MASK 0x02
141 #define EXPAND10_PIN_2_MASK 0x04
142 #define EXPAND10_PIN_3_MASK 0x08
143 #define EXPAND10_PIN_4_MASK 0x10
144 #define EXPAND10_PIN_5_MASK 0x20
145 #define EXPAND10_PIN_6_MASK 0x40
146 #define EXPAND10_PIN_7_MASK 0x80
147 #define EXPAND10_ALL_PINS_MASK 0xFF
148 
153 #define EXPAND10_PORT_0 0x00
154 #define EXPAND10_PORT_1 0x01
155 #define EXPAND10_PORT_2 0x02
156 
161 #define EXPAND10_OUTPUT_DIRECTION 0x00
162 #define EXPAND10_INPUT_DIRECTION 0x01
163 
168 #define EXPAND10_PIN_LOW_LEVEL 0x00
169 #define EXPAND10_PIN_HIGH_LEVEL 0x01
170 
175 #define EXPAND10_AUTO_INCREMENT_BIT 0x80
176 
181 #define EXPAND10_DEVICE_ID 0x000830
182 
187 #define EXPAND10_SOFTWARE_RESET 0x06
188 
193 #define EXPAND10_GEN_CALL_ADDR 0x00
194 #define EXPAND10_DEV_ID_ADDR 0x7C
195 
201 #define EXPAND10_SET_DEV_ADDR_0 0x22
202 #define EXPAND10_SET_DEV_ADDR_1 0x23
203  // expand10_set
205 
220 #define EXPAND10_MAP_MIKROBUS( cfg, mikrobus ) \
221  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
222  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
223  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
224  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
225  // expand10_map // expand10
228 
233 typedef struct
234 {
235  // Output pins
236  digital_out_t rst;
238  // Input pins
239  digital_in_t int_pin;
241  // Modules
242  i2c_master_t i2c;
244  // I2C slave address
245  uint8_t slave_address;
247 } expand10_t;
248 
253 typedef struct
254 {
255  pin_name_t scl;
256  pin_name_t sda;
258  pin_name_t rst;
259  pin_name_t int_pin;
261  uint32_t i2c_speed;
262  uint8_t i2c_address;
265 
270 typedef enum
271 {
273  EXPAND10_ERROR = -1
274 
276 
293 
309 
324 
340 err_t expand10_generic_write ( expand10_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
341 
357 err_t expand10_generic_read ( expand10_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
358 
368 void expand10_set_rst_pin ( expand10_t *ctx, uint8_t logic_level );
369 
379 
393 err_t expand10_write_register ( expand10_t *ctx, uint8_t reg, uint8_t data_in );
394 
408 err_t expand10_read_register ( expand10_t *ctx, uint8_t reg, uint8_t *data_out );
409 
422 
435 
453 err_t expand10_set_pin_direction ( expand10_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask );
454 
468 err_t expand10_set_all_pins_direction ( expand10_t *ctx, uint8_t direction );
469 
482 err_t expand10_set_all_pins_value ( expand10_t *ctx, uint8_t set_mask );
483 
500 err_t expand10_set_pin_value ( expand10_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
501 
517 err_t expand10_read_port_value ( expand10_t *ctx, uint8_t port, uint8_t *data_out );
518 
519 #ifdef __cplusplus
520 }
521 #endif
522 #endif // EXPAND10_H
523  // expand10
525 
526 // ------------------------------------------------------------------------ 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:234
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:261
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:272
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:271
expand10_cfg_t::sda
pin_name_t sda
Definition: expand10.h:256
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:262
expand10_cfg_t::scl
pin_name_t scl
Definition: expand10.h:255
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:259
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:258
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:245
expand10_t::i2c
i2c_master_t i2c
Definition: expand10.h:242
expand10_t::rst
digital_out_t rst
Definition: expand10.h:236
expand10_t::int_pin
digital_in_t int_pin
Definition: expand10.h:239
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:254
EXPAND10_ERROR
@ EXPAND10_ERROR
Definition: expand10.h:273
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.