stepper12 2.1.0.0
stepper12.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 STEPPER12_H
29#define STEPPER12_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
73#define STEPPER12_REG_INPUT_0 0x00
74#define STEPPER12_REG_INPUT_1 0x01
75#define STEPPER12_REG_OUTPUT_0 0x02
76#define STEPPER12_REG_OUTPUT_1 0x03
77#define STEPPER12_REG_POLARITY_0 0x04
78#define STEPPER12_REG_POLARITY_1 0x05
79#define STEPPER12_REG_CONFIG_0 0x06
80#define STEPPER12_REG_CONFIG_1 0x07
81
82 // stepper12_reg
83
98#define STEPPER12_P0_DMODE0_PIN 0x01
99#define STEPPER12_P0_DMODE1_PIN 0x02
100#define STEPPER12_P0_DMODE2_PIN 0x04
101#define STEPPER12_P0_DECAY_PIN 0x08
102#define STEPPER12_P0_TRQ0_PIN 0x20
103#define STEPPER12_P0_TRQ1_PIN 0x40
104#define STEPPER12_P0_SLEEP_X_PIN 0x80
105#define STEPPER12_P1_LO_PIN 0x01
106#define STEPPER12_P1_MO_PIN 0x04
107
112#define STEPPER12_P0_DEFAULT_CONFIG 0x10
113#define STEPPER12_P1_DEFAULT_CONFIG 0xFF
114
119#define STEPPER12_DIR_CW 1
120#define STEPPER12_DIR_CCW 0
121
126#define STEPPER12_PIN_LOW_LEVEL 0
127#define STEPPER12_PIN_HIGH_LEVEL 1
128
133#define STEPPER12_MODE_FULL_STEP 0x00
134#define STEPPER12_MODE_1_OVER_8 0x01
135#define STEPPER12_MODE_HALF_STEP_TYPE_B 0x02
136#define STEPPER12_MODE_1_OVER_32 0x03
137#define STEPPER12_MODE_HALF_STEP_TYPE_A 0x04
138#define STEPPER12_MODE_1_OVER_16 0x05
139#define STEPPER12_MODE_QUARTER_STEP 0x06
140#define STEPPER12_MODE_MASK 0x07
141
146#define STEPPER12_TORQUE_100_PCT 0x00
147#define STEPPER12_TORQUE_75_PCT 0x01
148#define STEPPER12_TORQUE_50_PCT 0x02
149#define STEPPER12_TORQUE_25_PCT 0x03
150#define STEPPER12_TORQUE_MASK 0x03
151
156#define STEPPER12_SPEED_VERY_SLOW 0
157#define STEPPER12_SPEED_SLOW 1
158#define STEPPER12_SPEED_MEDIUM 2
159#define STEPPER12_SPEED_FAST 3
160#define STEPPER12_SPEED_VERY_FAST 4
161
167#define STEPPER12_DEVICE_ADDRESS_A2A1A0_000 0x20
168#define STEPPER12_DEVICE_ADDRESS_A2A1A0_001 0x21
169#define STEPPER12_DEVICE_ADDRESS_A2A1A0_010 0x22
170#define STEPPER12_DEVICE_ADDRESS_A2A1A0_011 0x23
171#define STEPPER12_DEVICE_ADDRESS_A2A1A0_100 0x24
172#define STEPPER12_DEVICE_ADDRESS_A2A1A0_101 0x25
173#define STEPPER12_DEVICE_ADDRESS_A2A1A0_110 0x26
174#define STEPPER12_DEVICE_ADDRESS_A2A1A0_111 0x27
175
176 // stepper12_set
177
192#define STEPPER12_MAP_MIKROBUS( cfg, mikrobus ) \
193 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
194 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
195 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
196 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
197 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
198 cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
199 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
200
201 // stepper12_map
202 // stepper12
203
208typedef struct
209{
210 // Output pins
211 digital_out_t en;
212 digital_out_t dir;
213 digital_out_t rst;
214 digital_out_t clk;
216 // Input pins
217 digital_in_t int_pin;
219 // Modules
220 i2c_master_t i2c;
222 // I2C slave address
226
231typedef struct
232{
233 pin_name_t scl;
234 pin_name_t sda;
236 pin_name_t en;
237 pin_name_t dir;
238 pin_name_t rst;
239 pin_name_t clk;
240 pin_name_t int_pin;
242 uint32_t i2c_speed;
243 uint8_t i2c_address;
246
257
274
289
303
317err_t stepper12_write_register ( stepper12_t *ctx, uint8_t reg, uint8_t data_in );
318
331err_t stepper12_read_register ( stepper12_t *ctx, uint8_t reg, uint8_t *data_out );
332
344err_t stepper12_get_step_mode ( stepper12_t *ctx, uint8_t *mode );
345
357err_t stepper12_set_step_mode ( stepper12_t *ctx, uint8_t mode );
358
370err_t stepper12_get_torque ( stepper12_t *ctx, uint8_t *torque );
371
383err_t stepper12_set_torque ( stepper12_t *ctx, uint8_t torque );
384
397err_t stepper12_get_decay_pin ( stepper12_t *ctx, uint8_t *state );
398
411err_t stepper12_set_decay_pin ( stepper12_t *ctx, uint8_t state );
412
425err_t stepper12_get_sleep_x_pin ( stepper12_t *ctx, uint8_t *state );
426
439err_t stepper12_set_sleep_x_pin ( stepper12_t *ctx, uint8_t state );
440
453err_t stepper12_get_lo_pin ( stepper12_t *ctx, uint8_t *state );
454
467err_t stepper12_get_mo_pin ( stepper12_t *ctx, uint8_t *state );
468
484void stepper12_drive_motor ( stepper12_t *ctx, uint32_t steps, uint8_t speed );
485
495
505
516void stepper12_set_direction ( stepper12_t *ctx, uint8_t dir );
517
527
537
547
558void stepper12_set_clk_pin ( stepper12_t *ctx, uint8_t state );
559
560#ifdef __cplusplus
561}
562#endif
563#endif // STEPPER12_H
564
565 // stepper12
566
567// ------------------------------------------------------------------------ END
err_t stepper12_set_step_mode(stepper12_t *ctx, uint8_t mode)
Stepper 12 set step mode function.
err_t stepper12_write_register(stepper12_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 12 write register function.
void stepper12_drive_motor(stepper12_t *ctx, uint32_t steps, uint8_t speed)
Stepper 12 driver motor function.
uint8_t stepper12_get_int_pin(stepper12_t *ctx)
Stepper 12 get int pin function.
void stepper12_reset_device(stepper12_t *ctx)
Stepper 12 reset device function.
err_t stepper12_get_lo_pin(stepper12_t *ctx, uint8_t *state)
Stepper 12 get lo pin function.
void stepper12_set_clk_pin(stepper12_t *ctx, uint8_t state)
Stepper 12 set clk pin function.
void stepper12_disable_device(stepper12_t *ctx)
Stepper 12 disable device function.
void stepper12_switch_direction(stepper12_t *ctx)
Stepper 12 switch direction function.
err_t stepper12_read_register(stepper12_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 12 read register function.
err_t stepper12_get_step_mode(stepper12_t *ctx, uint8_t *mode)
Stepper 12 get step mode function.
err_t stepper12_get_mo_pin(stepper12_t *ctx, uint8_t *state)
Stepper 12 get mo pin function.
err_t stepper12_get_torque(stepper12_t *ctx, uint8_t *torque)
Stepper 12 get torque function.
err_t stepper12_default_cfg(stepper12_t *ctx)
Stepper 12 default configuration function.
void stepper12_enable_device(stepper12_t *ctx)
Stepper 12 enable device function.
err_t stepper12_init(stepper12_t *ctx, stepper12_cfg_t *cfg)
Stepper 12 initialization function.
void stepper12_cfg_setup(stepper12_cfg_t *cfg)
Stepper 12 configuration object setup function.
err_t stepper12_set_decay_pin(stepper12_t *ctx, uint8_t state)
Stepper 12 set decay pin function.
err_t stepper12_set_sleep_x_pin(stepper12_t *ctx, uint8_t state)
Stepper 12 set sleep x pin function.
err_t stepper12_set_torque(stepper12_t *ctx, uint8_t torque)
Stepper 12 set torque function.
void stepper12_set_direction(stepper12_t *ctx, uint8_t dir)
Stepper 12 set direction function.
err_t stepper12_get_sleep_x_pin(stepper12_t *ctx, uint8_t *state)
Stepper 12 get sleep x pin function.
err_t stepper12_get_decay_pin(stepper12_t *ctx, uint8_t *state)
Stepper 12 get decay pin function.
stepper12_return_value_t
Stepper 12 Click return value data.
Definition stepper12.h:252
@ STEPPER12_OK
Definition stepper12.h:253
@ STEPPER12_ERROR
Definition stepper12.h:254
Stepper 12 Click configuration object.
Definition stepper12.h:232
pin_name_t clk
Definition stepper12.h:239
uint32_t i2c_speed
Definition stepper12.h:242
pin_name_t dir
Definition stepper12.h:237
pin_name_t scl
Definition stepper12.h:233
pin_name_t en
Definition stepper12.h:236
pin_name_t int_pin
Definition stepper12.h:240
pin_name_t sda
Definition stepper12.h:234
pin_name_t rst
Definition stepper12.h:238
uint8_t i2c_address
Definition stepper12.h:243
Stepper 12 Click context object.
Definition stepper12.h:209
digital_in_t int_pin
Definition stepper12.h:217
i2c_master_t i2c
Definition stepper12.h:220
digital_out_t clk
Definition stepper12.h:214
digital_out_t en
Definition stepper12.h:211
digital_out_t rst
Definition stepper12.h:213
uint8_t slave_address
Definition stepper12.h:223
digital_out_t dir
Definition stepper12.h:212