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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_spi_master.h"
54
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define DCMOTOR10_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.inh = MIKROBUS( mikrobus, MIKROBUS_INT )
79#define DCMOTOR10_RETVAL uint8_t
80
81#define DCMOTOR10_OK 0x00
82#define DCMOTOR10_INIT_ERROR 0xFF
89#define DCMOTOR10_STATUS_REG_RST 0x0001
90#define DCMOTOR10_LS_SWITCH_1 0x0002
91#define DCMOTOR10_HS_SWITCH_1 0x0004
92#define DCMOTOR10_LS_SWITCH_2 0x0008
93#define DCMOTOR10_HS_SWITCH_2 0x0010
94#define DCMOTOR10_LS_SWITCH_3 0x0020
95#define DCMOTOR10_HS_SWITCH_3 0x0040
96#define DCMOTOR10_LS_SWITCH_4 0x0080
97#define DCMOTOR10_HS_SWITCH_4 0x0100
98#define DCMOTOR10_LS_SWITCH_5 0x0200
99#define DCMOTOR10_HS_SWITCH_5 0x0400
100#define DCMOTOR10_LS_SWITCH_6 0x0800
101#define DCMOTOR10_HS_SWITCH_6 0x1000
102#define DCMOTOR10_OVERCURRENT_SHUT_DOWN 0x2000
103#define DCMOTOR10_UNDERLOAD_SHUT_DOWN 0x4000
104#define DCMOTOR10_OVER_VOLT_LOCKOUT 0x8000
111#define DCMOTOR10_TEMP_PREWARNING 0x0001
112#define DCMOTOR10_STATUS_LS_SWITCH_1 0x0002
113#define DCMOTOR10_STATUS_HS_SWITCH_1 0x0004
114#define DCMOTOR10_STATUS_LS_SWITCH_2 0x0008
115#define DCMOTOR10_STATUS_HS_SWITCH_2 0x0010
116#define DCMOTOR10_STATUS_LS_SWITCH_3 0x0020
117#define DCMOTOR10_STATUS_HS_SWITCH_3 0x0040
118#define DCMOTOR10_STATUS_LS_SWITCH_4 0x0080
119#define DCMOTOR10_STATUS_HS_SWITCH_4 0x0100
120#define DCMOTOR10_STATUS_LS_SWITCH_5 0x0200
121#define DCMOTOR10_STATUS_HS_SWITCH_5 0x0400
122#define DCMOTOR10_STATUS_LS_SWITCH_6 0x0800
123#define DCMOTOR10_STATUS_HS_SWITCH_6 0x1000
124#define DCMOTOR10_OVERLOAD 0x2000
125#define DCMOTOR10_UNDERLOAD 0x4000
126#define DCMOTOR10_POWER_SUPPLY_FAIL 0x8000
133#define DCMOTOR10_OVERCURRENT_FAULT 0x2000
134#define DCMOTOR10_GND_SHORT_CIRCUIT 0x2000
135#define DCMOTOR10_VS_SHORT_CIRCUIT 0x2000
136#define DCMOTOR10_TEMP_WARNING 0x0001
137#define DCMOTOR10_OPENLOAD_FAULT 0x4000
138#define DCMOTOR10_UNDERLOAD_FAULT 0x4000
139#define DCMOTOR10_UNDER_VOLT_LOCKOUT_FAULT 0x8000
140#define DCMOTOR10_OVER_VOLT_LOCKOUT_FAULT 0x8000
147#define DCMOTOR10_RESET_STATUS_REG 0x0001
148#define DCMOTOR10_ENABLE_1 0x000E
149#define DCMOTOR10_ENABLE_2 0x0038
150#define DCMOTOR10_ENABLE_3 0x00E0
151#define DCMOTOR10_ENABLE_4 0x0380
152#define DCMOTOR10_ENABLE_5 0x0E00
153#define DCMOTOR10_ENABLE_6 0x3800
154#define DCMOTOR10_ENABLE_ALL 0x1FFE
161#define DCMOTOR10_HB_ENABLE_1_CV 0x000C
162#define DCMOTOR10_HB_ENABLE_1_CCV 0x0012
163#define DCMOTOR10_HB_ENABLE_2_CV 0x0030
164#define DCMOTOR10_HB_ENABLE_2_CCV 0x0048
165#define DCMOTOR10_HB_ENABLE_3_CV 0x00C0
166#define DCMOTOR10_HB_ENABLE_3_CCV 0x0120
167#define DCMOTOR10_HB_ENABLE_4_CV 0x0300
168#define DCMOTOR10_HB_ENABLE_4_CCV 0x0480
169#define DCMOTOR10_HB_ENABLE_5_CV 0x0C00
170#define DCMOTOR10_HB_ENABLE_5_CCV 0x1200
177#define DCMOTOR10_8_BIT_DATA 0xFF
178#define DCMOTOR10_INHIBIT 0x00
179#define DCMOTOR10_UNINHIBIT 0x01
182 // End group macro
183// --------------------------------------------------------------- PUBLIC TYPES
192typedef struct
193{
194 // Output pins
195
196 digital_out_t cs;
197 digital_out_t inh;
198
199 // Modules
200
201 spi_master_t spi;
202
203 // Ctx variable
204
206 pin_name_t chip_select;
207
209
213typedef struct
214{
215 // Communication gpio pins
216
217 pin_name_t miso;
218 pin_name_t mosi;
219 pin_name_t sck;
220 pin_name_t cs;
221
222 // Additional gpio pins
223
224 pin_name_t inh;
225
226 // static variable
227
228 uint32_t spi_speed;
229 spi_master_mode_t spi_mode;
230 spi_master_chip_select_polarity_t cs_polarity;
231
233
234 // End types group
235// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
236
241#ifdef __cplusplus
242extern "C"{
243#endif
244
254
264
274void dcmotor10_send_cmd ( dcmotor10_t *ctx, uint16_t wr_data );
275
287
296void dcmotor10_inhibit ( dcmotor10_t *ctx, uint8_t state );
297
298#ifdef __cplusplus
299}
300#endif
301#endif // _DCMOTOR10_H_
302
303 // End public_function group
305
306// ------------------------------------------------------------------------- END
#define DCMOTOR10_RETVAL
Definition dcmotor10.h:79
DCMOTOR10_RETVAL dcmotor10_init(dcmotor10_t *ctx, dcmotor10_cfg_t *cfg)
Initialization function.
void dcmotor10_send_cmd(dcmotor10_t *ctx, uint16_t wr_data)
Send command function.
uint16_t dcmotor10_read_status(dcmotor10_t *ctx)
Read status function.
void dcmotor10_inhibit(dcmotor10_t *ctx, uint8_t state)
Inhibit device function.
void dcmotor10_cfg_setup(dcmotor10_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition dcmotor10.h:214
pin_name_t inh
Definition dcmotor10.h:224
spi_master_chip_select_polarity_t cs_polarity
Definition dcmotor10.h:230
pin_name_t sck
Definition dcmotor10.h:219
spi_master_mode_t spi_mode
Definition dcmotor10.h:229
pin_name_t mosi
Definition dcmotor10.h:218
uint32_t spi_speed
Definition dcmotor10.h:228
pin_name_t miso
Definition dcmotor10.h:217
pin_name_t cs
Definition dcmotor10.h:220
Click ctx object definition.
Definition dcmotor10.h:193
digital_out_t cs
Definition dcmotor10.h:196
spi_master_t spi
Definition dcmotor10.h:201
digital_out_t inh
Definition dcmotor10.h:197
uint8_t slave_address
Definition dcmotor10.h:205
pin_name_t chip_select
Definition dcmotor10.h:206