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 
41 #ifdef PREINIT_SUPPORTED
42 #include "preinit.h"
43 #endif
44 
45 #ifdef MikroCCoreVersion
46  #if MikroCCoreVersion >= 1
47  #include "delays.h"
48  #endif
49 #endif
50 
51 #include "drv_digital_out.h"
52 #include "drv_digital_in.h"
53 #include "drv_i2c_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define EXPAND5_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define EXPAND5_RETVAL uint8_t
77 
78 #define EXPAND5_OK 0x00
79 #define EXPAND5_INIT_ERROR 0xFF
80 
86 #define EXPAND5_I2C_ADR_GND 0x22
87 #define EXPAND5_I2C_ADR_VCC 0x23
88 
94 #define EXPAND5_RA_IN_0 0x00
95 #define EXPAND5_RA_IN_1 0x01
96 #define EXPAND5_RA_IN_2 0x02
97 #define EXPAND5_RA_OUT_0 0x04
98 #define EXPAND5_RA_OUT_1 0x05
99 #define EXPAND5_RA_OUT_2 0x06
100 #define EXPAND5_RA_POL_0 0x08
101 #define EXPAND5_RA_POL_1 0x09
102 #define EXPAND5_RA_POL_2 0x0A
103 #define EXPAND5_RA_CFG_0 0x0C
104 #define EXPAND5_RA_CFG_1 0x0D
105 #define EXPAND5_RA_CFG_2 0x0E
106 
107 #define EXPAND5_AUTO_INC 0x80
108 
109 #define EXPAND5_LOW 0
110 #define EXPAND5_HIGH 1
111 
112 #define EXPAND5_POL_NORMAL 0
113 #define EXPAND5_POL_INVERTED 1
114 
115 #define EXPAND5_OUT 0
116 #define EXPAND5_IN 1
117 
118 #define EXPAND5_P00 0
119 #define EXPAND5_P01 1
120 #define EXPAND5_P02 2
121 #define EXPAND5_P03 3
122 #define EXPAND5_P04 4
123 #define EXPAND5_P05 5
124 #define EXPAND5_P06 6
125 #define EXPAND5_P07 7
126 #define EXPAND5_P10 8
127 #define EXPAND5_P11 9
128 #define EXPAND5_P12 10
129 #define EXPAND5_P13 11
130 #define EXPAND5_P14 12
131 #define EXPAND5_P15 13
132 #define EXPAND5_P16 14
133 #define EXPAND5_P17 15
134 #define EXPAND5_P20 16
135 #define EXPAND5_P21 17
136 #define EXPAND5_P22 18
137 #define EXPAND5_P23 19
138 #define EXPAND5_P24 20
139 #define EXPAND5_P25 21
140 #define EXPAND5_P26 22
141 #define EXPAND5_P27 23
142  // End group macro
145 // --------------------------------------------------------------- PUBLIC TYPES
154 typedef struct
155 {
156  // Output pins
157 
158  digital_out_t rst;
159 
160  // Input pins
161 
162  digital_in_t int_pin;
163 
164  // Modules
165 
166  i2c_master_t i2c;
167 
168  // ctx variable
169 
170  uint8_t slave_address;
171 
172 } expand5_t;
173 
177 typedef struct
178 {
179  // Communication gpio pins
180 
181  pin_name_t scl;
182  pin_name_t sda;
183 
184  // Additional gpio pins
185 
186  pin_name_t rst;
187  pin_name_t int_pin;
188 
189  // static variable
190 
191  uint32_t i2c_speed;
192  uint8_t i2c_address;
193 
194 } expand5_cfg_t;
195  // End types group
197 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
198 
204 #ifdef __cplusplus
205 extern "C"{
206 #endif
207 
217 
227 
238 void expand5_generic_write ( expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
239 
251 void expand5_generic_read ( expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
252 
264 uint8_t expand5_read_bit ( expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num );
265 
276 void expand5_write_bit ( expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num, uint8_t pin_val );
277 
288 uint8_t expand5_read_pin ( expand5_t *ctx, uint16_t pin );
289 
300 uint8_t expand5_read_bank ( expand5_t *ctx, uint8_t bank );
301 
312 void expand5_read_all_banks ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
313 
326 uint8_t expand5_get_pin_out_lvl ( expand5_t *ctx, uint16_t pin );
327 
340 uint8_t expand5_get_bank_out_lvl ( expand5_t *ctx, uint8_t bank );
341 
354 void expand5_get_all_banks_out_lvl ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
355 
365 void expand5_write_pin ( expand5_t *ctx, uint16_t pin, uint8_t pin_val );
366 
376 void expand5_write_bank ( expand5_t *ctx, uint8_t bank, uint8_t value );
377 
388 void expand5_write_all_banks ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
389 
400 uint8_t expand5_get_pin_pol ( expand5_t *ctx, uint16_t pin );
401 
412 uint8_t expand5_get_bank_pol ( expand5_t *ctx, uint8_t bank );
413 
424 void expand5_get_all_banks_pol ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
425 
435 void expand5_set_pin_pol ( expand5_t *ctx, uint16_t pin, uint8_t polarity );
436 
446 void expand5_set_bank_pol ( expand5_t *ctx, uint8_t bank, uint8_t polarity );
447 
458 void expand5_set_all_banks_pol ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
459 
470 uint8_t expand5_get_pin_dir ( expand5_t *ctx, uint16_t pin );
471 
482 uint8_t expand5_get_bank_dir ( expand5_t *ctx, uint8_t bank );
483 
494 void expand5_get_all_dir ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
495 
505 void expand5_set_pin_dir( expand5_t *ctx, uint16_t pin, uint8_t direction );
506 
516 void expand5_set_bank_dir ( expand5_t *ctx, uint8_t bank, uint8_t direction );
517 
528 void expand5_set_all_dir ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
529 
538 void expand5_reset ( expand5_t *ctx );
539 
551 uint8_t expand5_check_int ( expand5_t *ctx );
552 
553 #ifdef __cplusplus
554 }
555 #endif
556 #endif // _EXPAND5_H_
557  // End public_function group
560 
561 // ------------------------------------------------------------------------- END
expand5_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand5.h:192
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:181
expand5_cfg_t
Click configuration structure definition.
Definition: expand5.h:178
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:182
expand5_cfg_t::int_pin
pin_name_t int_pin
Definition: expand5.h:187
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:155
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:186
expand5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand5.h:191
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:158
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:170
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:76
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:162
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:166