00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef _QDEC_H_
00049 #define _QDEC_H_
00050
00051 #include <avr32/io.h>
00052
00053 #include "compiler.h"
00054
00055
00056 #ifdef AVR32_QDEC_100_H_INCLUDED
00057 #define AVR32_QDEC0_IRQ_GROUP 31
00058 #define AVR32_QDEC1_IRQ_GROUP 32
00059 #endif
00060
00062 #define QDEC_INVALID_ARGUMENT (-1)
00063
00066
00067 #define QDEC_IDXPHS_QEPB_0_QEPA_0
00068 #define QDEC_IDXPHS_QEPB_0_QEPA_1
00069 #define QDEC_IDXPHS_QEPB_1_QEPA_0
00070 #define QDEC_IDXPHS_QEPB_1_QEPA_1
00072
00074 #define QDEC_QDEC_MODE 1
00076 #define QDEC_TIMER_MODE 0
00077
00079 #define QDEC_TSIR_UP 0
00081 #define QDEC_TSIR_DOWN 1
00083 #define QDEC_UPD_TSDIR 0
00085 #define QDEC_UPD_EVNT 1
00086
00088 typedef struct
00089 {
00090 unsigned int :24;
00091
00093 unsigned int ovr :1;
00094
00096 unsigned int dirinv :1;
00097
00099 unsigned int idexerr :1;
00100
00102 unsigned int rcro :1;
00103
00105 unsigned int pcro :1;
00106
00108 unsigned int cap :1;
00109
00111 unsigned int cmp :1;
00112
00114 unsigned int qepi :1;
00115
00116 } qdec_interrupt_t;
00117
00119 typedef struct
00120 {
00121 unsigned int :5;
00122
00123 unsigned int :3;
00124
00126 unsigned int :6;
00127
00129 unsigned int :2;
00130
00132 unsigned int :2;
00133
00135 unsigned int filten :1;
00136
00138 unsigned int idxphs :2;
00139
00141 unsigned int idxinv :1;
00142
00144 unsigned int phsinvb :1;
00145
00147 unsigned int phsinva :1;
00148
00150 unsigned int :3;
00151
00153 unsigned int evtrge :1;
00154
00156 unsigned int rcce :1;
00157
00159 unsigned int pcce :1;
00160
00162 unsigned int idxe :1;
00163
00165 unsigned int qdec :1;
00166
00167 } qdec_quadrature_decoder_opt_t;
00168
00170 typedef struct
00171 {
00172 unsigned int :5;
00173
00175 unsigned int clks :3;
00176
00178 unsigned int :6;
00179
00181 unsigned int upd :1;
00182
00184 unsigned int tsdir :1;
00185
00186 unsigned int :2;
00187
00189 unsigned int filten :1;
00190
00192 unsigned int :5;
00193
00195 unsigned int :3;
00196
00198 unsigned int evtrge :1;
00199
00201 unsigned int rcce :1;
00202
00204 unsigned int pcce :1;
00205
00207 unsigned int :1;
00208
00210 unsigned int qdec :1;
00211
00212 } qdec_timer_opt_t;
00213
00221 extern int qdec_get_interrupt_settings(volatile avr32_qdec_t *qdec);
00222
00229 extern int qdec_configure_interrupts(volatile avr32_qdec_t *qdec, const qdec_interrupt_t *bitfield);
00230
00231
00238 extern int qdec_init_quadrature_decoder_mode(volatile avr32_qdec_t *qdec, const qdec_quadrature_decoder_opt_t *opt);
00239
00246 extern int qdec_init_timer_mode(volatile avr32_qdec_t *qdec, const qdec_timer_opt_t *opt);
00247
00253 extern int qdec_software_trigger(volatile avr32_qdec_t *qdec);
00254
00260 extern int qdec_stop(volatile avr32_qdec_t *qdec);
00261
00267 extern unsigned short int qdec_read_rc(volatile avr32_qdec_t *qdec);
00268
00274 extern unsigned short int qdec_read_pc(volatile avr32_qdec_t *qdec);
00275
00283 extern unsigned short int qdec_write_rc_cnt(volatile avr32_qdec_t *qdec,unsigned short int value);
00284
00292 extern unsigned short int qdec_write_pc_cnt(volatile avr32_qdec_t *qdec,unsigned short int value);
00293
00294
00302 extern unsigned short int qdec_write_rc_top(volatile avr32_qdec_t *qdec, unsigned short int value);
00303
00312 extern unsigned short int qdec_write_pc_top(volatile avr32_qdec_t *qdec, unsigned short int value);
00313
00322 extern unsigned short int qdec_write_rc_cmp(volatile avr32_qdec_t *qdec, unsigned short int value);
00323
00332 extern unsigned short int qdec_write_pc_cmp(volatile avr32_qdec_t *qdec, unsigned short int value);
00333
00334
00342 extern unsigned short int qdec_read_pc_cap(volatile avr32_qdec_t *qdec);
00343
00344
00352 extern unsigned short int qdec_read_rc_cap(volatile avr32_qdec_t *qdec);
00353
00354 #endif // _QDEC_H_
00355
00356
00357