stepper7  2.1.0.0
stepper7.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef STEPPER7_H
29 #define STEPPER7_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define STEPPER7_REG_IODIR 0x00
71 #define STEPPER7_REG_IPOL 0x01
72 #define STEPPER7_REG_GPINTEN 0x02
73 #define STEPPER7_REG_DEFVAL 0x03
74 #define STEPPER7_REG_INTCON 0x04
75 #define STEPPER7_REG_IOCON 0x05
76 #define STEPPER7_REG_GPPU 0x06
77 #define STEPPER7_REG_INTF 0x07
78 #define STEPPER7_REG_INTCAP 0x08
79 #define STEPPER7_REG_GPIO 0x09
80 #define STEPPER7_REG_OLAT 0x0A
81  // stepper7_reg
83 
98 #define STEPPER7_PIN_PHASE2 0x80
99 #define STEPPER7_PIN_PHASE1 0x40
100 #define STEPPER7_PIN_I12 0x20
101 #define STEPPER7_PIN_I02 0x10
102 #define STEPPER7_PIN_I11 0x08
103 #define STEPPER7_PIN_I01 0x04
104 
109 #define STEPPER7_IODIR_DEFAULT 0x03
110 #define STEPPER7_IOCON_DEFAULT 0x38
111 #define STEPPER7_GPIO_CLEAR 0x00
112 
117 #define STEPPER7_DIR_CW 0
118 #define STEPPER7_DIR_CCW 1
119 
124 #define STEPPER7_PIN_LOW_LEVEL 0
125 #define STEPPER7_PIN_HIGH_LEVEL 1
126 
131 #define STEPPER7_MODE_FULL_STEP 0
132 #define STEPPER7_MODE_HALF_STEP 1
133 #define STEPPER7_MODE_1_OVER_8_STEP 2
134 
139 #define STEPPER7_SPEED_VERY_SLOW 0
140 #define STEPPER7_SPEED_SLOW 1
141 #define STEPPER7_SPEED_MEDIUM 2
142 #define STEPPER7_SPEED_FAST 3
143 #define STEPPER7_SPEED_VERY_FAST 4
144 
149 #define STEPPER7_SPI_READ_OPCODE 0x41
150 #define STEPPER7_SPI_WRITE_OPCODE 0x40
151 
160 #define STEPPER7_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
161 #define STEPPER7_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
162  // stepper7_set
164 
179 #define STEPPER7_MAP_MIKROBUS( cfg, mikrobus ) \
180  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
181  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
182  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
183  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
184  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
185  // stepper7_map // stepper7
188 
193 typedef struct
194 {
195  // Output pins
196  digital_out_t rst;
198  // Modules
199  spi_master_t spi;
201  pin_name_t chip_select;
203  uint8_t step_mode;
204  uint8_t direction;
206 } stepper7_t;
207 
212 typedef struct
213 {
214  // Communication gpio pins
215  pin_name_t miso;
216  pin_name_t mosi;
217  pin_name_t sck;
218  pin_name_t cs;
220  // Additional gpio pins
221  pin_name_t rst;
223  // static variable
224  uint32_t spi_speed;
225  spi_master_mode_t spi_mode;
226  spi_master_chip_select_polarity_t cs_polarity;
229 
234 typedef enum
235 {
237  STEPPER7_ERROR = -1
238 
240 
257 
272 
286 
299 err_t stepper7_write_reg ( stepper7_t *ctx, uint8_t reg, uint8_t data_in );
300 
313 err_t stepper7_read_reg ( stepper7_t *ctx, uint8_t reg, uint8_t *data_out );
314 
325 void stepper7_set_rst_pin ( stepper7_t *ctx, uint8_t state );
326 
336 
349 err_t stepper7_set_phase2_pin ( stepper7_t *ctx, uint8_t state );
350 
363 err_t stepper7_set_phase1_pin ( stepper7_t *ctx, uint8_t state );
364 
377 err_t stepper7_set_i12_pin ( stepper7_t *ctx, uint8_t state );
378 
391 err_t stepper7_set_i02_pin ( stepper7_t *ctx, uint8_t state );
392 
405 err_t stepper7_set_i11_pin ( stepper7_t *ctx, uint8_t state );
406 
419 err_t stepper7_set_i01_pin ( stepper7_t *ctx, uint8_t state );
420 
432 
444 
457 void stepper7_set_step_mode ( stepper7_t *ctx, uint8_t mode );
458 
469 void stepper7_set_direction ( stepper7_t *ctx, uint8_t dir );
470 
480 
498 err_t stepper7_drive_motor ( stepper7_t *ctx, uint32_t steps, uint8_t speed );
499 
500 #ifdef __cplusplus
501 }
502 #endif
503 #endif // STEPPER7_H
504  // stepper7
506 
507 // ------------------------------------------------------------------------ END
stepper7_set_i11_pin
err_t stepper7_set_i11_pin(stepper7_t *ctx, uint8_t state)
Stepper 7 set I11 pin function.
STEPPER7_ERROR
@ STEPPER7_ERROR
Definition: stepper7.h:237
stepper7_t::chip_select
pin_name_t chip_select
Definition: stepper7.h:201
stepper7_enable_device
err_t stepper7_enable_device(stepper7_t *ctx)
Stepper 7 enable device function.
stepper7_switch_direction
void stepper7_switch_direction(stepper7_t *ctx)
Stepper 7 switch direction function.
stepper7_set_i01_pin
err_t stepper7_set_i01_pin(stepper7_t *ctx, uint8_t state)
Stepper 7 set I01 pin function.
stepper7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: stepper7.h:226
stepper7_set_step_mode
void stepper7_set_step_mode(stepper7_t *ctx, uint8_t mode)
Stepper 7 set step mode function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
stepper7_cfg_t
Stepper 7 Click configuration object.
Definition: stepper7.h:213
stepper7_t::rst
digital_out_t rst
Definition: stepper7.h:196
stepper7_cfg_t::spi_speed
uint32_t spi_speed
Definition: stepper7.h:224
stepper7_cfg_t::miso
pin_name_t miso
Definition: stepper7.h:215
stepper7_set_direction
void stepper7_set_direction(stepper7_t *ctx, uint8_t dir)
Stepper 7 set direction function.
stepper7_t
Stepper 7 Click context object.
Definition: stepper7.h:194
stepper7_t::direction
uint8_t direction
Definition: stepper7.h:204
stepper7_read_reg
err_t stepper7_read_reg(stepper7_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 7 read reg function.
stepper7_cfg_setup
void stepper7_cfg_setup(stepper7_cfg_t *cfg)
Stepper 7 configuration object setup function.
stepper7_return_value_t
stepper7_return_value_t
Stepper 7 Click return value data.
Definition: stepper7.h:235
stepper7_cfg_t::sck
pin_name_t sck
Definition: stepper7.h:217
stepper7_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: stepper7.h:225
stepper7_init
err_t stepper7_init(stepper7_t *ctx, stepper7_cfg_t *cfg)
Stepper 7 initialization function.
stepper7_set_rst_pin
void stepper7_set_rst_pin(stepper7_t *ctx, uint8_t state)
Stepper 7 set rst pin function.
stepper7_t::spi
spi_master_t spi
Definition: stepper7.h:199
stepper7_set_i12_pin
err_t stepper7_set_i12_pin(stepper7_t *ctx, uint8_t state)
Stepper 7 set I12 pin function.
stepper7_write_reg
err_t stepper7_write_reg(stepper7_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 7 write reg function.
stepper7_cfg_t::mosi
pin_name_t mosi
Definition: stepper7.h:216
stepper7_t::step_mode
uint8_t step_mode
Definition: stepper7.h:203
stepper7_set_i02_pin
err_t stepper7_set_i02_pin(stepper7_t *ctx, uint8_t state)
Stepper 7 set I02 pin function.
stepper7_cfg_t::cs
pin_name_t cs
Definition: stepper7.h:218
stepper7_drive_motor
err_t stepper7_drive_motor(stepper7_t *ctx, uint32_t steps, uint8_t speed)
Stepper 7 driver motor function.
stepper7_set_phase2_pin
err_t stepper7_set_phase2_pin(stepper7_t *ctx, uint8_t state)
Stepper 7 set PHASE2 pin function.
stepper7_default_cfg
err_t stepper7_default_cfg(stepper7_t *ctx)
Stepper 7 default configuration function.
stepper7_cfg_t::rst
pin_name_t rst
Definition: stepper7.h:221
stepper7_reset_device
void stepper7_reset_device(stepper7_t *ctx)
Stepper 7 reset device function.
stepper7_disable_device
err_t stepper7_disable_device(stepper7_t *ctx)
Stepper 7 disable device function.
STEPPER7_OK
@ STEPPER7_OK
Definition: stepper7.h:236
stepper7_set_phase1_pin
err_t stepper7_set_phase1_pin(stepper7_t *ctx, uint8_t state)
Stepper 7 set PHASE1 pin function.