dcmotor7  2.0.0.0
dcmotor7.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef DCMOTOR7_H
36 #define DCMOTOR7_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define DCMOTOR7_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.pwma = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.pwmb = MIKROBUS( mikrobus, MIKROBUS_PWM )
67 
73 #define DCMOTOR7_RETVAL uint8_t
74 
75 #define DCMOTOR7_OK 0x00
76 #define DCMOTOR7_INIT_ERROR 0xFF
77 
83 #define DCMOTOR7_CMD_INPUT_PORT 0x00 // def xxxx xxxx
84 #define DCMOTOR7_CMD_OUTPUT_PORT 0x01 // def 1111 1111
85 #define DCMOTOR7_CMD_POLARITY_INVERSION 0x02 // def 0000 0000
86 #define DCMOTOR7_CMD_CONFIGURATION 0x03 // def 1111 1111
87 
93 #define DCMOTOR7_PORT_0 0x01
94 #define DCMOTOR7_PORT_1 0x02
95 #define DCMOTOR7_PORT_2 0x04
96 #define DCMOTOR7_PORT_3 0x08
97 #define DCMOTOR7_PORT_4 0x10
98 #define DCMOTOR7_PORT_5 0x20
99 #define DCMOTOR7_PORT_6 0x40
100 #define DCMOTOR7_PORT_7 0x80
101 
107 #define DCMOTOR7_TBLK_FOSCM_X4_CLK 0x00
108 #define DCMOTOR7_TBLK_FOSCM_X6_CLK 0x01
109 
115 #define DCMOTOR7_HBMODE_SMALL_MODE 0x00
116 #define DCMOTOR7_HBMODE_LARGE_MODE 0x01
117 
123 #define DCMOTOR7_MOTOR_A 0x01
124 #define DCMOTOR7_MOTOR_B 0x02
125 
131 #define DCMOTOR7_SLAVE_ADDRESS_0_0 0x70
132 #define DCMOTOR7_SLAVE_ADDRESS_0_1 0x71
133 #define DCMOTOR7_SLAVE_ADDRESS_1_0 0x72
134 #define DCMOTOR7_SLAVE_ADDRESS_1_1 0x73
135 
141 #define DCMOTOR7_ENABLE_ALL_OUTPUT_PORT 0x00
142 #define DCMOTOR7_DISABLE_ALL_OUTPUT_PORT 0xFF
143  // End group macro
146 // --------------------------------------------------------------- PUBLIC TYPES
155 typedef struct
156 {
157  // Output pins
158 
159  digital_out_t pwma;
160  digital_out_t pwmb;
161 
162  // Modules
163 
164  i2c_master_t i2c;
165 
166  // ctx variable
167 
168  uint8_t slave_address;
169 
170 } dcmotor7_t;
171 
175 typedef struct
176 {
177  // Communication gpio pins
178 
179  pin_name_t scl;
180  pin_name_t sda;
181 
182  // Additional gpio pins
183 
184  pin_name_t pwma;
185  pin_name_t pwmb;
186 
187  // static variable
188 
189  uint32_t i2c_speed;
190  uint8_t i2c_address;
191 
193  // End types group
195 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
196 
202 #ifdef __cplusplus
203 extern "C"{
204 #endif
205 
215 
225 
243 
253 void dcmotor7_generic_write ( dcmotor7_t *ctx, uint8_t reg, uint8_t tmp );
254 
265 void dcmotor7_generic_read ( dcmotor7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
266 
274 void dcmotor7_set_port ( dcmotor7_t *ctx, uint8_t port, uint8_t value );
275 
284 void dcmotor7_set_motor ( dcmotor7_t *ctx, uint8_t motor, uint8_t in1, uint8_t in2 );
285 
292 void dcmotor7_set_tblkab ( dcmotor7_t *ctx, uint8_t tblk );
293 
300 void dcmotor7_set_hb_mode ( dcmotor7_t *ctx, uint8_t mode );
301 
308 void dcmotor7_motor_stop ( dcmotor7_t *ctx, uint8_t motor );
309 
316 void dcmotor7_go_to_stand_by_mode ( dcmotor7_t *ctx, uint8_t motor );
317 
324 void dcmotor7_set_pwm_motor_a ( dcmotor7_t *ctx, uint8_t state );
325 
332 void dcmotor7_set_pwm_motor_b ( dcmotor7_t *ctx, uint8_t state );
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 #endif // _DCMOTOR7_H_
338  // End public_function group
341 
342 // ------------------------------------------------------------------------- END
dcmotor7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: dcmotor7.h:189
dcmotor7_set_pwm_motor_b
void dcmotor7_set_pwm_motor_b(dcmotor7_t *ctx, uint8_t state)
Function for set PWM value for motor B.
dcmotor7_set_pwm_motor_a
void dcmotor7_set_pwm_motor_a(dcmotor7_t *ctx, uint8_t state)
Function for set PWM value for motor A.
dcmotor7_t::pwma
digital_out_t pwma
Definition: dcmotor7.h:159
dcmotor7_set_hb_mode
void dcmotor7_set_hb_mode(dcmotor7_t *ctx, uint8_t mode)
Functions for set H-Bridge operation mode.
DCMOTOR7_RETVAL
#define DCMOTOR7_RETVAL
Definition: dcmotor7.h:73
dcmotor7_cfg_t::i2c_address
uint8_t i2c_address
Definition: dcmotor7.h:190
dcmotor7_cfg_t::pwma
pin_name_t pwma
Definition: dcmotor7.h:184
dcmotor7_cfg_t::pwmb
pin_name_t pwmb
Definition: dcmotor7.h:185
dcmotor7_t
Click ctx object definition.
Definition: dcmotor7.h:156
dcmotor7_cfg_setup
void dcmotor7_cfg_setup(dcmotor7_cfg_t *cfg)
Config Object Initialization function.
dcmotor7_cfg_t::sda
pin_name_t sda
Definition: dcmotor7.h:180
dcmotor7_cfg_t::scl
pin_name_t scl
Definition: dcmotor7.h:179
dcmotor7_t::pwmb
digital_out_t pwmb
Definition: dcmotor7.h:160
dcmotor7_set_motor
void dcmotor7_set_motor(dcmotor7_t *ctx, uint8_t motor, uint8_t in1, uint8_t in2)
Functions for set Motor.
dcmotor7_t::slave_address
uint8_t slave_address
Definition: dcmotor7.h:168
dcmotor7_init
DCMOTOR7_RETVAL dcmotor7_init(dcmotor7_t *ctx, dcmotor7_cfg_t *cfg)
Initialization function.
dcmotor7_cfg_t
Click configuration structure definition.
Definition: dcmotor7.h:176
dcmotor7_motor_stop
void dcmotor7_motor_stop(dcmotor7_t *ctx, uint8_t motor)
Motor stop function.
dcmotor7_set_port
void dcmotor7_set_port(dcmotor7_t *ctx, uint8_t port, uint8_t value)
Functions for set port.
dcmotor7_go_to_stand_by_mode
void dcmotor7_go_to_stand_by_mode(dcmotor7_t *ctx, uint8_t motor)
Function for setting the motor in stand mode.
dcmotor7_generic_write
void dcmotor7_generic_write(dcmotor7_t *ctx, uint8_t reg, uint8_t tmp)
Generic write function.
dcmotor7_set_tblkab
void dcmotor7_set_tblkab(dcmotor7_t *ctx, uint8_t tblk)
Functions for set Motor Ach and Bch Digital tBLK.
dcmotor7_default_cfg
void dcmotor7_default_cfg(dcmotor7_t *ctx)
Default Confuguration.
dcmotor7_generic_read
void dcmotor7_generic_read(dcmotor7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
dcmotor7_t::i2c
i2c_master_t i2c
Definition: dcmotor7.h:164