dcmotor23  2.1.0.0
dcmotor23.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 DCMOTOR23_H
29 #define DCMOTOR23_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 DCMOTOR23_REG_INPUT 0x00
74 #define DCMOTOR23_REG_OUTPUT 0x01
75 #define DCMOTOR23_REG_POLARITY 0x02
76 #define DCMOTOR23_REG_CONFIG 0x03
77  // dcmotor23_reg
79 
98 #define DCMOTOR23_LO_PIN 0x01
99 #define DCMOTOR23_PHASE_A_PIN 0x02
100 #define DCMOTOR23_PHASE_B_PIN 0x04
101 #define DCMOTOR23_TRQ_A1_PIN 0x08
102 #define DCMOTOR23_TRQ_A2_PIN 0x10
103 #define DCMOTOR23_TRQ_B1_PIN 0x20
104 #define DCMOTOR23_TRQ_B2_PIN 0x40
105 
110 #define DCMOTOR23_DEFAULT_CONFIG 0x01
111 
116 #define DCMOTOR23_PIN_LOW_LEVEL 0
117 #define DCMOTOR23_PIN_HIGH_LEVEL 1
118 
123 #define DCMOTOR23_MODE_DECAY 0x00
124 #define DCMOTOR23_MODE_CCW 0x01
125 #define DCMOTOR23_MODE_CW 0x02
126 
131 #define DCMOTOR23_TORQUE_0 0x00
132 #define DCMOTOR23_TORQUE_38 0x01
133 #define DCMOTOR23_TORQUE_71 0x02
134 #define DCMOTOR23_TORQUE_100 0x03
135 
140 #define DCMOTOR23_SEL_OUT_A 0x00
141 #define DCMOTOR23_SEL_OUT_B 0x01
142 
148 #define DCMOTOR23_DEVICE_ADDRESS_0 0x70
149 #define DCMOTOR23_DEVICE_ADDRESS_1 0x71
150 #define DCMOTOR23_DEVICE_ADDRESS_2 0x72
151 #define DCMOTOR23_DEVICE_ADDRESS_3 0x73
152  // dcmotor23_set
154 
169 #define DCMOTOR23_MAP_MIKROBUS( cfg, mikrobus ) \
170  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
171  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
172  cfg.en_a = MIKROBUS( mikrobus, MIKROBUS_CS ); \
173  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
174  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
175  cfg.en_b = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
176  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
177  // dcmotor23_map // dcmotor23
180 
185 typedef struct
186 {
187  // Output pins
188  digital_out_t en_a;
189  digital_out_t slp;
190  digital_out_t rst;
191  digital_out_t en_b;
193  // Input pins
194 
195  digital_in_t int_pin;
197  // Modules
198  i2c_master_t i2c;
200  // I2C slave address
201  uint8_t slave_address;
203 } dcmotor23_t;
204 
209 typedef struct
210 {
211  pin_name_t scl;
212  pin_name_t sda;
214  pin_name_t en_a;
215  pin_name_t slp;
216  pin_name_t rst;
217  pin_name_t en_b;
218  pin_name_t int_pin;
220  uint32_t i2c_speed;
221  uint8_t i2c_address;
224 
229 typedef enum
230 {
232  DCMOTOR23_ERROR = -1
233 
235 
252 
267 
281 
297 err_t dcmotor23_write_register ( dcmotor23_t *ctx, uint8_t reg, uint8_t data_in );
298 
314 err_t dcmotor23_read_register ( dcmotor23_t *ctx, uint8_t reg, uint8_t *data_out );
315 
329 err_t dcmotor23_get_lo_pin ( dcmotor23_t *ctx, uint8_t *pin_state );
330 
350 err_t dcmotor23_set_output_mode ( dcmotor23_t *ctx, uint8_t mode, uint8_t sel_motor );
351 
367 err_t dcmotor23_set_clockwise ( dcmotor23_t *ctx, uint8_t sel_motor );
368 
384 err_t dcmotor23_set_counter_clockwise ( dcmotor23_t *ctx, uint8_t sel_motor );
385 
402 err_t dcmotor23_set_decay ( dcmotor23_t *ctx, uint8_t sel_motor );
403 
421 err_t dcmotor23_set_outa_torque ( dcmotor23_t *ctx, uint8_t torque );
422 
440 err_t dcmotor23_set_outb_torque ( dcmotor23_t *ctx, uint8_t torque );
441 
454 
467 
480 
493 
506 void dcmotor23_set_en_a_pin ( dcmotor23_t *ctx, uint8_t state );
507 
520 void dcmotor23_set_en_b_pin ( dcmotor23_t *ctx, uint8_t state );
521 
522 #ifdef __cplusplus
523 }
524 #endif
525 #endif // DCMOTOR23_H
526  // dcmotor23
528 
529 // ------------------------------------------------------------------------ END
dcmotor23_return_value_t
dcmotor23_return_value_t
DC Motor 23 Click return value data.
Definition: dcmotor23.h:230
dcmotor23_t::int_pin
digital_in_t int_pin
Definition: dcmotor23.h:195
DCMOTOR23_ERROR
@ DCMOTOR23_ERROR
Definition: dcmotor23.h:232
dcmotor23_t::en_b
digital_out_t en_b
Definition: dcmotor23.h:191
dcmotor23_get_int_pin
uint8_t dcmotor23_get_int_pin(dcmotor23_t *ctx)
DC Motor 23 get INT pin function.
dcmotor23_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dcmotor23.h:220
dcmotor23_cfg_t::en_b
pin_name_t en_b
Definition: dcmotor23.h:217
dcmotor23_set_en_b_pin
void dcmotor23_set_en_b_pin(dcmotor23_t *ctx, uint8_t state)
DC Motor 23 set EN_B pin function.
dcmotor23_cfg_t::en_a
pin_name_t en_a
Definition: dcmotor23.h:214
dcmotor23_cfg_t::int_pin
pin_name_t int_pin
Definition: dcmotor23.h:218
dcmotor23_set_output_mode
err_t dcmotor23_set_output_mode(dcmotor23_t *ctx, uint8_t mode, uint8_t sel_motor)
DC Motor 23 set output mode function.
dcmotor23_t::slave_address
uint8_t slave_address
Definition: dcmotor23.h:201
dcmotor23_write_register
err_t dcmotor23_write_register(dcmotor23_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 23 I2C writing function.
dcmotor23_cfg_t::sda
pin_name_t sda
Definition: dcmotor23.h:212
dcmotor23_sleep_mode
void dcmotor23_sleep_mode(dcmotor23_t *ctx)
DC Motor 23 set sleep operation mode function.
dcmotor23_init
err_t dcmotor23_init(dcmotor23_t *ctx, dcmotor23_cfg_t *cfg)
DC Motor 23 initialization function.
dcmotor23_read_register
err_t dcmotor23_read_register(dcmotor23_t *ctx, uint8_t reg, uint8_t *data_out)
DC Motor 23 I2C reading function.
dcmotor23_cfg_t::scl
pin_name_t scl
Definition: dcmotor23.h:211
dcmotor23_cfg_t::slp
pin_name_t slp
Definition: dcmotor23.h:215
dcmotor23_t
DC Motor 23 Click context object.
Definition: dcmotor23.h:186
dcmotor23_t::en_a
digital_out_t en_a
Definition: dcmotor23.h:188
dcmotor23_set_decay
err_t dcmotor23_set_decay(dcmotor23_t *ctx, uint8_t sel_motor)
DC Motor 23 set decay function.
dcmotor23_set_outb_torque
err_t dcmotor23_set_outb_torque(dcmotor23_t *ctx, uint8_t torque)
DC Motor 23 set OUTB torque function.
dcmotor23_normal_operation_mode
void dcmotor23_normal_operation_mode(dcmotor23_t *ctx)
DC Motor 23 set normal operation mode function.
dcmotor23_set_clockwise
err_t dcmotor23_set_clockwise(dcmotor23_t *ctx, uint8_t sel_motor)
DC Motor 23 set clockwise function.
dcmotor23_get_lo_pin
err_t dcmotor23_get_lo_pin(dcmotor23_t *ctx, uint8_t *pin_state)
DC Motor 23 get LO pin function.
dcmotor23_default_cfg
err_t dcmotor23_default_cfg(dcmotor23_t *ctx)
DC Motor 23 default configuration function.
dcmotor23_cfg_t::rst
pin_name_t rst
Definition: dcmotor23.h:216
dcmotor23_cfg_setup
void dcmotor23_cfg_setup(dcmotor23_cfg_t *cfg)
DC Motor 23 configuration object setup function.
DCMOTOR23_OK
@ DCMOTOR23_OK
Definition: dcmotor23.h:231
dcmotor23_reset_device
void dcmotor23_reset_device(dcmotor23_t *ctx)
DC Motor 23 reset device function.
dcmotor23_cfg_t::i2c_address
uint8_t i2c_address
Definition: dcmotor23.h:221
dcmotor23_cfg_t
DC Motor 23 Click configuration object.
Definition: dcmotor23.h:210
dcmotor23_set_en_a_pin
void dcmotor23_set_en_a_pin(dcmotor23_t *ctx, uint8_t state)
DC Motor 23 set EN_A pin function.
dcmotor23_t::slp
digital_out_t slp
Definition: dcmotor23.h:189
dcmotor23_t::rst
digital_out_t rst
Definition: dcmotor23.h:190
dcmotor23_t::i2c
i2c_master_t i2c
Definition: dcmotor23.h:198
dcmotor23_set_outa_torque
err_t dcmotor23_set_outa_torque(dcmotor23_t *ctx, uint8_t torque)
DC Motor 23 set OUTA torque function.
dcmotor23_set_counter_clockwise
err_t dcmotor23_set_counter_clockwise(dcmotor23_t *ctx, uint8_t sel_motor)
DC Motor 23 set counter clockwise function.