dcmotor27  2.1.0.0
dcmotor27.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 DCMOTOR27_H
29 #define DCMOTOR27_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_pwm.h"
48 
69 #define DCMOTOR27_DEF_FREQ 5000
70 
75 #define DCMOTOR27_SET_PIN_HIGH 0x01
76 #define DCMOTOR27_SET_PIN_LOW 0x00
77 
82 #define DCMOTOR27_SET_COAST_ON 0x01
83 #define DCMOTOR27_SET_COAST_OFF 0x00
84  // dcmotor27_cfg
86 
101 #define DCMOTOR27_MAP_MIKROBUS( cfg, mikrobus ) \
102  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
103  cfg.ip = MIKROBUS( mikrobus, MIKROBUS_AN ); \
104  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
105  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
106  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT );
107  // dcmotor27_map // dcmotor27
110 
115 typedef struct
116 {
117  // Output pins
118  digital_out_t rst;
119  digital_out_t cs;
121  // Input pins
122  digital_in_t ip;
123  digital_in_t flt;
125  // Modules
126  pwm_t pwm;
128  // ctx variable
129  uint32_t pwm_freq;
131 } dcmotor27_t;
132 
137 typedef struct
138 {
139  // Communication gpio pins
140  pin_name_t pwm;
142  // Additional gpio pins
143  pin_name_t ip;
144  pin_name_t rst;
145  pin_name_t cs;
146  pin_name_t flt;
148  // Static variable
149  uint32_t dev_pwm_freq;
152 
157 typedef enum
158 {
160  DCMOTOR27_ERROR = -1
161 
163 
180 
195 
209 
221 err_t dcmotor27_set_duty_cycle ( dcmotor27_t *ctx, float duty_cycle );
222 
234 
246 
256 
266 
276 void dcmotor27_set_rst_pin ( dcmotor27_t *ctx, uint8_t pin_state );
277 
287 void dcmotor27_set_cs_pin ( dcmotor27_t *ctx, uint8_t pin_state );
288 
298 void dcmotor27_set_coast ( dcmotor27_t *ctx, uint8_t coast_state );
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 #endif // DCMOTOR27_H
304  // dcmotor27
306 
307 // ------------------------------------------------------------------------ END
DCMOTOR27_OK
@ DCMOTOR27_OK
Definition: dcmotor27.h:159
dcmotor27_cfg_t::ip
pin_name_t ip
Definition: dcmotor27.h:143
dcmotor27_t::rst
digital_out_t rst
Definition: dcmotor27.h:118
dcmotor27_cfg_t::flt
pin_name_t flt
Definition: dcmotor27.h:146
dcmotor27_get_ip_pin
uint8_t dcmotor27_get_ip_pin(dcmotor27_t *ctx)
DC Motor 27 get ip pin state.
dcmotor27_t
DC Motor 27 Click context object.
Definition: dcmotor27.h:116
dcmotor27_set_duty_cycle
err_t dcmotor27_set_duty_cycle(dcmotor27_t *ctx, float duty_cycle)
DC Motor 27 sets PWM duty cycle.
dcmotor27_set_cs_pin
void dcmotor27_set_cs_pin(dcmotor27_t *ctx, uint8_t pin_state)
DC Motor 27 set CS pin state.
dcmotor27_init
err_t dcmotor27_init(dcmotor27_t *ctx, dcmotor27_cfg_t *cfg)
DC Motor 27 initialization function.
dcmotor27_t::ip
digital_in_t ip
Definition: dcmotor27.h:122
dcmotor27_cfg_t::cs
pin_name_t cs
Definition: dcmotor27.h:145
dcmotor27_t::cs
digital_out_t cs
Definition: dcmotor27.h:119
dcmotor27_default_cfg
err_t dcmotor27_default_cfg(dcmotor27_t *ctx)
DC Motor 27 default configuration function.
dcmotor27_set_coast
void dcmotor27_set_coast(dcmotor27_t *ctx, uint8_t coast_state)
DC Motor 27 set coast mode funtion.
dcmotor27_t::pwm
pwm_t pwm
Definition: dcmotor27.h:126
dcmotor27_pwm_start
err_t dcmotor27_pwm_start(dcmotor27_t *ctx)
DC Motor 27 start PWM module.
dcmotor27_get_flt_pin
uint8_t dcmotor27_get_flt_pin(dcmotor27_t *ctx)
DC Motor 27 get flt pin state.
dcmotor27_return_value_t
dcmotor27_return_value_t
DC Motor 27 Click return value data.
Definition: dcmotor27.h:158
DCMOTOR27_ERROR
@ DCMOTOR27_ERROR
Definition: dcmotor27.h:160
dcmotor27_t::flt
digital_in_t flt
Definition: dcmotor27.h:123
dcmotor27_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor27.h:149
dcmotor27_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor27.h:129
dcmotor27_cfg_setup
void dcmotor27_cfg_setup(dcmotor27_cfg_t *cfg)
DC Motor 27 configuration object setup function.
dcmotor27_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor27.h:140
dcmotor27_cfg_t
DC Motor 27 Click configuration object.
Definition: dcmotor27.h:138
dcmotor27_set_rst_pin
void dcmotor27_set_rst_pin(dcmotor27_t *ctx, uint8_t pin_state)
DC Motor 27 set RST pin state.
dcmotor27_cfg_t::rst
pin_name_t rst
Definition: dcmotor27.h:144
dcmotor27_pwm_stop
err_t dcmotor27_pwm_stop(dcmotor27_t *ctx)
DC Motor 27 stop PWM module.