|
@@ -85,7 +85,7 @@
|
85
|
85
|
#define OUT_WRITE(IO, v) do{ SET_OUTPUT(IO); WRITE(IO, v); }while(0)
|
86
|
86
|
|
87
|
87
|
/**
|
88
|
|
- * Interrupt Control
|
|
88
|
+ * Timer and Interrupt Control
|
89
|
89
|
*/
|
90
|
90
|
|
91
|
91
|
// Waveform Generation Modes
|
|
@@ -128,24 +128,86 @@ typedef enum {
|
128
|
128
|
CS_EXT_RISING // 7
|
129
|
129
|
} ClockSource;
|
130
|
130
|
|
131
|
|
-#define SET_WGM(T,V) do{ \
|
|
131
|
+// Clock Sources (Timer 2 only)
|
|
132
|
+typedef enum {
|
|
133
|
+ CS2_NONE, // 0
|
|
134
|
+ CS2_PRESCALER_1, // 1
|
|
135
|
+ CS2_PRESCALER_8, // 2
|
|
136
|
+ CS2_PRESCALER_32, // 3
|
|
137
|
+ CS2_PRESCALER_64, // 4
|
|
138
|
+ CS2_PRESCALER_128, // 5
|
|
139
|
+ CS2_PRESCALER_256, // 6
|
|
140
|
+ CS2_PRESCALER_1024 // 7
|
|
141
|
+} ClockSource2;
|
|
142
|
+
|
|
143
|
+// Get interrupt bits in an orderly way
|
|
144
|
+#define GET_WGM(T) (((TCCR##T##A >> WGM##T##0) & 0x3) | ((TCCR##T##B >> WGM##T##2 << 2) & 0xC))
|
|
145
|
+#define GET_CS(T) ((TCCR##T##B >> CS##T##0) & 0x7)
|
|
146
|
+#define GET_COM(T,Q) ((TCCR##T##Q >> COM##T##Q##0) & 0x3)
|
|
147
|
+#define GET_COMA(T) GET_COM(T,A)
|
|
148
|
+#define GET_COMB(T) GET_COM(T,B)
|
|
149
|
+#define GET_COMC(T) GET_COM(T,C)
|
|
150
|
+#define GET_ICNC(T) (!!(TCCR##T##B & _BV(ICNC##T)))
|
|
151
|
+#define GET_ICES(T) (!!(TCCR##T##B & _BV(ICES##T)))
|
|
152
|
+#define GET_FOC(T,Q) (!!(TCCR##T##C & _BV(FOC##T##Q)))
|
|
153
|
+#define GET_FOCA(T) GET_FOC(T,A)
|
|
154
|
+#define GET_FOCB(T) GET_FOC(T,B)
|
|
155
|
+#define GET_FOCC(T) GET_FOC(T,C)
|
|
156
|
+
|
|
157
|
+// Set Wave Generation Mode bits
|
|
158
|
+#define _SET_WGM(T,V) do{ \
|
132
|
159
|
TCCR##T##A = (TCCR##T##A & ~(0x3 << WGM##T##0)) | (( int(V) & 0x3) << WGM##T##0); \
|
133
|
160
|
TCCR##T##B = (TCCR##T##B & ~(0x3 << WGM##T##2)) | (((int(V) >> 2) & 0x3) << WGM##T##2); \
|
134
|
161
|
}while(0)
|
135
|
|
-
|
136
|
|
-#define SET_CS(T,V) do{ \
|
137
|
|
- TCCR##T##B = (TCCR##T##B & ~(0x7 << CS10)) | ((int(V) & 0x7) << CS10); \
|
138
|
|
- }while(0)
|
139
|
|
-
|
140
|
|
-#define SET_COM(T,Q,V) do{ \
|
141
|
|
- TCCR##T##Q = (TCCR##T##Q & ~(0x3 << COM1##Q##0)) | ((int(V) & 0x3) << COM1##Q##0); \
|
142
|
|
- }while(0)
|
|
162
|
+#define SET_WGM(T,V) _SET_WGM(T,WGM_##V)
|
|
163
|
+
|
|
164
|
+// Set Clock Select bits
|
|
165
|
+#define _SET_CS(T,V) (TCCR##T##B = (TCCR##T##B & ~(0x7 << CS##T##0)) | ((int(V) & 0x7) << CS##T##0))
|
|
166
|
+#define _SET_CS0(V) _SET_CS(0,V)
|
|
167
|
+#define _SET_CS1(V) _SET_CS(1,V)
|
|
168
|
+#ifdef TCCR2
|
|
169
|
+ #define _SET_CS2(V) (TCCR2 = (TCCR2 & ~(0x7 << CS20)) | (int(V) << CS20))
|
|
170
|
+#else
|
|
171
|
+ #define _SET_CS2(V) _SET_CS(2,V)
|
|
172
|
+#endif
|
|
173
|
+#define _SET_CS3(V) _SET_CS(3,V)
|
|
174
|
+#define _SET_CS4(V) _SET_CS(4,V)
|
|
175
|
+#define _SET_CS5(V) _SET_CS(5,V)
|
|
176
|
+#define SET_CS0(V) _SET_CS0(CS_##V)
|
|
177
|
+#define SET_CS1(V) _SET_CS1(CS_##V)
|
|
178
|
+#ifdef TCCR2
|
|
179
|
+ #define SET_CS2(V) _SET_CS2(CS2_##V)
|
|
180
|
+#else
|
|
181
|
+ #define SET_CS2(V) _SET_CS2(CS_##V)
|
|
182
|
+#endif
|
|
183
|
+#define SET_CS3(V) _SET_CS3(CS_##V)
|
|
184
|
+#define SET_CS4(V) _SET_CS4(CS_##V)
|
|
185
|
+#define SET_CS5(V) _SET_CS5(CS_##V)
|
|
186
|
+#define SET_CS(T,V) SET_CS##T(V)
|
|
187
|
+
|
|
188
|
+// Set Compare Mode bits
|
|
189
|
+#define _SET_COM(T,Q,V) (TCCR##T##Q = (TCCR##T##Q & ~(0x3 << COM##T##Q##0)) | (int(V) << COM##T##Q##0))
|
|
190
|
+#define _SET_COMA(T,V) _SET_COM(T,A,V)
|
|
191
|
+#define _SET_COMB(T,V) _SET_COM(T,B,V)
|
|
192
|
+#define _SET_COMC(T,V) _SET_COM(T,C,V)
|
|
193
|
+#define _SET_COMS(T,V1,V2,V3) do{ _SET_COMA(T,V1); _SET_COMB(T,V2); _SET_COMC(T,V3); }while(0)
|
|
194
|
+#define SET_COM(T,Q,V) _SET_COM(T,Q,COM_##V)
|
143
|
195
|
#define SET_COMA(T,V) SET_COM(T,A,V)
|
144
|
196
|
#define SET_COMB(T,V) SET_COM(T,B,V)
|
145
|
|
-#define SET_COMS(T,V1,V2) do{ SET_COMA(T,V1); SET_COMB(T,V2); }while(0)
|
|
197
|
+#define SET_COMC(T,V) SET_COM(T,C,V)
|
|
198
|
+#define SET_COMS(T,V1,V2,V3) do{ SET_COMA(T,V1); SET_COMB(T,V2); SET_COMC(T,V3); }while(0)
|
|
199
|
+
|
|
200
|
+// Set Noise Canceler bit
|
|
201
|
+#define SET_ICNC(T,V) (TCCR##T##B = (V) ? TCCR##T##B | _BV(ICNC##T) : TCCR##T##B & ~_BV(ICNC##T))
|
|
202
|
+
|
|
203
|
+// Set Input Capture Edge Select bit
|
|
204
|
+#define SET_ICES(T,V) (TCCR##T##B = (V) ? TCCR##T##B | _BV(ICES##T) : TCCR##T##B & ~_BV(ICES##T))
|
146
|
205
|
|
147
|
|
-#define SET_ICNC(T,V) (TCCR##T##B = (TCCR##T##B & ~_BV(7) | ((V) & 1) << 7))
|
148
|
|
-#define SET_ICES(T,V) (TCCR##T##B = (TCCR##T##B & ~_BV(6) | ((V) & 1) << 6))
|
|
206
|
+// Set Force Output Compare bit
|
|
207
|
+#define SET_FOC(T,Q,V) (TCCR##T##C = (V) ? TCCR##T##C | _BV(FOC##T##Q) : TCCR##T##C & ~_BV(FOC##T##Q))
|
|
208
|
+#define SET_FOCA(T,V) SET_FOC(T,A,V)
|
|
209
|
+#define SET_FOCB(T,V) SET_FOC(T,B,V)
|
|
210
|
+#define SET_FOCC(T,V) SET_FOC(T,C,V)
|
149
|
211
|
|
150
|
212
|
/**
|
151
|
213
|
* Ports and Functions
|
|
@@ -177,8 +239,8 @@ typedef enum {
|
177
|
239
|
#define DEBUG_LED AIO5
|
178
|
240
|
|
179
|
241
|
/**
|
180
|
|
- pins
|
181
|
|
- */
|
|
242
|
+ * Pins Info
|
|
243
|
+ */
|
182
|
244
|
|
183
|
245
|
#define DIO0_PIN PIND0
|
184
|
246
|
#define DIO0_RPORT PIND
|
|
@@ -513,9 +575,10 @@ typedef enum {
|
513
|
575
|
#define OC2B DIO14
|
514
|
576
|
|
515
|
577
|
#define DEBUG_LED DIO0
|
|
578
|
+
|
516
|
579
|
/**
|
517
|
|
- pins
|
518
|
|
- */
|
|
580
|
+ * Pins Info
|
|
581
|
+ */
|
519
|
582
|
|
520
|
583
|
#define DIO0_PIN PINB0
|
521
|
584
|
#define DIO0_RPORT PINB
|
|
@@ -757,8 +820,6 @@ typedef enum {
|
757
|
820
|
#define AIO7_DDR DDRA
|
758
|
821
|
#define AIO7_PWM NULL
|
759
|
822
|
|
760
|
|
-
|
761
|
|
-
|
762
|
823
|
#undef PA0
|
763
|
824
|
#define PA0_PIN PINA0
|
764
|
825
|
#define PA0_RPORT PINA
|
|
@@ -1023,8 +1084,9 @@ typedef enum {
|
1023
|
1084
|
#define DEBUG_LED DIO21
|
1024
|
1085
|
|
1025
|
1086
|
/**
|
1026
|
|
- pins
|
1027
|
|
- */
|
|
1087
|
+ * Pins Info
|
|
1088
|
+ */
|
|
1089
|
+
|
1028
|
1090
|
#define DIO0_PIN PINE0
|
1029
|
1091
|
#define DIO0_RPORT PINE
|
1030
|
1092
|
#define DIO0_WPORT PORTE
|
|
@@ -2075,7 +2137,7 @@ typedef enum {
|
2075
|
2137
|
#define DEBUG_LED DIO31 /* led D5 red */
|
2076
|
2138
|
|
2077
|
2139
|
/**
|
2078
|
|
- * pins
|
|
2140
|
+ * Pins Info
|
2079
|
2141
|
*/
|
2080
|
2142
|
|
2081
|
2143
|
//#define AT90USBxx_TEENSYPP_ASSIGNMENTS // Use Teensy++ 2.0 assignments
|
|
@@ -3402,8 +3464,9 @@ typedef enum {
|
3402
|
3464
|
#define DEBUG_LED DIO46
|
3403
|
3465
|
|
3404
|
3466
|
/**
|
3405
|
|
- pins
|
3406
|
|
- */
|
|
3467
|
+ * Pins Info
|
|
3468
|
+ */
|
|
3469
|
+
|
3407
|
3470
|
#define DIO0_PIN PINE0
|
3408
|
3471
|
#define DIO0_RPORT PINE
|
3409
|
3472
|
#define DIO0_WPORT PORTE
|
|
@@ -3728,9 +3791,6 @@ typedef enum {
|
3728
|
3791
|
#define DIO53_DDR DDRF
|
3729
|
3792
|
#define DIO53_PWM NULL
|
3730
|
3793
|
|
3731
|
|
-
|
3732
|
|
-
|
3733
|
|
-
|
3734
|
3794
|
#undef PA0
|
3735
|
3795
|
#define PA0_PIN PINA0
|
3736
|
3796
|
#define PA0_RPORT PINA
|