solidswitch3 2.0.0.0
solidswitch3.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 SOLIDSWITCH3_H
29#define SOLIDSWITCH3_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 SOLIDSWITCH3_CH_OUT1 0x01
75#define SOLIDSWITCH3_CH_OUT2 0x02
76#define SOLIDSWITCH3_CH_OUT3 0x04
77#define SOLIDSWITCH3_CH_OUT4 0x08
78#define SOLIDSWITCH3_CH_OUT5 0x10
79#define SOLIDSWITCH3_CH_OUT6 0x20
80#define SOLIDSWITCH3_CH_OUT7 0x40
81#define SOLIDSWITCH3_CH_OUT8 0x80
82#define SOLIDSWITCH3_ALL_CHANNELS 0xFF
83
88#define SOLIDSWITCH3_DIR_MODE_SPI 0
89#define SOLIDSWITCH3_DIR_MODE_GPIO 1
90
95#define SOLIDSWITCH3_OUT_DISABLE 0u
96#define SOLIDSWITCH3_OUT_IN_TERMINAL 1u
97#define SOLIDSWITCH3_OUT_ENABLE 2u
98#define SOLIDSWITCH3_OUT_BITS_MASK 3u
99
108#define SOLIDSWITCH3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
109#define SOLIDSWITCH3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
110
111 // solidswitch3_set
112
127#define SOLIDSWITCH3_MAP_MIKROBUS( cfg, mikrobus ) \
128 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
129 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
130 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
131 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
132 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
133 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
134 cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
135 cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_INT )
136
137 // solidswitch3_map
138 // solidswitch3
139
144typedef struct
145{
146 // Output pins
147 digital_out_t dir;
148 digital_out_t rst;
149 digital_out_t in1;
150 digital_out_t in2;
152 // Modules
153 spi_master_t spi;
155 pin_name_t chip_select;
157 uint16_t output_state;
160
165typedef struct
166{
167 // Communication gpio pins
168 pin_name_t miso;
169 pin_name_t mosi;
170 pin_name_t sck;
171 pin_name_t cs;
173 // Additional gpio pins
174 pin_name_t dir;
175 pin_name_t rst;
176 pin_name_t in1;
177 pin_name_t in2;
179 // static variable
180 uint32_t spi_speed;
181 spi_master_mode_t spi_mode;
182 spi_master_chip_select_polarity_t cs_polarity;
185
196
213
229
244
258err_t solidswitch3_write_data ( solidswitch3_t *ctx, uint16_t data_in );
259
272err_t solidswitch3_enable_output ( solidswitch3_t *ctx, uint8_t channel );
273
286err_t solidswitch3_disable_output ( solidswitch3_t *ctx, uint8_t channel );
287
297
311void solidswitch3_set_dir_mode ( solidswitch3_t *ctx, uint8_t dir_mode );
312
322void solidswitch3_set_rst_pin ( solidswitch3_t *ctx, uint8_t state );
323
333void solidswitch3_set_in1_pin ( solidswitch3_t *ctx, uint8_t state );
334
344void solidswitch3_set_in2_pin ( solidswitch3_t *ctx, uint8_t state );
345
346#ifdef __cplusplus
347}
348#endif
349#endif // SOLIDSWITCH3_H
350
351 // solidswitch3
352
353// ------------------------------------------------------------------------ END
void solidswitch3_reset(solidswitch3_t *ctx)
SolidSwitch 3 reset function.
void solidswitch3_set_in2_pin(solidswitch3_t *ctx, uint8_t state)
SolidSwitch 3 set in2 pin function.
void solidswitch3_set_rst_pin(solidswitch3_t *ctx, uint8_t state)
SolidSwitch 3 set rst pin function.
err_t solidswitch3_disable_output(solidswitch3_t *ctx, uint8_t channel)
SolidSwitch 3 disable output function.
void solidswitch3_cfg_setup(solidswitch3_cfg_t *cfg)
SolidSwitch 3 configuration object setup function.
err_t solidswitch3_init(solidswitch3_t *ctx, solidswitch3_cfg_t *cfg)
SolidSwitch 3 initialization function.
err_t solidswitch3_enable_output(solidswitch3_t *ctx, uint8_t channel)
SolidSwitch 3 enable output function.
err_t solidswitch3_default_cfg(solidswitch3_t *ctx)
SolidSwitch 3 default configuration function.
err_t solidswitch3_write_data(solidswitch3_t *ctx, uint16_t data_in)
SolidSwitch 3 write data function.
void solidswitch3_set_dir_mode(solidswitch3_t *ctx, uint8_t dir_mode)
SolidSwitch 3 set dir mode function.
void solidswitch3_set_in1_pin(solidswitch3_t *ctx, uint8_t state)
SolidSwitch 3 set in1 pin function.
solidswitch3_return_value_t
SolidSwitch 3 Click return value data.
Definition solidswitch3.h:191
@ SOLIDSWITCH3_ERROR
Definition solidswitch3.h:193
@ SOLIDSWITCH3_OK
Definition solidswitch3.h:192
This file contains SPI specific macros, functions, etc.
SolidSwitch 3 Click configuration object.
Definition solidswitch3.h:166
spi_master_chip_select_polarity_t cs_polarity
Definition solidswitch3.h:182
pin_name_t in2
Definition solidswitch3.h:177
pin_name_t sck
Definition solidswitch3.h:170
spi_master_mode_t spi_mode
Definition solidswitch3.h:181
pin_name_t mosi
Definition solidswitch3.h:169
uint32_t spi_speed
Definition solidswitch3.h:180
pin_name_t dir
Definition solidswitch3.h:174
pin_name_t in1
Definition solidswitch3.h:176
pin_name_t miso
Definition solidswitch3.h:168
pin_name_t rst
Definition solidswitch3.h:175
pin_name_t cs
Definition solidswitch3.h:171
SolidSwitch 3 Click context object.
Definition solidswitch3.h:145
uint16_t output_state
Definition solidswitch3.h:157
digital_out_t in2
Definition solidswitch3.h:150
spi_master_t spi
Definition solidswitch3.h:153
digital_out_t rst
Definition solidswitch3.h:148
pin_name_t chip_select
Definition solidswitch3.h:155
digital_out_t in1
Definition solidswitch3.h:149
digital_out_t dir
Definition solidswitch3.h:147