forked from openLRSng/openLRSng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardware.h
237 lines (182 loc) · 6 KB
/
hardware.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#if defined(COMPILE_TX)
#define BOARD_TYPE TX_BOARD_TYPE
#else
#define BOARD_TYPE RX_BOARD_TYPE
#endif
//####### Board Pinouts #########
#if (BOARD_TYPE == 0) // Flytron M1 TX
#ifndef COMPILE_TX
#error TX module cannot be used as RX
#endif
#define PPM_IN A5
#define BUZZER 9
#define BTN 10
#define Red_LED 12
#define Green_LED 11
#define Red_LED_ON PORTB |= _BV(4);
#define Red_LED_OFF PORTB &= ~_BV(4);
#define Green_LED_ON PORTB |= _BV(3);
#define Green_LED_OFF PORTB &= ~_BV(3);
#define PPM_Pin_Interrupt_Setup PCMSK1 = 0x20;PCICR|=(1<<PCIE1);
#define PPM_Signal_Interrupt PCINT1_vect
#define PPM_Signal_Edge_Check (PINC & 0x20)==0x20
//## RFM22B Pinouts for Public Edition (M1 or Rx v1)
#define nIRQ_1 (PIND & 0x08)==0x08 //D3
#define nIRQ_0 (PIND & 0x08)==0x00 //D3
#define nSEL_on PORTD |= (1<<4) //D4
#define nSEL_off PORTD &= 0xEF //D4
#define SCK_on PORTD |= (1<<2) //D2
#define SCK_off PORTD &= 0xFB //D2
#define SDI_on PORTC |= (1<<1) //C1
#define SDI_off PORTC &= 0xFD //C1
#define SDO_1 (PINC & 0x01) == 0x01 //C0
#define SDO_0 (PINC & 0x01) == 0x00 //C0
#define SDO_pin A0
#define SDI_pin A1
#define SCLK_pin 2
#define IRQ_pin 3
#define nSel_pin 4
#define IRQ_interrupt 0
#endif
#if (BOARD_TYPE == 1) // Flytron M1 RX
#ifndef COMPILE_TX
#error M1 RX not verified yet
#endif
#define PPM_IN 5
#define BUZZER 7
#define BTN 8
#define Red_LED A3
#define Green_LED A2
#define Red_LED_ON PORTC &= ~_BV(2);PORTC |= _BV(3);
#define Red_LED_OFF PORTC &= ~_BV(2);PORTC &= ~_BV(3);
#define Green_LED_ON PORTC &= ~_BV(3);PORTC |= _BV(2);
#define Green_LED_OFF PORTC &= ~_BV(3);PORTC &= ~_BV(2);
#define PPM_Pin_Interrupt_Setup PCMSK2 = 0x20;PCICR|=(1<<PCIE2);
#define PPM_Signal_Interrupt PCINT2_vect
#define PPM_Signal_Edge_Check (PIND & 0x20)==0x20
//## RFM22B Pinouts for Public Edition (M1 or Rx v1)
#define nIRQ_1 (PIND & 0x08)==0x08 //D3
#define nIRQ_0 (PIND & 0x08)==0x00 //D3
#define nSEL_on PORTD |= (1<<4) //D4
#define nSEL_off PORTD &= 0xEF //D4
#define SCK_on PORTD |= (1<<2) //D2
#define SCK_off PORTD &= 0xFB //D2
#define SDI_on PORTC |= (1<<1) //C1
#define SDI_off PORTC &= 0xFD //C1
#define SDO_1 (PINC & 0x01) == 0x01 //C0
#define SDO_0 (PINC & 0x01) == 0x00 //C0
#define SDO_pin A0
#define SDI_pin A1
#define SCLK_pin 2
#define IRQ_pin 3
#define nSel_pin 4
#define IRQ_interrupt 0
#endif
#if (BOARD_TYPE == 2)
#ifndef COMPILE_TX
#error TX module cannot be used as RX
#endif
#define PPM_IN 3
#define BUZZER 10
#define BTN 11
#define Red_LED 13
#define Green_LED 12
#define Red_LED_ON PORTB |= _BV(5);
#define Red_LED_OFF PORTB &= ~_BV(5);
#define Green_LED_ON PORTB |= _BV(4);
#define Green_LED_OFF PORTB &= ~_BV(4);
#define PPM_Pin_Interrupt_Setup PCMSK2 = 0x08;PCICR|=(1<<PCIE2);
#define PPM_Signal_Interrupt PCINT2_vect
#define PPM_Signal_Edge_Check (PIND & 0x08)==0x08
//## RFM22B Pinouts for Public Edition (M2)
#define nIRQ_1 (PIND & 0x04)==0x04 //D2
#define nIRQ_0 (PIND & 0x04)==0x00 //D2
#define nSEL_on PORTD |= (1<<4) //D4
#define nSEL_off PORTD &= 0xEF //D4
#define SCK_on PORTD |= (1<<7) //D7
#define SCK_off PORTD &= 0x7F //D7
#define SDI_on PORTB |= (1<<0) //B0
#define SDI_off PORTB &= 0xFE //B0
#define SDO_1 (PINB & 0x02) == 0x02 //B1
#define SDO_0 (PINB & 0x02) == 0x00 //B1
#define SDO_pin 9
#define SDI_pin 8
#define SCLK_pin 7
#define IRQ_pin 2
#define nSel_pin 4
#define IRQ_interrupt 0
#endif
#if (BOARD_TYPE == 3)
#ifdef COMPILE_TX
#ifndef MATCATLRS_HW
#define USE_ICP1 // use ICP1 for PPM input for less jitter
#ifdef USE_ICP1
#define PPM_IN 8 // ICP1
#else
#define PPM_IN 3
#define PPM_Pin_Interrupt_Setup PCMSK2 = 0x08;PCICR|=(1<<PCIE2);
#define PPM_Signal_Interrupt PCINT2_vect
#define PPM_Signal_Edge_Check (PIND & 0x08)==0x08
#endif
#define BUZZER 6
#define BTN 7
#endif
#else
#ifndef MATCATLRS_HW
#define PPM_OUT 9 // OCP1A
#define RSSI_OUT 3 // PD3
#define PWM_1 5
#define PWM_1_MASK 0x0020 //PD5
#define PWM_2 6
#define PWM_2_MASK 0x0040 //PD6
#define PWM_3 7
#define PWM_3_MASK 0x0080 //PD7
#define PWM_4 8
#define PWM_4_MASK 0x0100 //PB0
#define PWM_5 9
#define PWM_5_MASK 0x0200 // PB1
#define PWM_6 10
#define PWM_6_MASK 0x0400 // PB2
#define PWM_7 11
#define PWM_7_MASK 0x0800 // PB3
#define PWM_8 12
#define PWM_8_MASK 0x1000 // PB4
const unsigned short PWM_MASK[8] = { PWM_1_MASK, PWM_2_MASK, PWM_3_MASK, PWM_4_MASK, PWM_5_MASK, PWM_6_MASK, PWM_7_MASK, PWM_8_MASK };
#define PWM_ALL_MASK 0x1FE0 // all bits used for PWM (logic OR of above)
#define PWM_MASK_PORTB(x) (((x)>>8) & 0xff)
#define PWM_MASK_PORTD(x) ((x) & 0xff)
#endif
#endif
#ifndef MATCATLRS_HW
#define Red_LED A3
#define Green_LED 13
#define Red_LED_ON PORTC |= _BV(3);
#define Red_LED_OFF PORTC &= ~_BV(3); // Was originally #define Green_LED_OFF PORTB |= _BV(5); E.g turns it ON not OFF
#define Green_LED_ON PORTB |= _BV(5);
#define Green_LED_OFF PORTB &= ~_BV(5);
#else
#define Red_LED 10
#define Green_LED 9
#define Red_LED_ON PORTB &= ~_BV(2);
#define Red_LED_OFF PORTB |= _BV(2);
#define Green_LED_ON PORTB &= ~_BV(1);
#define Green_LED_OFF PORTB |= _BV(1);
#endif
//## RFM22B Pinouts for Public Edition (Rx v2)
#define nIRQ_1 (PIND & 0x04)==0x04 //D2
#define nIRQ_0 (PIND & 0x04)==0x00 //D2
#define nSEL_on PORTD |= (1<<4) //D4
#define nSEL_off PORTD &= 0xEF //D4
#define SCK_on PORTC |= (1<<2) //A2
#define SCK_off PORTC &= 0xFB //A2
#define SDI_on PORTC |= (1<<1) //A1
#define SDI_off PORTC &= 0xFD //A1
#define SDO_1 (PINC & 0x01) == 0x01 //A0
#define SDO_0 (PINC & 0x01) == 0x00 //A0
#define SDO_pin A0
#define SDI_pin A1
#define SCLK_pin A2
#define IRQ_pin 2
#define nSel_pin 4
#define IRQ_interrupt 0
#endif