dcmotor10  2.0.0.0
dcmotor10.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DCMOTOR10_H
36 #define DCMOTOR10_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_spi_master.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define DCMOTOR10_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.inh = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define DCMOTOR10_RETVAL uint8_t
76 
77 #define DCMOTOR10_OK 0x00
78 #define DCMOTOR10_INIT_ERROR 0xFF
79 
85 #define DCMOTOR10_STATUS_REG_RST 0x0001
86 #define DCMOTOR10_LS_SWITCH_1 0x0002
87 #define DCMOTOR10_HS_SWITCH_1 0x0004
88 #define DCMOTOR10_LS_SWITCH_2 0x0008
89 #define DCMOTOR10_HS_SWITCH_2 0x0010
90 #define DCMOTOR10_LS_SWITCH_3 0x0020
91 #define DCMOTOR10_HS_SWITCH_3 0x0040
92 #define DCMOTOR10_LS_SWITCH_4 0x0080
93 #define DCMOTOR10_HS_SWITCH_4 0x0100
94 #define DCMOTOR10_LS_SWITCH_5 0x0200
95 #define DCMOTOR10_HS_SWITCH_5 0x0400
96 #define DCMOTOR10_LS_SWITCH_6 0x0800
97 #define DCMOTOR10_HS_SWITCH_6 0x1000
98 #define DCMOTOR10_OVERCURRENT_SHUT_DOWN 0x2000
99 #define DCMOTOR10_UNDERLOAD_SHUT_DOWN 0x4000
100 #define DCMOTOR10_OVER_VOLT_LOCKOUT 0x8000
101 
107 #define DCMOTOR10_TEMP_PREWARNING 0x0001
108 #define DCMOTOR10_STATUS_LS_SWITCH_1 0x0002
109 #define DCMOTOR10_STATUS_HS_SWITCH_1 0x0004
110 #define DCMOTOR10_STATUS_LS_SWITCH_2 0x0008
111 #define DCMOTOR10_STATUS_HS_SWITCH_2 0x0010
112 #define DCMOTOR10_STATUS_LS_SWITCH_3 0x0020
113 #define DCMOTOR10_STATUS_HS_SWITCH_3 0x0040
114 #define DCMOTOR10_STATUS_LS_SWITCH_4 0x0080
115 #define DCMOTOR10_STATUS_HS_SWITCH_4 0x0100
116 #define DCMOTOR10_STATUS_LS_SWITCH_5 0x0200
117 #define DCMOTOR10_STATUS_HS_SWITCH_5 0x0400
118 #define DCMOTOR10_STATUS_LS_SWITCH_6 0x0800
119 #define DCMOTOR10_STATUS_HS_SWITCH_6 0x1000
120 #define DCMOTOR10_OVERLOAD 0x2000
121 #define DCMOTOR10_UNDERLOAD 0x4000
122 #define DCMOTOR10_POWER_SUPPLY_FAIL 0x8000
123 
129 #define DCMOTOR10_OVERCURRENT_FAULT 0x2000
130 #define DCMOTOR10_GND_SHORT_CIRCUIT 0x2000
131 #define DCMOTOR10_VS_SHORT_CIRCUIT 0x2000
132 #define DCMOTOR10_TEMP_WARNING 0x0001
133 #define DCMOTOR10_OPENLOAD_FAULT 0x4000
134 #define DCMOTOR10_UNDERLOAD_FAULT 0x4000
135 #define DCMOTOR10_UNDER_VOLT_LOCKOUT_FAULT 0x8000
136 #define DCMOTOR10_OVER_VOLT_LOCKOUT_FAULT 0x8000
137 
143 #define DCMOTOR10_RESET_STATUS_REG 0x0001
144 #define DCMOTOR10_ENABLE_1 0x000E
145 #define DCMOTOR10_ENABLE_2 0x0038
146 #define DCMOTOR10_ENABLE_3 0x00E0
147 #define DCMOTOR10_ENABLE_4 0x0380
148 #define DCMOTOR10_ENABLE_5 0x0E00
149 #define DCMOTOR10_ENABLE_6 0x3800
150 #define DCMOTOR10_ENABLE_ALL 0x1FFE
151 
157 #define DCMOTOR10_HB_ENABLE_1_CV 0x000C
158 #define DCMOTOR10_HB_ENABLE_1_CCV 0x0012
159 #define DCMOTOR10_HB_ENABLE_2_CV 0x0030
160 #define DCMOTOR10_HB_ENABLE_2_CCV 0x0048
161 #define DCMOTOR10_HB_ENABLE_3_CV 0x00C0
162 #define DCMOTOR10_HB_ENABLE_3_CCV 0x0120
163 #define DCMOTOR10_HB_ENABLE_4_CV 0x0300
164 #define DCMOTOR10_HB_ENABLE_4_CCV 0x0480
165 #define DCMOTOR10_HB_ENABLE_5_CV 0x0C00
166 #define DCMOTOR10_HB_ENABLE_5_CCV 0x1200
167 
173 #define DCMOTOR10_8_BIT_DATA 0xFF
174 #define DCMOTOR10_INHIBIT 0x00
175 #define DCMOTOR10_UNINHIBIT 0x01
176  // End group macro
179 // --------------------------------------------------------------- PUBLIC TYPES
188 typedef struct
189 {
190  // Output pins
191 
192  digital_out_t cs;
193  digital_out_t inh;
194 
195  // Modules
196 
197  spi_master_t spi;
198 
199  // Ctx variable
200 
201  uint8_t slave_address;
202  pin_name_t chip_select;
203 
204 } dcmotor10_t;
205 
209 typedef struct
210 {
211  // Communication gpio pins
212 
213  pin_name_t miso;
214  pin_name_t mosi;
215  pin_name_t sck;
216  pin_name_t cs;
217 
218  // Additional gpio pins
219 
220  pin_name_t inh;
221 
222  // static variable
223 
224  uint32_t spi_speed;
225  spi_master_mode_t spi_mode;
226  spi_master_chip_select_polarity_t cs_polarity;
227 
229  // End types group
231 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
232 
237 #ifdef __cplusplus
238 extern "C"{
239 #endif
240 
250 
260 
270 void dcmotor10_send_cmd ( dcmotor10_t *ctx, uint16_t wr_data );
271 
283 
292 void dcmotor10_inhibit ( dcmotor10_t *ctx, uint8_t state );
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 #endif // _DCMOTOR10_H_
298  // End public_function group
301 
302 // ------------------------------------------------------------------------- END
dcmotor10_cfg_t::miso
pin_name_t miso
Definition: dcmotor10.h:213
dcmotor10_cfg_t
Click configuration structure definition.
Definition: dcmotor10.h:210
DCMOTOR10_RETVAL
#define DCMOTOR10_RETVAL
Definition: dcmotor10.h:75
dcmotor10_t::slave_address
uint8_t slave_address
Definition: dcmotor10.h:201
dcmotor10_t::spi
spi_master_t spi
Definition: dcmotor10.h:197
dcmotor10_read_status
uint16_t dcmotor10_read_status(dcmotor10_t *ctx)
Read status function.
dcmotor10_init
DCMOTOR10_RETVAL dcmotor10_init(dcmotor10_t *ctx, dcmotor10_cfg_t *cfg)
Initialization function.
dcmotor10_cfg_setup
void dcmotor10_cfg_setup(dcmotor10_cfg_t *cfg)
Config Object Initialization function.
dcmotor10_t::chip_select
pin_name_t chip_select
Definition: dcmotor10.h:202
dcmotor10_send_cmd
void dcmotor10_send_cmd(dcmotor10_t *ctx, uint16_t wr_data)
Send command function.
dcmotor10_cfg_t::sck
pin_name_t sck
Definition: dcmotor10.h:215
dcmotor10_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dcmotor10.h:225
dcmotor10_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dcmotor10.h:226
dcmotor10_cfg_t::cs
pin_name_t cs
Definition: dcmotor10.h:216
dcmotor10_cfg_t::inh
pin_name_t inh
Definition: dcmotor10.h:220
dcmotor10_t::cs
digital_out_t cs
Definition: dcmotor10.h:192
dcmotor10_cfg_t::mosi
pin_name_t mosi
Definition: dcmotor10.h:214
dcmotor10_cfg_t::spi_speed
uint32_t spi_speed
Definition: dcmotor10.h:224
dcmotor10_t::inh
digital_out_t inh
Definition: dcmotor10.h:193
dcmotor10_inhibit
void dcmotor10_inhibit(dcmotor10_t *ctx, uint8_t state)
Inhibit device function.
dcmotor10_t
Click ctx object definition.
Definition: dcmotor10.h:189