39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
75#define SILENTSTEP4_REG_GCONF 0x00
76#define SILENTSTEP4_REG_GSTAT 0x01
77#define SILENTSTEP4_REG_IFCNT 0x02
78#define SILENTSTEP4_REG_NODECONF 0x03
79#define SILENTSTEP4_REG_IOIN 0x04
80#define SILENTSTEP4_REG_DRV_CONF 0x0A
81#define SILENTSTEP4_REG_GLOBAL_SCALER 0x0B
82#define SILENTSTEP4_REG_IHOLD_IRUN 0x10
83#define SILENTSTEP4_REG_TPOWERDOWN 0x11
84#define SILENTSTEP4_REG_TSTEP 0x12
85#define SILENTSTEP4_REG_TPWMTHRS 0x13
86#define SILENTSTEP4_REG_TCOOLTHRS 0x14
87#define SILENTSTEP4_REG_THIGH 0x15
88#define SILENTSTEP4_REG_DIRECT_MODE 0x2D
89#define SILENTSTEP4_REG_ENCMODE 0x38
90#define SILENTSTEP4_REG_X_ENC 0x39
91#define SILENTSTEP4_REG_ENC_CONST 0x3A
92#define SILENTSTEP4_REG_ENC_STATUS 0x3B
93#define SILENTSTEP4_REG_ENC_LATCH 0x3C
94#define SILENTSTEP4_REG_ADC_VSUPPLY_AIN 0x50
95#define SILENTSTEP4_REG_ADC_TEMP 0x51
96#define SILENTSTEP4_REG_OTW_OV_VTH 0x52
97#define SILENTSTEP4_REG_MSLUT_0 0x60
98#define SILENTSTEP4_REG_MSLUT_1 0x61
99#define SILENTSTEP4_REG_MSLUT_2 0x62
100#define SILENTSTEP4_REG_MSLUT_3 0x63
101#define SILENTSTEP4_REG_MSLUT_4 0x64
102#define SILENTSTEP4_REG_MSLUT_5 0x65
103#define SILENTSTEP4_REG_MSLUT_6 0x66
104#define SILENTSTEP4_REG_MSLUT_7 0x67
105#define SILENTSTEP4_REG_MSLUTSEL 0x68
106#define SILENTSTEP4_REG_MSLUTSTART 0x69
107#define SILENTSTEP4_REG_MSCNT 0x6A
108#define SILENTSTEP4_REG_MSCURACT 0x6B
109#define SILENTSTEP4_REG_CHOPCONF 0x6C
110#define SILENTSTEP4_REG_COOLCONF 0x6D
111#define SILENTSTEP4_REG_DRV_STATUS 0x6F
112#define SILENTSTEP4_REG_PWMCONF 0x70
113#define SILENTSTEP4_REG_PWM_SCALE 0x71
114#define SILENTSTEP4_REG_PWM_AUTO 0x72
115#define SILENTSTEP4_REG_SG4_THRS 0x74
116#define SILENTSTEP4_REG_SG4_RESULT 0x75
117#define SILENTSTEP4_REG_SG4_IND 0x76
123#define SILENTSTEP4_PCA9538A_REG_INPUT 0x00
124#define SILENTSTEP4_PCA9538A_REG_OUTPUT 0x01
125#define SILENTSTEP4_PCA9538A_REG_POLARITY 0x02
126#define SILENTSTEP4_PCA9538A_REG_CONFIG 0x03
142#define SILENTSTEP4_IOIN_VERSION_MASK 0xFF000000ul
143#define SILENTSTEP4_IOIN_VERSION_DEFAULT 0x40000000ul
149#define SILENTSTEP4_PIN_EN 0x01
150#define SILENTSTEP4_PIN_SLEEP 0x02
151#define SILENTSTEP4_PIN_DIAG0 0x04
152#define SILENTSTEP4_PIN_DIAG1 0x08
153#define SILENTSTEP4_PIN_OV 0x10
159#define SILENTSTEP4_PCA9538A_DEFAULT_CONFIG 0xFC
165#define SILENTSTEP4_DIR_CW 0
166#define SILENTSTEP4_DIR_CCW 1
172#define SILENTSTEP4_PIN_STATE_LOW 0
173#define SILENTSTEP4_PIN_STATE_HIGH 1
179#define SILENTSTEP4_SPEED_VERY_SLOW 0
180#define SILENTSTEP4_SPEED_SLOW 1
181#define SILENTSTEP4_SPEED_MEDIUM 2
182#define SILENTSTEP4_SPEED_FAST 3
183#define SILENTSTEP4_SPEED_VERY_FAST 4
189#define SILENTSTEP4_TOFF_MASK 0x0000000Ful
190#define SILENTSTEP4_TOFF_SHIFT 0
191#define SILENTSTEP4_TOFF_DRIVER_DISABLE 0
192#define SILENTSTEP4_TOFF_MIN 1
193#define SILENTSTEP4_TOFF_DEFAULT 4
194#define SILENTSTEP4_TOFF_MAX 15
200#define SILENTSTEP4_MRES_MASK 0x0F000000ul
201#define SILENTSTEP4_MRES_SHIFT 24
202#define SILENTSTEP4_MRES_256 0
203#define SILENTSTEP4_MRES_128 1
204#define SILENTSTEP4_MRES_64 2
205#define SILENTSTEP4_MRES_32 3
206#define SILENTSTEP4_MRES_16 4
207#define SILENTSTEP4_MRES_8 5
208#define SILENTSTEP4_MRES_4 6
209#define SILENTSTEP4_MRES_2 7
210#define SILENTSTEP4_MRES_FULLSTEP 8
216#define SILENTSTEP4_IRUN_MASK 0x00000F00ul
217#define SILENTSTEP4_IRUN_SHIFT 8
218#define SILENTSTEP4_IRUN_MIN 0
219#define SILENTSTEP4_IRUN_DEFAULT 16
220#define SILENTSTEP4_IRUN_MAX 31
227#define SILENTSTEP4_DEVICE_ADDRESS_A1A0_00 0x70
228#define SILENTSTEP4_DEVICE_ADDRESS_A1A0_01 0x71
229#define SILENTSTEP4_DEVICE_ADDRESS_A1A0_10 0x72
230#define SILENTSTEP4_DEVICE_ADDRESS_A1A0_11 0x73
240#define SILENTSTEP4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
241#define SILENTSTEP4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
259#define SILENTSTEP4_MAP_MIKROBUS( cfg, mikrobus ) \
260 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
261 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
262 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
263 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
264 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
265 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
266 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
267 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
268 cfg.step = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
269 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
err_t silentstep4_pca_write_reg(silentstep4_t *ctx, uint8_t reg, uint8_t data_in)
Silent Step 4 pca write reg function.
err_t silentstep4_set_run_current(silentstep4_t *ctx, uint8_t irun)
Silent Step 4 set run current function.
void silentstep4_set_rst_pin(silentstep4_t *ctx, uint8_t state)
Silent Step 4 set rst pin function.
err_t silentstep4_read_reg(silentstep4_t *ctx, uint8_t reg, uint32_t *data_out)
Silent Step 4 read reg function.
void silentstep4_set_direction(silentstep4_t *ctx, uint8_t dir)
Silent Step 4 set direction function.
void silentstep4_reset_pca(silentstep4_t *ctx)
Silent Step 4 reset device function.
spi_master_t spi
Definition silentstep4.h:287
uint8_t silentstep4_get_int_pin(silentstep4_t *ctx)
Silent Step 4 get int pin function.
silentstep4_return_value_t
Silent Step 4 Click return value data.
Definition silentstep4.h:325
err_t silentstep4_set_sleep_pin(silentstep4_t *ctx, uint8_t state)
Silent Step 4 set sleep pin function.
void silentstep4_switch_direction(silentstep4_t *ctx)
Silent Step 4 switch direction function.
void silentstep4_cfg_setup(silentstep4_cfg_t *cfg)
Silent Step 4 configuration object setup function.
err_t silentstep4_write_reg(silentstep4_t *ctx, uint8_t reg, uint32_t data_in)
Silent Step 4 write reg function.
err_t silentstep4_enable_device(silentstep4_t *ctx)
Silent Step 4 enable device function.
struct silentstep4_s silentstep4_t
Silent Step 4 Click context object.
pin_name_t step
Definition silentstep4.h:308
err_t silentstep4_init(silentstep4_t *ctx, silentstep4_cfg_t *cfg)
Silent Step 4 initialization function.
uint32_t i2c_speed
Definition silentstep4.h:311
err_t silentstep4_get_diag0_pin(silentstep4_t *ctx, uint8_t *state)
Silent Step 4 get diag0 pin function.
void silentstep4_set_step_pin(silentstep4_t *ctx, uint8_t state)
Silent Step 4 set step pin function.
err_t silentstep4_default_cfg(silentstep4_t *ctx)
Silent Step 4 default configuration function.
err_t silentstep4_set_toff(silentstep4_t *ctx, uint8_t toff)
Silent Step 4 set toff function.
spi_master_chip_select_polarity_t cs_polarity
Definition silentstep4.h:316
pin_name_t sck
Definition silentstep4.h:304
err_t silentstep4_set_step_res(silentstep4_t *ctx, uint8_t mres)
Silent Step 4 set step res function.
spi_master_mode_t spi_mode
Definition silentstep4.h:315
err_t silentstep4_set_en_pin(silentstep4_t *ctx, uint8_t state)
Silent Step 4 set en pin function.
digital_in_t int_pin
Definition silentstep4.h:284
digital_out_t step
Definition silentstep4.h:282
i2c_master_t i2c
Definition silentstep4.h:286
err_t silentstep4_get_diag1_pin(silentstep4_t *ctx, uint8_t *state)
Silent Step 4 get diag1 pin function.
err_t silentstep4_pca_read_reg(silentstep4_t *ctx, uint8_t reg, uint8_t *data_out)
Silent Step 4 pca read reg function.
pin_name_t mosi
Definition silentstep4.h:303
uint32_t spi_speed
Definition silentstep4.h:314
digital_out_t rst
Definition silentstep4.h:281
void silentstep4_drive_motor(silentstep4_t *ctx, uint32_t steps, uint8_t speed)
Silent Step 4 driver motor function.
pin_name_t dir
Definition silentstep4.h:306
pin_name_t scl
Definition silentstep4.h:300
uint8_t slave_address
Definition silentstep4.h:289
err_t silentstep4_get_en_pin(silentstep4_t *ctx, uint8_t *state)
Silent Step 4 get en pin function.
pin_name_t int_pin
Definition silentstep4.h:309
err_t silentstep4_get_ov_pin(silentstep4_t *ctx, uint8_t *state)
Silent Step 4 get ov pin function.
pin_name_t miso
Definition silentstep4.h:302
pin_name_t sda
Definition silentstep4.h:301
err_t silentstep4_get_sleep_pin(silentstep4_t *ctx, uint8_t *state)
Silent Step 4 get sleep pin function.
pin_name_t chip_select
Definition silentstep4.h:290
err_t silentstep4_disable_device(silentstep4_t *ctx)
Silent Step 4 disable device function.
pin_name_t rst
Definition silentstep4.h:307
digital_out_t dir
Definition silentstep4.h:280
pin_name_t cs
Definition silentstep4.h:305
err_t silentstep4_check_com(silentstep4_t *ctx)
Silent Step 4 check com function.
uint8_t i2c_address
Definition silentstep4.h:312
@ SILENTSTEP4_ERROR
Definition silentstep4.h:327
@ SILENTSTEP4_OK
Definition silentstep4.h:326
This file contains SPI specific macros, functions, etc.
Silent Step 4 Click configuration object.
Definition silentstep4.h:299
Silent Step 4 Click context object.
Definition silentstep4.h:279