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 
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_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define TIMERRELAY_PIN_STATE_HIGH 0x01
71 #define TIMERRELAY_PIN_STATE_LOW 0x00
72 
77 #define TIMERRELAY_5V_MAX_DELAY 60
78 #define TIMERRELAY_3V3_MAX_DELAY 160
79 #define TIMERRELAY_5V_CALCULATION_MULTIPLIER 0.2353f
80 #define TIMERRELAY_3V3_CALCULATION_MULTIPLIER 0.6275f
81 
86 #define TIMERRELAY_VCC_5V 0x01
87 #define TIMERRELAY_VCC_3V3 0x00
88 
97 #define TIMERRELAY_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
98 #define TIMERRELAY_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
99  // timerrelay_set
101 
116 #define TIMERRELAY_MAP_MIKROBUS( cfg, mikrobus ) \
117  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
118  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
119  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
120  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
121  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
122  cfg.trg = MIKROBUS( mikrobus, MIKROBUS_INT )
123  // timerrelay_map // timerrelay
126 
131 typedef struct
132 {
133  // Output pins
134  digital_out_t rst;
135  digital_out_t trg;
137  // Modules
138  spi_master_t spi;
140  pin_name_t chip_select;
142  uint8_t vcc_sel;
144 } timerrelay_t;
145 
150 typedef struct
151 {
152  // Communication gpio pins
153  pin_name_t miso;
154  pin_name_t mosi;
155  pin_name_t sck;
156  pin_name_t cs;
158  // Additional gpio pins
159  pin_name_t rst;
160  pin_name_t trg;
162  // static variable
163  uint32_t spi_speed;
164  spi_master_mode_t spi_mode;
165  spi_master_chip_select_polarity_t cs_polarity;
168 
173 typedef enum
174 {
176  TIMERRELAY_ERROR = -1
177 
179 
196 
211 
225 
240 err_t timerrelay_generic_write ( timerrelay_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
241 
252 void timerrelay_set_vcc_sel ( timerrelay_t *ctx, uint8_t vcc_sel );
253 
264 err_t timerrelay_set_wiper_pos ( timerrelay_t *ctx, uint8_t wiper_pos );
265 
277 err_t timerrelay_set_delay ( timerrelay_t *ctx, uint8_t delay );
278 
289 void timerrelay_set_rst_pin ( timerrelay_t *ctx, uint8_t pin_state );
290 
301 void timerrelay_set_trg_pin ( timerrelay_t *ctx, uint8_t pin_state );
302 
313 
324 
325 #ifdef __cplusplus
326 }
327 #endif
328 #endif // TIMERRELAY_H
329  // timerrelay
331 
332 // ------------------------------------------------------------------------ END
timerrelay_cfg_t::mosi
pin_name_t mosi
Definition: timerrelay.h:154
spi_specifics.h
This file contains SPI specific macros, functions, etc.
timerrelay_cfg_t::rst
pin_name_t rst
Definition: timerrelay.h:159
timerrelay_t::chip_select
pin_name_t chip_select
Definition: timerrelay.h:140
timerrelay_cfg_t
Timer Relay Click configuration object.
Definition: timerrelay.h:151
timerrelay_t
Timer Relay Click context object.
Definition: timerrelay.h:132
TIMERRELAY_ERROR
@ TIMERRELAY_ERROR
Definition: timerrelay.h:176
timerrelay_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: timerrelay.h:165
TIMERRELAY_OK
@ TIMERRELAY_OK
Definition: timerrelay.h:175
timerrelay_cfg_t::cs
pin_name_t cs
Definition: timerrelay.h:156
timerrelay_t::vcc_sel
uint8_t vcc_sel
Definition: timerrelay.h:142
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:163
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:155
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:135
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:164
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:160
timerrelay_return_value_t
timerrelay_return_value_t
Timer Relay Click return value data.
Definition: timerrelay.h:174
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:153
timerrelay_t::rst
digital_out_t rst
Definition: timerrelay.h:134
timerrelay_t::spi
spi_master_t spi
Definition: timerrelay.h:138
timerrelay_set_vcc_sel
void timerrelay_set_vcc_sel(timerrelay_t *ctx, uint8_t vcc_sel)
Timer Relay set Vcc select settings function.