dcmotor13 2.0.0.0
dcmotor13.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 DCMOTOR13_H
29#define DCMOTOR13_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_i2c_master.h"
52
73#define DCMOTOR13_REG_INPUT 0x00
74#define DCMOTOR13_REG_OUTPUT 0x01
75#define DCMOTOR13_REG_POLARITY 0x02
76#define DCMOTOR13_REG_CONFIG 0x03
77
78 // dcmotor13_reg
79
94#define DCMOTOR13_LO_PIN 0x01
95#define DCMOTOR13_AI2_PIN 0x02
96#define DCMOTOR13_BI2_PIN 0x04
97#define DCMOTOR13_TA1_PIN 0x08
98#define DCMOTOR13_TA2_PIN 0x10
99#define DCMOTOR13_TB1_PIN 0x20
100#define DCMOTOR13_TB2_PIN 0x40
101
106#define DCMOTOR13_DEFAULT_CONFIG 0x81
107
112#define DCMOTOR13_PIN_LOW_LEVEL 0
113#define DCMOTOR13_PIN_HIGH_LEVEL 1
114
119#define DCMOTOR13_MODE_SHORT_BRAKE 0x00
120#define DCMOTOR13_MODE_CCW 0x01
121#define DCMOTOR13_MODE_CW 0x02
122
127#define DCMOTOR13_TORQUE_0 0x00
128#define DCMOTOR13_TORQUE_38 0x01
129#define DCMOTOR13_TORQUE_71 0x02
130#define DCMOTOR13_TORQUE_100 0x03
131
137#define DCMOTOR13_DEVICE_ADDRESS_A1A0_00 0x70
138#define DCMOTOR13_DEVICE_ADDRESS_A1A0_01 0x71
139#define DCMOTOR13_DEVICE_ADDRESS_A1A0_10 0x72
140#define DCMOTOR13_DEVICE_ADDRESS_A1A0_11 0x73
141
142 // dcmotor13_set
143
158#define DCMOTOR13_MAP_MIKROBUS( cfg, mikrobus ) \
159 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
160 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
161 cfg.ai1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
162 cfg.slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
163 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
164 cfg.bi1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
165 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
166
167 // dcmotor13_map
168 // dcmotor13
169
174typedef struct
175{
176 // Output pins
177 digital_out_t ai1;
178 digital_out_t slp;
179 digital_out_t rst;
180 digital_out_t bi1;
182 // Input pins
183 digital_in_t int_pin;
185 // Modules
186 i2c_master_t i2c;
188 // I2C slave address
192
197typedef struct
198{
199 pin_name_t scl;
200 pin_name_t sda;
202 pin_name_t ai1;
203 pin_name_t slp;
204 pin_name_t rst;
205 pin_name_t bi1;
206 pin_name_t int_pin;
208 uint32_t i2c_speed;
209 uint8_t i2c_address;
212
223
240
255
269
283err_t dcmotor13_write_register ( dcmotor13_t *ctx, uint8_t reg, uint8_t data_in );
284
297err_t dcmotor13_read_register ( dcmotor13_t *ctx, uint8_t reg, uint8_t *data_out );
298
308
318
328
338
348void dcmotor13_set_ai1_pin ( dcmotor13_t *ctx, uint8_t state );
349
359void dcmotor13_set_bi1_pin ( dcmotor13_t *ctx, uint8_t state );
360
372err_t dcmotor13_get_lo_pin ( dcmotor13_t *ctx, uint8_t *pin_state );
373
387err_t dcmotor13_set_outa_mode ( dcmotor13_t *ctx, uint8_t mode );
388
402err_t dcmotor13_set_outb_mode ( dcmotor13_t *ctx, uint8_t mode );
403
418err_t dcmotor13_set_outa_torque ( dcmotor13_t *ctx, uint8_t torque );
419
434err_t dcmotor13_set_outb_torque ( dcmotor13_t *ctx, uint8_t torque );
435
436#ifdef __cplusplus
437}
438#endif
439#endif // DCMOTOR13_H
440
441 // dcmotor13
442
443// ------------------------------------------------------------------------ END
dcmotor13_return_value_t
DC Motor 13 Click return value data.
Definition dcmotor13.h:218
@ DCMOTOR13_ERROR
Definition dcmotor13.h:220
@ DCMOTOR13_OK
Definition dcmotor13.h:219
err_t dcmotor13_init(dcmotor13_t *ctx, dcmotor13_cfg_t *cfg)
DC Motor 13 initialization function.
err_t dcmotor13_set_outa_mode(dcmotor13_t *ctx, uint8_t mode)
DC Motor 13 set OUTA mode function.
err_t dcmotor13_set_outa_torque(dcmotor13_t *ctx, uint8_t torque)
DC Motor 13 set OUTA torque function.
err_t dcmotor13_set_outb_mode(dcmotor13_t *ctx, uint8_t mode)
DC Motor 13 set OUTB mode function.
err_t dcmotor13_set_outb_torque(dcmotor13_t *ctx, uint8_t torque)
DC Motor 13 set OUTB torque function.
void dcmotor13_disable_device(dcmotor13_t *ctx)
DC Motor 13 disable device function.
void dcmotor13_set_bi1_pin(dcmotor13_t *ctx, uint8_t state)
DC Motor 13 set BI1 pin function.
err_t dcmotor13_read_register(dcmotor13_t *ctx, uint8_t reg, uint8_t *data_out)
DC Motor 13 read register function.
void dcmotor13_reset_device(dcmotor13_t *ctx)
DC Motor 13 reset device function.
void dcmotor13_set_ai1_pin(dcmotor13_t *ctx, uint8_t state)
DC Motor 13 set AI1 pin function.
err_t dcmotor13_default_cfg(dcmotor13_t *ctx)
DC Motor 13 default configuration function.
void dcmotor13_cfg_setup(dcmotor13_cfg_t *cfg)
DC Motor 13 configuration object setup function.
err_t dcmotor13_write_register(dcmotor13_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 13 write register function.
err_t dcmotor13_get_lo_pin(dcmotor13_t *ctx, uint8_t *pin_state)
DC Motor 13 get LO pin function.
void dcmotor13_enable_device(dcmotor13_t *ctx)
DC Motor 13 enable device function.
uint8_t dcmotor13_get_int_pin(dcmotor13_t *ctx)
DC Motor 13 get int pin function.
DC Motor 13 Click configuration object.
Definition dcmotor13.h:198
pin_name_t slp
Definition dcmotor13.h:203
uint32_t i2c_speed
Definition dcmotor13.h:208
pin_name_t scl
Definition dcmotor13.h:199
pin_name_t int_pin
Definition dcmotor13.h:206
pin_name_t ai1
Definition dcmotor13.h:202
pin_name_t sda
Definition dcmotor13.h:200
pin_name_t rst
Definition dcmotor13.h:204
pin_name_t bi1
Definition dcmotor13.h:205
uint8_t i2c_address
Definition dcmotor13.h:209
DC Motor 13 Click context object.
Definition dcmotor13.h:175
digital_out_t slp
Definition dcmotor13.h:178
digital_in_t int_pin
Definition dcmotor13.h:183
i2c_master_t i2c
Definition dcmotor13.h:186
digital_out_t rst
Definition dcmotor13.h:179
uint8_t slave_address
Definition dcmotor13.h:189
digital_out_t bi1
Definition dcmotor13.h:180
digital_out_t ai1
Definition dcmotor13.h:177