relay5  2.1.0.0
relay5.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 RELAY5_H
29 #define RELAY5_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 RELAY5_REG_INPUT 0x00
70 #define RELAY5_REG_OUTPUT 0x01
71 #define RELAY5_REG_POLARITY 0x02
72 #define RELAY5_REG_CONFIG 0x03
73  // relay5_reg
75 
90 #define RELAY5_DEFAULT_CONFIG 0xF8
91 
96 #define RELAY5_PIN_RL3 0x01
97 #define RELAY5_PIN_RL2 0x02
98 #define RELAY5_PIN_RL1 0x04
99 
104 #define RELAY5_PIN_STATE_LOW 0
105 #define RELAY5_PIN_STATE_HIGH 1
106 
112 #define RELAY5_DEVICE_ADDRESS_A1A0_00 0x70
113 #define RELAY5_DEVICE_ADDRESS_A1A0_01 0x71
114 #define RELAY5_DEVICE_ADDRESS_A1A0_10 0x72
115 #define RELAY5_DEVICE_ADDRESS_A1A0_11 0x73
116  // relay5_set
118 
133 #define RELAY5_MAP_MIKROBUS( cfg, mikrobus ) \
134  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
135  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
136  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
137  // relay5_map // relay5
140 
145 typedef struct
146 {
147  // Output pins
148  digital_out_t rst;
150  // Modules
151  i2c_master_t i2c;
153  // I2C slave address
154  uint8_t slave_address;
156 } relay5_t;
157 
162 typedef struct
163 {
164  pin_name_t scl;
165  pin_name_t sda;
167  pin_name_t rst;
169  uint32_t i2c_speed;
170  uint8_t i2c_address;
172 } relay5_cfg_t;
173 
178 typedef enum
179 {
181  RELAY5_ERROR = -1
182 
184 
201 
215 err_t relay5_init ( relay5_t *ctx, relay5_cfg_t *cfg );
216 
230 
244 err_t relay5_write_register ( relay5_t *ctx, uint8_t reg, uint8_t data_in );
245 
258 err_t relay5_read_register ( relay5_t *ctx, uint8_t reg, uint8_t *data_out );
259 
271 
283 
295 
307 
319 
331 
343 
355 
367 
378 void relay5_set_rst_pin ( relay5_t *ctx, uint8_t state );
379 
389 
390 #ifdef __cplusplus
391 }
392 #endif
393 #endif // RELAY5_H
394  // relay5
396 
397 // ------------------------------------------------------------------------ END
relay5_set_relay3_close
err_t relay5_set_relay3_close(relay5_t *ctx)
Relay 5 set relay 3 close function.
relay5_return_value_t
relay5_return_value_t
Relay 5 Click return value data.
Definition: relay5.h:179
relay5_cfg_t::sda
pin_name_t sda
Definition: relay5.h:165
relay5_set_relay2_open
err_t relay5_set_relay2_open(relay5_t *ctx)
Relay 5 set relay 2 open function.
relay5_set_relay1_open
err_t relay5_set_relay1_open(relay5_t *ctx)
Relay 5 set relay 1 open function.
relay5_read_register
err_t relay5_read_register(relay5_t *ctx, uint8_t reg, uint8_t *data_out)
Relay 5 read register function.
relay5_reset_device
void relay5_reset_device(relay5_t *ctx)
Relay 5 reset device function.
relay5_cfg_t::rst
pin_name_t rst
Definition: relay5.h:167
relay5_t::slave_address
uint8_t slave_address
Definition: relay5.h:154
relay5_set_relay1_close
err_t relay5_set_relay1_close(relay5_t *ctx)
Relay 5 set relay 1 close function.
RELAY5_OK
@ RELAY5_OK
Definition: relay5.h:180
relay5_default_cfg
err_t relay5_default_cfg(relay5_t *ctx)
Relay 5 default configuration function.
relay5_init
err_t relay5_init(relay5_t *ctx, relay5_cfg_t *cfg)
Relay 5 initialization function.
relay5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: relay5.h:169
relay5_t::i2c
i2c_master_t i2c
Definition: relay5.h:151
relay5_set_relay2_close
err_t relay5_set_relay2_close(relay5_t *ctx)
Relay 5 set relay 2 close function.
relay5_cfg_t
Relay 5 Click configuration object.
Definition: relay5.h:163
relay5_switch_relay3
err_t relay5_switch_relay3(relay5_t *ctx)
Relay 5 switch relay 3 function.
relay5_set_rst_pin
void relay5_set_rst_pin(relay5_t *ctx, uint8_t state)
Relay 5 set rst pin function.
relay5_t::rst
digital_out_t rst
Definition: relay5.h:148
relay5_t
Relay 5 Click context object.
Definition: relay5.h:146
relay5_cfg_t::scl
pin_name_t scl
Definition: relay5.h:164
RELAY5_ERROR
@ RELAY5_ERROR
Definition: relay5.h:181
relay5_cfg_t::i2c_address
uint8_t i2c_address
Definition: relay5.h:170
relay5_cfg_setup
void relay5_cfg_setup(relay5_cfg_t *cfg)
Relay 5 configuration object setup function.
relay5_switch_relay2
err_t relay5_switch_relay2(relay5_t *ctx)
Relay 5 switch relay 2 function.
relay5_set_relay3_open
err_t relay5_set_relay3_open(relay5_t *ctx)
Relay 5 set relay 3 open function.
relay5_write_register
err_t relay5_write_register(relay5_t *ctx, uint8_t reg, uint8_t data_in)
Relay 5 write register function.
relay5_switch_relay1
err_t relay5_switch_relay1(relay5_t *ctx)
Relay 5 switch relay 1 function.