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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define DCMOTOR23_REG_INPUT 0x00
60 #define DCMOTOR23_REG_OUTPUT 0x01
61 #define DCMOTOR23_REG_POLARITY 0x02
62 #define DCMOTOR23_REG_CONFIG 0x03
63  // dcmotor23_reg
65 
84 #define DCMOTOR23_LO_PIN 0x01
85 #define DCMOTOR23_PHASE_A_PIN 0x02
86 #define DCMOTOR23_PHASE_B_PIN 0x04
87 #define DCMOTOR23_TRQ_A1_PIN 0x08
88 #define DCMOTOR23_TRQ_A2_PIN 0x10
89 #define DCMOTOR23_TRQ_B1_PIN 0x20
90 #define DCMOTOR23_TRQ_B2_PIN 0x40
91 
96 #define DCMOTOR23_DEFAULT_CONFIG 0x01
97 
102 #define DCMOTOR23_PIN_LOW_LEVEL 0
103 #define DCMOTOR23_PIN_HIGH_LEVEL 1
104 
109 #define DCMOTOR23_MODE_DECAY 0x00
110 #define DCMOTOR23_MODE_CCW 0x01
111 #define DCMOTOR23_MODE_CW 0x02
112 
117 #define DCMOTOR23_TORQUE_0 0x00
118 #define DCMOTOR23_TORQUE_38 0x01
119 #define DCMOTOR23_TORQUE_71 0x02
120 #define DCMOTOR23_TORQUE_100 0x03
121 
126 #define DCMOTOR23_SEL_OUT_A 0x00
127 #define DCMOTOR23_SEL_OUT_B 0x01
128 
134 #define DCMOTOR23_DEVICE_ADDRESS_0 0x70
135 #define DCMOTOR23_DEVICE_ADDRESS_1 0x71
136 #define DCMOTOR23_DEVICE_ADDRESS_2 0x72
137 #define DCMOTOR23_DEVICE_ADDRESS_3 0x73
138  // dcmotor23_set
140 
155 #define DCMOTOR23_MAP_MIKROBUS( cfg, mikrobus ) \
156  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
157  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
158  cfg.en_a = MIKROBUS( mikrobus, MIKROBUS_CS ); \
159  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
160  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
161  cfg.en_b = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
162  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
163  // dcmotor23_map // dcmotor23
166 
171 typedef struct
172 {
173  // Output pins
174  digital_out_t en_a;
175  digital_out_t slp;
176  digital_out_t rst;
177  digital_out_t en_b;
179  // Input pins
180 
181  digital_in_t int_pin;
183  // Modules
184  i2c_master_t i2c;
186  // I2C slave address
187  uint8_t slave_address;
189 } dcmotor23_t;
190 
195 typedef struct
196 {
197  pin_name_t scl;
198  pin_name_t sda;
200  pin_name_t en_a;
201  pin_name_t slp;
202  pin_name_t rst;
203  pin_name_t en_b;
204  pin_name_t int_pin;
206  uint32_t i2c_speed;
207  uint8_t i2c_address;
210 
215 typedef enum
216 {
218  DCMOTOR23_ERROR = -1
219 
221 
238 
253 
267 
283 err_t dcmotor23_write_register ( dcmotor23_t *ctx, uint8_t reg, uint8_t data_in );
284 
300 err_t dcmotor23_read_register ( dcmotor23_t *ctx, uint8_t reg, uint8_t *data_out );
301 
315 err_t dcmotor23_get_lo_pin ( dcmotor23_t *ctx, uint8_t *pin_state );
316 
336 err_t dcmotor23_set_output_mode ( dcmotor23_t *ctx, uint8_t mode, uint8_t sel_motor );
337 
353 err_t dcmotor23_set_clockwise ( dcmotor23_t *ctx, uint8_t sel_motor );
354 
370 err_t dcmotor23_set_counter_clockwise ( dcmotor23_t *ctx, uint8_t sel_motor );
371 
388 err_t dcmotor23_set_decay ( dcmotor23_t *ctx, uint8_t sel_motor );
389 
407 err_t dcmotor23_set_outa_torque ( dcmotor23_t *ctx, uint8_t torque );
408 
426 err_t dcmotor23_set_outb_torque ( dcmotor23_t *ctx, uint8_t torque );
427 
440 
453 
466 
479 
492 void dcmotor23_set_en_a_pin ( dcmotor23_t *ctx, uint8_t state );
493 
506 void dcmotor23_set_en_b_pin ( dcmotor23_t *ctx, uint8_t state );
507 
508 #ifdef __cplusplus
509 }
510 #endif
511 #endif // DCMOTOR23_H
512  // dcmotor23
514 
515 // ------------------------------------------------------------------------ END
dcmotor23_return_value_t
dcmotor23_return_value_t
DC Motor 23 Click return value data.
Definition: dcmotor23.h:216
dcmotor23_t::int_pin
digital_in_t int_pin
Definition: dcmotor23.h:181
DCMOTOR23_ERROR
@ DCMOTOR23_ERROR
Definition: dcmotor23.h:218
dcmotor23_t::en_b
digital_out_t en_b
Definition: dcmotor23.h:177
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:206
dcmotor23_cfg_t::en_b
pin_name_t en_b
Definition: dcmotor23.h:203
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:200
dcmotor23_cfg_t::int_pin
pin_name_t int_pin
Definition: dcmotor23.h:204
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:187
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:198
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:197
dcmotor23_cfg_t::slp
pin_name_t slp
Definition: dcmotor23.h:201
dcmotor23_t
DC Motor 23 Click context object.
Definition: dcmotor23.h:172
dcmotor23_t::en_a
digital_out_t en_a
Definition: dcmotor23.h:174
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:202
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:217
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:207
dcmotor23_cfg_t
DC Motor 23 Click configuration object.
Definition: dcmotor23.h:196
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:175
dcmotor23_t::rst
digital_out_t rst
Definition: dcmotor23.h:176
dcmotor23_t::i2c
i2c_master_t i2c
Definition: dcmotor23.h:184
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.