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 "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 EXPAND16_REG_DEV_ID_AND_CTRL 0x01
70#define EXPAND16_REG_IO_DIRECTION 0x03
71#define EXPAND16_REG_OUTPUT_STATE 0x05
72#define EXPAND16_REG_OUTPUT_HIGH_Z 0x07
73#define EXPAND16_REG_INPUT_DEF_STATE 0x09
74#define EXPAND16_REG_PULL_ENABLE 0x0B
75#define EXPAND16_REG_PULL_DOWN_UP 0x0D
76#define EXPAND16_REG_INPUT_STATE 0x0F
77#define EXPAND16_REG_INTERRUPT_MASK 0x11
78#define EXPAND16_REG_INTERRUPT_STATUS 0x13
79 // expand16_reg
81
96#define EXPAND16_PIN_MASK_NONE 0x00
97#define EXPAND16_PIN_MASK_GPIO_0 0x01
98#define EXPAND16_PIN_MASK_GPIO_1 0x02
99#define EXPAND16_PIN_MASK_GPIO_2 0x04
100#define EXPAND16_PIN_MASK_GPIO_3 0x08
101#define EXPAND16_PIN_MASK_GPIO_4 0x10
102#define EXPAND16_PIN_MASK_GPIO_5 0x20
103#define EXPAND16_PIN_MASK_GPIO_6 0x40
104#define EXPAND16_PIN_MASK_GPIO_7 0x80
105#define EXPAND16_PIN_MASK_ALL 0xFF
106
111#define EXPAND16_SW_RESET_CMD 0x01
112
117#define EXPAND16_DEVICE_ID 0xA0
118#define EXPAND16_DEVICE_ID_MASK 0xE0
119
124#define EXPAND16_PIN_STATE_HIGH 0x01
125#define EXPAND16_PIN_STATE_LOW 0x00
126
132#define EXPAND16_DEVICE_ADDRESS_GND 0x43
133#define EXPAND16_DEVICE_ADDRESS_VCC 0x44
134 // expand16_set
136
151#define EXPAND16_MAP_MIKROBUS( cfg, mikrobus ) \
152 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
153 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
154 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
155 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
156 // expand16_map // expand16
159
164typedef struct
165{
166 // Output pins
167 digital_out_t rst;
169 // Input pins
170 digital_in_t int_pin;
172 // Modules
173 i2c_master_t i2c;
175 // I2C slave address
178} expand16_t;
179
184typedef struct
185{
186 pin_name_t scl;
187 pin_name_t sda;
189 pin_name_t rst;
190 pin_name_t int_pin;
192 uint32_t i2c_speed;
193 uint8_t i2c_address;
196
201typedef enum
202{
204 EXPAND16_ERROR = -1
205
207
224
239
253
268err_t expand16_generic_write ( expand16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
269
284err_t expand16_generic_read ( expand16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
285
295void expand16_set_rst_pin ( expand16_t *ctx, uint8_t pin_state );
296
306
316
329err_t expand16_write_reg ( expand16_t *ctx, uint8_t reg, uint8_t data_in );
330
343err_t expand16_read_reg ( expand16_t *ctx, uint8_t reg, uint8_t *data_out );
344
357err_t expand16_set_io_dir ( expand16_t *ctx, uint8_t input_pins, uint8_t output_pins );
358
371err_t expand16_set_output_state ( expand16_t *ctx, uint8_t clr_mask, uint8_t set_mask );
372
373#ifdef __cplusplus
374}
375#endif
376#endif // EXPAND16_H
377 // expand16
379
380// ------------------------------------------------------------------------ END
expand16_return_value_t
Expand 16 Click return value data.
Definition: expand16.h:202
@ EXPAND16_OK
Definition: expand16.h:203
@ EXPAND16_ERROR
Definition: expand16.h:204
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:185
uint32_t i2c_speed
Definition: expand16.h:192
pin_name_t scl
Definition: expand16.h:186
pin_name_t int_pin
Definition: expand16.h:190
pin_name_t sda
Definition: expand16.h:187
pin_name_t rst
Definition: expand16.h:189
uint8_t i2c_address
Definition: expand16.h:193
Expand 16 Click context object.
Definition: expand16.h:165
digital_in_t int_pin
Definition: expand16.h:170
i2c_master_t i2c
Definition: expand16.h:173
digital_out_t rst
Definition: expand16.h:167
uint8_t slave_address
Definition: expand16.h:176