dcmotor19  2.0.0.0
dcmotor19.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 DCMOTOR19_H
29 #define DCMOTOR19_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 
72 #define DCMOTOR19_CHANNEL_1 0x01
73 #define DCMOTOR19_CHANNEL_2 0x02
74 
79 #define DCMOTOR19_MODE_STOP 0x00
80 #define DCMOTOR19_MODE_FORWARD 0x01
81 #define DCMOTOR19_MODE_REVERSE 0x02
82 #define DCMOTOR19_MODE_SHORT_BRAKE 0x03
83 
88 #define DCMOTOR19_SPEED_MAX 100
89 #define DCMOTOR19_SPEED_DEFAULT 5
90 #define DCMOTOR19_SPEED_MIN 1
91 #define DCMOTOR19_MS_TIME_STEP 10
92  // dcmotor19_set
94 
109 #define DCMOTOR19_MAP_MIKROBUS( cfg, mikrobus ) \
110  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
111  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112  cfg.sby = MIKROBUS( mikrobus, MIKROBUS_CS ); \
113  cfg.in3 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
114  cfg.in4 = MIKROBUS( mikrobus, MIKROBUS_INT )
115  // dcmotor19_map // dcmotor19
118 
123 typedef struct
124 {
125  digital_out_t in1;
126  digital_out_t in2;
127  digital_out_t sby;
128  digital_out_t in3;
129  digital_out_t in4;
131  uint8_t active_ch;
132  uint8_t mode;
134 } dcmotor19_t;
135 
140 typedef struct
141 {
142  pin_name_t in1;
143  pin_name_t in2;
144  pin_name_t sby;
145  pin_name_t in3;
146  pin_name_t in4;
149 
154 typedef enum
155 {
157  DCMOTOR19_ERROR = -1
158 
160 
177 
193 
209 err_t dcmotor19_drive_motor ( dcmotor19_t *ctx, uint8_t speed, uint32_t time_ms );
210 
225 err_t dcmotor19_set_channel_mode ( dcmotor19_t *ctx, uint8_t channel, uint8_t mode );
226 
236 
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 #endif // DCMOTOR19_H
251  // dcmotor19
253 
254 // ------------------------------------------------------------------------ END
dcmotor19_cfg_t
DC Motor 19 Click configuration object.
Definition: dcmotor19.h:141
dcmotor19_init
err_t dcmotor19_init(dcmotor19_t *ctx, dcmotor19_cfg_t *cfg)
DC Motor 19 initialization function.
dcmotor19_t::sby
digital_out_t sby
Definition: dcmotor19.h:127
dcmotor19_t::in2
digital_out_t in2
Definition: dcmotor19.h:126
dcmotor19_drive_motor
err_t dcmotor19_drive_motor(dcmotor19_t *ctx, uint8_t speed, uint32_t time_ms)
DC Motor 19 drive motor function.
dcmotor19_t::in3
digital_out_t in3
Definition: dcmotor19.h:128
dcmotor19_t
DC Motor 19 Click context object.
Definition: dcmotor19.h:124
dcmotor19_t::active_ch
uint8_t active_ch
Definition: dcmotor19.h:131
dcmotor19_t::in4
digital_out_t in4
Definition: dcmotor19.h:129
dcmotor19_cfg_t::in1
pin_name_t in1
Definition: dcmotor19.h:142
dcmotor19_enable_standby_mode
void dcmotor19_enable_standby_mode(dcmotor19_t *ctx)
DC Motor 19 enable standby mode function.
dcmotor19_cfg_t::in2
pin_name_t in2
Definition: dcmotor19.h:143
dcmotor19_return_value_t
dcmotor19_return_value_t
DC Motor 19 Click return value data.
Definition: dcmotor19.h:155
dcmotor19_cfg_t::in4
pin_name_t in4
Definition: dcmotor19.h:146
dcmotor19_cfg_setup
void dcmotor19_cfg_setup(dcmotor19_cfg_t *cfg)
DC Motor 19 configuration object setup function.
dcmotor19_t::in1
digital_out_t in1
Definition: dcmotor19.h:125
dcmotor19_cfg_t::sby
pin_name_t sby
Definition: dcmotor19.h:144
dcmotor19_cfg_t::in3
pin_name_t in3
Definition: dcmotor19.h:145
DCMOTOR19_OK
@ DCMOTOR19_OK
Definition: dcmotor19.h:156
dcmotor19_disable_standby_mode
void dcmotor19_disable_standby_mode(dcmotor19_t *ctx)
DC Motor 19 disable standby mode function.
DCMOTOR19_ERROR
@ DCMOTOR19_ERROR
Definition: dcmotor19.h:157
dcmotor19_set_channel_mode
err_t dcmotor19_set_channel_mode(dcmotor19_t *ctx, uint8_t channel, uint8_t mode)
DC Motor 19 set channel mode function.
dcmotor19_t::mode
uint8_t mode
Definition: dcmotor19.h:132