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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define DCMOTOR13_REG_INPUT 0x00
70 #define DCMOTOR13_REG_OUTPUT 0x01
71 #define DCMOTOR13_REG_POLARITY 0x02
72 #define DCMOTOR13_REG_CONFIG 0x03
73  // dcmotor13_reg
75 
90 #define DCMOTOR13_LO_PIN 0x01
91 #define DCMOTOR13_AI2_PIN 0x02
92 #define DCMOTOR13_BI2_PIN 0x04
93 #define DCMOTOR13_TA1_PIN 0x08
94 #define DCMOTOR13_TA2_PIN 0x10
95 #define DCMOTOR13_TB1_PIN 0x20
96 #define DCMOTOR13_TB2_PIN 0x40
97 
102 #define DCMOTOR13_DEFAULT_CONFIG 0x81
103 
108 #define DCMOTOR13_PIN_LOW_LEVEL 0
109 #define DCMOTOR13_PIN_HIGH_LEVEL 1
110 
115 #define DCMOTOR13_MODE_SHORT_BRAKE 0x00
116 #define DCMOTOR13_MODE_CCW 0x01
117 #define DCMOTOR13_MODE_CW 0x02
118 
123 #define DCMOTOR13_TORQUE_0 0x00
124 #define DCMOTOR13_TORQUE_38 0x01
125 #define DCMOTOR13_TORQUE_71 0x02
126 #define DCMOTOR13_TORQUE_100 0x03
127 
133 #define DCMOTOR13_DEVICE_ADDRESS_A1A0_00 0x70
134 #define DCMOTOR13_DEVICE_ADDRESS_A1A0_01 0x71
135 #define DCMOTOR13_DEVICE_ADDRESS_A1A0_10 0x72
136 #define DCMOTOR13_DEVICE_ADDRESS_A1A0_11 0x73
137  // dcmotor13_set
139 
154 #define DCMOTOR13_MAP_MIKROBUS( cfg, mikrobus ) \
155  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
156  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
157  cfg.ai1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
158  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
159  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
160  cfg.bi1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
161  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
162  // dcmotor13_map // dcmotor13
165 
170 typedef struct
171 {
172  // Output pins
173  digital_out_t ai1;
174  digital_out_t slp;
175  digital_out_t rst;
176  digital_out_t bi1;
178  // Input pins
179  digital_in_t int_pin;
181  // Modules
182  i2c_master_t i2c;
184  // I2C slave address
185  uint8_t slave_address;
187 } dcmotor13_t;
188 
193 typedef struct
194 {
195  pin_name_t scl;
196  pin_name_t sda;
198  pin_name_t ai1;
199  pin_name_t slp;
200  pin_name_t rst;
201  pin_name_t bi1;
202  pin_name_t int_pin;
204  uint32_t i2c_speed;
205  uint8_t i2c_address;
208 
213 typedef enum
214 {
216  DCMOTOR13_ERROR = -1
217 
219 
236 
251 
265 
279 err_t dcmotor13_write_register ( dcmotor13_t *ctx, uint8_t reg, uint8_t data_in );
280 
293 err_t dcmotor13_read_register ( dcmotor13_t *ctx, uint8_t reg, uint8_t *data_out );
294 
304 
314 
324 
334 
344 void dcmotor13_set_ai1_pin ( dcmotor13_t *ctx, uint8_t state );
345 
355 void dcmotor13_set_bi1_pin ( dcmotor13_t *ctx, uint8_t state );
356 
368 err_t dcmotor13_get_lo_pin ( dcmotor13_t *ctx, uint8_t *pin_state );
369 
383 err_t dcmotor13_set_outa_mode ( dcmotor13_t *ctx, uint8_t mode );
384 
398 err_t dcmotor13_set_outb_mode ( dcmotor13_t *ctx, uint8_t mode );
399 
414 err_t dcmotor13_set_outa_torque ( dcmotor13_t *ctx, uint8_t torque );
415 
430 err_t dcmotor13_set_outb_torque ( dcmotor13_t *ctx, uint8_t torque );
431 
432 #ifdef __cplusplus
433 }
434 #endif
435 #endif // DCMOTOR13_H
436  // dcmotor13
438 
439 // ------------------------------------------------------------------------ END
DCMOTOR13_OK
@ DCMOTOR13_OK
Definition: dcmotor13.h:215
dcmotor13_cfg_t
DC Motor 13 Click configuration object.
Definition: dcmotor13.h:194
dcmotor13_cfg_t::sda
pin_name_t sda
Definition: dcmotor13.h:196
dcmotor13_enable_device
void dcmotor13_enable_device(dcmotor13_t *ctx)
DC Motor 13 enable device function.
dcmotor13_t::int_pin
digital_in_t int_pin
Definition: dcmotor13.h:179
dcmotor13_reset_device
void dcmotor13_reset_device(dcmotor13_t *ctx)
DC Motor 13 reset device function.
dcmotor13_cfg_t::rst
pin_name_t rst
Definition: dcmotor13.h:200
dcmotor13_t
DC Motor 13 Click context object.
Definition: dcmotor13.h:171
dcmotor13_disable_device
void dcmotor13_disable_device(dcmotor13_t *ctx)
DC Motor 13 disable device function.
dcmotor13_cfg_t::scl
pin_name_t scl
Definition: dcmotor13.h:195
dcmotor13_cfg_t::slp
pin_name_t slp
Definition: dcmotor13.h:199
dcmotor13_cfg_t::ai1
pin_name_t ai1
Definition: dcmotor13.h:198
DCMOTOR13_ERROR
@ DCMOTOR13_ERROR
Definition: dcmotor13.h:216
dcmotor13_t::slave_address
uint8_t slave_address
Definition: dcmotor13.h:185
dcmotor13_t::ai1
digital_out_t ai1
Definition: dcmotor13.h:173
dcmotor13_set_outa_mode
err_t dcmotor13_set_outa_mode(dcmotor13_t *ctx, uint8_t mode)
DC Motor 13 set OUTA mode function.
dcmotor13_set_outb_torque
err_t dcmotor13_set_outb_torque(dcmotor13_t *ctx, uint8_t torque)
DC Motor 13 set OUTB torque function.
dcmotor13_init
err_t dcmotor13_init(dcmotor13_t *ctx, dcmotor13_cfg_t *cfg)
DC Motor 13 initialization function.
dcmotor13_cfg_t::bi1
pin_name_t bi1
Definition: dcmotor13.h:201
dcmotor13_set_bi1_pin
void dcmotor13_set_bi1_pin(dcmotor13_t *ctx, uint8_t state)
DC Motor 13 set BI1 pin function.
dcmotor13_cfg_setup
void dcmotor13_cfg_setup(dcmotor13_cfg_t *cfg)
DC Motor 13 configuration object setup function.
dcmotor13_set_ai1_pin
void dcmotor13_set_ai1_pin(dcmotor13_t *ctx, uint8_t state)
DC Motor 13 set AI1 pin function.
dcmotor13_get_lo_pin
err_t dcmotor13_get_lo_pin(dcmotor13_t *ctx, uint8_t *pin_state)
DC Motor 13 get LO pin function.
dcmotor13_cfg_t::int_pin
pin_name_t int_pin
Definition: dcmotor13.h:202
dcmotor13_get_int_pin
uint8_t dcmotor13_get_int_pin(dcmotor13_t *ctx)
DC Motor 13 get int pin function.
dcmotor13_cfg_t::i2c_address
uint8_t i2c_address
Definition: dcmotor13.h:205
dcmotor13_default_cfg
err_t dcmotor13_default_cfg(dcmotor13_t *ctx)
DC Motor 13 default configuration function.
dcmotor13_set_outb_mode
err_t dcmotor13_set_outb_mode(dcmotor13_t *ctx, uint8_t mode)
DC Motor 13 set OUTB mode function.
dcmotor13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dcmotor13.h:204
dcmotor13_set_outa_torque
err_t dcmotor13_set_outa_torque(dcmotor13_t *ctx, uint8_t torque)
DC Motor 13 set OUTA torque function.
dcmotor13_read_register
err_t dcmotor13_read_register(dcmotor13_t *ctx, uint8_t reg, uint8_t *data_out)
DC Motor 13 read register function.
dcmotor13_t::slp
digital_out_t slp
Definition: dcmotor13.h:174
dcmotor13_t::rst
digital_out_t rst
Definition: dcmotor13.h:175
dcmotor13_return_value_t
dcmotor13_return_value_t
DC Motor 13 Click return value data.
Definition: dcmotor13.h:214
dcmotor13_t::bi1
digital_out_t bi1
Definition: dcmotor13.h:176
dcmotor13_t::i2c
i2c_master_t i2c
Definition: dcmotor13.h:182
dcmotor13_write_register
err_t dcmotor13_write_register(dcmotor13_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 13 write register function.