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 
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  // 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  // 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  // relay5_map // relay5
144 
149 typedef struct
150 {
151  // Output pins
152  digital_out_t rst;
154  // Modules
155  i2c_master_t i2c;
157  // I2C slave address
158  uint8_t slave_address;
160 } relay5_t;
161 
166 typedef 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;
176 } relay5_cfg_t;
177 
182 typedef enum
183 {
185  RELAY5_ERROR = -1
186 
188 
205 
219 err_t relay5_init ( relay5_t *ctx, relay5_cfg_t *cfg );
220 
234 
248 err_t relay5_write_register ( relay5_t *ctx, uint8_t reg, uint8_t data_in );
249 
262 err_t relay5_read_register ( relay5_t *ctx, uint8_t reg, uint8_t *data_out );
263 
275 
287 
299 
311 
323 
335 
347 
359 
371 
382 void relay5_set_rst_pin ( relay5_t *ctx, uint8_t state );
383 
393 
394 #ifdef __cplusplus
395 }
396 #endif
397 #endif // RELAY5_H
398  // relay5
400 
401 // ------------------------------------------------------------------------ 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:183
relay5_cfg_t::sda
pin_name_t sda
Definition: relay5.h:169
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:171
relay5_t::slave_address
uint8_t slave_address
Definition: relay5.h:158
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:184
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:173
relay5_t::i2c
i2c_master_t i2c
Definition: relay5.h:155
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:167
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:152
relay5_t
Relay 5 Click context object.
Definition: relay5.h:150
relay5_cfg_t::scl
pin_name_t scl
Definition: relay5.h:168
RELAY5_ERROR
@ RELAY5_ERROR
Definition: relay5.h:185
relay5_cfg_t::i2c_address
uint8_t i2c_address
Definition: relay5.h:174
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.