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
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 EXPAND16_REG_DEV_ID_AND_CTRL 0x01
74#define EXPAND16_REG_IO_DIRECTION 0x03
75#define EXPAND16_REG_OUTPUT_STATE 0x05
76#define EXPAND16_REG_OUTPUT_HIGH_Z 0x07
77#define EXPAND16_REG_INPUT_DEF_STATE 0x09
78#define EXPAND16_REG_PULL_ENABLE 0x0B
79#define EXPAND16_REG_PULL_DOWN_UP 0x0D
80#define EXPAND16_REG_INPUT_STATE 0x0F
81#define EXPAND16_REG_INTERRUPT_MASK 0x11
82#define EXPAND16_REG_INTERRUPT_STATUS 0x13
83
84 // expand16_reg
85
100#define EXPAND16_PIN_MASK_NONE 0x00
101#define EXPAND16_PIN_MASK_GPIO_0 0x01
102#define EXPAND16_PIN_MASK_GPIO_1 0x02
103#define EXPAND16_PIN_MASK_GPIO_2 0x04
104#define EXPAND16_PIN_MASK_GPIO_3 0x08
105#define EXPAND16_PIN_MASK_GPIO_4 0x10
106#define EXPAND16_PIN_MASK_GPIO_5 0x20
107#define EXPAND16_PIN_MASK_GPIO_6 0x40
108#define EXPAND16_PIN_MASK_GPIO_7 0x80
109#define EXPAND16_PIN_MASK_ALL 0xFF
110
115#define EXPAND16_SW_RESET_CMD 0x01
116
121#define EXPAND16_DEVICE_ID 0xA0
122#define EXPAND16_DEVICE_ID_MASK 0xE0
123
128#define EXPAND16_PIN_STATE_HIGH 0x01
129#define EXPAND16_PIN_STATE_LOW 0x00
130
136#define EXPAND16_DEVICE_ADDRESS_GND 0x43
137#define EXPAND16_DEVICE_ADDRESS_VCC 0x44
138
139 // expand16_set
140
155#define EXPAND16_MAP_MIKROBUS( cfg, mikrobus ) \
156 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
157 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
158 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
159 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
160
161 // expand16_map
162 // expand16
163
168typedef struct
169{
170 // Output pins
171 digital_out_t rst;
173 // Input pins
174 digital_in_t int_pin;
176 // Modules
177 i2c_master_t i2c;
179 // I2C slave address
182} expand16_t;
183
188typedef struct
189{
190 pin_name_t scl;
191 pin_name_t sda;
193 pin_name_t rst;
194 pin_name_t int_pin;
196 uint32_t i2c_speed;
197 uint8_t i2c_address;
200
205typedef enum
206{
208 EXPAND16_ERROR = -1
209
211
228
243
257
272err_t expand16_generic_write ( expand16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
273
288err_t expand16_generic_read ( expand16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
289
299void expand16_set_rst_pin ( expand16_t *ctx, uint8_t pin_state );
300
310
320
333err_t expand16_write_reg ( expand16_t *ctx, uint8_t reg, uint8_t data_in );
334
347err_t expand16_read_reg ( expand16_t *ctx, uint8_t reg, uint8_t *data_out );
348
361err_t expand16_set_io_dir ( expand16_t *ctx, uint8_t input_pins, uint8_t output_pins );
362
375err_t expand16_set_output_state ( expand16_t *ctx, uint8_t clr_mask, uint8_t set_mask );
376
377#ifdef __cplusplus
378}
379#endif
380#endif // EXPAND16_H
381
382 // expand16
383
384// ------------------------------------------------------------------------ END
expand16_return_value_t
Expand 16 Click return value data.
Definition expand16.h:206
@ EXPAND16_OK
Definition expand16.h:207
@ EXPAND16_ERROR
Definition expand16.h:208
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:189
uint32_t i2c_speed
Definition expand16.h:196
pin_name_t scl
Definition expand16.h:190
pin_name_t int_pin
Definition expand16.h:194
pin_name_t sda
Definition expand16.h:191
pin_name_t rst
Definition expand16.h:193
uint8_t i2c_address
Definition expand16.h:197
Expand 16 Click context object.
Definition expand16.h:169
digital_in_t int_pin
Definition expand16.h:174
i2c_master_t i2c
Definition expand16.h:177
digital_out_t rst
Definition expand16.h:171
uint8_t slave_address
Definition expand16.h:180