dcmotor8  2.0.0.0
dcmotor8.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 DCMOTOR8_H
36 #define DCMOTOR8_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_pwm.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define DCMOTOR8_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
65 
71 #define DCMOTOR8_RETVAL uint8_t
72 
73 #define DCMOTOR8_OK 0x00
74 #define DCMOTOR8_INIT_ERROR 0xFF
75 
81 #define DCMOTOR8_ENABLE 1
82 #define DCMOTOR8_DISABLE 0
83 
89 #define DCMOTOR8_DEF_FREQ 20000
90  // End group macro
93 // --------------------------------------------------------------- PUBLIC TYPES
102 typedef struct
103 {
104 
105  // Output pins
106 
107  digital_out_t en;
108 
109  // Modules
110 
111  pwm_t pwm;
112 
113  // ctx variable
114 
115  uint32_t pwm_freq;
116 
117 } dcmotor8_t;
118 
122 typedef struct
123 {
124  // Communication gpio pins
125 
126  pin_name_t pwm;
127 
128  // Additional gpio pins
129 
130  pin_name_t en;
131 
132  // static variable
133 
134  uint32_t dev_pwm_freq;
135 
137  // End types group
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
159 
169 
178 void dcmotor8_set_duty_cycle ( dcmotor8_t *ctx, float duty_cycle );
179 
188 
197 
206 void dcmotor8_enable ( dcmotor8_t *ctx, uint8_t state );
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 #endif // _DCMOTOR8_H_
212  // End public_function group
215 
216 // ------------------------------------------------------------------------- END
dcmotor8_enable
void dcmotor8_enable(dcmotor8_t *ctx, uint8_t state)
Enable function.
dcmotor8_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor8.h:126
dcmotor8_pwm_start
void dcmotor8_pwm_start(dcmotor8_t *ctx)
Start PWM module.
dcmotor8_init
DCMOTOR8_RETVAL dcmotor8_init(dcmotor8_t *ctx, dcmotor8_cfg_t *cfg)
Initialization function.
dcmotor8_t::en
digital_out_t en
Definition: dcmotor8.h:107
dcmotor8_t
Click ctx object definition.
Definition: dcmotor8.h:103
dcmotor8_cfg_setup
void dcmotor8_cfg_setup(dcmotor8_cfg_t *cfg)
Config Object Initialization function.
dcmotor8_set_duty_cycle
void dcmotor8_set_duty_cycle(dcmotor8_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
dcmotor8_pwm_stop
void dcmotor8_pwm_stop(dcmotor8_t *ctx)
Stop PWM module.
dcmotor8_cfg_t::en
pin_name_t en
Definition: dcmotor8.h:130
DCMOTOR8_RETVAL
#define DCMOTOR8_RETVAL
Definition: dcmotor8.h:71
dcmotor8_t::pwm
pwm_t pwm
Definition: dcmotor8.h:111
dcmotor8_cfg_t
Click configuration structure definition.
Definition: dcmotor8.h:123
dcmotor8_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor8.h:134
dcmotor8_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor8.h:115