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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define DCMOTOR13_REG_INPUT 0x00
60 #define DCMOTOR13_REG_OUTPUT 0x01
61 #define DCMOTOR13_REG_POLARITY 0x02
62 #define DCMOTOR13_REG_CONFIG 0x03
63  // dcmotor13_reg
65 
80 #define DCMOTOR13_LO_PIN 0x01
81 #define DCMOTOR13_AI2_PIN 0x02
82 #define DCMOTOR13_BI2_PIN 0x04
83 #define DCMOTOR13_TA1_PIN 0x08
84 #define DCMOTOR13_TA2_PIN 0x10
85 #define DCMOTOR13_TB1_PIN 0x20
86 #define DCMOTOR13_TB2_PIN 0x40
87 
92 #define DCMOTOR13_DEFAULT_CONFIG 0x81
93 
98 #define DCMOTOR13_PIN_LOW_LEVEL 0
99 #define DCMOTOR13_PIN_HIGH_LEVEL 1
100 
105 #define DCMOTOR13_MODE_SHORT_BRAKE 0x00
106 #define DCMOTOR13_MODE_CCW 0x01
107 #define DCMOTOR13_MODE_CW 0x02
108 
113 #define DCMOTOR13_TORQUE_0 0x00
114 #define DCMOTOR13_TORQUE_38 0x01
115 #define DCMOTOR13_TORQUE_71 0x02
116 #define DCMOTOR13_TORQUE_100 0x03
117 
123 #define DCMOTOR13_DEVICE_ADDRESS_A1A0_00 0x70
124 #define DCMOTOR13_DEVICE_ADDRESS_A1A0_01 0x71
125 #define DCMOTOR13_DEVICE_ADDRESS_A1A0_10 0x72
126 #define DCMOTOR13_DEVICE_ADDRESS_A1A0_11 0x73
127  // dcmotor13_set
129 
144 #define DCMOTOR13_MAP_MIKROBUS( cfg, mikrobus ) \
145  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
146  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
147  cfg.ai1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
148  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
149  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
150  cfg.bi1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
151  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
152  // dcmotor13_map // dcmotor13
155 
160 typedef struct
161 {
162  // Output pins
163  digital_out_t ai1;
164  digital_out_t slp;
165  digital_out_t rst;
166  digital_out_t bi1;
168  // Input pins
169  digital_in_t int_pin;
171  // Modules
172  i2c_master_t i2c;
174  // I2C slave address
175  uint8_t slave_address;
177 } dcmotor13_t;
178 
183 typedef struct
184 {
185  pin_name_t scl;
186  pin_name_t sda;
188  pin_name_t ai1;
189  pin_name_t slp;
190  pin_name_t rst;
191  pin_name_t bi1;
192  pin_name_t int_pin;
194  uint32_t i2c_speed;
195  uint8_t i2c_address;
198 
203 typedef enum
204 {
206  DCMOTOR13_ERROR = -1
207 
209 
226 
241 
255 
269 err_t dcmotor13_write_register ( dcmotor13_t *ctx, uint8_t reg, uint8_t data_in );
270 
283 err_t dcmotor13_read_register ( dcmotor13_t *ctx, uint8_t reg, uint8_t *data_out );
284 
294 
304 
314 
324 
334 void dcmotor13_set_ai1_pin ( dcmotor13_t *ctx, uint8_t state );
335 
345 void dcmotor13_set_bi1_pin ( dcmotor13_t *ctx, uint8_t state );
346 
358 err_t dcmotor13_get_lo_pin ( dcmotor13_t *ctx, uint8_t *pin_state );
359 
373 err_t dcmotor13_set_outa_mode ( dcmotor13_t *ctx, uint8_t mode );
374 
388 err_t dcmotor13_set_outb_mode ( dcmotor13_t *ctx, uint8_t mode );
389 
404 err_t dcmotor13_set_outa_torque ( dcmotor13_t *ctx, uint8_t torque );
405 
420 err_t dcmotor13_set_outb_torque ( dcmotor13_t *ctx, uint8_t torque );
421 
422 #ifdef __cplusplus
423 }
424 #endif
425 #endif // DCMOTOR13_H
426  // dcmotor13
428 
429 // ------------------------------------------------------------------------ END
DCMOTOR13_OK
@ DCMOTOR13_OK
Definition: dcmotor13.h:205
dcmotor13_cfg_t
DC Motor 13 Click configuration object.
Definition: dcmotor13.h:184
dcmotor13_cfg_t::sda
pin_name_t sda
Definition: dcmotor13.h:186
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:169
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:190
dcmotor13_t
DC Motor 13 Click context object.
Definition: dcmotor13.h:161
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:185
dcmotor13_cfg_t::slp
pin_name_t slp
Definition: dcmotor13.h:189
dcmotor13_cfg_t::ai1
pin_name_t ai1
Definition: dcmotor13.h:188
DCMOTOR13_ERROR
@ DCMOTOR13_ERROR
Definition: dcmotor13.h:206
dcmotor13_t::slave_address
uint8_t slave_address
Definition: dcmotor13.h:175
dcmotor13_t::ai1
digital_out_t ai1
Definition: dcmotor13.h:163
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:191
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:192
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:195
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:194
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:164
dcmotor13_t::rst
digital_out_t rst
Definition: dcmotor13.h:165
dcmotor13_return_value_t
dcmotor13_return_value_t
DC Motor 13 Click return value data.
Definition: dcmotor13.h:204
dcmotor13_t::bi1
digital_out_t bi1
Definition: dcmotor13.h:166
dcmotor13_t::i2c
i2c_master_t i2c
Definition: dcmotor13.h:172
dcmotor13_write_register
err_t dcmotor13_write_register(dcmotor13_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 13 write register function.