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 
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_uart.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define DRV_RX_BUFFER_SIZE 500
64 
71 #define STSPIN233_MAP_MIKROBUS( cfg, mikrobus ) \
72  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
73  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
74  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
75  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76 
82 #define STSPIN233_RETVAL uint8_t
83 
84 #define STSPIN233_OK 0x00
85 #define STSPIN233_INIT_ERROR 0xFF
86 
92 #define STSPIN233_CMD_START_MOTOR "STARTM"
93 #define STSPIN233_CMD_STOP_MOTOR "STOPMT"
94 #define STSPIN233_CMD_DIR_MOTOR "DIRECT"
95 #define STSPIN233_CMD_SET_SPEED "SETSPD"
96 #define STSPIN233_CMD_GET_SPEED "GETSPD"
97 #define STSPIN233_CMD_STATUS "STATUS"
98 #define STSPIN233_CMD_HELP "HELP"
99 #define STSPIN233_CMD_SET_PWM "INIREF"
100 #define STSPIN233_CMD_COM_DELAY "COMDEL"
101 #define STSPIN233_CMD_MOTOR_POLE "POLESP"
102 #define STSPIN233_CMD_KP_PRM "KP-PRM"
103 #define STSPIN233_CMD_KI_PRM "KI-PRM"
104 
110 #define STSPIN233_CW_DIR "1"
111 #define STSPIN233_CCW_DIR "0"
112 
118 #define STSPIN233_START_PWM_DUTY_10p "409"
119 #define STSPIN233_START_PWM_DUTY_20p "819"
120 #define STSPIN233_START_PWM_DUTY_DEF "819"
121 #define STSPIN233_START_PWM_DUTY_30p "1229"
122 #define STSPIN233_START_PWM_DUTY_40p "1638"
123 #define STSPIN233_START_PWM_DUTY_50p "2048"
124 #define STSPIN233_START_PWM_DUTY_60p "2458"
125 #define STSPIN233_START_PWM_DUTY_70p "2867"
126 #define STSPIN233_START_PWM_DUTY_80p "3277"
127 #define STSPIN233_START_PWM_DUTY_90p "3687"
128 #define STSPIN233_START_PWM_DUTY_100p "4095"
129 
135 #define STSPIN233_COMM_DELAY_7ms "7"
136 #define STSPIN233_COMM_DELAY_DEF "7"
137 
143 #define STSPIN233_M_POLE_2 "2"
144 #define STSPIN233_M_POLE_3 "3"
145 #define STSPIN233_M_POLE_4 "4"
146 #define STSPIN233_M_POLE_5 "5"
147 #define STSPIN233_M_POLE_6 "6"
148 #define STSPIN233_M_POLE_DEF "6"
149 #define STSPIN233_M_POLE_7 "7"
150 #define STSPIN233_M_POLE_8 "8"
151 
157 #define STSPIN233_KP_PRM_DEF "500"
158 #define STSPIN233_KI_PRM_DEF "250"
159 
165 #define STSPIN233_SPEED_1000RPM "1000"
166 #define STSPIN233_SPEED_DEF "1000"
167 #define STSPIN233_SPEED_900RPM "900"
168 #define STSPIN233_SPEED_1100RPM "1100"
169 #define STSPIN233_SPEED_1200RPM "1200"
170 #define STSPIN233_SPEED_1300RPM "1300"
171 #define STSPIN233_SPEED_1400RPM "1400"
172 #define STSPIN233_SPEED_1500RPM "1500"
173 #define STSPIN233_SPEED_1600RPM "1600"
174 #define STSPIN233_SPEED_1700RPM "1700"
175 #define STSPIN233_SPEED_1800RPM "1800"
176 #define STSPIN233_SPEED_1900RPM "1900"
177 #define STSPIN233_SPEED_2000RPM "2000"
178 #define STSPIN233_SPEED_2100RPM "2100"
179  // End group macro
182 // --------------------------------------------------------------- PUBLIC TYPES
191 typedef struct
192 {
193  // Output pins
194 
195  digital_out_t rst;
196 
197  // Input pins
198 
199  digital_in_t int_pin;
200 
201  // Modules
202 
203  uart_t uart;
204 
205  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
206  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
207 
208 } stspin233_t;
209 
213 typedef struct
214 {
215  // Communication gpio pins
216 
217  pin_name_t rx_pin;
218  pin_name_t tx_pin;
219 
220  // Additional gpio pins
221 
222  pin_name_t rst;
223  pin_name_t int_pin;
224 
225  // static variable
226 
227  uint32_t baud_rate; // Clock speed.
229  uart_data_bits_t data_bit; // Data bits.
230  uart_parity_t parity_bit; // Parity bit.
231  uart_stop_bits_t stop_bit; // Stop bits.
232 
234  // End types group
236 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
237 
243 #ifdef __cplusplus
244 extern "C"{
245 #endif
246 
256 
265 
274 
281 void stspin233_generic_write ( stspin233_t *ctx, char *data_buf, uint16_t len );
282 
290 int32_t stspin233_generic_read ( stspin233_t *ctx, char *data_buf, uint16_t max_len );
291 
298 
311 void stspin233_send_single_cmd ( stspin233_t *ctx, uint8_t *tx_buf );
312 
327 void stspin233_send_double_cmd ( stspin233_t *ctx, uint8_t *cmd_buf, uint8_t *arg_buf );
328 
335 void stspin233_set_reset_state ( stspin233_t *ctx, uint8_t state );
336 
345 
346 #ifdef __cplusplus
347 }
348 #endif
349 #endif // _STSPIN233_H_
350  // End public_function group
353 
354 // ------------------------------------------------------------------------- END
stspin233_generic_write
void stspin233_generic_write(stspin233_t *ctx, char *data_buf, uint16_t len)
Generic write function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: stspin233.h:63
stspin233_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: stspin233.h:229
stspin233_generic_read
int32_t stspin233_generic_read(stspin233_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
stspin233_t::uart
uart_t uart
Definition: stspin233.h:203
STSPIN233_RETVAL
#define STSPIN233_RETVAL
Definition: stspin233.h:82
stspin233_cfg_t::rst
pin_name_t rst
Definition: stspin233.h:222
stspin233_t
Click ctx object definition.
Definition: stspin233.h:192
stspin233_get_int_state
uint8_t stspin233_get_int_state(stspin233_t *ctx)
Get INT pin state.
stspin233_cfg_setup
void stspin233_cfg_setup(stspin233_cfg_t *cfg)
Config Object Initialization function.
stspin233_cfg_t::uart_blocking
bool uart_blocking
Definition: stspin233.h:228
stspin233_cfg_t::int_pin
pin_name_t int_pin
Definition: stspin233.h:223
stspin233_cfg_t::tx_pin
pin_name_t tx_pin
Definition: stspin233.h:218
stspin233_init
STSPIN233_RETVAL stspin233_init(stspin233_t *ctx, stspin233_cfg_t *cfg)
Initialization function.
stspin233_wakeup
void stspin233_wakeup(stspin233_t *ctx)
Module wake-up (procedure)
stspin233_cfg_t::baud_rate
uint32_t baud_rate
Definition: stspin233.h:227
stspin233_send_double_cmd
void stspin233_send_double_cmd(stspin233_t *ctx, uint8_t *cmd_buf, uint8_t *arg_buf)
Send double command.
stspin233_default_cfg
void stspin233_default_cfg(stspin233_t *ctx)
Click Default Configuration function.
stspin233_t::int_pin
digital_in_t int_pin
Definition: stspin233.h:199
stspin233_cfg_t
Click configuration structure definition.
Definition: stspin233.h:214
stspin233_t::rst
digital_out_t rst
Definition: stspin233.h:195
stspin233_cfg_t::rx_pin
pin_name_t rx_pin
Definition: stspin233.h:217
stspin233_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: stspin233.h:231
stspin233_send_single_cmd
void stspin233_send_single_cmd(stspin233_t *ctx, uint8_t *tx_buf)
Send single command.
stspin233_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: stspin233.h:230
stspin233_set_reset_state
void stspin233_set_reset_state(stspin233_t *ctx, uint8_t state)
Set RST pin state.