-
Notifications
You must be signed in to change notification settings - Fork 141
/
IOArduino.cpp
363 lines (308 loc) · 7.78 KB
/
IOArduino.cpp
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2016,2017,2018 by Andy Uribe CA6JAU
* Copyright (C) 2017 by Danilo DB4PLE
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Config.h"
#include "Globals.h"
#include "IO.h"
#if defined(ARDUINO)
#if defined (__STM32F1__)
// STM32F1 pin definitions, using STM32duino
#if defined(ZUMSPOT_ADF7021)
#define PIN_SCLK PB5
#define PIN_SREAD PB6
#define PIN_SDATA PB7
#define PIN_SLE PB8
#define PIN_SLE2 PA6
#define PIN_CE PC14
#define PIN_RXD PB4
#define PIN_RXD2 PA4
#define PIN_TXD PB3
#define PIN_TXD2 PA5
#define PIN_CLKOUT PA15
#define PIN_LED PC13
#define PIN_DEB PB9
#define PIN_DSTAR_LED PB12
#define PIN_DMR_LED PB13
#define PIN_YSF_LED PB1
#define PIN_P25_LED PB0
#if defined(STM32_USB_HOST)
#define PIN_NXDN_LED PA1
#else
#define PIN_NXDN_LED PA7
#endif
#define PIN_POCSAG_LED PA5
#define PIN_PTT_LED PB14
#define PIN_COS_LED PB15
#elif defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV10)
#define PIN_SCLK PB5
#define PIN_SREAD PB7
#define PIN_SDATA PB6
#define PIN_SLE PB8
#define PIN_SLE2 PA6
#define PIN_CE PC14
#define PIN_RXD PB4
#define PIN_RXD2 PA4
#define PIN_TXD PB3
#define PIN_TXD2 PA5
#define PIN_CLKOUT PA15
#define PIN_LED PC13
#define PIN_DEB PB9
#define PIN_DSTAR_LED PB12
#define PIN_DMR_LED PB13
#define PIN_YSF_LED PB1
#define PIN_P25_LED PB0
#define PIN_NXDN_LED PA8
#define PIN_POCSAG_LED PA7
#define PIN_PTT_LED PB14
#define PIN_COS_LED PB15
#else
#error "Either ZUMSPOT_ADF7021, LIBRE_KIT_ADF7021, MMDVM_HS_HAT_REV12, MMDVM_HS_DUAL_HAT_REV10, NANO_HOTSPOT or NANO_DV_REV10 need to be defined"
#endif
#elif defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
// Teensy pin definitions
#define PIN_SCLK 2
#define PIN_SDATA 3
#define PIN_SREAD 4
#define PIN_SLE 5
#define PIN_CE 6
#define PIN_RXD 7
#define PIN_TXD 8
#define PIN_CLKOUT 22
#define PIN_LED 13
#define PIN_DEB 23
#define PIN_DSTAR_LED 16
#define PIN_DMR_LED 17
#define PIN_YSF_LED 18
#define PIN_P25_LED 19
#define PIN_NXDN_LED 20
#define PIN_POCSAG_LED 21
#define PIN_PTT_LED 14
#define PIN_COS_LED 15
#else
// Arduino pin definitions (Due and Zero)
#define PIN_SCLK 3
#define PIN_SDATA 4 // 2 in Arduino Zero Pro
#define PIN_SREAD 5
#define PIN_SLE 6
#define PIN_CE 12
#define PIN_RXD 7
#define PIN_TXD 8
#define PIN_CLKOUT 2 // 4 in Arduino Zero Pro
#define PIN_LED 13
#define PIN_DEB 11
#define PIN_DSTAR_LED 14
#define PIN_DMR_LED 15
#define PIN_YSF_LED 16
#define PIN_P25_LED 17
#define PIN_NXDN_LED 18
#define PIN_POCSAG_LED 19
#define PIN_PTT_LED 9
#define PIN_COS_LED 10
#endif
extern "C" {
void EXT_IRQHandler(void) {
io.interrupt();
}
}
#if defined(DUPLEX)
extern "C" {
void EXT_IRQHandler2(void) {
io.interrupt2();
}
}
#endif
void CIO::delay_IFcal() {
delayMicroseconds(10000);
}
void CIO::delay_reset() {
delayMicroseconds(300);
}
void CIO::Init()
{
#if defined (__STM32F1__)
#if defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV10)
afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
#endif
#endif
pinMode(PIN_SCLK, OUTPUT);
pinMode(PIN_SDATA, OUTPUT);
pinMode(PIN_SREAD, INPUT);
pinMode(PIN_SLE, OUTPUT);
pinMode(PIN_CE, OUTPUT);
pinMode(PIN_RXD, INPUT);
pinMode(PIN_CLKOUT, INPUT);
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_DEB, OUTPUT);
pinMode(PIN_DSTAR_LED, OUTPUT);
pinMode(PIN_DMR_LED, OUTPUT);
pinMode(PIN_YSF_LED, OUTPUT);
pinMode(PIN_P25_LED, OUTPUT);
pinMode(PIN_NXDN_LED, OUTPUT);
pinMode(PIN_POCSAG_LED, OUTPUT);
pinMode(PIN_PTT_LED, OUTPUT);
pinMode(PIN_COS_LED, OUTPUT);
#if defined(DUPLEX)
pinMode(PIN_SLE2, OUTPUT);
pinMode(PIN_RXD2, INPUT);
pinMode(PIN_TXD2, INPUT);
#endif
#if defined(BIDIR_DATA_PIN)
pinMode(PIN_TXD, INPUT);
#else
pinMode(PIN_TXD, OUTPUT);
#endif
}
void CIO::startInt()
{
#if defined(BIDIR_DATA_PIN)
// TXD pin is TxRxCLK of ADF7021, standard TX/RX data interface
#if defined (__STM32F1__)
attachInterrupt(PIN_TXD, EXT_IRQHandler, CHANGE);
#else
attachInterrupt(digitalPinToInterrupt(PIN_TXD), EXT_IRQHandler, CHANGE);
#endif
#else
#if defined (__STM32F1__)
attachInterrupt(PIN_CLKOUT, EXT_IRQHandler, CHANGE);
#else
attachInterrupt(digitalPinToInterrupt(PIN_CLKOUT), EXT_IRQHandler, CHANGE);
#endif
#endif
#if defined(DUPLEX)
attachInterrupt(PIN_TXD2, EXT_IRQHandler2, RISING);
#endif
}
#if defined(BIDIR_DATA_PIN)
// RXD pin is bidirectional in standard interfaces
void CIO::Data_dir_out(bool dir)
{
if(dir)
pinMode(PIN_RXD, OUTPUT);
else
pinMode(PIN_RXD, INPUT);
}
#endif
void CIO::SCLK_pin(bool on)
{
digitalWrite(PIN_SCLK, on ? HIGH : LOW);
}
void CIO::SDATA_pin(bool on)
{
digitalWrite(PIN_SDATA, on ? HIGH : LOW);
}
bool CIO::SREAD_pin()
{
return digitalRead(PIN_SREAD) == HIGH;
}
void CIO::SLE_pin(bool on)
{
digitalWrite(PIN_SLE, on ? HIGH : LOW);
}
#if defined(DUPLEX)
void CIO::SLE2_pin(bool on)
{
digitalWrite(PIN_SLE2, on ? HIGH : LOW);
}
bool CIO::RXD2_pin()
{
return digitalRead(PIN_RXD2) == HIGH;
}
#endif
void CIO::CE_pin(bool on)
{
digitalWrite(PIN_CE, on ? HIGH : LOW);
}
bool CIO::RXD_pin()
{
return digitalRead(PIN_RXD) == HIGH;
}
bool CIO::CLK_pin()
{
return digitalRead(PIN_TXD) == HIGH;
}
#if defined(BIDIR_DATA_PIN)
void CIO::RXD_pin_write(bool on)
{
digitalWrite(PIN_RXD, on ? HIGH : LOW);
}
#endif
void CIO::TXD_pin(bool on)
{
digitalWrite(PIN_TXD, on ? HIGH : LOW);
}
void CIO::LED_pin(bool on)
{
digitalWrite(PIN_LED, on ? HIGH : LOW);
}
void CIO::DEB_pin(bool on)
{
digitalWrite(PIN_DEB, on ? HIGH : LOW);
}
void CIO::DSTAR_pin(bool on)
{
digitalWrite(PIN_DSTAR_LED, on ? HIGH : LOW);
}
void CIO::DMR_pin(bool on)
{
digitalWrite(PIN_DMR_LED, on ? HIGH : LOW);
}
void CIO::YSF_pin(bool on)
{
digitalWrite(PIN_YSF_LED, on ? HIGH : LOW);
}
void CIO::P25_pin(bool on)
{
digitalWrite(PIN_P25_LED, on ? HIGH : LOW);
}
void CIO::NXDN_pin(bool on)
{
#if defined(USE_ALTERNATE_NXDN_LEDS)
digitalWrite(PIN_YSF_LED, on ? HIGH : LOW);
digitalWrite(PIN_P25_LED, on ? HIGH : LOW);
#else
digitalWrite(PIN_NXDN_LED, on ? HIGH : LOW);
#endif
}
void CIO::POCSAG_pin(bool on)
{
#if defined(USE_ALTERNATE_POCSAG_LEDS)
digitalWrite(PIN_DSTAR_LED, on ? HIGH : LOW);
digitalWrite(PIN_DMR_LED, on ? HIGH : LOW);
#else
digitalWrite(PIN_POCSAG_LED, on ? HIGH : LOW);
#endif
}
void CIO::PTT_pin(bool on)
{
digitalWrite(PIN_PTT_LED, on ? HIGH : LOW);
}
void CIO::COS_pin(bool on)
{
digitalWrite(PIN_COS_LED, on ? HIGH : LOW);
}
void CIO::delay_us(uint32_t us) {
::delayMicroseconds(us);
}
void CIO::dlybit(void)
{
asm volatile("nop \n\t"
"nop \n\t"
"nop \n\t"
);
}
#endif