forked from juribeparada/MMDVM_HS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOSTM.cpp
816 lines (649 loc) · 22.4 KB
/
IOSTM.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
/*
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM
* Copyright (C) 2016,2017,2018,2019,2020 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"
// Select initial release of ZUMspot RPi:
// #define PI_HAT_7021_REV_02
#if defined(STM32F10X_MD)
#include "Globals.h"
#include "IO.h"
#if defined(PI_HAT_7021_REV_02)
#define PIN_SCLK GPIO_Pin_4
#define PORT_SCLK GPIOB
#define PIN_SREAD GPIO_Pin_5
#define PORT_SREAD GPIOB
#define PIN_SDATA GPIO_Pin_6
#define PORT_SDATA GPIOB
#define PIN_SLE GPIO_Pin_7
#define PORT_SLE GPIOB
#define PIN_CE GPIO_Pin_14
#define PORT_CE GPIOC
#define PIN_RXD GPIO_Pin_3
#define PORT_RXD GPIOB
// TXD used in SPI Data mode of ADF7021
// TXD is TxRxCLK of ADF7021, standard TX/RX data interface
#define PIN_TXD GPIO_Pin_15
#define PORT_TXD GPIOA
#define PIN_TXD_INT GPIO_PinSource15
#define PORT_TXD_INT GPIO_PortSourceGPIOA
// CLKOUT used in SPI Data mode of ADF7021
#define PIN_CLKOUT GPIO_Pin_14
#define PORT_CLKOUT GPIOA
#define PIN_CLKOUT_INT GPIO_PinSource14
#define PORT_CLKOUT_INT GPIO_PortSourceGPIOA
#define PIN_LED GPIO_Pin_13
#define PORT_LED GPIOC
#define PIN_DEB GPIO_Pin_11
#define PORT_DEB GPIOA
#define PIN_DSTAR_LED GPIO_Pin_14
#define PORT_DSTAR_LED GPIOB
#define PIN_DMR_LED GPIO_Pin_15
#define PORT_DMR_LED GPIOB
#define PIN_YSF_LED GPIO_Pin_13
#define PORT_YSF_LED GPIOA
#define PIN_P25_LED GPIO_Pin_12
#define PORT_P25_LED GPIOA
#define PIN_NXDN_LED GPIO_Pin_8
#define PORT_NXDN_LED GPIOA
#define PIN_POCSAG_LED GPIO_Pin_5
#define PORT_POCSAG_LED GPIOA
#define PIN_PTT_LED GPIO_Pin_12
#define PORT_PTT_LED GPIOB
#define PIN_COS_LED GPIO_Pin_13
#define PORT_COS_LED GPIOB
#elif defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
#define PIN_SCLK GPIO_Pin_5
#define PORT_SCLK GPIOB
#define PIN_SREAD GPIO_Pin_6
#define PORT_SREAD GPIOB
#define PIN_SDATA GPIO_Pin_7
#define PORT_SDATA GPIOB
#define PIN_SLE GPIO_Pin_8
#define PORT_SLE GPIOB
#define PIN_SLE2 GPIO_Pin_6
#define PORT_SLE2 GPIOA
#define PIN_CE GPIO_Pin_14
#define PORT_CE GPIOC
#define PIN_RXD GPIO_Pin_4
#define PORT_RXD GPIOB
#define PIN_SGL_DBL GPIO_Pin_12
#define PORT_SGL_DBL GPIOA
#define PIN_DL_DPX GPIO_Pin_15
#define PORT_DL_DPX GPIOC
#define PIN_SET_BAND GPIO_Pin_15
#define PORT_SET_BAND GPIOA
// TXD used in SPI Data mode of ADF7021
// TXD is TxRxCLK of ADF7021, standard TX/RX data interface
#define PIN_TXD GPIO_Pin_3
#define PORT_TXD GPIOB
#define PIN_TXD_INT GPIO_PinSource3
#define PORT_TXD_INT GPIO_PortSourceGPIOB
#if defined(DUPLEX)
#define PIN_RXD2 GPIO_Pin_11
#define PORT_RXD2 GPIOA
// TXD2 is TxRxCLK of the second ADF7021, standard TX/RX data interface
#define PIN_TXD2 GPIO_Pin_8
#define PORT_TXD2 GPIOA
#define PIN_TXD2_INT GPIO_PinSource8
#define PORT_TXD2_INT GPIO_PortSourceGPIOA
#endif
// CLKOUT used in SPI Data mode of ADF7021
#define PIN_CLKOUT GPIO_Pin_15
#define PORT_CLKOUT GPIOA
#define PIN_CLKOUT_INT GPIO_PinSource15
#define PORT_CLKOUT_INT GPIO_PortSourceGPIOA
#define PIN_LED GPIO_Pin_13
#define PORT_LED GPIOC
#define PIN_DEB GPIO_Pin_9
#define PORT_DEB GPIOB
#define PIN_DSTAR_LED GPIO_Pin_12
#define PORT_DSTAR_LED GPIOB
#define PIN_DMR_LED GPIO_Pin_13
#define PORT_DMR_LED GPIOB
#define PIN_YSF_LED GPIO_Pin_1
#define PORT_YSF_LED GPIOB
#define PIN_P25_LED GPIO_Pin_0
#define PORT_P25_LED GPIOB
#if defined(STM32_USB_HOST)
#define PIN_NXDN_LED GPIO_Pin_1
#else
#define PIN_NXDN_LED GPIO_Pin_7
#endif
#define PORT_NXDN_LED GPIOA
#define PIN_POCSAG_LED GPIO_Pin_5
#define PORT_POCSAG_LED GPIOA
#define PIN_PTT_LED GPIO_Pin_14
#define PORT_PTT_LED GPIOB
#define PIN_COS_LED GPIO_Pin_15
#define PORT_COS_LED GPIOB
#elif defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS)
#define PIN_SCLK GPIO_Pin_5
#define PORT_SCLK GPIOB
#define PIN_SREAD GPIO_Pin_7
#define PORT_SREAD GPIOB
#define PIN_SDATA GPIO_Pin_6
#define PORT_SDATA GPIOB
#define PIN_SLE GPIO_Pin_8
#define PORT_SLE GPIOB
#define PIN_SLE2 GPIO_Pin_6
#define PORT_SLE2 GPIOA
#define PIN_CE GPIO_Pin_14
#define PORT_CE GPIOC
#define PIN_RXD GPIO_Pin_4
#define PORT_RXD GPIOB
#define PIN_RXD2 GPIO_Pin_4
#define PORT_RXD2 GPIOA
// TXD used in SPI Data mode of ADF7021
// TXD is TxRxCLK of ADF7021, standard TX/RX data interface
#define PIN_TXD GPIO_Pin_3
#define PORT_TXD GPIOB
#define PIN_TXD_INT GPIO_PinSource3
#define PORT_TXD_INT GPIO_PortSourceGPIOB
// TXD2 is TxRxCLK of the second ADF7021, standard TX/RX data interface
#define PIN_TXD2 GPIO_Pin_5
#define PORT_TXD2 GPIOA
#define PIN_TXD2_INT GPIO_PinSource5
#define PORT_TXD2_INT GPIO_PortSourceGPIOA
// CLKOUT used in SPI Data mode of ADF7021
#define PIN_CLKOUT GPIO_Pin_15
#define PORT_CLKOUT GPIOA
#define PIN_CLKOUT_INT GPIO_PinSource15
#define PORT_CLKOUT_INT GPIO_PortSourceGPIOA
#define PIN_LED GPIO_Pin_13
#define PORT_LED GPIOC
#define PIN_DEB GPIO_Pin_9
#define PORT_DEB GPIOB
#define PIN_DSTAR_LED GPIO_Pin_12
#define PORT_DSTAR_LED GPIOB
#define PIN_DMR_LED GPIO_Pin_13
#define PORT_DMR_LED GPIOB
#define PIN_YSF_LED GPIO_Pin_1
#define PORT_YSF_LED GPIOB
#define PIN_P25_LED GPIO_Pin_0
#define PORT_P25_LED GPIOB
#define PIN_NXDN_LED GPIO_Pin_8
#define PORT_NXDN_LED GPIOA
#define PIN_POCSAG_LED GPIO_Pin_7
#define PORT_POCSAG_LED GPIOA
#define PIN_PTT_LED GPIO_Pin_14
#define PORT_PTT_LED GPIOB
#define PIN_COS_LED GPIO_Pin_15
#define PORT_COS_LED GPIOB
#else
#error "Either PI_HAT_7021_REV_02, ZUMSPOT_ADF7021, LIBRE_KIT_ADF7021, MMDVM_HS_HAT_REV12, MMDVM_HS_DUAL_HAT_REV10, NANO_HOTSPOT, NANO_DV_REV11, D2RG_MMDVM_HS or SKYBRIDGE_HS need to be defined"
#endif
extern "C" {
#if defined(PI_HAT_7021_REV_02)
#if defined(BIDIR_DATA_PIN)
void EXTI15_10_IRQHandler(void) {
if(EXTI_GetITStatus(EXTI_Line15)!=RESET) {
io.interrupt();
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
#else
void EXTI15_10_IRQHandler(void) {
if(EXTI_GetITStatus(EXTI_Line14)!=RESET) {
io.interrupt();
EXTI_ClearITPendingBit(EXTI_Line14);
}
}
#endif
#elif defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS) || defined(SKYBRIDGE_HS)
#if defined(BIDIR_DATA_PIN)
void EXTI3_IRQHandler(void) {
if(EXTI_GetITStatus(EXTI_Line3)!=RESET) {
io.interrupt();
EXTI_ClearITPendingBit(EXTI_Line3);
}
}
#else
void EXTI15_10_IRQHandler(void) {
if(EXTI_GetITStatus(EXTI_Line15)!=RESET) {
io.interrupt();
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
#endif
#if defined(DUPLEX)
void EXTI9_5_IRQHandler(void) {
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
if(EXTI_GetITStatus(EXTI_Line8)!=RESET) {
io.interrupt2();
EXTI_ClearITPendingBit(EXTI_Line8);
}
#else
if(EXTI_GetITStatus(EXTI_Line5)!=RESET) {
io.interrupt2();
EXTI_ClearITPendingBit(EXTI_Line5);
}
#endif
}
#endif
#endif
}
void CIO::Init()
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct);
EXTI_InitTypeDef EXTI_InitStructure;
#if defined(DUPLEX)
EXTI_InitTypeDef EXTI_InitStructure2;
#endif
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
#if defined(PI_HAT_7021_REV_02)
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
#elif defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS) || defined(SKYBRIDGE_HS)
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
#endif
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
// Pin defines if the board has a single ADF7021 or double
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SGL_DBL;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(PORT_SGL_DBL, &GPIO_InitStruct);
// Pin defines if the board is dual band or duplex
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_DL_DPX;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(PORT_DL_DPX, &GPIO_InitStruct);
// Pin will set UHF or VHF
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SET_BAND;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SET_BAND, &GPIO_InitStruct);
// TODO: Remove this line
// GPIO_WriteBit(PORT_SET_BAND, PIN_SET_BAND, Bit_RESET);
#endif
#if defined(STM32_USB_HOST)
// Pin PA11,PA12 = LOW, USB Reset
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_WriteBit(GPIOA, GPIO_Pin_11, Bit_RESET);
GPIO_WriteBit(GPIOA, GPIO_Pin_12, Bit_RESET);
#endif
#if defined(LONG_USB_RESET)
// 10 ms delay
delay_us(10000U);
#else
volatile unsigned int delay;
for(delay = 0;delay<512;delay++);
#endif
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStruct);
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
// Pin SCLK
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SCLK;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SCLK, &GPIO_InitStruct);
// Pin SDATA
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SDATA;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SDATA, &GPIO_InitStruct);
// Pin SREAD
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SREAD;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_SREAD, &GPIO_InitStruct);
// Pin SLE
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SLE;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SLE, &GPIO_InitStruct);
#if defined(DUPLEX)
// Pin SLE2
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SLE2;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SLE2, &GPIO_InitStruct);
// Pin RXD2
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_RXD2;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_RXD2, &GPIO_InitStruct);
#endif
// Pin CE
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_CE;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_CE, &GPIO_InitStruct);
// Pin RXD
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_RXD;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_RXD, &GPIO_InitStruct);
// Pin TXD
// TXD is TxRxCLK of ADF7021, standard TX/RX data interface
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_TXD;
#if defined(BIDIR_DATA_PIN)
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
#else
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
#endif
GPIO_Init(PORT_TXD, &GPIO_InitStruct);
#if defined(DUPLEX)
GPIO_InitStruct.GPIO_Pin = PIN_TXD2;
GPIO_Init(PORT_TXD2, &GPIO_InitStruct);
#endif
// Pin TXRX_CLK
#if !defined(BIDIR_DATA_PIN)
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_CLKOUT;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_CLKOUT, &GPIO_InitStruct);
#endif
// Pin LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_LED, &GPIO_InitStruct);
// Pin Debug
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_DEB;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_DEB, &GPIO_InitStruct);
// D-Star LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_DSTAR_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_DSTAR_LED, &GPIO_InitStruct);
// DMR LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_DMR_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_DMR_LED, &GPIO_InitStruct);
// YSF LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_YSF_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_YSF_LED, &GPIO_InitStruct);
// P25 LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_P25_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_P25_LED, &GPIO_InitStruct);
// NXDN LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_NXDN_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_NXDN_LED, &GPIO_InitStruct);
// POCSAG LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_POCSAG_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_POCSAG_LED, &GPIO_InitStruct);
// PTT LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_PTT_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_PTT_LED, &GPIO_InitStruct);
// COS LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_COS_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_COS_LED, &GPIO_InitStruct);
#if defined(PI_HAT_7021_REV_02)
#if defined(BIDIR_DATA_PIN)
// Connect EXTI15 Line
GPIO_EXTILineConfig(PORT_TXD_INT, PIN_TXD_INT);
// Configure EXTI15 line
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
#else
// Connect EXTI14 Line
GPIO_EXTILineConfig(PORT_CLKOUT_INT, PIN_CLKOUT_INT);
// Configure EXTI14 line
EXTI_InitStructure.EXTI_Line = EXTI_Line14;
#endif
#elif defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS) || defined(SKYBRIDGE_HS)
#if defined(BIDIR_DATA_PIN)
// Connect EXTI3 Line
GPIO_EXTILineConfig(PORT_TXD_INT, PIN_TXD_INT);
// Configure EXTI3 line
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
#else
// Connect EXTI15 Line
GPIO_EXTILineConfig(PORT_CLKOUT_INT, PIN_CLKOUT_INT);
// Configure EXTI15 line
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
#endif
#if defined(DUPLEX)
// Connect EXTI5 Line
GPIO_EXTILineConfig(PORT_TXD2_INT, PIN_TXD2_INT);
// Configure EXT5 line
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
EXTI_InitStructure2.EXTI_Line = EXTI_Line8;
#else
EXTI_InitStructure2.EXTI_Line = EXTI_Line5;
#endif
#endif
#endif
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
#if defined(DUPLEX)
EXTI_InitStructure2.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure2.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure2.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure2);
#endif
}
void CIO::startInt()
{
NVIC_InitTypeDef NVIC_InitStructure;
#if defined(DUPLEX)
NVIC_InitTypeDef NVIC_InitStructure2;
#endif
#if defined(PI_HAT_7021_REV_02)
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
#elif defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS) || defined(SKYBRIDGE_HS)
#if defined(BIDIR_DATA_PIN)
// Enable and set EXTI3 Interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
#else
// Enable and set EXTI15 Interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
#endif
#if defined(DUPLEX)
NVIC_InitStructure2.NVIC_IRQChannel = EXTI9_5_IRQn;
#endif
#endif
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 15;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#if defined(DUPLEX)
NVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure2.NVIC_IRQChannelSubPriority = 15;
NVIC_InitStructure2.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure2);
#endif
}
#if defined(BIDIR_DATA_PIN)
// RXD pin is bidirectional in standard interfaces
void CIO::Data_dir_out(bool dir)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_RXD;
if(dir)
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
else
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_RXD, &GPIO_InitStruct);
}
#endif
void CIO::SCLK_pin(bool on)
{
GPIO_WriteBit(PORT_SCLK, PIN_SCLK, on ? Bit_SET : Bit_RESET);
}
void CIO::SDATA_pin(bool on)
{
GPIO_WriteBit(PORT_SDATA, PIN_SDATA, on ? Bit_SET : Bit_RESET);
}
bool CIO::SREAD_pin()
{
return GPIO_ReadInputDataBit(PORT_SREAD, PIN_SREAD) == Bit_SET;
}
void CIO::SLE_pin(bool on)
{
GPIO_WriteBit(PORT_SLE, PIN_SLE, on ? Bit_SET : Bit_RESET);
}
#if defined(DUPLEX)
void CIO::SLE2_pin(bool on)
{
GPIO_WriteBit(PORT_SLE2, PIN_SLE2, on ? Bit_SET : Bit_RESET);
}
bool CIO::RXD2_pin()
{
return GPIO_ReadInputDataBit(PORT_RXD2, PIN_RXD2) == Bit_SET;
}
#endif
void CIO::CE_pin(bool on)
{
GPIO_WriteBit(PORT_CE, PIN_CE, on ? Bit_SET : Bit_RESET);
}
bool CIO::RXD_pin()
{
return GPIO_ReadInputDataBit(PORT_RXD, PIN_RXD) == Bit_SET;
}
bool CIO::CLK_pin()
{
#if defined(BIDIR_DATA_PIN)
return GPIO_ReadInputDataBit(PORT_TXD, PIN_TXD) == Bit_SET;
#else
return GPIO_ReadInputDataBit(PORT_CLKOUT, PIN_CLKOUT) == Bit_SET;
#endif
}
#if defined(BIDIR_DATA_PIN)
void CIO::RXD_pin_write(bool on)
{
GPIO_WriteBit(PORT_RXD, PIN_RXD, on ? Bit_SET : Bit_RESET);
}
#endif
void CIO::TXD_pin(bool on)
{
GPIO_WriteBit(PORT_TXD, PIN_TXD, on ? Bit_SET : Bit_RESET);
}
void CIO::LED_pin(bool on)
{
GPIO_WriteBit(PORT_LED, PIN_LED, on ? Bit_SET : Bit_RESET);
}
void CIO::DEB_pin(bool on)
{
GPIO_WriteBit(PORT_DEB, PIN_DEB, on ? Bit_SET : Bit_RESET);
}
void CIO::DSTAR_pin(bool on)
{
GPIO_WriteBit(PORT_DSTAR_LED, PIN_DSTAR_LED, on ? Bit_SET : Bit_RESET);
}
void CIO::DMR_pin(bool on)
{
GPIO_WriteBit(PORT_DMR_LED, PIN_DMR_LED, on ? Bit_SET : Bit_RESET);
}
void CIO::YSF_pin(bool on)
{
GPIO_WriteBit(PORT_YSF_LED, PIN_YSF_LED, on ? Bit_SET : Bit_RESET);
}
void CIO::P25_pin(bool on)
{
GPIO_WriteBit(PORT_P25_LED, PIN_P25_LED, on ? Bit_SET : Bit_RESET);
}
void CIO::NXDN_pin(bool on)
{
#if defined(USE_ALTERNATE_NXDN_LEDS)
GPIO_WriteBit(PORT_YSF_LED, PIN_YSF_LED, on ? Bit_SET : Bit_RESET);
GPIO_WriteBit(PORT_P25_LED, PIN_P25_LED, on ? Bit_SET : Bit_RESET);
#else
GPIO_WriteBit(PORT_NXDN_LED, PIN_NXDN_LED, on ? Bit_SET : Bit_RESET);
#endif
}
void CIO::POCSAG_pin(bool on)
{
#if defined(USE_ALTERNATE_POCSAG_LEDS)
GPIO_WriteBit(PORT_DSTAR_LED, PIN_DSTAR_LED, on ? Bit_SET : Bit_RESET);
GPIO_WriteBit(PORT_DMR_LED, PIN_DMR_LED, on ? Bit_SET : Bit_RESET);
#else
GPIO_WriteBit(PORT_POCSAG_LED, PIN_POCSAG_LED, on ? Bit_SET : Bit_RESET);
#endif
}
void CIO::PTT_pin(bool on)
{
GPIO_WriteBit(PORT_PTT_LED, PIN_PTT_LED, on ? Bit_SET : Bit_RESET);
}
void CIO::COS_pin(bool on)
{
GPIO_WriteBit(PORT_COS_LED, PIN_COS_LED, on ? Bit_SET : Bit_RESET);
}
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
void CIO::setBandVHF(bool vhf_on) {
GPIO_WriteBit(PORT_SET_BAND, PIN_SET_BAND, vhf_on ? Bit_SET : Bit_RESET);
}
bool CIO::hasSingleADF7021() {
return GPIO_ReadInputDataBit(PORT_SGL_DBL, PIN_SGL_DBL) == Bit_SET;
}
bool CIO::isDualBand() {
return GPIO_ReadInputDataBit(PORT_DL_DPX, PIN_DL_DPX) == Bit_SET;
}
#endif
/**
* Function delay_us() from stm32duino project
*
* @brief Delay the given number of microseconds.
*
* @param us Number of microseconds to delay.
*/
static inline void delay_us(uint32_t us) {
us *= 12;
/* fudge for function call overhead */
us--;
asm volatile(" mov r0, %[us] \n\t"
"1: subs r0, #1 \n\t"
" bhi 1b \n\t"
:
: [us] "r" (us)
: "r0");
}
void CIO::delay_IFcal() {
delay_us(10000);
}
void CIO::delay_reset() {
delay_us(300);
}
void CIO::delay_us(uint32_t us) {
::delay_us(us);
}
static inline void delay_ns() {
asm volatile("nop \n\t"
"nop \n\t"
"nop \n\t"
);
}
void CIO::dlybit(void)
{
delay_ns();
}
#endif