solidswitch2 2.1.0.0
solidswitch2.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 SOLIDSWITCH2_H
29#define SOLIDSWITCH2_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 SOLIDSWITCH2_REG_CHIP_ID 0x00
75#define SOLIDSWITCH2_REG_CFG_0 0x01
76#define SOLIDSWITCH2_REG_CFG_1 0x02
77#define SOLIDSWITCH2_REG_CFG_2 0x03
78#define SOLIDSWITCH2_REG_BIM 0x04
79#define SOLIDSWITCH2_REG_RESERVED_1 0x05
80#define SOLIDSWITCH2_REG_PWM_SPI 0x06
81#define SOLIDSWITCH2_REG_MAP_IN0 0x07
82#define SOLIDSWITCH2_REG_MAP_IN1 0x08
83#define SOLIDSWITCH2_REG_MAP_PWM 0x09
84#define SOLIDSWITCH2_REG_PWM_SEL 0x0A
85#define SOLIDSWITCH2_REG_PWM_GEN_DC 0x0B
86#define SOLIDSWITCH2_REG_PWM_LED_DC 0x0C
87#define SOLIDSWITCH2_REG_DIAG_OFF_EN 0x0D
88#define SOLIDSWITCH2_REG_DIAG_OPL_ON_EN 0x0E
89#define SOLIDSWITCH2_REG_DIAG_OVC_OVT_RLW 0x0F
90#define SOLIDSWITCH2_REG_STA_0 0x10
91#define SOLIDSWITCH2_REG_STA_1 0x11
92#define SOLIDSWITCH2_REG_DIAG_OVC_OVT 0x12
93#define SOLIDSWITCH2_REG_DIAG_OPL_OFF 0x13
94#define SOLIDSWITCH2_REG_DIAG_OPL_ON 0x14
95#define SOLIDSWITCH2_REG_DIAG_SHD 0x15
96
97 // solidswitch2_reg
98
113#define SOLIDSWITCH2_CHIP_ID 0x56
114
119#define SOLIDSWITCH2_CFG_0_OUT7 0x80
120#define SOLIDSWITCH2_CFG_0_OUT6 0x40
121#define SOLIDSWITCH2_CFG_0_OUT5 0x20
122#define SOLIDSWITCH2_CFG_0_OUT4 0x10
123#define SOLIDSWITCH2_CFG_0_OUT3 0x08
124#define SOLIDSWITCH2_CFG_0_OUT2 0x04
125#define SOLIDSWITCH2_CFG_0_DIS_EN 0x02
126#define SOLIDSWITCH2_CFG_0_NRES_EN 0x01
127
132#define SOLIDSWITCH2_CFG_1_RST 0x80
133#define SOLIDSWITCH2_CFG_1_ACT 0x40
134#define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_122p5Hz 0x00
135#define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_245p1Hz 0x01
136#define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_490p2Hz 0x02
137#define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_980p4Hz 0x03
138
143#define SOLIDSWITCH2_CFG_2_FR_ADJ_NO_FREQ_ADJ 0x00
144#define SOLIDSWITCH2_CFG_2_FR_ADJ_MINUS_15_PCT 0x04
145#define SOLIDSWITCH2_CFG_2_FR_ADJ_PLUS_15_PCT 0x08
146#define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_122p5Hz 0x00
147#define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_245p1Hz 0x01
148#define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_490p2Hz 0x02
149#define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_980p4Hz 0x03
150
155#define SOLIDSWITCH2_OUT7 0x80
156#define SOLIDSWITCH2_OUT6 0x40
157#define SOLIDSWITCH2_OUT5 0x20
158#define SOLIDSWITCH2_OUT4 0x10
159#define SOLIDSWITCH2_OUT3 0x08
160#define SOLIDSWITCH2_OUT2 0x04
161#define SOLIDSWITCH2_OUT1 0x02
162#define SOLIDSWITCH2_OUT0 0x01
163#define SOLIDSWITCH2_OUT_NONE 0x00
164
169#define SOLIDSWITCH2_MAX_DUTY_CYCLE 0xFF
170#define SOLIDSWITCH2_MIN_DUTY_CYCLE 0x00
171
176#define SOLIDSWITCH2_SPI_RW_BIT 0x80
177#define SOLIDSWITCH2_SPI_ERROR_BIT 0x80
178#define SOLIDSWITCH2_ADDRESS_BIT_MASK 0x1F
179#define SOLIDSWITCH2_ODD_PARITY 0x01
180#define SOLIDSWITCH2_SPI_ERROR_BIT 0x80
181
190#define SOLIDSWITCH2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
191#define SOLIDSWITCH2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
192
193 // solidswitch2_set
194
209#define SOLIDSWITCH2_MAP_MIKROBUS( cfg, mikrobus ) \
210 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
211 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
212 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
213 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
214 cfg.idle = MIKROBUS( mikrobus, MIKROBUS_AN ); \
215 cfg.in0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
216 cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_INT )
217
218 // solidswitch2_map
219 // solidswitch2
220
225typedef struct
226{
227 // Output pins
228 digital_out_t idle;
229 digital_out_t in0;
230 digital_out_t in1;
232 // Modules
233 spi_master_t spi;
235 pin_name_t chip_select;
238
243typedef struct
244{
245 // Communication gpio pins
246 pin_name_t miso;
247 pin_name_t mosi;
248 pin_name_t sck;
249 pin_name_t cs;
251 // Additional gpio pins
252 pin_name_t idle;
253 pin_name_t in0;
254 pin_name_t in1;
256 // static variable
257 uint32_t spi_speed;
258 spi_master_mode_t spi_mode;
259 spi_master_chip_select_polarity_t cs_polarity;
262
273
290
305
319
332err_t solidswitch2_write_register ( solidswitch2_t *ctx, uint8_t reg, uint8_t data_in );
333
346err_t solidswitch2_read_register ( solidswitch2_t *ctx, uint8_t reg, uint8_t *data_out );
347
359
369void solidswitch2_set_idle_pin ( solidswitch2_t *ctx, uint8_t state );
370
380void solidswitch2_set_in0_pin ( solidswitch2_t *ctx, uint8_t state );
381
391void solidswitch2_set_in1_pin ( solidswitch2_t *ctx, uint8_t state );
392
402
412
424
425#ifdef __cplusplus
426}
427#endif
428#endif // SOLIDSWITCH2_H
429
430 // solidswitch2
431
432// ------------------------------------------------------------------------ END
void solidswitch2_toggle_in0_pin(solidswitch2_t *ctx)
SolidSwitch 2 toggle in0 pin function.
err_t solidswitch2_default_cfg(solidswitch2_t *ctx)
SolidSwitch 2 default configuration function.
err_t solidswitch2_check_communication(solidswitch2_t *ctx)
SolidSwitch 2 check communication function.
err_t solidswitch2_read_register(solidswitch2_t *ctx, uint8_t reg, uint8_t *data_out)
SolidSwitch 2 data reading function.
err_t solidswitch2_init(solidswitch2_t *ctx, solidswitch2_cfg_t *cfg)
SolidSwitch 2 initialization function.
void solidswitch2_set_in1_pin(solidswitch2_t *ctx, uint8_t state)
SolidSwitch 2 set in1 pin function.
void solidswitch2_cfg_setup(solidswitch2_cfg_t *cfg)
SolidSwitch 2 configuration object setup function.
err_t solidswitch2_soft_reset(solidswitch2_t *ctx)
SolidSwitch 2 soft reset function.
void solidswitch2_toggle_in1_pin(solidswitch2_t *ctx)
SolidSwitch 2 toggle in1 pin function.
err_t solidswitch2_write_register(solidswitch2_t *ctx, uint8_t reg, uint8_t data_in)
SolidSwitch 2 data writing function.
void solidswitch2_set_in0_pin(solidswitch2_t *ctx, uint8_t state)
SolidSwitch 2 set in0 pin function.
void solidswitch2_set_idle_pin(solidswitch2_t *ctx, uint8_t state)
SolidSwitch 2 set idle pin function.
solidswitch2_return_value_t
SolidSwitch 2 Click return value data.
Definition solidswitch2.h:268
@ SOLIDSWITCH2_ERROR
Definition solidswitch2.h:270
@ SOLIDSWITCH2_OK
Definition solidswitch2.h:269
This file contains SPI specific macros, functions, etc.
SolidSwitch 2 Click configuration object.
Definition solidswitch2.h:244
pin_name_t in0
Definition solidswitch2.h:253
pin_name_t idle
Definition solidswitch2.h:252
spi_master_chip_select_polarity_t cs_polarity
Definition solidswitch2.h:259
pin_name_t sck
Definition solidswitch2.h:248
spi_master_mode_t spi_mode
Definition solidswitch2.h:258
pin_name_t mosi
Definition solidswitch2.h:247
uint32_t spi_speed
Definition solidswitch2.h:257
pin_name_t in1
Definition solidswitch2.h:254
pin_name_t miso
Definition solidswitch2.h:246
pin_name_t cs
Definition solidswitch2.h:249
SolidSwitch 2 Click context object.
Definition solidswitch2.h:226
spi_master_t spi
Definition solidswitch2.h:233
digital_out_t idle
Definition solidswitch2.h:228
pin_name_t chip_select
Definition solidswitch2.h:235
digital_out_t in1
Definition solidswitch2.h:230
digital_out_t in0
Definition solidswitch2.h:229