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
32extern "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#include "drv_pwm.h"
52
73#define DCMOTOR27_DEF_FREQ 5000
74
79#define DCMOTOR27_SET_PIN_HIGH 0x01
80#define DCMOTOR27_SET_PIN_LOW 0x00
81
86#define DCMOTOR27_SET_COAST_ON 0x01
87#define DCMOTOR27_SET_COAST_OFF 0x00
88
89 // dcmotor27_cfg
90
105#define DCMOTOR27_MAP_MIKROBUS( cfg, mikrobus ) \
106 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
107 cfg.ip = MIKROBUS( mikrobus, MIKROBUS_AN ); \
108 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
109 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
110 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT );
111
112 // dcmotor27_map
113 // dcmotor27
114
119typedef struct
120{
121 // Output pins
122 digital_out_t rst;
123 digital_out_t cs;
125 // Input pins
126 digital_in_t ip;
127 digital_in_t flt;
129 // Modules
130 pwm_t pwm;
132 // ctx variable
133 uint32_t pwm_freq;
136
141typedef struct
142{
143 // Communication gpio pins
144 pin_name_t pwm;
146 // Additional gpio pins
147 pin_name_t ip;
148 pin_name_t rst;
149 pin_name_t cs;
150 pin_name_t flt;
152 // Static variable
153 uint32_t dev_pwm_freq;
156
167
184
199
213
225err_t dcmotor27_set_duty_cycle ( dcmotor27_t *ctx, float duty_cycle );
226
238
250
260
270
280void dcmotor27_set_rst_pin ( dcmotor27_t *ctx, uint8_t pin_state );
281
291void dcmotor27_set_cs_pin ( dcmotor27_t *ctx, uint8_t pin_state );
292
302void dcmotor27_set_coast ( dcmotor27_t *ctx, uint8_t coast_state );
303
304#ifdef __cplusplus
305}
306#endif
307#endif // DCMOTOR27_H
308
309 // dcmotor27
310
311// ------------------------------------------------------------------------ END
dcmotor27_return_value_t
DC Motor 27 Click return value data.
Definition dcmotor27.h:162
@ DCMOTOR27_ERROR
Definition dcmotor27.h:164
@ DCMOTOR27_OK
Definition dcmotor27.h:163
uint8_t dcmotor27_get_ip_pin(dcmotor27_t *ctx)
DC Motor 27 get ip pin state.
uint8_t dcmotor27_get_flt_pin(dcmotor27_t *ctx)
DC Motor 27 get flt pin state.
void dcmotor27_cfg_setup(dcmotor27_cfg_t *cfg)
DC Motor 27 configuration object setup function.
err_t dcmotor27_set_duty_cycle(dcmotor27_t *ctx, float duty_cycle)
DC Motor 27 sets PWM duty cycle.
err_t dcmotor27_init(dcmotor27_t *ctx, dcmotor27_cfg_t *cfg)
DC Motor 27 initialization function.
err_t dcmotor27_pwm_start(dcmotor27_t *ctx)
DC Motor 27 start PWM module.
err_t dcmotor27_default_cfg(dcmotor27_t *ctx)
DC Motor 27 default configuration function.
void dcmotor27_set_cs_pin(dcmotor27_t *ctx, uint8_t pin_state)
DC Motor 27 set CS pin state.
void dcmotor27_set_rst_pin(dcmotor27_t *ctx, uint8_t pin_state)
DC Motor 27 set RST pin state.
void dcmotor27_set_coast(dcmotor27_t *ctx, uint8_t coast_state)
DC Motor 27 set coast mode funtion.
err_t dcmotor27_pwm_stop(dcmotor27_t *ctx)
DC Motor 27 stop PWM module.
DC Motor 27 Click configuration object.
Definition dcmotor27.h:142
pin_name_t ip
Definition dcmotor27.h:147
uint32_t dev_pwm_freq
Definition dcmotor27.h:153
pin_name_t flt
Definition dcmotor27.h:150
pin_name_t pwm
Definition dcmotor27.h:144
pin_name_t rst
Definition dcmotor27.h:148
pin_name_t cs
Definition dcmotor27.h:149
DC Motor 27 Click context object.
Definition dcmotor27.h:120
digital_out_t cs
Definition dcmotor27.h:123
digital_in_t flt
Definition dcmotor27.h:127
uint32_t pwm_freq
Definition dcmotor27.h:133
digital_in_t ip
Definition dcmotor27.h:126
digital_out_t rst
Definition dcmotor27.h:122
pwm_t pwm
Definition dcmotor27.h:130