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 
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 STSPIN250_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg.ph = MIKROBUS( mikrobus, MIKROBUS_AN ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define STSPIN250_RETVAL uint8_t
75 
76 #define STSPIN250_OK 0x00
77 #define STSPIN250_INIT_ERROR 0xFF
78 
84 #define STSPIN250_DEVICE_ENABLE 1
85 #define STSPIN250_DEVICE_DISABLE 0
86 
92 #define STSPIN250_DEF_FREQ 20000 //500
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
105 typedef struct
106 {
107 
108  // Output pins
109 
110  digital_out_t ph;
111  digital_out_t rst;
112  digital_out_t en;
113 
114  // Input pins
115 
116  digital_in_t flt;
117 
118  // Modules
119 
120  pwm_t pwm;
121 
122  // ctx variable
123 
124  uint32_t pwm_freq;
125 
126 } stspin250_t;
127 
131 typedef struct
132 {
133  // Communication gpio pins
134 
135  pin_name_t pwm;
136 
137  // Additional gpio pins
138 
139  pin_name_t ph;
140  pin_name_t rst;
141  pin_name_t en;
142  pin_name_t flt;
143 
144  // static variable
145 
146  uint32_t dev_pwm_freq;
147 
149  // End types group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
181 
190 
199 void stspin250_set_duty_cycle ( stspin250_t *ctx, float duty_cycle );
200 
209 
218 
227 void stspin250_enable ( stspin250_t *ctx, uint8_t state);
228 
238 void stspin250_set_ph ( stspin250_t *ctx, uint8_t state );
239 
249 
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 #endif // _STSPIN250_H_
264  // End public_function group
267 
268 // ------------------------------------------------------------------------- END
stspin250_enable
void stspin250_enable(stspin250_t *ctx, uint8_t state)
Enable pin function.
STSPIN250_RETVAL
#define STSPIN250_RETVAL
Definition: stspin250.h:74
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:116
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:132
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:146
stspin250_t::pwm
pwm_t pwm
Definition: stspin250.h:120
stspin250_t::pwm_freq
uint32_t pwm_freq
Definition: stspin250.h:124
stspin250_cfg_t::rst
pin_name_t rst
Definition: stspin250.h:140
stspin250_cfg_t::pwm
pin_name_t pwm
Definition: stspin250.h:135
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:106
stspin250_cfg_t::ph
pin_name_t ph
Definition: stspin250.h:139
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:142
stspin250_t::en
digital_out_t en
Definition: stspin250.h:112
stspin250_t::ph
digital_out_t ph
Definition: stspin250.h:110
stspin250_cfg_t::en
pin_name_t en
Definition: stspin250.h:141
stspin250_t::rst
digital_out_t rst
Definition: stspin250.h:111
stspin250_default_cfg
void stspin250_default_cfg(stspin250_t *ctx)
Click Default Configuration function.