dcmotor29 2.1.0.0
dcmotor29.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 DCMOTOR29_H
29#define DCMOTOR29_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#include "drv_i2c_master.h"
54
75#define DCMOTOR29_REG_DEVICE_ID 0x00
76#define DCMOTOR29_REG_FAULT_SUMMARY 0x01
77#define DCMOTOR29_REG_STATUS1 0x02
78#define DCMOTOR29_REG_STATUS2 0x03
79#define DCMOTOR29_REG_COMMAND 0x08
80#define DCMOTOR29_REG_SPI_IN 0x09
81#define DCMOTOR29_REG_CONFIG1 0x0A
82#define DCMOTOR29_REG_CONFIG2 0x0B
83#define DCMOTOR29_REG_CONFIG3 0x0C
84#define DCMOTOR29_REG_CONFIG4 0x0D
85#define DCMOTOR29_REG_INPUT_PORT 0x00
86#define DCMOTOR29_REG_OUTPUT_PORT 0x01
87#define DCMOTOR29_REG_POLARITY_INV 0x02
88#define DCMOTOR29_REG_CONFIG 0x03
89
90 // dcmotor29_reg
91
106#define DCMOTOR29_CLR_FLT_CMD 0x80
107#define DCMOTOR29_SPI_IN_UNLOCK_CMD 0x10
108#define DCMOTOR29_SPI_IN_LOCK_CMD 0x08
109#define DCMOTOR29_REG_UNLOCK_CMD 0x01
110#define DCMOTOR29_REG_LOCK_CMD 0x02
111
117#define DCMOTOR29_NONE_PIN 0x00
118#define DCMOTOR29_IN2_PIN 0x01
119#define DCMOTOR29_DOF_PIN 0x02
120#define DCMOTOR29_FLT_PIN 0x04
121#define DCMOTOR29_ALL_PIN 0x07
122
128#define DCMOTOR29_READ_REG_MASK 0x40
129
135#define DCMOTOR29_DRVOFF_ON 0x01
136#define DCMOTOR29_DRVOFF_OFF 0x00
137
143#define DCMOTOR29_PIN_STATE_HIGH 0x01
144#define DCMOTOR29_PIN_STATE_LOW 0x00
145
151#define DCMOTOR29_S_EN_DEVOFF_MASK 0x08
152#define DCMOTOR29_S_EN_DEVOFF2_MASK 0x04
153#define DCMOTOR29_S_EN_IN1_MASK 0x02
154#define DCMOTOR29_S_EN_IN2_MASK 0x01
155#define DCMOTOR29_S_EN_NONE 0x00
156
162#define DCMOTOR29_EN_OLA 0x80
163#define DCMOTOR29_VMOV_SEL_DISABLED 0x60
164#define DCMOTOR29_VMOV_SEL_18V 0x40
165#define DCMOTOR29_VMOV_SEL_28V 0x20
166#define DCMOTOR29_VMOV_SEL_35V 0x00
167#define DCMOTOR29_SSC_DISABLE 0x10
168#define DCMOTOR29_OCP_RETRY 0x08
169#define DCMOTOR29_TSD_RETRY 0x04
170#define DCMOTOR29_VMOV_RETRY 0x02
171#define DCMOTOR29_OLA_RETRY 0x01
172
178#define DCMOTOR29_TOF_50_US 0xC0
179#define DCMOTOR29_TOF_40_US 0x80
180#define DCMOTOR29_TOF_30_US 0x40
181#define DCMOTOR29_TOF_20_US 0x00
182#define DCMOTOR29_S_SR_50_V_US 0x1C
183#define DCMOTOR29_S_SR_38_V_US 0x18
184#define DCMOTOR29_S_SR_26_V_US 0x14
185#define DCMOTOR29_S_SR_20_V_US 0x10
186#define DCMOTOR29_S_SR_14_V_US 0x0C
187#define DCMOTOR29_S_SR_9_8V_US 0x08
188#define DCMOTOR29_S_SR_5_V_US 0x04
189#define DCMOTOR29_S_SR_1_5V_US 0x00
190#define DCMOTOR29_S_MODE_PWM 0x03
191#define DCMOTOR29_S_MODE_INDEPENDENT 0x01
192#define DCMOTOR29_S_MODE_PH_EN 0x00
193
199#define DCMOTOR29_DRIVE_MOTOR_CW 0x00
200#define DCMOTOR29_DRIVE_MOTOR_CCW 0x01
201#define DCMOTOR29_DRIVE_MOTOR_BRAKE 0x02
202#define DCMOTOR29_DRIVE_MOTOR_COASTING 0x03
203
209#define DCMOTOR29_DEVICE_ADDRESS_A1A0_00 0x70
210#define DCMOTOR29_DEVICE_ADDRESS_A1A0_01 0x71
211#define DCMOTOR29_DEVICE_ADDRESS_A1A0_10 0x72
212#define DCMOTOR29_DEVICE_ADDRESS_A1A0_11 0x73
213
222#define DCMOTOR29_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
223#define DCMOTOR29_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
224
225 // dcmotor29_set
226
241#define DCMOTOR29_MAP_MIKROBUS( cfg, mikrobus ) \
242 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
243 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
244 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
245 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
246 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
247 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
248 cfg.ip = MIKROBUS( mikrobus, MIKROBUS_AN ); \
249 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
250 cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
251 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
252
253 // dcmotor29_map
254 // dcmotor29
255
260typedef struct
261{
262 // Output pins
263 digital_out_t rst;
264 digital_out_t in1;
266 // Input pins
267 digital_in_t ip;
268 digital_in_t int_pin;
270 // Modules
271 spi_master_t spi;
272 i2c_master_t i2c;
274 // I2C slave address
277 pin_name_t chip_select;
280
285typedef struct
286{
287 // Communication gpio pins
288 pin_name_t miso;
289 pin_name_t mosi;
290 pin_name_t sck;
291 pin_name_t cs;
292 pin_name_t scl;
293 pin_name_t sda;
295 // Additional gpio pins
296 pin_name_t ip;
297 pin_name_t rst;
298 pin_name_t in1;
299 pin_name_t int_pin;
301 // static variable
302 uint32_t spi_speed;
303 spi_master_mode_t spi_mode;
304 spi_master_chip_select_polarity_t cs_polarity;
305 uint32_t i2c_speed;
306 uint8_t i2c_address;
309
320
337
352
366
381err_t dcmotor29_generic_write ( dcmotor29_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
382
397err_t dcmotor29_generic_read ( dcmotor29_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
398
408void dcmotor29_set_in1_pin ( dcmotor29_t *ctx, uint8_t pin_state );
409
419void dcmotor29_set_rst_pin ( dcmotor29_t *ctx, uint8_t pin_state );
420
430
440
455err_t dcmotor29_register_write ( dcmotor29_t *ctx, uint8_t reg, uint8_t data_in );
456
470err_t dcmotor29_register_read ( dcmotor29_t *ctx, uint8_t reg, uint8_t *data_out );
471
486err_t dcmotor29_port_expander_write ( dcmotor29_t *ctx, uint8_t reg, uint8_t data_in );
487
501err_t dcmotor29_port_expander_read ( dcmotor29_t *ctx, uint8_t reg, uint8_t *data_out );
502
515err_t dcmotor29_set_pins ( dcmotor29_t *ctx, uint8_t set_mask, uint8_t clr_mask );
516
528err_t dcmotor29_drvoff_state ( dcmotor29_t *ctx, uint8_t drvoff_state );
529
541err_t dcmotor29_drive_motor ( dcmotor29_t *ctx, uint8_t state );
542
543#ifdef __cplusplus
544}
545#endif
546#endif // DCMOTOR29_H
547
548 // dcmotor29
549
550// ------------------------------------------------------------------------ END
dcmotor29_return_value_t
DC Motor 29 Click return value data.
Definition dcmotor29.h:315
@ DCMOTOR29_OK
Definition dcmotor29.h:316
@ DCMOTOR29_ERROR
Definition dcmotor29.h:317
err_t dcmotor29_drive_motor(dcmotor29_t *ctx, uint8_t state)
DC Motor 29 drive motor function.
err_t dcmotor29_register_write(dcmotor29_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 29 data register writing function.
void dcmotor29_cfg_setup(dcmotor29_cfg_t *cfg)
DC Motor 29 configuration object setup function.
err_t dcmotor29_drvoff_state(dcmotor29_t *ctx, uint8_t drvoff_state)
DC Motor 29 control drvoff function.
uint8_t dcmotor29_get_ip_pin(dcmotor29_t *ctx)
DC Motor 29 get IP pin function.
err_t dcmotor29_port_expander_read(dcmotor29_t *ctx, uint8_t reg, uint8_t *data_out)
DC Motor 29 port ecpander read register function.
void dcmotor29_set_in1_pin(dcmotor29_t *ctx, uint8_t pin_state)
DC Motor 29 set IN1 pin function.
err_t dcmotor29_generic_write(dcmotor29_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
DC Motor 29 data writing function.
err_t dcmotor29_default_cfg(dcmotor29_t *ctx)
DC Motor 29 default configuration function.
err_t dcmotor29_set_pins(dcmotor29_t *ctx, uint8_t set_mask, uint8_t clr_mask)
DC Motor 29 set pins function.
err_t dcmotor29_generic_read(dcmotor29_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
DC Motor 29 data reading function.
uint8_t dcmotor29_get_int_pin(dcmotor29_t *ctx)
DC Motor 29 get INT pin function.
void dcmotor29_set_rst_pin(dcmotor29_t *ctx, uint8_t pin_state)
DC Motor 29 set RST pin function.
err_t dcmotor29_port_expander_write(dcmotor29_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 29 port ecpander write register function.
err_t dcmotor29_init(dcmotor29_t *ctx, dcmotor29_cfg_t *cfg)
DC Motor 29 initialization function.
err_t dcmotor29_register_read(dcmotor29_t *ctx, uint8_t reg, uint8_t *data_out)
DC Motor 29 data register reading function.
This file contains SPI specific macros, functions, etc.
DC Motor 29 Click configuration object.
Definition dcmotor29.h:286
uint32_t i2c_speed
Definition dcmotor29.h:305
pin_name_t ip
Definition dcmotor29.h:296
spi_master_chip_select_polarity_t cs_polarity
Definition dcmotor29.h:304
pin_name_t sck
Definition dcmotor29.h:290
spi_master_mode_t spi_mode
Definition dcmotor29.h:303
pin_name_t mosi
Definition dcmotor29.h:289
uint32_t spi_speed
Definition dcmotor29.h:302
pin_name_t scl
Definition dcmotor29.h:292
pin_name_t in1
Definition dcmotor29.h:298
pin_name_t int_pin
Definition dcmotor29.h:299
pin_name_t miso
Definition dcmotor29.h:288
pin_name_t sda
Definition dcmotor29.h:293
pin_name_t rst
Definition dcmotor29.h:297
pin_name_t cs
Definition dcmotor29.h:291
uint8_t i2c_address
Definition dcmotor29.h:306
DC Motor 29 Click context object.
Definition dcmotor29.h:261
spi_master_t spi
Definition dcmotor29.h:271
digital_in_t int_pin
Definition dcmotor29.h:268
i2c_master_t i2c
Definition dcmotor29.h:272
digital_in_t ip
Definition dcmotor29.h:267
digital_out_t rst
Definition dcmotor29.h:263
uint8_t slave_address
Definition dcmotor29.h:275
pin_name_t chip_select
Definition dcmotor29.h:277
digital_out_t in1
Definition dcmotor29.h:264