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 )
72 
78 #define STSPIN250_RETVAL uint8_t
79 
80 #define STSPIN250_OK 0x00
81 #define STSPIN250_INIT_ERROR 0xFF
82 
88 #define STSPIN250_DEVICE_ENABLE 1
89 #define STSPIN250_DEVICE_DISABLE 0
90 
96 #define STSPIN250_DEF_FREQ 20000 //500
97  // End group macro
100 // --------------------------------------------------------------- PUBLIC TYPES
109 typedef 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 
130 } stspin250_t;
131 
135 typedef 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  // End types group
155 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156 
162 #ifdef __cplusplus
163 extern "C"{
164 #endif
165 
175 
185 
194 
203 void stspin250_set_duty_cycle ( stspin250_t *ctx, float duty_cycle );
204 
213 
222 
231 void stspin250_enable ( stspin250_t *ctx, uint8_t state);
232 
242 void stspin250_set_ph ( stspin250_t *ctx, uint8_t state );
243 
253 
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 #endif // _STSPIN250_H_
268  // End public_function group
271 
272 // ------------------------------------------------------------------------- END
stspin250_enable
void stspin250_enable(stspin250_t *ctx, uint8_t state)
Enable pin function.
STSPIN250_RETVAL
#define STSPIN250_RETVAL
Definition: stspin250.h:78
stspin250_pwm_start
void stspin250_pwm_start(stspin250_t *ctx)
Start PWM module.
stspin250_get_fault
uint8_t stspin250_get_fault(stspin250_t *ctx)
Fault get function.
stspin250_pwm_stop
void stspin250_pwm_stop(stspin250_t *ctx)
Stop PWM module.
stspin250_t::flt
digital_in_t flt
Definition: stspin250.h:120
stspin250_set_ph
void stspin250_set_ph(stspin250_t *ctx, uint8_t state)
Dir ctrl pin function.
stspin250_cfg_t
Click configuration structure definition.
Definition: stspin250.h:136
stspin250_cfg_setup
void stspin250_cfg_setup(stspin250_cfg_t *cfg)
Config Object Initialization function.
stspin250_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: stspin250.h:150
stspin250_t::pwm
pwm_t pwm
Definition: stspin250.h:124
stspin250_t::pwm_freq
uint32_t pwm_freq
Definition: stspin250.h:128
stspin250_cfg_t::rst
pin_name_t rst
Definition: stspin250.h:144
stspin250_cfg_t::pwm
pin_name_t pwm
Definition: stspin250.h:139
stspin250_set_duty_cycle
void stspin250_set_duty_cycle(stspin250_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
stspin250_reset
void stspin250_reset(stspin250_t *ctx)
Reset pin function.
stspin250_t
Click ctx object definition.
Definition: stspin250.h:110
stspin250_cfg_t::ph
pin_name_t ph
Definition: stspin250.h:143
stspin250_init
STSPIN250_RETVAL stspin250_init(stspin250_t *ctx, stspin250_cfg_t *cfg)
Initialization function.
stspin250_cfg_t::flt
pin_name_t flt
Definition: stspin250.h:146
stspin250_t::en
digital_out_t en
Definition: stspin250.h:116
stspin250_t::ph
digital_out_t ph
Definition: stspin250.h:114
stspin250_cfg_t::en
pin_name_t en
Definition: stspin250.h:145
stspin250_t::rst
digital_out_t rst
Definition: stspin250.h:115
stspin250_default_cfg
void stspin250_default_cfg(stspin250_t *ctx)
Click Default Configuration function.