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
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_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  // 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  // timerrelay_map // timerrelay
130 
135 typedef 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;
148 } timerrelay_t;
149 
154 typedef 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 
177 typedef enum
178 {
180  TIMERRELAY_ERROR = -1
181 
183 
200 
215 
229 
244 err_t timerrelay_generic_write ( timerrelay_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
245 
256 void timerrelay_set_vcc_sel ( timerrelay_t *ctx, uint8_t vcc_sel );
257 
268 err_t timerrelay_set_wiper_pos ( timerrelay_t *ctx, uint8_t wiper_pos );
269 
281 err_t timerrelay_set_delay ( timerrelay_t *ctx, uint8_t delay );
282 
293 void timerrelay_set_rst_pin ( timerrelay_t *ctx, uint8_t pin_state );
294 
305 void 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  // timerrelay
335 
336 // ------------------------------------------------------------------------ END
timerrelay_cfg_t::mosi
pin_name_t mosi
Definition: timerrelay.h:158
spi_specifics.h
This file contains SPI specific macros, functions, etc.
timerrelay_cfg_t::rst
pin_name_t rst
Definition: timerrelay.h:163
timerrelay_t::chip_select
pin_name_t chip_select
Definition: timerrelay.h:144
timerrelay_cfg_t
Timer Relay Click configuration object.
Definition: timerrelay.h:155
timerrelay_t
Timer Relay Click context object.
Definition: timerrelay.h:136
TIMERRELAY_ERROR
@ TIMERRELAY_ERROR
Definition: timerrelay.h:180
timerrelay_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: timerrelay.h:169
TIMERRELAY_OK
@ TIMERRELAY_OK
Definition: timerrelay.h:179
timerrelay_cfg_t::cs
pin_name_t cs
Definition: timerrelay.h:160
timerrelay_t::vcc_sel
uint8_t vcc_sel
Definition: timerrelay.h:146
timerrelay_generic_write
err_t timerrelay_generic_write(timerrelay_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Timer Relay data writing function.
timerrelay_activate_reset
void timerrelay_activate_reset(timerrelay_t *ctx)
Timer Relay reset timer function.
timerrelay_set_rst_pin
void timerrelay_set_rst_pin(timerrelay_t *ctx, uint8_t pin_state)
Timer Relay set RST pin state function.
timerrelay_init
err_t timerrelay_init(timerrelay_t *ctx, timerrelay_cfg_t *cfg)
Timer Relay initialization function.
timerrelay_cfg_t::spi_speed
uint32_t spi_speed
Definition: timerrelay.h:167
timerrelay_cfg_setup
void timerrelay_cfg_setup(timerrelay_cfg_t *cfg)
Timer Relay configuration object setup function.
timerrelay_cfg_t::sck
pin_name_t sck
Definition: timerrelay.h:159
timerrelay_set_trg_pin
void timerrelay_set_trg_pin(timerrelay_t *ctx, uint8_t pin_state)
Timer Relay set TRG pin state function.
timerrelay_t::trg
digital_out_t trg
Definition: timerrelay.h:139
timerrelay_default_cfg
err_t timerrelay_default_cfg(timerrelay_t *ctx)
Timer Relay default configuration function.
timerrelay_set_delay
err_t timerrelay_set_delay(timerrelay_t *ctx, uint8_t delay)
Timer Relay set delay function.
timerrelay_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: timerrelay.h:168
timerrelay_set_wiper_pos
err_t timerrelay_set_wiper_pos(timerrelay_t *ctx, uint8_t wiper_pos)
Timer Relay set wiper position function.
timerrelay_cfg_t::trg
pin_name_t trg
Definition: timerrelay.h:164
timerrelay_return_value_t
timerrelay_return_value_t
Timer Relay Click return value data.
Definition: timerrelay.h:178
timerrelay_activate_trigger
void timerrelay_activate_trigger(timerrelay_t *ctx)
Timer Relay activate trigger function.
timerrelay_cfg_t::miso
pin_name_t miso
Definition: timerrelay.h:157
timerrelay_t::rst
digital_out_t rst
Definition: timerrelay.h:138
timerrelay_t::spi
spi_master_t spi
Definition: timerrelay.h:142
timerrelay_set_vcc_sel
void timerrelay_set_vcc_sel(timerrelay_t *ctx, uint8_t vcc_sel)
Timer Relay set Vcc select settings function.