timerrelay 2.1.0.0
timerrelay.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 TIMERRELAY_H
29#define TIMERRELAY_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_spi_master.h"
52#include "spi_specifics.h"
53
74#define TIMERRELAY_PIN_STATE_HIGH 0x01
75#define TIMERRELAY_PIN_STATE_LOW 0x00
76
81#define TIMERRELAY_5V_MAX_DELAY 60
82#define TIMERRELAY_3V3_MAX_DELAY 160
83#define TIMERRELAY_5V_CALCULATION_MULTIPLIER 0.2353f
84#define TIMERRELAY_3V3_CALCULATION_MULTIPLIER 0.6275f
85
90#define TIMERRELAY_VCC_5V 0x01
91#define TIMERRELAY_VCC_3V3 0x00
92
101#define TIMERRELAY_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
102#define TIMERRELAY_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
103
104 // timerrelay_set
105
120#define TIMERRELAY_MAP_MIKROBUS( cfg, mikrobus ) \
121 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
122 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
123 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
124 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
125 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
126 cfg.trg = MIKROBUS( mikrobus, MIKROBUS_INT )
127
128 // timerrelay_map
129 // timerrelay
130
135typedef struct
136{
137 // Output pins
138 digital_out_t rst;
139 digital_out_t trg;
141 // Modules
142 spi_master_t spi;
144 pin_name_t chip_select;
146 uint8_t vcc_sel;
149
154typedef struct
155{
156 // Communication gpio pins
157 pin_name_t miso;
158 pin_name_t mosi;
159 pin_name_t sck;
160 pin_name_t cs;
162 // Additional gpio pins
163 pin_name_t rst;
164 pin_name_t trg;
166 // static variable
167 uint32_t spi_speed;
168 spi_master_mode_t spi_mode;
169 spi_master_chip_select_polarity_t cs_polarity;
172
183
200
215
229
244err_t timerrelay_generic_write ( timerrelay_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
245
256void timerrelay_set_vcc_sel ( timerrelay_t *ctx, uint8_t vcc_sel );
257
268err_t timerrelay_set_wiper_pos ( timerrelay_t *ctx, uint8_t wiper_pos );
269
281err_t timerrelay_set_delay ( timerrelay_t *ctx, uint8_t delay );
282
293void timerrelay_set_rst_pin ( timerrelay_t *ctx, uint8_t pin_state );
294
305void timerrelay_set_trg_pin ( timerrelay_t *ctx, uint8_t pin_state );
306
317
328
329#ifdef __cplusplus
330}
331#endif
332#endif // TIMERRELAY_H
333
334 // timerrelay
335
336// ------------------------------------------------------------------------ END
void timerrelay_activate_trigger(timerrelay_t *ctx)
Timer Relay activate trigger function.
void timerrelay_cfg_setup(timerrelay_cfg_t *cfg)
Timer Relay configuration object setup function.
err_t timerrelay_generic_write(timerrelay_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Timer Relay data writing function.
void timerrelay_set_trg_pin(timerrelay_t *ctx, uint8_t pin_state)
Timer Relay set TRG pin state function.
void timerrelay_activate_reset(timerrelay_t *ctx)
Timer Relay reset timer function.
err_t timerrelay_set_wiper_pos(timerrelay_t *ctx, uint8_t wiper_pos)
Timer Relay set wiper position function.
err_t timerrelay_init(timerrelay_t *ctx, timerrelay_cfg_t *cfg)
Timer Relay initialization function.
err_t timerrelay_default_cfg(timerrelay_t *ctx)
Timer Relay default configuration function.
void timerrelay_set_vcc_sel(timerrelay_t *ctx, uint8_t vcc_sel)
Timer Relay set Vcc select settings function.
err_t timerrelay_set_delay(timerrelay_t *ctx, uint8_t delay)
Timer Relay set delay function.
void timerrelay_set_rst_pin(timerrelay_t *ctx, uint8_t pin_state)
Timer Relay set RST pin state function.
This file contains SPI specific macros, functions, etc.
Timer Relay Click configuration object.
Definition timerrelay.h:155
spi_master_chip_select_polarity_t cs_polarity
Definition timerrelay.h:169
pin_name_t sck
Definition timerrelay.h:159
spi_master_mode_t spi_mode
Definition timerrelay.h:168
pin_name_t mosi
Definition timerrelay.h:158
uint32_t spi_speed
Definition timerrelay.h:167
pin_name_t trg
Definition timerrelay.h:164
pin_name_t miso
Definition timerrelay.h:157
pin_name_t rst
Definition timerrelay.h:163
pin_name_t cs
Definition timerrelay.h:160
Timer Relay Click context object.
Definition timerrelay.h:136
spi_master_t spi
Definition timerrelay.h:142
digital_out_t trg
Definition timerrelay.h:139
digital_out_t rst
Definition timerrelay.h:138
uint8_t vcc_sel
Definition timerrelay.h:146
pin_name_t chip_select
Definition timerrelay.h:144
timerrelay_return_value_t
Timer Relay Click return value data.
Definition timerrelay.h:178
@ TIMERRELAY_ERROR
Definition timerrelay.h:180
@ TIMERRELAY_OK
Definition timerrelay.h:179