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 "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define EXPAND5_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define EXPAND5_RETVAL uint8_t
73 
74 #define EXPAND5_OK 0x00
75 #define EXPAND5_INIT_ERROR 0xFF
76 
82 #define EXPAND5_I2C_ADR_GND 0x22
83 #define EXPAND5_I2C_ADR_VCC 0x23
84 
90 #define EXPAND5_RA_IN_0 0x00
91 #define EXPAND5_RA_IN_1 0x01
92 #define EXPAND5_RA_IN_2 0x02
93 #define EXPAND5_RA_OUT_0 0x04
94 #define EXPAND5_RA_OUT_1 0x05
95 #define EXPAND5_RA_OUT_2 0x06
96 #define EXPAND5_RA_POL_0 0x08
97 #define EXPAND5_RA_POL_1 0x09
98 #define EXPAND5_RA_POL_2 0x0A
99 #define EXPAND5_RA_CFG_0 0x0C
100 #define EXPAND5_RA_CFG_1 0x0D
101 #define EXPAND5_RA_CFG_2 0x0E
102 
103 #define EXPAND5_AUTO_INC 0x80
104 
105 #define EXPAND5_LOW 0
106 #define EXPAND5_HIGH 1
107 
108 #define EXPAND5_POL_NORMAL 0
109 #define EXPAND5_POL_INVERTED 1
110 
111 #define EXPAND5_OUT 0
112 #define EXPAND5_IN 1
113 
114 #define EXPAND5_P00 0
115 #define EXPAND5_P01 1
116 #define EXPAND5_P02 2
117 #define EXPAND5_P03 3
118 #define EXPAND5_P04 4
119 #define EXPAND5_P05 5
120 #define EXPAND5_P06 6
121 #define EXPAND5_P07 7
122 #define EXPAND5_P10 8
123 #define EXPAND5_P11 9
124 #define EXPAND5_P12 10
125 #define EXPAND5_P13 11
126 #define EXPAND5_P14 12
127 #define EXPAND5_P15 13
128 #define EXPAND5_P16 14
129 #define EXPAND5_P17 15
130 #define EXPAND5_P20 16
131 #define EXPAND5_P21 17
132 #define EXPAND5_P22 18
133 #define EXPAND5_P23 19
134 #define EXPAND5_P24 20
135 #define EXPAND5_P25 21
136 #define EXPAND5_P26 22
137 #define EXPAND5_P27 23
138  // End group macro
141 // --------------------------------------------------------------- PUBLIC TYPES
150 typedef struct
151 {
152  // Output pins
153 
154  digital_out_t rst;
155 
156  // Input pins
157 
158  digital_in_t int_pin;
159 
160  // Modules
161 
162  i2c_master_t i2c;
163 
164  // ctx variable
165 
166  uint8_t slave_address;
167 
168 } expand5_t;
169 
173 typedef struct
174 {
175  // Communication gpio pins
176 
177  pin_name_t scl;
178  pin_name_t sda;
179 
180  // Additional gpio pins
181 
182  pin_name_t rst;
183  pin_name_t int_pin;
184 
185  // static variable
186 
187  uint32_t i2c_speed;
188  uint8_t i2c_address;
189 
190 } expand5_cfg_t;
191  // End types group
193 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
194 
200 #ifdef __cplusplus
201 extern "C"{
202 #endif
203 
213 
223 
234 void expand5_generic_write ( expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
235 
247 void expand5_generic_read ( expand5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
248 
260 uint8_t expand5_read_bit ( expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num );
261 
272 void expand5_write_bit ( expand5_t *ctx, uint8_t reg_adr, uint8_t bit_num, uint8_t pin_val );
273 
284 uint8_t expand5_read_pin ( expand5_t *ctx, uint16_t pin );
285 
296 uint8_t expand5_read_bank ( expand5_t *ctx, uint8_t bank );
297 
308 void expand5_read_all_banks ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
309 
322 uint8_t expand5_get_pin_out_lvl ( expand5_t *ctx, uint16_t pin );
323 
336 uint8_t expand5_get_bank_out_lvl ( expand5_t *ctx, uint8_t bank );
337 
350 void expand5_get_all_banks_out_lvl ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
351 
361 void expand5_write_pin ( expand5_t *ctx, uint16_t pin, uint8_t pin_val );
362 
372 void expand5_write_bank ( expand5_t *ctx, uint8_t bank, uint8_t value );
373 
384 void expand5_write_all_banks ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
385 
396 uint8_t expand5_get_pin_pol ( expand5_t *ctx, uint16_t pin );
397 
408 uint8_t expand5_get_bank_pol ( expand5_t *ctx, uint8_t bank );
409 
420 void expand5_get_all_banks_pol ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
421 
431 void expand5_set_pin_pol ( expand5_t *ctx, uint16_t pin, uint8_t polarity );
432 
442 void expand5_set_bank_pol ( expand5_t *ctx, uint8_t bank, uint8_t polarity );
443 
454 void expand5_set_all_banks_pol ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
455 
466 uint8_t expand5_get_pin_dir ( expand5_t *ctx, uint16_t pin );
467 
478 uint8_t expand5_get_bank_dir ( expand5_t *ctx, uint8_t bank );
479 
490 void expand5_get_all_dir ( expand5_t *ctx, uint8_t *bank0, uint8_t *bank1, uint8_t *bank2 );
491 
501 void expand5_set_pin_dir( expand5_t *ctx, uint16_t pin, uint8_t direction );
502 
512 void expand5_set_bank_dir ( expand5_t *ctx, uint8_t bank, uint8_t direction );
513 
524 void expand5_set_all_dir ( expand5_t *ctx, uint8_t bank0, uint8_t bank1, uint8_t bank2 );
525 
534 void expand5_reset ( expand5_t *ctx );
535 
547 uint8_t expand5_check_int ( expand5_t *ctx );
548 
549 #ifdef __cplusplus
550 }
551 #endif
552 #endif // _EXPAND5_H_
553  // End public_function group
556 
557 // ------------------------------------------------------------------------- END
expand5_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand5.h:188
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:177
expand5_cfg_t
Click configuration structure definition.
Definition: expand5.h:174
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:178
expand5_cfg_t::int_pin
pin_name_t int_pin
Definition: expand5.h:183
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:151
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:182
expand5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand5.h:187
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:154
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:166
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:72
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:158
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:162