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
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 SOLIDSWITCH2_REG_CHIP_ID 0x00
71 #define SOLIDSWITCH2_REG_CFG_0 0x01
72 #define SOLIDSWITCH2_REG_CFG_1 0x02
73 #define SOLIDSWITCH2_REG_CFG_2 0x03
74 #define SOLIDSWITCH2_REG_BIM 0x04
75 #define SOLIDSWITCH2_REG_RESERVED_1 0x05
76 #define SOLIDSWITCH2_REG_PWM_SPI 0x06
77 #define SOLIDSWITCH2_REG_MAP_IN0 0x07
78 #define SOLIDSWITCH2_REG_MAP_IN1 0x08
79 #define SOLIDSWITCH2_REG_MAP_PWM 0x09
80 #define SOLIDSWITCH2_REG_PWM_SEL 0x0A
81 #define SOLIDSWITCH2_REG_PWM_GEN_DC 0x0B
82 #define SOLIDSWITCH2_REG_PWM_LED_DC 0x0C
83 #define SOLIDSWITCH2_REG_DIAG_OFF_EN 0x0D
84 #define SOLIDSWITCH2_REG_DIAG_OPL_ON_EN 0x0E
85 #define SOLIDSWITCH2_REG_DIAG_OVC_OVT_RLW 0x0F
86 #define SOLIDSWITCH2_REG_STA_0 0x10
87 #define SOLIDSWITCH2_REG_STA_1 0x11
88 #define SOLIDSWITCH2_REG_DIAG_OVC_OVT 0x12
89 #define SOLIDSWITCH2_REG_DIAG_OPL_OFF 0x13
90 #define SOLIDSWITCH2_REG_DIAG_OPL_ON 0x14
91 #define SOLIDSWITCH2_REG_DIAG_SHD 0x15
92  // solidswitch2_reg
94 
109 #define SOLIDSWITCH2_CHIP_ID 0x56
110 
115 #define SOLIDSWITCH2_CFG_0_OUT7 0x80
116 #define SOLIDSWITCH2_CFG_0_OUT6 0x40
117 #define SOLIDSWITCH2_CFG_0_OUT5 0x20
118 #define SOLIDSWITCH2_CFG_0_OUT4 0x10
119 #define SOLIDSWITCH2_CFG_0_OUT3 0x08
120 #define SOLIDSWITCH2_CFG_0_OUT2 0x04
121 #define SOLIDSWITCH2_CFG_0_DIS_EN 0x02
122 #define SOLIDSWITCH2_CFG_0_NRES_EN 0x01
123 
128 #define SOLIDSWITCH2_CFG_1_RST 0x80
129 #define SOLIDSWITCH2_CFG_1_ACT 0x40
130 #define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_122p5Hz 0x00
131 #define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_245p1Hz 0x01
132 #define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_490p2Hz 0x02
133 #define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_980p4Hz 0x03
134 
139 #define SOLIDSWITCH2_CFG_2_FR_ADJ_NO_FREQ_ADJ 0x00
140 #define SOLIDSWITCH2_CFG_2_FR_ADJ_MINUS_15_PCT 0x04
141 #define SOLIDSWITCH2_CFG_2_FR_ADJ_PLUS_15_PCT 0x08
142 #define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_122p5Hz 0x00
143 #define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_245p1Hz 0x01
144 #define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_490p2Hz 0x02
145 #define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_980p4Hz 0x03
146 
151 #define SOLIDSWITCH2_OUT7 0x80
152 #define SOLIDSWITCH2_OUT6 0x40
153 #define SOLIDSWITCH2_OUT5 0x20
154 #define SOLIDSWITCH2_OUT4 0x10
155 #define SOLIDSWITCH2_OUT3 0x08
156 #define SOLIDSWITCH2_OUT2 0x04
157 #define SOLIDSWITCH2_OUT1 0x02
158 #define SOLIDSWITCH2_OUT0 0x01
159 #define SOLIDSWITCH2_OUT_NONE 0x00
160 
165 #define SOLIDSWITCH2_MAX_DUTY_CYCLE 0xFF
166 #define SOLIDSWITCH2_MIN_DUTY_CYCLE 0x00
167 
172 #define SOLIDSWITCH2_SPI_RW_BIT 0x80
173 #define SOLIDSWITCH2_SPI_ERROR_BIT 0x80
174 #define SOLIDSWITCH2_ADDRESS_BIT_MASK 0x1F
175 #define SOLIDSWITCH2_ODD_PARITY 0x01
176 #define SOLIDSWITCH2_SPI_ERROR_BIT 0x80
177 
186 #define SOLIDSWITCH2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
187 #define SOLIDSWITCH2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
188  // solidswitch2_set
190 
205 #define SOLIDSWITCH2_MAP_MIKROBUS( cfg, mikrobus ) \
206  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
207  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
208  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
209  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
210  cfg.idle = MIKROBUS( mikrobus, MIKROBUS_AN ); \
211  cfg.in0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
212  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_INT )
213  // solidswitch2_map // solidswitch2
216 
221 typedef struct
222 {
223  // Output pins
224  digital_out_t idle;
225  digital_out_t in0;
226  digital_out_t in1;
228  // Modules
229  spi_master_t spi;
231  pin_name_t chip_select;
234 
239 typedef struct
240 {
241  // Communication gpio pins
242  pin_name_t miso;
243  pin_name_t mosi;
244  pin_name_t sck;
245  pin_name_t cs;
247  // Additional gpio pins
248  pin_name_t idle;
249  pin_name_t in0;
250  pin_name_t in1;
252  // static variable
253  uint32_t spi_speed;
254  spi_master_mode_t spi_mode;
255  spi_master_chip_select_polarity_t cs_polarity;
258 
263 typedef enum
264 {
266  SOLIDSWITCH2_ERROR = -1
267 
269 
286 
301 
315 
328 err_t solidswitch2_write_register ( solidswitch2_t *ctx, uint8_t reg, uint8_t data_in );
329 
342 err_t solidswitch2_read_register ( solidswitch2_t *ctx, uint8_t reg, uint8_t *data_out );
343 
355 
365 void solidswitch2_set_idle_pin ( solidswitch2_t *ctx, uint8_t state );
366 
376 void solidswitch2_set_in0_pin ( solidswitch2_t *ctx, uint8_t state );
377 
387 void solidswitch2_set_in1_pin ( solidswitch2_t *ctx, uint8_t state );
388 
398 
408 
420 
421 #ifdef __cplusplus
422 }
423 #endif
424 #endif // SOLIDSWITCH2_H
425  // solidswitch2
427 
428 // ------------------------------------------------------------------------ END
solidswitch2_cfg_t::idle
pin_name_t idle
Definition: solidswitch2.h:248
solidswitch2_cfg_t::in1
pin_name_t in1
Definition: solidswitch2.h:250
solidswitch2_t::idle
digital_out_t idle
Definition: solidswitch2.h:224
solidswitch2_cfg_setup
void solidswitch2_cfg_setup(solidswitch2_cfg_t *cfg)
SolidSwitch 2 configuration object setup function.
solidswitch2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: solidswitch2.h:255
spi_specifics.h
This file contains SPI specific macros, functions, etc.
solidswitch2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: solidswitch2.h:254
solidswitch2_return_value_t
solidswitch2_return_value_t
SolidSwitch 2 Click return value data.
Definition: solidswitch2.h:264
SOLIDSWITCH2_OK
@ SOLIDSWITCH2_OK
Definition: solidswitch2.h:265
solidswitch2_cfg_t
SolidSwitch 2 Click configuration object.
Definition: solidswitch2.h:240
solidswitch2_default_cfg
err_t solidswitch2_default_cfg(solidswitch2_t *ctx)
SolidSwitch 2 default configuration function.
solidswitch2_check_communication
err_t solidswitch2_check_communication(solidswitch2_t *ctx)
SolidSwitch 2 check communication function.
solidswitch2_cfg_t::mosi
pin_name_t mosi
Definition: solidswitch2.h:243
solidswitch2_set_idle_pin
void solidswitch2_set_idle_pin(solidswitch2_t *ctx, uint8_t state)
SolidSwitch 2 set idle pin function.
solidswitch2_cfg_t::cs
pin_name_t cs
Definition: solidswitch2.h:245
solidswitch2_set_in0_pin
void solidswitch2_set_in0_pin(solidswitch2_t *ctx, uint8_t state)
SolidSwitch 2 set in0 pin function.
solidswitch2_cfg_t::spi_speed
uint32_t spi_speed
Definition: solidswitch2.h:253
solidswitch2_read_register
err_t solidswitch2_read_register(solidswitch2_t *ctx, uint8_t reg, uint8_t *data_out)
SolidSwitch 2 data reading function.
solidswitch2_cfg_t::in0
pin_name_t in0
Definition: solidswitch2.h:249
solidswitch2_cfg_t::sck
pin_name_t sck
Definition: solidswitch2.h:244
solidswitch2_write_register
err_t solidswitch2_write_register(solidswitch2_t *ctx, uint8_t reg, uint8_t data_in)
SolidSwitch 2 data writing function.
solidswitch2_cfg_t::miso
pin_name_t miso
Definition: solidswitch2.h:242
solidswitch2_soft_reset
err_t solidswitch2_soft_reset(solidswitch2_t *ctx)
SolidSwitch 2 soft reset function.
solidswitch2_t
SolidSwitch 2 Click context object.
Definition: solidswitch2.h:222
solidswitch2_t::in0
digital_out_t in0
Definition: solidswitch2.h:225
solidswitch2_set_in1_pin
void solidswitch2_set_in1_pin(solidswitch2_t *ctx, uint8_t state)
SolidSwitch 2 set in1 pin function.
SOLIDSWITCH2_ERROR
@ SOLIDSWITCH2_ERROR
Definition: solidswitch2.h:266
solidswitch2_toggle_in0_pin
void solidswitch2_toggle_in0_pin(solidswitch2_t *ctx)
SolidSwitch 2 toggle in0 pin function.
solidswitch2_init
err_t solidswitch2_init(solidswitch2_t *ctx, solidswitch2_cfg_t *cfg)
SolidSwitch 2 initialization function.
solidswitch2_t::spi
spi_master_t spi
Definition: solidswitch2.h:229
solidswitch2_toggle_in1_pin
void solidswitch2_toggle_in1_pin(solidswitch2_t *ctx)
SolidSwitch 2 toggle in1 pin function.
solidswitch2_t::in1
digital_out_t in1
Definition: solidswitch2.h:226
solidswitch2_t::chip_select
pin_name_t chip_select
Definition: solidswitch2.h:231