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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define SOLIDSWITCH2_REG_CHIP_ID 0x00
61 #define SOLIDSWITCH2_REG_CFG_0 0x01
62 #define SOLIDSWITCH2_REG_CFG_1 0x02
63 #define SOLIDSWITCH2_REG_CFG_2 0x03
64 #define SOLIDSWITCH2_REG_BIM 0x04
65 #define SOLIDSWITCH2_REG_RESERVED_1 0x05
66 #define SOLIDSWITCH2_REG_PWM_SPI 0x06
67 #define SOLIDSWITCH2_REG_MAP_IN0 0x07
68 #define SOLIDSWITCH2_REG_MAP_IN1 0x08
69 #define SOLIDSWITCH2_REG_MAP_PWM 0x09
70 #define SOLIDSWITCH2_REG_PWM_SEL 0x0A
71 #define SOLIDSWITCH2_REG_PWM_GEN_DC 0x0B
72 #define SOLIDSWITCH2_REG_PWM_LED_DC 0x0C
73 #define SOLIDSWITCH2_REG_DIAG_OFF_EN 0x0D
74 #define SOLIDSWITCH2_REG_DIAG_OPL_ON_EN 0x0E
75 #define SOLIDSWITCH2_REG_DIAG_OVC_OVT_RLW 0x0F
76 #define SOLIDSWITCH2_REG_STA_0 0x10
77 #define SOLIDSWITCH2_REG_STA_1 0x11
78 #define SOLIDSWITCH2_REG_DIAG_OVC_OVT 0x12
79 #define SOLIDSWITCH2_REG_DIAG_OPL_OFF 0x13
80 #define SOLIDSWITCH2_REG_DIAG_OPL_ON 0x14
81 #define SOLIDSWITCH2_REG_DIAG_SHD 0x15
82  // solidswitch2_reg
84 
99 #define SOLIDSWITCH2_CHIP_ID 0x56
100 
105 #define SOLIDSWITCH2_CFG_0_OUT7 0x80
106 #define SOLIDSWITCH2_CFG_0_OUT6 0x40
107 #define SOLIDSWITCH2_CFG_0_OUT5 0x20
108 #define SOLIDSWITCH2_CFG_0_OUT4 0x10
109 #define SOLIDSWITCH2_CFG_0_OUT3 0x08
110 #define SOLIDSWITCH2_CFG_0_OUT2 0x04
111 #define SOLIDSWITCH2_CFG_0_DIS_EN 0x02
112 #define SOLIDSWITCH2_CFG_0_NRES_EN 0x01
113 
118 #define SOLIDSWITCH2_CFG_1_RST 0x80
119 #define SOLIDSWITCH2_CFG_1_ACT 0x40
120 #define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_122p5Hz 0x00
121 #define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_245p1Hz 0x01
122 #define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_490p2Hz 0x02
123 #define SOLIDSWITCH2_CFG_1_PWM_DIV_LED_980p4Hz 0x03
124 
129 #define SOLIDSWITCH2_CFG_2_FR_ADJ_NO_FREQ_ADJ 0x00
130 #define SOLIDSWITCH2_CFG_2_FR_ADJ_MINUS_15_PCT 0x04
131 #define SOLIDSWITCH2_CFG_2_FR_ADJ_PLUS_15_PCT 0x08
132 #define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_122p5Hz 0x00
133 #define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_245p1Hz 0x01
134 #define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_490p2Hz 0x02
135 #define SOLIDSWITCH2_CFG_2_PWM_DIV_GEN_980p4Hz 0x03
136 
141 #define SOLIDSWITCH2_OUT7 0x80
142 #define SOLIDSWITCH2_OUT6 0x40
143 #define SOLIDSWITCH2_OUT5 0x20
144 #define SOLIDSWITCH2_OUT4 0x10
145 #define SOLIDSWITCH2_OUT3 0x08
146 #define SOLIDSWITCH2_OUT2 0x04
147 #define SOLIDSWITCH2_OUT1 0x02
148 #define SOLIDSWITCH2_OUT0 0x01
149 #define SOLIDSWITCH2_OUT_NONE 0x00
150 
155 #define SOLIDSWITCH2_MAX_DUTY_CYCLE 0xFF
156 #define SOLIDSWITCH2_MIN_DUTY_CYCLE 0x00
157 
162 #define SOLIDSWITCH2_SPI_RW_BIT 0x80
163 #define SOLIDSWITCH2_SPI_ERROR_BIT 0x80
164 #define SOLIDSWITCH2_ADDRESS_BIT_MASK 0x1F
165 #define SOLIDSWITCH2_ODD_PARITY 0x01
166 #define SOLIDSWITCH2_SPI_ERROR_BIT 0x80
167 
176 #define SOLIDSWITCH2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
177 #define SOLIDSWITCH2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
178  // solidswitch2_set
180 
195 #define SOLIDSWITCH2_MAP_MIKROBUS( cfg, mikrobus ) \
196  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
197  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
198  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
199  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
200  cfg.idle = MIKROBUS( mikrobus, MIKROBUS_AN ); \
201  cfg.in0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
202  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_INT )
203  // solidswitch2_map // solidswitch2
206 
211 typedef struct
212 {
213  // Output pins
214  digital_out_t idle;
215  digital_out_t in0;
216  digital_out_t in1;
218  // Modules
219  spi_master_t spi;
221  pin_name_t chip_select;
224 
229 typedef struct
230 {
231  // Communication gpio pins
232  pin_name_t miso;
233  pin_name_t mosi;
234  pin_name_t sck;
235  pin_name_t cs;
237  // Additional gpio pins
238  pin_name_t idle;
239  pin_name_t in0;
240  pin_name_t in1;
242  // static variable
243  uint32_t spi_speed;
244  spi_master_mode_t spi_mode;
245  spi_master_chip_select_polarity_t cs_polarity;
248 
253 typedef enum
254 {
256  SOLIDSWITCH2_ERROR = -1
257 
259 
276 
291 
305 
318 err_t solidswitch2_write_register ( solidswitch2_t *ctx, uint8_t reg, uint8_t data_in );
319 
332 err_t solidswitch2_read_register ( solidswitch2_t *ctx, uint8_t reg, uint8_t *data_out );
333 
345 
355 void solidswitch2_set_idle_pin ( solidswitch2_t *ctx, uint8_t state );
356 
366 void solidswitch2_set_in0_pin ( solidswitch2_t *ctx, uint8_t state );
367 
377 void solidswitch2_set_in1_pin ( solidswitch2_t *ctx, uint8_t state );
378 
388 
398 
410 
411 #ifdef __cplusplus
412 }
413 #endif
414 #endif // SOLIDSWITCH2_H
415  // solidswitch2
417 
418 // ------------------------------------------------------------------------ END
solidswitch2_cfg_t::idle
pin_name_t idle
Definition: solidswitch2.h:238
solidswitch2_cfg_t::in1
pin_name_t in1
Definition: solidswitch2.h:240
solidswitch2_t::idle
digital_out_t idle
Definition: solidswitch2.h:214
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:245
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:244
solidswitch2_return_value_t
solidswitch2_return_value_t
SolidSwitch 2 Click return value data.
Definition: solidswitch2.h:254
SOLIDSWITCH2_OK
@ SOLIDSWITCH2_OK
Definition: solidswitch2.h:255
solidswitch2_cfg_t
SolidSwitch 2 Click configuration object.
Definition: solidswitch2.h:230
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:233
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:235
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:243
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:239
solidswitch2_cfg_t::sck
pin_name_t sck
Definition: solidswitch2.h:234
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:232
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:212
solidswitch2_t::in0
digital_out_t in0
Definition: solidswitch2.h:215
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:256
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:219
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:216
solidswitch2_t::chip_select
pin_name_t chip_select
Definition: solidswitch2.h:221