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
32extern "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 EXPAND10_REG_INPUT_P0 0x00
60#define EXPAND10_REG_INPUT_P1 0x01
61#define EXPAND10_REG_INPUT_P2 0x02
62#define EXPAND10_REG_OUTPUT_P0 0x04
63#define EXPAND10_REG_OUTPUT_P1 0x05
64#define EXPAND10_REG_OUTPUT_P2 0x06
65#define EXPAND10_REG_POLARITY_INV_P0 0x08
66#define EXPAND10_REG_POLARITY_INV_P1 0x09
67#define EXPAND10_REG_POLARITY_INV_P2 0x0A
68#define EXPAND10_REG_CONFIG_P0 0x0C
69#define EXPAND10_REG_CONFIG_P1 0x0D
70#define EXPAND10_REG_CONFIG_P2 0x0E
71#define EXPAND10_REG_OUTPUT_DRIVE_P0A 0x40
72#define EXPAND10_REG_OUTPUT_DRIVE_P0B 0x41
73#define EXPAND10_REG_OUTPUT_DRIVE_P1A 0x42
74#define EXPAND10_REG_OUTPUT_DRIVE_P1B 0x43
75#define EXPAND10_REG_OUTPUT_DRIVE_P2A 0x44
76#define EXPAND10_REG_OUTPUT_DRIVE_P2B 0x45
77#define EXPAND10_REG_INPUT_LAT_P0 0x48
78#define EXPAND10_REG_INPUT_LAT_P1 0x49
79#define EXPAND10_REG_INPUT_LAT_P2 0x4A
80#define EXPAND10_REG_PULL_ENABLE_P0 0x4C
81#define EXPAND10_REG_PULL_ENABLE_P1 0x4D
82#define EXPAND10_REG_PULL_ENABLE_P2 0x4E
83#define EXPAND10_REG_PULL_SELECTION_P0 0x50
84#define EXPAND10_REG_PULL_SELECTION_P1 0x51
85#define EXPAND10_REG_PULL_SELECTION_P2 0x52
86#define EXPAND10_REG_INT_MASK_P0 0x54
87#define EXPAND10_REG_INT_MASK_P1 0x55
88#define EXPAND10_REG_INT_MASK_P2 0x56
89#define EXPAND10_REG_INT_STATUS_P0 0x58
90#define EXPAND10_REG_INT_STATUS_P1 0x59
91#define EXPAND10_REG_INT_STATUS_P2 0x5A
92#define EXPAND10_REG_OUTPUT_PORT_CONFIG 0x5C
93#define EXPAND10_REG_INT_EDGE_P0A 0x60
94#define EXPAND10_REG_INT_EDGE_P0B 0x61
95#define EXPAND10_REG_INT_EDGE_P1A 0x62
96#define EXPAND10_REG_INT_EDGE_P1B 0x63
97#define EXPAND10_REG_INT_EDGE_P2A 0x64
98#define EXPAND10_REG_INT_EDGE_P2B 0x65
99#define EXPAND10_REG_INT_CLEAR_P0 0x68
100#define EXPAND10_REG_INT_CLEAR_P1 0x69
101#define EXPAND10_REG_INT_CLEAR_P2 0x6A
102#define EXPAND10_REG_INPUT_STATUS_P0 0x6C
103#define EXPAND10_REG_INPUT_STATUS_P1 0x6D
104#define EXPAND10_REG_INPUT_STATUS_P2 0x6E
105#define EXPAND10_REG_PIN_OUTPUT_P0_CONFIG 0x70
106#define EXPAND10_REG_PIN_OUTPUT_P1_CONFIG 0x71
107#define EXPAND10_REG_PIN_OUTPUT_P2_CONFIG 0x72
108#define EXPAND10_REG_SWITCH_DEBOUNCE_EN_0 0x74
109#define EXPAND10_REG_SWITCH_DEBOUNCE_EN_1 0x75
110#define EXPAND10_REG_SWITCH_DEBOUNCE_CNT 0x76
111 // expand10_reg
113
128#define EXPAND10_NO_PIN_MASK 0x00
129#define EXPAND10_PIN_0_MASK 0x01
130#define EXPAND10_PIN_1_MASK 0x02
131#define EXPAND10_PIN_2_MASK 0x04
132#define EXPAND10_PIN_3_MASK 0x08
133#define EXPAND10_PIN_4_MASK 0x10
134#define EXPAND10_PIN_5_MASK 0x20
135#define EXPAND10_PIN_6_MASK 0x40
136#define EXPAND10_PIN_7_MASK 0x80
137#define EXPAND10_ALL_PINS_MASK 0xFF
138
143#define EXPAND10_PORT_0 0x00
144#define EXPAND10_PORT_1 0x01
145#define EXPAND10_PORT_2 0x02
146
151#define EXPAND10_OUTPUT_DIRECTION 0x00
152#define EXPAND10_INPUT_DIRECTION 0x01
153
158#define EXPAND10_PIN_LOW_LEVEL 0x00
159#define EXPAND10_PIN_HIGH_LEVEL 0x01
160
165#define EXPAND10_AUTO_INCREMENT_BIT 0x80
166
171#define EXPAND10_DEVICE_ID 0x000830
172
177#define EXPAND10_SOFTWARE_RESET 0x06
178
183#define EXPAND10_GEN_CALL_ADDR 0x00
184#define EXPAND10_DEV_ID_ADDR 0x7C
185
191#define EXPAND10_SET_DEV_ADDR_0 0x22
192#define EXPAND10_SET_DEV_ADDR_1 0x23
193 // expand10_set
195
210#define EXPAND10_MAP_MIKROBUS( cfg, mikrobus ) \
211 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
212 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
213 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
214 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
215 // expand10_map // expand10
218
223typedef struct
224{
225 // Output pins
226 digital_out_t rst;
228 // Input pins
229 digital_in_t int_pin;
231 // Modules
232 i2c_master_t i2c;
234 // I2C slave address
237} expand10_t;
238
243typedef struct
244{
245 pin_name_t scl;
246 pin_name_t sda;
248 pin_name_t rst;
249 pin_name_t int_pin;
251 uint32_t i2c_speed;
252 uint8_t i2c_address;
255
260typedef enum
261{
263 EXPAND10_ERROR = -1
264
266
283
299
314
330err_t expand10_generic_write ( expand10_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
331
347err_t expand10_generic_read ( expand10_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
348
358void expand10_set_rst_pin ( expand10_t *ctx, uint8_t logic_level );
359
369
383err_t expand10_write_register ( expand10_t *ctx, uint8_t reg, uint8_t data_in );
384
398err_t expand10_read_register ( expand10_t *ctx, uint8_t reg, uint8_t *data_out );
399
412
425
443err_t expand10_set_pin_direction ( expand10_t *ctx, uint8_t direction, uint8_t port, uint8_t pin_mask );
444
458err_t expand10_set_all_pins_direction ( expand10_t *ctx, uint8_t direction );
459
472err_t expand10_set_all_pins_value ( expand10_t *ctx, uint8_t set_mask );
473
490err_t expand10_set_pin_value ( expand10_t *ctx, uint8_t port, uint8_t clr_mask, uint8_t set_mask );
491
507err_t expand10_read_port_value ( expand10_t *ctx, uint8_t port, uint8_t *data_out );
508
509#ifdef __cplusplus
510}
511#endif
512#endif // EXPAND10_H
513 // expand10
515
516// ------------------------------------------------------------------------ END
expand10_return_value_t
Expand 10 Click return value data.
Definition: expand10.h:261
@ EXPAND10_ERROR
Definition: expand10.h:263
@ EXPAND10_OK
Definition: expand10.h:262
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.
void expand10_set_rst_pin(expand10_t *ctx, uint8_t logic_level)
Expand 10 set RST pin function.
void expand10_cfg_setup(expand10_cfg_t *cfg)
Expand 10 configuration object setup function.
err_t expand10_write_register(expand10_t *ctx, uint8_t reg, uint8_t data_in)
Expand 10 write register function.
err_t expand10_set_all_pins_direction(expand10_t *ctx, uint8_t direction)
Expand 10 set all pins direction function.
err_t expand10_generic_write(expand10_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Expand 10 I2C writing function.
err_t expand10_check_device_id(expand10_t *ctx)
Expand 10 check device ID function.
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.
err_t expand10_init(expand10_t *ctx, expand10_cfg_t *cfg)
Expand 10 initialization function.
uint8_t expand10_get_int_pin(expand10_t *ctx)
Expand 10 get INT pin function.
err_t expand10_read_register(expand10_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 10 read register function.
err_t expand10_software_reset(expand10_t *ctx)
Expand 10 software reset function.
err_t expand10_read_port_value(expand10_t *ctx, uint8_t port, uint8_t *data_out)
Expand 10 read port value function.
err_t expand10_generic_read(expand10_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Expand 10 I2C reading function.
err_t expand10_default_cfg(expand10_t *ctx)
Expand 10 default configuration function.
err_t expand10_set_all_pins_value(expand10_t *ctx, uint8_t set_mask)
Expand 10 set all pins value function.
Expand 10 Click configuration object.
Definition: expand10.h:244
uint32_t i2c_speed
Definition: expand10.h:251
pin_name_t scl
Definition: expand10.h:245
pin_name_t int_pin
Definition: expand10.h:249
pin_name_t sda
Definition: expand10.h:246
pin_name_t rst
Definition: expand10.h:248
uint8_t i2c_address
Definition: expand10.h:252
Expand 10 Click context object.
Definition: expand10.h:224
digital_in_t int_pin
Definition: expand10.h:229
i2c_master_t i2c
Definition: expand10.h:232
digital_out_t rst
Definition: expand10.h:226
uint8_t slave_address
Definition: expand10.h:235