expand16 2.1.0.0
expand16.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 EXPAND16_H
29#define EXPAND16_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 EXPAND16_REG_DEV_ID_AND_CTRL 0x01
60#define EXPAND16_REG_IO_DIRECTION 0x03
61#define EXPAND16_REG_OUTPUT_STATE 0x05
62#define EXPAND16_REG_OUTPUT_HIGH_Z 0x07
63#define EXPAND16_REG_INPUT_DEF_STATE 0x09
64#define EXPAND16_REG_PULL_ENABLE 0x0B
65#define EXPAND16_REG_PULL_DOWN_UP 0x0D
66#define EXPAND16_REG_INPUT_STATE 0x0F
67#define EXPAND16_REG_INTERRUPT_MASK 0x11
68#define EXPAND16_REG_INTERRUPT_STATUS 0x13
69 // expand16_reg
71
86#define EXPAND16_PIN_MASK_NONE 0x00
87#define EXPAND16_PIN_MASK_GPIO_0 0x01
88#define EXPAND16_PIN_MASK_GPIO_1 0x02
89#define EXPAND16_PIN_MASK_GPIO_2 0x04
90#define EXPAND16_PIN_MASK_GPIO_3 0x08
91#define EXPAND16_PIN_MASK_GPIO_4 0x10
92#define EXPAND16_PIN_MASK_GPIO_5 0x20
93#define EXPAND16_PIN_MASK_GPIO_6 0x40
94#define EXPAND16_PIN_MASK_GPIO_7 0x80
95#define EXPAND16_PIN_MASK_ALL 0xFF
96
101#define EXPAND16_SW_RESET_CMD 0x01
102
107#define EXPAND16_DEVICE_ID 0xA0
108#define EXPAND16_DEVICE_ID_MASK 0xE0
109
114#define EXPAND16_PIN_STATE_HIGH 0x01
115#define EXPAND16_PIN_STATE_LOW 0x00
116
122#define EXPAND16_DEVICE_ADDRESS_GND 0x43
123#define EXPAND16_DEVICE_ADDRESS_VCC 0x44
124 // expand16_set
126
141#define EXPAND16_MAP_MIKROBUS( cfg, mikrobus ) \
142 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
143 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
144 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
145 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
146 // expand16_map // expand16
149
154typedef struct
155{
156 // Output pins
157 digital_out_t rst;
159 // Input pins
160 digital_in_t int_pin;
162 // Modules
163 i2c_master_t i2c;
165 // I2C slave address
168} expand16_t;
169
174typedef struct
175{
176 pin_name_t scl;
177 pin_name_t sda;
179 pin_name_t rst;
180 pin_name_t int_pin;
182 uint32_t i2c_speed;
183 uint8_t i2c_address;
186
191typedef enum
192{
194 EXPAND16_ERROR = -1
195
197
214
229
243
258err_t expand16_generic_write ( expand16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
259
274err_t expand16_generic_read ( expand16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
275
285void expand16_set_rst_pin ( expand16_t *ctx, uint8_t pin_state );
286
296
306
319err_t expand16_write_reg ( expand16_t *ctx, uint8_t reg, uint8_t data_in );
320
333err_t expand16_read_reg ( expand16_t *ctx, uint8_t reg, uint8_t *data_out );
334
347err_t expand16_set_io_dir ( expand16_t *ctx, uint8_t input_pins, uint8_t output_pins );
348
361err_t expand16_set_output_state ( expand16_t *ctx, uint8_t clr_mask, uint8_t set_mask );
362
363#ifdef __cplusplus
364}
365#endif
366#endif // EXPAND16_H
367 // expand16
369
370// ------------------------------------------------------------------------ END
expand16_return_value_t
Expand 16 Click return value data.
Definition: expand16.h:192
@ EXPAND16_OK
Definition: expand16.h:193
@ EXPAND16_ERROR
Definition: expand16.h:194
err_t expand16_init(expand16_t *ctx, expand16_cfg_t *cfg)
Expand 16 initialization function.
void expand16_set_rst_pin(expand16_t *ctx, uint8_t pin_state)
Expand 16 set RST pin state function.
err_t expand16_set_output_state(expand16_t *ctx, uint8_t clr_mask, uint8_t set_mask)
Expand 16 set output pins state function.
void expand16_cfg_setup(expand16_cfg_t *cfg)
Expand 16 configuration object setup function.
uint8_t expand16_get_int_pin(expand16_t *ctx)
Expand 16 get INT pin function.
void expand16_hw_reset(expand16_t *ctx)
Expand 16 Hardware reset function.
err_t expand16_generic_write(expand16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Expand 16 I2C writing function.
err_t expand16_set_io_dir(expand16_t *ctx, uint8_t input_pins, uint8_t output_pins)
Expand 16 set pin input or output direction function.
err_t expand16_read_reg(expand16_t *ctx, uint8_t reg, uint8_t *data_out)
Expand 16 register read function.
err_t expand16_default_cfg(expand16_t *ctx)
Expand 16 default configuration function.
err_t expand16_generic_read(expand16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Expand 16 I2C reading function.
err_t expand16_write_reg(expand16_t *ctx, uint8_t reg, uint8_t data_in)
Expand 16 register write function.
Expand 16 Click configuration object.
Definition: expand16.h:175
uint32_t i2c_speed
Definition: expand16.h:182
pin_name_t scl
Definition: expand16.h:176
pin_name_t int_pin
Definition: expand16.h:180
pin_name_t sda
Definition: expand16.h:177
pin_name_t rst
Definition: expand16.h:179
uint8_t i2c_address
Definition: expand16.h:183
Expand 16 Click context object.
Definition: expand16.h:155
digital_in_t int_pin
Definition: expand16.h:160
i2c_master_t i2c
Definition: expand16.h:163
digital_out_t rst
Definition: expand16.h:157
uint8_t slave_address
Definition: expand16.h:166