stspin233 2.0.0.0
stspin233.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 STSPIN233_H
36#define STSPIN233_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_uart.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define DRV_RX_BUFFER_SIZE 500
75#define STSPIN233_MAP_MIKROBUS( cfg, mikrobus ) \
76 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
77 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
78 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
79 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
86#define STSPIN233_RETVAL uint8_t
87
88#define STSPIN233_OK 0x00
89#define STSPIN233_INIT_ERROR 0xFF
96#define STSPIN233_CMD_START_MOTOR "STARTM"
97#define STSPIN233_CMD_STOP_MOTOR "STOPMT"
98#define STSPIN233_CMD_DIR_MOTOR "DIRECT"
99#define STSPIN233_CMD_SET_SPEED "SETSPD"
100#define STSPIN233_CMD_GET_SPEED "GETSPD"
101#define STSPIN233_CMD_STATUS "STATUS"
102#define STSPIN233_CMD_HELP "HELP"
103#define STSPIN233_CMD_SET_PWM "INIREF"
104#define STSPIN233_CMD_COM_DELAY "COMDEL"
105#define STSPIN233_CMD_MOTOR_POLE "POLESP"
106#define STSPIN233_CMD_KP_PRM "KP-PRM"
107#define STSPIN233_CMD_KI_PRM "KI-PRM"
114#define STSPIN233_CW_DIR "1"
115#define STSPIN233_CCW_DIR "0"
122#define STSPIN233_START_PWM_DUTY_10p "409"
123#define STSPIN233_START_PWM_DUTY_20p "819"
124#define STSPIN233_START_PWM_DUTY_DEF "819"
125#define STSPIN233_START_PWM_DUTY_30p "1229"
126#define STSPIN233_START_PWM_DUTY_40p "1638"
127#define STSPIN233_START_PWM_DUTY_50p "2048"
128#define STSPIN233_START_PWM_DUTY_60p "2458"
129#define STSPIN233_START_PWM_DUTY_70p "2867"
130#define STSPIN233_START_PWM_DUTY_80p "3277"
131#define STSPIN233_START_PWM_DUTY_90p "3687"
132#define STSPIN233_START_PWM_DUTY_100p "4095"
139#define STSPIN233_COMM_DELAY_7ms "7"
140#define STSPIN233_COMM_DELAY_DEF "7"
147#define STSPIN233_M_POLE_2 "2"
148#define STSPIN233_M_POLE_3 "3"
149#define STSPIN233_M_POLE_4 "4"
150#define STSPIN233_M_POLE_5 "5"
151#define STSPIN233_M_POLE_6 "6"
152#define STSPIN233_M_POLE_DEF "6"
153#define STSPIN233_M_POLE_7 "7"
154#define STSPIN233_M_POLE_8 "8"
161#define STSPIN233_KP_PRM_DEF "500"
162#define STSPIN233_KI_PRM_DEF "250"
169#define STSPIN233_SPEED_1000RPM "1000"
170#define STSPIN233_SPEED_DEF "1000"
171#define STSPIN233_SPEED_900RPM "900"
172#define STSPIN233_SPEED_1100RPM "1100"
173#define STSPIN233_SPEED_1200RPM "1200"
174#define STSPIN233_SPEED_1300RPM "1300"
175#define STSPIN233_SPEED_1400RPM "1400"
176#define STSPIN233_SPEED_1500RPM "1500"
177#define STSPIN233_SPEED_1600RPM "1600"
178#define STSPIN233_SPEED_1700RPM "1700"
179#define STSPIN233_SPEED_1800RPM "1800"
180#define STSPIN233_SPEED_1900RPM "1900"
181#define STSPIN233_SPEED_2000RPM "2000"
182#define STSPIN233_SPEED_2100RPM "2100"
185 // End group macro
186// --------------------------------------------------------------- PUBLIC TYPES
195typedef struct
196{
197 // Output pins
198
199 digital_out_t rst;
200
201 // Input pins
202
203 digital_in_t int_pin;
204
205 // Modules
206
207 uart_t uart;
208
209 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
210 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
211
213
217typedef struct
218{
219 // Communication gpio pins
220
221 pin_name_t rx_pin;
222 pin_name_t tx_pin;
223
224 // Additional gpio pins
225
226 pin_name_t rst;
227 pin_name_t int_pin;
228
229 // static variable
230
231 uint32_t baud_rate; // Clock speed.
233 uart_data_bits_t data_bit; // Data bits.
234 uart_parity_t parity_bit; // Parity bit.
235 uart_stop_bits_t stop_bit; // Stop bits.
236
238
239 // End types group
240// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
241
247#ifdef __cplusplus
248extern "C"{
249#endif
250
260
269
278
285void stspin233_generic_write ( stspin233_t *ctx, char *data_buf, uint16_t len );
286
294int32_t stspin233_generic_read ( stspin233_t *ctx, char *data_buf, uint16_t max_len );
295
302
315void stspin233_send_single_cmd ( stspin233_t *ctx, uint8_t *tx_buf );
316
331void stspin233_send_double_cmd ( stspin233_t *ctx, uint8_t *cmd_buf, uint8_t *arg_buf );
332
339void stspin233_set_reset_state ( stspin233_t *ctx, uint8_t state );
340
349
350#ifdef __cplusplus
351}
352#endif
353#endif // _STSPIN233_H_
354
355 // End public_function group
357
358// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition stspin233.h:67
#define STSPIN233_RETVAL
Definition stspin233.h:86
void stspin233_generic_write(stspin233_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void stspin233_cfg_setup(stspin233_cfg_t *cfg)
Config Object Initialization function.
int32_t stspin233_generic_read(stspin233_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void stspin233_default_cfg(stspin233_t *ctx)
Click Default Configuration function.
uint8_t stspin233_get_int_state(stspin233_t *ctx)
Get INT pin state.
void stspin233_set_reset_state(stspin233_t *ctx, uint8_t state)
Set RST pin state.
STSPIN233_RETVAL stspin233_init(stspin233_t *ctx, stspin233_cfg_t *cfg)
Initialization function.
void stspin233_wakeup(stspin233_t *ctx)
Module wake-up (procedure)
void stspin233_send_single_cmd(stspin233_t *ctx, uint8_t *tx_buf)
Send single command.
void stspin233_send_double_cmd(stspin233_t *ctx, uint8_t *cmd_buf, uint8_t *arg_buf)
Send double command.
Click configuration structure definition.
Definition stspin233.h:218
uint32_t baud_rate
Definition stspin233.h:231
bool uart_blocking
Definition stspin233.h:232
uart_data_bits_t data_bit
Definition stspin233.h:233
pin_name_t tx_pin
Definition stspin233.h:222
pin_name_t rx_pin
Definition stspin233.h:221
uart_stop_bits_t stop_bit
Definition stspin233.h:235
pin_name_t int_pin
Definition stspin233.h:227
uart_parity_t parity_bit
Definition stspin233.h:234
pin_name_t rst
Definition stspin233.h:226
Click ctx object definition.
Definition stspin233.h:196
uart_t uart
Definition stspin233.h:207
digital_in_t int_pin
Definition stspin233.h:203
digital_out_t rst
Definition stspin233.h:199