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 
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  // 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  // 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  // dcmotor13_map // dcmotor13
169 
174 typedef 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
189  uint8_t slave_address;
191 } dcmotor13_t;
192 
197 typedef 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 
217 typedef enum
218 {
220  DCMOTOR13_ERROR = -1
221 
223 
240 
255 
269 
283 err_t dcmotor13_write_register ( dcmotor13_t *ctx, uint8_t reg, uint8_t data_in );
284 
297 err_t dcmotor13_read_register ( dcmotor13_t *ctx, uint8_t reg, uint8_t *data_out );
298 
308 
318 
328 
338 
348 void dcmotor13_set_ai1_pin ( dcmotor13_t *ctx, uint8_t state );
349 
359 void dcmotor13_set_bi1_pin ( dcmotor13_t *ctx, uint8_t state );
360 
372 err_t dcmotor13_get_lo_pin ( dcmotor13_t *ctx, uint8_t *pin_state );
373 
387 err_t dcmotor13_set_outa_mode ( dcmotor13_t *ctx, uint8_t mode );
388 
402 err_t dcmotor13_set_outb_mode ( dcmotor13_t *ctx, uint8_t mode );
403 
418 err_t dcmotor13_set_outa_torque ( dcmotor13_t *ctx, uint8_t torque );
419 
434 err_t dcmotor13_set_outb_torque ( dcmotor13_t *ctx, uint8_t torque );
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 #endif // DCMOTOR13_H
440  // dcmotor13
442 
443 // ------------------------------------------------------------------------ END
DCMOTOR13_OK
@ DCMOTOR13_OK
Definition: dcmotor13.h:219
dcmotor13_cfg_t
DC Motor 13 Click configuration object.
Definition: dcmotor13.h:198
dcmotor13_cfg_t::sda
pin_name_t sda
Definition: dcmotor13.h:200
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:183
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:204
dcmotor13_t
DC Motor 13 Click context object.
Definition: dcmotor13.h:175
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:199
dcmotor13_cfg_t::slp
pin_name_t slp
Definition: dcmotor13.h:203
dcmotor13_cfg_t::ai1
pin_name_t ai1
Definition: dcmotor13.h:202
DCMOTOR13_ERROR
@ DCMOTOR13_ERROR
Definition: dcmotor13.h:220
dcmotor13_t::slave_address
uint8_t slave_address
Definition: dcmotor13.h:189
dcmotor13_t::ai1
digital_out_t ai1
Definition: dcmotor13.h:177
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:205
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:206
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:209
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:208
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:178
dcmotor13_t::rst
digital_out_t rst
Definition: dcmotor13.h:179
dcmotor13_return_value_t
dcmotor13_return_value_t
DC Motor 13 Click return value data.
Definition: dcmotor13.h:218
dcmotor13_t::bi1
digital_out_t bi1
Definition: dcmotor13.h:180
dcmotor13_t::i2c
i2c_master_t i2c
Definition: dcmotor13.h:186
dcmotor13_write_register
err_t dcmotor13_write_register(dcmotor13_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 13 write register function.