expand15  2.1.0.0
expand15.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 EXPAND15_H
29 #define EXPAND15_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define EXPAND15_REG_INPUT_PORT_0 0x00
70 #define EXPAND15_REG_INPUT_PORT_1 0x01
71 #define EXPAND15_REG_OUTPUT_PORT_0 0x02
72 #define EXPAND15_REG_OUTPUT_PORT_1 0x03
73 #define EXPAND15_REG_POLARITY_INVERSION_0 0x04
74 #define EXPAND15_REG_POLARITY_INVERSION_1 0x05
75 #define EXPAND15_REG_CONFIGURATION_0 0x06
76 #define EXPAND15_REG_CONFIGURATION_1 0x07
77 #define EXPAND15_REG_OUTPUT_DRV_STRENGTH_0_0 0x40
78 #define EXPAND15_REG_OUTPUT_DRV_STRENGTH_0_1 0x41
79 #define EXPAND15_REG_OUTPUT_DRV_STRENGTH_1_0 0x42
80 #define EXPAND15_REG_OUTPUT_DRV_STRENGTH_1_1 0x43
81 #define EXPAND15_REG_INPUT_LATCH_0 0x44
82 #define EXPAND15_REG_INPUT_LATCH_1 0x45
83 #define EXPAND15_REG_PULL_UP_DOWN_EN_0 0x46
84 #define EXPAND15_REG_PULL_UP_DOWN_EN_1 0x47
85 #define EXPAND15_REG_PULL_UP_DOWN_SELECT_0 0x48
86 #define EXPAND15_REG_PULL_UP_DOWN_SELECT_1 0x49
87 #define EXPAND15_REG_INTERRUPT_MASK_0 0x4A
88 #define EXPAND15_REG_INTERRUPT_MASK_1 0x4B
89 #define EXPAND15_REG_INTERRUPT_STATUS_0 0x4C
90 #define EXPAND15_REG_INTERRUPT_STATUS_1 0x4D
91 #define EXPAND15_REG_OUTPUT_PORT_CFG 0x4F
92 
93  // expand15_reg
95 
110 #define EXPAND15_PIN_00_MASK 0x01
111 #define EXPAND15_PIN_01_MASK 0x02
112 #define EXPAND15_PIN_02_MASK 0x04
113 #define EXPAND15_PIN_03_MASK 0x08
114 #define EXPAND15_PIN_04_MASK 0x10
115 #define EXPAND15_PIN_05_MASK 0x20
116 #define EXPAND15_PIN_06_MASK 0x40
117 #define EXPAND15_PIN_07_MASK 0x80
118 #define EXPAND15_PIN_10_MASK 0x01
119 #define EXPAND15_PIN_11_MASK 0x02
120 #define EXPAND15_PIN_12_MASK 0x04
121 #define EXPAND15_PIN_13_MASK 0x08
122 #define EXPAND15_PIN_14_MASK 0x10
123 #define EXPAND15_PIN_15_MASK 0x20
124 #define EXPAND15_PIN_16_MASK 0x40
125 #define EXPAND15_PIN_17_MASK 0x80
126 
131 #define EXPAND15_PORT_0 0x00
132 #define EXPAND15_PORT_1 0x01
133 
138 #define EXPAND15_OUTPUT_STRENGTH_FULL 0x03
139 #define EXPAND15_OUTPUT_STRENGTH_3_QUARTERS 0x02
140 #define EXPAND15_OUTPUT_STRENGTH_HALF 0x01
141 #define EXPAND15_OUTPUT_STRENGTH_1_QUARTER 0x00
142 
147 #define EXPAND15_PORT_PUSH_PULL 0x00
148 #define EXPAND15_PORT_OPEN_DRAIN 0x01
149 
154 #define EXPAND15_ALL_PINS_ON 0xFF
155 #define EXPAND15_ALL_PINS_OFF 0x00
156 
162 #define EXPAND15_DEVICE_ADDRESS_GND 0x20
163 #define EXPAND15_DEVICE_ADDRESS_VCC 0x21
164  // expand15_set
166 
181 #define EXPAND15_MAP_MIKROBUS( cfg, mikrobus ) \
182  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
183  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
184  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
185  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
186  // expand15_map // expand15
189 
194 typedef struct
195 {
196  // Output pins
197  digital_out_t rst;
199  // Input pins
200  digital_in_t int_pin;
202  // Modules
203  i2c_master_t i2c;
205  // I2C slave address
206  uint8_t slave_address;
208 } expand15_t;
209 
214 typedef struct
215 {
216  pin_name_t scl;
217  pin_name_t sda;
219  pin_name_t rst;
220  pin_name_t int_pin;
222  uint32_t i2c_speed;
223  uint8_t i2c_address;
226 
231 typedef enum
232 {
234  EXPAND15_ERROR = -1
235 
237 
254 
269 
283 
298 err_t expand15_generic_write ( expand15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
299 
314 err_t expand15_generic_read ( expand15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
315 
325 
335 
348 err_t expand15_get_in_pin_state ( expand15_t *ctx, uint8_t port, uint8_t *pin_state );
349 
362 err_t expand15_get_out_pin_state ( expand15_t *ctx, uint8_t port, uint8_t *pin_state );
363 
376 err_t expand15_set_out_pin_state ( expand15_t *ctx, uint8_t port, uint8_t pin_state );
377 
390 err_t expand15_get_in_pin_polarity ( expand15_t *ctx, uint8_t port, uint8_t *pin_polarity );
391 
404 err_t expand15_set_in_pin_polarity ( expand15_t *ctx, uint8_t port, uint8_t pin_polarity );
405 
418 err_t expand15_get_pin_config ( expand15_t *ctx, uint8_t port, uint8_t *pin_config );
419 
432 err_t expand15_set_pin_as_in ( expand15_t *ctx, uint8_t port, uint8_t pin_config );
433 
446 err_t expand15_set_pin_as_out ( expand15_t *ctx, uint8_t port, uint8_t pin_config );
447 
460 err_t expand15_get_out_level ( expand15_t *ctx, uint8_t port, uint16_t *pin_output_level );
461 
474 err_t expand15_set_out_level ( expand15_t *ctx, uint8_t port, uint16_t pin_output_level );
475 
489 err_t expand15_set_out_pin_strength( expand15_t *ctx, uint8_t port, uint8_t pin, uint8_t strength );
490 
503 err_t expand15_set_en_pull_up_down ( expand15_t *ctx, uint8_t port, uint8_t port_config );
504 
517 err_t expand15_get_en_pull_up_down ( expand15_t *ctx, uint8_t port, uint8_t *port_config );
518 
531 err_t expand15_set_pull_up_down ( expand15_t *ctx, uint8_t port, uint8_t pin_config );
532 
545 err_t expand15_get_pull_up_down ( expand15_t *ctx, uint8_t port, uint8_t *pin_config );
546 
559 err_t expand15_set_int_mask ( expand15_t *ctx, uint8_t port, uint8_t int_config );
560 
573 err_t expand15_get_int_mask ( expand15_t *ctx, uint8_t port, uint8_t *int_config );
574 
587 err_t expand15_get_int_status ( expand15_t *ctx, uint8_t port, uint8_t *int_status );
588 
601 err_t expand15_get_out_port_config ( expand15_t *ctx, uint8_t *port0_cfg, uint8_t *port1_cfg );
602 
615 err_t expand15_set_out_port_config ( expand15_t *ctx, uint8_t port0_cfg, uint8_t port1_cfg );
616 
617 #ifdef __cplusplus
618 }
619 #endif
620 #endif // EXPAND15_H
621  // expand15
623 
624 // ------------------------------------------------------------------------ END
expand15_hw_reset
void expand15_hw_reset(expand15_t *ctx)
Expand 15 hardware reset function.
expand15_default_cfg
err_t expand15_default_cfg(expand15_t *ctx)
Expand 15 default configuration function.
expand15_set_pull_up_down
err_t expand15_set_pull_up_down(expand15_t *ctx, uint8_t port, uint8_t pin_config)
Expand 15 set pull up/down function.
expand15_generic_read
err_t expand15_generic_read(expand15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Expand 15 I2C reading function.
expand15_set_in_pin_polarity
err_t expand15_set_in_pin_polarity(expand15_t *ctx, uint8_t port, uint8_t pin_polarity)
Expand 15 set input pin polarity function.
expand15_set_out_level
err_t expand15_set_out_level(expand15_t *ctx, uint8_t port, uint16_t pin_output_level)
Expand 15 set output level function.
expand15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: expand15.h:222
expand15_t::int_pin
digital_in_t int_pin
Definition: expand15.h:200
expand15_t
Expand 15 Click context object.
Definition: expand15.h:195
expand15_cfg_t::rst
pin_name_t rst
Definition: expand15.h:219
EXPAND15_ERROR
@ EXPAND15_ERROR
Definition: expand15.h:234
expand15_set_en_pull_up_down
err_t expand15_set_en_pull_up_down(expand15_t *ctx, uint8_t port, uint8_t port_config)
Expand 15 set enable pull up/down function.
expand15_set_out_port_config
err_t expand15_set_out_port_config(expand15_t *ctx, uint8_t port0_cfg, uint8_t port1_cfg)
Expand 15 set output port configuration function.
expand15_return_value_t
expand15_return_value_t
Expand 15 Click return value data.
Definition: expand15.h:232
expand15_get_pull_up_down
err_t expand15_get_pull_up_down(expand15_t *ctx, uint8_t port, uint8_t *pin_config)
Expand 15 get pull up/down function.
expand15_set_pin_as_out
err_t expand15_set_pin_as_out(expand15_t *ctx, uint8_t port, uint8_t pin_config)
Expand 15 set pin as output function.
expand15_set_out_pin_state
err_t expand15_set_out_pin_state(expand15_t *ctx, uint8_t port, uint8_t pin_state)
Expand 15 set output pin state function.
expand15_set_out_pin_strength
err_t expand15_set_out_pin_strength(expand15_t *ctx, uint8_t port, uint8_t pin, uint8_t strength)
Expand 15 set pin output strength function.
expand15_generic_write
err_t expand15_generic_write(expand15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Expand 15 I2C writing function.
expand15_init
err_t expand15_init(expand15_t *ctx, expand15_cfg_t *cfg)
Expand 15 initialization function.
expand15_set_pin_as_in
err_t expand15_set_pin_as_in(expand15_t *ctx, uint8_t port, uint8_t pin_config)
Expand 15 set pin as input function.
expand15_t::slave_address
uint8_t slave_address
Definition: expand15.h:206
expand15_cfg_t::int_pin
pin_name_t int_pin
Definition: expand15.h:220
expand15_get_int_mask
err_t expand15_get_int_mask(expand15_t *ctx, uint8_t port, uint8_t *int_config)
Expand 15 get interrupt mask function.
expand15_get_in_pin_state
err_t expand15_get_in_pin_state(expand15_t *ctx, uint8_t port, uint8_t *pin_state)
Expand 15 get input pin state function.
expand15_get_int_pin_state
uint8_t expand15_get_int_pin_state(expand15_t *ctx)
Expand 15 get interrupt function.
expand15_get_out_level
err_t expand15_get_out_level(expand15_t *ctx, uint8_t port, uint16_t *pin_output_level)
Expand 15 get output level function.
expand15_get_in_pin_polarity
err_t expand15_get_in_pin_polarity(expand15_t *ctx, uint8_t port, uint8_t *pin_polarity)
Expand 15 get input pin polarity function.
expand15_cfg_t::scl
pin_name_t scl
Definition: expand15.h:216
expand15_get_int_status
err_t expand15_get_int_status(expand15_t *ctx, uint8_t port, uint8_t *int_status)
Expand 15 get interrupt status function.
EXPAND15_OK
@ EXPAND15_OK
Definition: expand15.h:233
expand15_get_pin_config
err_t expand15_get_pin_config(expand15_t *ctx, uint8_t port, uint8_t *pin_config)
Expand 15 get pin configuration function.
expand15_cfg_t::i2c_address
uint8_t i2c_address
Definition: expand15.h:223
expand15_set_int_mask
err_t expand15_set_int_mask(expand15_t *ctx, uint8_t port, uint8_t int_config)
Expand 15 set interrupt mask function.
expand15_get_out_pin_state
err_t expand15_get_out_pin_state(expand15_t *ctx, uint8_t port, uint8_t *pin_state)
Expand 15 get output pin state function.
expand15_cfg_setup
void expand15_cfg_setup(expand15_cfg_t *cfg)
Expand 15 configuration object setup function.
expand15_cfg_t
Expand 15 Click configuration object.
Definition: expand15.h:215
expand15_get_en_pull_up_down
err_t expand15_get_en_pull_up_down(expand15_t *ctx, uint8_t port, uint8_t *port_config)
Expand 15 get enable pull up/down function.
expand15_t::rst
digital_out_t rst
Definition: expand15.h:197
expand15_get_out_port_config
err_t expand15_get_out_port_config(expand15_t *ctx, uint8_t *port0_cfg, uint8_t *port1_cfg)
Expand 15 get output port configuration function.
expand15_cfg_t::sda
pin_name_t sda
Definition: expand15.h:217
expand15_t::i2c
i2c_master_t i2c
Definition: expand15.h:203