76 lines
3.0 KiB
C
Executable File
76 lines
3.0 KiB
C
Executable File
#include <linux/ioctl.h>
|
|
|
|
|
|
typedef enum
|
|
{
|
|
fh_sm_constant = 0,
|
|
fh_sm_high = 1,
|
|
fh_sm_manual_4 = 2,
|
|
fh_sm_manual_8 = 3,
|
|
}fh_sm_mode;
|
|
|
|
typedef struct
|
|
{
|
|
int period; // pwm num in one period (n+1, >=7)
|
|
int counter; // clk num in one pwm num
|
|
int copy; // pwm period num in one microstep (n+1)
|
|
int microstep; // microstep num in one time
|
|
}fh_sm_timingparam;
|
|
|
|
typedef struct
|
|
{
|
|
int NeedInit; // if init, 0: not, 1: init(sned some last pwm)
|
|
int InitRunNum; // pwm period for init (n+1)
|
|
int NeedUpdatePos; // if update position
|
|
int InitStep; // step for init
|
|
int InitMicroStep; // micro step for init
|
|
}fh_sm_param_init;
|
|
|
|
typedef struct
|
|
{
|
|
int AutoStopEn; // 0: stop external stop, 1:enable external stop
|
|
int AutoStopSigPol; // polarity for hw stop, 0: rising edge, 1: falling edge
|
|
int AutoStopSigDeb; // 0: stop debounce, 1: enable debounce
|
|
int AutoStopSigDebSet; // clk div, db_clk=1Mhz/(clk_div+1)
|
|
int AutoStopChechGPIO;
|
|
}fh_sm_param_autostop;
|
|
|
|
/* manual_pwm_choosenA & manual_pwm_choosenB, each 2bits: 00-wave1 01-wave2 10-all1 11-all0*/
|
|
/* bit|0,1|2,3|4,5|6,7|8,9|10,11|12,13|14,15|16,17|18,19|20,21|22,23|24,25|26,27|28,29|30,31| */
|
|
/* A | A1| A2| A3| A4| A5| A6 | A7 | A8 | AN1 | AN2 | AN3 | AN4 | AN5 | AN6 | AN7 | AN8 | */
|
|
/* B | B1| B2| B3| B4| B5| B6 | B7 | B8 | BN1 | BN2 | BN3 | BN4 | BN5 | BN6 | BN7 | BN8 | */
|
|
typedef struct
|
|
{
|
|
fh_sm_mode mode;
|
|
int direction; // only constant & high mode, 0: positive, 1:negative
|
|
int output_invert_A; // A pwm inverse, 0: +, 1: -
|
|
int output_invert_B; // B pwm inverse, 0: +, 1: -
|
|
unsigned int manual_pwm_choosenA; // manual4 or manual8 need
|
|
unsigned int manual_pwm_choosenB; // manual4 or manual8 need
|
|
fh_sm_timingparam timingparam; // see fh_sm_timingparam
|
|
fh_sm_param_init initparam; // see fh_sm_param_init
|
|
int keep; // if keep out last pwm
|
|
fh_sm_param_autostop autostopparam; // see fh_sm_param_autostop
|
|
}fh_sm_param;
|
|
|
|
typedef struct
|
|
{
|
|
int lutsize;
|
|
int *lut;
|
|
}fh_sm_lut;
|
|
|
|
|
|
#define FH_SM_IOCTL_MAGIC 's'
|
|
#define RESERVERD _IO(FH_SM_IOCTL_MAGIC, 0)
|
|
#define FH_SM_SET_PARAM _IOWR(FH_SM_IOCTL_MAGIC, 1, unsigned int) //fh_sm_param
|
|
#define FH_SM_START_SYNC _IOWR(FH_SM_IOCTL_MAGIC, 2, unsigned int) //int:microstepNum, wait to return microstep num already run
|
|
#define FH_SM_STOP _IOWR(FH_SM_IOCTL_MAGIC, 3, unsigned int) //stop, return microstep num already run
|
|
#define FH_SM_SET_LUT _IOWR(FH_SM_IOCTL_MAGIC, 4, unsigned int) //fh_sm_lut
|
|
#define FH_SM_GET_LUT _IOWR(FH_SM_IOCTL_MAGIC, 5, unsigned int) //fh_sm_lut
|
|
#define FH_SM_GET_PARAM _IOWR(FH_SM_IOCTL_MAGIC, 6, unsigned int) //fh_sm_param
|
|
#define FH_SM_START_ASYNC _IOWR(FH_SM_IOCTL_MAGIC, 7, unsigned int) //int:microstepNum, return immediately
|
|
#define FH_SM_GET_CUR_CYCLE _IOWR(FH_SM_IOCTL_MAGIC, 8, unsigned int) //int:microstepNum, return microstep num already run
|
|
#define FH_SM_CHECKISTOP _IOWR(FH_SM_IOCTL_MAGIC, 9, unsigned int) //return 0:busy, 1:stop
|
|
|
|
|