1 #ifndef __SWM341_QEI_H__
2 #define __SWM341_QEI_H__
3 
4 typedef struct {
5     uint8_t  mode;                  //QEI_MODE_X2、QEI_MODE_X4
6     uint16_t maxcnt;                //最大计数值
7     uint8_t  swapAB;                //1 交换A、B引脚
8     uint8_t  intINDEXEn;            //检测到Index脉冲中断使能
9     uint8_t  intMATCHEn;            //POSCNT递增到与MAXCNT相等,或POSCNT从MAXCNT递减到0中断使能
10     uint8_t  intCNTOVEn;            //Counter Overrun,计数器溢出中断使能
11     uint8_t  intERROREn;            //计数器错误中断使能
12 } QEI_InitStructure;
13 
14 
15 #define QEI_MODE_X2         0
16 #define QEI_MODE_X4         1
17 
18 #define QEI_INT_INDEX       (1 << 0)
19 #define QEI_INT_MATCH       (1 << 1)
20 #define QEI_INT_CNTOV       (1 << 2)
21 #define QEI_INT_ERROR       (1 << 3)
22 
23 
24 void QEI_Init(QEI_TypeDef * QEIx, QEI_InitStructure * initStruct);      //QEI初始化
25 void QEI_Start(QEI_TypeDef * QEIx);                     //启动QEI
26 void QEI_Stop(QEI_TypeDef * QEIx);                      //关闭QEI
27 
28 uint32_t QEI_IndexLvl(QEI_TypeDef * QEIx);              //QEI Index引脚电平
29 uint32_t QEI_CountDir(QEI_TypeDef * QEIx);              //QEI计数方向,0 反向计数    1 正向计数
30 
31 void QEI_IntEn(QEI_TypeDef * QEIx, uint32_t it);        //QEI中断使能
32 void QEI_IntDis(QEI_TypeDef * QEIx, uint32_t it);       //QEI中断关闭
33 void QEI_IntClr(QEI_TypeDef * QEIx, uint32_t it);       //QEI中断标志清除
34 uint32_t QEI_IntStat(QEI_TypeDef * QEIx, uint32_t it);  //QEI中断状态查询
35 
36 
37 #endif //__SWM341_QEI_H__
38