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 )
56 
62 #define EXPAND5_RETVAL uint8_t
63 
64 #define EXPAND5_OK 0x00
65 #define EXPAND5_INIT_ERROR 0xFF
66 
72 #define EXPAND5_I2C_ADR_GND 0x22
73 #define EXPAND5_I2C_ADR_VCC 0x23
74 
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
128  // End group macro
131 // --------------------------------------------------------------- PUBLIC TYPES
140 typedef 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 
156  uint8_t slave_address;
157 
158 } expand5_t;
159 
163 typedef 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 
180 } expand5_cfg_t;
181  // End types group
183 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184 
190 #ifdef __cplusplus
191 extern "C"{
192 #endif
193 
202 void expand5_cfg_setup ( expand5_cfg_t *cfg );
203 
213 
224 void expand5_generic_write ( expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
225 
237 void expand5_generic_read ( expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
238 
250 uint8_t expand5_read_bit ( expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num );
251 
262 void expand5_write_bit ( expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num, uint8_t pin_val );
263 
274 uint8_t expand5_read_pin ( expand5_t *ctx, uint16_t pin );
275 
286 uint8_t expand5_read_bank ( expand5_t *ctx, uint8_t bank );
287 
298 void expand5_read_all_banks ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
299 
312 uint8_t expand5_get_pin_out_lvl ( expand5_t *ctx, uint16_t pin );
313 
326 uint8_t expand5_get_bank_out_lvl ( expand5_t *ctx, uint8_t bank );
327 
340 void expand5_get_all_banks_out_lvl ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
341 
351 void expand5_write_pin ( expand5_t *ctx, uint16_t pin, uint8_t pin_val );
352 
362 void expand5_write_bank ( expand5_t *ctx, uint8_t bank, uint8_t value );
363 
374 void expand5_write_all_banks ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
375 
386 uint8_t expand5_get_pin_pol ( expand5_t *ctx, uint16_t pin );
387 
398 uint8_t expand5_get_bank_pol ( expand5_t *ctx, uint8_t bank );
399 
410 void expand5_get_all_banks_pol ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
411 
421 void expand5_set_pin_pol ( expand5_t *ctx, uint16_t pin, uint8_t polarity );
422 
432 void expand5_set_bank_pol ( expand5_t *ctx, uint8_t bank, uint8_t polarity );
433 
444 void expand5_set_all_banks_pol ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
445 
456 uint8_t expand5_get_pin_dir ( expand5_t *ctx, uint16_t pin );
457 
468 uint8_t expand5_get_bank_dir ( expand5_t *ctx, uint8_t bank );
469 
480 void expand5_get_all_dir ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
481 
491 void expand5_set_pin_dir( expand5_t *ctx, uint16_t pin, uint8_t direction );
492 
502 void expand5_set_bank_dir ( expand5_t *ctx, uint8_t bank, uint8_t direction );
503 
514 void expand5_set_all_dir ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
515 
524 void expand5_reset ( expand5_t *ctx );
525 
537 uint8_t expand5_check_int ( expand5_t *ctx );
538 
539 #ifdef __cplusplus
540 }
541 #endif
542 #endif // _EXPAND5_H_
543  // End public_function group
546 
547 // ------------------------------------------------------------------------- END
expand5_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand5.h:178
expand5_get_all_banks_pol
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.
expand5_cfg_t::scl
pin_name_t scl
Definition: expand5.h:167
expand5_cfg_t
Click configuration structure definition.
Definition: expand5.h:163
expand5_generic_read
void expand5_generic_read(expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
expand5_get_pin_pol
uint8_t expand5_get_pin_pol(expand5_t *ctx, uint16_t pin)
Get a single pin's polarity ( normal/inverted ) setting function.
expand5_set_all_dir
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.
expand5_cfg_t::sda
pin_name_t sda
Definition: expand5.h:168
expand5_cfg_t::int_pin
pin_name_t int_pin
Definition: expand5.h:173
expand5_init
EXPAND5_RETVAL expand5_init(expand5_t *ctx, expand5_cfg_t *cfg)
Initialization function.
expand5_write_all_banks
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.
expand5_t
Click ctx object definition.
Definition: expand5.h:140
expand5_cfg_setup
void expand5_cfg_setup(expand5_cfg_t *cfg)
Config Object Initialization function.
expand5_set_all_banks_pol
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.
expand5_write_pin
void expand5_write_pin(expand5_t *ctx, uint16_t pin, uint8_t pin_val)
Set a single OUTPUT pin's logic level function.
expand5_set_pin_dir
void expand5_set_pin_dir(expand5_t *ctx, uint16_t pin, uint8_t direction)
Set a single pin's direction ( I/O ) setting function.
expand5_get_pin_dir
uint8_t expand5_get_pin_dir(expand5_t *ctx, uint16_t pin)
Get a single pin's direction ( I/O ) setting function.
expand5_set_pin_pol
void expand5_set_pin_pol(expand5_t *ctx, uint16_t pin, uint8_t polarity)
Set a single pin's polarity ( normal/inverted ) setting function.
expand5_get_bank_out_lvl
uint8_t expand5_get_bank_out_lvl(expand5_t *ctx, uint8_t bank)
Get all pin output settings from one bank function.
expand5_read_pin
uint8_t expand5_read_pin(expand5_t *ctx, uint16_t pin)
Get a single INPUT pin's logic level function.
expand5_cfg_t::rst
pin_name_t rst
Definition: expand5.h:172
expand5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand5.h:177
expand5_set_bank_dir
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.
expand5_t::rst
digital_out_t rst
Definition: expand5.h:144
expand5_get_bank_pol
uint8_t expand5_get_bank_pol(expand5_t *ctx, uint8_t bank)
Get all pin polarity ( normal/inverted ) settings from one bank function.
expand5_check_int
uint8_t expand5_check_int(expand5_t *ctx)
Get Interrupt state function.
expand5_reset
void expand5_reset(expand5_t *ctx)
Reset function.
expand5_set_bank_pol
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.
expand5_get_all_dir
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.
expand5_write_bank
void expand5_write_bank(expand5_t *ctx, uint8_t bank, uint8_t value)
Set all OUTPUT pins' logic levels in one bank function.
expand5_t::slave_address
uint8_t slave_address
Definition: expand5.h:156
expand5_get_all_banks_out_lvl
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.
expand5_generic_write
void expand5_generic_write(expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
EXPAND5_RETVAL
#define EXPAND5_RETVAL
Definition: expand5.h:62
expand5_read_bank
uint8_t expand5_read_bank(expand5_t *ctx, uint8_t bank)
Get all pin logic levels from one bank function.
expand5_get_bank_dir
uint8_t expand5_get_bank_dir(expand5_t *ctx, uint8_t bank)
Get all pin direction ( I/O ) settings from one bank function.
expand5_t::int_pin
digital_in_t int_pin
Definition: expand5.h:148
expand5_get_pin_out_lvl
uint8_t expand5_get_pin_out_lvl(expand5_t *ctx, uint16_t pin)
Get a single OUTPUT pin's setting function.
expand5_read_all_banks
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.
expand5_read_bit
uint8_t expand5_read_bit(expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num)
Read bit function.
expand5_write_bit
void expand5_write_bit(expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num, uint8_t pin_val)
Write bit function.
expand5_t::i2c
i2c_master_t i2c
Definition: expand5.h:152