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
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_spi_master.h"
38#include "spi_specifics.h"
39
60#define TIMERRELAY_PIN_STATE_HIGH 0x01
61#define TIMERRELAY_PIN_STATE_LOW 0x00
62
67#define TIMERRELAY_5V_MAX_DELAY 60
68#define TIMERRELAY_3V3_MAX_DELAY 160
69#define TIMERRELAY_5V_CALCULATION_MULTIPLIER 0.2353f
70#define TIMERRELAY_3V3CALCULATION_MULTIPLIER 0.6275f
71
76#define TIMERRELAY_VCC_5V 0x01
77#define TIMERRELAY_VCC_3V3 0x00
78
87#define TIMERRELAY_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
88#define TIMERRELAY_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
89 // timerrelay_set
91
106#define TIMERRELAY_MAP_MIKROBUS( cfg, mikrobus ) \
107 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
108 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
109 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
110 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
111 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112 cfg.trg = MIKROBUS( mikrobus, MIKROBUS_INT )
113 // timerrelay_map // timerrelay
116
121typedef struct
122{
123 // Output pins
124 digital_out_t rst;
125 digital_out_t trg;
127 // Modules
128 spi_master_t spi;
130 pin_name_t chip_select;
132 uint8_t vcc_sel;
135
140typedef struct
141{
142 // Communication gpio pins
143 pin_name_t miso;
144 pin_name_t mosi;
145 pin_name_t sck;
146 pin_name_t cs;
148 // Additional gpio pins
149 pin_name_t rst;
150 pin_name_t trg;
152 // static variable
153 uint32_t spi_speed;
154 spi_master_mode_t spi_mode;
155 spi_master_chip_select_polarity_t cs_polarity;
158
163typedef enum
164{
167
169
186
201
215
230err_t timerrelay_generic_write ( timerrelay_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
231
242void timerrelay_set_vcc_sel ( timerrelay_t *ctx, uint8_t vcc_sel );
243
254err_t timerrelay_set_wiper_pos ( timerrelay_t *ctx, uint8_t wiper_pos );
255
267err_t timerrelay_set_delay ( timerrelay_t *ctx, uint8_t delay );
268
279void timerrelay_set_rst_pin ( timerrelay_t *ctx, uint8_t pin_state );
280
291void timerrelay_set_trg_pin ( timerrelay_t *ctx, uint8_t pin_state );
292
303
314
315#ifdef __cplusplus
316}
317#endif
318#endif // TIMERRELAY_H
319 // timerrelay
321
322// ------------------------------------------------------------------------ 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:141
spi_master_chip_select_polarity_t cs_polarity
Definition: timerrelay.h:155
pin_name_t sck
Definition: timerrelay.h:145
spi_master_mode_t spi_mode
Definition: timerrelay.h:154
pin_name_t mosi
Definition: timerrelay.h:144
uint32_t spi_speed
Definition: timerrelay.h:153
pin_name_t trg
Definition: timerrelay.h:150
pin_name_t miso
Definition: timerrelay.h:143
pin_name_t rst
Definition: timerrelay.h:149
pin_name_t cs
Definition: timerrelay.h:146
Timer Relay Click context object.
Definition: timerrelay.h:122
spi_master_t spi
Definition: timerrelay.h:128
digital_out_t trg
Definition: timerrelay.h:125
digital_out_t rst
Definition: timerrelay.h:124
uint8_t vcc_sel
Definition: timerrelay.h:132
pin_name_t chip_select
Definition: timerrelay.h:130
timerrelay_return_value_t
Timer Relay Click return value data.
Definition: timerrelay.h:164
@ TIMERRELAY_ERROR
Definition: timerrelay.h:166
@ TIMERRELAY_OK
Definition: timerrelay.h:165