|
-
-
- #ifndef STEPPER_H
- #define STEPPER_H
-
- #include <stdint.h>
- #include "periph/gpio.h"
- #include "periph/uart.h"
- #include "sensor.h"
- #include "byteorder.h"
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #define STEPPER_PARAM_VEL_MAX (25)
- #define STEPPER_PARAM_ACC_MAX (200)
- #define STEPPER_PARAM_VELOCITY_DEFAULT (0)
- #define STEPPER_PARAM_MICROSTEP_DEFAULT (16)
- #define STEPPER_PARAM_DIVISION_DEFAULT (200)
- #define STEPPER_PARAM_ANGLE_DEFAULT (0)
- #define STEPPER_PARAM_HOMING_ANGLE_DEFAULT (20)
-
- #define STEPPER_UART_SLAVE_ADDR (0x0)
- #define STEPPER_UART_SYNC (0x05)
- #define STEPPER_UART_REG_GCONF (0x00)
- #define STEPPER_UART_REG_GSTAT (0x01)
- #define STEPPER_UART_REG_IFCNT (0x02)
- #define STEPPER_UART_REG_SLAVECONF (0x03)
-
- #define STEPPER_GCONF_BIT_I_SCALE_ANALOG (0x0 << 0)
- #define STEPPER_GCONF_BIT_INTERNAL_RSENSE (0x1 << 1) //
- #define STEPPER_GCONF_BIT_SPREADCYCLE (0x1 << 2) // enable spreadcycle
- #define STEPPER_GCONF_BIT_SHAFT (0x0 << 3) // Non inverse
- #define STEPPER_GCONF_BIT_PDN_DISABLE (0x1 << 6) // Set to 1 when using UART
- #define STEPPER_GCONF_BIT_MSTEP_SELECT (0x1 << 7)
-
- // default datagram => 05 ff 00 00 00 01 01 bb
- #define STEPPER_GCONF_ADDR (0x00) // 0x00
- #define STEPPER_GCONF_VALUES (0xC1000000UL) //(0x83800000UL) // 000001C1 set bit 0,6,7,8. 6: PDN disable is require for UART operation.
-
- // default datagram => 05 ff 6c 17 01 00 53 3e
- #define STEPPER_CHOPCONF_ADDR (0x6c) // 6C
- #define STEPPER_CHOPCONF_VALUES (0xB5810132UL)//(0xCA00004CUL) // 32000053 set dedge=0x1, intpol=0x1, mres=0x2, hstrt=0x5, toff=0x3. others are 0x0.
- //#define STEPPER_CHOPCONF_VALUES [0x32,0x00,0x00,0x53] // set dedge=0x1, intpol=0x1, mres=0x2, hstrt=0x5, toff=0x3. others are 0x0.
-
-
-
- /**
- * @brief Status and error codes
- */
- enum {
- STEPPER_OK = 0,
- STEPPER_NO = -1,
- };
-
- /**
- * @brief Direction for stepper
- */
- typedef enum {
- STEPPER_FORWARD = 0x0,
- STEPPER_REVERSE = 0x1,
- } stepper_direction_t;
-
- /**
- * @brief Data structure holding the device parameters needed for initialization
- */
- typedef struct {
- gpio_t step_pin;
- gpio_t dir_pin;
- uint8_t uart;
- uint8_t vel_max;
- uint8_t acc_max;
- uint8_t microstep;
- uint16_t division;
- float angle;
- float velocity;
- sensor_t sensor;
- float homing_angle;
- } stepper_params_t;
-
- /**
- * @brief Device Descriptor for Stepper controller
- */
- typedef struct {
- stepper_params_t p;
- } stepper_t;
-
- int stepper_init(stepper_t *dev, const stepper_params_t *params);
-
- int stepper_set_velocity(stepper_t *dev, float *velocity);
-
- int stepper_homing(stepper_t *dev);
-
- int stepper_get_angle(stepper_t *dev, float *angle);
-
- int stepper_step(stepper_t *dev, stepper_direction_t *direction);
-
- int stepper_write(stepper_t *dev, uint8_t reg, le_uint32_t *data);
-
- int stepper_read(stepper_t *dev, uint8_t reg);
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif /* STEPPER_H */
|