stepper10 2.1.0.0
stepper10.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 STEPPER10_H
29#define STEPPER10_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define STEPPER10_TCA9534A_REG_INPUT 0x00
76#define STEPPER10_TCA9534A_REG_OUTPUT 0x01
77#define STEPPER10_TCA9534A_REG_POLARITY 0x02
78#define STEPPER10_TCA9534A_REG_CONFIG 0x03
79
80 // stepper10_reg
81
96#define STEPPER10_PIN0_MS0 0x01
97#define STEPPER10_PIN0_MS1 0x02
98#define STEPPER10_PIN0_MS2 0x04
99#define STEPPER10_PIN0_MS_MASK 0x07
100#define STEPPER10_PIN0_SLEEP 0x08
101#define STEPPER10_PIN0_MDT0 0x10
102#define STEPPER10_PIN0_MDT1 0x20
103#define STEPPER10_PIN0_MDT_MASK 0x30
104#define STEPPER10_PIN0_AGC 0x40
105#define STEPPER10_PIN0_IF_SEL 0x80
106#define STEPPER10_PIN1_TORQUE0 0x01
107#define STEPPER10_PIN1_TORQUE1 0x02
108#define STEPPER10_PIN1_TORQUE2 0x04
109#define STEPPER10_PIN1_TORQUE_MASK 0x07
110#define STEPPER10_PIN1_CLIM0 0x08
111#define STEPPER10_PIN1_EDG_SEL 0x10
112#define STEPPER10_PIN1_MO 0x20
113#define STEPPER10_PIN1_LO0 0x40
114#define STEPPER10_PIN1_LO1 0x80
115#define STEPPER10_PIN1_LO_MASK 0xC0
116
121#define STEPPER10_TCA9534A_0_DEFAULT_CONFIG 0x00
122#define STEPPER10_TCA9534A_1_DEFAULT_CONFIG 0xE0
123
128#define STEPPER10_DIR_CW 0
129#define STEPPER10_DIR_CCW 1
130
135#define STEPPER10_PIN_STATE_LOW 0
136#define STEPPER10_PIN_STATE_HIGH 1
137
142#define STEPPER10_SPEED_VERY_SLOW 0
143#define STEPPER10_SPEED_SLOW 1
144#define STEPPER10_SPEED_MEDIUM 2
145#define STEPPER10_SPEED_FAST 3
146#define STEPPER10_SPEED_VERY_FAST 4
147
152#define STEPPER10_MODE_FULL_STEP 0
153#define STEPPER10_MODE_HALF_STEP 1
154#define STEPPER10_MODE_QUARTER_STEP 2
155#define STEPPER10_MODE_1_OVER_8 3
156#define STEPPER10_MODE_1_OVER_16 4
157#define STEPPER10_MODE_1_OVER_32 5
158#define STEPPER10_MODE_1_OVER_64 6
159#define STEPPER10_MODE_1_OVER_128 7
160
165#define STEPPER10_MIXED_DECAY_FAST_37_5 0
166#define STEPPER10_MIXED_DECAY_FAST_50 1
167#define STEPPER10_MIXED_DECAY_FAST_ONLY 2
168#define STEPPER10_MIXED_DECAY_ADMD 3
169
174#define STEPPER10_TORQUE_100 0
175#define STEPPER10_TORQUE_85 1
176#define STEPPER10_TORQUE_70 2
177#define STEPPER10_TORQUE_60 3
178#define STEPPER10_TORQUE_50 4
179#define STEPPER10_TORQUE_40 5
180#define STEPPER10_TORQUE_25 6
181#define STEPPER10_TORQUE_10 7
182
187#define STEPPER10_LO_THERMAL_SHUTDOWN 0
188#define STEPPER10_LO_MOTOR_LOAD_OPEN 1
189#define STEPPER10_LO_OVER_CURRENT 2
190#define STEPPER10_LO_NORMAL 3
191
197#define STEPPER10_DEVICE0_ADDRESS_A2A1_00 0x38
198#define STEPPER10_DEVICE0_ADDRESS_A2A1_01 0x3A
199#define STEPPER10_DEVICE0_ADDRESS_A2A1_10 0x3C
200#define STEPPER10_DEVICE0_ADDRESS_A2A1_11 0x3E
201#define STEPPER10_DEVICE1_ADDRESS_A2A1_00 0x39
202#define STEPPER10_DEVICE1_ADDRESS_A2A1_01 0x3B
203#define STEPPER10_DEVICE1_ADDRESS_A2A1_10 0x3D
204#define STEPPER10_DEVICE1_ADDRESS_A2A1_11 0x3F
205
214#define STEPPER10_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
215#define STEPPER10_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
216
217 // stepper10_set
218
233#define STEPPER10_MAP_MIKROBUS( cfg, mikrobus ) \
234 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
235 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
236 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
237 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
238 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
239 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
240 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
241 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
242 cfg.step = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
243 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
244
245 // stepper10_map
246 // stepper10
247
252typedef struct stepper10_s
253{
254 digital_out_t dir;
255 digital_out_t rst;
256 digital_out_t step;
257 digital_out_t en;
259 digital_in_t int_pin;
261 i2c_master_t i2c;
262 spi_master_t spi;
265 pin_name_t chip_select;
268
273typedef struct
274{
275 pin_name_t scl;
276 pin_name_t sda;
277 pin_name_t miso;
278 pin_name_t mosi;
279 pin_name_t sck;
280 pin_name_t en;
281 pin_name_t dir;
282 pin_name_t rst;
283 pin_name_t step;
284 pin_name_t int_pin;
286 uint32_t i2c_speed;
287 uint8_t i2c_address;
289 uint32_t spi_speed;
290 spi_master_mode_t spi_mode;
293
304
321
336
350
362err_t stepper10_write_spi_bank0 ( stepper10_t *ctx, uint32_t data_in );
363
375err_t stepper10_write_spi_bank1 ( stepper10_t *ctx, uint32_t data_in );
376
390err_t stepper10_tca_write_reg ( stepper10_t *ctx, uint8_t reg, uint8_t data_in );
391
404err_t stepper10_tca_read_reg ( stepper10_t *ctx, uint8_t reg, uint8_t *data_out );
405
425err_t stepper10_get_step_mode ( stepper10_t *ctx, uint8_t *mode );
426
446err_t stepper10_set_step_mode ( stepper10_t *ctx, uint8_t mode );
447
460err_t stepper10_get_sleep_pin ( stepper10_t *ctx, uint8_t *state );
461
474err_t stepper10_set_sleep_pin ( stepper10_t *ctx, uint8_t state );
475
491err_t stepper10_get_mixed_decay ( stepper10_t *ctx, uint8_t *mode );
492
508err_t stepper10_set_mixed_decay ( stepper10_t *ctx, uint8_t mode );
509
522err_t stepper10_get_agc_pin ( stepper10_t *ctx, uint8_t *state );
523
536err_t stepper10_set_agc_pin ( stepper10_t *ctx, uint8_t state );
537
549
561
581err_t stepper10_get_torque ( stepper10_t *ctx, uint8_t *mode );
582
602err_t stepper10_set_torque ( stepper10_t *ctx, uint8_t mode );
603
616err_t stepper10_get_clim0_pin ( stepper10_t *ctx, uint8_t *state );
617
630err_t stepper10_set_clim0_pin ( stepper10_t *ctx, uint8_t state );
631
644err_t stepper10_get_edg_sel_pin ( stepper10_t *ctx, uint8_t *state );
645
658err_t stepper10_set_edg_sel_pin ( stepper10_t *ctx, uint8_t state );
659
672err_t stepper10_get_mo_pin ( stepper10_t *ctx, uint8_t *state );
673
689err_t stepper10_get_lo_state ( stepper10_t *ctx, uint8_t *state );
690
700
710
720
731void stepper10_set_direction ( stepper10_t *ctx, uint8_t dir );
732
743void stepper10_set_rst_pin ( stepper10_t *ctx, uint8_t state );
744
754
765void stepper10_set_step_pin ( stepper10_t *ctx, uint8_t state );
766
784err_t stepper10_drive_motor ( stepper10_t *ctx, uint32_t steps, uint8_t speed );
785
786#ifdef __cplusplus
787}
788#endif
789#endif // STEPPER10_H
790
791 // stepper10
792
793// ------------------------------------------------------------------------ END
err_t stepper10_set_agc_pin(stepper10_t *ctx, uint8_t state)
Stepper 10 set agc pin function.
void stepper10_set_direction(stepper10_t *ctx, uint8_t dir)
Stepper 10 set direction function.
err_t stepper10_get_torque(stepper10_t *ctx, uint8_t *mode)
Stepper 10 get torque function.
err_t stepper10_tca_read_reg(stepper10_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 10 tca read reg function.
err_t stepper10_select_gpio(stepper10_t *ctx)
Stepper 10 select GPIO function.
err_t stepper10_get_edg_sel_pin(stepper10_t *ctx, uint8_t *state)
Stepper 10 get edg_sel pin function.
err_t stepper10_get_mixed_decay(stepper10_t *ctx, uint8_t *mode)
Stepper 10 get mixed decay function.
void stepper10_set_rst_pin(stepper10_t *ctx, uint8_t state)
Stepper 10 set rst pin function.
err_t stepper10_get_agc_pin(stepper10_t *ctx, uint8_t *state)
Stepper 10 get agc pin function.
err_t stepper10_get_step_mode(stepper10_t *ctx, uint8_t *mode)
Stepper 10 get step mode function.
err_t stepper10_get_lo_state(stepper10_t *ctx, uint8_t *state)
Stepper 10 get LO function.
err_t stepper10_set_edg_sel_pin(stepper10_t *ctx, uint8_t state)
Stepper 10 set edg_sel pin function.
err_t stepper10_set_torque(stepper10_t *ctx, uint8_t mode)
Stepper 10 set torque function.
void stepper10_cfg_setup(stepper10_cfg_t *cfg)
Stepper 10 configuration object setup function.
err_t stepper10_get_sleep_pin(stepper10_t *ctx, uint8_t *state)
Stepper 10 get sleep pin function.
void stepper10_enable_device(stepper10_t *ctx)
Stepper 10 enable device function.
err_t stepper10_get_clim0_pin(stepper10_t *ctx, uint8_t *state)
Stepper 10 get clim0 pin function.
err_t stepper10_set_clim0_pin(stepper10_t *ctx, uint8_t state)
Stepper 10 set clim0 pin function.
err_t stepper10_write_spi_bank0(stepper10_t *ctx, uint32_t data_in)
Stepper 10 write spi bank0 function.
uint8_t stepper10_get_int_pin(stepper10_t *ctx)
Stepper 10 get INT pin function.
err_t stepper10_write_spi_bank1(stepper10_t *ctx, uint32_t data_in)
Stepper 10 write spi bank1 function.
err_t stepper10_set_step_mode(stepper10_t *ctx, uint8_t mode)
Stepper 10 set step mode function.
err_t stepper10_drive_motor(stepper10_t *ctx, uint32_t steps, uint8_t speed)
Stepper 10 driver motor function.
err_t stepper10_tca_write_reg(stepper10_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 10 tca write reg function.
void stepper10_disable_device(stepper10_t *ctx)
Stepper 10 disable device function.
err_t stepper10_select_spi(stepper10_t *ctx)
Stepper 10 select SPI function.
void stepper10_set_step_pin(stepper10_t *ctx, uint8_t state)
Stepper 10 set step pin function.
err_t stepper10_set_sleep_pin(stepper10_t *ctx, uint8_t state)
Stepper 10 set sleep pin function.
err_t stepper10_set_mixed_decay(stepper10_t *ctx, uint8_t mode)
Stepper 10 set mixed decay function.
err_t stepper10_init(stepper10_t *ctx, stepper10_cfg_t *cfg)
Stepper 10 initialization function.
err_t stepper10_default_cfg(stepper10_t *ctx)
Stepper 10 default configuration function.
err_t stepper10_get_mo_pin(stepper10_t *ctx, uint8_t *state)
Stepper 10 get mo pin function.
void stepper10_reset_device(stepper10_t *ctx)
Stepper 10 reset device function.
This file contains SPI specific macros, functions, etc.
stepper10_return_value_t
Stepper 10 Click return value data.
Definition stepper10.h:299
@ STEPPER10_ERROR
Definition stepper10.h:301
@ STEPPER10_OK
Definition stepper10.h:300
struct stepper10_s stepper10_t
Stepper 10 Click context object.
Stepper 10 Click configuration object.
Definition stepper10.h:274
pin_name_t step
Definition stepper10.h:283
uint32_t i2c_speed
Definition stepper10.h:286
pin_name_t sck
Definition stepper10.h:279
spi_master_mode_t spi_mode
Definition stepper10.h:290
pin_name_t mosi
Definition stepper10.h:278
uint32_t spi_speed
Definition stepper10.h:289
pin_name_t dir
Definition stepper10.h:281
pin_name_t scl
Definition stepper10.h:275
pin_name_t en
Definition stepper10.h:280
pin_name_t int_pin
Definition stepper10.h:284
pin_name_t miso
Definition stepper10.h:277
pin_name_t sda
Definition stepper10.h:276
pin_name_t rst
Definition stepper10.h:282
uint8_t i2c_address
Definition stepper10.h:287
Stepper 10 Click context object.
Definition stepper10.h:253
spi_master_t spi
Definition stepper10.h:262
digital_in_t int_pin
Definition stepper10.h:259
digital_out_t step
Definition stepper10.h:256
i2c_master_t i2c
Definition stepper10.h:261
digital_out_t en
Definition stepper10.h:257
digital_out_t rst
Definition stepper10.h:255
uint8_t slave_address
Definition stepper10.h:264
pin_name_t chip_select
Definition stepper10.h:265
digital_out_t dir
Definition stepper10.h:254