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
32extern "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 RELAY5_REG_INPUT 0x00
74#define RELAY5_REG_OUTPUT 0x01
75#define RELAY5_REG_POLARITY 0x02
76#define RELAY5_REG_CONFIG 0x03
77
78 // relay5_reg
79
94#define RELAY5_DEFAULT_CONFIG 0xF8
95
100#define RELAY5_PIN_RL3 0x01
101#define RELAY5_PIN_RL2 0x02
102#define RELAY5_PIN_RL1 0x04
103
108#define RELAY5_PIN_STATE_LOW 0
109#define RELAY5_PIN_STATE_HIGH 1
110
116#define RELAY5_DEVICE_ADDRESS_A1A0_00 0x70
117#define RELAY5_DEVICE_ADDRESS_A1A0_01 0x71
118#define RELAY5_DEVICE_ADDRESS_A1A0_10 0x72
119#define RELAY5_DEVICE_ADDRESS_A1A0_11 0x73
120
121 // relay5_set
122
137#define RELAY5_MAP_MIKROBUS( cfg, mikrobus ) \
138 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
139 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
140 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
141
142 // relay5_map
143 // relay5
144
149typedef struct
150{
151 // Output pins
152 digital_out_t rst;
154 // Modules
155 i2c_master_t i2c;
157 // I2C slave address
160} relay5_t;
161
166typedef struct
167{
168 pin_name_t scl;
169 pin_name_t sda;
171 pin_name_t rst;
173 uint32_t i2c_speed;
174 uint8_t i2c_address;
177
182typedef enum
183{
185 RELAY5_ERROR = -1
186
188
205
219err_t relay5_init ( relay5_t *ctx, relay5_cfg_t *cfg );
220
234
248err_t relay5_write_register ( relay5_t *ctx, uint8_t reg, uint8_t data_in );
249
262err_t relay5_read_register ( relay5_t *ctx, uint8_t reg, uint8_t *data_out );
263
275
287
299
311
323
335
347
359
371
382void relay5_set_rst_pin ( relay5_t *ctx, uint8_t state );
383
393
394#ifdef __cplusplus
395}
396#endif
397#endif // RELAY5_H
398
399 // relay5
400
401// ------------------------------------------------------------------------ END
err_t relay5_default_cfg(relay5_t *ctx)
Relay 5 default configuration function.
err_t relay5_switch_relay3(relay5_t *ctx)
Relay 5 switch relay 3 function.
err_t relay5_set_relay3_close(relay5_t *ctx)
Relay 5 set relay 3 close function.
err_t relay5_set_relay1_close(relay5_t *ctx)
Relay 5 set relay 1 close function.
void relay5_reset_device(relay5_t *ctx)
Relay 5 reset device function.
err_t relay5_set_relay2_close(relay5_t *ctx)
Relay 5 set relay 2 close function.
err_t relay5_set_relay2_open(relay5_t *ctx)
Relay 5 set relay 2 open function.
void relay5_set_rst_pin(relay5_t *ctx, uint8_t state)
Relay 5 set rst pin function.
err_t relay5_init(relay5_t *ctx, relay5_cfg_t *cfg)
Relay 5 initialization function.
err_t relay5_write_register(relay5_t *ctx, uint8_t reg, uint8_t data_in)
Relay 5 write register function.
err_t relay5_switch_relay1(relay5_t *ctx)
Relay 5 switch relay 1 function.
void relay5_cfg_setup(relay5_cfg_t *cfg)
Relay 5 configuration object setup function.
err_t relay5_set_relay1_open(relay5_t *ctx)
Relay 5 set relay 1 open function.
err_t relay5_set_relay3_open(relay5_t *ctx)
Relay 5 set relay 3 open function.
err_t relay5_switch_relay2(relay5_t *ctx)
Relay 5 switch relay 2 function.
err_t relay5_read_register(relay5_t *ctx, uint8_t reg, uint8_t *data_out)
Relay 5 read register function.
relay5_return_value_t
Relay 5 Click return value data.
Definition relay5.h:183
@ RELAY5_OK
Definition relay5.h:184
@ RELAY5_ERROR
Definition relay5.h:185
Relay 5 Click configuration object.
Definition relay5.h:167
uint32_t i2c_speed
Definition relay5.h:173
pin_name_t scl
Definition relay5.h:168
pin_name_t sda
Definition relay5.h:169
pin_name_t rst
Definition relay5.h:171
uint8_t i2c_address
Definition relay5.h:174
Relay 5 Click context object.
Definition relay5.h:150
i2c_master_t i2c
Definition relay5.h:155
digital_out_t rst
Definition relay5.h:152
uint8_t slave_address
Definition relay5.h:158