stspin250 2.0.0.0
stspin250.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 STSPIN250_H
36#define STSPIN250_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_pwm.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define STSPIN250_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68 cfg.ph = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define STSPIN250_RETVAL uint8_t
79
80#define STSPIN250_OK 0x00
81#define STSPIN250_INIT_ERROR 0xFF
88#define STSPIN250_DEVICE_ENABLE 1
89#define STSPIN250_DEVICE_DISABLE 0
96#define STSPIN250_DEF_FREQ 20000 //500
99 // End group macro
100// --------------------------------------------------------------- PUBLIC TYPES
109typedef struct
110{
111
112 // Output pins
113
114 digital_out_t ph;
115 digital_out_t rst;
116 digital_out_t en;
117
118 // Input pins
119
120 digital_in_t flt;
121
122 // Modules
123
124 pwm_t pwm;
125
126 // ctx variable
127
128 uint32_t pwm_freq;
129
131
135typedef struct
136{
137 // Communication gpio pins
138
139 pin_name_t pwm;
140
141 // Additional gpio pins
142
143 pin_name_t ph;
144 pin_name_t rst;
145 pin_name_t en;
146 pin_name_t flt;
147
148 // static variable
149
150 uint32_t dev_pwm_freq;
151
153
154 // End types group
155// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156
162#ifdef __cplusplus
163extern "C"{
164#endif
165
175
185
194
203void stspin250_set_duty_cycle ( stspin250_t *ctx, float duty_cycle );
204
213
222
231void stspin250_enable ( stspin250_t *ctx, uint8_t state);
232
242void stspin250_set_ph ( stspin250_t *ctx, uint8_t state );
243
253
263
264#ifdef __cplusplus
265}
266#endif
267#endif // _STSPIN250_H_
268
269 // End public_function group
271
272// ------------------------------------------------------------------------- END
#define STSPIN250_RETVAL
Definition stspin250.h:78
void stspin250_pwm_start(stspin250_t *ctx)
Start PWM module.
uint8_t stspin250_get_fault(stspin250_t *ctx)
Fault get function.
STSPIN250_RETVAL stspin250_init(stspin250_t *ctx, stspin250_cfg_t *cfg)
Initialization function.
void stspin250_enable(stspin250_t *ctx, uint8_t state)
Enable pin function.
void stspin250_cfg_setup(stspin250_cfg_t *cfg)
Config Object Initialization function.
void stspin250_set_duty_cycle(stspin250_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void stspin250_set_ph(stspin250_t *ctx, uint8_t state)
Dir ctrl pin function.
void stspin250_reset(stspin250_t *ctx)
Reset pin function.
void stspin250_pwm_stop(stspin250_t *ctx)
Stop PWM module.
void stspin250_default_cfg(stspin250_t *ctx)
Click Default Configuration function.
Click configuration structure definition.
Definition stspin250.h:136
pin_name_t ph
Definition stspin250.h:143
uint32_t dev_pwm_freq
Definition stspin250.h:150
pin_name_t flt
Definition stspin250.h:146
pin_name_t en
Definition stspin250.h:145
pin_name_t pwm
Definition stspin250.h:139
pin_name_t rst
Definition stspin250.h:144
Click ctx object definition.
Definition stspin250.h:110
digital_in_t flt
Definition stspin250.h:120
uint32_t pwm_freq
Definition stspin250.h:128
digital_out_t en
Definition stspin250.h:116
digital_out_t rst
Definition stspin250.h:115
digital_out_t ph
Definition stspin250.h:114
pwm_t pwm
Definition stspin250.h:124