expand5 2.0.0.0
expand5.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
32// ----------------------------------------------------------------------------
33
34#ifndef EXPAND5_H
35#define EXPAND5_H
36
37#include "drv_digital_out.h"
38#include "drv_digital_in.h"
39#include "drv_i2c_master.h"
40
41// -------------------------------------------------------------- PUBLIC MACROS
51#define EXPAND5_MAP_MIKROBUS( cfg, mikrobus ) \
52 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
55 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
62#define EXPAND5_RETVAL uint8_t
63
64#define EXPAND5_OK 0x00
65#define EXPAND5_INIT_ERROR 0xFF
72#define EXPAND5_I2C_ADR_GND 0x22
73#define EXPAND5_I2C_ADR_VCC 0x23
80#define EXPAND5_RA_IN_0 0x00
81#define EXPAND5_RA_IN_1 0x01
82#define EXPAND5_RA_IN_2 0x02
83#define EXPAND5_RA_OUT_0 0x04
84#define EXPAND5_RA_OUT_1 0x05
85#define EXPAND5_RA_OUT_2 0x06
86#define EXPAND5_RA_POL_0 0x08
87#define EXPAND5_RA_POL_1 0x09
88#define EXPAND5_RA_POL_2 0x0A
89#define EXPAND5_RA_CFG_0 0x0C
90#define EXPAND5_RA_CFG_1 0x0D
91#define EXPAND5_RA_CFG_2 0x0E
92
93#define EXPAND5_AUTO_INC 0x80
94
95#define EXPAND5_LOW 0
96#define EXPAND5_HIGH 1
97
98#define EXPAND5_POL_NORMAL 0
99#define EXPAND5_POL_INVERTED 1
100
101#define EXPAND5_OUT 0
102#define EXPAND5_IN 1
103
104#define EXPAND5_P00 0
105#define EXPAND5_P01 1
106#define EXPAND5_P02 2
107#define EXPAND5_P03 3
108#define EXPAND5_P04 4
109#define EXPAND5_P05 5
110#define EXPAND5_P06 6
111#define EXPAND5_P07 7
112#define EXPAND5_P10 8
113#define EXPAND5_P11 9
114#define EXPAND5_P12 10
115#define EXPAND5_P13 11
116#define EXPAND5_P14 12
117#define EXPAND5_P15 13
118#define EXPAND5_P16 14
119#define EXPAND5_P17 15
120#define EXPAND5_P20 16
121#define EXPAND5_P21 17
122#define EXPAND5_P22 18
123#define EXPAND5_P23 19
124#define EXPAND5_P24 20
125#define EXPAND5_P25 21
126#define EXPAND5_P26 22
127#define EXPAND5_P27 23 // End group macro
131// --------------------------------------------------------------- PUBLIC TYPES
140typedef struct
141{
142 // Output pins
143
144 digital_out_t rst;
145
146 // Input pins
147
148 digital_in_t int_pin;
149
150 // Modules
151
152 i2c_master_t i2c;
153
154 // ctx variable
155
157
158} expand5_t;
159
163typedef struct
164{
165 // Communication gpio pins
166
167 pin_name_t scl;
168 pin_name_t sda;
169
170 // Additional gpio pins
171
172 pin_name_t rst;
173 pin_name_t int_pin;
174
175 // static variable
176
177 uint32_t i2c_speed;
178 uint8_t i2c_address;
179
181 // End types group
183// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184
190#ifdef __cplusplus
191extern "C"{
192#endif
193
203
213
224void expand5_generic_write ( expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
225
237void expand5_generic_read ( expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
238
250uint8_t expand5_read_bit ( expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num );
251
262void expand5_write_bit ( expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num, uint8_t pin_val );
263
274uint8_t expand5_read_pin ( expand5_t *ctx, uint16_t pin );
275
286uint8_t expand5_read_bank ( expand5_t *ctx, uint8_t bank );
287
298void expand5_read_all_banks ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
299
312uint8_t expand5_get_pin_out_lvl ( expand5_t *ctx, uint16_t pin );
313
326uint8_t expand5_get_bank_out_lvl ( expand5_t *ctx, uint8_t bank );
327
340void expand5_get_all_banks_out_lvl ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
341
351void expand5_write_pin ( expand5_t *ctx, uint16_t pin, uint8_t pin_val );
352
362void expand5_write_bank ( expand5_t *ctx, uint8_t bank, uint8_t value );
363
374void expand5_write_all_banks ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
375
386uint8_t expand5_get_pin_pol ( expand5_t *ctx, uint16_t pin );
387
398uint8_t expand5_get_bank_pol ( expand5_t *ctx, uint8_t bank );
399
410void expand5_get_all_banks_pol ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
411
421void expand5_set_pin_pol ( expand5_t *ctx, uint16_t pin, uint8_t polarity );
422
432void expand5_set_bank_pol ( expand5_t *ctx, uint8_t bank, uint8_t polarity );
433
444void expand5_set_all_banks_pol ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
445
456uint8_t expand5_get_pin_dir ( expand5_t *ctx, uint16_t pin );
457
468uint8_t expand5_get_bank_dir ( expand5_t *ctx, uint8_t bank );
469
480void expand5_get_all_dir ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
481
491void expand5_set_pin_dir( expand5_t *ctx, uint16_t pin, uint8_t direction );
492
502void expand5_set_bank_dir ( expand5_t *ctx, uint8_t bank, uint8_t direction );
503
514void expand5_set_all_dir ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
515
525
538
539#ifdef __cplusplus
540}
541#endif
542#endif // _EXPAND5_H_
543 // End public_function group
546
547// ------------------------------------------------------------------------- END
#define EXPAND5_RETVAL
Definition: expand5.h:62
void expand5_generic_write(expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t expand5_get_pin_dir(expand5_t *ctx, uint16_t pin)
Get a single pin's direction ( I/O ) setting function.
void expand5_set_all_dir(expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2)
Set all pin direction ( I/O ) settings in all banks function.
void expand5_set_bank_dir(expand5_t *ctx, uint8_t bank, uint8_t direction)
Set all pin direction ( I/O ) settings in one bank function.
void expand5_read_all_banks(expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2)
Get all pins logic levels from all banks function.
uint8_t expand5_get_bank_pol(expand5_t *ctx, uint8_t bank)
Get all pin polarity ( normal/inverted ) settings from one bank function.
uint8_t expand5_read_pin(expand5_t *ctx, uint16_t pin)
Get a single INPUT pin's logic level function.
uint8_t expand5_get_bank_dir(expand5_t *ctx, uint8_t bank)
Get all pin direction ( I/O ) settings from one bank function.
void expand5_get_all_banks_pol(expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2)
Get all pin polarity ( normal/inverted ) settings from all banks function.
void expand5_write_all_banks(expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2)
Set all OUTPUT pins' logic levels in all banks function.
void expand5_write_bit(expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num, uint8_t pin_val)
Write bit function.
void expand5_write_bank(expand5_t *ctx, uint8_t bank, uint8_t value)
Set all OUTPUT pins' logic levels in one bank function.
uint8_t expand5_read_bit(expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num)
Read bit function.
void expand5_get_all_dir(expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2)
Get all pin direction ( I/O ) settings from all banks function.
uint8_t expand5_get_bank_out_lvl(expand5_t *ctx, uint8_t bank)
Get all pin output settings from one bank function.
void expand5_set_pin_dir(expand5_t *ctx, uint16_t pin, uint8_t direction)
Set a single pin's direction ( I/O ) setting function.
void expand5_generic_read(expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t expand5_check_int(expand5_t *ctx)
Get Interrupt state function.
uint8_t expand5_get_pin_out_lvl(expand5_t *ctx, uint16_t pin)
Get a single OUTPUT pin's setting function.
void expand5_get_all_banks_out_lvl(expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2)
Get all pin output settings from all banks function.
uint8_t expand5_get_pin_pol(expand5_t *ctx, uint16_t pin)
Get a single pin's polarity ( normal/inverted ) setting function.
void expand5_cfg_setup(expand5_cfg_t *cfg)
Config Object Initialization function.
void expand5_write_pin(expand5_t *ctx, uint16_t pin, uint8_t pin_val)
Set a single OUTPUT pin's logic level function.
uint8_t expand5_read_bank(expand5_t *ctx, uint8_t bank)
Get all pin logic levels from one bank function.
EXPAND5_RETVAL expand5_init(expand5_t *ctx, expand5_cfg_t *cfg)
Initialization function.
void expand5_set_all_banks_pol(expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2)
Set all pin polarity ( normal/inverted ) settings in all banks function.
void expand5_set_bank_pol(expand5_t *ctx, uint8_t bank, uint8_t polarity)
Set all pin polarity ( normal/inverted ) settings in one bank function.
void expand5_reset(expand5_t *ctx)
Reset function.
void expand5_set_pin_pol(expand5_t *ctx, uint16_t pin, uint8_t polarity)
Set a single pin's polarity ( normal/inverted ) setting function.
Click configuration structure definition.
Definition: expand5.h:164
uint32_t i2c_speed
Definition: expand5.h:177
pin_name_t scl
Definition: expand5.h:167
pin_name_t int_pin
Definition: expand5.h:173
pin_name_t sda
Definition: expand5.h:168
pin_name_t rst
Definition: expand5.h:172
uint8_t i2c_address
Definition: expand5.h:178
Click ctx object definition.
Definition: expand5.h:141
digital_in_t int_pin
Definition: expand5.h:148
i2c_master_t i2c
Definition: expand5.h:152
digital_out_t rst
Definition: expand5.h:144
uint8_t slave_address
Definition: expand5.h:156