relay6  2.1.0.0
relay6.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 RELAY6_H
29 #define RELAY6_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define RELAY6_REG_INPUT_PORT 0x00
74 #define RELAY6_REG_OUTPUT_PORT 0x01
75 #define RELAY6_REG_POLARITY_INV 0x02
76 #define RELAY6_REG_CONFIG 0x03
77  // relay6_reg
79 
94 #define RELAY6_NONE_PIN 0x00
95 #define RELAY6_RELAY1_PIN 0x01
96 #define RELAY6_RELAY2_PIN 0x02
97 #define RELAY6_RELAY3_PIN 0x04
98 #define RELAY6_RELAY4_PIN 0x08
99 #define RELAY6_ALL_PIN 0x0F
100 
106 #define RELAY6_PIN_STATE_HIGH 0x01
107 #define RELAY6_PIN_STATE_LOW 0x00
108 
114 #define RELAY6_DEVICE_ADDRESS_A1A0_00 0x70
115 #define RELAY6_DEVICE_ADDRESS_A1A0_01 0x71
116 #define RELAY6_DEVICE_ADDRESS_A1A0_10 0x72
117 #define RELAY6_DEVICE_ADDRESS_A1A0_11 0x73
118  // relay6_set
120 
135 #define RELAY6_MAP_MIKROBUS( cfg, mikrobus ) \
136  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
137  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
138  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
139  // relay6_map // relay6
142 
147 typedef struct
148 {
149  // Output pins
150  digital_out_t rst;
152  // Modules
153  i2c_master_t i2c;
155  // I2C slave address
156  uint8_t slave_address;
158 } relay6_t;
159 
164 typedef struct
165 {
166  pin_name_t scl;
167  pin_name_t sda;
169  pin_name_t rst;
171  uint32_t i2c_speed;
172  uint8_t i2c_address;
174 } relay6_cfg_t;
175 
180 typedef enum
181 {
183  RELAY6_ERROR = -1
184 
186 
203 
217 err_t relay6_init ( relay6_t *ctx, relay6_cfg_t *cfg );
218 
232 
247 err_t relay6_generic_write ( relay6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
248 
263 err_t relay6_generic_read ( relay6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
264 
274 void relay6_set_rst_pin ( relay6_t *ctx, uint8_t pin_state );
275 
285 
299 err_t relay6_port_expander_write ( relay6_t *ctx, uint8_t reg, uint8_t data_in );
300 
314 err_t relay6_port_expander_read ( relay6_t *ctx, uint8_t reg, uint8_t *data_out );
315 
328 err_t relay6_set_relay ( relay6_t *ctx, uint8_t on_relay, uint8_t off_relay );
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 #endif // RELAY6_H
334  // relay6
336 
337 // ------------------------------------------------------------------------ END
relay6_default_cfg
err_t relay6_default_cfg(relay6_t *ctx)
Relay 6 default configuration function.
relay6_set_rst_pin
void relay6_set_rst_pin(relay6_t *ctx, uint8_t pin_state)
Relay 6 set RST pin function.
relay6_cfg_t::i2c_address
uint8_t i2c_address
Definition: relay6.h:172
RELAY6_OK
@ RELAY6_OK
Definition: relay6.h:182
relay6_cfg_t::scl
pin_name_t scl
Definition: relay6.h:166
relay6_t::rst
digital_out_t rst
Definition: relay6.h:150
relay6_t::i2c
i2c_master_t i2c
Definition: relay6.h:153
relay6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: relay6.h:171
relay6_cfg_setup
void relay6_cfg_setup(relay6_cfg_t *cfg)
Relay 6 configuration object setup function.
RELAY6_ERROR
@ RELAY6_ERROR
Definition: relay6.h:183
relay6_set_relay
err_t relay6_set_relay(relay6_t *ctx, uint8_t on_relay, uint8_t off_relay)
Relay 6 set relay state function.
relay6_return_value_t
relay6_return_value_t
Relay 6 Click return value data.
Definition: relay6.h:181
relay6_cfg_t
Relay 6 Click configuration object.
Definition: relay6.h:165
relay6_generic_read
err_t relay6_generic_read(relay6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Relay 6 I2C reading function.
relay6_reset_port_expander
void relay6_reset_port_expander(relay6_t *ctx)
Relay 6 reset port expander function.
relay6_generic_write
err_t relay6_generic_write(relay6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Relay 6 I2C writing function.
relay6_cfg_t::rst
pin_name_t rst
Definition: relay6.h:169
relay6_port_expander_read
err_t relay6_port_expander_read(relay6_t *ctx, uint8_t reg, uint8_t *data_out)
Relay 6 port expander read register function.
relay6_port_expander_write
err_t relay6_port_expander_write(relay6_t *ctx, uint8_t reg, uint8_t data_in)
Relay 6 port expander write register function.
relay6_t::slave_address
uint8_t slave_address
Definition: relay6.h:156
relay6_t
Relay 6 Click context object.
Definition: relay6.h:148
relay6_init
err_t relay6_init(relay6_t *ctx, relay6_cfg_t *cfg)
Relay 6 initialization function.
relay6_cfg_t::sda
pin_name_t sda
Definition: relay6.h:167