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 "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 DCMOTOR23_REG_INPUT 0x00
70 #define DCMOTOR23_REG_OUTPUT 0x01
71 #define DCMOTOR23_REG_POLARITY 0x02
72 #define DCMOTOR23_REG_CONFIG 0x03
73  // dcmotor23_reg
75 
94 #define DCMOTOR23_LO_PIN 0x01
95 #define DCMOTOR23_PHASE_A_PIN 0x02
96 #define DCMOTOR23_PHASE_B_PIN 0x04
97 #define DCMOTOR23_TRQ_A1_PIN 0x08
98 #define DCMOTOR23_TRQ_A2_PIN 0x10
99 #define DCMOTOR23_TRQ_B1_PIN 0x20
100 #define DCMOTOR23_TRQ_B2_PIN 0x40
101 
106 #define DCMOTOR23_DEFAULT_CONFIG 0x01
107 
112 #define DCMOTOR23_PIN_LOW_LEVEL 0
113 #define DCMOTOR23_PIN_HIGH_LEVEL 1
114 
119 #define DCMOTOR23_MODE_DECAY 0x00
120 #define DCMOTOR23_MODE_CCW 0x01
121 #define DCMOTOR23_MODE_CW 0x02
122 
127 #define DCMOTOR23_TORQUE_0 0x00
128 #define DCMOTOR23_TORQUE_38 0x01
129 #define DCMOTOR23_TORQUE_71 0x02
130 #define DCMOTOR23_TORQUE_100 0x03
131 
136 #define DCMOTOR23_SEL_OUT_A 0x00
137 #define DCMOTOR23_SEL_OUT_B 0x01
138 
144 #define DCMOTOR23_DEVICE_ADDRESS_0 0x70
145 #define DCMOTOR23_DEVICE_ADDRESS_1 0x71
146 #define DCMOTOR23_DEVICE_ADDRESS_2 0x72
147 #define DCMOTOR23_DEVICE_ADDRESS_3 0x73
148  // dcmotor23_set
150 
165 #define DCMOTOR23_MAP_MIKROBUS( cfg, mikrobus ) \
166  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
167  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
168  cfg.en_a = MIKROBUS( mikrobus, MIKROBUS_CS ); \
169  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
170  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
171  cfg.en_b = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
172  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
173  // dcmotor23_map // dcmotor23
176 
181 typedef struct
182 {
183  // Output pins
184  digital_out_t en_a;
185  digital_out_t slp;
186  digital_out_t rst;
187  digital_out_t en_b;
189  // Input pins
190 
191  digital_in_t int_pin;
193  // Modules
194  i2c_master_t i2c;
196  // I2C slave address
197  uint8_t slave_address;
199 } dcmotor23_t;
200 
205 typedef struct
206 {
207  pin_name_t scl;
208  pin_name_t sda;
210  pin_name_t en_a;
211  pin_name_t slp;
212  pin_name_t rst;
213  pin_name_t en_b;
214  pin_name_t int_pin;
216  uint32_t i2c_speed;
217  uint8_t i2c_address;
220 
225 typedef enum
226 {
228  DCMOTOR23_ERROR = -1
229 
231 
248 
263 
277 
293 err_t dcmotor23_write_register ( dcmotor23_t *ctx, uint8_t reg, uint8_t data_in );
294 
310 err_t dcmotor23_read_register ( dcmotor23_t *ctx, uint8_t reg, uint8_t *data_out );
311 
325 err_t dcmotor23_get_lo_pin ( dcmotor23_t *ctx, uint8_t *pin_state );
326 
346 err_t dcmotor23_set_output_mode ( dcmotor23_t *ctx, uint8_t mode, uint8_t sel_motor );
347 
363 err_t dcmotor23_set_clockwise ( dcmotor23_t *ctx, uint8_t sel_motor );
364 
380 err_t dcmotor23_set_counter_clockwise ( dcmotor23_t *ctx, uint8_t sel_motor );
381 
398 err_t dcmotor23_set_decay ( dcmotor23_t *ctx, uint8_t sel_motor );
399 
417 err_t dcmotor23_set_outa_torque ( dcmotor23_t *ctx, uint8_t torque );
418 
436 err_t dcmotor23_set_outb_torque ( dcmotor23_t *ctx, uint8_t torque );
437 
450 
463 
476 
489 
502 void dcmotor23_set_en_a_pin ( dcmotor23_t *ctx, uint8_t state );
503 
516 void dcmotor23_set_en_b_pin ( dcmotor23_t *ctx, uint8_t state );
517 
518 #ifdef __cplusplus
519 }
520 #endif
521 #endif // DCMOTOR23_H
522  // dcmotor23
524 
525 // ------------------------------------------------------------------------ END
dcmotor23_return_value_t
dcmotor23_return_value_t
DC Motor 23 Click return value data.
Definition: dcmotor23.h:226
dcmotor23_t::int_pin
digital_in_t int_pin
Definition: dcmotor23.h:191
DCMOTOR23_ERROR
@ DCMOTOR23_ERROR
Definition: dcmotor23.h:228
dcmotor23_t::en_b
digital_out_t en_b
Definition: dcmotor23.h:187
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:216
dcmotor23_cfg_t::en_b
pin_name_t en_b
Definition: dcmotor23.h:213
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:210
dcmotor23_cfg_t::int_pin
pin_name_t int_pin
Definition: dcmotor23.h:214
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:197
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:208
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:207
dcmotor23_cfg_t::slp
pin_name_t slp
Definition: dcmotor23.h:211
dcmotor23_t
DC Motor 23 Click context object.
Definition: dcmotor23.h:182
dcmotor23_t::en_a
digital_out_t en_a
Definition: dcmotor23.h:184
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:212
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:227
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:217
dcmotor23_cfg_t
DC Motor 23 Click configuration object.
Definition: dcmotor23.h:206
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:185
dcmotor23_t::rst
digital_out_t rst
Definition: dcmotor23.h:186
dcmotor23_t::i2c
i2c_master_t i2c
Definition: dcmotor23.h:194
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.